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 "llvm/Passes/PassBuilder.h"
11#include "llvm/Support/CommandLine.h"
12#include "llvm/Support/ErrorHandling.h"
13
14using namespace llvm;
15
16extern cl::OptionCategory LLVMReduceOptions;
17
18static cl::opt<std::string>
19 PassPipeline("ir-passes",
20 cl::desc("A textual description of the pass pipeline, same as "
21 "what's passed to `opt -passes`."),
22 cl::init(Val: "function(sroa,instcombine<no-verify-fixpoint>,gvn,"
23 "simplifycfg,infer-address-spaces)"),
24 cl::cat(LLVMReduceOptions));
25
26void llvm::runIRPassesDeltaPass(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, IRUnitRef) { return !O.shouldKeep(); });
36 PassBuilder PB(Program.getContext(), nullptr, std::nullopt, std::nullopt,
37 &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, PipelineText: PassPipeline))
47 report_fatal_error(Err: std::move(Err), gen_crash_diag: false);
48 MPM.run(IR&: Program, AM&: MAM);
49}
50