Index: lld/ELF/Config.h =================================================================== --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -85,6 +85,7 @@ llvm::StringRef Init; llvm::StringRef LTOAAPipeline; llvm::StringRef LTONewPmPasses; + llvm::StringRef LTOSampleProfile; llvm::StringRef MapFile; llvm::StringRef OutputFile; llvm::StringRef OptRemarksFilename; @@ -131,6 +132,7 @@ bool ICF; bool IgnoreDataAddressEquality; bool IgnoreFunctionAddressEquality; + bool LTONewPassManager; bool MergeArmExidx; bool MipsN32Abi = false; bool NoinhibitExec; Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -657,9 +657,11 @@ Args.hasArg(OPT_ignore_function_address_equality); Config->Init = Args.getLastArgValue(OPT_init, "_init"); Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline); + Config->LTONewPassManager = Args.hasArg(OPT_lto_new_pass_manager); Config->LTONewPmPasses = Args.getLastArgValue(OPT_lto_newpm_passes); Config->LTOO = args::getInteger(Args, OPT_lto_O, 2); Config->LTOPartitions = args::getInteger(Args, OPT_lto_partitions, 1); + Config->LTOSampleProfile = Args.getLastArgValue(OPT_lto_sample_profile); Config->MapFile = Args.getLastArgValue(OPT_Map); Config->MergeArmExidx = Args.hasFlag(OPT_merge_exidx_entries, OPT_no_merge_exidx_entries, true); @@ -734,6 +736,10 @@ Config->ThinLTOJobs = parseInt(S.substr(5), Arg); else if (S.startswith("mcpu=")) parseClangOption(Saver.save("-" + S), Arg->getSpelling()); + else if (S == "new-pass-manager") + Config->LTONewPassManager = true; + else if (S.startswith("sample-profile=")) + Config->LTOSampleProfile = S.substr(strlen("sample-profile=")); else if (!S.startswith("/") && !S.startswith("-fresolution=") && !S.startswith("-pass-through=") && !S.startswith("thinlto")) parseClangOption(S, Arg->getSpelling()); Index: lld/ELF/LTO.cpp =================================================================== --- lld/ELF/LTO.cpp +++ lld/ELF/LTO.cpp @@ -104,6 +104,10 @@ lto::ThinBackend Backend; if (Config->ThinLTOJobs != -1u) Backend = lto::createInProcessThinBackend(Config->ThinLTOJobs); + + Conf.SampleProfile = Config->LTOSampleProfile; + Conf.UseNewPM = Config->LTONewPassManager; + return llvm::make_unique(std::move(Conf), Backend, Config->LTOPartitions); } Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -394,10 +394,14 @@ // LTO-related options. def lto_aa_pipeline: J<"lto-aa-pipeline=">, HelpText<"AA pipeline to run during LTO. Used in conjunction with -lto-newpm-passes">; +def lto_new_pass_manager: F<"lto-new-pass-manager">, + HelpText<"Use new pass manager">; def lto_newpm_passes: J<"lto-newpm-passes=">, HelpText<"Passes to run during LTO">; def lto_partitions: J<"lto-partitions=">, HelpText<"Number of LTO codegen partitions">; +def lto_sample_profile: J<"lto-sample-profile=">, + HelpText<"Sample profile file path">; def disable_verify: F<"disable-verify">; defm mllvm: Eq<"mllvm">; def opt_remarks_filename: Separate<["--"], "opt-remarks-filename">, Index: lld/test/ELF/lto/new-pass-manager.ll =================================================================== --- /dev/null +++ lld/test/ELF/lto/new-pass-manager.ll @@ -0,0 +1,10 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o + +; Try the new pass manager for LTO (make sure the option +; is accepted). +; RUN: ld.lld --plugin-opt=new-pass-manager %t.o -o %t.s.o +; RUN: ld.lld --plugin-opt=thinlto --lto-new-pass-manager %t.o -o %t1.o + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" Index: lld/test/ELF/lto/sample-profile.ll =================================================================== --- /dev/null +++ lld/test/ELF/lto/sample-profile.ll @@ -0,0 +1,25 @@ +; REQUIRES: x86 +; RUN: opt -module-summary %s -o %t1.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o + +; RUN: rm -f %t1.lto.o %t2.lto.o +; RUN: ld.lld --lto-sample-profile=/dev/null %t1.o %t2.o -o %t3 +; RUN opt -S %t3.lto.o | FileCheck %s + +; RUN: rm -f %t1.lto.o %t2.lto.o +; RUN: ld.lld --plugin-opt=sample-profile=/dev/null %t1.o %t2.o -o %t3 +; RUN opt -S %t3.lto.o | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: ProfileSummary +declare void @g(...) +declare void @h(...) + +define void @f() { +entry: + call void (...) @g() + call void (...) @h() + ret void +}