| 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 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | extern cl::OptionCategory LLVMReduceOptions; |
| 17 | |
| 18 | static 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 | |
| 26 | void 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, 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 | report_fatal_error(Err: std::move(Err), gen_crash_diag: false); |
| 47 | MPM.run(IR&: Program, AM&: MAM); |
| 48 | } |
| 49 | |