LLVM  10.0.0svn
LoopUnrollPass.h
Go to the documentation of this file.
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"
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  ForgetSCEV(ForgetSCEV) {}
43 
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 ///
67  int OptLevel;
68 
69  /// If false, use a cost model to determine whether unrolling of a loop is
70  /// profitable. If true, only loops that explicitly request unrolling via
71  /// metadata are considered. All other loops are skipped.
73 
74  /// If true, forget all loops when unrolling. If false, forget top-most loop
75  /// of the currently processed loops, which removes one entry at a time from
76  /// the internal SCEV records. For large loops, the former is faster.
77  const bool ForgetSCEV;
78 
79  LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false,
80  bool ForgetSCEV = false)
81  : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
82  ForgetSCEV(ForgetSCEV) {}
83 
84  /// Enables or disables partial unrolling. When disabled only full unrolling
85  /// is allowed.
86  LoopUnrollOptions &setPartial(bool Partial) {
87  AllowPartial = Partial;
88  return *this;
89  }
90 
91  /// Enables or disables unrolling of loops with runtime trip count.
92  LoopUnrollOptions &setRuntime(bool Runtime) {
93  AllowRuntime = Runtime;
94  return *this;
95  }
96 
97  /// Enables or disables loop peeling.
98  LoopUnrollOptions &setPeeling(bool Peeling) {
99  AllowPeeling = Peeling;
100  return *this;
101  }
102 
103  /// Enables or disables the use of trip count upper bound
104  /// in loop unrolling.
105  LoopUnrollOptions &setUpperBound(bool UpperBound) {
106  AllowUpperBound = UpperBound;
107  return *this;
108  }
109 
110  // Sets "optimization level" tuning parameter for loop unrolling.
112  OptLevel = O;
113  return *this;
114  }
115 
116  // Enables or disables loop peeling basing on profile.
118  AllowProfileBasedPeeling = O;
119  return *this;
120  }
121 
122  // Sets the max full unroll count.
124  FullUnrollMaxCount = O;
125  return *this;
126  }
127 };
128 
129 /// Loop unroll pass that will support both full and partial unrolling.
130 /// It is a function pass to have access to function and module analyses.
131 /// It will also put loops into canonical form (simplified and LCSSA).
132 class LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> {
133  LoopUnrollOptions UnrollOpts;
134 
135 public:
136  /// This uses the target information (or flags) to control the thresholds for
137  /// different unrolling stategies but supports all of them.
138  explicit LoopUnrollPass(LoopUnrollOptions UnrollOpts = {})
139  : UnrollOpts(UnrollOpts) {}
140 
142 };
143 
144 } // end namespace llvm
145 
146 #endif // LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
A set of parameters used to control various transforms performed by the LoopUnroll pass...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool OnlyWhenForced
If false, use a cost model to determine whether unrolling of a loop is profitable.
cl::opt< bool > ForgetSCEVInLoopUnroll
LoopUnrollOptions & setFullUnrollMaxCount(unsigned O)
LoopUnrollOptions & setUpperBound(bool UpperBound)
Enables or disables the use of trip count upper bound in loop unrolling.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
Loop unroll pass that only does full loop unrolling.
Loop unroll pass that will support both full and partial unrolling.
Optional< bool > AllowProfileBasedPeeling
Optional< bool > AllowPeeling
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:373
This header provides classes for managing per-loop analyses.
LoopUnrollOptions & setPartial(bool Partial)
Enables or disables partial unrolling.
LoopUnrollOptions(int OptLevel=2, bool OnlyWhenForced=false, bool ForgetSCEV=false)
LoopUnrollPass(LoopUnrollOptions UnrollOpts={})
This uses the target information (or flags) to control the thresholds for different unrolling stategi...
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
const bool ForgetSCEV
If true, forget all loops when unrolling.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
LoopUnrollOptions & setProfileBasedPeeling(int O)
LoopUnrollOptions & setOptLevel(int O)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
LoopFullUnrollPass(int OptLevel=2, bool OnlyWhenForced=false, bool ForgetSCEV=false)
Optional< bool > AllowPartial
Optional< bool > AllowUpperBound
LoopUnrollOptions & setRuntime(bool Runtime)
Enables or disables unrolling of loops with runtime trip count.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
A container for analyses that lazily runs them and caches their results.
Optional< bool > AllowRuntime
This header defines various interfaces for pass management in LLVM.
Optional< unsigned > FullUnrollMaxCount
LoopUnrollOptions & setPeeling(bool Peeling)
Enables or disables loop peeling.