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"
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!");
26 // Likewise for UnwindInst
27 void UnwindInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {
28 assert(0 && "UnwindInst has no successors!");
31 void BranchInst::init(BasicBlock *IfTrue)
33 assert(IfTrue != 0 && "Branch destination may not be null!");
35 Operands.push_back(Use(IfTrue, this));
38 void BranchInst::init(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond)
40 assert(IfTrue && IfFalse && Cond &&
41 "Branch destinations and condition may not be null!");
42 assert(Cond && Cond->getType() == Type::BoolTy &&
43 "May only branch on boolean predicates!");
45 Operands.push_back(Use(IfTrue, this));
46 Operands.push_back(Use(IfFalse, this));
47 Operands.push_back(Use(Cond, this));
50 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
51 Operands.reserve(BI.Operands.size());
52 Operands.push_back(Use(BI.Operands[0], this));
53 if (BI.Operands.size() != 1) {
54 assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
55 Operands.push_back(Use(BI.Operands[1], this));
56 Operands.push_back(Use(BI.Operands[2], this));