From 7ab1c3ebd02c31bfa1333cc51de1261c1499d6f7 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 27 Oct 2009 19:48:08 +0000 Subject: [PATCH] Set OptimizeForSize LLVM function attribute with -Os. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85278 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 2 ++ test/CodeGen/function-attributes.c | 35 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 78655168e8..06cd05cc75 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -441,6 +441,8 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, RetAttrs |= llvm::Attribute::NoAlias; } + if (CompileOpts.OptimizeSize) + FuncAttrs |= llvm::Attribute::OptimizeForSize; if (CompileOpts.DisableRedZone) FuncAttrs |= llvm::Attribute::NoRedZone; if (CompileOpts.NoImplicitFloat) diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c index 376d0b1022..b09b28b8d9 100644 --- a/test/CodeGen/function-attributes.c +++ b/test/CodeGen/function-attributes.c @@ -1,4 +1,4 @@ -// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s +// RUN: clang-cc -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s // CHECK: define signext i8 @f0(i32 %x) nounwind // CHECK: define zeroext i8 @f1(i32 %x) nounwind // CHECK: define void @f2(i8 signext %x) nounwind @@ -24,15 +24,22 @@ void f6(signed short x) { } void f7(unsigned short x) { } -// CHECK: define void @f8() nounwind alwaysinline +// CHECK: define void @f8() +// CHECK: nounwind +// CHECK: alwaysinline +// CHECK: { void __attribute__((always_inline)) f8(void) { } -// CHECK: call void @f9_t() noreturn +// CHECK: call void @f9_t() +// CHECK: noreturn +// CHECK: { void __attribute__((noreturn)) f9_t(void); void f9(void) { f9_t(); } // FIXME: We should be setting nounwind on calls. -// CHECK: call i32 @f10_t() readnone +// CHECK: call i32 @f10_t() +// CHECK: readnone +// CHECK: { int __attribute__((const)) f10_t(void); int f10(void) { return f10_t(); } int f11(void) { @@ -49,9 +56,9 @@ void f13(void){} // Ensure that these get inlined: rdar://6853279 -// CHECK: define i32 @f14 +// CHECK: define void @f14 // CHECK-NOT: @ai_ -// CHECK: ret i32 +// CHECK: call void @f14_end static __inline__ __attribute__((always_inline)) int ai_1() { return 4; } @@ -60,7 +67,17 @@ struct { int a, b, c, d, e; } ai_2() { while (1) {} } -int f14() { - ai_2(); - return ai_1(); +void f14(int a) { + extern void f14_end(void); + if (a) + ai_2(); + ai_1(); + f14_end(); +} + +// [irgen] clang isn't setting the optsize bit on functions +// CHECK: define void @f15 +// CHECK: optsize +// CHECK: { +void f15(void) { } -- 2.40.0