Home | History | Annotate | Download | only in Vectorize
      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/Analysis/AliasAnalysis.h"
     53 #include "llvm/IR/PassManager.h"
     54 #include <functional>
     55 
     56 namespace llvm {
     57 
     58 class AssumptionCache;
     59 class BlockFrequencyInfo;
     60 class DemandedBits;
     61 class DominatorTree;
     62 class Function;
     63 class Loop;
     64 class LoopAccessInfo;
     65 class LoopInfo;
     66 class OptimizationRemarkEmitter;
     67 class ScalarEvolution;
     68 class TargetLibraryInfo;
     69 class TargetTransformInfo;
     70 
     71 /// The LoopVectorize Pass.
     72 struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
     73   bool DisableUnrolling = false;
     74 
     75   /// If true, consider all loops for vectorization.
     76   /// If false, only loops that explicitly request vectorization are
     77   /// considered.
     78   bool AlwaysVectorize = true;
     79 
     80   ScalarEvolution *SE;
     81   LoopInfo *LI;
     82   TargetTransformInfo *TTI;
     83   DominatorTree *DT;
     84   BlockFrequencyInfo *BFI;
     85   TargetLibraryInfo *TLI;
     86   DemandedBits *DB;
     87   AliasAnalysis *AA;
     88   AssumptionCache *AC;
     89   std::function<const LoopAccessInfo &(Loop &)> *GetLAA;
     90   OptimizationRemarkEmitter *ORE;
     91 
     92   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
     93 
     94   // Shim for old PM.
     95   bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
     96                TargetTransformInfo &TTI_, DominatorTree &DT_,
     97                BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_,
     98                DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
     99                std::function<const LoopAccessInfo &(Loop &)> &GetLAA_,
    100                OptimizationRemarkEmitter &ORE);
    101 
    102   bool processLoop(Loop *L);
    103 };
    104 
    105 } // end namespace llvm
    106 
    107 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H
    108