LLVM  10.0.0svn
LoopVectorize.h
Go to the documentation of this file.
1 //===- LoopVectorize.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 // This is the LLVM loop vectorizer. This pass modifies 'vectorizable' loops
10 // and generates target-independent LLVM-IR.
11 // The vectorizer uses the TargetTransformInfo analysis to estimate the costs
12 // of instructions in order to estimate the profitability of vectorization.
13 //
14 // The loop vectorizer combines consecutive loop iterations into a single
15 // 'wide' iteration. After this transformation the index is incremented
16 // by the SIMD vector width, and not by one.
17 //
18 // This pass has three parts:
19 // 1. The main loop pass that drives the different parts.
20 // 2. LoopVectorizationLegality - A unit that checks for the legality
21 // of the vectorization.
22 // 3. InnerLoopVectorizer - A unit that performs the actual
23 // widening of instructions.
24 // 4. LoopVectorizationCostModel - A unit that checks for the profitability
25 // of vectorization. It decides on the optimal vector width, which
26 // can be one, if vectorization is not profitable.
27 //
28 // There is a development effort going on to migrate loop vectorizer to the
29 // VPlan infrastructure and to introduce outer loop vectorization support (see
30 // docs/Proposal/VectorizationPlan.rst and
31 // http://lists.llvm.org/pipermail/llvm-dev/2017-December/119523.html). For this
32 // purpose, we temporarily introduced the VPlan-native vectorization path: an
33 // alternative vectorization path that is natively implemented on top of the
34 // VPlan infrastructure. See EnableVPlanNativePath for enabling.
35 //
36 //===----------------------------------------------------------------------===//
37 //
38 // The reduction-variable vectorization is based on the paper:
39 // D. Nuzman and R. Henderson. Multi-platform Auto-vectorization.
40 //
41 // Variable uniformity checks are inspired by:
42 // Karrenberg, R. and Hack, S. Whole Function Vectorization.
43 //
44 // The interleaved access vectorization is based on the paper:
45 // Dorit Nuzman, Ira Rosen and Ayal Zaks. Auto-Vectorization of Interleaved
46 // Data for SIMD
47 //
48 // Other ideas/concepts are from:
49 // A. Zaks and D. Nuzman. Autovectorization in GCC-two years later.
50 //
51 // S. Maleki, Y. Gao, M. Garzaran, T. Wong and D. Padua. An Evaluation of
52 // Vectorizing Compilers.
53 //
54 //===----------------------------------------------------------------------===//
55 
56 #ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
57 #define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
58 
60 #include "llvm/IR/PassManager.h"
61 #include <functional>
62 
63 namespace llvm {
64 
65 class AssumptionCache;
66 class BlockFrequencyInfo;
67 class DemandedBits;
68 class DominatorTree;
69 class Function;
70 class Loop;
71 class LoopAccessInfo;
72 class LoopInfo;
73 class OptimizationRemarkEmitter;
74 class ProfileSummaryInfo;
75 class ScalarEvolution;
76 class TargetLibraryInfo;
77 class TargetTransformInfo;
78 
79 extern cl::opt<bool> EnableLoopInterleaving;
80 extern cl::opt<bool> EnableLoopVectorization;
81 
83  /// If false, consider all loops for interleaving.
84  /// If true, only loops that explicitly request interleaving are considered.
86 
87  /// If false, consider all loops for vectorization.
88  /// If true, only loops that explicitly request vectorization are considered.
90 
91  /// The current defaults when creating the pass with no arguments are:
92  /// EnableLoopInterleaving = true and EnableLoopVectorization = true. This
93  /// means that interleaving default is consistent with the cl::opt flag, while
94  /// vectorization is not.
95  /// FIXME: The default for EnableLoopVectorization in the cl::opt should be
96  /// set to true, and the corresponding change to account for this be made in
97  /// opt.cpp. The initializations below will become:
98  /// InterleaveOnlyWhenForced(!EnableLoopInterleaving)
99  /// VectorizeOnlyWhenForced(!EnableLoopVectorization).
101  : InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {}
102  LoopVectorizeOptions(bool InterleaveOnlyWhenForced,
103  bool VectorizeOnlyWhenForced)
104  : InterleaveOnlyWhenForced(InterleaveOnlyWhenForced),
105  VectorizeOnlyWhenForced(VectorizeOnlyWhenForced) {}
106 
108  InterleaveOnlyWhenForced = Value;
109  return *this;
110  }
111 
113  VectorizeOnlyWhenForced = Value;
114  return *this;
115  }
116 };
117 
118 /// The LoopVectorize Pass.
119 struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
120  /// If false, consider all loops for interleaving.
121  /// If true, only loops that explicitly request interleaving are considered.
123 
124  /// If false, consider all loops for vectorization.
125  /// If true, only loops that explicitly request vectorization are considered.
127 
129  : InterleaveOnlyWhenForced(Opts.InterleaveOnlyWhenForced),
130  VectorizeOnlyWhenForced(Opts.VectorizeOnlyWhenForced) {}
131 
141  std::function<const LoopAccessInfo &(Loop &)> *GetLAA;
144 
146 
147  // Shim for old PM.
148  bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
151  DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
152  std::function<const LoopAccessInfo &(Loop &)> &GetLAA_,
154 
155  bool processLoop(Loop *L);
156 };
157 
158 } // end namespace llvm
159 
160 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
static bool runImpl(Function &F, TargetLibraryInfo &TLI, DominatorTree &DT)
This is the entry point for all transforms.
std::function< const LoopAccessInfo &(Loop &)> * GetLAA
This class represents lattice values for constants.
Definition: AllocatorList.h:23
AssumptionCache * AC
BlockFrequencyInfo * BFI
Analysis providing profile information.
The main scalar evolution driver.
A cache of @llvm.assume calls within a function.
F(f)
LoopVectorizeOptions()
The current defaults when creating the pass with no arguments are: EnableLoopInterleaving = true and ...
TargetLibraryInfo * TLI
ScalarEvolution * SE
ProfileSummaryInfo * PSI
cl::opt< bool > EnableLoopInterleaving
bool VectorizeOnlyWhenForced
If false, consider all loops for vectorization.
Definition: LoopVectorize.h:89
LoopVectorizePass(LoopVectorizeOptions Opts={})
LoopVectorizeOptions(bool InterleaveOnlyWhenForced, bool VectorizeOnlyWhenForced)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:372
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
bool InterleaveOnlyWhenForced
If false, consider all loops for interleaving.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
TargetTransformInfo * TTI
bool VectorizeOnlyWhenForced
If false, consider all loops for vectorization.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
LoopVectorizeOptions & setVectorizeOnlyWhenForced(bool Value)
Provides information about what library functions are available for the current target.
Drive the analysis of memory accesses in the loop.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:506
cl::opt< bool > EnableLoopVectorization
OptimizationRemarkEmitter * ORE
LLVM Value Representation.
Definition: Value.h:72
The LoopVectorize Pass.
bool InterleaveOnlyWhenForced
If false, consider all loops for interleaving.
Definition: LoopVectorize.h:85
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
The optimization diagnostic interface.