blob: 3833a7a431ae3ebf86ecc6690af20b171890260a [file] [log] [blame]
Misha Brukmanef6a6a62003-08-21 22:14:26 +00001//===-- Passes.h - Target independent code generation passes ----*- C++ -*-===//
Misha Brukmanea61c352005-04-21 20:39:54 +00002//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner7ed47a12007-12-29 19:59:42 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanea61c352005-04-21 20:39:54 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnerdb000652003-01-13 01:01:31 +00009//
Misha Brukmanef6a6a62003-08-21 22:14:26 +000010// This file defines interfaces to access the target independent code generation
Chris Lattnerdb000652003-01-13 01:01:31 +000011// passes provided by the LLVM backend.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_PASSES_H
16#define LLVM_CODEGEN_PASSES_H
17
Evan Chengfa163542009-10-16 21:06:15 +000018#include "llvm/Target/TargetMachine.h"
Brian Gaekefc1f6e82004-02-04 21:41:10 +000019#include <string>
Brian Gaeke09caa372004-01-30 21:53:46 +000020
Brian Gaeked0fde302003-11-11 22:41:34 +000021namespace llvm {
22
Chris Lattner3e200e62003-12-20 10:18:58 +000023 class FunctionPass;
David Greene5c8aa952010-04-02 23:17:14 +000024 class MachineFunctionPass;
Chris Lattner3e200e62003-12-20 10:18:58 +000025 class PassInfo;
Bill Wendling80a320d2008-11-04 21:53:09 +000026 class TargetLowering;
David Greene2c17c4d2007-09-06 16:18:45 +000027 class RegisterCoalescer;
Chris Lattnercf143a42009-08-23 03:13:20 +000028 class raw_ostream;
Chris Lattner8b708e42004-07-02 05:44:13 +000029
30 /// createUnreachableBlockEliminationPass - The LLVM code generator does not
31 /// work well with unreachable basic blocks (what live ranges make sense for a
32 /// block that cannot be reached?). As such, a code generator should either
33 /// not instruction select unreachable blocks, or it can run this pass as it's
34 /// last LLVM modifying pass to clean up blocks that are not reachable from
35 /// the entry block.
36 FunctionPass *createUnreachableBlockEliminationPass();
Misha Brukmanea61c352005-04-21 20:39:54 +000037
Chris Lattner3e200e62003-12-20 10:18:58 +000038 /// MachineFunctionPrinter pass - This pass prints out the machine function to
Daniel Dunbar275872e2009-08-03 01:02:24 +000039 /// the given stream, as a debugging tool.
David Greene5c8aa952010-04-02 23:17:14 +000040 MachineFunctionPass *
41 createMachineFunctionPrinterPass(raw_ostream &OS,
42 const std::string &Banner ="");
Brian Gaeke09caa372004-01-30 21:53:46 +000043
Bill Wendling67d65bb2008-01-04 20:54:55 +000044 /// MachineLoopInfo pass - This pass is a loop analysis pass.
45 ///
Dan Gohman6ddba2b2008-05-13 02:05:11 +000046 extern const PassInfo *const MachineLoopInfoID;
Bill Wendling67d65bb2008-01-04 20:54:55 +000047
48 /// MachineDominators pass - This pass is a machine dominators analysis pass.
49 ///
Dan Gohman6ddba2b2008-05-13 02:05:11 +000050 extern const PassInfo *const MachineDominatorsID;
Bill Wendling67d65bb2008-01-04 20:54:55 +000051
Chris Lattner3e200e62003-12-20 10:18:58 +000052 /// PHIElimination pass - This pass eliminates machine instruction PHI nodes
53 /// by inserting copy instructions. This destroys SSA information, but is the
54 /// desired input for some register allocators. This pass is "required" by
55 /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
56 ///
Dan Gohman6ddba2b2008-05-13 02:05:11 +000057 extern const PassInfo *const PHIEliminationID;
Owen Anderson0bda0e82007-10-31 03:37:57 +000058
59 /// StrongPHIElimination pass - This pass eliminates machine instruction PHI
60 /// nodes by inserting copy instructions. This destroys SSA information, but
61 /// is the desired input for some register allocators. This pass is
62 /// "required" by these register allocator like this:
63 /// AU.addRequiredID(PHIEliminationID);
64 /// This pass is still in development
Dan Gohman6ddba2b2008-05-13 02:05:11 +000065 extern const PassInfo *const StrongPHIEliminationID;
Chris Lattnerdb000652003-01-13 01:01:31 +000066
Evan Cheng09e8ca82008-10-20 21:44:59 +000067 extern const PassInfo *const PreAllocSplittingID;
68
David Greene25133302007-06-08 17:18:56 +000069 /// SimpleRegisterCoalescing pass. Aggressively coalesces every register
70 /// copy it can.
71 ///
Dan Gohman6ddba2b2008-05-13 02:05:11 +000072 extern const PassInfo *const SimpleRegisterCoalescingID;
David Greene25133302007-06-08 17:18:56 +000073
Chris Lattner3e200e62003-12-20 10:18:58 +000074 /// TwoAddressInstruction pass - This pass reduces two-address instructions to
75 /// use two operands. This destroys SSA information but it is desired by
76 /// register allocators.
Dan Gohman6ddba2b2008-05-13 02:05:11 +000077 extern const PassInfo *const TwoAddressInstructionPassID;
Chris Lattnerdb000652003-01-13 01:01:31 +000078
Owen Andersonbd3ba462008-08-04 23:54:43 +000079 /// UnreachableMachineBlockElimination pass - This pass removes unreachable
80 /// machine basic blocks.
81 extern const PassInfo *const UnreachableMachineBlockElimID;
82
Dan Gohmand3ead432008-09-17 00:43:24 +000083 /// DeadMachineInstructionElim pass - This pass removes dead machine
84 /// instructions.
85 ///
86 FunctionPass *createDeadMachineInstructionElimPass();
87
Chris Lattner3e200e62003-12-20 10:18:58 +000088 /// Creates a register allocator as the user specified on the command line.
89 ///
90 FunctionPass *createRegisterAllocator();
Alkis Evlogimenos4c080862003-12-18 22:40:24 +000091
Chris Lattner3e200e62003-12-20 10:18:58 +000092 /// LocalRegisterAllocation Pass - This pass register allocates the input code
93 /// a basic block at a time, yielding code better than the simple register
94 /// allocator, but not as good as a global allocator.
Misha Brukmanea61c352005-04-21 20:39:54 +000095 ///
Chris Lattner3e200e62003-12-20 10:18:58 +000096 FunctionPass *createLocalRegisterAllocator();
Misha Brukmanea61c352005-04-21 20:39:54 +000097
Chris Lattner3e200e62003-12-20 10:18:58 +000098 /// LinearScanRegisterAllocation Pass - This pass implements the linear scan
99 /// register allocation algorithm, a global register allocator.
100 ///
101 FunctionPass *createLinearScanRegisterAllocator();
Chris Lattnerdb000652003-01-13 01:01:31 +0000102
Evan Chengb1290a62008-10-02 18:29:27 +0000103 /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
104 /// Quadratic Prograaming (PBQP) based register allocator.
105 ///
106 FunctionPass *createPBQPRegisterAllocator();
107
David Greene2c17c4d2007-09-06 16:18:45 +0000108 /// SimpleRegisterCoalescing Pass - Coalesce all copies possible. Can run
109 /// independently of the register allocator.
110 ///
111 RegisterCoalescer *createSimpleRegisterCoalescer();
112
Chris Lattner3e200e62003-12-20 10:18:58 +0000113 /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
114 /// and eliminates abstract frame references.
115 ///
116 FunctionPass *createPrologEpilogCodeInserter();
Christopher Lambbab24742007-07-26 08:18:32 +0000117
118 /// LowerSubregs Pass - This pass lowers subregs to register-register copies
Christopher Lamb98363222007-08-06 16:33:56 +0000119 /// which yields suboptimal, but correct code if the register allocator
Christopher Lambbab24742007-07-26 08:18:32 +0000120 /// cannot coalesce all subreg operations during allocation.
121 ///
122 FunctionPass *createLowerSubregsPass();
Chris Lattnerdb000652003-01-13 01:01:31 +0000123
Evan Chengfa163542009-10-16 21:06:15 +0000124 /// createPostRAScheduler - This pass performs post register allocation
125 /// scheduling.
126 FunctionPass *createPostRAScheduler(CodeGenOpt::Level OptLevel);
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000127
Chris Lattner36c29db2004-07-31 09:59:14 +0000128 /// BranchFolding Pass - This pass performs machine code CFG based
129 /// optimizations to delete branches to branches, eliminate branches to
130 /// successor blocks (creating fall throughs), and eliminating branches over
131 /// branches.
Bob Wilsona5971032009-10-28 20:46:46 +0000132 FunctionPass *createBranchFoldingPass(bool DefaultEnableTailMerge);
Chris Lattner36c29db2004-07-31 09:59:14 +0000133
Bob Wilson2d521e52009-11-26 21:38:41 +0000134 /// TailDuplicate Pass - Duplicate blocks with unconditional branches
Bob Wilson15acadd2009-11-26 00:32:21 +0000135 /// into tails of their predecessors.
Evan Cheng79fc6f42009-12-04 09:42:45 +0000136 FunctionPass *createTailDuplicatePass(bool PreRegAlloc = false);
Bob Wilson15acadd2009-11-26 00:32:21 +0000137
Bob Wilsona5971032009-10-28 20:46:46 +0000138 /// IfConverter Pass - This pass performs machine code if conversion.
139 FunctionPass *createIfConverterPass();
Evan Cheng4e654852007-05-16 02:00:57 +0000140
Evan Chengbbf1db72009-05-07 05:42:24 +0000141 /// Code Placement Pass - This pass optimize code placement and aligns loop
142 /// headers to target specific alignment boundary.
143 FunctionPass *createCodePlacementOptPass();
Evan Chengfb8075d2008-02-28 00:43:03 +0000144
Chris Lattner3e200e62003-12-20 10:18:58 +0000145 /// getRegisterAllocator - This creates an instance of the register allocator
146 /// for the Sparc.
147 FunctionPass *getRegisterAllocator(TargetMachine &T);
Tanya Lattner5a75c912004-05-08 16:14:02 +0000148
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000149 /// IntrinsicLowering Pass - Performs target-independent LLVM IR
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000150 /// transformations for highly portable strategies.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000151 FunctionPass *createGCLoweringPass();
152
153 /// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
154 /// machine code. Must be added very late during code generation, just prior
155 /// to output, and importantly after all CFG transformations (such as branch
156 /// folding).
157 FunctionPass *createGCMachineCodeAnalysisPass();
158
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000159 /// Deleter Pass - Releases GC metadata.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000160 ///
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000161 FunctionPass *createGCInfoDeleter();
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000162
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000163 /// Creates a pass to print GC metadata.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000164 ///
Chris Lattnercf143a42009-08-23 03:13:20 +0000165 FunctionPass *createGCInfoPrinter(raw_ostream &OS);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000166
Evan Chengc6fe3332010-03-02 02:38:24 +0000167 /// createMachineCSEPass - This pass performs global CSE on machine
168 /// instructions.
169 FunctionPass *createMachineCSEPass();
170
Bill Wendling0f940c92007-12-07 21:42:31 +0000171 /// createMachineLICMPass - This pass performs LICM on machine instructions.
172 ///
Evan Chengd94671a2010-04-07 00:41:17 +0000173 FunctionPass *createMachineLICMPass(bool PreRegAlloc = true);
Bill Wendling0f940c92007-12-07 21:42:31 +0000174
Chris Lattnerc4ce73f2008-01-04 07:36:53 +0000175 /// createMachineSinkingPass - This pass performs sinking on machine
176 /// instructions.
177 FunctionPass *createMachineSinkingPass();
Evan Cheng3f32d652008-06-04 09:18:41 +0000178
Evan Cheng7da9ecf2010-01-13 00:30:23 +0000179 /// createOptimizeExtsPass - This pass performs sign / zero extension
180 /// optimization by increasing uses of extended values.
181 FunctionPass *createOptimizeExtsPass();
182
Bob Wilsonfe61fb12010-02-12 01:30:21 +0000183 /// createOptimizePHIsPass - This pass optimizes machine instruction PHIs
184 /// to take advantage of opportunities created during DAG legalization.
185 FunctionPass *createOptimizePHIsPass();
186
Evan Cheng3f32d652008-06-04 09:18:41 +0000187 /// createStackSlotColoringPass - This pass performs stack slot coloring.
Bill Wendling2c1d7722009-05-07 01:33:38 +0000188 FunctionPass *createStackSlotColoringPass(bool);
Bill Wendling2b58ce52008-11-04 02:10:20 +0000189
190 /// createStackProtectorPass - This pass adds stack protectors to functions.
Bill Wendlinge9e6bdf2008-11-13 01:02:14 +0000191 FunctionPass *createStackProtectorPass(const TargetLowering *tli);
Bill Wendling2b58ce52008-11-04 02:10:20 +0000192
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000193 /// createMachineVerifierPass - This pass verifies cenerated machine code
194 /// instructions for correctness.
195 ///
Dan Gohmanfb76fe02010-02-22 04:10:52 +0000196 /// @param allowDoubleDefs ignore double definitions of
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000197 /// registers. Useful before LiveVariables has run.
198 FunctionPass *createMachineVerifierPass(bool allowDoubleDefs);
199
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000200 /// createDwarfEHPass - This pass mulches exception handling code into a form
201 /// adapted to code generation. Required if using dwarf exception handling.
Dan Gohman55e59c12010-04-19 19:05:59 +0000202 FunctionPass *createDwarfEHPass(const TargetMachine *tm, bool fast);
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000203
Jim Grosbach8b818d72009-08-17 16:41:22 +0000204 /// createSjLjEHPass - This pass adapts exception handling code to use
205 /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
206 FunctionPass *createSjLjEHPass(const TargetLowering *tli);
207
Brian Gaeked0fde302003-11-11 22:41:34 +0000208} // End llvm namespace
209
Chris Lattnerdb000652003-01-13 01:01:31 +0000210#endif