1 //===- llvm/Transforms/Utils/VectorUtils.h - Vector utilities -*- 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 file defines some vectorizer utilities. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TRANSFORMS_UTILS_VECTORUTILS_H 15 #define LLVM_TRANSFORMS_UTILS_VECTORUTILS_H 16 17 #include "llvm/ADT/ArrayRef.h" 18 #include "llvm/ADT/MapVector.h" 19 #include "llvm/Analysis/TargetLibraryInfo.h" 20 #include "llvm/IR/IntrinsicInst.h" 21 #include "llvm/IR/Intrinsics.h" 22 23 namespace llvm { 24 25 struct DemandedBits; 26 class GetElementPtrInst; 27 class Loop; 28 class ScalarEvolution; 29 class TargetTransformInfo; 30 class Type; 31 class Value; 32 33 /// \brief Identify if the intrinsic is trivially vectorizable. 34 /// This method returns true if the intrinsic's argument types are all 35 /// scalars for the scalar form of the intrinsic and all vectors for 36 /// the vector form of the intrinsic. 37 bool isTriviallyVectorizable(Intrinsic::ID ID); 38 39 /// \brief Identifies if the intrinsic has a scalar operand. It checks for 40 /// ctlz,cttz and powi special intrinsics whose argument is scalar. 41 bool hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx); 42 43 /// \brief Identify if call has a unary float signature 44 /// It returns input intrinsic ID if call has a single argument, 45 /// argument type and call instruction type should be floating 46 /// point type and call should only reads memory. 47 /// else return not_intrinsic. 48 Intrinsic::ID checkUnaryFloatSignature(const CallInst &I, 49 Intrinsic::ID ValidIntrinsicID); 50 51 /// \brief Identify if call has a binary float signature 52 /// It returns input intrinsic ID if call has two arguments, 53 /// arguments type and call instruction type should be floating 54 /// point type and call should only reads memory. 55 /// else return not_intrinsic. 56 Intrinsic::ID checkBinaryFloatSignature(const CallInst &I, 57 Intrinsic::ID ValidIntrinsicID); 58 59 /// \brief Returns intrinsic ID for call. 60 /// For the input call instruction it finds mapping intrinsic and returns 61 /// its intrinsic ID, in case it does not found it return not_intrinsic. 62 Intrinsic::ID getIntrinsicIDForCall(CallInst *CI, const TargetLibraryInfo *TLI); 63 64 /// \brief Find the operand of the GEP that should be checked for consecutive 65 /// stores. This ignores trailing indices that have no effect on the final 66 /// pointer. 67 unsigned getGEPInductionOperand(const GetElementPtrInst *Gep); 68 69 /// \brief If the argument is a GEP, then returns the operand identified by 70 /// getGEPInductionOperand. However, if there is some other non-loop-invariant 71 /// operand, it returns that instead. 72 Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp); 73 74 /// \brief If a value has only one user that is a CastInst, return it. 75 Value *getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty); 76 77 /// \brief Get the stride of a pointer access in a loop. Looks for symbolic 78 /// strides "a[i*stride]". Returns the symbolic stride, or null otherwise. 79 Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp); 80 81 /// \brief Given a vector and an element number, see if the scalar value is 82 /// already around as a register, for example if it were inserted then extracted 83 /// from the vector. 84 Value *findScalarElement(Value *V, unsigned EltNo); 85 86 /// \brief Get splat value if the input is a splat vector or return nullptr. 87 /// The value may be extracted from a splat constants vector or from 88 /// a sequence of instructions that broadcast a single value into a vector. 89 const Value *getSplatValue(const Value *V); 90 91 /// \brief Compute a map of integer instructions to their minimum legal type 92 /// size. 93 /// 94 /// C semantics force sub-int-sized values (e.g. i8, i16) to be promoted to int 95 /// type (e.g. i32) whenever arithmetic is performed on them. 96 /// 97 /// For targets with native i8 or i16 operations, usually InstCombine can shrink 98 /// the arithmetic type down again. However InstCombine refuses to create 99 /// illegal types, so for targets without i8 or i16 registers, the lengthening 100 /// and shrinking remains. 101 /// 102 /// Most SIMD ISAs (e.g. NEON) however support vectors of i8 or i16 even when 103 /// their scalar equivalents do not, so during vectorization it is important to 104 /// remove these lengthens and truncates when deciding the profitability of 105 /// vectorization. 106 /// 107 /// This function analyzes the given range of instructions and determines the 108 /// minimum type size each can be converted to. It attempts to remove or 109 /// minimize type size changes across each def-use chain, so for example in the 110 /// following code: 111 /// 112 /// %1 = load i8, i8* 113 /// %2 = add i8 %1, 2 114 /// %3 = load i16, i16* 115 /// %4 = zext i8 %2 to i32 116 /// %5 = zext i16 %3 to i32 117 /// %6 = add i32 %4, %5 118 /// %7 = trunc i32 %6 to i16 119 /// 120 /// Instruction %6 must be done at least in i16, so computeMinimumValueSizes 121 /// will return: {%1: 16, %2: 16, %3: 16, %4: 16, %5: 16, %6: 16, %7: 16}. 122 /// 123 /// If the optional TargetTransformInfo is provided, this function tries harder 124 /// to do less work by only looking at illegal types. 125 MapVector<Instruction*, uint64_t> 126 computeMinimumValueSizes(ArrayRef<BasicBlock*> Blocks, 127 DemandedBits &DB, 128 const TargetTransformInfo *TTI=nullptr); 129 130 } // llvm namespace 131 132 #endif 133