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

Topological sort working. Added support for query intrinsics in BuildDFG

parent bb68383e
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ namespace builddfg {
// Functions
void handleCreateNode (DFInternalNode* N, IntrinsicInst* II);
void handleCreateEdge (DFInternalNode* N, IntrinsicInst* II);
void handleGetParentNode (DFInternalNode* N, IntrinsicInst* II);
void BuildGraph (DFInternalNode* N, Function* F);
......
......@@ -199,24 +199,51 @@ namespace builddfg {
Type *SrcTy, *DestTy;
// Get destination type
FunctionType *FT = DestDF->getFuncPointer()->getFunctionType();
assert((FT->getNumParams() > DestPosition)
&& "Invalid argument number for destination dataflow node!");
DestTy = FT->getParamType(DestPosition);
// If destination is the parent node. Then we need the return type of the
// parent node. Hence need to handle it as a special case
if (DestDF == (DFNode*) N) {
StructType* OutTy = cast<StructType>(DestDF->getOutputType());
assert((OutTy->getNumElements() > DestPosition)
&& "Invalid argument number for destination parent dataflow node!");
DestTy = OutTy->getElementType(DestPosition);
}
else {
// If destination is a sibling
FunctionType *FT = DestDF->getFuncPointer()->getFunctionType();
errs() << "Destination: "<< DestDF->getFuncPointer()->getName() << "\n";
errs() << FT->getNumParams() << " " << DestPosition << "\n";
errs() << *FT << "\n";
assert((FT->getNumParams() > DestPosition)
&& "Invalid argument number for destination dataflow node!");
DestTy = FT->getParamType(DestPosition);
}
// Get source type
if(isa<DFInternalNode>(SrcDF)) {
// For Internal node, get the correct element type from the struct type
StructType* OutTy = cast<StructType>(SrcDF->getOutputType());
assert((OutTy->getNumElements() > SourcePosition)
&& "Invalid argument number for source dataflow node!");
SrcTy = OutTy->getElementType(SourcePosition);
// If source is the parent node. Then we need the parameter list of the
// parent node. Hence need to handle it as a special case
if (SrcDF == (DFNode*) N) {
FunctionType *FT = SrcDF->getFuncPointer()->getFunctionType();
assert((FT->getNumParams() > SourcePosition)
&& "Invalid argument number for source parent dataflow node!");
SrcTy = FT->getParamType(SourcePosition);
}
else {
// For Leaf node, there is just one outgoing edge
assert((SourcePosition == 0)
&& "Invalid argument number for source dataflow node!");
SrcTy = SrcDF->getOutputType();
// If source is a sibling
if(isa<DFInternalNode>(SrcDF)) {
// For Internal node, get the correct element type from the struct type
StructType* OutTy = cast<StructType>(SrcDF->getOutputType());
errs() << "Source: " << SrcDF->getFuncPointer()->getName() << "\n";
errs() << OutTy->getNumElements() << " " << SourcePosition << "\n";
assert((OutTy->getNumElements() > SourcePosition)
&& "Invalid argument number for source dataflow node!");
SrcTy = OutTy->getElementType(SourcePosition);
}
else {
// For Leaf node, there is just one outgoing edge
assert((SourcePosition == 0)
&& "Invalid argument number for source dataflow node!");
SrcTy = SrcDF->getOutputType();
}
}
// check if the types are compatible
......@@ -236,6 +263,14 @@ namespace builddfg {
N->addEdgeToDFGraph(newDFEdge);
}
void BuildDFG::handleGetParentNode (DFInternalNode* N, IntrinsicInst* II) {
HandleToDFNode::iterator DFI = HandleToDFNodeMap.find(II->getOperand(0));
assert(DFI != HandleToDFNodeMap.end() && "Undefined operand!");
DFNode* DF = HandleToDFNodeMap[II->getOperand(0)];
HandleToDFNodeMap[II] = DF->getParent();
}
void BuildDFG::BuildGraph (DFInternalNode* N, Function *F) {
// TODO: Place checks for valid visc functions. For example one of the
......@@ -264,8 +299,15 @@ namespace builddfg {
case Intrinsic::visc_createEdge:
handleCreateEdge(N, II);
break;
case Intrinsic::visc_getNode:
HandleToDFNodeMap[II] = N;
break;
case Intrinsic::visc_getParentNode:
handleGetParentNode(N, II);
break;
//TODO: Reconsider launch within a dataflow graph (recursion?)
//TODO: Reconsider launch within a dataflow graph (recursion?)
case Intrinsic::visc_launch:
errs() << "Error: Launch intrinsic used within a dataflow graph\n";
break;
......
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