Skip to content

Commit 433f04b

Browse files
author
git apple-llvm automerger
committed
Merge commit '8439aebd3dd3' from llvm.org/main into next
2 parents 0c9677e + 8439aeb commit 433f04b

File tree

2 files changed

+61
-57
lines changed

2 files changed

+61
-57
lines changed

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
7373
DiagnosticsEngine *Diags = nullptr,
7474
bool DefaultDiagColor = true);
7575

76+
unsigned getOptimizationLevel(llvm::opt::ArgList &Args, InputKind IK,
77+
DiagnosticsEngine &Diags);
78+
79+
unsigned getOptimizationLevelSize(llvm::opt::ArgList &Args);
80+
7681
/// The base class of CompilerInvocation. It keeps individual option objects
7782
/// behind reference-counted pointers, which is useful for clients that want to
7883
/// keep select option objects alive (even after CompilerInvocation gets

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -750,52 +750,6 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
750750
// Deserialization (from args)
751751
//===----------------------------------------------------------------------===//
752752

753-
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
754-
DiagnosticsEngine &Diags) {
755-
unsigned DefaultOpt = 0;
756-
if ((IK.getLanguage() == Language::OpenCL ||
757-
IK.getLanguage() == Language::OpenCLCXX) &&
758-
!Args.hasArg(OPT_cl_opt_disable))
759-
DefaultOpt = 2;
760-
761-
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
762-
if (A->getOption().matches(options::OPT_O0))
763-
return 0;
764-
765-
if (A->getOption().matches(options::OPT_Ofast))
766-
return 3;
767-
768-
assert(A->getOption().matches(options::OPT_O));
769-
770-
StringRef S(A->getValue());
771-
if (S == "s" || S == "z")
772-
return 2;
773-
774-
if (S == "g")
775-
return 1;
776-
777-
return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags);
778-
}
779-
780-
return DefaultOpt;
781-
}
782-
783-
static unsigned getOptimizationLevelSize(ArgList &Args) {
784-
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
785-
if (A->getOption().matches(options::OPT_O)) {
786-
switch (A->getValue()[0]) {
787-
default:
788-
return 0;
789-
case 's':
790-
return 1;
791-
case 'z':
792-
return 2;
793-
}
794-
}
795-
}
796-
return 0;
797-
}
798-
799753
static void GenerateArg(ArgumentConsumer Consumer,
800754
llvm::opt::OptSpecifier OptSpecifier) {
801755
Option Opt = getDriverOptTable().getOption(OptSpecifier);
@@ -2035,17 +1989,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
20351989
const CASOptions &CASOpts) {
20361990
unsigned NumErrorsBefore = Diags.getNumErrors();
20371991

2038-
unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
2039-
// TODO: This could be done in Driver
2040-
unsigned MaxOptLevel = 3;
2041-
if (OptimizationLevel > MaxOptLevel) {
2042-
// If the optimization level is not supported, fall back on the default
2043-
// optimization
2044-
Diags.Report(diag::warn_drv_optimization_value)
2045-
<< Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel;
2046-
OptimizationLevel = MaxOptLevel;
2047-
}
2048-
Opts.OptimizationLevel = OptimizationLevel;
1992+
Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
20491993

20501994
// The key paths of codegen options defined in Options.td start with
20511995
// "CodeGenOpts.". Let's provide the expected variable name and type.
@@ -2954,6 +2898,61 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
29542898
return Diags->getNumErrors() == NumErrorsBefore;
29552899
}
29562900

2901+
unsigned clang::getOptimizationLevel(ArgList &Args, InputKind IK,
2902+
DiagnosticsEngine &Diags) {
2903+
unsigned DefaultOpt = 0;
2904+
if ((IK.getLanguage() == Language::OpenCL ||
2905+
IK.getLanguage() == Language::OpenCLCXX) &&
2906+
!Args.hasArg(OPT_cl_opt_disable))
2907+
DefaultOpt = 2;
2908+
2909+
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
2910+
if (A->getOption().matches(options::OPT_O0))
2911+
return 0;
2912+
2913+
if (A->getOption().matches(options::OPT_Ofast))
2914+
return 3;
2915+
2916+
assert(A->getOption().matches(options::OPT_O));
2917+
2918+
StringRef S(A->getValue());
2919+
if (S == "s" || S == "z")
2920+
return 2;
2921+
2922+
if (S == "g")
2923+
return 1;
2924+
2925+
DefaultOpt = getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags);
2926+
}
2927+
2928+
unsigned MaxOptLevel = 3;
2929+
if (DefaultOpt > MaxOptLevel) {
2930+
// If the optimization level is not supported, fall back on the default
2931+
// optimization
2932+
Diags.Report(diag::warn_drv_optimization_value)
2933+
<< Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel;
2934+
DefaultOpt = MaxOptLevel;
2935+
}
2936+
2937+
return DefaultOpt;
2938+
}
2939+
2940+
unsigned clang::getOptimizationLevelSize(ArgList &Args) {
2941+
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
2942+
if (A->getOption().matches(options::OPT_O)) {
2943+
switch (A->getValue()[0]) {
2944+
default:
2945+
return 0;
2946+
case 's':
2947+
return 1;
2948+
case 'z':
2949+
return 2;
2950+
}
2951+
}
2952+
}
2953+
return 0;
2954+
}
2955+
29572956
/// Parse the argument to the -ftest-module-file-extension
29582957
/// command-line argument.
29592958
///

0 commit comments

Comments
 (0)