bug 122:
[oota-llvm.git] / lib / VMCore / iBranch.cpp
1 //===-- iBranch.cpp - Implement the Branch instruction --------------------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the 'br' instruction, which can represent either a 
11 // conditional or unconditional branch.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/iTerminators.h"
16 #include "llvm/BasicBlock.h"
17 #include "llvm/Type.h"
18 using namespace llvm;
19
20 // Out-of-line ReturnInst method, put here so the C++ compiler can choose to
21 // emit the vtable for the class in this translation unit.
22 void ReturnInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {
23   assert(0 && "ReturnInst has no successors!");
24 }
25
26 // Likewise for UnwindInst
27 void UnwindInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {
28   assert(0 && "UnwindInst has no successors!");
29 }
30
31 void BranchInst::init(BasicBlock *IfTrue)
32 {
33   assert(IfTrue != 0 && "Branch destination may not be null!");
34   Operands.reserve(1);
35   Operands.push_back(Use(IfTrue, this));
36 }
37
38 void BranchInst::init(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond)
39 {
40   assert(IfTrue && IfFalse && Cond &&
41          "Branch destinations and condition may not be null!");
42   assert(Cond && Cond->getType() == Type::BoolTy && 
43          "May only branch on boolean predicates!");
44   Operands.reserve(3);
45   Operands.push_back(Use(IfTrue, this));
46   Operands.push_back(Use(IfFalse, this));
47   Operands.push_back(Use(Cond, this));
48 }
49
50 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
51   Operands.reserve(BI.Operands.size());
52   Operands.push_back(Use(BI.Operands[0], this));
53   if (BI.Operands.size() != 1) {
54     assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
55     Operands.push_back(Use(BI.Operands[1], this));
56     Operands.push_back(Use(BI.Operands[2], this));
57   }
58 }