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