* Expose new command line arg --debug-pass for gccas and llc debugging
[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 #ifndef NDEBUG
11 #include "llvm/Type.h"       // Only used for assertions...
12 #include "llvm/Assembly/Writer.h"
13 #include <iostream>
14 #endif
15
16 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) 
17   : TerminatorInst(Instruction::Br) {
18   assert(True != 0 && "True branch destination may not be null!!!");
19   Operands.reserve(False ? 3 : 1);
20   Operands.push_back(Use(True, this));
21   if (False) {
22     Operands.push_back(Use(False, this));
23     Operands.push_back(Use(Cond, this));
24   }
25
26   assert(!!False == !!Cond &&
27          "Either both cond and false or neither can be specified!");
28
29 #ifndef NDEBUG
30   if (Cond != 0 && Cond->getType() != Type::BoolTy)
31     std::cerr << "Bad Condition: " << Cond << "\n";
32 #endif
33   assert((Cond == 0 || Cond->getType() == Type::BoolTy) && 
34          "May only branch on boolean predicates!!!!");
35 }
36
37 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
38   Operands.reserve(BI.Operands.size());
39   Operands.push_back(Use(BI.Operands[0], this));
40   if (BI.Operands.size() != 1) {
41     assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
42     Operands.push_back(Use(BI.Operands[1], this));
43     Operands.push_back(Use(BI.Operands[2], this));
44   }
45 }