[lld] r269605 - [LTO] Add the ability to specify a subset of passes to run.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Sun May 15 12:29:38 PDT 2016
Author: davide
Date: Sun May 15 14:29:38 2016
New Revision: 269605
URL: http://llvm.org/viewvc/llvm-project?rev=269605&view=rev
Log:
[LTO] Add the ability to specify a subset of passes to run.
Differential Revision: http://reviews.llvm.org/D20267
Added:
lld/trunk/test/ELF/lto/ltopasses-custom.ll
Modified:
lld/trunk/ELF/CMakeLists.txt
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/Options.td
Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=269605&r1=269604&r2=269605&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Sun May 15 14:29:38 2016
@@ -31,6 +31,7 @@ add_lld_library(lldELF
Linker
Object
Option
+ Passes
MC
Support
Target
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=269605&r1=269604&r2=269605&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Sun May 15 14:29:38 2016
@@ -44,6 +44,7 @@ struct Configuration {
llvm::StringRef Emulation;
llvm::StringRef Fini;
llvm::StringRef Init;
+ llvm::StringRef LtoNewPmPasses;
llvm::StringRef OutputFile;
llvm::StringRef SoName;
llvm::StringRef Sysroot;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=269605&r1=269604&r2=269605&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sun May 15 14:29:38 2016
@@ -337,6 +337,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->Entry = getString(Args, OPT_entry);
Config->Fini = getString(Args, OPT_fini, "_fini");
Config->Init = getString(Args, OPT_init, "_init");
+ Config->LtoNewPmPasses = getString(Args, OPT_lto_newpm_passes);
Config->OutputFile = getString(Args, OPT_o);
Config->SoName = getString(Args, OPT_soname);
Config->Sysroot = getString(Args, OPT_sysroot);
@@ -495,6 +496,8 @@ template <class ELFT> void LinkerDriver:
Symtab.scanVersionScript();
Symtab.addCombinedLtoObject();
+ if (HasError)
+ return;
for (auto *Arg : Args.filtered(OPT_wrap))
Symtab.wrap(Arg->getValue());
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=269605&r1=269604&r2=269605&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Sun May 15 14:29:38 2016
@@ -13,6 +13,9 @@
#include "Error.h"
#include "InputFiles.h"
#include "Symbols.h"
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/CGSCCPassManager.h"
+#include "llvm/Analysis/LoopPassManager.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/ReaderWriter.h"
@@ -20,13 +23,16 @@
#include "llvm/CodeGen/ParallelCG.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Linker/IRMover.h"
+#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
+#include <llvm/IR/Verifier.h>
using namespace llvm;
using namespace llvm::object;
@@ -56,10 +62,44 @@ static void saveBCFile(Module &M, String
WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
}
-// Run LTO passes.
-// Note that the gold plugin has a similar piece of code, so
-// it is probably better to move this code to a common place.
-static void runLTOPasses(Module &M, TargetMachine &TM) {
+static void runNewCustomLtoPasses(Module &M, TargetMachine &TM) {
+ PassBuilder PB(&TM);
+
+ AAManager AA;
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
+
+ // Register the AA manager first so that our version is the one used.
+ FAM.registerPass([&] { return std::move(AA); });
+
+ // Register all the basic analyses with the managers.
+ PB.registerModuleAnalyses(MAM);
+ PB.registerCGSCCAnalyses(CGAM);
+ PB.registerFunctionAnalyses(FAM);
+ PB.registerLoopAnalyses(LAM);
+ PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+
+ ModulePassManager MPM;
+ if (!Config->DisableVerify)
+ MPM.addPass(VerifierPass());
+
+ // Now, add all the passes we've been requested to.
+ if (!PB.parsePassPipeline(MPM, Config->LtoNewPmPasses)) {
+ error("unable to parse pass pipeline description: " +
+ Config->LtoNewPmPasses);
+ return;
+ }
+
+ if (!Config->DisableVerify)
+ MPM.addPass(VerifierPass());
+ MPM.run(M, MAM);
+}
+
+static void runOldLtoPasses(Module &M, TargetMachine &TM) {
+ // Note that the gold plugin has a similar piece of code, so
+ // it is probably better to move this code to a common place.
legacy::PassManager LtoPasses;
LtoPasses.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
PassManagerBuilder PMB;
@@ -71,6 +111,21 @@ static void runLTOPasses(Module &M, Targ
PMB.OptLevel = Config->LtoO;
PMB.populateLTOPassManager(LtoPasses);
LtoPasses.run(M);
+}
+
+static void runLTOPasses(Module &M, TargetMachine &TM) {
+ if (!Config->LtoNewPmPasses.empty()) {
+ // The user explicitly asked for a set of passes to be run.
+ // This needs the new PM to work as there's no clean way to
+ // pass a set of passes to run in the legacy PM.
+ runNewCustomLtoPasses(M, TM);
+ if (HasError)
+ return;
+ } else {
+ // Run the 'default' set of LTO passes. This code still uses
+ // the legacy PM as the new one is not the default.
+ runOldLtoPasses(M, TM);
+ }
if (Config->SaveTemps)
saveBCFile(M, ".lto.opt.bc");
@@ -226,6 +281,8 @@ std::vector<std::unique_ptr<InputFile>>
std::unique_ptr<TargetMachine> TM = CreateTargetMachine();
runLTOPasses(*Combined, *TM);
+ if (HasError)
+ return {};
return runSplitCodegen(CreateTargetMachine);
}
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=269605&r1=269604&r2=269605&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Sun May 15 14:29:38 2016
@@ -255,6 +255,8 @@ def alias_version_script_version_script
// LTO-related options.
def lto_jobs : Joined<["--"], "lto-jobs=">,
HelpText<"Number of threads to run codegen">;
+def lto_newpm_passes : Joined<["--"], "lto-newpm-passes=">,
+ HelpText<"Passes to run during LTO">;
def disable_verify : Flag<["-"], "disable-verify">;
def mllvm : Separate<["-"], "mllvm">;
def save_temps : Flag<["-"], "save-temps">;
Added: lld/trunk/test/ELF/lto/ltopasses-custom.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/ltopasses-custom.ll?rev=269605&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/ltopasses-custom.ll (added)
+++ lld/trunk/test/ELF/lto/ltopasses-custom.ll Sun May 15 14:29:38 2016
@@ -0,0 +1,29 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -save-temps --lto-newpm-passes=ipsccp -shared
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t2.so -save-temps --lto-newpm-passes=loweratomic -shared
+; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s
+; RUN: llvm-dis %t2.so.lto.opt.bc -o - | FileCheck %s --check-prefix=ATOMIC
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @barrier() {
+ fence seq_cst
+ ret void
+}
+
+; IPSCCP won't remove the fence.
+; CHECK: define void @barrier() {
+; CHECK-NEXT: fence seq_cst
+; CHECK-NEXT: ret void
+
+; LowerAtomic will remove the fence.
+; ATOMIC: define void @barrier() {
+; ATOMIC-NEXT: ret void
+
+; Check that invalid passes are rejected gracefully.
+; RUN: not ld.lld -m elf_x86_64 %t.o -o %t2.so \
+; RUN: --lto-newpm-passes=iamnotapass -shared 2>&1 | \
+; RUN: FileCheck %s --check-prefix=INVALID
+; INVALID: unable to parse pass pipeline description: iamnotapass
More information about the llvm-commits
mailing list