LLVM  8.0.1
LoopUnrollPass.h
Go to the documentation of this file.
1 //===- LoopUnrollPass.h -----------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
11 #define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
12 
13 #include "llvm/ADT/Optional.h"
15 #include "llvm/IR/PassManager.h"
16 
17 namespace llvm {
18 
19 class Function;
20 class Loop;
21 class LPMUpdater;
22 
23 /// Loop unroll pass that only does full loop unrolling.
24 class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> {
25  const int OptLevel;
26 
27  /// If false, use a cost model to determine whether unrolling of a loop is
28  /// profitable. If true, only loops that explicitly request unrolling via
29  /// metadata are considered. All other loops are skipped.
30  const bool OnlyWhenForced;
31 
32 public:
33  explicit LoopFullUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false)
34  : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
35 
38 };
39 
40 /// A set of parameters used to control various transforms performed by the
41 /// LoopUnroll pass. Each of the boolean parameters can be set to:
42 /// true - enabling the transformation.
43 /// false - disabling the transformation.
44 /// None - relying on a global default.
45 ///
46 /// There is also OptLevel parameter, which is used for additional loop unroll
47 /// tuning.
48 ///
49 /// Intended use is to create a default object, modify parameters with
50 /// additional setters and then pass it to LoopUnrollPass.
51 ///
57  int OptLevel;
58 
59  /// If false, use a cost model to determine whether unrolling of a loop is
60  /// profitable. If true, only loops that explicitly request unrolling via
61  /// metadata are considered. All other loops are skipped.
63 
64  LoopUnrollOptions(int OptLevel = 2, bool OnlyWhenForced = false)
65  : OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced) {}
66 
67  /// Enables or disables partial unrolling. When disabled only full unrolling
68  /// is allowed.
69  LoopUnrollOptions &setPartial(bool Partial) {
70  AllowPartial = Partial;
71  return *this;
72  }
73 
74  /// Enables or disables unrolling of loops with runtime trip count.
75  LoopUnrollOptions &setRuntime(bool Runtime) {
76  AllowRuntime = Runtime;
77  return *this;
78  }
79 
80  /// Enables or disables loop peeling.
81  LoopUnrollOptions &setPeeling(bool Peeling) {
82  AllowPeeling = Peeling;
83  return *this;
84  }
85 
86  /// Enables or disables the use of trip count upper bound
87  /// in loop unrolling.
88  LoopUnrollOptions &setUpperBound(bool UpperBound) {
89  AllowUpperBound = UpperBound;
90  return *this;
91  }
92 
93  // Sets "optimization level" tuning parameter for loop unrolling.
95  OptLevel = O;
96  return *this;
97  }
98 };
99 
100 /// Loop unroll pass that will support both full and partial unrolling.
101 /// It is a function pass to have access to function and module analyses.
102 /// It will also put loops into canonical form (simplified and LCSSA).
103 class LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> {
104  LoopUnrollOptions UnrollOpts;
105 
106 public:
107  /// This uses the target information (or flags) to control the thresholds for
108  /// different unrolling stategies but supports all of them.
109  explicit LoopUnrollPass(LoopUnrollOptions UnrollOpts = {})
110  : UnrollOpts(UnrollOpts) {}
111 
113 };
114 
115 } // end namespace llvm
116 
117 #endif // LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
A set of parameters used to control various transforms performed by the LoopUnroll pass...
LoopUnrollOptions(int OptLevel=2, bool OnlyWhenForced=false)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool OnlyWhenForced
If false, use a cost model to determine whether unrolling of a loop is profitable.
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.
LoopFullUnrollPass(int OptLevel=2, bool OnlyWhenForced=false)
Optional< bool > AllowPeeling
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:366
This header provides classes for managing per-loop analyses.
LoopUnrollOptions & setPartial(bool Partial)
Enables or disables partial unrolling.
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
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
LoopUnrollOptions & setOptLevel(int O)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
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:465
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.
LoopUnrollOptions & setPeeling(bool Peeling)
Enables or disables loop peeling.