/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h
Line | Count | Source |
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 | | |
59 | | #include "llvm/Analysis/AliasAnalysis.h" |
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 | | |
82 | | struct LoopVectorizeOptions { |
83 | | /// If false, consider all loops for interleaving. |
84 | | /// If true, only loops that explicitly request interleaving are considered. |
85 | | bool InterleaveOnlyWhenForced; |
86 | | |
87 | | /// If false, consider all loops for vectorization. |
88 | | /// If true, only loops that explicitly request vectorization are considered. |
89 | | bool VectorizeOnlyWhenForced; |
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). |
100 | | LoopVectorizeOptions() |
101 | 13.7k | : InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {} |
102 | | LoopVectorizeOptions(bool InterleaveOnlyWhenForced, |
103 | | bool VectorizeOnlyWhenForced) |
104 | | : InterleaveOnlyWhenForced(InterleaveOnlyWhenForced), |
105 | 137 | VectorizeOnlyWhenForced(VectorizeOnlyWhenForced) {} |
106 | | |
107 | 2 | LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) { |
108 | 2 | InterleaveOnlyWhenForced = Value; |
109 | 2 | return *this; |
110 | 2 | } |
111 | | |
112 | 2 | LoopVectorizeOptions &setVectorizeOnlyWhenForced(bool Value) { |
113 | 2 | VectorizeOnlyWhenForced = Value; |
114 | 2 | return *this; |
115 | 2 | } |
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. |
122 | | bool InterleaveOnlyWhenForced; |
123 | | |
124 | | /// If false, consider all loops for vectorization. |
125 | | /// If true, only loops that explicitly request vectorization are considered. |
126 | | bool VectorizeOnlyWhenForced; |
127 | | |
128 | | LoopVectorizePass(LoopVectorizeOptions Opts = {}) |
129 | | : InterleaveOnlyWhenForced(Opts.InterleaveOnlyWhenForced), |
130 | 13.8k | VectorizeOnlyWhenForced(Opts.VectorizeOnlyWhenForced) {} |
131 | | |
132 | | ScalarEvolution *SE; |
133 | | LoopInfo *LI; |
134 | | TargetTransformInfo *TTI; |
135 | | DominatorTree *DT; |
136 | | BlockFrequencyInfo *BFI; |
137 | | TargetLibraryInfo *TLI; |
138 | | DemandedBits *DB; |
139 | | AliasAnalysis *AA; |
140 | | AssumptionCache *AC; |
141 | | std::function<const LoopAccessInfo &(Loop &)> *GetLAA; |
142 | | OptimizationRemarkEmitter *ORE; |
143 | | ProfileSummaryInfo *PSI; |
144 | | |
145 | | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
146 | | |
147 | | // Shim for old PM. |
148 | | bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_, |
149 | | TargetTransformInfo &TTI_, DominatorTree &DT_, |
150 | | BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_, |
151 | | DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_, |
152 | | std::function<const LoopAccessInfo &(Loop &)> &GetLAA_, |
153 | | OptimizationRemarkEmitter &ORE_, ProfileSummaryInfo *PSI_); |
154 | | |
155 | | bool processLoop(Loop *L); |
156 | | }; |
157 | | |
158 | | } // end namespace llvm |
159 | | |
160 | | #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H |