summaryrefslogtreecommitdiff
path: root/lib/VMCore/iBranch.cpp
blob: 59dc303d70103856fe85b1764db47cd029b2f10c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//===-- iBranch.cpp - Implement the Branch instruction --------------------===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
//
// This file implements the 'br' instruction, which can represent either a 
// conditional or unconditional branch.
//
//===----------------------------------------------------------------------===//

#include "llvm/iTerminators.h"
#include "llvm/BasicBlock.h"
#include "llvm/Type.h"

namespace llvm {

BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
                       Instruction *InsertBefore) 
  : TerminatorInst(Instruction::Br, InsertBefore) {
  assert(True != 0 && "True branch destination may not be null!!!");
  Operands.reserve(False ? 3 : 1);
  Operands.push_back(Use(True, this));
  if (False) {
    Operands.push_back(Use(False, this));
    Operands.push_back(Use(Cond, this));
  }

  assert(!!False == !!Cond &&
	 "Either both cond and false or neither can be specified!");
  assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
         "May only branch on boolean predicates!!!!");
}

BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) 
  : TerminatorInst(Instruction::Br, InsertBefore) {
  assert(True != 0 && "True branch destination may not be null!!!");
  Operands.reserve(1);
  Operands.push_back(Use(True, this));
}

BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
  Operands.reserve(BI.Operands.size());
  Operands.push_back(Use(BI.Operands[0], this));
  if (BI.Operands.size() != 1) {
    assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
    Operands.push_back(Use(BI.Operands[1], this));
    Operands.push_back(Use(BI.Operands[2], this));
  }
}

} // End llvm namespace