introduce a useful abstraction to find out if a Use is in the call position of an...
authorGabor Greif <ggreif@gmail.com>
Thu, 22 Jan 2009 21:35:57 +0000 (21:35 +0000)
committerGabor Greif <ggreif@gmail.com>
Thu, 22 Jan 2009 21:35:57 +0000 (21:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62788 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 520f8de79fb5b8162eade689af1df64fba4f3d59..dc41590fb8a561b73997d72c89f81732a4b536b8 100644 (file)
@@ -180,6 +180,10 @@ public:
     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 {
index c8f1d920658e201d4db2ac58f579605d03473fb2..ea7d7feb4cd83000e520c06f7f6b93345e7dfdff 100644 (file)
@@ -126,7 +126,8 @@ private:
 
     // 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;
index 69e427e8ad1b4456a8c88d3bd279d0067de0207e..183e1a1e0a4cca6e9bdf7e430d3b3161737008a2 100644 (file)
@@ -135,7 +135,7 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
 
     // 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;
   }
 
index 6ae8276d5247616f97f820b2ee09a2bf35706d32..2dc8558246915385a2298a144b17217b07ef7be0 100644 (file)
@@ -88,11 +88,12 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
   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 @@ bool IPCP::PropagateConstantReturn(Function &F) {
 
     // 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?
index 00556f963352ad602f80750267e84b63b7b2eb76..9f54388aa45e27a0a91662562cd7d8485f3e72b8 100644 (file)
@@ -149,14 +149,11 @@ bool SRETPromotion::isSafeToUpdateAllCallers(Function *F) {
        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;