Index: lld/trunk/ELF/Config.h =================================================================== --- lld/trunk/ELF/Config.h +++ lld/trunk/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,8 @@ bool ICF; bool IgnoreDataAddressEquality; bool IgnoreFunctionAddressEquality; + bool LTODebugPassManager; + bool LTONewPassManager; bool MergeArmExidx; bool MipsN32Abi = false; bool NoinhibitExec; Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -657,9 +657,12 @@ Args.hasArg(OPT_ignore_function_address_equality); Config->Init = Args.getLastArgValue(OPT_init, "_init"); Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline); + Config->LTODebugPassManager = Args.hasArg(OPT_lto_debug_pass_manager); + 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 +737,12 @@ 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 == "debug-pass-manager") + Config->LTODebugPassManager = 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/trunk/ELF/LTO.cpp =================================================================== --- lld/trunk/ELF/LTO.cpp +++ lld/trunk/ELF/LTO.cpp @@ -104,6 +104,11 @@ lto::ThinBackend Backend; if (Config->ThinLTOJobs != -1u) Backend = lto::createInProcessThinBackend(Config->ThinLTOJobs); + + Conf.SampleProfile = Config->LTOSampleProfile; + Conf.UseNewPM = Config->LTONewPassManager; + Conf.DebugPassManager = Config->LTODebugPassManager; + return llvm::make_unique(std::move(Conf), Backend, Config->LTOPartitions); } Index: lld/trunk/ELF/Options.td =================================================================== --- lld/trunk/ELF/Options.td +++ lld/trunk/ELF/Options.td @@ -394,10 +394,16 @@ // 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_debug_pass_manager: F<"lto-debug-pass-manager">, + HelpText<"Debug new pass manager">; +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/trunk/test/ELF/lto/new-pass-manager.ll =================================================================== --- lld/trunk/test/ELF/lto/new-pass-manager.ll +++ lld/trunk/test/ELF/lto/new-pass-manager.ll @@ -0,0 +1,14 @@ +; REQUIRES: x86 +; RUN: opt -module-summary %s -o %t.o + +; Test new-pass-manager and debug-pass-manager option +; RUN: ld.lld --plugin-opt=new-pass-manager --plugin-opt=debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --plugin-opt=new-pass-manager --lto-debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --lto-new-pass-manager --plugin-opt=debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s +; RUN: ld.lld --lto-new-pass-manager --lto-debug-pass-manager -o %t2.o %t.o 2>&1 | FileCheck %s + +; CHECK: Starting llvm::Module pass manager run +; CHECK: Finished llvm::Module pass manager run + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" Index: lld/trunk/test/ELF/lto/sample-profile.ll =================================================================== --- lld/trunk/test/ELF/lto/sample-profile.ll +++ lld/trunk/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 +}