blob: a8f4fbabe802b819b109c3bd22ffebb3c4c7a48f [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
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +000088 /// Creates a register allocator as the user specified on the command line, or
89 /// picks one that matches OptLevel.
Chris Lattner3e200e62003-12-20 10:18:58 +000090 ///
Jakob Stoklund Olesen700bfad2010-05-27 23:57:25 +000091 FunctionPass *createRegisterAllocator(CodeGenOpt::Level OptLevel);
Alkis Evlogimenos4c080862003-12-18 22:40:24 +000092
Chris Lattner3e200e62003-12-20 10:18:58 +000093 /// LocalRegisterAllocation Pass - This pass register allocates the input code
94 /// a basic block at a time, yielding code better than the simple register
95 /// allocator, but not as good as a global allocator.
Misha Brukmanea61c352005-04-21 20:39:54 +000096 ///
Chris Lattner3e200e62003-12-20 10:18:58 +000097 FunctionPass *createLocalRegisterAllocator();
Misha Brukmanea61c352005-04-21 20:39:54 +000098
Jakob Stoklund Olesen00207232010-04-21 18:02:42 +000099 /// FastRegisterAllocation Pass - This pass register allocates as fast as
100 /// possible. It is best suited for debug code where live ranges are short.
101 ///
102 FunctionPass *createFastRegisterAllocator();
103
Chris Lattner3e200e62003-12-20 10:18:58 +0000104 /// LinearScanRegisterAllocation Pass - This pass implements the linear scan
105 /// register allocation algorithm, a global register allocator.
106 ///
107 FunctionPass *createLinearScanRegisterAllocator();
Chris Lattnerdb000652003-01-13 01:01:31 +0000108
Evan Chengb1290a62008-10-02 18:29:27 +0000109 /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
110 /// Quadratic Prograaming (PBQP) based register allocator.
111 ///
112 FunctionPass *createPBQPRegisterAllocator();
113
David Greene2c17c4d2007-09-06 16:18:45 +0000114 /// SimpleRegisterCoalescing Pass - Coalesce all copies possible. Can run
115 /// independently of the register allocator.
116 ///
117 RegisterCoalescer *createSimpleRegisterCoalescer();
118
Chris Lattner3e200e62003-12-20 10:18:58 +0000119 /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
120 /// and eliminates abstract frame references.
121 ///
122 FunctionPass *createPrologEpilogCodeInserter();
Christopher Lambbab24742007-07-26 08:18:32 +0000123
124 /// LowerSubregs Pass - This pass lowers subregs to register-register copies
Christopher Lamb98363222007-08-06 16:33:56 +0000125 /// which yields suboptimal, but correct code if the register allocator
Christopher Lambbab24742007-07-26 08:18:32 +0000126 /// cannot coalesce all subreg operations during allocation.
127 ///
128 FunctionPass *createLowerSubregsPass();
Chris Lattnerdb000652003-01-13 01:01:31 +0000129
Evan Chengfa163542009-10-16 21:06:15 +0000130 /// createPostRAScheduler - This pass performs post register allocation
131 /// scheduling.
132 FunctionPass *createPostRAScheduler(CodeGenOpt::Level OptLevel);
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000133
Chris Lattner36c29db2004-07-31 09:59:14 +0000134 /// BranchFolding Pass - This pass performs machine code CFG based
135 /// optimizations to delete branches to branches, eliminate branches to
136 /// successor blocks (creating fall throughs), and eliminating branches over
137 /// branches.
Bob Wilsona5971032009-10-28 20:46:46 +0000138 FunctionPass *createBranchFoldingPass(bool DefaultEnableTailMerge);
Chris Lattner36c29db2004-07-31 09:59:14 +0000139
Bob Wilson2d521e52009-11-26 21:38:41 +0000140 /// TailDuplicate Pass - Duplicate blocks with unconditional branches
Bob Wilson15acadd2009-11-26 00:32:21 +0000141 /// into tails of their predecessors.
Evan Cheng79fc6f42009-12-04 09:42:45 +0000142 FunctionPass *createTailDuplicatePass(bool PreRegAlloc = false);
Bob Wilson15acadd2009-11-26 00:32:21 +0000143
Bob Wilsona5971032009-10-28 20:46:46 +0000144 /// IfConverter Pass - This pass performs machine code if conversion.
145 FunctionPass *createIfConverterPass();
Evan Cheng4e654852007-05-16 02:00:57 +0000146
Evan Chengbbf1db72009-05-07 05:42:24 +0000147 /// Code Placement Pass - This pass optimize code placement and aligns loop
148 /// headers to target specific alignment boundary.
149 FunctionPass *createCodePlacementOptPass();
Evan Chengfb8075d2008-02-28 00:43:03 +0000150
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000151 /// IntrinsicLowering Pass - Performs target-independent LLVM IR
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000152 /// transformations for highly portable strategies.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000153 FunctionPass *createGCLoweringPass();
154
155 /// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
156 /// machine code. Must be added very late during code generation, just prior
157 /// to output, and importantly after all CFG transformations (such as branch
158 /// folding).
159 FunctionPass *createGCMachineCodeAnalysisPass();
160
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000161 /// Deleter Pass - Releases GC metadata.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000162 ///
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000163 FunctionPass *createGCInfoDeleter();
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000164
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000165 /// Creates a pass to print GC metadata.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000166 ///
Chris Lattnercf143a42009-08-23 03:13:20 +0000167 FunctionPass *createGCInfoPrinter(raw_ostream &OS);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000168
Evan Chengc6fe3332010-03-02 02:38:24 +0000169 /// createMachineCSEPass - This pass performs global CSE on machine
170 /// instructions.
171 FunctionPass *createMachineCSEPass();
172
Bill Wendling0f940c92007-12-07 21:42:31 +0000173 /// createMachineLICMPass - This pass performs LICM on machine instructions.
174 ///
Evan Chengd94671a2010-04-07 00:41:17 +0000175 FunctionPass *createMachineLICMPass(bool PreRegAlloc = true);
Bill Wendling0f940c92007-12-07 21:42:31 +0000176
Chris Lattnerc4ce73f2008-01-04 07:36:53 +0000177 /// createMachineSinkingPass - This pass performs sinking on machine
178 /// instructions.
179 FunctionPass *createMachineSinkingPass();
Evan Cheng3f32d652008-06-04 09:18:41 +0000180
Evan Cheng7da9ecf2010-01-13 00:30:23 +0000181 /// createOptimizeExtsPass - This pass performs sign / zero extension
182 /// optimization by increasing uses of extended values.
183 FunctionPass *createOptimizeExtsPass();
184
Bob Wilsonfe61fb12010-02-12 01:30:21 +0000185 /// createOptimizePHIsPass - This pass optimizes machine instruction PHIs
186 /// to take advantage of opportunities created during DAG legalization.
187 FunctionPass *createOptimizePHIsPass();
188
Evan Cheng3f32d652008-06-04 09:18:41 +0000189 /// createStackSlotColoringPass - This pass performs stack slot coloring.
Bill Wendling2c1d7722009-05-07 01:33:38 +0000190 FunctionPass *createStackSlotColoringPass(bool);
Bill Wendling2b58ce52008-11-04 02:10:20 +0000191
192 /// createStackProtectorPass - This pass adds stack protectors to functions.
Bill Wendlinge9e6bdf2008-11-13 01:02:14 +0000193 FunctionPass *createStackProtectorPass(const TargetLowering *tli);
Bill Wendling2b58ce52008-11-04 02:10:20 +0000194
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000195 /// createMachineVerifierPass - This pass verifies cenerated machine code
196 /// instructions for correctness.
197 ///
Dan Gohmanfb76fe02010-02-22 04:10:52 +0000198 /// @param allowDoubleDefs ignore double definitions of
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000199 /// registers. Useful before LiveVariables has run.
200 FunctionPass *createMachineVerifierPass(bool allowDoubleDefs);
201
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000202 /// createDwarfEHPass - This pass mulches exception handling code into a form
203 /// adapted to code generation. Required if using dwarf exception handling.
Dan Gohman55e59c12010-04-19 19:05:59 +0000204 FunctionPass *createDwarfEHPass(const TargetMachine *tm, bool fast);
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000205
Jim Grosbach8b818d72009-08-17 16:41:22 +0000206 /// createSjLjEHPass - This pass adapts exception handling code to use
207 /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
208 FunctionPass *createSjLjEHPass(const TargetLowering *tli);
209
Brian Gaeked0fde302003-11-11 22:41:34 +0000210} // End llvm namespace
211
Chris Lattnerdb000652003-01-13 01:01:31 +0000212#endif