]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/Passes.h
Merge lld trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / Passes.h
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
15 #ifndef LLVM_CODEGEN_PASSES_H
16 #define LLVM_CODEGEN_PASSES_H
17
18 #include <functional>
19 #include <string>
20
21 namespace llvm {
22
23 class FunctionPass;
24 class MachineFunction;
25 class MachineFunctionPass;
26 class ModulePass;
27 class Pass;
28 class TargetMachine;
29 class TargetRegisterClass;
30 class raw_ostream;
31
32 } // End llvm namespace
33
34 /// List of target independent CodeGen pass IDs.
35 namespace llvm {
36   FunctionPass *createAtomicExpandPass(const TargetMachine *TM);
37
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
43   /// the entry block.
44   FunctionPass *createUnreachableBlockEliminationPass();
45
46   /// Insert mcount-like function calls.
47   FunctionPass *createCountingFunctionInserterPass();
48
49   /// MachineFunctionPrinter pass - This pass prints out the machine function to
50   /// the given stream as a debugging tool.
51   MachineFunctionPass *
52   createMachineFunctionPrinterPass(raw_ostream &OS,
53                                    const std::string &Banner ="");
54
55   /// MIRPrinting pass - this pass prints out the LLVM IR into the given stream
56   /// using the MIR serialization format.
57   MachineFunctionPass *createPrintMIRPass(raw_ostream &OS);
58
59   /// This pass resets a MachineFunction when it has the FailedISel property
60   /// as if it was just created.
61   /// If EmitFallbackDiag is true, the pass will emit a
62   /// DiagnosticInfoISelFallback for every MachineFunction it resets.
63   /// If AbortOnFailedISel is true, abort compilation instead of resetting.
64   MachineFunctionPass *createResetMachineFunctionPass(bool EmitFallbackDiag,
65                                                       bool AbortOnFailedISel);
66
67   /// createCodeGenPreparePass - Transform the code to expose more pattern
68   /// matching during instruction selection.
69   FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = nullptr);
70
71   /// AtomicExpandID -- Lowers atomic operations in terms of either cmpxchg
72   /// load-linked/store-conditional loops.
73   extern char &AtomicExpandID;
74
75   /// MachineLoopInfo - This pass is a loop analysis pass.
76   extern char &MachineLoopInfoID;
77
78   /// MachineDominators - This pass is a machine dominators analysis pass.
79   extern char &MachineDominatorsID;
80
81 /// MachineDominanaceFrontier - This pass is a machine dominators analysis pass.
82   extern char &MachineDominanceFrontierID;
83
84   /// MachineRegionInfo - This pass computes SESE regions for machine functions.
85   extern char &MachineRegionInfoPassID;
86
87   /// EdgeBundles analysis - Bundle machine CFG edges.
88   extern char &EdgeBundlesID;
89
90   /// LiveVariables pass - This pass computes the set of blocks in which each
91   /// variable is life and sets machine operand kill flags.
92   extern char &LiveVariablesID;
93
94   /// PHIElimination - This pass eliminates machine instruction PHI nodes
95   /// by inserting copy instructions.  This destroys SSA information, but is the
96   /// desired input for some register allocators.  This pass is "required" by
97   /// these register allocator like this: AU.addRequiredID(PHIEliminationID);
98   extern char &PHIEliminationID;
99
100   /// LiveIntervals - This analysis keeps track of the live ranges of virtual
101   /// and physical registers.
102   extern char &LiveIntervalsID;
103
104   /// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
105   extern char &LiveStacksID;
106
107   /// TwoAddressInstruction - This pass reduces two-address instructions to
108   /// use two operands. This destroys SSA information but it is desired by
109   /// register allocators.
110   extern char &TwoAddressInstructionPassID;
111
112   /// ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
113   extern char &ProcessImplicitDefsID;
114
115   /// RegisterCoalescer - This pass merges live ranges to eliminate copies.
116   extern char &RegisterCoalescerID;
117
118   /// MachineScheduler - This pass schedules machine instructions.
119   extern char &MachineSchedulerID;
120
121   /// PostMachineScheduler - This pass schedules machine instructions postRA.
122   extern char &PostMachineSchedulerID;
123
124   /// SpillPlacement analysis. Suggest optimal placement of spill code between
125   /// basic blocks.
126   extern char &SpillPlacementID;
127
128   /// ShrinkWrap pass. Look for the best place to insert save and restore
129   // instruction and update the MachineFunctionInfo with that information.
130   extern char &ShrinkWrapID;
131
132   /// Greedy register allocator.
133   extern char &RAGreedyID;
134
135   /// VirtRegRewriter pass. Rewrite virtual registers to physical registers as
136   /// assigned in VirtRegMap.
137   extern char &VirtRegRewriterID;
138
139   /// UnreachableMachineBlockElimination - This pass removes unreachable
140   /// machine basic blocks.
141   extern char &UnreachableMachineBlockElimID;
142
143   /// DeadMachineInstructionElim - This pass removes dead machine instructions.
144   extern char &DeadMachineInstructionElimID;
145
146   /// This pass adds dead/undef flags after analyzing subregister lanes.
147   extern char &DetectDeadLanesID;
148
149   /// FastRegisterAllocation Pass - This pass register allocates as fast as
150   /// possible. It is best suited for debug code where live ranges are short.
151   ///
152   FunctionPass *createFastRegisterAllocator();
153
154   /// BasicRegisterAllocation Pass - This pass implements a degenerate global
155   /// register allocator using the basic regalloc framework.
156   ///
157   FunctionPass *createBasicRegisterAllocator();
158
159   /// Greedy register allocation pass - This pass implements a global register
160   /// allocator for optimized builds.
161   ///
162   FunctionPass *createGreedyRegisterAllocator();
163
164   /// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
165   /// Quadratic Prograaming (PBQP) based register allocator.
166   ///
167   FunctionPass *createDefaultPBQPRegisterAllocator();
168
169   /// PrologEpilogCodeInserter - This pass inserts prolog and epilog code,
170   /// and eliminates abstract frame references.
171   extern char &PrologEpilogCodeInserterID;
172   MachineFunctionPass *createPrologEpilogInserterPass(const TargetMachine *TM);
173
174   /// ExpandPostRAPseudos - This pass expands pseudo instructions after
175   /// register allocation.
176   extern char &ExpandPostRAPseudosID;
177
178   /// createPostRAHazardRecognizer - This pass runs the post-ra hazard
179   /// recognizer.
180   extern char &PostRAHazardRecognizerID;
181
182   /// createPostRAScheduler - This pass performs post register allocation
183   /// scheduling.
184   extern char &PostRASchedulerID;
185
186   /// BranchFolding - This pass performs machine code CFG based
187   /// optimizations to delete branches to branches, eliminate branches to
188   /// successor blocks (creating fall throughs), and eliminating branches over
189   /// branches.
190   extern char &BranchFolderPassID;
191
192   /// BranchRelaxation - This pass replaces branches that need to jump further
193   /// than is supported by a branch instruction.
194   extern char &BranchRelaxationPassID;
195
196   /// MachineFunctionPrinterPass - This pass prints out MachineInstr's.
197   extern char &MachineFunctionPrinterPassID;
198
199   /// MIRPrintingPass - this pass prints out the LLVM IR using the MIR
200   /// serialization format.
201   extern char &MIRPrintingPassID;
202
203   /// TailDuplicate - Duplicate blocks with unconditional branches
204   /// into tails of their predecessors.
205   extern char &TailDuplicateID;
206
207   /// MachineTraceMetrics - This pass computes critical path and CPU resource
208   /// usage in an ensemble of traces.
209   extern char &MachineTraceMetricsID;
210
211   /// EarlyIfConverter - This pass performs if-conversion on SSA form by
212   /// inserting cmov instructions.
213   extern char &EarlyIfConverterID;
214
215   /// This pass performs instruction combining using trace metrics to estimate
216   /// critical-path and resource depth.
217   extern char &MachineCombinerID;
218
219   /// StackSlotColoring - This pass performs stack coloring and merging.
220   /// It merges disjoint allocas to reduce the stack size.
221   extern char &StackColoringID;
222
223   /// IfConverter - This pass performs machine code if conversion.
224   extern char &IfConverterID;
225
226   FunctionPass *createIfConverter(
227       std::function<bool(const MachineFunction &)> Ftor);
228
229   /// MachineBlockPlacement - This pass places basic blocks based on branch
230   /// probabilities.
231   extern char &MachineBlockPlacementID;
232
233   /// MachineBlockPlacementStats - This pass collects statistics about the
234   /// basic block placement using branch probabilities and block frequency
235   /// information.
236   extern char &MachineBlockPlacementStatsID;
237
238   /// GCLowering Pass - Used by gc.root to perform its default lowering
239   /// operations.
240   FunctionPass *createGCLoweringPass();
241
242   /// ShadowStackGCLowering - Implements the custom lowering mechanism
243   /// used by the shadow stack GC.  Only runs on functions which opt in to
244   /// the shadow stack collector.
245   FunctionPass *createShadowStackGCLoweringPass();
246
247   /// GCMachineCodeAnalysis - Target-independent pass to mark safe points
248   /// in machine code. Must be added very late during code generation, just
249   /// prior to output, and importantly after all CFG transformations (such as
250   /// branch folding).
251   extern char &GCMachineCodeAnalysisID;
252
253   /// Creates a pass to print GC metadata.
254   ///
255   FunctionPass *createGCInfoPrinter(raw_ostream &OS);
256
257   /// MachineCSE - This pass performs global CSE on machine instructions.
258   extern char &MachineCSEID;
259
260   /// ImplicitNullChecks - This pass folds null pointer checks into nearby
261   /// memory operations.
262   extern char &ImplicitNullChecksID;
263
264   /// MachineLICM - This pass performs LICM on machine instructions.
265   extern char &MachineLICMID;
266
267   /// MachineSinking - This pass performs sinking on machine instructions.
268   extern char &MachineSinkingID;
269
270   /// MachineCopyPropagation - This pass performs copy propagation on
271   /// machine instructions.
272   extern char &MachineCopyPropagationID;
273
274   /// PeepholeOptimizer - This pass performs peephole optimizations -
275   /// like extension and comparison eliminations.
276   extern char &PeepholeOptimizerID;
277
278   /// OptimizePHIs - This pass optimizes machine instruction PHIs
279   /// to take advantage of opportunities created during DAG legalization.
280   extern char &OptimizePHIsID;
281
282   /// StackSlotColoring - This pass performs stack slot coloring.
283   extern char &StackSlotColoringID;
284
285   /// \brief This pass lays out funclets contiguously.
286   extern char &FuncletLayoutID;
287
288   /// This pass inserts the XRay instrumentation sleds if they are supported by
289   /// the target platform.
290   extern char &XRayInstrumentationID;
291
292   /// This pass inserts FEntry calls
293   extern char &FEntryInserterID;
294
295   /// \brief This pass implements the "patchable-function" attribute.
296   extern char &PatchableFunctionID;
297
298   /// createStackProtectorPass - This pass adds stack protectors to functions.
299   ///
300   FunctionPass *createStackProtectorPass(const TargetMachine *TM);
301
302   /// createMachineVerifierPass - This pass verifies cenerated machine code
303   /// instructions for correctness.
304   ///
305   FunctionPass *createMachineVerifierPass(const std::string& Banner);
306
307   /// createDwarfEHPass - This pass mulches exception handling code into a form
308   /// adapted to code generation.  Required if using dwarf exception handling.
309   FunctionPass *createDwarfEHPass(const TargetMachine *TM);
310
311   /// createWinEHPass - Prepares personality functions used by MSVC on Windows,
312   /// in addition to the Itanium LSDA based personalities.
313   FunctionPass *createWinEHPass(const TargetMachine *TM);
314
315   /// createSjLjEHPreparePass - This pass adapts exception handling code to use
316   /// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
317   ///
318   FunctionPass *createSjLjEHPreparePass();
319
320   /// LocalStackSlotAllocation - This pass assigns local frame indices to stack
321   /// slots relative to one another and allocates base registers to access them
322   /// when it is estimated by the target to be out of range of normal frame
323   /// pointer or stack pointer index addressing.
324   extern char &LocalStackSlotAllocationID;
325
326   /// ExpandISelPseudos - This pass expands pseudo-instructions.
327   extern char &ExpandISelPseudosID;
328
329   /// UnpackMachineBundles - This pass unpack machine instruction bundles.
330   extern char &UnpackMachineBundlesID;
331
332   FunctionPass *
333   createUnpackMachineBundles(std::function<bool(const MachineFunction &)> Ftor);
334
335   /// FinalizeMachineBundles - This pass finalize machine instruction
336   /// bundles (created earlier, e.g. during pre-RA scheduling).
337   extern char &FinalizeMachineBundlesID;
338
339   /// StackMapLiveness - This pass analyses the register live-out set of
340   /// stackmap/patchpoint intrinsics and attaches the calculated information to
341   /// the intrinsic for later emission to the StackMap.
342   extern char &StackMapLivenessID;
343
344   /// LiveDebugValues pass
345   extern char &LiveDebugValuesID;
346
347   /// createJumpInstrTables - This pass creates jump-instruction tables.
348   ModulePass *createJumpInstrTablesPass();
349
350   /// createForwardControlFlowIntegrityPass - This pass adds control-flow
351   /// integrity.
352   ModulePass *createForwardControlFlowIntegrityPass();
353
354   /// InterleavedAccess Pass - This pass identifies and matches interleaved
355   /// memory accesses to target specific intrinsics.
356   ///
357   FunctionPass *createInterleavedAccessPass(const TargetMachine *TM);
358
359   /// LowerEmuTLS - This pass generates __emutls_[vt].xyz variables for all
360   /// TLS variables for the emulated TLS model.
361   ///
362   ModulePass *createLowerEmuTLSPass(const TargetMachine *TM);
363
364   /// This pass lowers the @llvm.load.relative intrinsic to instructions.
365   /// This is unsafe to do earlier because a pass may combine the constant
366   /// initializer into the load, which may result in an overflowing evaluation.
367   ModulePass *createPreISelIntrinsicLoweringPass();
368
369   /// GlobalMerge - This pass merges internal (by default) globals into structs
370   /// to enable reuse of a base pointer by indexed addressing modes.
371   /// It can also be configured to focus on size optimizations only.
372   ///
373   Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
374                               bool OnlyOptimizeForSize = false,
375                               bool MergeExternalByDefault = false);
376
377   /// This pass splits the stack into a safe stack and an unsafe stack to
378   /// protect against stack-based overflow vulnerabilities.
379   FunctionPass *createSafeStackPass(const TargetMachine *TM = nullptr);
380
381   /// This pass detects subregister lanes in a virtual register that are used
382   /// independently of other lanes and splits them into separate virtual
383   /// registers.
384   extern char &RenameIndependentSubregsID;
385
386   /// This pass is executed POST-RA to collect which physical registers are
387   /// preserved by given machine function.
388   FunctionPass *createRegUsageInfoCollector();
389
390   /// Return a MachineFunction pass that identifies call sites
391   /// and propagates register usage information of callee to caller
392   /// if available with PysicalRegisterUsageInfo pass.
393   FunctionPass *createRegUsageInfoPropPass();
394
395   /// This pass performs software pipelining on machine instructions.
396   extern char &MachinePipelinerID;
397
398   /// This pass frees the memory occupied by the MachineFunction.
399   FunctionPass *createFreeMachineFunctionPass();
400
401   /// This pass combine basic blocks guarded by the same branch.
402   extern char &BranchCoalescingID;
403
404   /// This pass performs outlining on machine instructions directly before
405   /// printing assembly.
406   ModulePass *createMachineOutlinerPass();
407
408 } // End llvm namespace
409
410 /// Target machine pass initializer for passes with dependencies. Use with
411 /// INITIALIZE_TM_PASS_END.
412 #define INITIALIZE_TM_PASS_BEGIN INITIALIZE_PASS_BEGIN
413
414 /// Target machine pass initializer for passes with dependencies. Use with
415 /// INITIALIZE_TM_PASS_BEGIN.
416 #define INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)             \
417   PassInfo *PI = new PassInfo(                                                 \
418       name, arg, &passName::ID,                                                \
419       PassInfo::NormalCtor_t(callDefaultCtor<passName>), cfg, analysis,        \
420       PassInfo::TargetMachineCtor_t(callTargetMachineCtor<passName>));         \
421   Registry.registerPass(*PI, true);                                            \
422   return PI;                                                                   \
423   }                                                                            \
424   static llvm::once_flag Initialize##passName##PassFlag;                       \
425   void llvm::initialize##passName##Pass(PassRegistry &Registry) {              \
426     llvm::call_once(Initialize##passName##PassFlag,                            \
427                     initialize##passName##PassOnce, std::ref(Registry));       \
428   }
429
430 /// This initializer registers TargetMachine constructor, so the pass being
431 /// initialized can use target dependent interfaces. Please do not move this
432 /// macro to be together with INITIALIZE_PASS, which is a complete target
433 /// independent initializer, and we don't want to make libScalarOpts depend
434 /// on libCodeGen.
435 #define INITIALIZE_TM_PASS(passName, arg, name, cfg, analysis)                 \
436   INITIALIZE_TM_PASS_BEGIN(passName, arg, name, cfg, analysis)                 \
437   INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)
438
439 #endif