[cfe-commits] r120875 - /cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Peter Collingbourne
peter at pcc.me.uk
Fri Dec 3 17:50:36 PST 2010
Author: pcc
Date: Fri Dec 3 19:50:36 2010
New Revision: 120875
URL: http://llvm.org/viewvc/llvm-project?rev=120875&view=rev
Log:
Refactor optimisation level code
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=120875&r1=120874&r2=120875&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Dec 3 19:50:36 2010
@@ -772,6 +772,12 @@
//
+static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
+ Diagnostic &Diags) {
+ // -Os implies -O2
+ return Args.hasArg(OPT_Os) ? 2 : Args.getLastArgIntValue(OPT_O, 0, Diags);
+}
+
static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
Diagnostic &Diags) {
using namespace cc1options;
@@ -849,19 +855,15 @@
Opts.IdempotentOps = Args.hasArg(OPT_analysis_WarnIdempotentOps);
}
-static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
+static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Diagnostic &Diags) {
using namespace cc1options;
- // -Os implies -O2
- if (Args.hasArg(OPT_Os))
- Opts.OptimizationLevel = 2;
- else {
- Opts.OptimizationLevel = Args.getLastArgIntValue(OPT_O, 0, Diags);
- if (Opts.OptimizationLevel > 3) {
- Diags.Report(diag::err_drv_invalid_value)
- << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel;
- Opts.OptimizationLevel = 3;
- }
+
+ Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
+ if (Opts.OptimizationLevel > 3) {
+ Diags.Report(diag::err_drv_invalid_value)
+ << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel;
+ Opts.OptimizationLevel = 3;
}
// We must always run at least the always inlining pass.
@@ -1415,8 +1417,7 @@
Opts.OptimizeSize = 0;
// FIXME: Eliminate this dependency.
- unsigned Opt =
- Args.hasArg(OPT_Os) ? 2 : Args.getLastArgIntValue(OPT_O, 0, Diags);
+ unsigned Opt = getOptimizationLevel(Args, IK, Diags);
Opts.Optimize = Opt != 0;
// This is the __NO_INLINE__ define, which just depends on things like the
@@ -1570,11 +1571,12 @@
Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args);
ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags);
- ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, Diags);
ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags);
ParseFileSystemArgs(Res.getFileSystemOpts(), *Args);
+ // FIXME: We shouldn't have to pass the DashX option around here
InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags);
+ ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags);
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
if (DashX != IK_AST && DashX != IK_LLVM_IR)
ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
More information about the cfe-commits
mailing list