[llvm-commits] [llvm] r52489 - /llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp

Matthijs Kooijman matthijs at stdin.nl
Thu Jun 19 01:53:24 PDT 2008


Author: matthijs
Date: Thu Jun 19 03:53:24 2008
New Revision: 52489

URL: http://llvm.org/viewvc/llvm-project?rev=52489&view=rev
Log:
Use a CallSite to find the nth argument of a call/invoke instruction instead of
using getOperand() directly. This makes things work with invoke instructions as
well.

Modified:
    llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp

Modified: llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp?rev=52489&r1=52488&r2=52489&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Thu Jun 19 03:53:24 2008
@@ -218,13 +218,15 @@
   // constant.
   bool MadeChange = false;
   for (Value::use_iterator UI = F.use_begin(), E = F.use_end(); UI != E; ++UI) {
-    // Make sure this is an invoke or call and that the use is for the callee.
-    if (!(isa<InvokeInst>(*UI) || isa<CallInst>(*UI)) ||
-        UI.getOperandNo() != 0) {
+    CallSite CS = CallSite::get(*UI);
+    Instruction* Call = CS.getInstruction();
+
+    // Not a call instruction or a call instruction that's not calling F
+    // directly?
+    if (!Call || UI.getOperandNo() != 0)
       continue;
-    }
     
-    Instruction *Call = cast<Instruction>(*UI);
+    // Call result not used?
     if (Call->use_empty())
       continue;
 
@@ -234,9 +236,8 @@
       Value* New = RetVals[0];
       if (Argument *A = dyn_cast<Argument>(New))
         // Was an argument returned? Then find the corresponding argument in
-        // the call instruction and use that. Add 1 to the argument number
-        // to skip the first argument (the function itself).
-        New = Call->getOperand(A->getArgNo() + 1);
+        // the call instruction and use that.
+        New = CS.getArgument(A->getArgNo());
       Call->replaceAllUsesWith(New);
       continue;
     }
@@ -267,9 +268,8 @@
         if (New) {
           if (Argument *A = dyn_cast<Argument>(New))
             // Was an argument returned? Then find the corresponding argument in
-            // the call instruction and use that. Add 1 to the argument number
-            // to skip the first argument (the function itself).
-            New = Call->getOperand(A->getArgNo() + 1);
+            // the call instruction and use that.
+            New = CS.getArgument(A->getArgNo());
           Ins->replaceAllUsesWith(New);
           Ins->eraseFromParent();
         }





More information about the llvm-commits mailing list