Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.5 KiB

  1. //===- llvm/DefaultPasses.h - Default Pass Support code --------*- 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. // This file defines the infrastructure for registering the standard pass list.
  10. // This defines sets of standard optimizations that plugins can modify and
  11. // front ends can use.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEFAULT_PASS_SUPPORT_H
  14. #define LLVM_DEFAULT_PASS_SUPPORT_H
  15. #include "llvm/PassSupport.h"
  16. namespace llvm {
  17. class PassManagerBase;
  18. /// Unique identifiers for the default standard passes. The addresses of
  19. /// these symbols are used to uniquely identify passes from the default list.
  20. namespace DefaultStandardPasses {
  21. extern unsigned char AggressiveDCEID;
  22. extern unsigned char ArgumentPromotionID;
  23. extern unsigned char BasicAliasAnalysisID;
  24. extern unsigned char CFGSimplificationID;
  25. extern unsigned char ConstantMergeID;
  26. extern unsigned char CorrelatedValuePropagationID;
  27. extern unsigned char DeadArgEliminationID;
  28. extern unsigned char DeadStoreEliminationID;
  29. extern unsigned char EarlyCSEID;
  30. extern unsigned char FunctionAttrsID;
  31. extern unsigned char FunctionInliningID;
  32. extern unsigned char GVNID;
  33. extern unsigned char GlobalDCEID;
  34. extern unsigned char GlobalOptimizerID;
  35. extern unsigned char GlobalsModRefID;
  36. extern unsigned char IPSCCPID;
  37. extern unsigned char IndVarSimplifyID;
  38. extern unsigned char InlinerPlaceholderID;
  39. extern unsigned char InstructionCombiningID;
  40. extern unsigned char JumpThreadingID;
  41. extern unsigned char LICMID;
  42. extern unsigned char LoopDeletionID;
  43. extern unsigned char LoopIdiomID;
  44. extern unsigned char LoopRotateID;
  45. extern unsigned char LoopUnrollID;
  46. extern unsigned char LoopUnswitchID;
  47. extern unsigned char MemCpyOptID;
  48. extern unsigned char PruneEHID;
  49. extern unsigned char ReassociateID;
  50. extern unsigned char SCCPID;
  51. extern unsigned char ScalarReplAggregatesID;
  52. extern unsigned char SimplifyLibCallsID;
  53. extern unsigned char StripDeadPrototypesID;
  54. extern unsigned char TailCallEliminationID;
  55. extern unsigned char TypeBasedAliasAnalysisID;
  56. }
  57. /// StandardPass - The class responsible for maintaining the lists of standard
  58. class StandardPass {
  59. friend class RegisterStandardPassLists;
  60. public:
  61. /// Predefined standard sets of passes
  62. enum StandardSet {
  63. AliasAnalysis,
  64. Function,
  65. Module,
  66. LTO
  67. };
  68. /// Flags to specify whether a pass should be enabled. Passes registered
  69. /// with the standard sets may specify a minimum optimization level and one
  70. /// or more flags that must be set when constructing the set for the pass to
  71. /// be used.
  72. enum OptimizationFlags {
  73. /// Optimize for size was requested.
  74. OptimizeSize = 1<<0,
  75. /// Allow passes which may make global module changes.
  76. UnitAtATime = 1<<1,
  77. /// UnrollLoops - Allow loop unrolling.
  78. UnrollLoops = 1<<2,
  79. /// Allow library calls to be simplified.
  80. SimplifyLibCalls = 1<<3,
  81. /// Whether the module may have code using exceptions.
  82. HaveExceptions = 1<<4,
  83. // Run an inliner pass as part of this set.
  84. RunInliner = 1<<5
  85. };
  86. enum OptimizationFlagComponents {
  87. /// The low bits are used to store the optimization level. When requesting
  88. /// passes, this should store the requested optimisation level. When
  89. /// setting passes, this should set the minimum optimization level at which
  90. /// the pass will run.
  91. OptimizationLevelMask=0xf,
  92. /// The maximum optimisation level at which the pass is run.
  93. MaxOptimizationLevelMask=0xf0,
  94. // Flags that must be set
  95. RequiredFlagMask=0xff00,
  96. // Flags that may not be set.
  97. DisallowedFlagMask=0xff0000,
  98. MaxOptimizationLevelShift=4,
  99. RequiredFlagShift=8,
  100. DisallowedFlagShift=16
  101. };
  102. /// Returns the optimisation level from a set of flags.
  103. static unsigned OptimizationLevel(unsigned flags) {
  104. return flags & OptimizationLevelMask;
  105. }
  106. /// Returns the maximum optimization level for this set of flags
  107. static unsigned MaxOptimizationLevel(unsigned flags) {
  108. return (flags & MaxOptimizationLevelMask) >> 4;
  109. }
  110. /// Constructs a set of flags from the specified minimum and maximum
  111. /// optimisation level
  112. static unsigned OptimzationFlags(unsigned minLevel=0, unsigned maxLevel=0xf,
  113. unsigned requiredFlags=0, unsigned disallowedFlags=0) {
  114. return ((minLevel & OptimizationLevelMask) |
  115. ((maxLevel<<MaxOptimizationLevelShift) & MaxOptimizationLevelMask)
  116. | ((requiredFlags<<RequiredFlagShift) & RequiredFlagMask)
  117. | ((disallowedFlags<<DisallowedFlagShift) & DisallowedFlagMask));
  118. }
  119. /// Returns the flags that must be set for this to match
  120. static unsigned RequiredFlags(unsigned flags) {
  121. return (flags & RequiredFlagMask) >> RequiredFlagShift;
  122. }
  123. /// Returns the flags that must not be set for this to match
  124. static unsigned DisallowedFlags(unsigned flags) {
  125. return (flags & DisallowedFlagMask) >> DisallowedFlagShift;
  126. }
  127. /// Register a standard pass in the specified set. If flags is non-zero,
  128. /// then the pass will only be returned when the specified flags are set.
  129. template<typename passName>
  130. class RegisterStandardPass {
  131. public:
  132. RegisterStandardPass(StandardSet set, unsigned char *runBefore=0,
  133. unsigned flags=0, unsigned char *ID=0) {
  134. // Use the pass's ID if one is not specified
  135. RegisterDefaultPass(PassInfo::NormalCtor_t(callDefaultCtor<passName>),
  136. ID ? ID : (unsigned char*)&passName::ID, runBefore, set, flags);
  137. }
  138. };
  139. /// Adds the passes from the specified set to the provided pass manager
  140. static void AddPassesFromSet(PassManagerBase *PM,
  141. StandardSet set,
  142. unsigned flags=0,
  143. bool VerifyEach=false,
  144. Pass *inliner=0);
  145. private:
  146. /// Registers the default passes. This is set by RegisterStandardPassLists
  147. /// and is called lazily.
  148. static void (*RegisterDefaultPasses)(void);
  149. /// Creates the verifier pass that is inserted when a VerifyEach is passed to
  150. /// AddPassesFromSet()
  151. static Pass* (*CreateVerifierPass)(void);
  152. /// Registers the pass
  153. static void RegisterDefaultPass(PassInfo::NormalCtor_t constructor,
  154. unsigned char *newPass,
  155. unsigned char *oldPass,
  156. StandardSet set,
  157. unsigned flags=0);
  158. };
  159. } // namespace llvm
  160. #endif