]> granicus.if.org Git - clang/commitdiff
[PATCH] Generate cold attribute for functions marked __atribute__((cold))
authorDiego Novillo <dnovillo@google.com>
Fri, 24 May 2013 20:18:15 +0000 (20:18 +0000)
committerDiego Novillo <dnovillo@google.com>
Fri, 24 May 2013 20:18:15 +0000 (20:18 +0000)
This removes a FIXME in CodeGenModule::SetLLVMFunctionAttributesForDefinition.
When a function is declared cold we can now generate the IR attribute in
addition to marking the function to be optimized for size.

I tried adding a separate CHECK in the existing test, but it was
failing.  I suppose CHECK matches one line exactly once?  This would be
a problem if the attributes are listed in a different order, though they
seem to be sorted.

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

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/attr-coldhot.c

index e65128813e1762e16c56fcbcb2929e4fa8b5048e..7ad08e0e0a72a6d20a53df7cdf64fee739369f9d 100644 (file)
@@ -620,9 +620,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
     B.addAttribute(llvm::Attribute::AlwaysInline);
   }
 
-  // FIXME: Communicate hot and cold attributes to LLVM more directly.
-  if (D->hasAttr<ColdAttr>())
+  if (D->hasAttr<ColdAttr>()) {
     B.addAttribute(llvm::Attribute::OptimizeForSize);
+    B.addAttribute(llvm::Attribute::Cold);
+  }
 
   if (D->hasAttr<MinSizeAttr>())
     B.addAttribute(llvm::Attribute::MinSize);
index a27711970842aea6fcaae2237e89f5d8fe143c59..ec54edde9d777798db9239879454570431f6e7d0 100644 (file)
@@ -8,4 +8,4 @@ int test1() __attribute__((__cold__)) {
 // CHECK: ret
 }
 
-// CHECK: attributes [[ATTR]] = { {{.*}}optsize{{.*}} }
+// CHECK: attributes [[ATTR]] = { {{.*}}cold{{.*}}optsize{{.*}} }