[llvm-commits] [llvm] r124659 - in /llvm/trunk: include/llvm/Instructions.h lib/VMCore/Instructions.cpp
Jay Foad
jay.foad at gmail.com
Tue Feb 1 01:22:34 PST 2011
Author: foad
Date: Tue Feb 1 03:22:34 2011
New Revision: 124659
URL: http://llvm.org/viewvc/llvm-project?rev=124659&view=rev
Log:
Make SwitchInst::removeCase() more efficient.
Modified:
llvm/trunk/include/llvm/Instructions.h
llvm/trunk/lib/VMCore/Instructions.cpp
Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=124659&r1=124658&r2=124659&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Tue Feb 1 03:22:34 2011
@@ -2247,7 +2247,8 @@
/// removeCase - This method removes the specified successor from the switch
/// instruction. Note that this cannot be used to remove the default
- /// destination (successor #0).
+ /// destination (successor #0). Also note that this operation may reorder the
+ /// remaining cases at index idx and above.
///
void removeCase(unsigned idx);
Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=124659&r1=124658&r2=124659&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Tue Feb 1 03:22:34 2011
@@ -3009,14 +3009,10 @@
unsigned NumOps = getNumOperands();
Use *OL = OperandList;
- // Move everything after this operand down.
- //
- // FIXME: we could just swap with the end of the list, then erase. However,
- // client might not expect this to happen. The code as it is thrashes the
- // use/def lists, which is kinda lame.
- for (unsigned i = (idx+1)*2; i != NumOps; i += 2) {
- OL[i-2] = OL[i];
- OL[i-2+1] = OL[i+1];
+ // Overwrite this case with the end of the list.
+ if ((idx + 1) * 2 != NumOps) {
+ OL[idx * 2] = OL[NumOps - 2];
+ OL[idx * 2 + 1] = OL[NumOps - 1];
}
// Nuke the last value.
More information about the llvm-commits
mailing list