PassBuilder.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. /// \file
  10. ///
  11. /// Interfaces for registering analysis passes, producing common pass manager
  12. /// configurations, and parsing of pass pipelines.
  13. ///
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_PASSES_PASSBUILDER_H
  16. #define LLVM_PASSES_PASSBUILDER_H
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/Analysis/CGSCCPassManager.h"
  19. #include "llvm/IR/PassManager.h"
  20. namespace llvm {
  21. class TargetMachine;
  22. /// \brief This class provides access to building LLVM's passes.
  23. ///
  24. /// It's members provide the baseline state available to passes during their
  25. /// construction. The \c PassRegistry.def file specifies how to construct all
  26. /// of the built-in passes, and those may reference these members during
  27. /// construction.
  28. class PassBuilder {
  29. TargetMachine *TM;
  30. public:
  31. explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
  32. /// \brief Registers all available module analysis passes.
  33. ///
  34. /// This is an interface that can be used to populate a \c
  35. /// ModuleAnalysisManager with all registered module analyses. Callers can
  36. /// still manually register any additional analyses.
  37. void registerModuleAnalyses(ModuleAnalysisManager &MAM);
  38. /// \brief Registers all available CGSCC analysis passes.
  39. ///
  40. /// This is an interface that can be used to populate a \c CGSCCAnalysisManager
  41. /// with all registered CGSCC analyses. Callers can still manually register any
  42. /// additional analyses.
  43. void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
  44. /// \brief Registers all available function analysis passes.
  45. ///
  46. /// This is an interface that can be used to populate a \c
  47. /// FunctionAnalysisManager with all registered function analyses. Callers can
  48. /// still manually register any additional analyses.
  49. void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
  50. /// \brief Parse a textual pass pipeline description into a \c ModulePassManager.
  51. ///
  52. /// The format of the textual pass pipeline description looks something like:
  53. ///
  54. /// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...)
  55. ///
  56. /// Pass managers have ()s describing the nest structure of passes. All passes
  57. /// are comma separated. As a special shortcut, if the very first pass is not
  58. /// a module pass (as a module pass manager is), this will automatically form
  59. /// the shortest stack of pass managers that allow inserting that first pass.
  60. /// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes
  61. /// 'lpassN', all of these are valid:
  62. ///
  63. /// fpass1,fpass2,fpass3
  64. /// cgpass1,cgpass2,cgpass3
  65. /// lpass1,lpass2,lpass3
  66. ///
  67. /// And they are equivalent to the following (resp.):
  68. ///
  69. /// module(function(fpass1,fpass2,fpass3))
  70. /// module(cgscc(cgpass1,cgpass2,cgpass3))
  71. /// module(function(loop(lpass1,lpass2,lpass3)))
  72. ///
  73. /// This shortcut is especially useful for debugging and testing small pass
  74. /// combinations. Note that these shortcuts don't introduce any other magic. If
  75. /// the sequence of passes aren't all the exact same kind of pass, it will be
  76. /// an error. You cannot mix different levels implicitly, you must explicitly
  77. /// form a pass manager in which to nest passes.
  78. bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
  79. bool VerifyEachPass = true, bool DebugLogging = false);
  80. private:
  81. bool parseModulePassName(ModulePassManager &MPM, StringRef Name);
  82. bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name);
  83. bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name);
  84. bool parseFunctionPassPipeline(FunctionPassManager &FPM,
  85. StringRef &PipelineText, bool VerifyEachPass,
  86. bool DebugLogging);
  87. bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
  88. bool VerifyEachPass, bool DebugLogging);
  89. bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
  90. bool VerifyEachPass, bool DebugLogging);
  91. };
  92. }
  93. #endif