diff options
author | Gabor Greif <ggreif@gmail.com> | 2009-01-22 21:35:57 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2009-01-22 21:35:57 +0000 |
commit | f4013373cd9919fb7f4425ad549e4fdf0c875fba (patch) | |
tree | ca91eca70111f94b6a90c0122a063b49db4c37ae | |
parent | 8c5ffd07610476f5e7fd95fca8817e12c76584f4 (diff) | |
download | bcm5719-llvm-f4013373cd9919fb7f4425ad549e4fdf0c875fba.tar.gz bcm5719-llvm-f4013373cd9919fb7f4425ad549e4fdf0c875fba.zip |
introduce a useful abstraction to find out if a Use is in the call position of an instruction
llvm-svn: 62788
-rw-r--r-- | llvm/include/llvm/Support/CallSite.h | 4 | ||||
-rw-r--r-- | llvm/lib/Analysis/IPA/CallGraph.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/IPConstantPropagation.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/StructRetPromotion.cpp | 5 |
5 files changed, 12 insertions, 9 deletions
diff --git a/llvm/include/llvm/Support/CallSite.h b/llvm/include/llvm/Support/CallSite.h index 520f8de79fb..dc41590fb8a 100644 --- a/llvm/include/llvm/Support/CallSite.h +++ b/llvm/include/llvm/Support/CallSite.h @@ -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 { diff --git a/llvm/lib/Analysis/IPA/CallGraph.cpp b/llvm/lib/Analysis/IPA/CallGraph.cpp index c8f1d920658..ea7d7feb4cd 100644 --- a/llvm/lib/Analysis/IPA/CallGraph.cpp +++ b/llvm/lib/Analysis/IPA/CallGraph.cpp @@ -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; diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index 69e427e8ad1..183e1a1e0a4 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -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; } diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp index 6ae8276d524..2dc85582469 100644 --- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -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? diff --git a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp b/llvm/lib/Transforms/IPO/StructRetPromotion.cpp index 00556f96335..9f54388aa45 100644 --- a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/llvm/lib/Transforms/IPO/StructRetPromotion.cpp @@ -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; |