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
15using namespace llvm;
16
17extern cl::OptionCategory LLVMReduceOptions;
18
19static 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(Val: "function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"),
24 cl::cat(LLVMReduceOptions));
25
26static 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 C: [&](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, PipelineText: PassPipeline)) {
46 errs() << toString(E: std::move(Err)) << "\n";
47 report_fatal_error(reason: "Error constructing pass pipeline");
48 }
49 MPM.run(IR&: Program, AM&: MAM);
50}
51
52void llvm::runIRPassesDeltaPass(TestRunner &Test) {
53 runDeltaPass(Test, ExtractChunksFromModule: runPasses, Message: "Running passes");
54}
55