summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/iBranch.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
committerChris Lattner <sabre@nondot.org>2001-07-07 08:36:50 +0000
commita073acb22d6262e40bef357279fd61ab0ef8b642 (patch)
treeb9a1ef2336895d1d3d250a339370d84b6b99f8d1 /llvm/lib/VMCore/iBranch.cpp
parent37099990b3d340de8cfa635cd8559ef79e8b2c5f (diff)
downloadbcm5719-llvm-a073acb22d6262e40bef357279fd61ab0ef8b642.tar.gz
bcm5719-llvm-a073acb22d6262e40bef357279fd61ab0ef8b642.zip
Changed the fundemental architecture of Operands for Instructions. Now
Operands are maintained as a vector<Use> in the User class, and operator iterators are provided as before. Getting an operand no longer requires a virtual function call. WARNING: getOperand(x) where x >= getNumOperands() will now assert instead of returning null! llvm-svn: 149
Diffstat (limited to 'llvm/lib/VMCore/iBranch.cpp')
-rw-r--r--llvm/lib/VMCore/iBranch.cpp61
1 files changed, 18 insertions, 43 deletions
diff --git a/llvm/lib/VMCore/iBranch.cpp b/llvm/lib/VMCore/iBranch.cpp
index 05f35059a54..d0f437e293b 100644
--- a/llvm/lib/VMCore/iBranch.cpp
+++ b/llvm/lib/VMCore/iBranch.cpp
@@ -13,9 +13,17 @@
#endif
BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond)
- : TerminatorInst(Instruction::Br), TrueDest(True, this),
- FalseDest(False, this), Condition(Cond, this) {
+ : TerminatorInst(Instruction::Br) {
assert(True != 0 && "True branch destination may not be null!!!");
+ Operands.reserve(False ? 3 : 1);
+ Operands.push_back(Use(True, this));
+ if (False) {
+ Operands.push_back(Use(False, this));
+ Operands.push_back(Use(Cond, this));
+ }
+
+ assert(!!False == !!Cond &&
+ "Either both cond and false or neither can be specified!");
#ifndef NDEBUG
if (Cond != 0 && Cond->getType() != Type::BoolTy)
@@ -25,45 +33,12 @@ BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond)
"May only branch on boolean predicates!!!!");
}
-BranchInst::BranchInst(const BranchInst &BI)
- : TerminatorInst(Instruction::Br), TrueDest(BI.TrueDest, this),
- FalseDest(BI.FalseDest, this), Condition(BI.Condition, this) {
-}
-
-
-void BranchInst::dropAllReferences() {
- Condition = 0;
- TrueDest = FalseDest = 0;
-}
-
-const Value *BranchInst::getOperand(unsigned i) const {
- return (i == 0) ? (Value*)TrueDest :
- ((i == 1) ? (Value*)FalseDest :
- ((i == 2) ? (Value*)Condition : 0));
-}
-
-const BasicBlock *BranchInst::getSuccessor(unsigned i) const {
- return (i == 0) ? (const BasicBlock*)TrueDest :
- ((i == 1) ? (const BasicBlock*)FalseDest : 0);
-}
-
-bool BranchInst::setOperand(unsigned i, Value *Val) {
- switch (i) {
- case 0:
- assert(Val && "Can't change primary direction to 0!");
- assert(Val->getType() == Type::LabelTy);
- TrueDest = (BasicBlock*)Val;
- return true;
- case 1:
- assert(Val == 0 || Val->getType() == Type::LabelTy);
- FalseDest = (BasicBlock*)Val;
- return true;
- case 2:
- Condition = Val;
- assert(!Condition || Condition->getType() == Type::BoolTy &&
- "Condition expr must be a boolean expression!");
- return true;
- }
-
- return false;
+BranchInst::BranchInst(const BranchInst &BI) : TerminatorInst(Instruction::Br) {
+ Operands.reserve(BI.Operands.size());
+ Operands.push_back(Use(BI.Operands[0], this));
+ if (BI.Operands.size() != 1) {
+ assert(BI.Operands.size() == 3 && "BR can have 1 or 3 operands!");
+ Operands.push_back(Use(BI.Operands[1], this));
+ Operands.push_back(Use(BI.Operands[2], this));
+ }
}
OpenPOWER on IntegriCloud