102 using namespace llvm;
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");
168 Arg->replaceAllUsesWith(AllocA);
177 void NVPTXLowerArgs::markPointerAsGlobal(
Value *Ptr) {
185 InsertPt =
Arg->getParent()->getEntryBlock().begin();
188 InsertPt = ++cast<Instruction>(Ptr)->getIterator();
189 assert(InsertPt != InsertPt->getParent()->end() &&
190 "We don't call this function with Ptr being a terminator.");
201 PtrInGlobal->setOperand(0, Ptr);
207 bool NVPTXLowerArgs::runOnKernelFunction(
Function &
F) {
212 if (
LoadInst *LI = dyn_cast<LoadInst>(&
I)) {
213 if (LI->getType()->isPointerTy()) {
215 F.getParent()->getDataLayout());
217 if (
Arg->hasByValAttr()) {
219 markPointerAsGlobal(LI);
230 if (
Arg.hasByValAttr())
231 handleByValParam(&
Arg);
233 markPointerAsGlobal(&
Arg);
240 bool NVPTXLowerArgs::runOnDeviceFunction(
Function &F) {
243 handleByValParam(&
Arg);
248 return isKernelFunction(F) ? runOnKernelFunction(F) : runOnDeviceFunction(F);
253 return new NVPTXLowerArgs(TM);
void initializeNVPTXLowerArgsPass(PassRegistry &)
This class represents an incoming formal argument to a Function.
This class represents lattice values for constants.
void setAlignment(unsigned Align)
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
unsigned getAllocaAddrSpace() const
This class represents a conversion between pointers from one address space to another.
Type * getPointerElementType() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Class to represent struct types.
bool isKernelFunction(const Function &F)
Type * getType() const
All values are typed, get the type of this value.
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.
const BasicBlock & getEntryBlock() const
static bool runOnFunction(Function &F, bool PostInlining)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
The instances of the Type class are immutable: once they are created, they are never changed...
bool isPointerTy() const
True if this is an instance of PointerType.
const Instruction & front() const
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.
amdgpu Simplify well known AMD library false Value Value * Arg
FunctionPass * createNVPTXLowerArgsPass(const NVPTXTargetMachine *TM)
INITIALIZE_PASS(NVPTXLowerArgs, "nvptx-lower-args", "Lower arguments (NVPTX)", false, false) void NVPTXLowerArgs
StringRef getName() const
Return a constant reference to the value's name.
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())
Module * getParent()
Get the module that this global value is contained inside of...
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...
Type * getElementType() const
iterator_range< arg_iterator > args()
an instruction to allocate memory on the stack