Refactor optimisation level code

llvm-svn: 120875
This commit is contained in:
Peter Collingbourne 2010-12-04 01:50:36 +00:00
parent aaeb73b159
commit b8e5dd44ed
1 changed files with 16 additions and 14 deletions

View File

@ -772,6 +772,12 @@ using namespace clang::driver::cc1options;
//
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,20 +855,16 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
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);
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.
Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
@ -1415,8 +1417,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
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 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
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);