LLVM 24.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. LoopVectorizationPlanner - A unit that builds VPlans for the candidate
23// vectorization factors, selects the best one and executes it to generate
24// the vector code.
25// 4. LoopVectorizationCostModel - A unit that checks for the profitability
26// of vectorization. It decides on the optimal vector width, which
27// can be one, if vectorization is not profitable.
28//
29// There is a development effort going on to migrate loop vectorizer to the
30// VPlan infrastructure and to introduce outer loop vectorization support (see
31// docs/VectorizationPlan.rst and
32// http://lists.llvm.org/pipermail/llvm-dev/2017-December/119523.html). For this
33// purpose, we temporarily introduced the VPlan-native vectorization path: an
34// alternative vectorization path that is natively implemented on top of the
35// VPlan infrastructure. See EnableVPlanNativePath for enabling.
36//
37//===----------------------------------------------------------------------===//
38//
39// The reduction-variable vectorization is based on the paper:
40// D. Nuzman and R. Henderson. Multi-platform Auto-vectorization.
41//
42// Variable uniformity checks are inspired by:
43// Karrenberg, R. and Hack, S. Whole Function Vectorization.
44//
45// The interleaved access vectorization is based on the paper:
46// Dorit Nuzman, Ira Rosen and Ayal Zaks. Auto-Vectorization of Interleaved
47// Data for SIMD
48//
49// Other ideas/concepts are from:
50// A. Zaks and D. Nuzman. Autovectorization in GCC-two years later.
51//
52// S. Maleki, Y. Gao, M. Garzaran, T. Wong and D. Padua. An Evaluation of
53// Vectorizing Compilers.
54//
55//===----------------------------------------------------------------------===//
56
57#ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
58#define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
59
60#include "llvm/IR/PassManager.h"
63#include <functional>
64
65namespace llvm {
66
67class AssumptionCache;
70class DemandedBits;
71class DominatorTree;
72class Function;
73class Instruction;
74class Loop;
76class LoopInfo;
79class ScalarEvolution;
82
84 /// If false, consider all loops for interleaving.
85 /// If true, only loops that explicitly request interleaving are considered.
87
88 /// If false, consider all loops for vectorization.
89 /// If true, only loops that explicitly request vectorization are considered.
91
92 /// The current defaults when creating the pass with no arguments are:
93 /// EnableLoopInterleaving = true and EnableLoopVectorization = true. This
94 /// means that interleaving default is consistent with the cl::opt flag, while
95 /// vectorization is not.
96 /// FIXME: The default for EnableLoopVectorization in the cl::opt should be
97 /// set to true, and the corresponding change to account for this be made in
98 /// opt.cpp. The initializations below will become:
99 /// InterleaveOnlyWhenForced(!EnableLoopInterleaving)
100 /// VectorizeOnlyWhenForced(!EnableLoopVectorization).
107
112
117};
118
119/// Storage for information about made changes.
127
128/// The LoopVectorize Pass.
129struct LoopVectorizePass : public OptionalPassInfoMixin<LoopVectorizePass> {
130private:
131 /// If false, consider all loops for interleaving.
132 /// If true, only loops that explicitly request interleaving are considered.
133 bool InterleaveOnlyWhenForced;
134
135 /// If false, consider all loops for vectorization.
136 /// If true, only loops that explicitly request vectorization are considered.
137 bool VectorizeOnlyWhenForced;
138
139public:
141
146 std::function<BlockFrequencyInfo &()> GetBFI;
147 std::function<const BranchProbabilityInfo &()> GetBPI;
155
156 bool CFGChanged = false;
157
159 LLVM_ABI void
161 function_ref<StringRef(StringRef)> MapClassName2PassName);
162
163 // Shim for old PM.
165
166 LLVM_ABI bool processLoop(Loop *L);
167};
168
169/// A marker analysis to determine if extra passes should be run after loop
170/// vectorization.
172 : public ShouldRunExtraPasses<ShouldRunExtraVectorPasses>,
173 public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
175};
176} // end namespace llvm
177
178#endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
#define LLVM_ABI
Definition Compiler.h:211
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:54
A cache of @llvm.assume calls within a function.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Analysis providing profile information.
The main scalar evolution driver.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:75
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:53
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
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.
bool VectorizeOnlyWhenForced
If false, consider all loops for vectorization.
TargetLibraryInfo * TLI
LLVM_ABI LoopVectorizeResult runImpl(Function &F)
LLVM_ABI bool processLoop(Loop *L)
ProfileSummaryInfo * PSI
LoopAccessInfoManager * LAIs
std::function< const BranchProbabilityInfo &()> GetBPI
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
LLVM_ABI LoopVectorizePass(LoopVectorizeOptions Opts={})
ScalarEvolution * SE
AssumptionCache * AC
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
OptimizationRemarkEmitter * ORE
std::function< BlockFrequencyInfo &()> GetBFI
TargetTransformInfo * TTI
Storage for information about made changes.
LoopVectorizeResult(bool MadeAnyChange, bool MadeCFGChange)
A CRTP mix-in for passes that can be skipped.
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.
static LLVM_ABI AnalysisKey Key