From 4a6357101c5d7ea3511de73e4aac374c695f82e1 Mon Sep 17 00:00:00 2001 From: Stepan Dyatkovskiy Date: Thu, 8 Mar 2012 07:07:02 +0000 Subject: Taken into account Duncan's comments for r149481 dated by 2nd Feb 2012: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120130/136146.html Implemented CaseIterator and it solves almost all described issues: we don't need to mix operand/case/successor indexing anymore. Base iterator class is implemented as a template since it may be initialized either from "const SwitchInst*" or from "SwitchInst*". ConstCaseIt is just a read-only iterator. CaseIt is read-write iterator; it allows to change case successor and case value. Usage of iterator allows totally remove resolveXXXX methods. All indexing convertions done automatically inside the iterator's getters. Main way of iterator usage looks like this: SwitchInst *SI = ... // intialize it somehow for (SwitchInst::CaseIt i = SI->caseBegin(), e = SI->caseEnd(); i != e; ++i) { BasicBlock *BB = i.getCaseSuccessor(); ConstantInt *V = i.getCaseValue(); // Do something. } If you want to convert case number to TerminatorInst successor index, just use getSuccessorIndex iterator's method. If you want initialize iterator from TerminatorInst successor index, use CaseIt::fromSuccessorIndex(...) method. There are also related changes in llvm-clients: klee and clang. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@152299 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Module/LowerSwitch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/Module') diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp index fb37da86..9ccf4804 100644 --- a/lib/Module/LowerSwitch.cpp +++ b/lib/Module/LowerSwitch.cpp @@ -117,9 +117,9 @@ void LowerSwitchPass::processSwitchInst(SwitchInst *SI) { CaseVector cases; #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1) - for (unsigned i = 0; i < SI->getNumCases(); ++i) - cases.push_back(SwitchCase(SI->getCaseValue(i), - SI->getCaseSuccessor(i))); + for (SwitchInst::CaseIt i = SI->caseBegin(), e = SI->caseEnd(); i != e; ++i) + cases.push_back(SwitchCase(i.getCaseValue(), + i.getCaseSuccessor())); #else for (unsigned i = 1; i < SI->getNumSuccessors(); ++i) cases.push_back(SwitchCase(SI->getSuccessorValue(i), -- cgit 1.4.1