diff options
| author | Jay Foad <jay.foad@gmail.com> | 2009-06-10 08:41:11 +0000 | 
|---|---|---|
| committer | Jay Foad <jay.foad@gmail.com> | 2009-06-10 08:41:11 +0000 | 
| commit | 557169d923e6155feafc984bbea05abb04e8129e (patch) | |
| tree | 9261d65ee4739b858aa87c83d41b506a2a19911b /llvm/lib/Transforms | |
| parent | 76d864c7e756008490d11473773ea04a48186626 (diff) | |
| download | bcm5719-llvm-557169d923e6155feafc984bbea05abb04e8129e.tar.gz bcm5719-llvm-557169d923e6155feafc984bbea05abb04e8129e.zip | |
Implement and use new method Function::hasAddressTaken().
llvm-svn: 73164
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 13 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 20 | 
3 files changed, 6 insertions, 38 deletions
| diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index 2bb6428060c..a6126340161 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -127,17 +127,8 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {    // Second check: make sure that all callers are direct callers.  We can't    // transform functions that have indirect callers. -  for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); -       UI != E; ++UI) { -    CallSite CS = CallSite::get(*UI); -    if (!CS.getInstruction())       // "Taking the address" of the function -      return false; - -    // Ensure that this call site is CALLING the function, not passing it as -    // an argument. -    if (!CS.isCallee(UI)) -      return false; -  } +  if (F->hasAddressTaken()) +    return false;    // Check to see which arguments are promotable.  If an argument is promotable,    // add it to ArgsToPromote. diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp index 666db7e8d74..e480dadca89 100644 --- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -175,15 +175,8 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {    if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;    // Ensure that the function is only directly called. -  for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ++I) { -    // If this use is anything other than a call site, give up. -    CallSite CS = CallSite::get(*I); -    Instruction *TheCall = CS.getInstruction(); -    if (!TheCall) return false;   // Not a direct call site? - -    // The addr of this function is passed to the call. -    if (!CS.isCallee(I)) return false; -  } +  if (Fn.hasAddressTaken()) +    return false;    // Okay, we know we can transform this function if safe.  Scan its body    // looking for calls to llvm.vastart. diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index f881e089c26..9a1b2941907 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1769,22 +1769,6 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,    return false;  } -/// OnlyCalledDirectly - Return true if the specified function is only called -/// directly.  In other words, its address is never taken. -static bool OnlyCalledDirectly(Function *F) { -  for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E;++UI){ -    Instruction *User = dyn_cast<Instruction>(*UI); -    if (!User) return false; -    if (!isa<CallInst>(User) && !isa<InvokeInst>(User)) return false; - -    // See if the function address is passed as an argument. -    for (User::op_iterator i = User->op_begin() + 1, e = User->op_end(); -         i != e; ++i) -      if (*i == F) return false; -  } -  return true; -} -  /// ChangeCalleesToFastCall - Walk all of the direct calls of the specified  /// function, changing them to FastCC.  static void ChangeCalleesToFastCall(Function *F) { @@ -1830,7 +1814,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {        ++NumFnDeleted;      } else if (F->hasLocalLinkage()) {        if (F->getCallingConv() == CallingConv::C && !F->isVarArg() && -          OnlyCalledDirectly(F)) { +          !F->hasAddressTaken()) {          // If this function has C calling conventions, is not a varargs          // function, and is only called directly, promote it to use the Fast          // calling convention. @@ -1841,7 +1825,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {        }        if (F->getAttributes().hasAttrSomewhere(Attribute::Nest) && -          OnlyCalledDirectly(F)) { +          !F->hasAddressTaken()) {          // The function is not used by a trampoline intrinsic, so it is safe          // to remove the 'nest' attribute.          RemoveNestAttribute(F); | 

