1 //===- llvm/Transforms/Utils/VectorUtils.h - Vector utilities -*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines some vectorizer utilities.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_UTILS_VECTORUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_VECTORUTILS_H
17 #include "llvm/Analysis/TargetLibraryInfo.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Intrinsics.h"
23 class GetElementPtrInst;
25 class ScalarEvolution;
29 /// \brief Identify if the intrinsic is trivially vectorizable.
30 /// This method returns true if the intrinsic's argument types are all
31 /// scalars for the scalar form of the intrinsic and all vectors for
32 /// the vector form of the intrinsic.
33 bool isTriviallyVectorizable(Intrinsic::ID ID);
35 /// \brief Identifies if the intrinsic has a scalar operand. It checks for
36 /// ctlz,cttz and powi special intrinsics whose argument is scalar.
37 bool hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx);
39 /// \brief Identify if call has a unary float signature
40 /// It returns input intrinsic ID if call has a single argument,
41 /// argument type and call instruction type should be floating
42 /// point type and call should only reads memory.
43 /// else return not_intrinsic.
44 Intrinsic::ID checkUnaryFloatSignature(const CallInst &I,
45 Intrinsic::ID ValidIntrinsicID);
47 /// \brief Identify if call has a binary float signature
48 /// It returns input intrinsic ID if call has two arguments,
49 /// arguments type and call instruction type should be floating
50 /// point type and call should only reads memory.
51 /// else return not_intrinsic.
52 Intrinsic::ID checkBinaryFloatSignature(const CallInst &I,
53 Intrinsic::ID ValidIntrinsicID);
55 /// \brief Returns intrinsic ID for call.
56 /// For the input call instruction it finds mapping intrinsic and returns
57 /// its intrinsic ID, in case it does not found it return not_intrinsic.
58 Intrinsic::ID getIntrinsicIDForCall(CallInst *CI, const TargetLibraryInfo *TLI);
60 /// \brief Find the operand of the GEP that should be checked for consecutive
61 /// stores. This ignores trailing indices that have no effect on the final
63 unsigned getGEPInductionOperand(const GetElementPtrInst *Gep);
65 /// \brief If the argument is a GEP, then returns the operand identified by
66 /// getGEPInductionOperand. However, if there is some other non-loop-invariant
67 /// operand, it returns that instead.
68 Value *stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp);
70 /// \brief If a value has only one user that is a CastInst, return it.
71 Value *getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty);
73 /// \brief Get the stride of a pointer access in a loop. Looks for symbolic
74 /// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
75 Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp);
77 /// \brief Given a vector and an element number, see if the scalar value is
78 /// already around as a register, for example if it were inserted then extracted
80 Value *findScalarElement(Value *V, unsigned EltNo);