[llvm-commits] [llvm] r156703 - in /llvm/trunk: include/llvm/Function.h lib/Transforms/IPO/GlobalOpt.cpp lib/VMCore/Function.cpp test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll

Jay Foad jay.foad at gmail.com
Sat May 12 01:30:16 PDT 2012


Author: foad
Date: Sat May 12 03:30:16 2012
New Revision: 156703

URL: http://llvm.org/viewvc/llvm-project?rev=156703&view=rev
Log:
Teach Function::hasAddressTaken that BlockAddress doesn't really take
the address of a function.

Added:
    llvm/trunk/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll
Modified:
    llvm/trunk/include/llvm/Function.h
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/lib/VMCore/Function.cpp

Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=156703&r1=156702&r2=156703&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Sat May 12 03:30:16 2012
@@ -420,8 +420,8 @@
   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;
 

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=156703&r1=156702&r2=156703&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sat May 12 03:30:16 2012
@@ -1870,6 +1870,8 @@
 /// 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 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()));
   }

Modified: llvm/trunk/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=156703&r1=156702&r2=156703&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Function.cpp (original)
+++ llvm/trunk/lib/VMCore/Function.cpp Sat May 12 03:30:16 2012
@@ -400,7 +400,8 @@
 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));

Added: llvm/trunk/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll?rev=156703&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/2012-05-11-blockaddress.ll Sat May 12 03:30:16 2012
@@ -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
+}





More information about the llvm-commits mailing list