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