diff options
author | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-02-01 07:49:51 +0000 |
---|---|---|
committer | Stepan Dyatkovskiy <stpworld@narod.ru> | 2012-02-01 07:49:51 +0000 |
commit | 24473120a253a05f3601cd3373403b47e6d03d41 (patch) | |
tree | bc2bd5e85b17ffe6e39259aef743bad59f6c0508 /tools/llvm-diff | |
parent | 11e43291540db9d885b736cbd652558faab80955 (diff) |
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/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-diff')
-rw-r--r-- | tools/llvm-diff/DifferenceEngine.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/llvm-diff/DifferenceEngine.cpp b/tools/llvm-diff/DifferenceEngine.cpp index e827b23a73..8113fd4c66 100644 --- a/tools/llvm-diff/DifferenceEngine.cpp +++ b/tools/llvm-diff/DifferenceEngine.cpp @@ -319,13 +319,13 @@ class FunctionDifferenceEngine { bool Difference = false; DenseMap<ConstantInt*,BasicBlock*> LCases; - for (unsigned I = 1, E = LI->getNumCases(); I != E; ++I) - LCases[LI->getCaseValue(I)] = LI->getSuccessor(I); - for (unsigned I = 1, E = RI->getNumCases(); I != E; ++I) { + for (unsigned I = 0, E = LI->getNumCases(); I != E; ++I) + LCases[LI->getCaseValue(I)] = LI->getCaseSuccessor(I); + for (unsigned I = 0, E = RI->getNumCases(); I != E; ++I) { ConstantInt *CaseValue = RI->getCaseValue(I); BasicBlock *LCase = LCases[CaseValue]; if (LCase) { - if (TryUnify) tryUnify(LCase, RI->getSuccessor(I)); + if (TryUnify) tryUnify(LCase, RI->getCaseSuccessor(I)); LCases.erase(CaseValue); } else if (Complain || !Difference) { if (Complain) |