RunIRPasses.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "RunIRPasses.h"
  9. #include "Delta.h"
  10. #include "llvm/Passes/PassBuilder.h"
  11. #include "llvm/Support/CommandLine.h"
  12. #include "llvm/Support/ErrorHandling.h"
  13. using namespace llvm;
  14. extern cl::OptionCategory LLVMReduceOptions;
  15. static cl::opt<std::string> PassPipeline(
  16. "ir-passes",
  17. cl::desc("A textual description of the pass pipeline, same as "
  18. "what's passed to `opt -passes`."),
  19. cl::init("function(sroa,instcombine,gvn,simplifycfg,infer-address-spaces)"),
  20. cl::cat(LLVMReduceOptions));
  21. static void runPasses(Oracle &O, ReducerWorkItem &WorkItem) {
  22. Module &Program = WorkItem.getModule();
  23. LoopAnalysisManager LAM;
  24. FunctionAnalysisManager FAM;
  25. CGSCCAnalysisManager CGAM;
  26. ModuleAnalysisManager MAM;
  27. PassInstrumentationCallbacks PIC;
  28. PIC.registerShouldRunOptionalPassCallback(
  29. [&](StringRef, Any) { return !O.shouldKeep(); });
  30. PassBuilder PB(nullptr, PipelineTuningOptions(), std::nullopt, &PIC);
  31. PB.registerModuleAnalyses(MAM);
  32. PB.registerCGSCCAnalyses(CGAM);
  33. PB.registerFunctionAnalyses(FAM);
  34. PB.registerLoopAnalyses(LAM);
  35. PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
  36. ModulePassManager MPM;
  37. if (auto Err = PB.parsePassPipeline(MPM, PassPipeline)) {
  38. errs() << toString(std::move(Err)) << "\n";
  39. report_fatal_error("Error constructing pass pipeline");
  40. }
  41. MPM.run(Program, MAM);
  42. }
  43. void llvm::runIRPassesDeltaPass(TestRunner &Test) {
  44. runDeltaPass(Test, runPasses, "Running passes");
  45. }