@@ -703,52 +703,6 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
703703// Deserialization (from args)
704704// ===----------------------------------------------------------------------===//
705705
706- static unsigned getOptimizationLevel (ArgList &Args, InputKind IK,
707- DiagnosticsEngine &Diags) {
708- unsigned DefaultOpt = 0 ;
709- if ((IK.getLanguage () == Language::OpenCL ||
710- IK.getLanguage () == Language::OpenCLCXX) &&
711- !Args.hasArg (OPT_cl_opt_disable))
712- DefaultOpt = 2 ;
713-
714- if (Arg *A = Args.getLastArg (options::OPT_O_Group)) {
715- if (A->getOption ().matches (options::OPT_O0))
716- return 0 ;
717-
718- if (A->getOption ().matches (options::OPT_Ofast))
719- return 3 ;
720-
721- assert (A->getOption ().matches (options::OPT_O));
722-
723- StringRef S (A->getValue ());
724- if (S == " s" || S == " z" )
725- return 2 ;
726-
727- if (S == " g" )
728- return 1 ;
729-
730- return getLastArgIntValue (Args, OPT_O, DefaultOpt, Diags);
731- }
732-
733- return DefaultOpt;
734- }
735-
736- static unsigned getOptimizationLevelSize (ArgList &Args) {
737- if (Arg *A = Args.getLastArg (options::OPT_O_Group)) {
738- if (A->getOption ().matches (options::OPT_O)) {
739- switch (A->getValue ()[0 ]) {
740- default :
741- return 0 ;
742- case ' s' :
743- return 1 ;
744- case ' z' :
745- return 2 ;
746- }
747- }
748- }
749- return 0 ;
750- }
751-
752706static void GenerateArg (ArgumentConsumer Consumer,
753707 llvm::opt::OptSpecifier OptSpecifier) {
754708 Option Opt = getDriverOptTable ().getOption (OptSpecifier);
@@ -1859,17 +1813,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
18591813 const LangOptions &LangOptsRef) {
18601814 unsigned NumErrorsBefore = Diags.getNumErrors ();
18611815
1862- unsigned OptimizationLevel = getOptimizationLevel (Args, IK, Diags);
1863- // TODO: This could be done in Driver
1864- unsigned MaxOptLevel = 3 ;
1865- if (OptimizationLevel > MaxOptLevel) {
1866- // If the optimization level is not supported, fall back on the default
1867- // optimization
1868- Diags.Report (diag::warn_drv_optimization_value)
1869- << Args.getLastArg (OPT_O)->getAsString (Args) << " -O" << MaxOptLevel;
1870- OptimizationLevel = MaxOptLevel;
1871- }
1872- Opts.OptimizationLevel = OptimizationLevel;
1816+ Opts.OptimizationLevel = getOptimizationLevel (Args, IK, Diags);
18731817
18741818 // The key paths of codegen options defined in Options.td start with
18751819 // "CodeGenOpts.". Let's provide the expected variable name and type.
@@ -2728,6 +2672,61 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
27282672 return Diags->getNumErrors () == NumErrorsBefore;
27292673}
27302674
2675+ unsigned clang::getOptimizationLevel (ArgList &Args, InputKind IK,
2676+ DiagnosticsEngine &Diags) {
2677+ unsigned DefaultOpt = 0 ;
2678+ if ((IK.getLanguage () == Language::OpenCL ||
2679+ IK.getLanguage () == Language::OpenCLCXX) &&
2680+ !Args.hasArg (OPT_cl_opt_disable))
2681+ DefaultOpt = 2 ;
2682+
2683+ if (Arg *A = Args.getLastArg (options::OPT_O_Group)) {
2684+ if (A->getOption ().matches (options::OPT_O0))
2685+ return 0 ;
2686+
2687+ if (A->getOption ().matches (options::OPT_Ofast))
2688+ return 3 ;
2689+
2690+ assert (A->getOption ().matches (options::OPT_O));
2691+
2692+ StringRef S (A->getValue ());
2693+ if (S == " s" || S == " z" )
2694+ return 2 ;
2695+
2696+ if (S == " g" )
2697+ return 1 ;
2698+
2699+ DefaultOpt = getLastArgIntValue (Args, OPT_O, DefaultOpt, Diags);
2700+ }
2701+
2702+ unsigned MaxOptLevel = 3 ;
2703+ if (DefaultOpt > MaxOptLevel) {
2704+ // If the optimization level is not supported, fall back on the default
2705+ // optimization
2706+ Diags.Report (diag::warn_drv_optimization_value)
2707+ << Args.getLastArg (OPT_O)->getAsString (Args) << " -O" << MaxOptLevel;
2708+ DefaultOpt = MaxOptLevel;
2709+ }
2710+
2711+ return DefaultOpt;
2712+ }
2713+
2714+ unsigned clang::getOptimizationLevelSize (ArgList &Args) {
2715+ if (Arg *A = Args.getLastArg (options::OPT_O_Group)) {
2716+ if (A->getOption ().matches (options::OPT_O)) {
2717+ switch (A->getValue ()[0 ]) {
2718+ default :
2719+ return 0 ;
2720+ case ' s' :
2721+ return 1 ;
2722+ case ' z' :
2723+ return 2 ;
2724+ }
2725+ }
2726+ }
2727+ return 0 ;
2728+ }
2729+
27312730// / Parse the argument to the -ftest-module-file-extension
27322731// / command-line argument.
27332732// /
0 commit comments