1 //===-- iBranch.cpp - Implement the Branch instruction --------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the 'br' instruction, which can represent either a
11 // conditional or unconditional branch.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/iTerminators.h"
16 #include "llvm/BasicBlock.h"
17 #include "llvm/Type.h"
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));
26 Operands.push_back(Use(False, this));
27 Operands.push_back(Use(Cond, this));
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!!!!");
36 BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
37 : TerminatorInst(Instruction::Br, InsertBefore) {
38 assert(True != 0 && "True branch destination may not be null!!!");
40 Operands.push_back(Use(True, this));
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));