29 #define DEBUG_TYPE "nvptx"
47 static const unsigned MaxAggrCopySize = 128;
49 const char *getPassName()
const override {
50 return "Lower aggregate copies/intrinsics into loops";
72 unsigned srcAS = cast<PointerType>(srcAddr->
getType())->getAddressSpace();
73 unsigned dstAS = cast<PointerType>(dstAddr->
getType())->getAddressSpace();
112 unsigned dstAS = cast<PointerType>(dstAddr->
getType())->getAddressSpace();
130 bool NVPTXLowerAggrCopies::runOnFunction(
Function &
F) {
144 if (
LoadInst *load = dyn_cast<LoadInst>(II)) {
145 if (!load->hasOneUse())
152 if (
StoreInst *store = dyn_cast<StoreInst>(use)) {
153 if (store->getOperand(0) != load)
158 Value *len = intr->getLength();
161 if (
ConstantInt *len_int = dyn_cast<ConstantInt>(len)) {
162 if (len_int->getZExtValue() >= MaxAggrCopySize) {
169 }
else if (
MemSetInst *memsetintr = dyn_cast<MemSetInst>(II)) {
170 Value *len = memsetintr->getLength();
171 if (
ConstantInt *len_int = dyn_cast<ConstantInt>(len)) {
172 if (len_int->getZExtValue() >= MaxAggrCopySize) {
182 if ((aggrLoads.
size() == 0) && (aggrMemcpys.
size() == 0) &&
183 (aggrMemsets.
size() == 0))
191 Value *srcAddr = load->getOperand(0);
200 load->eraseFromParent();
212 cpy->eraseFromParent();
216 Value *len = memsetinst->getLength();
217 Value *val = memsetinst->getValue();
220 memsetinst->eraseFromParent();
227 return new NVPTXLowerAggrCopies();
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LoadInst * CreateLoad(Value *Ptr, const char *Name)
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - Add an incoming value to the end of the PHI list
bool isVolatile() const
isVolatile - Return true if this is a store to a volatile memory location.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
MemSetInst - This class wraps the llvm.memset intrinsic.
LoadInst - an instruction for reading from memory.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
MachineFunctionAnalysis - This class is a Pass that manages a MachineFunction object.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
FunctionPass * createLowerAggrCopies()
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
StoreInst - an instruction for storing to memory.
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
This is the shared class of boolean and integer constants.
static void convertMemSetToLoop(Instruction *splitAt, Value *dstAddr, Value *len, Value *val, LLVMContext &Context, Function &F)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static void convertTransferToLoop(Instruction *splitAt, Value *srcAddr, Value *dstAddr, Value *len, bool srcVolatile, bool dstVolatile, LLVMContext &Context, Function &F)
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static IntegerType * getInt32Ty(LLVMContext &C)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
const BasicBlock * getParent() const
LLVMContext & getContext() const
Get the global data context.