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

Added functions that change the data layout and the target triple.

parent cd55e712
No related branches found
No related tags found
No related merge requests found
......@@ -8,8 +8,10 @@
//===----------------------------------------------------------------------===//
#define ENABLE_ASSERTS
#define TARGET_PTX 32
#define DEBUG_TYPE "DFG2LLVM_NVPTX"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/InstIterator.h"
......@@ -25,6 +27,13 @@ using namespace builddfg;
//STATISTIC(IntrinsicCounter, "Counts number of visc intrinsics greeted");
namespace {
// Helper function declarations
void changeDataLayout(Module &);
void changeTargetTriple(Module &);
std::string convertInt(int);
void findReturnInst(Function *, std::vector<ReturnInst *> &);
// DFG2LLVM_NVPTX - The first implementation.
struct DFG2LLVM_NVPTX : public ModulePass {
static char ID; // Pass identification, replacement for typeid
......@@ -61,8 +70,6 @@ namespace {
//Functions
void addReturnValueArgs(Function* F);
Argument* getArgumentFromEnd(Function* F, unsigned offset);
Argument* getArgumentAt(Function* F, unsigned offset);
void codeGen(DFInternalNode* N);
void codeGen(DFLeafNode* N);
......@@ -146,9 +153,8 @@ namespace {
IntrinsicInst* ArgII;
DFNode* ArgDFNode;
/******************************************************************************
* Handle VISC Query intrinsics *
******************************************************************************/
/************************ Handle VISC Query intrinsics ************************/
switch (II->getIntrinsicID()) {
/**************************** llvm.visc.getNode() *****************************/
case Intrinsic::visc_getNode: {
......@@ -381,22 +387,6 @@ namespace {
return true;
}
std::string convertInt(int number) {
std::stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}
void findReturnInst(Function* F, std::vector<ReturnInst *> & ReturnInstVec) {
for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
Instruction *I = &(*i);
ReturnInst* RI = dyn_cast<ReturnInst>(I);
if (RI) {
ReturnInstVec.push_back(RI);
}
}
}
void CodeGenTraversal::addReturnValueArgs(Function* F) {
// FIXME: Maybe do that using the Node?
......@@ -453,7 +443,7 @@ namespace {
check++;
}
DEBUG(errs() << "\tcheck = " << check << "\tinitialNumParams = " << initialNumParams << "\n");
// DEBUG(errs() << "\tcheck = " << check << "\tinitialNumParams = " << initialNumParams << "\n");
assert(check == initialNumParams);
DEBUG(errs() << "\tReplacing Return statements\n");
......@@ -480,10 +470,8 @@ namespace {
}
DEBUG(errs() << "\tReplaced return statements\n");
// Adding new arguments to the function argument list, would not change the
// function type. We need to change the type of this function to reflect the
// added arguments
......@@ -496,6 +484,56 @@ namespace {
}
/******************************************************************************
* Helper functions *
******************************************************************************/
// Changes the data layout of the Module to be compiled with NVPTX backend
// TODO: Figure out when to call it, probably after duplicating the modules
void changeDataLayout(Module &M) {
std::string nvptx32_layoutStr = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64";
std::string nvptx64_layoutStr = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64";
if (TARGET_PTX == 32)
M.setDataLayout(StringRef(nvptx32_layoutStr));
else if (TARGET_PTX == 64)
M.setDataLayout(StringRef(nvptx64_layoutStr));
else assert(false && "Invalid PTX target");
return;
}
void changeTargetTriple(Module &M) {
std::string nvptx32_TargetTriple = "nvptx--nvidiacl";
std::string nvptx64_TargetTriple = "nvptx64--nvidiacl";
if (TARGET_PTX == 32)
M.setTargetTriple(StringRef(nvptx32_TargetTriple));
else if (TARGET_PTX == 64)
M.setTargetTriple(StringRef(nvptx64_TargetTriple));
else assert(false && "Invalid PTX target");
return;
}
// Helper function, convert int to string
std::string convertInt(int number) {
std::stringstream ss;//create a stringstream
ss << number;//add number to the stream
return ss.str();//return a string with the contents of the stream
}
// Helper function, populate a vector with all return statements in a function
void findReturnInst(Function* F, std::vector<ReturnInst *> & ReturnInstVec) {
for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) {
Instruction *I = &(*i);
ReturnInst* RI = dyn_cast<ReturnInst>(I);
if (RI) {
ReturnInstVec.push_back(RI);
}
}
}
} // End of namespace
char DFG2LLVM_NVPTX::ID = 0;
......
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