Passes.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 <functional>
  19. #include <string>
  20. namespace llvm {
  21. class MachineFunctionPass;
  22. class PassConfigImpl;
  23. class PassInfo;
  24. class ScheduleDAGInstrs;
  25. class TargetLowering;
  26. class TargetLoweringBase;
  27. class TargetRegisterClass;
  28. class raw_ostream;
  29. struct MachineSchedContext;
  30. // The old pass manager infrastructure is hidden in a legacy namespace now.
  31. namespace legacy {
  32. class PassManagerBase;
  33. }
  34. using legacy::PassManagerBase;
  35. /// Discriminated union of Pass ID types.
  36. ///
  37. /// The PassConfig API prefers dealing with IDs because they are safer and more
  38. /// efficient. IDs decouple configuration from instantiation. This way, when a
  39. /// pass is overriden, it isn't unnecessarily instantiated. It is also unsafe to
  40. /// refer to a Pass pointer after adding it to a pass manager, which deletes
  41. /// redundant pass instances.
  42. ///
  43. /// However, it is convient to directly instantiate target passes with
  44. /// non-default ctors. These often don't have a registered PassInfo. Rather than
  45. /// force all target passes to implement the pass registry boilerplate, allow
  46. /// the PassConfig API to handle either type.
  47. ///
  48. /// AnalysisID is sadly char*, so PointerIntPair won't work.
  49. class IdentifyingPassPtr {
  50. union {
  51. AnalysisID ID;
  52. Pass *P;
  53. };
  54. bool IsInstance;
  55. public:
  56. IdentifyingPassPtr() : P(nullptr), IsInstance(false) {}
  57. IdentifyingPassPtr(AnalysisID IDPtr) : ID(IDPtr), IsInstance(false) {}
  58. IdentifyingPassPtr(Pass *InstancePtr) : P(InstancePtr), IsInstance(true) {}
  59. bool isValid() const { return P; }
  60. bool isInstance() const { return IsInstance; }
  61. AnalysisID getID() const {
  62. assert(!IsInstance && "Not a Pass ID");
  63. return ID;
  64. }
  65. Pass *getInstance() const {
  66. assert(IsInstance && "Not a Pass Instance");
  67. return P;
  68. }
  69. };
  70. template <> struct isPodLike<IdentifyingPassPtr> {
  71. static const bool value = true;
  72. };
  73. /// Target-Independent Code Generator Pass Configuration Options.
  74. ///
  75. /// This is an ImmutablePass solely for the purpose of exposing CodeGen options
  76. /// to the internals of other CodeGen passes.
  77. class TargetPassConfig : public ImmutablePass {
  78. public:
  79. /// Pseudo Pass IDs. These are defined within TargetPassConfig because they
  80. /// are unregistered pass IDs. They are only useful for use with
  81. /// TargetPassConfig APIs to identify multiple occurrences of the same pass.
  82. ///
  83. /// EarlyTailDuplicate - A clone of the TailDuplicate pass that runs early
  84. /// during codegen, on SSA form.
  85. static char EarlyTailDuplicateID;
  86. /// PostRAMachineLICM - A clone of the LICM pass that runs during late machine
  87. /// optimization after regalloc.
  88. static char PostRAMachineLICMID;
  89. private:
  90. PassManagerBase *PM;
  91. AnalysisID StartBefore, StartAfter;
  92. AnalysisID StopAfter;
  93. bool Started;
  94. bool Stopped;
  95. bool AddingMachinePasses;
  96. protected:
  97. TargetMachine *TM;
  98. PassConfigImpl *Impl; // Internal data structures
  99. bool Initialized; // Flagged after all passes are configured.
  100. // Target Pass Options
  101. // Targets provide a default setting, user flags override.
  102. //
  103. bool DisableVerify;
  104. /// Default setting for -enable-tail-merge on this target.
  105. bool EnableTailMerge;
  106. /// Default setting for -enable-shrink-wrap on this target.
  107. bool EnableShrinkWrap;
  108. public:
  109. TargetPassConfig(TargetMachine *tm, PassManagerBase &pm);
  110. // Dummy constructor.
  111. TargetPassConfig();
  112. ~TargetPassConfig() override;
  113. static char ID;
  114. /// Get the right type of TargetMachine for this target.
  115. template<typename TMC> TMC &getTM() const {
  116. return *static_cast<TMC*>(TM);
  117. }
  118. //
  119. void setInitialized() { Initialized = true; }
  120. CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); }
  121. /// Set the StartAfter, StartBefore and StopAfter passes to allow running only
  122. /// a portion of the normal code-gen pass sequence.
  123. ///
  124. /// If the StartAfter and StartBefore pass ID is zero, then compilation will
  125. /// begin at the normal point; otherwise, clear the Started flag to indicate
  126. /// that passes should not be added until the starting pass is seen. If the
  127. /// Stop pass ID is zero, then compilation will continue to the end.
  128. ///
  129. /// This function expects that at least one of the StartAfter or the
  130. /// StartBefore pass IDs is null.
  131. void setStartStopPasses(AnalysisID StartBefore, AnalysisID StartAfter,
  132. AnalysisID StopAfter) {
  133. if (StartAfter)
  134. assert(!StartBefore && "Start after and start before passes are given");
  135. this->StartBefore = StartBefore;
  136. this->StartAfter = StartAfter;
  137. this->StopAfter = StopAfter;
  138. Started = (StartAfter == nullptr) && (StartBefore == nullptr);
  139. }
  140. void setDisableVerify(bool Disable) { setOpt(DisableVerify, Disable); }
  141. bool getEnableTailMerge() const { return EnableTailMerge; }
  142. void setEnableTailMerge(bool Enable) { setOpt(EnableTailMerge, Enable); }
  143. /// Allow the target to override a specific pass without overriding the pass
  144. /// pipeline. When passes are added to the standard pipeline at the
  145. /// point where StandardID is expected, add TargetID in its place.
  146. void substitutePass(AnalysisID StandardID, IdentifyingPassPtr TargetID);
  147. /// Insert InsertedPassID pass after TargetPassID pass.
  148. void insertPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID);
  149. /// Allow the target to enable a specific standard pass by default.
  150. void enablePass(AnalysisID PassID) { substitutePass(PassID, PassID); }
  151. /// Allow the target to disable a specific standard pass by default.
  152. void disablePass(AnalysisID PassID) {
  153. substitutePass(PassID, IdentifyingPassPtr());
  154. }
  155. /// Return the pass substituted for StandardID by the target.
  156. /// If no substitution exists, return StandardID.
  157. IdentifyingPassPtr getPassSubstitution(AnalysisID StandardID) const;
  158. /// Return true if the optimized regalloc pipeline is enabled.
  159. bool getOptimizeRegAlloc() const;
  160. /// Return true if shrink wrapping is enabled.
  161. bool getEnableShrinkWrap() const;
  162. /// Return true if the default global register allocator is in use and
  163. /// has not be overriden on the command line with '-regalloc=...'
  164. bool usingDefaultRegAlloc() const;
  165. /// Add common target configurable passes that perform LLVM IR to IR
  166. /// transforms following machine independent optimization.
  167. virtual void addIRPasses();
  168. /// Add passes to lower exception handling for the code generator.
  169. void addPassesToHandleExceptions();
  170. /// Add pass to prepare the LLVM IR for code generation. This should be done
  171. /// before exception handling preparation passes.
  172. virtual void addCodeGenPrepare();
  173. /// Add common passes that perform LLVM IR to IR transforms in preparation for
  174. /// instruction selection.
  175. virtual void addISelPrepare();
  176. /// addInstSelector - This method should install an instruction selector pass,
  177. /// which converts from LLVM code to machine instructions.
  178. virtual bool addInstSelector() {
  179. return true;
  180. }
  181. /// Add the complete, standard set of LLVM CodeGen passes.
  182. /// Fully developed targets will not generally override this.
  183. virtual void addMachinePasses();
  184. /// Create an instance of ScheduleDAGInstrs to be run within the standard
  185. /// MachineScheduler pass for this function and target at the current
  186. /// optimization level.
  187. ///
  188. /// This can also be used to plug a new MachineSchedStrategy into an instance
  189. /// of the standard ScheduleDAGMI:
  190. /// return new ScheduleDAGMI(C, make_unique<MyStrategy>(C), /* IsPostRA= */false)
  191. ///
  192. /// Return NULL to select the default (generic) machine scheduler.
  193. virtual ScheduleDAGInstrs *
  194. createMachineScheduler(MachineSchedContext *C) const {
  195. return nullptr;
  196. }
  197. /// Similar to createMachineScheduler but used when postRA machine scheduling
  198. /// is enabled.
  199. virtual ScheduleDAGInstrs *
  200. createPostMachineScheduler(MachineSchedContext *C) const {
  201. return nullptr;
  202. }
  203. protected:
  204. // Helper to verify the analysis is really immutable.
  205. void setOpt(bool &Opt, bool Val);
  206. /// Methods with trivial inline returns are convenient points in the common
  207. /// codegen pass pipeline where targets may insert passes. Methods with
  208. /// out-of-line standard implementations are major CodeGen stages called by
  209. /// addMachinePasses. Some targets may override major stages when inserting
  210. /// passes is insufficient, but maintaining overriden stages is more work.
  211. ///
  212. /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
  213. /// passes (which are run just before instruction selector).
  214. virtual bool addPreISel() {
  215. return true;
  216. }
  217. /// addMachineSSAOptimization - Add standard passes that optimize machine
  218. /// instructions in SSA form.
  219. virtual void addMachineSSAOptimization();
  220. /// Add passes that optimize instruction level parallelism for out-of-order
  221. /// targets. These passes are run while the machine code is still in SSA
  222. /// form, so they can use MachineTraceMetrics to control their heuristics.
  223. ///
  224. /// All passes added here should preserve the MachineDominatorTree,
  225. /// MachineLoopInfo, and MachineTraceMetrics analyses.
  226. virtual bool addILPOpts() {
  227. return false;
  228. }
  229. /// This method may be implemented by targets that want to run passes
  230. /// immediately before register allocation.
  231. virtual void addPreRegAlloc() { }
  232. /// createTargetRegisterAllocator - Create the register allocator pass for
  233. /// this target at the current optimization level.
  234. virtual FunctionPass *createTargetRegisterAllocator(bool Optimized);
  235. /// addFastRegAlloc - Add the minimum set of target-independent passes that
  236. /// are required for fast register allocation.
  237. virtual void addFastRegAlloc(FunctionPass *RegAllocPass);
  238. /// addOptimizedRegAlloc - Add passes related to register allocation.
  239. /// LLVMTargetMachine provides standard regalloc passes for most targets.
  240. virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass);
  241. /// addPreRewrite - Add passes to the optimized register allocation pipeline
  242. /// after register allocation is complete, but before virtual registers are
  243. /// rewritten to physical registers.
  244. ///
  245. /// These passes must preserve VirtRegMap and LiveIntervals, and when running
  246. /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
  247. /// When these passes run, VirtRegMap contains legal physreg assignments for
  248. /// all virtual registers.
  249. virtual bool addPreRewrite() {
  250. return false;
  251. }
  252. /// This method may be implemented by targets that want to run passes after
  253. /// register allocation pass pipeline but before prolog-epilog insertion.
  254. virtual void addPostRegAlloc() { }
  255. /// Add passes that optimize machine instructions after register allocation.
  256. virtual void addMachineLateOptimization();
  257. /// This method may be implemented by targets that want to run passes after
  258. /// prolog-epilog insertion and before the second instruction scheduling pass.
  259. virtual void addPreSched2() { }
  260. /// addGCPasses - Add late codegen passes that analyze code for garbage
  261. /// collection. This should return true if GC info should be printed after
  262. /// these passes.
  263. virtual bool addGCPasses();
  264. /// Add standard basic block placement passes.
  265. virtual void addBlockPlacement();
  266. /// This pass may be implemented by targets that want to run passes
  267. /// immediately before machine code is emitted.
  268. virtual void addPreEmitPass() { }
  269. /// Utilities for targets to add passes to the pass manager.
  270. ///
  271. /// Add a CodeGen pass at this point in the pipeline after checking overrides.
  272. /// Return the pass that was added, or zero if no pass was added.
  273. /// @p printAfter if true and adding a machine function pass add an extra
  274. /// machine printer pass afterwards
  275. /// @p verifyAfter if true and adding a machine function pass add an extra
  276. /// machine verification pass afterwards.
  277. AnalysisID addPass(AnalysisID PassID, bool verifyAfter = true,
  278. bool printAfter = true);
  279. /// Add a pass to the PassManager if that pass is supposed to be run, as
  280. /// determined by the StartAfter and StopAfter options. Takes ownership of the
  281. /// pass.
  282. /// @p printAfter if true and adding a machine function pass add an extra
  283. /// machine printer pass afterwards
  284. /// @p verifyAfter if true and adding a machine function pass add an extra
  285. /// machine verification pass afterwards.
  286. void addPass(Pass *P, bool verifyAfter = true, bool printAfter = true);
  287. /// addMachinePasses helper to create the target-selected or overriden
  288. /// regalloc pass.
  289. FunctionPass *createRegAllocPass(bool Optimized);
  290. /// printAndVerify - Add a pass to dump then verify the machine function, if
  291. /// those steps are enabled.
  292. ///
  293. void printAndVerify(const std::string &Banner);
  294. /// Add a pass to print the machine function if printing is enabled.
  295. void addPrintPass(const std::string &Banner);
  296. /// Add a pass to perform basic verification of the machine function if
  297. /// verification is enabled.
  298. void addVerifyPass(const std::string &Banner);
  299. };
  300. } // namespace llvm
  301. /// List of target independent CodeGen pass IDs.
  302. namespace llvm {
  303. FunctionPass *createAtomicExpandPass(const TargetMachine *TM);
  304. /// createUnreachableBlockEliminationPass - The LLVM code generator does not
  305. /// work well with unreachable basic blocks (what live ranges make sense for a
  306. /// block that cannot be reached?). As such, a code generator should either
  307. /// not instruction select unreachable blocks, or run this pass as its
  308. /// last LLVM modifying pass to clean up blocks that are not reachable from
  309. /// the entry block.
  310. FunctionPass *createUnreachableBlockEliminationPass();
  311. /// MachineFunctionPrinter pass - This pass prints out the machine function to
  312. /// the given stream as a debugging tool.
  313. MachineFunctionPass *
  314. createMachineFunctionPrinterPass(raw_ostream &OS,
  315. const std::string &Banner ="");
  316. /// MIRPrinting pass - this pass prints out the LLVM IR into the given stream
  317. /// using the MIR serialization format.
  318. MachineFunctionPass *createPrintMIRPass(raw_ostream &OS);
  319. /// createCodeGenPreparePass - Transform the code to expose more pattern
  320. /// matching during instruction selection.
  321. FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = nullptr);
  322. /// AtomicExpandID -- Lowers atomic operations in terms of either cmpxchg
  323. /// load-linked/store-conditional loops.
  324. extern char &AtomicExpandID;
  325. /// MachineLoopInfo - This pass is a loop analysis pass.
  326. extern char &MachineLoopInfoID;
  327. /// MachineDominators - This pass is a machine dominators analysis pass.
  328. extern char &MachineDominatorsID;
  329. /// MachineDominanaceFrontier - This pass is a machine dominators analysis pass.
  330. extern char &MachineDominanceFrontierID;
  331. /// EdgeBundles analysis - Bundle machine CFG edges.
  332. extern char &EdgeBundlesID;
  333. /// LiveVariables pass - This pass computes the set of blocks in which each
  334. /// variable is life and sets machine operand kill flags.
  335. extern char &LiveVariablesID;
  336. /// PHIElimination - This pass eliminates machine instruction PHI nodes
  337. /// by inserting copy instructions. This destroys SSA information, but is the
  338. /// desired input for some register allocators. This pass is "required" by
  339. /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
  340. extern char &PHIEliminationID;
  341. /// LiveIntervals - This analysis keeps track of the live ranges of virtual
  342. /// and physical registers.
  343. extern char &LiveIntervalsID;
  344. /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
  345. extern char &LiveStacksID;
  346. /// TwoAddressInstruction - This pass reduces two-address instructions to
  347. /// use two operands. This destroys SSA information but it is desired by
  348. /// register allocators.
  349. extern char &TwoAddressInstructionPassID;
  350. /// ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
  351. extern char &ProcessImplicitDefsID;
  352. /// RegisterCoalescer - This pass merges live ranges to eliminate copies.
  353. extern char &RegisterCoalescerID;
  354. /// MachineScheduler - This pass schedules machine instructions.
  355. extern char &MachineSchedulerID;
  356. /// PostMachineScheduler - This pass schedules machine instructions postRA.
  357. extern char &PostMachineSchedulerID;
  358. /// SpillPlacement analysis. Suggest optimal placement of spill code between
  359. /// basic blocks.
  360. extern char &SpillPlacementID;
  361. /// ShrinkWrap pass. Look for the best place to insert save and restore
  362. // instruction and update the MachineFunctionInfo with that information.
  363. extern char &ShrinkWrapID;
  364. /// VirtRegRewriter pass. Rewrite virtual registers to physical registers as
  365. /// assigned in VirtRegMap.
  366. extern char &VirtRegRewriterID;
  367. /// UnreachableMachineBlockElimination - This pass removes unreachable
  368. /// machine basic blocks.
  369. extern char &UnreachableMachineBlockElimID;
  370. /// DeadMachineInstructionElim - This pass removes dead machine instructions.
  371. extern char &DeadMachineInstructionElimID;
  372. /// FastRegisterAllocation Pass - This pass register allocates as fast as
  373. /// possible. It is best suited for debug code where live ranges are short.
  374. ///
  375. FunctionPass *createFastRegisterAllocator();
  376. /// BasicRegisterAllocation Pass - This pass implements a degenerate global
  377. /// register allocator using the basic regalloc framework.
  378. ///
  379. FunctionPass *createBasicRegisterAllocator();
  380. /// Greedy register allocation pass - This pass implements a global register
  381. /// allocator for optimized builds.
  382. ///
  383. FunctionPass *createGreedyRegisterAllocator();
  384. /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
  385. /// Quadratic Prograaming (PBQP) based register allocator.
  386. ///
  387. FunctionPass *createDefaultPBQPRegisterAllocator();
  388. /// PrologEpilogCodeInserter - This pass inserts prolog and epilog code,
  389. /// and eliminates abstract frame references.
  390. extern char &PrologEpilogCodeInserterID;
  391. /// ExpandPostRAPseudos - This pass expands pseudo instructions after
  392. /// register allocation.
  393. extern char &ExpandPostRAPseudosID;
  394. /// createPostRAScheduler - This pass performs post register allocation
  395. /// scheduling.
  396. extern char &PostRASchedulerID;
  397. /// BranchFolding - This pass performs machine code CFG based
  398. /// optimizations to delete branches to branches, eliminate branches to
  399. /// successor blocks (creating fall throughs), and eliminating branches over
  400. /// branches.
  401. extern char &BranchFolderPassID;
  402. /// MachineFunctionPrinterPass - This pass prints out MachineInstr's.
  403. extern char &MachineFunctionPrinterPassID;
  404. /// MIRPrintingPass - this pass prints out the LLVM IR using the MIR
  405. /// serialization format.
  406. extern char &MIRPrintingPassID;
  407. /// TailDuplicate - Duplicate blocks with unconditional branches
  408. /// into tails of their predecessors.
  409. extern char &TailDuplicateID;
  410. /// MachineTraceMetrics - This pass computes critical path and CPU resource
  411. /// usage in an ensemble of traces.
  412. extern char &MachineTraceMetricsID;
  413. /// EarlyIfConverter - This pass performs if-conversion on SSA form by
  414. /// inserting cmov instructions.
  415. extern char &EarlyIfConverterID;
  416. /// This pass performs instruction combining using trace metrics to estimate
  417. /// critical-path and resource depth.
  418. extern char &MachineCombinerID;
  419. /// StackSlotColoring - This pass performs stack coloring and merging.
  420. /// It merges disjoint allocas to reduce the stack size.
  421. extern char &StackColoringID;
  422. /// IfConverter - This pass performs machine code if conversion.
  423. extern char &IfConverterID;
  424. FunctionPass *createIfConverter(std::function<bool(const Function &)> Ftor);
  425. /// MachineBlockPlacement - This pass places basic blocks based on branch
  426. /// probabilities.
  427. extern char &MachineBlockPlacementID;
  428. /// MachineBlockPlacementStats - This pass collects statistics about the
  429. /// basic block placement using branch probabilities and block frequency
  430. /// information.
  431. extern char &MachineBlockPlacementStatsID;
  432. /// GCLowering Pass - Used by gc.root to perform its default lowering
  433. /// operations.
  434. FunctionPass *createGCLoweringPass();
  435. /// ShadowStackGCLowering - Implements the custom lowering mechanism
  436. /// used by the shadow stack GC. Only runs on functions which opt in to
  437. /// the shadow stack collector.
  438. FunctionPass *createShadowStackGCLoweringPass();
  439. /// GCMachineCodeAnalysis - Target-independent pass to mark safe points
  440. /// in machine code. Must be added very late during code generation, just
  441. /// prior to output, and importantly after all CFG transformations (such as
  442. /// branch folding).
  443. extern char &GCMachineCodeAnalysisID;
  444. /// Creates a pass to print GC metadata.
  445. ///
  446. FunctionPass *createGCInfoPrinter(raw_ostream &OS);
  447. /// MachineCSE - This pass performs global CSE on machine instructions.
  448. extern char &MachineCSEID;
  449. /// ImplicitNullChecks - This pass folds null pointer checks into nearby
  450. /// memory operations.
  451. extern char &ImplicitNullChecksID;
  452. /// MachineLICM - This pass performs LICM on machine instructions.
  453. extern char &MachineLICMID;
  454. /// MachineSinking - This pass performs sinking on machine instructions.
  455. extern char &MachineSinkingID;
  456. /// MachineCopyPropagation - This pass performs copy propagation on
  457. /// machine instructions.
  458. extern char &MachineCopyPropagationID;
  459. /// PeepholeOptimizer - This pass performs peephole optimizations -
  460. /// like extension and comparison eliminations.
  461. extern char &PeepholeOptimizerID;
  462. /// OptimizePHIs - This pass optimizes machine instruction PHIs
  463. /// to take advantage of opportunities created during DAG legalization.
  464. extern char &OptimizePHIsID;
  465. /// StackSlotColoring - This pass performs stack slot coloring.
  466. extern char &StackSlotColoringID;
  467. /// createStackProtectorPass - This pass adds stack protectors to functions.
  468. ///
  469. FunctionPass *createStackProtectorPass(const TargetMachine *TM);
  470. /// createMachineVerifierPass - This pass verifies cenerated machine code
  471. /// instructions for correctness.
  472. ///
  473. FunctionPass *createMachineVerifierPass(const std::string& Banner);
  474. /// createDwarfEHPass - This pass mulches exception handling code into a form
  475. /// adapted to code generation. Required if using dwarf exception handling.
  476. FunctionPass *createDwarfEHPass(const TargetMachine *TM);
  477. /// createWinEHPass - Prepares personality functions used by MSVC on Windows,
  478. /// in addition to the Itanium LSDA based personalities.
  479. FunctionPass *createWinEHPass(const TargetMachine *TM);
  480. /// createSjLjEHPreparePass - This pass adapts exception handling code to use
  481. /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
  482. ///
  483. FunctionPass *createSjLjEHPreparePass();
  484. /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
  485. /// slots relative to one another and allocates base registers to access them
  486. /// when it is estimated by the target to be out of range of normal frame
  487. /// pointer or stack pointer index addressing.
  488. extern char &LocalStackSlotAllocationID;
  489. /// ExpandISelPseudos - This pass expands pseudo-instructions.
  490. extern char &ExpandISelPseudosID;
  491. /// createExecutionDependencyFixPass - This pass fixes execution time
  492. /// problems with dependent instructions, such as switching execution
  493. /// domains to match.
  494. ///
  495. /// The pass will examine instructions using and defining registers in RC.
  496. ///
  497. FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
  498. /// UnpackMachineBundles - This pass unpack machine instruction bundles.
  499. extern char &UnpackMachineBundlesID;
  500. FunctionPass *
  501. createUnpackMachineBundles(std::function<bool(const Function &)> Ftor);
  502. /// FinalizeMachineBundles - This pass finalize machine instruction
  503. /// bundles (created earlier, e.g. during pre-RA scheduling).
  504. extern char &FinalizeMachineBundlesID;
  505. /// StackMapLiveness - This pass analyses the register live-out set of
  506. /// stackmap/patchpoint intrinsics and attaches the calculated information to
  507. /// the intrinsic for later emission to the StackMap.
  508. extern char &StackMapLivenessID;
  509. /// createJumpInstrTables - This pass creates jump-instruction tables.
  510. ModulePass *createJumpInstrTablesPass();
  511. /// createForwardControlFlowIntegrityPass - This pass adds control-flow
  512. /// integrity.
  513. ModulePass *createForwardControlFlowIntegrityPass();
  514. /// InterleavedAccess Pass - This pass identifies and matches interleaved
  515. /// memory accesses to target specific intrinsics.
  516. ///
  517. FunctionPass *createInterleavedAccessPass(const TargetMachine *TM);
  518. } // End llvm namespace
  519. /// Target machine pass initializer for passes with dependencies. Use with
  520. /// INITIALIZE_TM_PASS_END.
  521. #define INITIALIZE_TM_PASS_BEGIN INITIALIZE_PASS_BEGIN
  522. /// Target machine pass initializer for passes with dependencies. Use with
  523. /// INITIALIZE_TM_PASS_BEGIN.
  524. #define INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis) \
  525. PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
  526. PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis, \
  527. PassInfo::TargetMachineCtor_t(callTargetMachineCtor< passName >)); \
  528. Registry.registerPass(*PI, true); \
  529. return PI; \
  530. } \
  531. void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
  532. CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
  533. }
  534. /// This initializer registers TargetMachine constructor, so the pass being
  535. /// initialized can use target dependent interfaces. Please do not move this
  536. /// macro to be together with INITIALIZE_PASS, which is a complete target
  537. /// independent initializer, and we don't want to make libScalarOpts depend
  538. /// on libCodeGen.
  539. #define INITIALIZE_TM_PASS(passName, arg, name, cfg, analysis) \
  540. INITIALIZE_TM_PASS_BEGIN(passName, arg, name, cfg, analysis) \
  541. INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)
  542. #endif