diff options
| author | Paul Robinson <paul_robinson@playstation.sony.com> | 2014-12-11 20:14:04 +0000 |
|---|---|---|
| committer | Paul Robinson <paul_robinson@playstation.sony.com> | 2014-12-11 20:14:04 +0000 |
| commit | 0855695159d62d4b900909f84d601e87219d454c (patch) | |
| tree | 61af814dcc587d3b9f82d008581b811d96177998 /clang/lib/CodeGen | |
| parent | 7eb1f1856c3b6549544256da9c4b881f695903cc (diff) | |
| download | bcm5719-llvm-0855695159d62d4b900909f84d601e87219d454c.tar.gz bcm5719-llvm-0855695159d62d4b900909f84d601e87219d454c.zip | |
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.
llvm-svn: 224047
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 7 |
2 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 6db753f1686..c052cf245c4 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1340,6 +1340,7 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, bool AttrOnCallSite) { llvm::AttrBuilder FuncAttrs; llvm::AttrBuilder RetAttrs; + bool HasOptnone = false; CallingConv = FI.getEffectiveCallingConvention(); @@ -1380,12 +1381,18 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, 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) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 597fd364d78..06467fda6ef 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -725,7 +725,8 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, } 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::SetLLVMFunctionAttributesForDefinition(const Decl *D, 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); |

