]> granicus.if.org Git - clang/commitdiff
Make -fno-inline attach NoInline attribute to all functions that are not
authorRoman Divacky <rdivacky@freebsd.org>
Wed, 15 Jan 2014 19:07:16 +0000 (19:07 +0000)
committerRoman Divacky <rdivacky@freebsd.org>
Wed, 15 Jan 2014 19:07:16 +0000 (19:07 +0000)
marked as AlwaysInline or ForceInline.

This moves us to what gcc does with -fno-inline. The attribute approach
was discussed to be better than switching to InlineAlways inliner in presence
of LTO.

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

lib/CodeGen/CodeGenFunction.cpp
test/CodeGen/noinline.c

index 108c14778198ed3536af40103b48dba61bcfee4e..cffbca37bddccfc0309056fe9bd8e8e59b2a851c 100644 (file)
@@ -509,15 +509,20 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
   }
 
   // Pass inline keyword to optimizer if it appears explicitly on any
-  // declaration.
-  if (!CGM.getCodeGenOpts().NoInline)
-    if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
+  // declaration. Also, in the case of -fno-inline attach NoInline
+  // attribute to all function that are not marked AlwaysInline or ForceInline.
+  if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
+    if (!CGM.getCodeGenOpts().NoInline) {
       for (FunctionDecl::redecl_iterator RI = FD->redecls_begin(),
              RE = FD->redecls_end(); RI != RE; ++RI)
         if (RI->isInlineSpecified()) {
           Fn->addFnAttr(llvm::Attribute::InlineHint);
           break;
         }
+    } else if (!FD->hasAttr<AlwaysInlineAttr>() &&
+               !FD->hasAttr<ForceInlineAttr>())
+      Fn->addFnAttr(llvm::Attribute::NoInline);
+  }
 
   if (getLangOpts().OpenCL) {
     // Add metadata for a kernel function.
index e64a1a539f4b4d3289d65b7571c0ba396a49b575..bd5a9d8c35ff5d03ece9b57e73f8558aa02392e9 100644 (file)
@@ -5,10 +5,17 @@
 
 inline int dont_inline_me(int a, int b) { return(a+b); }
 
+inline __attribute__ ((__always_inline__)) int inline_me(int a, int b) { return(a*b); }
+
 volatile int *pa = (int*) 0x1000;
 void foo() {
 // NOINLINE: @foo
 // NOINLINE: dont_inline_me
 // NOINLINE-NOT: inlinehint
     pa[0] = dont_inline_me(pa[1],pa[2]);       
+// NOINLINE-NOT: inline_me
+    pa[3] = inline_me(pa[4],pa[5]);
 }
+
+// NOINLINE: Function Attrs: noinline
+// NOINLINE: @dont_inline_me