[llvm-commits] [llvm] r62788 - in /llvm/trunk: include/llvm/Support/CallSite.h lib/Analysis/IPA/CallGraph.cpp lib/Transforms/IPO/ArgumentPromotion.cpp lib/Transforms/IPO/IPConstantPropagation.cpp lib/Transforms/IPO/StructRetPromotion.cpp

Gabor Greif ggreif at gmail.com
Thu Jan 22 13:35:57 PST 2009


Author: ggreif
Date: Thu Jan 22 15:35:57 2009
New Revision: 62788

URL: http://llvm.org/viewvc/llvm-project?rev=62788&view=rev
Log:
introduce a useful abstraction to find out if a Use is in the call position of an instruction

Modified:
    llvm/trunk/include/llvm/Support/CallSite.h
    llvm/trunk/lib/Analysis/IPA/CallGraph.cpp
    llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
    llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
    llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp

Modified: llvm/trunk/include/llvm/Support/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CallSite.h?rev=62788&r1=62787&r2=62788&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/CallSite.h (original)
+++ llvm/trunk/include/llvm/Support/CallSite.h Thu Jan 22 15:35:57 2009
@@ -180,6 +180,10 @@
     return getInstruction() < CS.getInstruction();
   }
 
+  bool isCallee(Value::use_iterator UI) const {
+    return getInstruction()->op_begin() == &UI.getUse();
+  }
+
 private:
   /// Returns the operand number of the first argument
   unsigned getArgumentOffset() const {

Modified: llvm/trunk/lib/Analysis/IPA/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/CallGraph.cpp?rev=62788&r1=62787&r2=62788&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/IPA/CallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/CallGraph.cpp Thu Jan 22 15:35:57 2009
@@ -126,7 +126,8 @@
 
     // Loop over all of the users of the function, looking for non-call uses.
     for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ++I)
-      if ((!isa<CallInst>(*I) && !isa<InvokeInst>(*I)) || I.getOperandNo()) {
+      if ((!isa<CallInst>(I) && !isa<InvokeInst>(I))
+          || !CallSite(cast<Instruction>(I)).isCallee(I)) {
         // Not a call, or being used as a parameter rather than as the callee.
         ExternalCallingNode->addCalledFunction(CallSite(), Node);
         break;

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

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp Thu Jan 22 15:35:57 2009
@@ -135,7 +135,7 @@
 
     // Ensure that this call site is CALLING the function, not passing it as
     // an argument.
-    if (UI.getOperandNo() != 0)
+    if (!CS.isCallee(UI))
       return false;
   }
 

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

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Thu Jan 22 15:35:57 2009
@@ -88,11 +88,12 @@
   for (Value::use_iterator UI = F.use_begin(), E = F.use_end(); UI != E; ++UI) {
     // Used by a non-instruction, or not the callee of a function, do not
     // transform.
-    if (UI.getOperandNo() != 0 ||
-        (!isa<CallInst>(*UI) && !isa<InvokeInst>(*UI)))
+    if (!isa<CallInst>(*UI) && !isa<InvokeInst>(*UI))
       return false;
     
     CallSite CS = CallSite::get(cast<Instruction>(*UI));
+    if (!CS.isCallee(UI))
+      return false;
 
     // Check out all of the potentially constant arguments.  Note that we don't
     // inspect varargs here.
@@ -219,7 +220,7 @@
 
     // Not a call instruction or a call instruction that's not calling F
     // directly?
-    if (!Call || UI.getOperandNo() != 0)
+    if (!Call || !CS.isCallee(UI))
       continue;
     
     // Call result not used?

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

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StructRetPromotion.cpp Thu Jan 22 15:35:57 2009
@@ -149,14 +149,11 @@
        FnUseI != FnUseE; ++FnUseI) {
     // The function is passed in as an argument to (possibly) another function,
     // we can't change it!
-    if (FnUseI.getOperandNo() != 0)
-      return false;
-
     CallSite CS = CallSite::get(*FnUseI);
     Instruction *Call = CS.getInstruction();
     // The function is used by something else than a call or invoke instruction,
     // we can't change it!
-    if (!Call)
+    if (!Call || !CS.isCallee(FnUseI))
       return false;
     CallSite::arg_iterator AI = CS.arg_begin();
     Value *FirstArg = *AI;





More information about the llvm-commits mailing list