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 //===----------------------------------------------------------------------===// 30 // 31 // The reduction-variable vectorization is based on the paper: 32 // D. Nuzman and R. Henderson. Multi-platform Auto-vectorization. 33 // 34 // Variable uniformity checks are inspired by: 35 // Karrenberg, R. and Hack, S. Whole Function Vectorization. 36 // 37 // The interleaved access vectorization is based on the paper: 38 // Dorit Nuzman, Ira Rosen and Ayal Zaks. Auto-Vectorization of Interleaved 39 // Data for SIMD 40 // 41 // Other ideas/concepts are from: 42 // A. Zaks and D. Nuzman. Autovectorization in GCC-two years later. 43 // 44 // S. Maleki, Y. Gao, M. Garzaran, T. Wong and D. Padua. An Evaluation of 45 // Vectorizing Compilers. 46 // 47 //===----------------------------------------------------------------------===// 48 49 #ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H 50 #define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H 51 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" 65 #include <functional> 66 67 namespace llvm { 68 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 74 /// considered. 75 bool AlwaysVectorize = true; 76 77 ScalarEvolution *SE; 78 LoopInfo *LI; 79 TargetTransformInfo *TTI; 80 DominatorTree *DT; 81 BlockFrequencyInfo *BFI; 82 TargetLibraryInfo *TLI; 83 DemandedBits *DB; 84 AliasAnalysis *AA; 85 AssumptionCache *AC; 86 std::function<const LoopAccessInfo &(Loop &)> *GetLAA; 87 88 BlockFrequency ColdEntryFreq; 89 90 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 91 92 // Shim for old PM. 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_); 98 99 bool processLoop(Loop *L); 100 }; 101 } 102 103 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H 104