1 //===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header file defines prototypes for accessor functions that expose passes
10 // in the Scalar transformations library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_SCALAR_H
15 #define LLVM_TRANSFORMS_SCALAR_H
16 
17 #include <functional>
18 
19 namespace llvm {
20 
21 class Function;
22 class FunctionPass;
23 class ModulePass;
24 class Pass;
25 
26 //===----------------------------------------------------------------------===//
27 //
28 // ConstantPropagation - A worklist driven constant propagation pass
29 //
30 FunctionPass *createConstantPropagationPass();
31 
32 //===----------------------------------------------------------------------===//
33 //
34 // AlignmentFromAssumptions - Use assume intrinsics to set load/store
35 // alignments.
36 //
37 FunctionPass *createAlignmentFromAssumptionsPass();
38 
39 //===----------------------------------------------------------------------===//
40 //
41 // SCCP - Sparse conditional constant propagation.
42 //
43 FunctionPass *createSCCPPass();
44 
45 //===----------------------------------------------------------------------===//
46 //
47 // DeadInstElimination - This pass quickly removes trivially dead instructions
48 // without modifying the CFG of the function.  It is a FunctionPass.
49 //
50 Pass *createDeadInstEliminationPass();
51 
52 //===----------------------------------------------------------------------===//
53 //
54 // RedundantDbgInstElimination - This pass removes redundant dbg intrinsics
55 // without modifying the CFG of the function.  It is a FunctionPass.
56 //
57 Pass *createRedundantDbgInstEliminationPass();
58 
59 //===----------------------------------------------------------------------===//
60 //
61 // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
62 // because it is worklist driven that can potentially revisit instructions when
63 // their other instructions become dead, to eliminate chains of dead
64 // computations.
65 //
66 FunctionPass *createDeadCodeEliminationPass();
67 
68 //===----------------------------------------------------------------------===//
69 //
70 // DeadStoreElimination - This pass deletes stores that are post-dominated by
71 // must-aliased stores and are not loaded used between the stores.
72 //
73 FunctionPass *createDeadStoreEliminationPass();
74 
75 
76 //===----------------------------------------------------------------------===//
77 //
78 // CallSiteSplitting - This pass split call-site based on its known argument
79 // values.
80 FunctionPass *createCallSiteSplittingPass();
81 
82 //===----------------------------------------------------------------------===//
83 //
84 // AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm.  This
85 // algorithm assumes instructions are dead until proven otherwise, which makes
86 // it more successful are removing non-obviously dead instructions.
87 //
88 FunctionPass *createAggressiveDCEPass();
89 
90 //===----------------------------------------------------------------------===//
91 //
92 // GuardWidening - An optimization over the @llvm.experimental.guard intrinsic
93 // that (optimistically) combines multiple guards into one to have fewer checks
94 // at runtime.
95 //
96 FunctionPass *createGuardWideningPass();
97 
98 
99 //===----------------------------------------------------------------------===//
100 //
101 // LoopGuardWidening - Analogous to the GuardWidening pass, but restricted to a
102 // single loop at a time for use within a LoopPassManager.  Desired effect is
103 // to widen guards into preheader or a single guard within loop if that's not
104 // possible.
105 //
106 Pass *createLoopGuardWideningPass();
107 
108 
109 //===----------------------------------------------------------------------===//
110 //
111 // BitTrackingDCE - This pass uses a bit-tracking DCE algorithm in order to
112 // remove computations of dead bits.
113 //
114 FunctionPass *createBitTrackingDCEPass();
115 
116 //===----------------------------------------------------------------------===//
117 //
118 // SROA - Replace aggregates or pieces of aggregates with scalar SSA values.
119 //
120 FunctionPass *createSROAPass();
121 
122 //===----------------------------------------------------------------------===//
123 //
124 // InductiveRangeCheckElimination - Transform loops to elide range checks on
125 // linear functions of the induction variable.
126 //
127 Pass *createInductiveRangeCheckEliminationPass();
128 
129 //===----------------------------------------------------------------------===//
130 //
131 // InductionVariableSimplify - Transform induction variables in a program to all
132 // use a single canonical induction variable per loop.
133 //
134 Pass *createIndVarSimplifyPass();
135 
136 //===----------------------------------------------------------------------===//
137 //
138 // LICM - This pass is a loop invariant code motion and memory promotion pass.
139 //
140 Pass *createLICMPass();
141 Pass *createLICMPass(unsigned LicmMssaOptCap,
142                      unsigned LicmMssaNoAccForPromotionCap);
143 
144 //===----------------------------------------------------------------------===//
145 //
146 // LoopSink - This pass sinks invariants from preheader to loop body where
147 // frequency is lower than loop preheader.
148 //
149 Pass *createLoopSinkPass();
150 
151 //===----------------------------------------------------------------------===//
152 //
153 // LoopPredication - This pass does loop predication on guards.
154 //
155 Pass *createLoopPredicationPass();
156 
157 //===----------------------------------------------------------------------===//
158 //
159 // LoopInterchange - This pass interchanges loops to provide a more
160 // cache-friendly memory access patterns.
161 //
162 Pass *createLoopInterchangePass();
163 
164 //===----------------------------------------------------------------------===//
165 //
166 // LoopStrengthReduce - This pass is strength reduces GEP instructions that use
167 // a loop's canonical induction variable as one of their indices.
168 //
169 Pass *createLoopStrengthReducePass();
170 
171 //===----------------------------------------------------------------------===//
172 //
173 // LoopUnswitch - This pass is a simple loop unswitching pass.
174 //
175 Pass *createLoopUnswitchPass(bool OptimizeForSize = false,
176                              bool hasBranchDivergence = false);
177 
178 //===----------------------------------------------------------------------===//
179 //
180 // LoopInstSimplify - This pass simplifies instructions in a loop's body.
181 //
182 Pass *createLoopInstSimplifyPass();
183 
184 //===----------------------------------------------------------------------===//
185 //
186 // LoopUnroll - This pass is a simple loop unrolling pass.
187 //
188 Pass *createLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
189                            bool ForgetAllSCEV = false, int Threshold = -1,
190                            int Count = -1, int AllowPartial = -1,
191                            int Runtime = -1, int UpperBound = -1,
192                            int AllowPeeling = -1);
193 // Create an unrolling pass for full unrolling that uses exact trip count only.
194 Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false,
195                                  bool ForgetAllSCEV = false);
196 
197 //===----------------------------------------------------------------------===//
198 //
199 // LoopUnrollAndJam - This pass is a simple loop unroll and jam pass.
200 //
201 Pass *createLoopUnrollAndJamPass(int OptLevel = 2);
202 
203 //===----------------------------------------------------------------------===//
204 //
205 // LoopReroll - This pass is a simple loop rerolling pass.
206 //
207 Pass *createLoopRerollPass();
208 
209 //===----------------------------------------------------------------------===//
210 //
211 // LoopRotate - This pass is a simple loop rotating pass.
212 //
213 Pass *createLoopRotatePass(int MaxHeaderSize = -1);
214 
215 //===----------------------------------------------------------------------===//
216 //
217 // LoopIdiom - This pass recognizes and replaces idioms in loops.
218 //
219 Pass *createLoopIdiomPass();
220 
221 //===----------------------------------------------------------------------===//
222 //
223 // LoopVersioningLICM - This pass is a loop versioning pass for LICM.
224 //
225 Pass *createLoopVersioningLICMPass();
226 
227 //===----------------------------------------------------------------------===//
228 //
229 // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory
230 // references. In basically undoes the PromoteMemoryToRegister pass to make cfg
231 // hacking easier.
232 //
233 FunctionPass *createDemoteRegisterToMemoryPass();
234 extern char &DemoteRegisterToMemoryID;
235 
236 //===----------------------------------------------------------------------===//
237 //
238 // Reassociate - This pass reassociates commutative expressions in an order that
239 // is designed to promote better constant propagation, GCSE, LICM, PRE...
240 //
241 // For example:  4 + (x + 5)  ->  x + (4 + 5)
242 //
243 FunctionPass *createReassociatePass();
244 
245 //===----------------------------------------------------------------------===//
246 //
247 // JumpThreading - Thread control through mult-pred/multi-succ blocks where some
248 // preds always go to some succ. Thresholds other than minus one override the
249 // internal BB duplication default threshold.
250 //
251 FunctionPass *createJumpThreadingPass(int Threshold = -1);
252 
253 //===----------------------------------------------------------------------===//
254 //
255 // CFGSimplification - Merge basic blocks, eliminate unreachable blocks,
256 // simplify terminator instructions, convert switches to lookup tables, etc.
257 //
258 FunctionPass *createCFGSimplificationPass(
259     unsigned Threshold = 1, bool ForwardSwitchCond = false,
260     bool ConvertSwitch = false, bool KeepLoops = true, bool SinkCommon = false,
261     std::function<bool(const Function &)> Ftor = nullptr);
262 
263 //===----------------------------------------------------------------------===//
264 //
265 // FlattenCFG - flatten CFG, reduce number of conditional branches by using
266 // parallel-and and parallel-or mode, etc...
267 //
268 FunctionPass *createFlattenCFGPass();
269 
270 //===----------------------------------------------------------------------===//
271 //
272 // CFG Structurization - Remove irreducible control flow
273 //
274 ///
275 /// When \p SkipUniformRegions is true the structizer will not structurize
276 /// regions that only contain uniform branches.
277 Pass *createStructurizeCFGPass(bool SkipUniformRegions = false);
278 
279 //===----------------------------------------------------------------------===//
280 //
281 // TailCallElimination - This pass eliminates call instructions to the current
282 // function which occur immediately before return instructions.
283 //
284 FunctionPass *createTailCallEliminationPass();
285 
286 //===----------------------------------------------------------------------===//
287 //
288 // EarlyCSE - This pass performs a simple and fast CSE pass over the dominator
289 // tree.
290 //
291 FunctionPass *createEarlyCSEPass(bool UseMemorySSA = false);
292 
293 //===----------------------------------------------------------------------===//
294 //
295 // GVNHoist - This pass performs a simple and fast GVN pass over the dominator
296 // tree to hoist common expressions from sibling branches.
297 //
298 FunctionPass *createGVNHoistPass();
299 
300 //===----------------------------------------------------------------------===//
301 //
302 // GVNSink - This pass uses an "inverted" value numbering to decide the
303 // similarity of expressions and sinks similar expressions into successors.
304 //
305 FunctionPass *createGVNSinkPass();
306 
307 //===----------------------------------------------------------------------===//
308 //
309 // MergedLoadStoreMotion - This pass merges loads and stores in diamonds. Loads
310 // are hoisted into the header, while stores sink into the footer.
311 //
312 FunctionPass *createMergedLoadStoreMotionPass(bool SplitFooterBB = false);
313 
314 //===----------------------------------------------------------------------===//
315 //
316 // GVN - This pass performs global value numbering and redundant load
317 // elimination cotemporaneously.
318 //
319 FunctionPass *createNewGVNPass();
320 
321 //===----------------------------------------------------------------------===//
322 //
323 // DivRemPairs - Hoist/decompose integer division and remainder instructions.
324 //
325 FunctionPass *createDivRemPairsPass();
326 
327 //===----------------------------------------------------------------------===//
328 //
329 // MemCpyOpt - This pass performs optimizations related to eliminating memcpy
330 // calls and/or combining multiple stores into memset's.
331 //
332 FunctionPass *createMemCpyOptPass();
333 
334 //===----------------------------------------------------------------------===//
335 //
336 // LoopDeletion - This pass performs DCE of non-infinite loops that it
337 // can prove are dead.
338 //
339 Pass *createLoopDeletionPass();
340 
341 //===----------------------------------------------------------------------===//
342 //
343 // ConstantHoisting - This pass prepares a function for expensive constants.
344 //
345 FunctionPass *createConstantHoistingPass();
346 
347 //===----------------------------------------------------------------------===//
348 //
349 // Sink - Code Sinking
350 //
351 FunctionPass *createSinkingPass();
352 
353 //===----------------------------------------------------------------------===//
354 //
355 // LowerAtomic - Lower atomic intrinsics to non-atomic form
356 //
357 Pass *createLowerAtomicPass();
358 
359 //===----------------------------------------------------------------------===//
360 //
361 // LowerGuardIntrinsic - Lower guard intrinsics to normal control flow.
362 //
363 Pass *createLowerGuardIntrinsicPass();
364 
365 //===----------------------------------------------------------------------===//
366 //
367 // LowerMatrixIntrinsics - Lower matrix intrinsics to vector operations.
368 //
369 Pass *createLowerMatrixIntrinsicsPass();
370 
371 //===----------------------------------------------------------------------===//
372 //
373 // LowerWidenableCondition - Lower widenable condition to i1 true.
374 //
375 Pass *createLowerWidenableConditionPass();
376 
377 //===----------------------------------------------------------------------===//
378 //
379 // MergeICmps - Merge integer comparison chains into a memcmp
380 //
381 Pass *createMergeICmpsLegacyPass();
382 
383 //===----------------------------------------------------------------------===//
384 //
385 // ValuePropagation - Propagate CFG-derived value information
386 //
387 Pass *createCorrelatedValuePropagationPass();
388 
389 //===----------------------------------------------------------------------===//
390 //
391 // InferAddressSpaces - Modify users of addrspacecast instructions with values
392 // in the source address space if using the destination address space is slower
393 // on the target. If AddressSpace is left to its default value, it will be
394 // obtained from the TargetTransformInfo.
395 //
396 FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
397 extern char &InferAddressSpacesID;
398 
399 //===----------------------------------------------------------------------===//
400 //
401 // LowerExpectIntrinsics - Removes llvm.expect intrinsics and creates
402 // "block_weights" metadata.
403 FunctionPass *createLowerExpectIntrinsicPass();
404 
405 //===----------------------------------------------------------------------===//
406 //
407 // LowerConstantIntrinsicss - Expand any remaining llvm.objectsize and
408 // llvm.is.constant intrinsic calls, even for the unknown cases.
409 //
410 FunctionPass *createLowerConstantIntrinsicsPass();
411 
412 //===----------------------------------------------------------------------===//
413 //
414 // PartiallyInlineLibCalls - Tries to inline the fast path of library
415 // calls such as sqrt.
416 //
417 FunctionPass *createPartiallyInlineLibCallsPass();
418 
419 //===----------------------------------------------------------------------===//
420 //
421 // SeparateConstOffsetFromGEP - Split GEPs for better CSE
422 //
423 FunctionPass *createSeparateConstOffsetFromGEPPass(bool LowerGEP = false);
424 
425 //===----------------------------------------------------------------------===//
426 //
427 // SpeculativeExecution - Aggressively hoist instructions to enable
428 // speculative execution on targets where branches are expensive.
429 //
430 FunctionPass *createSpeculativeExecutionPass();
431 
432 // Same as createSpeculativeExecutionPass, but does nothing unless
433 // TargetTransformInfo::hasBranchDivergence() is true.
434 FunctionPass *createSpeculativeExecutionIfHasBranchDivergencePass();
435 
436 //===----------------------------------------------------------------------===//
437 //
438 // StraightLineStrengthReduce - This pass strength-reduces some certain
439 // instruction patterns in straight-line code.
440 //
441 FunctionPass *createStraightLineStrengthReducePass();
442 
443 //===----------------------------------------------------------------------===//
444 //
445 // PlaceSafepoints - Rewrite any IR calls to gc.statepoints and insert any
446 // safepoint polls (method entry, backedge) that might be required.  This pass
447 // does not generate explicit relocation sequences - that's handled by
448 // RewriteStatepointsForGC which can be run at an arbitrary point in the pass
449 // order following this pass.
450 //
451 FunctionPass *createPlaceSafepointsPass();
452 
453 //===----------------------------------------------------------------------===//
454 //
455 // RewriteStatepointsForGC - Rewrite any gc.statepoints which do not yet have
456 // explicit relocations to include explicit relocations.
457 //
458 ModulePass *createRewriteStatepointsForGCLegacyPass();
459 
460 //===----------------------------------------------------------------------===//
461 //
462 // Float2Int - Demote floats to ints where possible.
463 //
464 FunctionPass *createFloat2IntPass();
465 
466 //===----------------------------------------------------------------------===//
467 //
468 // NaryReassociate - Simplify n-ary operations by reassociation.
469 //
470 FunctionPass *createNaryReassociatePass();
471 
472 //===----------------------------------------------------------------------===//
473 //
474 // LoopDistribute - Distribute loops.
475 //
476 FunctionPass *createLoopDistributePass();
477 
478 //===----------------------------------------------------------------------===//
479 //
480 // LoopFuse - Fuse loops.
481 //
482 FunctionPass *createLoopFusePass();
483 
484 //===----------------------------------------------------------------------===//
485 //
486 // LoopLoadElimination - Perform loop-aware load elimination.
487 //
488 FunctionPass *createLoopLoadEliminationPass();
489 
490 //===----------------------------------------------------------------------===//
491 //
492 // LoopVersioning - Perform loop multi-versioning.
493 //
494 FunctionPass *createLoopVersioningPass();
495 
496 //===----------------------------------------------------------------------===//
497 //
498 // LoopDataPrefetch - Perform data prefetching in loops.
499 //
500 FunctionPass *createLoopDataPrefetchPass();
501 
502 ///===---------------------------------------------------------------------===//
503 ModulePass *createNameAnonGlobalPass();
504 ModulePass *createCanonicalizeAliasesPass();
505 
506 //===----------------------------------------------------------------------===//
507 //
508 // LibCallsShrinkWrap - Shrink-wraps a call to function if the result is not
509 // used.
510 //
511 FunctionPass *createLibCallsShrinkWrapPass();
512 
513 //===----------------------------------------------------------------------===//
514 //
515 // LoopSimplifyCFG - This pass performs basic CFG simplification on loops,
516 // primarily to help other loop passes.
517 //
518 Pass *createLoopSimplifyCFGPass();
519 
520 //===----------------------------------------------------------------------===//
521 //
522 // WarnMissedTransformations - This pass emits warnings for leftover forced
523 // transformations.
524 //
525 Pass *createWarnMissedTransformationsPass();
526 } // End llvm namespace
527 
528 #endif
529