r182666 - [PATCH] Generate cold attribute for functions marked __atribute__((cold))

Diego Novillo dnovillo at google.com
Fri May 24 13:18:15 PDT 2013


Author: dnovillo
Date: Fri May 24 15:18:15 2013
New Revision: 182666

URL: http://llvm.org/viewvc/llvm-project?rev=182666&view=rev
Log:
[PATCH] Generate cold attribute for functions marked __atribute__((cold))

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.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/attr-coldhot.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=182666&r1=182665&r2=182666&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri May 24 15:18:15 2013
@@ -620,9 +620,10 @@ void CodeGenModule::SetLLVMFunctionAttri
     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);

Modified: cfe/trunk/test/CodeGen/attr-coldhot.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-coldhot.c?rev=182666&r1=182665&r2=182666&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-coldhot.c (original)
+++ cfe/trunk/test/CodeGen/attr-coldhot.c Fri May 24 15:18:15 2013
@@ -8,4 +8,4 @@ int test1() __attribute__((__cold__)) {
 // CHECK: ret
 }
 
-// CHECK: attributes [[ATTR]] = { {{.*}}optsize{{.*}} }
+// CHECK: attributes [[ATTR]] = { {{.*}}cold{{.*}}optsize{{.*}} }





More information about the cfe-commits mailing list