1 //===-- Passes.h - Target independent code generation passes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines interfaces to access the target independent code generation
11 // passes provided by the LLVM backend.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_PASSES_H
16 #define LLVM_CODEGEN_PASSES_H
24 class MachineFunction;
25 class MachineFunctionPass;
29 class TargetRegisterClass;
32 } // End llvm namespace
34 /// List of target independent CodeGen pass IDs.
36 FunctionPass *createAtomicExpandPass();
38 /// createUnreachableBlockEliminationPass - The LLVM code generator does not
39 /// work well with unreachable basic blocks (what live ranges make sense for a
40 /// block that cannot be reached?). As such, a code generator should either
41 /// not instruction select unreachable blocks, or run this pass as its
42 /// last LLVM modifying pass to clean up blocks that are not reachable from
44 FunctionPass *createUnreachableBlockEliminationPass();
46 /// MachineFunctionPrinter pass - This pass prints out the machine function to
47 /// the given stream as a debugging tool.
49 createMachineFunctionPrinterPass(raw_ostream &OS,
50 const std::string &Banner ="");
52 /// MIRPrinting pass - this pass prints out the LLVM IR into the given stream
53 /// using the MIR serialization format.
54 MachineFunctionPass *createPrintMIRPass(raw_ostream &OS);
56 /// This pass resets a MachineFunction when it has the FailedISel property
57 /// as if it was just created.
58 /// If EmitFallbackDiag is true, the pass will emit a
59 /// DiagnosticInfoISelFallback for every MachineFunction it resets.
60 /// If AbortOnFailedISel is true, abort compilation instead of resetting.
61 MachineFunctionPass *createResetMachineFunctionPass(bool EmitFallbackDiag,
62 bool AbortOnFailedISel);
64 /// createCodeGenPreparePass - Transform the code to expose more pattern
65 /// matching during instruction selection.
66 FunctionPass *createCodeGenPreparePass();
68 /// createScalarizeMaskedMemIntrinPass - Replace masked load, store, gather
69 /// and scatter intrinsics with scalar code when target doesn't support them.
70 FunctionPass *createScalarizeMaskedMemIntrinPass();
72 /// AtomicExpandID -- Lowers atomic operations in terms of either cmpxchg
73 /// load-linked/store-conditional loops.
74 extern char &AtomicExpandID;
76 /// MachineLoopInfo - This pass is a loop analysis pass.
77 extern char &MachineLoopInfoID;
79 /// MachineDominators - This pass is a machine dominators analysis pass.
80 extern char &MachineDominatorsID;
82 /// MachineDominanaceFrontier - This pass is a machine dominators analysis pass.
83 extern char &MachineDominanceFrontierID;
85 /// MachineRegionInfo - This pass computes SESE regions for machine functions.
86 extern char &MachineRegionInfoPassID;
88 /// EdgeBundles analysis - Bundle machine CFG edges.
89 extern char &EdgeBundlesID;
91 /// LiveVariables pass - This pass computes the set of blocks in which each
92 /// variable is life and sets machine operand kill flags.
93 extern char &LiveVariablesID;
95 /// PHIElimination - This pass eliminates machine instruction PHI nodes
96 /// by inserting copy instructions. This destroys SSA information, but is the
97 /// desired input for some register allocators. This pass is "required" by
98 /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
99 extern char &PHIEliminationID;
101 /// LiveIntervals - This analysis keeps track of the live ranges of virtual
102 /// and physical registers.
103 extern char &LiveIntervalsID;
105 /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
106 extern char &LiveStacksID;
108 /// TwoAddressInstruction - This pass reduces two-address instructions to
109 /// use two operands. This destroys SSA information but it is desired by
110 /// register allocators.
111 extern char &TwoAddressInstructionPassID;
113 /// ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
114 extern char &ProcessImplicitDefsID;
116 /// RegisterCoalescer - This pass merges live ranges to eliminate copies.
117 extern char &RegisterCoalescerID;
119 /// MachineScheduler - This pass schedules machine instructions.
120 extern char &MachineSchedulerID;
122 /// PostMachineScheduler - This pass schedules machine instructions postRA.
123 extern char &PostMachineSchedulerID;
125 /// SpillPlacement analysis. Suggest optimal placement of spill code between
127 extern char &SpillPlacementID;
129 /// ShrinkWrap pass. Look for the best place to insert save and restore
130 // instruction and update the MachineFunctionInfo with that information.
131 extern char &ShrinkWrapID;
133 /// LiveRangeShrink pass. Move instruction close to its definition to shrink
134 /// the definition's live range.
135 extern char &LiveRangeShrinkID;
137 /// Greedy register allocator.
138 extern char &RAGreedyID;
140 /// Basic register allocator.
141 extern char &RABasicID;
143 /// VirtRegRewriter pass. Rewrite virtual registers to physical registers as
144 /// assigned in VirtRegMap.
145 extern char &VirtRegRewriterID;
147 /// UnreachableMachineBlockElimination - This pass removes unreachable
148 /// machine basic blocks.
149 extern char &UnreachableMachineBlockElimID;
151 /// DeadMachineInstructionElim - This pass removes dead machine instructions.
152 extern char &DeadMachineInstructionElimID;
154 /// This pass adds dead/undef flags after analyzing subregister lanes.
155 extern char &DetectDeadLanesID;
157 /// This pass perform post-ra machine sink for COPY instructions.
158 extern char &PostRAMachineSinkingID;
160 /// FastRegisterAllocation Pass - This pass register allocates as fast as
161 /// possible. It is best suited for debug code where live ranges are short.
163 FunctionPass *createFastRegisterAllocator();
165 /// BasicRegisterAllocation Pass - This pass implements a degenerate global
166 /// register allocator using the basic regalloc framework.
168 FunctionPass *createBasicRegisterAllocator();
170 /// Greedy register allocation pass - This pass implements a global register
171 /// allocator for optimized builds.
173 FunctionPass *createGreedyRegisterAllocator();
175 /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
176 /// Quadratic Prograaming (PBQP) based register allocator.
178 FunctionPass *createDefaultPBQPRegisterAllocator();
180 /// PrologEpilogCodeInserter - This pass inserts prolog and epilog code,
181 /// and eliminates abstract frame references.
182 extern char &PrologEpilogCodeInserterID;
183 MachineFunctionPass *createPrologEpilogInserterPass();
185 /// ExpandPostRAPseudos - This pass expands pseudo instructions after
186 /// register allocation.
187 extern char &ExpandPostRAPseudosID;
189 /// createPostRAHazardRecognizer - This pass runs the post-ra hazard
191 extern char &PostRAHazardRecognizerID;
193 /// createPostRAScheduler - This pass performs post register allocation
195 extern char &PostRASchedulerID;
197 /// BranchFolding - This pass performs machine code CFG based
198 /// optimizations to delete branches to branches, eliminate branches to
199 /// successor blocks (creating fall throughs), and eliminating branches over
201 extern char &BranchFolderPassID;
203 /// BranchRelaxation - This pass replaces branches that need to jump further
204 /// than is supported by a branch instruction.
205 extern char &BranchRelaxationPassID;
207 /// MachineFunctionPrinterPass - This pass prints out MachineInstr's.
208 extern char &MachineFunctionPrinterPassID;
210 /// MIRPrintingPass - this pass prints out the LLVM IR using the MIR
211 /// serialization format.
212 extern char &MIRPrintingPassID;
214 /// TailDuplicate - Duplicate blocks with unconditional branches
215 /// into tails of their predecessors.
216 extern char &TailDuplicateID;
218 /// Duplicate blocks with unconditional branches into tails of their
219 /// predecessors. Variant that works before register allocation.
220 extern char &EarlyTailDuplicateID;
222 /// MachineTraceMetrics - This pass computes critical path and CPU resource
223 /// usage in an ensemble of traces.
224 extern char &MachineTraceMetricsID;
226 /// EarlyIfConverter - This pass performs if-conversion on SSA form by
227 /// inserting cmov instructions.
228 extern char &EarlyIfConverterID;
230 /// This pass performs instruction combining using trace metrics to estimate
231 /// critical-path and resource depth.
232 extern char &MachineCombinerID;
234 /// StackSlotColoring - This pass performs stack coloring and merging.
235 /// It merges disjoint allocas to reduce the stack size.
236 extern char &StackColoringID;
238 /// IfConverter - This pass performs machine code if conversion.
239 extern char &IfConverterID;
241 FunctionPass *createIfConverter(
242 std::function<bool(const MachineFunction &)> Ftor);
244 /// MachineBlockPlacement - This pass places basic blocks based on branch
246 extern char &MachineBlockPlacementID;
248 /// MachineBlockPlacementStats - This pass collects statistics about the
249 /// basic block placement using branch probabilities and block frequency
251 extern char &MachineBlockPlacementStatsID;
253 /// GCLowering Pass - Used by gc.root to perform its default lowering
255 FunctionPass *createGCLoweringPass();
257 /// ShadowStackGCLowering - Implements the custom lowering mechanism
258 /// used by the shadow stack GC. Only runs on functions which opt in to
259 /// the shadow stack collector.
260 FunctionPass *createShadowStackGCLoweringPass();
262 /// GCMachineCodeAnalysis - Target-independent pass to mark safe points
263 /// in machine code. Must be added very late during code generation, just
264 /// prior to output, and importantly after all CFG transformations (such as
266 extern char &GCMachineCodeAnalysisID;
268 /// Creates a pass to print GC metadata.
270 FunctionPass *createGCInfoPrinter(raw_ostream &OS);
272 /// MachineCSE - This pass performs global CSE on machine instructions.
273 extern char &MachineCSEID;
275 /// ImplicitNullChecks - This pass folds null pointer checks into nearby
276 /// memory operations.
277 extern char &ImplicitNullChecksID;
279 /// This pass performs loop invariant code motion on machine instructions.
280 extern char &MachineLICMID;
282 /// This pass performs loop invariant code motion on machine instructions.
283 /// This variant works before register allocation. \see MachineLICMID.
284 extern char &EarlyMachineLICMID;
286 /// MachineSinking - This pass performs sinking on machine instructions.
287 extern char &MachineSinkingID;
289 /// MachineCopyPropagation - This pass performs copy propagation on
290 /// machine instructions.
291 extern char &MachineCopyPropagationID;
293 /// PeepholeOptimizer - This pass performs peephole optimizations -
294 /// like extension and comparison eliminations.
295 extern char &PeepholeOptimizerID;
297 /// OptimizePHIs - This pass optimizes machine instruction PHIs
298 /// to take advantage of opportunities created during DAG legalization.
299 extern char &OptimizePHIsID;
301 /// StackSlotColoring - This pass performs stack slot coloring.
302 extern char &StackSlotColoringID;
304 /// This pass lays out funclets contiguously.
305 extern char &FuncletLayoutID;
307 /// This pass inserts the XRay instrumentation sleds if they are supported by
308 /// the target platform.
309 extern char &XRayInstrumentationID;
311 /// This pass inserts FEntry calls
312 extern char &FEntryInserterID;
314 /// This pass implements the "patchable-function" attribute.
315 extern char &PatchableFunctionID;
317 /// createStackProtectorPass - This pass adds stack protectors to functions.
319 FunctionPass *createStackProtectorPass();
321 /// createMachineVerifierPass - This pass verifies cenerated machine code
322 /// instructions for correctness.
324 FunctionPass *createMachineVerifierPass(const std::string& Banner);
326 /// createDwarfEHPass - This pass mulches exception handling code into a form
327 /// adapted to code generation. Required if using dwarf exception handling.
328 FunctionPass *createDwarfEHPass();
330 /// createWinEHPass - Prepares personality functions used by MSVC on Windows,
331 /// in addition to the Itanium LSDA based personalities.
332 FunctionPass *createWinEHPass(bool DemoteCatchSwitchPHIOnly = false);
334 /// createSjLjEHPreparePass - This pass adapts exception handling code to use
335 /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
337 FunctionPass *createSjLjEHPreparePass();
339 /// createWasmEHPass - This pass adapts exception handling code to use
340 /// WebAssembly's exception handling scheme.
341 FunctionPass *createWasmEHPass();
343 /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
344 /// slots relative to one another and allocates base registers to access them
345 /// when it is estimated by the target to be out of range of normal frame
346 /// pointer or stack pointer index addressing.
347 extern char &LocalStackSlotAllocationID;
349 /// ExpandISelPseudos - This pass expands pseudo-instructions.
350 extern char &ExpandISelPseudosID;
352 /// UnpackMachineBundles - This pass unpack machine instruction bundles.
353 extern char &UnpackMachineBundlesID;
356 createUnpackMachineBundles(std::function<bool(const MachineFunction &)> Ftor);
358 /// FinalizeMachineBundles - This pass finalize machine instruction
359 /// bundles (created earlier, e.g. during pre-RA scheduling).
360 extern char &FinalizeMachineBundlesID;
362 /// StackMapLiveness - This pass analyses the register live-out set of
363 /// stackmap/patchpoint intrinsics and attaches the calculated information to
364 /// the intrinsic for later emission to the StackMap.
365 extern char &StackMapLivenessID;
367 /// LiveDebugValues pass
368 extern char &LiveDebugValuesID;
370 /// createJumpInstrTables - This pass creates jump-instruction tables.
371 ModulePass *createJumpInstrTablesPass();
373 /// createForwardControlFlowIntegrityPass - This pass adds control-flow
375 ModulePass *createForwardControlFlowIntegrityPass();
377 /// InterleavedAccess Pass - This pass identifies and matches interleaved
378 /// memory accesses to target specific intrinsics.
380 FunctionPass *createInterleavedAccessPass();
382 /// InterleavedLoadCombines Pass - This pass identifies interleaved loads and
383 /// combines them into wide loads detectable by InterleavedAccessPass
385 FunctionPass *createInterleavedLoadCombinePass();
387 /// LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all
388 /// TLS variables for the emulated TLS model.
390 ModulePass *createLowerEmuTLSPass();
392 /// This pass lowers the \@llvm.load.relative and \@llvm.objc.* intrinsics to
393 /// instructions. This is unsafe to do earlier because a pass may combine the
394 /// constant initializer into the load, which may result in an overflowing
396 ModulePass *createPreISelIntrinsicLoweringPass();
398 /// GlobalMerge - This pass merges internal (by default) globals into structs
399 /// to enable reuse of a base pointer by indexed addressing modes.
400 /// It can also be configured to focus on size optimizations only.
402 Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
403 bool OnlyOptimizeForSize = false,
404 bool MergeExternalByDefault = false);
406 /// This pass splits the stack into a safe stack and an unsafe stack to
407 /// protect against stack-based overflow vulnerabilities.
408 FunctionPass *createSafeStackPass();
410 /// This pass detects subregister lanes in a virtual register that are used
411 /// independently of other lanes and splits them into separate virtual
413 extern char &RenameIndependentSubregsID;
415 /// This pass is executed POST-RA to collect which physical registers are
416 /// preserved by given machine function.
417 FunctionPass *createRegUsageInfoCollector();
419 /// Return a MachineFunction pass that identifies call sites
420 /// and propagates register usage information of callee to caller
421 /// if available with PysicalRegisterUsageInfo pass.
422 FunctionPass *createRegUsageInfoPropPass();
424 /// This pass performs software pipelining on machine instructions.
425 extern char &MachinePipelinerID;
427 /// This pass frees the memory occupied by the MachineFunction.
428 FunctionPass *createFreeMachineFunctionPass();
430 /// This pass performs outlining on machine instructions directly before
431 /// printing assembly.
432 ModulePass *createMachineOutlinerPass(bool RunOnAllFunctions = true);
434 /// This pass expands the experimental reduction intrinsics into sequences of
436 FunctionPass *createExpandReductionsPass();
438 // This pass expands memcmp() to load/stores.
439 FunctionPass *createExpandMemCmpPass();
441 /// Creates Break False Dependencies pass. \see BreakFalseDeps.cpp
442 FunctionPass *createBreakFalseDeps();
444 // This pass expands indirectbr instructions.
445 FunctionPass *createIndirectBrExpandPass();
447 /// Creates CFI Instruction Inserter pass. \see CFIInstrInserter.cpp
448 FunctionPass *createCFIInstrInserter();
450 } // End llvm namespace