First attempt at handling frame index elimination.
[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 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
32                        Instruction *InsertBefore) 
33   : TerminatorInst(Instruction::Br, InsertBefore) {
34   assert(True != 0 && "True branch destination may not be null!!!");
35   Operands.reserve(False ? 3 : 1);
36   Operands.push_back(Use(True, this));
37   if (False) {
38     Operands.push_back(Use(False, this));
39     Operands.push_back(Use(Cond, this));
40   }
41
42   assert(!!False == !!Cond &&
43          "Either both cond and false or neither can be specified!");
44   assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
45          "May only branch on boolean predicates!!!!");
46 }
47
48 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
49                        BasicBlock *InsertAtEnd) 
50   : TerminatorInst(Instruction::Br, InsertAtEnd) {
51   assert(True != 0 && "True branch destination may not be null!!!");
52   Operands.reserve(False ? 3 : 1);
53   Operands.push_back(Use(True, this));
54   if (False) {
55     Operands.push_back(Use(False, this));
56     Operands.push_back(Use(Cond, this));
57   }
58
59   assert(!!False == !!Cond &&
60          "Either both cond and false or neither can be specified!");
61   assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
62          "May only branch on boolean predicates!!!!");
63 }
64
65 BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) 
66   : TerminatorInst(Instruction::Br, InsertBefore) {
67   assert(True != 0 && "True branch destination may not be null!!!");
68   Operands.reserve(1);
69   Operands.push_back(Use(True, this));
70 }
71
72 BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd) 
73   : TerminatorInst(Instruction::Br, InsertAtEnd) {
74   assert(True != 0 && "True branch destination may not be null!!!");
75   Operands.reserve(1);
76   Operands.push_back(Use(True, this));
77 }
78
79 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
80   Operands.reserve(BI.Operands.size());
81   Operands.push_back(Use(BI.Operands[0], this));
82   if (BI.Operands.size() != 1) {
83     assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
84     Operands.push_back(Use(BI.Operands[1], this));
85     Operands.push_back(Use(BI.Operands[2], this));
86   }
87 }