aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Wilson <bob.wilson@apple.com>2011-04-29 22:49:50 +0000
committerBob Wilson <bob.wilson@apple.com>2011-04-29 22:49:50 +0000
commita0fa203f04235cb6d05eeb8cea3392a01aa7571b (patch)
tree9a3822857914a10ce31324c43495b30f0897289c
parent73a6f8e8ad2174fb70cfb4c7d7afe424cfe8a147 (diff)
Add -Oz option and use it to set the inline threshold to 25.
Radar 9333566. Patch by Chad Rosier! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130554 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/CC1Options.td1
-rw-r--r--include/clang/Frontend/CodeGenOptions.h2
-rw-r--r--lib/CodeGen/BackendUtil.cpp4
-rw-r--r--lib/Driver/Tools.cpp4
-rw-r--r--lib/Frontend/CompilerInvocation.cpp7
5 files changed, 9 insertions, 9 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 065fdd2c2c..55d061bb1f 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -179,6 +179,7 @@ def mms_bitfields : Flag<"-mms-bitfields">,
HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard.">;
def O : Joined<"-O">, HelpText<"Optimization level">;
def Os : Flag<"-Os">, HelpText<"Optimize for size">;
+def Oz : Flag<"-Oz">, HelpText<"Optimize for size, regardless of performance">;
def pg : Flag<"-pg">, HelpText<"Enable mcount instrumentation">;
//===----------------------------------------------------------------------===//
diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h
index cede010199..4e17bdce0f 100644
--- a/include/clang/Frontend/CodeGenOptions.h
+++ b/include/clang/Frontend/CodeGenOptions.h
@@ -76,7 +76,7 @@ public:
unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is
/// enabled.
unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
- unsigned OptimizeSize : 1; /// If -Os is specified.
+ unsigned OptimizeSize : 2; /// If -Os (==1) or -Oz (==2) is specified.
unsigned RelaxAll : 1; /// Relax all machine code instructions.
unsigned RelaxedAliasing : 1; /// Set when -fno-strict-aliasing is enabled.
unsigned SaveTempLabels : 1; /// Save temporary labels.
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index 9bd4bfd70c..497ccc54ee 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -134,8 +134,10 @@ void EmitAssemblyHelper::CreatePasses() {
//
// FIXME: Derive these constants in a principled fashion.
unsigned Threshold = 225;
- if (CodeGenOpts.OptimizeSize)
+ if (CodeGenOpts.OptimizeSize == 1) //-Os
Threshold = 75;
+ else if (CodeGenOpts.OptimizeSize == 2) //-Oz
+ Threshold = 25;
else if (OptLevel > 2)
Threshold = 275;
InliningPass = createFunctionInliningPass(Threshold);
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 9f8a87b3ac..b4693010e1 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1309,10 +1309,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
else if (A->getOption().matches(options::OPT_O) &&
A->getValue(Args)[0] == '\0')
CmdArgs.push_back("-O2");
- else if (A->getOption().matches(options::OPT_O) &&
- A->getValue(Args)[0] == 'z' &&
- A->getValue(Args)[1] == '\0')
- CmdArgs.push_back("-Os");
else
A->render(Args, CmdArgs);
}
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 998ca8aa4a..841a2311d0 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -139,7 +139,7 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
Res.push_back("-momit-leaf-frame-pointer");
if (Opts.OptimizeSize) {
assert(Opts.OptimizationLevel == 2 && "Invalid options!");
- Res.push_back("-Os");
+ Opts.OptimizeSize == 1 ? Res.push_back("-Os") : Res.push_back("-Oz");
} else if (Opts.OptimizationLevel != 0)
Res.push_back("-O" + llvm::utostr(Opts.OptimizationLevel));
if (!Opts.MainFileName.empty()) {
@@ -815,8 +815,8 @@ static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
unsigned DefaultOpt = 0;
if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
DefaultOpt = 2;
- // -Os implies -O2
- return Args.hasArg(OPT_Os) ? 2 :
+ // -Os/-Oz implies -O2
+ return (Args.hasArg(OPT_Os) || Args.hasArg (OPT_Oz)) ? 2 :
Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags);
}
@@ -931,6 +931,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.NoCommon = Args.hasArg(OPT_fno_common);
Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Opts.OptimizeSize = Args.hasArg(OPT_Os);
+ Opts.OptimizeSize = Args.hasArg(OPT_Oz) ? 2 : Opts.OptimizeSize;
Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
Args.hasArg(OPT_ffreestanding));
Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||