add some accessors to callsite/callinst/invokeinst to check
authorChris Lattner <sabre@nondot.org>
Tue, 23 Mar 2010 22:59:07 +0000 (22:59 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 23 Mar 2010 22:59:07 +0000 (22:59 +0000)
for the noinline attribute, and make the inliner refuse to
inline a call site when the call site is marked noinline even
if the callee isn't.  This fixes PR6682.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99341 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
include/llvm/Support/CallSite.h
lib/Transforms/Utils/InlineFunction.cpp
lib/VMCore/Instructions.cpp
test/Transforms/Inline/noinline.ll [new file with mode: 0644]

index b1f1996045898a355f5d06a6634f6f3a20d70b61..b382f0c9122b5d726ffad9a97c3dfeacdad14895 100644 (file)
@@ -971,6 +971,13 @@ public:
   unsigned getParamAlignment(unsigned i) const {
     return AttributeList.getParamAlignment(i);
   }
+  
+  /// @brief Return true if the call should not be inlined.
+  bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
+  void setIsNoInline(bool Value) {
+    if (Value) addAttribute(~0, Attribute::NoInline);
+    else removeAttribute(~0, Attribute::NoInline);
+  }
 
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const {
@@ -2456,6 +2463,13 @@ public:
     return AttributeList.getParamAlignment(i);
   }
 
+  /// @brief Return true if the call should not be inlined.
+  bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
+  void setIsNoInline(bool Value) {
+    if (Value) addAttribute(~0, Attribute::NoInline);
+    else removeAttribute(~0, Attribute::NoInline);
+  }
+  
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const {
     return paramHasAttr(~0, Attribute::ReadNone);
index 285b558afccbae1f4acd669e1250cf2dfd803b63..23d24e7c5e0e349b783a7e31e70ab1121868ab9f 100644 (file)
@@ -76,6 +76,10 @@ public:
   /// @brief Extract the alignment for a call or parameter (0=unknown).
   uint16_t getParamAlignment(uint16_t i) const;
 
+  /// @brief Return true if the call should not be inlined.
+  bool isNoInline() const;
+  void setIsNoInline(bool Value = true);
+  
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const;
   void setDoesNotAccessMemory(bool doesNotAccessMemory = true);
index 17f8827fd5c088795bcd93cac1ee36a2758756cd..599fe33aa03181fe64aa488df5037b1b48f90a8d 100644 (file)
@@ -229,7 +229,9 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD,
   const Function *CalledFunc = CS.getCalledFunction();
   if (CalledFunc == 0 ||          // Can't inline external function or indirect
       CalledFunc->isDeclaration() || // call, or call to a vararg function!
-      CalledFunc->getFunctionType()->isVarArg()) return false;
+      CalledFunc->getFunctionType()->isVarArg() ||
+      CS.isNoInline())            // Call site is marked noinline.
+    return false;
 
 
   // If the call to the callee is not a tail call, we must clear the 'tail'
index ba749bc1514dce2b0152fb5c1447fcc83b8f0b14..b6d9ec2b98c1ce2d2c87012c97f8e8d22a7dc835 100644 (file)
@@ -31,13 +31,13 @@ using namespace llvm;
 //===----------------------------------------------------------------------===//
 
 #define CALLSITE_DELEGATE_GETTER(METHOD) \
-  Instruction *II(getInstruction());     \
+  Instruction *II = getInstruction();    \
   return isCall()                        \
     ? cast<CallInst>(II)->METHOD         \
     : cast<InvokeInst>(II)->METHOD
 
 #define CALLSITE_DELEGATE_SETTER(METHOD) \
-  Instruction *II(getInstruction());     \
+  Instruction *II = getInstruction();    \
   if (isCall())                          \
     cast<CallInst>(II)->METHOD;          \
   else                                   \
@@ -66,6 +66,17 @@ bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
 uint16_t CallSite::getParamAlignment(uint16_t i) const {
   CALLSITE_DELEGATE_GETTER(getParamAlignment(i));
 }
+
+/// @brief Return true if the call should not be inlined.
+bool CallSite::isNoInline() const {
+  CALLSITE_DELEGATE_GETTER(isNoInline());
+}
+
+void CallSite::setIsNoInline(bool Value) {
+  CALLSITE_DELEGATE_GETTER(setIsNoInline(Value));
+}
+
+
 bool CallSite::doesNotAccessMemory() const {
   CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
 }
diff --git a/test/Transforms/Inline/noinline.ll b/test/Transforms/Inline/noinline.ll
new file mode 100644 (file)
index 0000000..dc3f6e0
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: opt %s -inline -S | FileCheck %s
+; PR6682
+declare void @foo() nounwind
+
+define void @bar() nounwind {
+entry:
+    tail call void @foo() nounwind
+    ret void
+}
+
+define void @bazz() nounwind {
+entry:
+    tail call void @bar() nounwind noinline
+    ret void
+}
+
+; CHECK: define void @bazz()
+; CHECK: call void @bar()