r224047 - Instead of having -Os/-Oz add OptimizeForSize/MinSize first, and later

Paul Robinson paul_robinson at playstation.sony.com
Thu Dec 11 12:14:04 PST 2014


Author: probinson
Date: Thu Dec 11 14:14:04 2014
New Revision: 224047

URL: http://llvm.org/viewvc/llvm-project?rev=224047&view=rev
Log:
Instead of having -Os/-Oz add OptimizeForSize/MinSize first, and later
having OptimizeNone remove them again, just don't add them in the
first place if the function already has OptimizeNone.

Note that MinSize can still appear due to attributes on different
declarations; a future patch will address that.


Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/attr-optnone.c
    cfe/trunk/test/SemaCXX/pragma-optimize.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=224047&r1=224046&r2=224047&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Dec 11 14:14:04 2014
@@ -1340,6 +1340,7 @@ void CodeGenModule::ConstructAttributeLi
                                            bool AttrOnCallSite) {
   llvm::AttrBuilder FuncAttrs;
   llvm::AttrBuilder RetAttrs;
+  bool HasOptnone = false;
 
   CallingConv = FI.getEffectiveCallingConvention();
 
@@ -1380,12 +1381,18 @@ void CodeGenModule::ConstructAttributeLi
       RetAttrs.addAttribute(llvm::Attribute::NoAlias);
     if (TargetDecl->hasAttr<ReturnsNonNullAttr>())
       RetAttrs.addAttribute(llvm::Attribute::NonNull);
+
+    HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
+  }
+
+  // OptimizeNoneAttr takes precedence over -Os or -Oz. No warning needed.
+  if (!HasOptnone) {
+    if (CodeGenOpts.OptimizeSize)
+      FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
+    if (CodeGenOpts.OptimizeSize == 2)
+      FuncAttrs.addAttribute(llvm::Attribute::MinSize);
   }
 
-  if (CodeGenOpts.OptimizeSize)
-    FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
-  if (CodeGenOpts.OptimizeSize == 2)
-    FuncAttrs.addAttribute(llvm::Attribute::MinSize);
   if (CodeGenOpts.DisableRedZone)
     FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
   if (CodeGenOpts.NoImplicitFloat)

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=224047&r1=224046&r2=224047&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Dec 11 14:14:04 2014
@@ -725,7 +725,8 @@ void CodeGenModule::SetLLVMFunctionAttri
   }
 
   if (D->hasAttr<ColdAttr>()) {
-    B.addAttribute(llvm::Attribute::OptimizeForSize);
+    if (!D->hasAttr<OptimizeNoneAttr>())
+      B.addAttribute(llvm::Attribute::OptimizeForSize);
     B.addAttribute(llvm::Attribute::Cold);
   }
 
@@ -766,7 +767,9 @@ void CodeGenModule::SetLLVMFunctionAttri
     F->addFnAttr(llvm::Attribute::NoInline);
 
     // OptimizeNone wins over OptimizeForSize, MinSize, AlwaysInline.
-    F->removeFnAttr(llvm::Attribute::OptimizeForSize);
+    assert(!F->hasFnAttribute(llvm::Attribute::OptimizeForSize) &&
+           "OptimizeNone and OptimizeForSize on same function!");
+    // FIXME: Change these to asserts.
     F->removeFnAttr(llvm::Attribute::MinSize);
     F->removeFnAttr(llvm::Attribute::AlwaysInline);
 

Modified: cfe/trunk/test/CodeGen/attr-optnone.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-optnone.c?rev=224047&r1=224046&r2=224047&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-optnone.c (original)
+++ cfe/trunk/test/CodeGen/attr-optnone.c Thu Dec 11 14:14:04 2014
@@ -4,10 +4,14 @@
 // RUN: %clang_cc1 -emit-llvm -Os < %s > %t
 // RUN: FileCheck %s --check-prefix=PRESENT < %t
 // RUN: FileCheck %s --check-prefix=OPTSIZE < %t
+// RUN: %clang_cc1 -emit-llvm -Oz < %s > %t
+// RUN: FileCheck %s --check-prefix=PRESENT < %t
+// RUN: FileCheck %s --check-prefix=MINSIZE < %t
 
 __attribute__((always_inline))
 int test2() { return 0; }
 // OPTSIZE: @test2{{.*}}[[ATTR2:#[0-9]+]]
+// MINSIZE: @test2{{.*}}[[ATTR2:#[0-9]+]]
 
 __attribute__((optnone))
 int test3() { return 0; }
@@ -31,3 +35,8 @@ int test4() { return test2(); }
 // OPTSIZE-NOT: optsize
 // OPTSIZE: attributes [[ATTR2]] = { {{.*}}optsize{{.*}} }
 // OPTSIZE-NOT: optsize
+
+// With -Oz, check that 'minsize' appears only on test2.
+// MINSIZE-NOT: minsize
+// MINSIZE: attributes [[ATTR2]] = { {{.*}}minsize{{.*}} }
+// MINSIZE-NOT: minsize

Modified: cfe/trunk/test/SemaCXX/pragma-optimize.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-optimize.cpp?rev=224047&r1=224046&r2=224047&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/pragma-optimize.cpp (original)
+++ cfe/trunk/test/SemaCXX/pragma-optimize.cpp Thu Dec 11 14:14:04 2014
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -O2 < %s | FileCheck %s
+// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -Os < %s | FileCheck %s
+// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -Oz < %s | FileCheck %s
 
 #pragma clang optimize off
 





More information about the cfe-commits mailing list