Reapply r99451 with a fix to move the NoInline check to the cost functions
authorEric Christopher <echristo@apple.com>
Thu, 25 Mar 2010 04:49:10 +0000 (04:49 +0000)
committerEric Christopher <echristo@apple.com>
Thu, 25 Mar 2010 04:49:10 +0000 (04:49 +0000)
instead of InlineFunction.

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

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

index 2fe1abba135313bdb9c53260f6d3be28857e0a24..413a595ab38af64d902a9a0fd91b55ad012ca1f6 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 4c6689fffd01bf3c6bc7ccf7233a98f4a33f089f..9d9a30e6ad2f0305762c65569d111c5ad2125b76 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 5b8b53495c40f3a3dd82a8fe813c1d984d98aa61..c599e907eb60efb142ff43c46f5f29adad42d65b 100644 (file)
@@ -255,9 +255,11 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
   Function *Caller = TheCall->getParent()->getParent();
 
   // Don't inline functions which can be redefined at link-time to mean
-  // something else.  Don't inline functions marked noinline.
+  // something else.  Don't inline functions marked noinline or call sites
+  // marked noinline.
   if (Callee->mayBeOverridden() ||
-      Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee))
+      Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee) ||
+      CS.isNoInline())
     return llvm::InlineCost::getNever();
 
   // InlineCost - This value measures how good of an inline candidate this call
index 171e0211ddb48d58c3371f08157077b62b4805c1..11e218c49ec8323782c771c3fc0d02680f9af1c9 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()