[PATCH] D34133: Cold attribute on function decls are lost. Fix the problem

David Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 19:23:13 PDT 2017


davidxl created this revision.
Herald added a subscriber: sanjoy.

LLVM static branch prediction depends on cold attribute to annotate branch probability. This is  currently not possible for cold function decls as the information is dropped by FE.

This patch attaches the attributes to the callsite as noReturn. Another way is to pass the attribute to the function decl.

Also need suggestions on how to add a clang test case.


https://reviews.llvm.org/D34133

Files:
  lib/CodeGen/CGCall.cpp


Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1795,6 +1795,8 @@
       FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
     if (TargetDecl->hasAttr<NoReturnAttr>())
       FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
+    if (TargetDecl->hasAttr<ColdAttr>())
+      FuncAttrs.addAttribute(llvm::Attribute::Cold);
     if (TargetDecl->hasAttr<NoDuplicateAttr>())
       FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
     if (TargetDecl->hasAttr<ConvergentAttr>())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34133.102286.patch
Type: text/x-patch
Size: 590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170613/cf9a8537/attachment-0001.bin>


More information about the cfe-commits mailing list