Skip to content
Snippets Groups Projects
Commit 953c4af0 authored by Prakalp Srivastava's avatar Prakalp Srivastava
Browse files

(1) Addrspace issue of NVPTX backend handled by swapping the enum values of

Global and Generic memory in NVPTX backend. Still commiting the code with
functions to change address space of arguments, but not calling them. Might need
in future if things break.
parent a2850070
No related branches found
No related tags found
No related merge requests found
......@@ -90,6 +90,7 @@ namespace {
//Functions
std::string getKernelsModuleName(Module &M);
void fixValueAddrspace(Value* V, unsigned addrspace);
void changeArgAddrspace(Function* F, unsigned i);
void addCLMetadata(Function* F);
void writeKernelsModule();
......@@ -841,7 +842,6 @@ namespace {
re = IItoRemove.rend(); ri != re; ++ri)
(*ri)->eraseFromParent();
changeArgAddrspace(F_nvptx, 1);
addCLMetadata(F_nvptx);
DEBUG(errs() << KernelM);
......@@ -874,7 +874,39 @@ namespace {
return mid.append("_kernels.ll");
}
void CodeGenTraversal::changeArgAddrspace(Function* F, unsigned i) {
void CodeGenTraversal::fixValueAddrspace(Value* V, unsigned addrspace) {
assert(isa<PointerType>(V->getType())
&& "Value should be of Pointer Type!");
PointerType* OldTy = cast<PointerType>(V->getType());
PointerType* NewTy = PointerType::get(OldTy->getElementType(), addrspace);
V->mutateType(NewTy);
for(Value::use_iterator ui = V->use_begin(), ue = V->use_end(); ui != ue; ui++) {
// Change all uses producing pointer type in same address space to new
// addressspace.
if(PointerType* PTy = dyn_cast<PointerType>(ui->getType())) {
if(PTy->getAddressSpace() == OldTy->getAddressSpace()) {
fixValueAddrspace(*ui, addrspace);
}
}
}
}
void CodeGenTraversal::changeArgAddrspace(Function* F, unsigned addrspace) {
std::vector<Type*> ArgTypes;
for(auto& arg: F->getArgumentList()) {
DEBUG(errs() << arg << "\n");
if(PointerType* argTy = dyn_cast<PointerType>(arg.getType())) {
if(argTy->getAddressSpace() == 0) {
fixValueAddrspace(&arg, addrspace);
}
}
ArgTypes.push_back(arg.getType());
}
FunctionType* FTy = FunctionType::get(F->getReturnType(), ArgTypes, false);
PointerType* PTy = FTy->getPointerTo(cast<PointerType>(F->getType())->getAddressSpace());
F->mutateType(PTy);
DEBUG(errs() << *F->getFunctionType() << "\n" <<*F << "\n");
}
void CodeGenTraversal::addCLMetadata(Function* F) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment