33 #include "llvm/IR/IntrinsicsARM.h" 45 #define DEBUG_TYPE "mve-gather-scatter-lowering" 49 cl::desc(
"Enable the generation of masked gathers and scatters"));
64 return "MVE gather/scatter lowering";
75 bool isLegalTypeAndAlignment(
unsigned NumElements,
unsigned ElemSize,
78 void lookThroughBitcast(
Value *&Ptr);
98 "MVE gather/scattering lowering pass",
false,
false)
101 return new MVEGatherScatterLowering();
104 bool MVEGatherScatterLowering::isLegalTypeAndAlignment(
unsigned NumElements,
106 unsigned Alignment) {
108 if (((NumElements == 4 && ElemSize == 32) ||
109 (NumElements == 8 && ElemSize == 16) ||
110 (NumElements == 16 && ElemSize == 8)) &&
111 ElemSize / 8 <= Alignment)
113 LLVM_DEBUG(
dbgs() <<
"masked gathers: instruction does not have valid " 114 <<
"alignment or vector type \n");
122 LLVM_DEBUG(
dbgs() <<
"masked gathers: no getelementpointer found\n");
125 LLVM_DEBUG(
dbgs() <<
"masked gathers: getelementpointer found. Loading" 126 <<
" from base + vector of offsets\n");
129 LLVM_DEBUG(
dbgs() <<
"masked gathers: gather from a vector of pointers" 130 <<
" hidden behind a getelementptr currently not" 131 <<
" supported. Expanding.\n");
135 LLVM_DEBUG(
dbgs() <<
"masked gathers: getelementptr with too many" 136 <<
" operands. Expanding.\n");
142 if (
ZExtInst *ZextOffs = dyn_cast<ZExtInst>(Offsets))
143 Offsets = ZextOffs->getOperand(0);
148 if (OffsType != Offsets->
getType()) {
152 Offsets = Builder.
CreateZExt(Offsets, OffsType,
"");
154 LLVM_DEBUG(
dbgs() <<
"masked gathers: no correct offset type. Can't" 155 <<
" create masked gather\n");
163 void MVEGatherScatterLowering::lookThroughBitcast(
Value *&Ptr) {
165 if (
auto *BitCast = dyn_cast<BitCastInst>(Ptr)) {
166 Type *BCTy = BitCast->getType();
167 Type *BCSrcTy = BitCast->getOperand(0)->getType();
169 LLVM_DEBUG(
dbgs() <<
"masked gathers: looking through bitcast\n");
170 Ptr = BitCast->getOperand(0);
177 LLVM_DEBUG(
dbgs() <<
"masked gathers: checking transform preconditions\n");
184 unsigned Alignment = cast<ConstantInt>(I->
getArgOperand(1))->getZExtValue();
191 lookThroughBitcast(Ptr);
197 Value *
Load = tryCreateMaskedGatherOffset(I, Ptr, Builder);
199 Load = tryCreateMaskedGatherBase(I, Ptr, Builder);
203 if (!isa<UndefValue>(PassThru) && !
match(PassThru,
m_Zero())) {
204 LLVM_DEBUG(
dbgs() <<
"masked gathers: found non-trivial passthru - " 205 <<
"creating select\n");
209 LLVM_DEBUG(
dbgs() <<
"masked gathers: successfully built masked gather\n");
215 Value *MVEGatherScatterLowering::tryCreateMaskedGatherBase(
218 LLVM_DEBUG(
dbgs() <<
"masked gathers: loading from vector of pointers\n");
230 Intrinsic::arm_mve_vldr_gather_base_predicated,
235 Value *MVEGatherScatterLowering::tryCreateMaskedGatherOffset(
240 Value *BasePtr = checkGEP(Offsets, Ty, Ptr, Builder);
250 if (GEPElemSize == 32 && ResultElemSize == 32) {
252 }
else if (GEPElemSize == 16 && ResultElemSize == 16) {
254 }
else if (GEPElemSize == 8) {
257 LLVM_DEBUG(
dbgs() <<
"masked gathers: incorrect scale for load. Can't" 258 <<
" create masked gather\n");
265 Intrinsic::arm_mve_vldr_gather_offset_predicated,
271 Intrinsic::arm_mve_vldr_gather_offset,
280 auto &TPC = getAnalysis<TargetPassConfig>();
283 if (!ST->hasMVEIntegerOps())
Pass interface - Implemented by all 'passes'.
void initializeMVEGatherScatterLoweringPass(PassRegistry &)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Value * getPointerOperand()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
This class represents lattice values for constants.
This class represents zero extension of integer types.
void push_back(const T &Elt)
LLVMContext & getContext() const
All values hold a context through their type.
bool isVectorTy() const
True if this is an instance of VectorType.
Value * getArgOperand(unsigned i) const
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
Type * getPointerElementType() const
Target-Independent Code Generator Pass Configuration Options.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Type * getType() const
All values are typed, get the type of this value.
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
Pass * createMVEGatherScatterLoweringPass()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static bool runOnFunction(Function &F, bool PostInlining)
INITIALIZE_PASS(MVEGatherScatterLowering, DEBUG_TYPE, "MVE gather/scattering lowering pass", false, false) Pass *llvm
initializer< Ty > init(const Ty &Val)
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Represent the analysis usage information of a pass.
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type...
FunctionPass class - This class is used to implement most global optimizations.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
unsigned getNumOperands() const
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type *> Types, ArrayRef< Value *> Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with args, mangled using Types.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getVectorNumElements() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_NODISCARD bool empty() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Primary interface to the complete machine description for the target machine.
cl::opt< bool > EnableMaskedGatherScatters("enable-arm-maskedgatscat", cl::Hidden, cl::init(false), cl::desc("Enable the generation of masked gathers and scatters"))
StringRef - Represent a constant reference to a string, i.e.
A wrapper class for inspecting calls to intrinsic functions.
This file describes how to lower LLVM code to machine code.