Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / RunIRPasses.cpp
blobacef29a68194159c74e1f564a86de28ecf092e62
1 //===- RunIRPasses.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "RunIRPasses.h"
10 #include "Delta.h"
11 #include "llvm/Passes/PassBuilder.h"
12 #include "llvm/Support/CommandLine.h"
13 #include "llvm/Support/ErrorHandling.h"
15 using namespace llvm;
17 extern cl::OptionCategory LLVMReduceOptions;
19 static cl::opt<std::string> PassPipeline(
20 "ir-passes",
21 cl::desc("A textual description of the pass pipeline, same as "
22 "what's passed to `opt -passes`."),
23 cl::init("function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"),
24 cl::cat(LLVMReduceOptions));
26 static void runPasses(Oracle &O, ReducerWorkItem &WorkItem) {
27 Module &Program = WorkItem.getModule();
28 LoopAnalysisManager LAM;
29 FunctionAnalysisManager FAM;
30 CGSCCAnalysisManager CGAM;
31 ModuleAnalysisManager MAM;
33 PassInstrumentationCallbacks PIC;
34 PIC.registerShouldRunOptionalPassCallback(
35 [&](StringRef, Any) { return !O.shouldKeep(); });
36 PassBuilder PB(nullptr, PipelineTuningOptions(), std::nullopt, &PIC);
38 PB.registerModuleAnalyses(MAM);
39 PB.registerCGSCCAnalyses(CGAM);
40 PB.registerFunctionAnalyses(FAM);
41 PB.registerLoopAnalyses(LAM);
42 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
44 ModulePassManager MPM;
45 if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
46 errs() << toString(std::move(Err)) << "\n";
47 report_fatal_error("Error constructing pass pipeline");
49 MPM.run(Program, MAM);
52 void llvm::runIRPassesDeltaPass(TestRunner &Test) {
53 runDeltaPass(Test, runPasses, "Running passes");