/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
Line | Count | Source (jump to first uncovered line) |
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 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H |
10 | | #define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H |
11 | | |
12 | | #include "llvm/ADT/Optional.h" |
13 | | #include "llvm/Analysis/LoopAnalysisManager.h" |
14 | | #include "llvm/IR/PassManager.h" |
15 | | |
16 | | namespace llvm { |
17 | | |
18 | | extern cl::opt<bool> ForgetSCEVInLoopUnroll; |
19 | | |
20 | | class Function; |
21 | | class Loop; |
22 | | class LPMUpdater; |
23 | | |
24 | | /// Loop unroll pass that only does full loop unrolling. |
25 | | class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> { |
26 | | const int OptLevel; |
27 | | |
28 | | /// If false, use a cost model to determine whether unrolling of a loop is |
29 | | /// profitable. If true, only loops that explicitly request unrolling via |
30 | | /// metadata are considered. All other loops are skipped. |
31 | | const bool OnlyWhenForced; |
32 | | |
33 | | /// If true, forget all loops when unrolling. If false, forget top-most loop |
34 | | /// of the currently processed loops, which removes one entry at a time from |
35 | | /// the internal SCEV records. For large loops, the former is faster. |
36 | | const bool ForgetSCEV; |
37 | | |
38 | | public: |
39 | | explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, |
40 | | bool ForgetSCEV = false) |
41 | | : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced), |
42 | 139 | ForgetSCEV(ForgetSCEV) {} |
43 | | |
44 | | PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, |
45 | | LoopStandardAnalysisResults &AR, LPMUpdater &U); |
46 | | }; |
47 | | |
48 | | /// A set of parameters used to control various transforms performed by the |
49 | | /// LoopUnroll pass. Each of the boolean parameters can be set to: |
50 | | /// true - enabling the transformation. |
51 | | /// false - disabling the transformation. |
52 | | /// None - relying on a global default. |
53 | | /// |
54 | | /// There is also OptLevel parameter, which is used for additional loop unroll |
55 | | /// tuning. |
56 | | /// |
57 | | /// Intended use is to create a default object, modify parameters with |
58 | | /// additional setters and then pass it to LoopUnrollPass. |
59 | | /// |
60 | | struct LoopUnrollOptions { |
61 | | Optional<bool> AllowPartial; |
62 | | Optional<bool> AllowPeeling; |
63 | | Optional<bool> AllowRuntime; |
64 | | Optional<bool> AllowUpperBound; |
65 | | int OptLevel; |
66 | | |
67 | | /// If false, use a cost model to determine whether unrolling of a loop is |
68 | | /// profitable. If true, only loops that explicitly request unrolling via |
69 | | /// metadata are considered. All other loops are skipped. |
70 | | bool OnlyWhenForced; |
71 | | |
72 | | /// If true, forget all loops when unrolling. If false, forget top-most loop |
73 | | /// of the currently processed loops, which removes one entry at a time from |
74 | | /// the internal SCEV records. For large loops, the former is faster. |
75 | | const bool ForgetSCEV; |
76 | | |
77 | | LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false, |
78 | | bool ForgetSCEV = false) |
79 | | : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced), |
80 | 130 | ForgetSCEV(ForgetSCEV) {} |
81 | | |
82 | | /// Enables or disables partial unrolling. When disabled only full unrolling |
83 | | /// is allowed. |
84 | 0 | LoopUnrollOptions &setPartial(bool Partial) { |
85 | 0 | AllowPartial = Partial; |
86 | 0 | return *this; |
87 | 0 | } |
88 | | |
89 | | /// Enables or disables unrolling of loops with runtime trip count. |
90 | 3 | LoopUnrollOptions &setRuntime(bool Runtime) { |
91 | 3 | AllowRuntime = Runtime; |
92 | 3 | return *this; |
93 | 3 | } |
94 | | |
95 | | /// Enables or disables loop peeling. |
96 | 3 | LoopUnrollOptions &setPeeling(bool Peeling) { |
97 | 3 | AllowPeeling = Peeling; |
98 | 3 | return *this; |
99 | 3 | } |
100 | | |
101 | | /// Enables or disables the use of trip count upper bound |
102 | | /// in loop unrolling. |
103 | 0 | LoopUnrollOptions &setUpperBound(bool UpperBound) { |
104 | 0 | AllowUpperBound = UpperBound; |
105 | 0 | return *this; |
106 | 0 | } |
107 | | |
108 | | // Sets "optimization level" tuning parameter for loop unrolling. |
109 | 0 | LoopUnrollOptions &setOptLevel(int O) { |
110 | 0 | OptLevel = O; |
111 | 0 | return *this; |
112 | 0 | } |
113 | | }; |
114 | | |
115 | | /// Loop unroll pass that will support both full and partial unrolling. |
116 | | /// It is a function pass to have access to function and module analyses. |
117 | | /// It will also put loops into canonical form (simplified and LCSSA). |
118 | | class LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> { |
119 | | LoopUnrollOptions UnrollOpts; |
120 | | |
121 | | public: |
122 | | /// This uses the target information (or flags) to control the thresholds for |
123 | | /// different unrolling stategies but supports all of them. |
124 | | explicit LoopUnrollPass(LoopUnrollOptions UnrollOpts = {}) |
125 | 130 | : UnrollOpts(UnrollOpts) {} |
126 | | |
127 | | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
128 | | }; |
129 | | |
130 | | } // end namespace llvm |
131 | | |
132 | | #endif // LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H |