mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-10 16:24:04 +00:00
Implement and use new method Function::hasAddressTaken().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73164 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cb597c9cc4
commit
757068f3ba
@ -395,6 +395,10 @@ public:
|
|||||||
/// including any contained basic blocks.
|
/// including any contained basic blocks.
|
||||||
///
|
///
|
||||||
void dropAllReferences();
|
void dropAllReferences();
|
||||||
|
|
||||||
|
/// hasAddressTaken - returns true if there are any uses of this function
|
||||||
|
/// other than direct calls or invokes to it.
|
||||||
|
bool hasAddressTaken() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline ValueSymbolTable *
|
inline ValueSymbolTable *
|
||||||
|
@ -127,18 +127,9 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
|
|||||||
|
|
||||||
// Second check: make sure that all callers are direct callers. We can't
|
// Second check: make sure that all callers are direct callers. We can't
|
||||||
// transform functions that have indirect callers.
|
// transform functions that have indirect callers.
|
||||||
for (Value::use_iterator UI = F->use_begin(), E = F->use_end();
|
if (F->hasAddressTaken())
|
||||||
UI != E; ++UI) {
|
|
||||||
CallSite CS = CallSite::get(*UI);
|
|
||||||
if (!CS.getInstruction()) // "Taking the address" of the function
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Ensure that this call site is CALLING the function, not passing it as
|
|
||||||
// an argument.
|
|
||||||
if (!CS.isCallee(UI))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to see which arguments are promotable. If an argument is promotable,
|
// Check to see which arguments are promotable. If an argument is promotable,
|
||||||
// add it to ArgsToPromote.
|
// add it to ArgsToPromote.
|
||||||
SmallPtrSet<Argument*, 8> ArgsToPromote;
|
SmallPtrSet<Argument*, 8> ArgsToPromote;
|
||||||
|
@ -175,15 +175,8 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
|
|||||||
if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
|
if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
|
||||||
|
|
||||||
// Ensure that the function is only directly called.
|
// Ensure that the function is only directly called.
|
||||||
for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ++I) {
|
if (Fn.hasAddressTaken())
|
||||||
// If this use is anything other than a call site, give up.
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Okay, we know we can transform this function if safe. Scan its body
|
// Okay, we know we can transform this function if safe. Scan its body
|
||||||
// looking for calls to llvm.vastart.
|
// looking for calls to llvm.vastart.
|
||||||
|
@ -1769,22 +1769,6 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
|
|||||||
return false;
|
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
|
/// ChangeCalleesToFastCall - Walk all of the direct calls of the specified
|
||||||
/// function, changing them to FastCC.
|
/// function, changing them to FastCC.
|
||||||
static void ChangeCalleesToFastCall(Function *F) {
|
static void ChangeCalleesToFastCall(Function *F) {
|
||||||
@ -1830,7 +1814,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
|
|||||||
++NumFnDeleted;
|
++NumFnDeleted;
|
||||||
} else if (F->hasLocalLinkage()) {
|
} else if (F->hasLocalLinkage()) {
|
||||||
if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
|
if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
|
||||||
OnlyCalledDirectly(F)) {
|
!F->hasAddressTaken()) {
|
||||||
// If this function has C calling conventions, is not a varargs
|
// If this function has C calling conventions, is not a varargs
|
||||||
// function, and is only called directly, promote it to use the Fast
|
// function, and is only called directly, promote it to use the Fast
|
||||||
// calling convention.
|
// calling convention.
|
||||||
@ -1841,7 +1825,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (F->getAttributes().hasAttrSomewhere(Attribute::Nest) &&
|
if (F->getAttributes().hasAttrSomewhere(Attribute::Nest) &&
|
||||||
OnlyCalledDirectly(F)) {
|
!F->hasAddressTaken()) {
|
||||||
// The function is not used by a trampoline intrinsic, so it is safe
|
// The function is not used by a trampoline intrinsic, so it is safe
|
||||||
// to remove the 'nest' attribute.
|
// to remove the 'nest' attribute.
|
||||||
RemoveNestAttribute(F);
|
RemoveNestAttribute(F);
|
||||||
|
@ -364,4 +364,15 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
|
|||||||
#include "llvm/Intrinsics.gen"
|
#include "llvm/Intrinsics.gen"
|
||||||
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
||||||
|
|
||||||
|
/// hasAddressTaken - returns true if there are any uses of this function
|
||||||
|
/// other than direct calls or invokes to it.
|
||||||
|
bool Function::hasAddressTaken() const {
|
||||||
|
for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) {
|
||||||
|
if (I.getOperandNo() != 0 ||
|
||||||
|
(!isa<CallInst>(*I) && !isa<InvokeInst>(*I)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// vim: sw=2 ai
|
// vim: sw=2 ai
|
||||||
|
Loading…
Reference in New Issue
Block a user