Added LLVM project notice to the top of every C++ source file.
[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
19 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
20                        Instruction *InsertBefore) 
21   : TerminatorInst(Instruction::Br, InsertBefore) {
22   assert(True != 0 && "True branch destination may not be null!!!");
23   Operands.reserve(False ? 3 : 1);
24   Operands.push_back(Use(True, this));
25   if (False) {
26     Operands.push_back(Use(False, this));
27     Operands.push_back(Use(Cond, this));
28   }
29
30   assert(!!False == !!Cond &&
31          "Either both cond and false or neither can be specified!");
32   assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
33          "May only branch on boolean predicates!!!!");
34 }
35
36 BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) 
37   : TerminatorInst(Instruction::Br, InsertBefore) {
38   assert(True != 0 && "True branch destination may not be null!!!");
39   Operands.reserve(1);
40   Operands.push_back(Use(True, this));
41 }
42
43 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
44   Operands.reserve(BI.Operands.size());
45   Operands.push_back(Use(BI.Operands[0], this));
46   if (BI.Operands.size() != 1) {
47     assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
48     Operands.push_back(Use(BI.Operands[1], this));
49     Operands.push_back(Use(BI.Operands[2], this));
50   }
51 }