aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/Interpreter/Execution.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/Execution.cpp')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index af47be9c5b56..5202b091654e 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -651,11 +651,40 @@ void Interpreter::visitSwitchInst(SwitchInst &I) {
// Check to see if any of the cases match...
BasicBlock *Dest = 0;
for (SwitchInst::CaseIt i = I.case_begin(), e = I.case_end(); i != e; ++i) {
- GenericValue CaseVal = getOperandValue(i.getCaseValue(), SF);
- if (executeICMP_EQ(CondVal, CaseVal, ElTy).IntVal != 0) {
- Dest = cast<BasicBlock>(i.getCaseSuccessor());
- break;
+ IntegersSubset& Case = i.getCaseValueEx();
+ if (Case.isSingleNumber()) {
+ // FIXME: Currently work with ConstantInt based numbers.
+ const ConstantInt *CI = Case.getSingleNumber(0).toConstantInt();
+ GenericValue Val = getOperandValue(const_cast<ConstantInt*>(CI), SF);
+ if (executeICMP_EQ(Val, CondVal, ElTy).IntVal != 0) {
+ Dest = cast<BasicBlock>(i.getCaseSuccessor());
+ break;
+ }
}
+ if (Case.isSingleNumbersOnly()) {
+ for (unsigned n = 0, en = Case.getNumItems(); n != en; ++n) {
+ // FIXME: Currently work with ConstantInt based numbers.
+ const ConstantInt *CI = Case.getSingleNumber(n).toConstantInt();
+ GenericValue Val = getOperandValue(const_cast<ConstantInt*>(CI), SF);
+ if (executeICMP_EQ(Val, CondVal, ElTy).IntVal != 0) {
+ Dest = cast<BasicBlock>(i.getCaseSuccessor());
+ break;
+ }
+ }
+ } else
+ for (unsigned n = 0, en = Case.getNumItems(); n != en; ++n) {
+ IntegersSubset::Range r = Case.getItem(n);
+ // FIXME: Currently work with ConstantInt based numbers.
+ const ConstantInt *LowCI = r.getLow().toConstantInt();
+ const ConstantInt *HighCI = r.getHigh().toConstantInt();
+ GenericValue Low = getOperandValue(const_cast<ConstantInt*>(LowCI), SF);
+ GenericValue High = getOperandValue(const_cast<ConstantInt*>(HighCI), SF);
+ if (executeICMP_ULE(Low, CondVal, ElTy).IntVal != 0 &&
+ executeICMP_ULE(CondVal, High, ElTy).IntVal != 0) {
+ Dest = cast<BasicBlock>(i.getCaseSuccessor());
+ break;
+ }
+ }
}
if (!Dest) Dest = I.getDefaultDest(); // No cases matched: use default
SwitchToNewBasicBlock(Dest, SF);