LLVM 20.0.0git
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 four 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/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/IR/PassManager.h"
62#include <functional>
63
64namespace llvm {
65
66class AssumptionCache;
67class BlockFrequencyInfo;
68class DemandedBits;
69class DominatorTree;
70class Function;
71class Instruction;
72class Loop;
73class LoopAccessInfoManager;
74class LoopInfo;
75class OptimizationRemarkEmitter;
76class ProfileSummaryInfo;
77class ScalarEvolution;
78class TargetLibraryInfo;
79class TargetTransformInfo;
80
81extern cl::opt<bool> EnableLoopInterleaving;
82extern cl::opt<bool> EnableLoopVectorization;
83
85 /// If false, consider all loops for interleaving.
86 /// If true, only loops that explicitly request interleaving are considered.
88
89 /// If false, consider all loops for vectorization.
90 /// If true, only loops that explicitly request vectorization are considered.
92
93 /// The current defaults when creating the pass with no arguments are:
94 /// EnableLoopInterleaving = true and EnableLoopVectorization = true. This
95 /// means that interleaving default is consistent with the cl::opt flag, while
96 /// vectorization is not.
97 /// FIXME: The default for EnableLoopVectorization in the cl::opt should be
98 /// set to true, and the corresponding change to account for this be made in
99 /// opt.cpp. The initializations below will become:
100 /// InterleaveOnlyWhenForced(!EnableLoopInterleaving)
101 /// VectorizeOnlyWhenForced(!EnableLoopVectorization).
108
111 return *this;
112 }
113
116 return *this;
117 }
118};
119
120/// Storage for information about made changes.
124
127};
128
129/// The LoopVectorize Pass.
130struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
131private:
132 /// If false, consider all loops for interleaving.
133 /// If true, only loops that explicitly request interleaving are considered.
134 bool InterleaveOnlyWhenForced;
135
136 /// If false, consider all loops for vectorization.
137 /// If true, only loops that explicitly request vectorization are considered.
138 bool VectorizeOnlyWhenForced;
139
140public:
142
154
157 function_ref<StringRef(StringRef)> MapClassName2PassName);
158
159 // Shim for old PM.
161
162 bool processLoop(Loop *L);
163};
164
165/// Reports a vectorization failure: print \p DebugMsg for debugging
166/// purposes along with the corresponding optimization remark \p RemarkName.
167/// If \p I is passed, it is an instruction that prevents vectorization.
168/// Otherwise, the loop \p TheLoop is used for the location of the remark.
169void reportVectorizationFailure(const StringRef DebugMsg,
170 const StringRef OREMsg, const StringRef ORETag,
171 OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr);
172
173/// Same as above, but the debug message and optimization remark are identical
174inline void reportVectorizationFailure(const StringRef DebugMsg,
175 const StringRef ORETag,
177 Loop *TheLoop,
178 Instruction *I = nullptr) {
179 reportVectorizationFailure(DebugMsg, DebugMsg, ORETag, ORE, TheLoop, I);
180}
181
182/// A marker analysis to determine if extra passes should be run after loop
183/// vectorization.
185 : public ShouldRunExtraPasses<ShouldRunExtraVectorPasses>,
186 public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
188};
189} // end namespace llvm
190
191#endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
This file provides a pass manager that only runs its passes if the provided marker analysis has been ...
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
A cache of @llvm.assume calls within a function.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
Analysis providing profile information.
The main scalar evolution driver.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< bool > EnableLoopVectorization
void reportVectorizationFailure(const StringRef DebugMsg, const StringRef OREMsg, const StringRef ORETag, OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I=nullptr)
Reports a vectorization failure: print DebugMsg for debugging purposes along with the corresponding o...
cl::opt< bool > EnableLoopInterleaving
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
LoopVectorizeOptions(bool InterleaveOnlyWhenForced, bool VectorizeOnlyWhenForced)
LoopVectorizeOptions & setVectorizeOnlyWhenForced(bool Value)
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
LoopVectorizeOptions()
The current defaults when creating the pass with no arguments are: EnableLoopInterleaving = true and ...
bool InterleaveOnlyWhenForced
If false, consider all loops for interleaving.
Definition: LoopVectorize.h:87
bool VectorizeOnlyWhenForced
If false, consider all loops for vectorization.
Definition: LoopVectorize.h:91
The LoopVectorize Pass.
TargetLibraryInfo * TLI
LoopVectorizeResult runImpl(Function &F)
ProfileSummaryInfo * PSI
LoopAccessInfoManager * LAIs
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
BlockFrequencyInfo * BFI
ScalarEvolution * SE
AssumptionCache * AC
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
OptimizationRemarkEmitter * ORE
TargetTransformInfo * TTI
Storage for information about made changes.
LoopVectorizeResult(bool MadeAnyChange, bool MadeCFGChange)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69
A marker analysis to determine if extra passes should be run on demand.
A marker analysis to determine if extra passes should be run after loop vectorization.