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

(1) Fixed bugs in DFG2LLVM_X86 pass.

    Need to replace any value with undef before deleting.
    Fixed bug in extending parameter list of a function.
(2) Modified svn properties of DFG2LLVM_NVPTX to ignore Debug+Asserts
parent f6021666
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ namespace {
//Functions
void addIdxDimArgs(Function* F);
Argument* getArgumentFromEnd(Function* F, unsigned offset);
void codeGen(DFInternalNode* N);
void codeGen(DFLeafNode* N);
public:
......@@ -105,18 +106,23 @@ namespace {
void CodeGenTraversal::addIdxDimArgs(Function* F) {
// Add Index and Dim arguments
Argument* idxX = new Argument(Type::getInt32Ty(F->getContext()), "idxX", F);
Argument* idxY = new Argument(Type::getInt32Ty(F->getContext()), "idxY", F);
Argument* idxZ = new Argument(Type::getInt32Ty(F->getContext()), "idxZ", F);
Argument* dimX = new Argument(Type::getInt32Ty(F->getContext()), "dimX", F);
Argument* dimY = new Argument(Type::getInt32Ty(F->getContext()), "dimY", F);
Argument* dimZ = new Argument(Type::getInt32Ty(F->getContext()), "dimZ", F);
DEBUG(errs() << "Adding Arguments\n");
std::string names[] = {"idx_x", "idx_y", "idx_z", "dim_x", "dim_y", "dim_z"};
for (int i = 0; i < 6; ++i) {
new Argument(Type::getInt32Ty(F->getContext()), names[i], F);
DEBUG(errs() << names[i] << "\n");
}
DEBUG(errs() << "Getting type list\n");
// Create the argument type list with added argument types
std::vector<Type*> ArgTypes;
for(Function::const_arg_iterator i = F->arg_begin(), e = F->arg_end();
i != e; ++i)
ArgTypes.push_back(i->getType());
DEBUG(errs() << F->getName() << "\n");
for(Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
ai != ae; ++ai) {
DEBUG(errs() << *ai << "\n");
ArgTypes.push_back(ai->getType());
}
// Adding new arguments to the function argument list, would not change the
......@@ -127,16 +133,21 @@ namespace {
// Change the function type
F->mutateType(PTy);
int offset = 3 + 2;
Argument* index;
for(Function::arg_iterator ai = F->getArgumentList().begin(),
ae = --(F->getArgumentList().end()); offset != 0; --ae) {
index = ae;
DEBUG(errs() << "\n************ " << offset << " :: " << *index << " *************\n\n");
DEBUG(errs() << "Done with adding index args to clone\n");
}
Argument* CodeGenTraversal::getArgumentFromEnd(Function* F, unsigned offset) {
assert((F->getFunctionType()->getNumParams() >= offset && offset > 0)
&& "Invalid offset to access arguments!");
Function::arg_iterator e = F->arg_end();
// Last element of argument iterator is dummy. Skip it.
e--;
Argument* arg;
for( ; offset != 0; e--) {
offset--;
arg = e;
}
DEBUG(errs() << "\n*****************" << *index << "*************\n\n");
return arg;
}
void CodeGenTraversal::codeGen(DFInternalNode* N) {
......@@ -157,6 +168,7 @@ namespace {
return;
}
DEBUG(errs() << "Start\n");
std::vector<IntrinsicInst *> IItoRemove;
std::vector<std::pair<IntrinsicInst *, Value *> > IItoReplace;
......@@ -165,14 +177,18 @@ namespace {
// Get the function associated woth the dataflow node
Function *F = N->getFuncPointer();
DEBUG(errs() << "Duplicate module\n");
// Look up if we have visited this fucntion before. If we have, then just
// get the cloned function pointer from FMap. Otherwise, create the cloned
// function and add it to the FMap.
Function *F_X86;
if(FMap.count(F)) {
DEBUG(errs() << "If\n");
F_X86 = FMap[F];
}
else {
DEBUG(errs() << "Else\n");
// Clone the function
ValueToValueMapTy VMap;
F_X86 = CloneFunction(F, VMap, true);
......@@ -190,6 +206,7 @@ namespace {
FMap[F] = F_X86;
}
DEBUG(errs() << "Iterate over instructions\n");
// Go through all the instructions
for (inst_iterator i = inst_begin(F_X86), e = inst_end(F_X86); i != e; ++i) {
Instruction *I = &(*i);
......@@ -275,14 +292,13 @@ namespace {
assert((numParamsF_X86 - numParamsF == 6)
&& "Difference of arguments between function and its clone is not 6!");
int offset = 3 + (3-dim);
Argument* indexVal;
for(Function::arg_iterator ai = F_X86->getArgumentList().begin(),
ae = --(F_X86->getArgumentList().end()); offset != 0; ae--) {
offset--;
indexVal = ae;
}
DEBUG(errs() << *indexVal << "\n");
unsigned offset = 3 + (3-dim);
// Traverse argument list of F_X86 in reverse order to find the
// correct index or dim argument.
Argument* indexVal = getArgumentFromEnd(F_X86, offset);
assert(indexVal && "Index argument not found. Invalid offset!");
DEBUG(errs() << *II << " replaced with " << *indexVal << "\n");
II->replaceAllUsesWith(indexVal);
IItoRemove.push_back(II);
......@@ -323,14 +339,13 @@ namespace {
assert((numParamsF_X86 - numParamsF == 6)
&& "Difference of arguments between function and its clone is not 6!");
int offset = 3 - dim;
Argument* limitVal;
for(Function::arg_iterator ai = F_X86->getArgumentList().begin(),
ae = --(F_X86->getArgumentList().end()); offset != 0; ae--) {
offset--;
limitVal = ae;
}
DEBUG(errs() << *limitVal << "\n");
unsigned offset = 3 - dim;
// Traverse argument list of F_X86 in reverse order to find the
// correct index or dim argument.
Argument* limitVal = getArgumentFromEnd(F_X86, offset);
assert(limitVal && "Limit argument not found. Invalid offset!");
DEBUG(errs() << *II << " replaced with " << *limitVal << "\n");
II->replaceAllUsesWith(limitVal);
IItoRemove.push_back(II);
......@@ -359,8 +374,10 @@ namespace {
//TODO: maybe leave these instructions to be removed by a later DCE pass
for (std::vector<IntrinsicInst *>::iterator i = IItoRemove.begin();
i != IItoRemove.end(); ++i)
i != IItoRemove.end(); ++i) {
(*i)->replaceAllUsesWith(UndefValue::get((*i)->getType()));
(*i)->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