diff options
author | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-02-01 07:56:09 +0000 |
---|---|---|
committer | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-02-01 07:56:09 +0000 |
commit | 5fa73a2145c1150c826e8d8de65ff3c7b3da962c (patch) | |
tree | ea4a01a271274dc92e2a2c18779223f30447ced6 /lib/Module/LowerSwitch.cpp | |
parent | 1715ee37118cdf8785a1dd70d812b6a88ad623e7 (diff) | |
download | klee-5fa73a2145c1150c826e8d8de65ff3c7b3da962c.tar.gz |
Compatability fix for SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want. What was done: 1. Changed semantics of index inside the getCaseValue method: getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous. 2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned. 3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment. 4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst. 4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor. 4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor. Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@149484 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Module/LowerSwitch.cpp')
-rw-r--r-- | lib/Module/LowerSwitch.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp index 6667a006..852603b8 100644 --- a/lib/Module/LowerSwitch.cpp +++ b/lib/Module/LowerSwitch.cpp @@ -96,7 +96,7 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) { BasicBlock *origBlock = SI->getParent(); BasicBlock *defaultBlock = SI->getDefaultDest(); Function *F = origBlock->getParent(); - Value *switchValue = SI->getOperand(0); + Value *switchValue = SI->getCondition(); // Create a new, empty default block so that the new hierarchy of // if-then statements go to this and the PHI nodes are happy. @@ -115,9 +115,9 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) { } CaseVector cases; - for (unsigned i = 1; i < SI->getNumSuccessors(); ++i) - cases.push_back(SwitchCase(SI->getSuccessorValue(i), - SI->getSuccessor(i))); + for (unsigned i = 0; i < SI->getNumCases(); ++i) + cases.push_back(SwitchCase(SI->getCaseValue(i), + SI->getCaseSuccessor(i))); // reverse cases, as switchConvert constructs a chain of // basic blocks by appending to the front. if we reverse, |