Skip to content
Snippets Groups Projects
Commit b2920eec authored by kotsifa2's avatar kotsifa2
Browse files

Edited the transformation of non-void functions to void in dfg2llvm-nvptx.

Now we add an argument that is a pointer to the function's (struct) return type.
parent 10e2dff7
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define ENABLE_ASSERTS #define ENABLE_ASSERTS
#define TARGET_PTX 32 #define TARGET_PTX 32
#define GLOBAL_ADDRSPACE 1
#define DEBUG_TYPE "DFG2LLVM_NVPTX" #define DEBUG_TYPE "DFG2LLVM_NVPTX"
#include "llvm/IR/DataLayout.h" #include "llvm/IR/DataLayout.h"
...@@ -70,7 +71,7 @@ namespace { ...@@ -70,7 +71,7 @@ namespace {
ValueMap<Function*, Function*> FMap; ValueMap<Function*, Function*> FMap;
//Functions //Functions
void addReturnValueArgs(Function* F); void transformFunctionToVoid(Function* F);
void codeGen(DFInternalNode* N); void codeGen(DFInternalNode* N);
void codeGen(DFLeafNode* N); void codeGen(DFLeafNode* N);
...@@ -112,13 +113,12 @@ namespace { ...@@ -112,13 +113,12 @@ namespace {
if (N == KernelLaunchNode) { if (N == KernelLaunchNode) {
DEBUG(errs() << "Found kernel launch node. Generating host code.\n"); DEBUG(errs() << "Found kernel launch node. Generating host code.\n");
//TODO //TODO
DEBUG(errs() << "Changing pointer address spaces to addrspace 1.\n");
//TODO // Now the remaining nodes to be visited should be ignored
KernelLaunchNode = NULL;
} else { } else {
DEBUG(errs() << "Found intermediate node. Generating device code.\n"); DEBUG(errs() << "Found intermediate node. Generating device code.\n");
//TODO //TODO
DEBUG(errs() << "Changing leaf node function to device function.\n");
//TODO
} }
} }
...@@ -169,7 +169,7 @@ namespace { ...@@ -169,7 +169,7 @@ namespace {
FMap[F] = F_nvptx; FMap[F] = F_nvptx;
} }
addReturnValueArgs(F_nvptx); transformFunctionToVoid(F_nvptx);
// Go through all the instructions // Go through all the instructions
for (inst_iterator i = inst_begin(F_nvptx), e = inst_end(F_nvptx); i != e; ++i) { for (inst_iterator i = inst_begin(F_nvptx), e = inst_end(F_nvptx); i != e; ++i) {
...@@ -417,11 +417,11 @@ namespace { ...@@ -417,11 +417,11 @@ namespace {
return true; return true;
} }
void CodeGenTraversal::addReturnValueArgs(Function* F) { void CodeGenTraversal::transformFunctionToVoid(Function* F) {
// FIXME: Maybe do that using the Node? // FIXME: Maybe do that using the Node?
StructType* FRetTy = cast<StructType>(F->getReturnType()); StructType* FRetTy = cast<StructType>(F->getReturnType());
assert(FRetTy && "Return Type is NULL, it should be a struct"); assert(FRetTy && "Return Type must always be a struct");
// Keeps return statements, because we will need to replace them // Keeps return statements, because we will need to replace them
std::vector<ReturnInst *> RItoRemove; std::vector<ReturnInst *> RItoRemove;
...@@ -445,31 +445,27 @@ namespace { ...@@ -445,31 +445,27 @@ namespace {
return; return;
} }
// The struct has return values that need to be converted to parameters // The struct has return values, thus needs to be converted to parameter
int initialNumParams = F->arg_size(); int initialNumParams = F->arg_size();
// Create the extra parameters with appropriate pointer types Type* ArgType = FRetTy->getPointerTo(GLOBAL_ADDRSPACE);
for (unsigned i=0; i < FRetTy->getNumElements(); i++) { new Argument(ArgType, "ret_struct_ptr", F);
Type* FieldType = FRetTy->getElementType(i); DEBUG(errs() << "\tCreated parameter\n");
Type* ArgType = FieldType->getPointerTo(); //TODO: AddressSpace
new Argument(ArgType, "ret_arg_" + convertInt(i), F);
}
DEBUG(errs() << "\tCreated parameters\n");
// Create the argument type list with added argument types // Create the argument type list with the added argument's type
std::vector<Type*> ArgTypes; std::vector<Type*> ArgTypes;
for(Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); for(Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
ai != ae; ++ai) { ai != ae; ++ai) {
ArgTypes.push_back(ai->getType()); ArgTypes.push_back(ai->getType());
} }
// Find where the new parameters start in the header // Find where the new parameter is in the header
Function::arg_iterator ai, ae; Function::arg_iterator ai, ae;
int check = 0; int check = 0;
for (ai = F->arg_begin(), ae = F->arg_end(); for (ai = F->arg_begin(), ae = F->arg_end();
ai != ae; ++ai) { ai != ae; ++ai) {
if (ai->getName().startswith("ret_arg_")) break; if (ai->getName().equals("ret_struct_ptr")) break;
check++; check++;
} }
...@@ -486,15 +482,7 @@ namespace { ...@@ -486,15 +482,7 @@ namespace {
// StructType* RetType = cast<StructType>(RetVal->getType()); // StructType* RetType = cast<StructType>(RetVal->getType());
// assert(RetType && "Return type is not a struct"); // assert(RetType && "Return type is not a struct");
Function::arg_iterator ret_ai = ai; new StoreInst(RetVal, &(*ai), RI);
for (unsigned i=0; i < FRetTy->getNumElements(); i++, ++ret_ai) {
std::vector<unsigned> IndexList;
IndexList.push_back(i);
ExtractValueInst* EI = ExtractValueInst::Create(RetVal, IndexList, Twine(""), RI);
// StoreInst* SI = new StoreInst(EI, &(*ret_ai), RI);
new StoreInst(EI, &(*ret_ai), RI);
}
ReturnInst::Create((F->getContext()), 0, RI); ReturnInst::Create((F->getContext()), 0, RI);
RI->eraseFromParent(); RI->eraseFromParent();
......
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