Teach Function::hasAddressTaken that BlockAddress doesn't really take

the address of a function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad 2012-05-12 08:30:16 +00:00
parent 2b38c12643
commit b7454fd9df
4 changed files with 24 additions and 3 deletions

View File

@ -420,8 +420,8 @@ public:
void dropAllReferences();
/// hasAddressTaken - returns true if there are any uses of this function
/// other than direct calls or invokes to it. Optionally passes back the
/// offending user for diagnostic purposes.
/// other than direct calls or invokes to it, or blockaddress expressions.
/// Optionally passes back an offending user for diagnostic purposes.
///
bool hasAddressTaken(const User** = 0) const;

View File

@ -1870,6 +1870,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
/// function, changing them to FastCC.
static void ChangeCalleesToFastCall(Function *F) {
for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E;++UI){
if (isa<BlockAddress>(*UI))
continue;
CallSite User(cast<Instruction>(*UI));
User.setCallingConv(CallingConv::Fast);
}
@ -1890,6 +1892,8 @@ static AttrListPtr StripNest(const AttrListPtr &Attrs) {
static void RemoveNestAttribute(Function *F) {
F->setAttributes(StripNest(F->getAttributes()));
for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E;++UI){
if (isa<BlockAddress>(*UI))
continue;
CallSite User(cast<Instruction>(*UI));
User.setAttributes(StripNest(User.getAttributes()));
}

View File

@ -400,7 +400,8 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) {
bool Function::hasAddressTaken(const User* *PutOffender) const {
for (Value::const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) {
const User *U = *I;
// FIXME: Check for blockaddress, which does not take the address.
if (isa<BlockAddress>(U))
continue;
if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
return PutOffender ? (*PutOffender = U, true) : true;
ImmutableCallSite CS(cast<Instruction>(U));

View File

@ -0,0 +1,16 @@
; RUN: opt < %s -globalopt -S | FileCheck %s
; Check that the mere presence of a blockaddress doesn't prevent -globalopt
; from promoting @f to fastcc.
; CHECK: define{{.*}}fastcc{{.*}}@f
define internal i8* @f() {
ret i8* blockaddress(@f, %L1)
L1:
ret i8* null
}
define void @g() {
; CHECK: call{{.*}}fastcc{{.*}}@f
%p = call i8* @f()
ret void
}