1 //===- LoopVectorize.h ------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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. 14 // 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. 18 // 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. 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/Proposal/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/Analysis/AliasAnalysis.h" 61 #include "llvm/IR/PassManager.h" 62 #include <functional> 63 64 namespace llvm { 65 66 class AssumptionCache; 67 class BlockFrequencyInfo; 68 class DemandedBits; 69 class DominatorTree; 70 class Function; 71 class Loop; 72 class LoopAccessInfo; 73 class LoopInfo; 74 class OptimizationRemarkEmitter; 75 class ScalarEvolution; 76 class TargetLibraryInfo; 77 class TargetTransformInfo; 78 79 /// The LoopVectorize Pass. 80 struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> { 81 /// If false, consider all loops for interleaving. 82 /// If true, only loops that explicitly request interleaving are considered. 83 bool InterleaveOnlyWhenForced = false; 84 85 /// If false, consider all loops for vectorization. 86 /// If true, only loops that explicitly request vectorization are considered. 87 bool VectorizeOnlyWhenForced = false; 88 89 ScalarEvolution *SE; 90 LoopInfo *LI; 91 TargetTransformInfo *TTI; 92 DominatorTree *DT; 93 BlockFrequencyInfo *BFI; 94 TargetLibraryInfo *TLI; 95 DemandedBits *DB; 96 AliasAnalysis *AA; 97 AssumptionCache *AC; 98 std::function<const LoopAccessInfo &(Loop &)> *GetLAA; 99 OptimizationRemarkEmitter *ORE; 100 101 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 102 103 // Shim for old PM. 104 bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_, 105 TargetTransformInfo &TTI_, DominatorTree &DT_, 106 BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_, 107 DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_, 108 std::function<const LoopAccessInfo &(Loop &)> &GetLAA_, 109 OptimizationRemarkEmitter &ORE); 110 111 bool processLoop(Loop *L); 112 }; 113 114 } // end namespace llvm 115 116 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H 117