X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FiSwitch.cpp;h=a63adfdfcfd289ec712457d26ecf82286e7777f6;hb=61d295aa291ae66eec95f60a12bacddbefb2f6a2;hp=2a1eec263911d69038a376ef0d13aab70e933fb8;hpb=009505452b713ed2e3a8e99c5545a6e721c65495;p=oota-llvm.git diff --git a/lib/VMCore/iSwitch.cpp b/lib/VMCore/iSwitch.cpp index 2a1eec26391..a63adfdfcfd 100644 --- a/lib/VMCore/iSwitch.cpp +++ b/lib/VMCore/iSwitch.cpp @@ -6,76 +6,26 @@ #include "llvm/iTerminators.h" #include "llvm/BasicBlock.h" -#ifndef NDEBUG -#include "llvm/Type.h" -#endif -SwitchInst::SwitchInst(Value *V, BasicBlock *DefV) - : TerminatorInst(Instruction::Switch), - DefaultDest(DefV, this), Val(V, this) { - assert(Val && DefV); +SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest, + Instruction *InsertBefore) + : TerminatorInst(Instruction::Switch, InsertBefore) { + assert(V && DefaultDest); + Operands.push_back(Use(V, this)); + Operands.push_back(Use(DefaultDest, this)); } SwitchInst::SwitchInst(const SwitchInst &SI) - : TerminatorInst(Instruction::Switch), DefaultDest(SI.DefaultDest), - Val(SI.Val) { + : TerminatorInst(Instruction::Switch) { + Operands.reserve(SI.Operands.size()); - for (dest_const_iterator I = SI.Destinations.begin(), - end = SI.Destinations.end(); I != end; ++I) - Destinations.push_back(dest_value(ConstPoolUse(I->first, this), - BasicBlockUse(I->second, this))); -} - - -void SwitchInst::dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest) { - Destinations.push_back(dest_value(ConstPoolUse(OnVal, this), - BasicBlockUse(Dest, this))); -} - -void SwitchInst::dropAllReferences() { - Val = 0; - DefaultDest = 0; - Destinations.clear(); -} - -const BasicBlock *SwitchInst::getSuccessor(unsigned idx) const { - if (idx == 0) return DefaultDest; - if (idx > Destinations.size()) return 0; - return Destinations[idx-1].second; -} - -unsigned SwitchInst::getNumOperands() const { - return 2+Destinations.size(); -} - -const Value *SwitchInst::getOperand(unsigned i) const { - if (i == 0) return Val; - else if (i == 1) return DefaultDest; - - unsigned slot = (i-2) >> 1; - if (slot >= Destinations.size()) return 0; - - if (i & 1) return Destinations[slot].second; - return Destinations[slot].first; -} - -bool SwitchInst::setOperand(unsigned i, Value *V) { - if (i == 0) { Val = V; return true; } - else if (i == 1) { - assert(V->getType() == Type::LabelTy); - DefaultDest = (BasicBlock*)V; - return true; + for (unsigned i = 0, E = SI.Operands.size(); i != E; i+=2) { + Operands.push_back(Use(SI.Operands[i], this)); + Operands.push_back(Use(SI.Operands[i+1], this)); } +} - unsigned slot = (i-2) >> 1; - if (slot >= Destinations.size()) return 0; - - if (i & 1) { - assert(V->getType() == Type::LabelTy); - Destinations[slot].second = (BasicBlock*)V; - } else { - // TODO: assert constant - Destinations[slot].first = (ConstPoolVal*)V; - } - return true; +void SwitchInst::dest_push_back(Constant *OnVal, BasicBlock *Dest) { + Operands.push_back(Use((Value*)OnVal, this)); + Operands.push_back(Use((Value*)Dest, this)); }