PassManagerBuilder.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. // llvm/Transforms/IPO/PassManagerBuilder.h - Build Standard Pass -*- C++ -*-=//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the PassManagerBuilder class, which is used to set up a
  15. // "standard" optimization sequence suitable for languages like C and C++.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
  19. #define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
  20. #include "llvm-c/Transforms/PassManagerBuilder.h"
  21. #include <functional>
  22. #include <string>
  23. #include <vector>
  24. namespace llvm {
  25. class ModuleSummaryIndex;
  26. class Pass;
  27. class TargetLibraryInfoImpl;
  28. // The old pass manager infrastructure is hidden in a legacy namespace now.
  29. namespace legacy {
  30. class FunctionPassManager;
  31. class PassManagerBase;
  32. }
  33. /// PassManagerBuilder - This class is used to set up a standard optimization
  34. /// sequence for languages like C and C++, allowing some APIs to customize the
  35. /// pass sequence in various ways. A simple example of using it would be:
  36. ///
  37. /// PassManagerBuilder Builder;
  38. /// Builder.OptLevel = 2;
  39. /// Builder.populateFunctionPassManager(FPM);
  40. /// Builder.populateModulePassManager(MPM);
  41. ///
  42. /// In addition to setting up the basic passes, PassManagerBuilder allows
  43. /// frontends to vend a plugin API, where plugins are allowed to add extensions
  44. /// to the default pass manager. They do this by specifying where in the pass
  45. /// pipeline they want to be added, along with a callback function that adds
  46. /// the pass(es). For example, a plugin that wanted to add a loop optimization
  47. /// could do something like this:
  48. ///
  49. /// static void addMyLoopPass(const PMBuilder &Builder, PassManagerBase &PM) {
  50. /// if (Builder.getOptLevel() > 2 && Builder.getOptSizeLevel() == 0)
  51. /// PM.add(createMyAwesomePass());
  52. /// }
  53. /// ...
  54. /// Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd,
  55. /// addMyLoopPass);
  56. /// ...
  57. class PassManagerBuilder {
  58. public:
  59. /// Extensions are passed to the builder itself (so they can see how it is
  60. /// configured) as well as the pass manager to add stuff to.
  61. typedef std::function<void(const PassManagerBuilder &Builder,
  62. legacy::PassManagerBase &PM)>
  63. ExtensionFn;
  64. typedef int GlobalExtensionID;
  65. /// The Optimization Level - Specify the basic optimization level.
  66. /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
  67. unsigned OptLevel;
  68. /// SizeLevel - How much we're optimizing for size.
  69. /// 0 = none, 1 = -Os, 2 = -Oz
  70. unsigned SizeLevel;
  71. /// LibraryInfo - Specifies information about the runtime library for the
  72. /// optimizer. If this is non-null, it is added to both the function and
  73. /// per-module pass pipeline.
  74. TargetLibraryInfoImpl *LibraryInfo;
  75. /// Inliner - Specifies the inliner to use. If this is non-null, it is
  76. /// added to the per-module passes.
  77. Pass *Inliner;
  78. /// The module summary index to use for exporting information from the
  79. /// regular LTO phase, for example for the CFI and devirtualization type
  80. /// tests.
  81. ModuleSummaryIndex *ExportSummary = nullptr;
  82. /// The module summary index to use for importing information to the
  83. /// thin LTO backends, for example for the CFI and devirtualization type
  84. /// tests.
  85. const ModuleSummaryIndex *ImportSummary = nullptr;
  86. bool DisableUnrollLoops;
  87. bool CallGraphProfile;
  88. bool SLPVectorize;
  89. bool LoopVectorize;
  90. bool LoopsInterleaved;
  91. bool DisableGVNLoadPRE;
  92. bool ForgetAllSCEVInLoopUnroll;
  93. bool VerifyInput;
  94. bool VerifyOutput;
  95. bool MergeFunctions;
  96. bool DivergentTarget;
  97. unsigned LicmMssaOptCap;
  98. unsigned LicmMssaNoAccForPromotionCap;
  99. public:
  100. PassManagerBuilder();
  101. ~PassManagerBuilder();
  102. private:
  103. void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
  104. void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
  105. void addVectorPasses(legacy::PassManagerBase &PM, bool IsFullLTO);
  106. public:
  107. /// populateFunctionPassManager - This fills in the function pass manager,
  108. /// which is expected to be run on each function immediately as it is
  109. /// generated. The idea is to reduce the size of the IR in memory.
  110. void populateFunctionPassManager(legacy::FunctionPassManager &FPM);
  111. /// populateModulePassManager - This sets up the primary pass manager.
  112. void populateModulePassManager(legacy::PassManagerBase &MPM);
  113. };
  114. inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
  115. return reinterpret_cast<PassManagerBuilder*>(P);
  116. }
  117. inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
  118. return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
  119. }
  120. } // end namespace llvm
  121. #endif
  122. #ifdef __GNUC__
  123. #pragma GCC diagnostic pop
  124. #endif