10 changes: 8 additions & 2 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ static void readConfigs(opt::InputArgList &args) {
config->importTable = args.hasArg(OPT_import_table);
config->importUndefined = args.hasArg(OPT_import_undefined);
config->ltoo = args::getInteger(args, OPT_lto_O, 2);
if (config->ltoo > 3)
error("invalid optimization level for LTO: " + Twine(config->ltoo));
unsigned ltoCgo =
args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo));
if (auto level = CodeGenOpt::getLevel(ltoCgo))
config->ltoCgo = *level;
else
error("invalid codegen optimization level for LTO: " + Twine(ltoCgo));
config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
config->mapFile = args.getLastArgValue(OPT_Map);
Expand Down Expand Up @@ -560,8 +568,6 @@ static void checkOptions(opt::InputArgList &args) {
error("--compress-relocations is incompatible with output debug"
" information. Please pass --strip-debug or --strip-all");

if (config->ltoo > 3)
error("invalid optimization level for LTO: " + Twine(config->ltoo));
if (config->ltoPartitions == 0)
error("--lto-partitions: number of threads must be > 0");
if (!get_threadpool_strategy(config->thinLTOJobs))
Expand Down
2 changes: 1 addition & 1 deletion lld/wasm/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
c.DiagHandler = diagnosticHandler;
c.OptLevel = config->ltoo;
c.MAttrs = getMAttrs();
c.CGOptLevel = args::getCGOptLevel(config->ltoo);
c.CGOptLevel = config->ltoCgo;
c.DebugPassManager = config->ltoDebugPassManager;

if (config->relocatable)
Expand Down
2 changes: 2 additions & 0 deletions lld/wasm/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
// LTO-related options.
def lto_O: JJ<"lto-O">, MetaVarName<"<opt-level>">,
HelpText<"Optimization level for LTO">;
def lto_CGO: JJ<"lto-CGO">, MetaVarName<"<cgopt-level>">,
HelpText<"Codegen optimization level for LTO">;
def lto_partitions: JJ<"lto-partitions=">,
HelpText<"Number of LTO codegen partitions">;
def disable_verify: F<"disable-verify">;
Expand Down