From: Jay Foad Date: Sat, 12 May 2012 08:30:16 +0000 (+0000) Subject: Teach Function::hasAddressTaken that BlockAddress doesn't really take X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b7454fd9df0b477e3daf2fce6e1d5e1b241562df;p=oota-llvm.git 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 --- diff --git a/include/llvm/Function.h b/include/llvm/Function.h index e17cd87fe34..fdd90d1d8fa 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -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; diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 1522aa408b6..d316d526785 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -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(*UI)) + continue; CallSite User(cast(*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(*UI)) + continue; CallSite User(cast(*UI)); User.setAttributes(StripNest(User.getAttributes())); } diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index af6344ef616..9b098a25250 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -400,7 +400,8 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef 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(U)) + continue; if (!isa(U) && !isa(U)) return PutOffender ? (*PutOffender = U, true) : true; ImmutableCallSite CS(cast(U)); diff --git a/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll b/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll new file mode 100644 index 00000000000..0c58c1a9d9c --- /dev/null +++ b/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll @@ -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 +}