mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-13 23:18:58 +00:00
131d19f9c6
Add new removeCase method git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8088 91177308-0d34-0410-b5e6-96231b3b80d8
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
//===-- iSwitch.cpp - Implement the Switch instruction -----------*- C++ -*--=//
|
|
//
|
|
// This file implements the Switch instruction...
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/iTerminators.h"
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
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) {
|
|
Operands.reserve(SI.Operands.size());
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
/// addCase - Add an entry to the switch instruction...
|
|
///
|
|
void SwitchInst::addCase(Constant *OnVal, BasicBlock *Dest) {
|
|
Operands.push_back(Use((Value*)OnVal, this));
|
|
Operands.push_back(Use((Value*)Dest, this));
|
|
}
|
|
|
|
/// removeCase - This method removes the specified successor from the switch
|
|
/// instruction. Note that this cannot be used to remove the default
|
|
/// destination (successor #0).
|
|
///
|
|
void SwitchInst::removeCase(unsigned idx) {
|
|
assert(idx != 0 && "Cannot remove the default case!");
|
|
assert(idx*2 < Operands.size() && "Successor index out of range!!!");
|
|
Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);
|
|
}
|