Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / include / llvm / Transforms / Scalar / LoopUnrollPass.h
blob1445373eb4f2d7a669546521eb67c4364d60818d
1 //===- LoopUnrollPass.h -----------------------------------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
10 #define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/Analysis/LoopAnalysisManager.h"
14 #include "llvm/IR/PassManager.h"
16 namespace llvm {
18 class Function;
19 class Loop;
20 class LPMUpdater;
22 /// Loop unroll pass that only does full loop unrolling.
23 class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> {
24 const int OptLevel;
26 /// If false, use a cost model to determine whether unrolling of a loop is
27 /// profitable. If true, only loops that explicitly request unrolling via
28 /// metadata are considered. All other loops are skipped.
29 const bool OnlyWhenForced;
31 public:
32 explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false)
33 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
35 PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
36 LoopStandardAnalysisResults &AR, LPMUpdater &U);
39 /// A set of parameters used to control various transforms performed by the
40 /// LoopUnroll pass. Each of the boolean parameters can be set to:
41 /// true - enabling the transformation.
42 /// false - disabling the transformation.
43 /// None - relying on a global default.
44 ///
45 /// There is also OptLevel parameter, which is used for additional loop unroll
46 /// tuning.
47 ///
48 /// Intended use is to create a default object, modify parameters with
49 /// additional setters and then pass it to LoopUnrollPass.
50 ///
51 struct LoopUnrollOptions {
52 Optional<bool> AllowPartial;
53 Optional<bool> AllowPeeling;
54 Optional<bool> AllowRuntime;
55 Optional<bool> AllowUpperBound;
56 int OptLevel;
58 /// If false, use a cost model to determine whether unrolling of a loop is
59 /// profitable. If true, only loops that explicitly request unrolling via
60 /// metadata are considered. All other loops are skipped.
61 bool OnlyWhenForced;
63 LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false)
64 : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
66 /// Enables or disables partial unrolling. When disabled only full unrolling
67 /// is allowed.
68 LoopUnrollOptions &setPartial(bool Partial) {
69 AllowPartial = Partial;
70 return *this;
73 /// Enables or disables unrolling of loops with runtime trip count.
74 LoopUnrollOptions &setRuntime(bool Runtime) {
75 AllowRuntime = Runtime;
76 return *this;
79 /// Enables or disables loop peeling.
80 LoopUnrollOptions &setPeeling(bool Peeling) {
81 AllowPeeling = Peeling;
82 return *this;
85 /// Enables or disables the use of trip count upper bound
86 /// in loop unrolling.
87 LoopUnrollOptions &setUpperBound(bool UpperBound) {
88 AllowUpperBound = UpperBound;
89 return *this;
92 // Sets "optimization level" tuning parameter for loop unrolling.
93 LoopUnrollOptions &setOptLevel(int O) {
94 OptLevel = O;
95 return *this;
99 /// Loop unroll pass that will support both full and partial unrolling.
100 /// It is a function pass to have access to function and module analyses.
101 /// It will also put loops into canonical form (simplified and LCSSA).
102 class LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> {
103 LoopUnrollOptions UnrollOpts;
105 public:
106 /// This uses the target information (or flags) to control the thresholds for
107 /// different unrolling stategies but supports all of them.
108 explicit LoopUnrollPass(LoopUnrollOptions UnrollOpts = {})
109 : UnrollOpts(UnrollOpts) {}
111 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
114 } // end namespace llvm
116 #endif // LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H