xref: /llvm-project/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp (revision 4f14bfeddedcf21e0eaf0ff3ddf7b62938f66df5)
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 //===----------------------------------------------------------------------===//
8 
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"
14 
15 using namespace llvm;
16 
17 extern cl::OptionCategory LLVMReduceOptions;
18 
19 static cl::opt<std::string>
20     PassPipeline("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<no-verify-fixpoint>,gvn,"
24                           "simplifycfg,infer-address-spaces)"),
25                  cl::cat(LLVMReduceOptions));
26 
27 static void runPasses(Oracle &O, ReducerWorkItem &WorkItem) {
28   Module &Program = WorkItem.getModule();
29   LoopAnalysisManager LAM;
30   FunctionAnalysisManager FAM;
31   CGSCCAnalysisManager CGAM;
32   ModuleAnalysisManager MAM;
33 
34   PassInstrumentationCallbacks PIC;
35   PIC.registerShouldRunOptionalPassCallback(
36       [&](StringRef, Any) { return !O.shouldKeep(); });
37   PassBuilder PB(nullptr, PipelineTuningOptions(), std::nullopt, &PIC);
38 
39   PB.registerModuleAnalyses(MAM);
40   PB.registerCGSCCAnalyses(CGAM);
41   PB.registerFunctionAnalyses(FAM);
42   PB.registerLoopAnalyses(LAM);
43   PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
44 
45   ModulePassManager MPM;
46   if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
47     errs() << toString(std::move(Err)) << "\n";
48     report_fatal_error("Error constructing pass pipeline");
49   }
50   MPM.run(Program, MAM);
51 }
52 
53 void llvm::runIRPassesDeltaPass(TestRunner &Test) {
54   runDeltaPass(Test, runPasses, "Running passes");
55 }
56