1 //===---- LoopVectorize.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the LLVM loop vectorizer. This pass modifies 'vectorizable' loops
11 // and generates target-independent LLVM-IR.
12 // The vectorizer uses the TargetTransformInfo analysis to estimate the costs
13 // of instructions in order to estimate the profitability of vectorization.
15 // The loop vectorizer combines consecutive loop iterations into a single
16 // 'wide' iteration. After this transformation the index is incremented
17 // by the SIMD vector width, and not by one.
19 // This pass has three parts:
20 // 1. The main loop pass that drives the different parts.
21 // 2. LoopVectorizationLegality - A unit that checks for the legality
22 // of the vectorization.
23 // 3. InnerLoopVectorizer - A unit that performs the actual
24 // widening of instructions.
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.
29 //===----------------------------------------------------------------------===//
31 // The reduction-variable vectorization is based on the paper:
32 // D. Nuzman and R. Henderson. Multi-platform Auto-vectorization.
34 // Variable uniformity checks are inspired by:
35 // Karrenberg, R. and Hack, S. Whole Function Vectorization.
37 // The interleaved access vectorization is based on the paper:
38 // Dorit Nuzman, Ira Rosen and Ayal Zaks. Auto-Vectorization of Interleaved
41 // Other ideas/concepts are from:
42 // A. Zaks and D. Nuzman. Autovectorization in GCC-two years later.
44 // S. Maleki, Y. Gao, M. Garzaran, T. Wong and D. Padua. An Evaluation of
45 // Vectorizing Compilers.
47 //===----------------------------------------------------------------------===//
49 #ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
50 #define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
52 #include "llvm/ADT/MapVector.h"
53 #include "llvm/Analysis/AliasAnalysis.h"
54 #include "llvm/Analysis/AssumptionCache.h"
55 #include "llvm/Analysis/BasicAliasAnalysis.h"
56 #include "llvm/Analysis/BlockFrequencyInfo.h"
57 #include "llvm/Analysis/DemandedBits.h"
58 #include "llvm/Analysis/LoopAccessAnalysis.h"
59 #include "llvm/Analysis/LoopInfo.h"
60 #include "llvm/Analysis/LoopPassManager.h"
61 #include "llvm/Analysis/ScalarEvolution.h"
62 #include "llvm/Analysis/TargetTransformInfo.h"
63 #include "llvm/IR/Function.h"
64 #include "llvm/IR/PassManager.h"
69 /// The LoopVectorize Pass.
70 struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
71 bool DisableUnrolling = false;
72 /// If true, consider all loops for vectorization.
73 /// If false, only loops that explicitly request vectorization are
75 bool AlwaysVectorize = true;
79 TargetTransformInfo *TTI;
81 BlockFrequencyInfo *BFI;
82 TargetLibraryInfo *TLI;
86 std::function<const LoopAccessInfo &(Loop &)> *GetLAA;
88 BlockFrequency ColdEntryFreq;
90 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
93 bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
94 TargetTransformInfo &TTI_, DominatorTree &DT_,
95 BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_,
96 DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
97 std::function<const LoopAccessInfo &(Loop &)> &GetLAA_);
99 bool processLoop(Loop *L);
103 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H