[Frontend] Simplify -finline* handling. NFC

This commit is contained in:
Fangrui Song 2022-04-10 00:31:25 -07:00
parent ee7fb36ba0
commit d74039fa8e
1 changed files with 16 additions and 17 deletions

View File

@ -1613,23 +1613,22 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
// At O0 we want to fully disable inlining outside of cases marked with
// 'alwaysinline' that are required for correctness.
Opts.setInlining((Opts.OptimizationLevel == 0)
? CodeGenOptions::OnlyAlwaysInlining
: CodeGenOptions::NormalInlining);
// Explicit inlining flags can disable some or all inlining even at
// optimization levels above zero.
if (Arg *InlineArg = Args.getLastArg(
options::OPT_finline_functions, options::OPT_finline_hint_functions,
options::OPT_fno_inline_functions, options::OPT_fno_inline)) {
if (Opts.OptimizationLevel > 0) {
const Option &InlineOpt = InlineArg->getOption();
if (InlineOpt.matches(options::OPT_finline_functions))
Opts.setInlining(CodeGenOptions::NormalInlining);
else if (InlineOpt.matches(options::OPT_finline_hint_functions))
Opts.setInlining(CodeGenOptions::OnlyHintInlining);
else
Opts.setInlining(CodeGenOptions::OnlyAlwaysInlining);
}
if (Opts.OptimizationLevel == 0) {
Opts.setInlining(CodeGenOptions::OnlyAlwaysInlining);
} else if (const Arg *A = Args.getLastArg(options::OPT_finline_functions,
options::OPT_finline_hint_functions,
options::OPT_fno_inline_functions,
options::OPT_fno_inline)) {
// Explicit inlining flags can disable some or all inlining even at
// optimization levels above zero.
if (A->getOption().matches(options::OPT_finline_functions))
Opts.setInlining(CodeGenOptions::NormalInlining);
else if (A->getOption().matches(options::OPT_finline_hint_functions))
Opts.setInlining(CodeGenOptions::OnlyHintInlining);
else
Opts.setInlining(CodeGenOptions::OnlyAlwaysInlining);
} else {
Opts.setInlining(CodeGenOptions::NormalInlining);
}
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to