From c10fa6c801e48771b5eade50afc2fe6abaf08227 Mon Sep 17 00:00:00 2001 From: Stepan Dyatkovskiy Date: Thu, 8 Mar 2012 07:06:20 +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/llvm/trunk@152297 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/Bitcode/Writer') diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 9376990..c04c009 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1142,9 +1142,10 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Vals.push_back(VE.getTypeID(SI.getCondition()->getType())); Vals.push_back(VE.getValueID(SI.getCondition())); Vals.push_back(VE.getValueID(SI.getDefaultDest())); - for (unsigned i = 0, e = SI.getNumCases(); i != e; ++i) { - Vals.push_back(VE.getValueID(SI.getCaseValue(i))); - Vals.push_back(VE.getValueID(SI.getCaseSuccessor(i))); + for (SwitchInst::CaseIt i = SI.caseBegin(), e = SI.caseEnd(); + i != e; ++i) { + Vals.push_back(VE.getValueID(i.getCaseValue())); + Vals.push_back(VE.getValueID(i.getCaseSuccessor())); } } break; -- cgit v1.1 From 3d3abe0852d5f499bed7ab014519dd582a0a795d Mon Sep 17 00:00:00 2001 From: Stepan Dyatkovskiy Date: Sun, 11 Mar 2012 06:09:17 +0000 Subject: llvm::SwitchInst Renamed methods caseBegin, caseEnd and caseDefault with case_begin, case_end, and case_default. Added some notes relative to case iterators. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152532 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Bitcode/Writer') diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index c04c009..b25d2e9 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1142,7 +1142,7 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Vals.push_back(VE.getTypeID(SI.getCondition()->getType())); Vals.push_back(VE.getValueID(SI.getCondition())); Vals.push_back(VE.getValueID(SI.getDefaultDest())); - for (SwitchInst::CaseIt i = SI.caseBegin(), e = SI.caseEnd(); + for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; ++i) { Vals.push_back(VE.getValueID(i.getCaseValue())); Vals.push_back(VE.getValueID(i.getCaseSuccessor())); -- cgit v1.1