Debian Codegraph @

llvm-project/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp

raw
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> 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));
25
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;
32
33 PassInstrumentationCallbacks PIC;
34 PIC.registerShouldRunOptionalPassCallback(
35 [&](StringRef, Any) { return !O.shouldKeep(); });
36 PassBuilder PB(nullptr, PipelineTuningOptions(), std::nullopt, &PIC);
37
38 PB.registerModuleAnalyses(MAM);
39 PB.registerCGSCCAnalyses(CGAM);
40 PB.registerFunctionAnalyses(FAM);
41 PB.registerLoopAnalyses(LAM);
42 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
43
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");
48 }
49 MPM.run(Program, MAM);
50 }
51
52 void llvm::runIRPassesDeltaPass(TestRunner &Test) {
53 runDeltaPass(Test, runPasses, "Running passes");
54 }