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 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
32 Instruction *InsertBefore)
33 : TerminatorInst(Instruction::Br, InsertBefore) {
34 assert(True != 0 && "True branch destination may not be null!!!");
35 Operands.reserve(False ? 3 : 1);
36 Operands.push_back(Use(True, this));
38 Operands.push_back(Use(False, this));
39 Operands.push_back(Use(Cond, this));
42 assert(!!False == !!Cond &&
43 "Either both cond and false or neither can be specified!");
44 assert((Cond == 0 || Cond->getType() == Type::BoolTy) &&
45 "May only branch on boolean predicates!!!!");
48 BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond,
49 BasicBlock *InsertAtEnd)
50 : TerminatorInst(Instruction::Br, InsertAtEnd) {
51 assert(True != 0 && "True branch destination may not be null!!!");
52 Operands.reserve(False ? 3 : 1);
53 Operands.push_back(Use(True, this));
55 Operands.push_back(Use(False, this));
56 Operands.push_back(Use(Cond, this));
59 assert(!!False == !!Cond &&
60 "Either both cond and false or neither can be specified!");
61 assert((Cond == 0 || Cond->getType() == Type::BoolTy) &&
62 "May only branch on boolean predicates!!!!");
65 BranchInst::BranchInst(BasicBlock *True, Instruction *InsertBefore)
66 : TerminatorInst(Instruction::Br, InsertBefore) {
67 assert(True != 0 && "True branch destination may not be null!!!");
69 Operands.push_back(Use(True, this));
72 BranchInst::BranchInst(BasicBlock *True, BasicBlock *InsertAtEnd)
73 : TerminatorInst(Instruction::Br, InsertAtEnd) {
74 assert(True != 0 && "True branch destination may not be null!!!");
76 Operands.push_back(Use(True, this));
79 BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
80 Operands.reserve(BI.Operands.size());
81 Operands.push_back(Use(BI.Operands[0], this));
82 if (BI.Operands.size() != 1) {
83 assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
84 Operands.push_back(Use(BI.Operands[1], this));
85 Operands.push_back(Use(BI.Operands[2], this));