aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Foad <jay.foad@gmail.com>2012-05-12 08:30:16 +0000
committerJay Foad <jay.foad@gmail.com>2012-05-12 08:30:16 +0000
commitb7454fd9df0b477e3daf2fce6e1d5e1b241562df (patch)
treebb926d40337ccaa32dd4cc1e7318545ec34add08
parent2b38c12643236825a6a49c31ef49da8e62b094c2 (diff)
downloadexternal_llvm-b7454fd9df0b477e3daf2fce6e1d5e1b241562df.zip
external_llvm-b7454fd9df0b477e3daf2fce6e1d5e1b241562df.tar.gz
external_llvm-b7454fd9df0b477e3daf2fce6e1d5e1b241562df.tar.bz2
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
-rw-r--r--include/llvm/Function.h4
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp4
-rw-r--r--lib/VMCore/Function.cpp3
-rw-r--r--test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll16
4 files changed, 24 insertions, 3 deletions
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index e17cd87..fdd90d1 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 1522aa4..d316d52 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<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()));
}
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index af6344e..9b098a2 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -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));
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 0000000..0c58c1a
--- /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
+}