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.

563 lines
21 KiB

  1. //===-- Passes.h - Target independent code generation passes ----*- 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. //
  10. // This file defines interfaces to access the target independent code generation
  11. // passes provided by the LLVM backend.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CODEGEN_PASSES_H
  15. #define LLVM_CODEGEN_PASSES_H
  16. #include "llvm/Pass.h"
  17. #include "llvm/Target/TargetMachine.h"
  18. #include <string>
  19. namespace llvm {
  20. class FunctionPass;
  21. class MachineFunctionPass;
  22. class PassInfo;
  23. class PassManagerBase;
  24. class TargetLoweringBase;
  25. class TargetLowering;
  26. class TargetRegisterClass;
  27. class raw_ostream;
  28. }
  29. namespace llvm {
  30. class PassConfigImpl;
  31. /// Discriminated union of Pass ID types.
  32. ///
  33. /// The PassConfig API prefers dealing with IDs because they are safer and more
  34. /// efficient. IDs decouple configuration from instantiation. This way, when a
  35. /// pass is overriden, it isn't unnecessarily instantiated. It is also unsafe to
  36. /// refer to a Pass pointer after adding it to a pass manager, which deletes
  37. /// redundant pass instances.
  38. ///
  39. /// However, it is convient to directly instantiate target passes with
  40. /// non-default ctors. These often don't have a registered PassInfo. Rather than
  41. /// force all target passes to implement the pass registry boilerplate, allow
  42. /// the PassConfig API to handle either type.
  43. ///
  44. /// AnalysisID is sadly char*, so PointerIntPair won't work.
  45. class IdentifyingPassPtr {
  46. union {
  47. AnalysisID ID;
  48. Pass *P;
  49. };
  50. bool IsInstance;
  51. public:
  52. IdentifyingPassPtr() : P(0), IsInstance(false) {}
  53. IdentifyingPassPtr(AnalysisID IDPtr) : ID(IDPtr), IsInstance(false) {}
  54. IdentifyingPassPtr(Pass *InstancePtr) : P(InstancePtr), IsInstance(true) {}
  55. bool isValid() const { return P; }
  56. bool isInstance() const { return IsInstance; }
  57. AnalysisID getID() const {
  58. assert(!IsInstance && "Not a Pass ID");
  59. return ID;
  60. }
  61. Pass *getInstance() const {
  62. assert(IsInstance && "Not a Pass Instance");
  63. return P;
  64. }
  65. };
  66. template <> struct isPodLike<IdentifyingPassPtr> {
  67. static const bool value = true;
  68. };
  69. /// Target-Independent Code Generator Pass Configuration Options.
  70. ///
  71. /// This is an ImmutablePass solely for the purpose of exposing CodeGen options
  72. /// to the internals of other CodeGen passes.
  73. class TargetPassConfig : public ImmutablePass {
  74. public:
  75. /// Pseudo Pass IDs. These are defined within TargetPassConfig because they
  76. /// are unregistered pass IDs. They are only useful for use with
  77. /// TargetPassConfig APIs to identify multiple occurrences of the same pass.
  78. ///
  79. /// EarlyTailDuplicate - A clone of the TailDuplicate pass that runs early
  80. /// during codegen, on SSA form.
  81. static char EarlyTailDuplicateID;
  82. /// PostRAMachineLICM - A clone of the LICM pass that runs during late machine
  83. /// optimization after regalloc.
  84. static char PostRAMachineLICMID;
  85. private:
  86. PassManagerBase *PM;
  87. AnalysisID StartAfter;
  88. AnalysisID StopAfter;
  89. bool Started;
  90. bool Stopped;
  91. protected:
  92. TargetMachine *TM;
  93. PassConfigImpl *Impl; // Internal data structures
  94. bool Initialized; // Flagged after all passes are configured.
  95. // Target Pass Options
  96. // Targets provide a default setting, user flags override.
  97. //
  98. bool DisableVerify;
  99. /// Default setting for -enable-tail-merge on this target.
  100. bool EnableTailMerge;
  101. public:
  102. TargetPassConfig(TargetMachine *tm, PassManagerBase &pm);
  103. // Dummy constructor.
  104. TargetPassConfig();
  105. virtual ~TargetPassConfig();
  106. static char ID;
  107. /// Get the right type of TargetMachine for this target.
  108. template<typename TMC> TMC &getTM() const {
  109. return *static_cast<TMC*>(TM);
  110. }
  111. const TargetLowering *getTargetLowering() const {
  112. return TM->getTargetLowering();
  113. }
  114. //
  115. void setInitialized() { Initialized = true; }
  116. CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); }
  117. /// setStartStopPasses - Set the StartAfter and StopAfter passes to allow
  118. /// running only a portion of the normal code-gen pass sequence. If the
  119. /// Start pass ID is zero, then compilation will begin at the normal point;
  120. /// otherwise, clear the Started flag to indicate that passes should not be
  121. /// added until the starting pass is seen. If the Stop pass ID is zero,
  122. /// then compilation will continue to the end.
  123. void setStartStopPasses(AnalysisID Start, AnalysisID Stop) {
  124. StartAfter = Start;
  125. StopAfter = Stop;
  126. Started = (StartAfter == 0);
  127. }
  128. void setDisableVerify(bool Disable) { setOpt(DisableVerify, Disable); }
  129. bool getEnableTailMerge() const { return EnableTailMerge; }
  130. void setEnableTailMerge(bool Enable) { setOpt(EnableTailMerge, Enable); }
  131. /// Allow the target to override a specific pass without overriding the pass
  132. /// pipeline. When passes are added to the standard pipeline at the
  133. /// point where StandardID is expected, add TargetID in its place.
  134. void substitutePass(AnalysisID StandardID, IdentifyingPassPtr TargetID);
  135. /// Insert InsertedPassID pass after TargetPassID pass.
  136. void insertPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID);
  137. /// Allow the target to enable a specific standard pass by default.
  138. void enablePass(AnalysisID PassID) { substitutePass(PassID, PassID); }
  139. /// Allow the target to disable a specific standard pass by default.
  140. void disablePass(AnalysisID PassID) {
  141. substitutePass(PassID, IdentifyingPassPtr());
  142. }
  143. /// Return the pass substituted for StandardID by the target.
  144. /// If no substitution exists, return StandardID.
  145. IdentifyingPassPtr getPassSubstitution(AnalysisID StandardID) const;
  146. /// Return true if the optimized regalloc pipeline is enabled.
  147. bool getOptimizeRegAlloc() const;
  148. /// Add common target configurable passes that perform LLVM IR to IR
  149. /// transforms following machine independent optimization.
  150. virtual void addIRPasses();
  151. /// Add passes to lower exception handling for the code generator.
  152. void addPassesToHandleExceptions();
  153. /// Add pass to prepare the LLVM IR for code generation. This should be done
  154. /// before exception handling preparation passes.
  155. virtual void addCodeGenPrepare();
  156. /// Add common passes that perform LLVM IR to IR transforms in preparation for
  157. /// instruction selection.
  158. virtual void addISelPrepare();
  159. /// addInstSelector - This method should install an instruction selector pass,
  160. /// which converts from LLVM code to machine instructions.
  161. virtual bool addInstSelector() {
  162. return true;
  163. }
  164. /// Add the complete, standard set of LLVM CodeGen passes.
  165. /// Fully developed targets will not generally override this.
  166. virtual void addMachinePasses();
  167. protected:
  168. // Helper to verify the analysis is really immutable.
  169. void setOpt(bool &Opt, bool Val);
  170. /// Methods with trivial inline returns are convenient points in the common
  171. /// codegen pass pipeline where targets may insert passes. Methods with
  172. /// out-of-line standard implementations are major CodeGen stages called by
  173. /// addMachinePasses. Some targets may override major stages when inserting
  174. /// passes is insufficient, but maintaining overriden stages is more work.
  175. ///
  176. /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
  177. /// passes (which are run just before instruction selector).
  178. virtual bool addPreISel() {
  179. return true;
  180. }
  181. /// addMachineSSAOptimization - Add standard passes that optimize machine
  182. /// instructions in SSA form.
  183. virtual void addMachineSSAOptimization();
  184. /// Add passes that optimize instruction level parallelism for out-of-order
  185. /// targets. These passes are run while the machine code is still in SSA
  186. /// form, so they can use MachineTraceMetrics to control their heuristics.
  187. ///
  188. /// All passes added here should preserve the MachineDominatorTree,
  189. /// MachineLoopInfo, and MachineTraceMetrics analyses.
  190. virtual bool addILPOpts() {
  191. return false;
  192. }
  193. /// addPreRegAlloc - This method may be implemented by targets that want to
  194. /// run passes immediately before register allocation. This should return
  195. /// true if -print-machineinstrs should print after these passes.
  196. virtual bool addPreRegAlloc() {
  197. return false;
  198. }
  199. /// createTargetRegisterAllocator - Create the register allocator pass for
  200. /// this target at the current optimization level.
  201. virtual FunctionPass *createTargetRegisterAllocator(bool Optimized);
  202. /// addFastRegAlloc - Add the minimum set of target-independent passes that
  203. /// are required for fast register allocation.
  204. virtual void addFastRegAlloc(FunctionPass *RegAllocPass);
  205. /// addOptimizedRegAlloc - Add passes related to register allocation.
  206. /// LLVMTargetMachine provides standard regalloc passes for most targets.
  207. virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass);
  208. /// addPreRewrite - Add passes to the optimized register allocation pipeline
  209. /// after register allocation is complete, but before virtual registers are
  210. /// rewritten to physical registers.
  211. ///
  212. /// These passes must preserve VirtRegMap and LiveIntervals, and when running
  213. /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
  214. /// When these passes run, VirtRegMap contains legal physreg assignments for
  215. /// all virtual registers.
  216. virtual bool addPreRewrite() {
  217. return false;
  218. }
  219. /// addPostRegAlloc - This method may be implemented by targets that want to
  220. /// run passes after register allocation pass pipeline but before
  221. /// prolog-epilog insertion. This should return true if -print-machineinstrs
  222. /// should print after these passes.
  223. virtual bool addPostRegAlloc() {
  224. return false;
  225. }
  226. /// Add passes that optimize machine instructions after register allocation.
  227. virtual void addMachineLateOptimization();
  228. /// addPreSched2 - This method may be implemented by targets that want to
  229. /// run passes after prolog-epilog insertion and before the second instruction
  230. /// scheduling pass. This should return true if -print-machineinstrs should
  231. /// print after these passes.
  232. virtual bool addPreSched2() {
  233. return false;
  234. }
  235. /// addGCPasses - Add late codegen passes that analyze code for garbage
  236. /// collection. This should return true if GC info should be printed after
  237. /// these passes.
  238. virtual bool addGCPasses();
  239. /// Add standard basic block placement passes.
  240. virtual void addBlockPlacement();
  241. /// addPreEmitPass - This pass may be implemented by targets that want to run
  242. /// passes immediately before machine code is emitted. This should return
  243. /// true if -print-machineinstrs should print out the code after the passes.
  244. virtual bool addPreEmitPass() {
  245. return false;
  246. }
  247. /// Utilities for targets to add passes to the pass manager.
  248. ///
  249. /// Add a CodeGen pass at this point in the pipeline after checking overrides.
  250. /// Return the pass that was added, or zero if no pass was added.
  251. AnalysisID addPass(AnalysisID PassID);
  252. /// Add a pass to the PassManager if that pass is supposed to be run, as
  253. /// determined by the StartAfter and StopAfter options.
  254. void addPass(Pass *P);
  255. /// addMachinePasses helper to create the target-selected or overriden
  256. /// regalloc pass.
  257. FunctionPass *createRegAllocPass(bool Optimized);
  258. /// printAndVerify - Add a pass to dump then verify the machine function, if
  259. /// those steps are enabled.
  260. ///
  261. void printAndVerify(const char *Banner);
  262. };
  263. } // namespace llvm
  264. /// List of target independent CodeGen pass IDs.
  265. namespace llvm {
  266. /// \brief Create a basic TargetTransformInfo analysis pass.
  267. ///
  268. /// This pass implements the target transform info analysis using the target
  269. /// independent information available to the LLVM code generator.
  270. ImmutablePass *
  271. createBasicTargetTransformInfoPass(const TargetLoweringBase *TLI);
  272. /// createUnreachableBlockEliminationPass - The LLVM code generator does not
  273. /// work well with unreachable basic blocks (what live ranges make sense for a
  274. /// block that cannot be reached?). As such, a code generator should either
  275. /// not instruction select unreachable blocks, or run this pass as its
  276. /// last LLVM modifying pass to clean up blocks that are not reachable from
  277. /// the entry block.
  278. FunctionPass *createUnreachableBlockEliminationPass();
  279. /// MachineFunctionPrinter pass - This pass prints out the machine function to
  280. /// the given stream as a debugging tool.
  281. MachineFunctionPass *
  282. createMachineFunctionPrinterPass(raw_ostream &OS,
  283. const std::string &Banner ="");
  284. /// MachineLoopInfo - This pass is a loop analysis pass.
  285. extern char &MachineLoopInfoID;
  286. /// MachineDominators - This pass is a machine dominators analysis pass.
  287. extern char &MachineDominatorsID;
  288. /// EdgeBundles analysis - Bundle machine CFG edges.
  289. extern char &EdgeBundlesID;
  290. /// LiveVariables pass - This pass computes the set of blocks in which each
  291. /// variable is life and sets machine operand kill flags.
  292. extern char &LiveVariablesID;
  293. /// PHIElimination - This pass eliminates machine instruction PHI nodes
  294. /// by inserting copy instructions. This destroys SSA information, but is the
  295. /// desired input for some register allocators. This pass is "required" by
  296. /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
  297. extern char &PHIEliminationID;
  298. /// StrongPHIElimination - This pass eliminates machine instruction PHI
  299. /// nodes by inserting copy instructions. This destroys SSA information, but
  300. /// is the desired input for some register allocators. This pass is
  301. /// "required" by these register allocator like this:
  302. /// AU.addRequiredID(PHIEliminationID);
  303. /// This pass is still in development
  304. extern char &StrongPHIEliminationID;
  305. /// LiveIntervals - This analysis keeps track of the live ranges of virtual
  306. /// and physical registers.
  307. extern char &LiveIntervalsID;
  308. /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
  309. extern char &LiveStacksID;
  310. /// TwoAddressInstruction - This pass reduces two-address instructions to
  311. /// use two operands. This destroys SSA information but it is desired by
  312. /// register allocators.
  313. extern char &TwoAddressInstructionPassID;
  314. /// ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
  315. extern char &ProcessImplicitDefsID;
  316. /// RegisterCoalescer - This pass merges live ranges to eliminate copies.
  317. extern char &RegisterCoalescerID;
  318. /// MachineScheduler - This pass schedules machine instructions.
  319. extern char &MachineSchedulerID;
  320. /// SpillPlacement analysis. Suggest optimal placement of spill code between
  321. /// basic blocks.
  322. extern char &SpillPlacementID;
  323. /// VirtRegRewriter pass. Rewrite virtual registers to physical registers as
  324. /// assigned in VirtRegMap.
  325. extern char &VirtRegRewriterID;
  326. /// UnreachableMachineBlockElimination - This pass removes unreachable
  327. /// machine basic blocks.
  328. extern char &UnreachableMachineBlockElimID;
  329. /// DeadMachineInstructionElim - This pass removes dead machine instructions.
  330. extern char &DeadMachineInstructionElimID;
  331. /// FastRegisterAllocation Pass - This pass register allocates as fast as
  332. /// possible. It is best suited for debug code where live ranges are short.
  333. ///
  334. FunctionPass *createFastRegisterAllocator();
  335. /// BasicRegisterAllocation Pass - This pass implements a degenerate global
  336. /// register allocator using the basic regalloc framework.
  337. ///
  338. FunctionPass *createBasicRegisterAllocator();
  339. /// Greedy register allocation pass - This pass implements a global register
  340. /// allocator for optimized builds.
  341. ///
  342. FunctionPass *createGreedyRegisterAllocator();
  343. /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
  344. /// Quadratic Prograaming (PBQP) based register allocator.
  345. ///
  346. FunctionPass *createDefaultPBQPRegisterAllocator();
  347. /// PrologEpilogCodeInserter - This pass inserts prolog and epilog code,
  348. /// and eliminates abstract frame references.
  349. extern char &PrologEpilogCodeInserterID;
  350. /// ExpandPostRAPseudos - This pass expands pseudo instructions after
  351. /// register allocation.
  352. extern char &ExpandPostRAPseudosID;
  353. /// createPostRAScheduler - This pass performs post register allocation
  354. /// scheduling.
  355. extern char &PostRASchedulerID;
  356. /// BranchFolding - This pass performs machine code CFG based
  357. /// optimizations to delete branches to branches, eliminate branches to
  358. /// successor blocks (creating fall throughs), and eliminating branches over
  359. /// branches.
  360. extern char &BranchFolderPassID;
  361. /// MachineFunctionPrinterPass - This pass prints out MachineInstr's.
  362. extern char &MachineFunctionPrinterPassID;
  363. /// TailDuplicate - Duplicate blocks with unconditional branches
  364. /// into tails of their predecessors.
  365. extern char &TailDuplicateID;
  366. /// MachineTraceMetrics - This pass computes critical path and CPU resource
  367. /// usage in an ensemble of traces.
  368. extern char &MachineTraceMetricsID;
  369. /// EarlyIfConverter - This pass performs if-conversion on SSA form by
  370. /// inserting cmov instructions.
  371. extern char &EarlyIfConverterID;
  372. /// StackSlotColoring - This pass performs stack coloring and merging.
  373. /// It merges disjoint allocas to reduce the stack size.
  374. extern char &StackColoringID;
  375. /// IfConverter - This pass performs machine code if conversion.
  376. extern char &IfConverterID;
  377. /// MachineBlockPlacement - This pass places basic blocks based on branch
  378. /// probabilities.
  379. extern char &MachineBlockPlacementID;
  380. /// MachineBlockPlacementStats - This pass collects statistics about the
  381. /// basic block placement using branch probabilities and block frequency
  382. /// information.
  383. extern char &MachineBlockPlacementStatsID;
  384. /// GCLowering Pass - Performs target-independent LLVM IR transformations for
  385. /// highly portable strategies.
  386. ///
  387. FunctionPass *createGCLoweringPass();
  388. /// GCMachineCodeAnalysis - Target-independent pass to mark safe points
  389. /// in machine code. Must be added very late during code generation, just
  390. /// prior to output, and importantly after all CFG transformations (such as
  391. /// branch folding).
  392. extern char &GCMachineCodeAnalysisID;
  393. /// Creates a pass to print GC metadata.
  394. ///
  395. FunctionPass *createGCInfoPrinter(raw_ostream &OS);
  396. /// MachineCSE - This pass performs global CSE on machine instructions.
  397. extern char &MachineCSEID;
  398. /// MachineLICM - This pass performs LICM on machine instructions.
  399. extern char &MachineLICMID;
  400. /// MachineSinking - This pass performs sinking on machine instructions.
  401. extern char &MachineSinkingID;
  402. /// MachineCopyPropagation - This pass performs copy propagation on
  403. /// machine instructions.
  404. extern char &MachineCopyPropagationID;
  405. /// PeepholeOptimizer - This pass performs peephole optimizations -
  406. /// like extension and comparison eliminations.
  407. extern char &PeepholeOptimizerID;
  408. /// OptimizePHIs - This pass optimizes machine instruction PHIs
  409. /// to take advantage of opportunities created during DAG legalization.
  410. extern char &OptimizePHIsID;
  411. /// StackSlotColoring - This pass performs stack slot coloring.
  412. extern char &StackSlotColoringID;
  413. /// createStackProtectorPass - This pass adds stack protectors to functions.
  414. ///
  415. FunctionPass *createStackProtectorPass(const TargetLoweringBase *tli);
  416. /// createMachineVerifierPass - This pass verifies cenerated machine code
  417. /// instructions for correctness.
  418. ///
  419. FunctionPass *createMachineVerifierPass(const char *Banner = 0);
  420. /// createDwarfEHPass - This pass mulches exception handling code into a form
  421. /// adapted to code generation. Required if using dwarf exception handling.
  422. FunctionPass *createDwarfEHPass(const TargetMachine *tm);
  423. /// createSjLjEHPreparePass - This pass adapts exception handling code to use
  424. /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
  425. ///
  426. FunctionPass *createSjLjEHPreparePass(const TargetLoweringBase *tli);
  427. /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
  428. /// slots relative to one another and allocates base registers to access them
  429. /// when it is estimated by the target to be out of range of normal frame
  430. /// pointer or stack pointer index addressing.
  431. extern char &LocalStackSlotAllocationID;
  432. /// ExpandISelPseudos - This pass expands pseudo-instructions.
  433. extern char &ExpandISelPseudosID;
  434. /// createExecutionDependencyFixPass - This pass fixes execution time
  435. /// problems with dependent instructions, such as switching execution
  436. /// domains to match.
  437. ///
  438. /// The pass will examine instructions using and defining registers in RC.
  439. ///
  440. FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
  441. /// UnpackMachineBundles - This pass unpack machine instruction bundles.
  442. extern char &UnpackMachineBundlesID;
  443. /// FinalizeMachineBundles - This pass finalize machine instruction
  444. /// bundles (created earlier, e.g. during pre-RA scheduling).
  445. extern char &FinalizeMachineBundlesID;
  446. } // End llvm namespace
  447. #endif