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

Edited DFG2LLVM pass

1. Bug fix
2. Properly remove or replace intrinsics
parent 973995ac
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,6 @@ namespace {
void codeGen(DFLeafNode* N) {
std::vector<IntrinsicInst *> IItoRemove;
std::vector<std::pair<IntrinsicInst *, Value *> > IItoReplace;
BuildDFG::HandleToDFNode Leaf_HandleToDFNodeMap;
// Get the function associated woth the dataflow node
......@@ -91,12 +90,13 @@ namespace {
// get the parent node of the arg node
// get argument node
ArgII = cast<IntrinsicInst>((II->getOperand(0))->stripPointerCasts());
// get the parent node of the arg node
ArgDFNode = Leaf_HandleToDFNodeMap[ArgII];
// get the parent node of the arg node
// Add mapping <intrinsic, parent node> to the node-specific map
// the argument node must have been added to the map, orelse the
// code could not refer to it
Leaf_HandleToDFNodeMap[II] = ArgDFNode;
Leaf_HandleToDFNodeMap[II] = ArgDFNode->getParent();
IItoRemove.push_back(II);
}
break;
......@@ -107,8 +107,11 @@ namespace {
int numOfDim = Leaf_HandleToDFNodeMap[ArgII]->getNumOfDim();
IntegerType* IntTy = Type::getInt32Ty(getGlobalContext());
ConstantInt* numOfDimConstant = ConstantInt::getSigned(IntTy, (int64_t) numOfDim);
IItoReplace.push_back(std::make_pair(II,numOfDimConstant));
// Replace the result of the intrinsic with the computed value
II->replaceAllUsesWith(numOfDimConstant);
IItoRemove.push_back(II);
}
break;
/*********************** llvm.visc.getNodeInstanceID() ************************/
......@@ -166,8 +169,12 @@ namespace {
assert(false && "Unable to translate this intrinsic");
}
CallInst* CI = CallInst::Create(OpenCLFunction, Args);
IItoReplace.push_back(std::make_pair(II,CI));
// Create call instruction, insert it before the intrinsic and
// replace the uses of the previous instruction with the new one
CallInst* CI = CallInst::Create(OpenCLFunction, Args, "", II);
II->replaceAllUsesWith(CI);
IItoRemove.push_back(II);
}
break;
/********************** llvm.visc.getNumNodeInstances() ***********************/
......@@ -226,8 +233,12 @@ namespace {
assert(false && "Unable to translate this intrinsic");
}
CallInst* CI = CallInst::Create(OpenCLFunction, Args);
IItoReplace.push_back(std::make_pair(II,CI));
// Create call instruction, insert it before the intrinsic and
// replace the uses of the previous instruction with the new one
CallInst* CI = CallInst::Create(OpenCLFunction, Args, "", II);
II->replaceAllUsesWith(CI);
IItoRemove.push_back(II);
}
break;
default:
......@@ -250,7 +261,8 @@ namespace {
// using dyn_cast in order to determine if we replace with inst or value
//TODO: maybe leave these instructions to be removed by a later DCE pass
//We need to do this explicitly: DCE pass will not remove them because we
// have assumed theworst memory behaviour for these function calls
for (std::vector<IntrinsicInst *>::iterator i = IItoRemove.begin();
i != IItoRemove.end(); ++i)
(*i)->eraseFromParent();
......@@ -297,6 +309,8 @@ namespace {
// Initiate code generation for root DFNode
CGTVisitor->visit(Root);
//TODO: Edit module epilogue to remove the VISC intrinsic declarations
return true;
}
......
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