102 using namespace llvm;
110 bool runOnFunction(
Function &
F)
override;
116 void handleByValParam(
Argument *Arg);
121 void markPointerAsGlobal(
Value *
Ptr);
128 return "Lower pointer arguments of CUDA kernels";
139 "Lower arguments (NVPTX)",
false,
false)
154 void NVPTXLowerArgs::handleByValParam(
Argument *Arg) {
159 assert(PType &&
"Expecting pointer type in handleByValParam");
167 Arg->replaceAllUsesWith(AllocA);
176 void NVPTXLowerArgs::markPointerAsGlobal(
Value *
Ptr) {
182 if (
Argument *Arg = dyn_cast<Argument>(Ptr)) {
184 InsertPt = Arg->getParent()->getEntryBlock().begin();
187 InsertPt = ++cast<Instruction>(
Ptr)->getIterator();
188 assert(InsertPt != InsertPt->getParent()->end() &&
189 "We don't call this function with Ptr being a terminator.");
206 bool NVPTXLowerArgs::runOnKernelFunction(
Function &
F) {
211 if (
LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
212 if (LI->getType()->isPointerTy()) {
214 F.getParent()->getDataLayout());
215 if (
Argument *Arg = dyn_cast<Argument>(UO)) {
216 if (Arg->hasByValAttr()) {
218 markPointerAsGlobal(LI);
228 if (Arg.getType()->isPointerTy()) {
229 if (Arg.hasByValAttr())
230 handleByValParam(&Arg);
232 markPointerAsGlobal(&Arg);
239 bool NVPTXLowerArgs::runOnDeviceFunction(
Function &F) {
241 if (Arg.getType()->isPointerTy() && Arg.hasByValAttr())
242 handleByValParam(&Arg);
246 bool NVPTXLowerArgs::runOnFunction(
Function &F) {
247 return isKernelFunction(F) ? runOnKernelFunction(F) : runOnDeviceFunction(F);
252 return new NVPTXLowerArgs(TM);
void initializeNVPTXLowerArgsPass(PassRegistry &)
LLVM Argument representation.
void setAlignment(unsigned Align)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
const Instruction & front() const
An instruction for reading from memory.
Type * getElementType() const
Type * getPointerElementType() const
StringRef getName() const
Return a constant reference to the value's name.
This class represents a conversion between pointers from one address space to another.
Class to represent struct types.
bool isKernelFunction(const Function &F)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Class to represent pointers.
The instances of the Type class are immutable: once they are created, they are never changed...
FunctionPass class - This class is used to implement most global optimizations.
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
Iterator for intrusive lists based on ilist_node.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
INITIALIZE_PASS(NVPTXLowerArgs,"nvptx-lower-args","Lower arguments (NVPTX)", false, false) void NVPTXLowerArgs
const BasicBlock & getEntryBlock() const
void setOperand(unsigned i, Value *Val)
FunctionPass * createNVPTXLowerArgsPass(const NVPTXTargetMachine *TM)
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())
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
LLVM Value Representation.
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
iterator_range< arg_iterator > args()
an instruction to allocate memory on the stack