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

Richard Smith richard at metafoo.co.uk
Fri May 24 12:57:51 PDT 2013


On Fri, May 24, 2013 at 12:20 PM, Diego Novillo <dnovillo at google.com> wrote:

> 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.
>
> OK to commit?


LGTM

Thanks.  Diego.
>
> ---
>  lib/CodeGen/CodeGenModule.cpp | 5 +++--
>  test/CodeGen/attr-coldhot.c   | 2 +-
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
> index e651288..7ad08e0 100644
> --- a/lib/CodeGen/CodeGenModule.cpp
> +++ b/lib/CodeGen/CodeGenModule.cpp
> @@ -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);
> diff --git a/test/CodeGen/attr-coldhot.c b/test/CodeGen/attr-coldhot.c
> index a277119..ec54edd 100644
> --- a/test/CodeGen/attr-coldhot.c
> +++ b/test/CodeGen/attr-coldhot.c
> @@ -8,4 +8,4 @@ int test1() __attribute__((__cold__)) {
>  // CHECK: ret
>  }
>
> -// CHECK: attributes [[ATTR]] = { {{.*}}optsize{{.*}} }
> +// CHECK: attributes [[ATTR]] = { {{.*}}cold{{.*}}optsize{{.*}} }
> --
> 1.8.2.1
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130524/75eab8c9/attachment.html>


More information about the cfe-commits mailing list