From 9046768d2c7e21a7933c8158664550a866fcdd74 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Fri, 26 Oct 2012 00:29:48 +0000 Subject: [PATCH] Oz optimization level sets ForceSizeOpt attribute for each function git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166744 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 2 ++ test/CodeGen/attr-forcesizeopt.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/CodeGen/attr-forcesizeopt.c diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index b356e640a1..f09332efc6 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -968,6 +968,8 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, if (CodeGenOpts.OptimizeSize) FuncAttrs.addAttribute(llvm::Attributes::OptimizeForSize); + if (CodeGenOpts.OptimizeSize == 2) + FuncAttrs.addAttribute(llvm::Attributes::ForceSizeOpt); if (CodeGenOpts.DisableRedZone) FuncAttrs.addAttribute(llvm::Attributes::NoRedZone); if (CodeGenOpts.NoImplicitFloat) diff --git a/test/CodeGen/attr-forcesizeopt.c b/test/CodeGen/attr-forcesizeopt.c new file mode 100644 index 0000000000..c4e6c4ad81 --- /dev/null +++ b/test/CodeGen/attr-forcesizeopt.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -Oz -emit-llvm %s -o - | FileCheck %s -check-prefix=Oz +// RUN: %clang_cc1 -O0 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER +// RUN: %clang_cc1 -O1 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER +// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER +// RUN: %clang_cc1 -O3 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER +// RUN: %clang_cc1 -Os -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER +// Check that we set the forcesizeopt attribute on each function +// when Oz optimization level is set. + +int test1() { + return 42; +// Oz: @test1{{.*}}forcesizeopt +// Oz: ret +// OTHER: @test1 +// OTHER-NOT: forcesizeopt +// OTHER: ret +} + +int test2() { + return 42; +// Oz: @test2{{.*}}forcesizeopt +// Oz: ret +// OTHER: @test2 +// OTHER-NOT: forcesizeopt +// OTHER: ret +} -- 2.40.0