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

refactored BuildDFG code. Now just addEdgeToDFGraph should be enough to make...

refactored BuildDFG code. Now just addEdgeToDFGraph should be enough to make all the successor and predecessor changes to nodes
parent e318c05c
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,6 @@ class DFTreeTraversal; ...@@ -41,7 +41,6 @@ class DFTreeTraversal;
class DFEdgeVisitor; class DFEdgeVisitor;
class DFGraph; class DFGraph;
//template<> struct GraphTraits
class DFGraph { class DFGraph {
...@@ -282,6 +281,9 @@ public: ...@@ -282,6 +281,9 @@ public:
}; };
/*****************************************************
* DFInternalNode class implementation
*****************************************************/
class DFInternalNode : public DFNode { class DFInternalNode : public DFNode {
private: private:
...@@ -315,10 +317,8 @@ public: ...@@ -315,10 +317,8 @@ public:
childGraph->addChildDFNode(N); childGraph->addChildDFNode(N);
} }
void addEdgeToDFGraph(DFEdge* E) { void addEdgeToDFGraph(DFEdge* E);
childGraph->addDFEdge(E);
}
DFGraph* getChildGraph() { DFGraph* getChildGraph() {
return childGraph; return childGraph;
} }
...@@ -327,6 +327,9 @@ public: ...@@ -327,6 +327,9 @@ public:
// void applyDFEdgeVisitor(DFEdgeVisitor &V); /*virtual*/ // void applyDFEdgeVisitor(DFEdgeVisitor &V); /*virtual*/
}; };
/*****************************************************
* DFLeafNode class implementation
*****************************************************/
class DFLeafNode : public DFNode { class DFLeafNode : public DFNode {
private: private:
...@@ -424,6 +427,26 @@ public: ...@@ -424,6 +427,26 @@ public:
}; };
//===--------------------- DFInternalNode Outlined Functions --------------===//
void DFInternalNode::addEdgeToDFGraph(DFEdge* E) {
DFNode* S = E->getSourceDF();
DFNode* D = E->getDestDF();
assert(std::find(childGraph->begin(), childGraph->end(), S)!=childGraph->end()
&& "Source node not found in child dataflow graph!");
assert(std::find(childGraph->begin(), childGraph->end(), D)!=childGraph->end()
&& "Destination node not found in child dataflow graph!");
// Update Graph
childGraph->addDFEdge(E);
// Update source and destination nodes
S->addSuccessor(D);
S->addOutDFEdge(E);
D->addInDFEdge(E);
}
//===-------------------------- Visitor Classes ---------------------------===// //===-------------------------- Visitor Classes ---------------------------===//
// Visitor for DFNode objects // Visitor for DFNode objects
...@@ -483,51 +506,12 @@ class DFEdgeVisitor { ...@@ -483,51 +506,12 @@ class DFEdgeVisitor {
public: public:
virtual void visit(DFEdge* E) = 0; virtual void visit(DFEdge* E) = 0;
}; };
*/
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// GraphTraits specializations for DFNode graph (DFG) // GraphTraits specializations for DFNode graph (DFG)
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Provide specializations of GraphTraits to be able to treat a DFNode as a
// graph of DFNodes...struct GraphTraits {
// Elements to provide:
// typedef NodeType - Type of Node in the graph
// typedef ChildIteratorType - Type used to iterate over children in graph
// static NodeType *getEntryNode(const GraphType &)
// Return the entry node of the graph
// static ChildIteratorType child_begin(NodeType *)
// static ChildIteratorType child_end (NodeType *)
// Return iterators that point to the beginning and ending of the child
// node list for the specified node.
//
// typedef ...iterator nodes_iterator;
// static nodes_iterator nodes_begin(GraphType *G)
// static nodes_iterator nodes_end (GraphType *G)
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
// static unsigned size (GraphType *G)
// Return total number of nodes in the graph
//
// If anyone tries to use this class without having an appropriate
// specialization, make an error. If you get this error, it's because you
// need to include the appropriate specialization of GraphTraits<> for your
// graph, or you need to define it for a new graph type. Either that or
// your argument to XXX_begin(...) is unknown or needs to have the proper .h
// file #include'd.
//
typedef typename GraphType::UnknownGraphTypeError NodeType;
//};
*/
template <> struct GraphTraits<DFNode*> { template <> struct GraphTraits<DFNode*> {
typedef DFNode NodeType; typedef DFNode NodeType;
typedef typename DFNode::successor_iterator ChildIteratorType; typedef typename DFNode::successor_iterator ChildIteratorType;
...@@ -580,15 +564,11 @@ struct DOTGraphTraits<DFGraph*> : public DefaultDOTGraphTraits { ...@@ -580,15 +564,11 @@ struct DOTGraphTraits<DFGraph*> : public DefaultDOTGraphTraits {
} }
}; };
void viewDFGraph(DFGraph *G) { void viewDFGraph(DFGraph *G) {
llvm::WriteGraph(G, "DataflowGrpah"); llvm::WriteGraph(G, "DataflowGrpah");
llvm::ViewGraph(G, "DataflowGraph"); llvm::ViewGraph(G, "DataflowGraph");
} }
} // End llvm namespace } // End llvm namespace
#endif #endif
...@@ -88,46 +88,34 @@ namespace builddfg { ...@@ -88,46 +88,34 @@ namespace builddfg {
// Returns true if instruction I is a visc launch intrinsic, false otherwise // Returns true if instruction I is a visc launch intrinsic, false otherwise
bool BuildDFG::isViscLaunchIntrinsic(Instruction* I) { bool BuildDFG::isViscLaunchIntrinsic(Instruction* I) {
if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(I)) { if(!isa<IntrinsicInst>(I))
if (((II->getCalledFunction()->getName()).equals("llvm.visc.launch"))) { return false;
// It is a visc launch intrinsic IntrinsicInst* II = cast<IntrinsicInst>(I);
return true; return (II->getCalledFunction()->getName()).equals("llvm.visc.launch");
}
}
return false;
} }
// Returns true if instruction I is a visc graph intrinsic, false otherwise // Returns true if instruction I is a visc graph intrinsic, false otherwise
bool BuildDFG::isViscGraphIntrinsic(Instruction* I) { bool BuildDFG::isViscGraphIntrinsic(Instruction* I) {
if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(I)) { if(!isa<IntrinsicInst>(I))
if (((II->getCalledFunction()->getName()).startswith("llvm.visc.create"))) { return false;
// It is a visc graph intrinsic IntrinsicInst* II = cast<IntrinsicInst>(I);
return true; return (II->getCalledFunction()->getName()).startswith("llvm.visc.create");
}
}
return false;
} }
// Returns true if instruction I is a visc query intrinsic, false otherwise // Returns true if instruction I is a visc query intrinsic, false otherwise
bool BuildDFG::isViscQueryIntrinsic(Instruction* I) { bool BuildDFG::isViscQueryIntrinsic(Instruction* I) {
if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(I)) { if(!isa<IntrinsicInst>(I))
if (((II->getCalledFunction()->getName()).startswith("llvm.visc.get"))) { return false;
// It is a visc query intrinsic IntrinsicInst* II = cast<IntrinsicInst>(I);
return true; return (II->getCalledFunction()->getName()).startswith("llvm.visc.get");
}
}
return false;
} }
// Returns true if instruction I is a visc intrinsic, false otherwise // Returns true if instruction I is a visc intrinsic, false otherwise
bool BuildDFG::isViscIntrinsic(Instruction* I) { bool BuildDFG::isViscIntrinsic(Instruction* I) {
if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(I)) { if(!isa<IntrinsicInst>(I))
if (((II->getCalledFunction()->getName()).startswith("llvm.visc"))) { return false;
// It is a visc query intrinsic IntrinsicInst* II = cast<IntrinsicInst>(I);
return true; return (II->getCalledFunction()->getName()).startswith("llvm.visc");
}
}
return false;
} }
// Two types are "congruent" if they are identical, or if they are both // Two types are "congruent" if they are identical, or if they are both
...@@ -233,14 +221,8 @@ namespace builddfg { ...@@ -233,14 +221,8 @@ namespace builddfg {
HandleToDFEdgeMap[II] = newDFEdge; HandleToDFEdgeMap[II] = newDFEdge;
// Update parent node // Add Edge to the dataflow graph associated with the parent node
N->addEdgeToDFGraph(newDFEdge); N->addEdgeToDFGraph(newDFEdge);
// Update source and destination nodes
SrcDF->addSuccessor(DestDF);
SrcDF->addOutDFEdge(newDFEdge);
DestDF->addInDFEdge(newDFEdge);
} }
void BuildDFG::BuildGraph (DFInternalNode* N, Function *F) { void BuildDFG::BuildGraph (DFInternalNode* N, Function *F) {
......
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