Skip to content

Commit 93a4ea9

Browse files
committed
Add the ability to customise the pre-link pipeline
This adds `--newpm-passes <pipeline>`. For consistency, this has the same semantics as LLVM's extant `--lto-newpm-passes` switch. Note that by imitating `--lto-newpm-passes` we inherit a quirk: if you pass the empty string for the pipeline, you get the default pipeline, and not an empty pipeline as one might expect. This is because the switches are backed by a string, and the existence of the switches is decided by checking for an empty string. When the string is non-empty, it goes through a parsing function which annoying also has no way to specify an empty pipeline. Ideally the switches would be backed by a `optional<string>` (or the parser would have a way to specify the empty pipeline), but: a) that would be a separate change, and b) it should probably go upstream too. For now, if you want an empty pipeline, I suggest you add a pass which is a no-op on the IR, e.g. `verify`.
1 parent 29f8990 commit 93a4ea9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

clang/lib/CodeGen/BackendUtil.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
109109
cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
110110
}
111111

112+
static cl::opt<std::string> NewPMPasses("newpm-passes", cl::Optional,
113+
cl::desc("Specify a custom pre-link pipeline. An empty string specifies the default pipeline."),
114+
cl::init(""));
115+
112116
namespace {
113117

114118
// Default filename used for profile generation.
@@ -994,7 +998,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
994998
MPM.addPass(InstrProfiling(*Options, false));
995999
});
9961000

997-
if (CodeGenOpts.OptimizationLevel == 0) {
1001+
if (!NewPMPasses.empty()) {
1002+
MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO);
1003+
if (auto Err = PB.parsePassPipeline(MPM, NewPMPasses)) {
1004+
report_fatal_error(Twine("unable to parse pass pipeline description '") +
1005+
NewPMPasses + "': " + toString(std::move(Err)));
1006+
}
1007+
} else if (CodeGenOpts.OptimizationLevel == 0) {
9981008
MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO);
9991009
} else if (IsThinLTO) {
10001010
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);

0 commit comments

Comments
 (0)