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