Fix bug: Assembler/2003-03-03-DuplicateConstant.ll
[oota-llvm.git] / lib / VMCore / iBranch.cpp
1 //===-- iBranch.cpp - Implement the Branch instruction -----------*- C++ -*--=//
2 //
3 // This file implements the 'br' instruction, which can represent either a 
4 // conditional or unconditional branch.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/iTerminators.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/Type.h"
11
12 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
13                        Instruction *InsertBefore) 
14   : TerminatorInst(Instruction::Br, InsertBefore) {
15   assert(True != 0 && "True branch destination may not be null!!!");
16   Operands.reserve(False ? 3 : 1);
17   Operands.push_back(Use(True, this));
18   if (False) {
19     Operands.push_back(Use(False, this));
20     Operands.push_back(Use(Cond, this));
21   }
22
23   assert(!!False == !!Cond &&
24          "Either both cond and false or neither can be specified!");
25   assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
26          "May only branch on boolean predicates!!!!");
27 }
28
29 BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore) 
30   : TerminatorInst(Instruction::Br, InsertBefore) {
31   assert(True != 0 && "True branch destination may not be null!!!");
32   Operands.reserve(1);
33   Operands.push_back(Use(True, this));
34 }
35
36 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
37   Operands.reserve(BI.Operands.size());
38   Operands.push_back(Use(BI.Operands[0], this));
39   if (BI.Operands.size() != 1) {
40     assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
41     Operands.push_back(Use(BI.Operands[1], this));
42     Operands.push_back(Use(BI.Operands[2], this));
43   }
44 }