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

(1)DF Graph is output to dot file.(2) Removed bugs relating to stripping...

(1)DF Graph is output to dot file.(2) Removed bugs relating to stripping function pointers off bitcast operations
parent 25ca91c9
No related branches found
No related tags found
No related merge requests found
...@@ -26,14 +26,21 @@ ...@@ -26,14 +26,21 @@
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/GraphWriter.h"
namespace llvm { namespace llvm {
class DFNode; class DFNode;
class DFInternalNode;
class DFLeafNode;
class DFEdge; class DFEdge;
class DFNodeVisitor; class DFNodeVisitor;
class DFTreeTraversal; class DFTreeTraversal;
class DFEdgeVisitor; class DFEdgeVisitor;
class DFGraph;
//template<> struct GraphTraits
class DFGraph { class DFGraph {
...@@ -42,11 +49,16 @@ private: ...@@ -42,11 +49,16 @@ private:
typedef std::vector<DFEdge*> DFEdgeListType; typedef std::vector<DFEdge*> DFEdgeListType;
// Important things that make up a Dataflow graph // Important things that make up a Dataflow graph
// DFLeafNode* Entry;
DFInternalNode* Parent;
DFNodeListType ChildrenList; ///< List of children Dataflow Nodes DFNodeListType ChildrenList; ///< List of children Dataflow Nodes
DFEdgeListType DFEdgeList; ///< List of Dataflow edges among children DFEdgeListType DFEdgeList; ///< List of Dataflow edges among children
public: public:
DFGraph() {} DFGraph(DFInternalNode* P) {
//ChildrenList.push_back(llvm::DFLeafNode::Create(NULL, NULL, NULL));
Parent = P;
}
void addChildDFNode(DFNode* child) { void addChildDFNode(DFNode* child) {
ChildrenList.push_back(child); ChildrenList.push_back(child);
...@@ -97,6 +109,9 @@ public: ...@@ -97,6 +109,9 @@ public:
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
DFInternalNode* getParent() {
return Parent;
}
}; };
...@@ -161,6 +176,7 @@ public: ...@@ -161,6 +176,7 @@ public:
return FuncPointer; return FuncPointer;
} }
virtual void applyDFNodeVisitor(DFNodeVisitor &V) = 0; virtual void applyDFNodeVisitor(DFNodeVisitor &V) = 0;
// virtual void applyDFEdgeVisitor(DFEdgeVisitor &V) = 0; // virtual void applyDFEdgeVisitor(DFEdgeVisitor &V) = 0;
...@@ -175,7 +191,8 @@ private: ...@@ -175,7 +191,8 @@ private:
DFInternalNode(IntrinsicInst* II, Function* FuncPointer, DFNode* Parent, DFInternalNode(IntrinsicInst* II, Function* FuncPointer, DFNode* Parent,
int NumOfDim, std::vector<Value*> DimLimits) : int NumOfDim, std::vector<Value*> DimLimits) :
DFNode(II, FuncPointer, Parent, NumOfDim, DimLimits) { DFNode(II, FuncPointer, Parent, NumOfDim, DimLimits) {
childGraph = new DFGraph(); childGraph = new DFGraph(this);
//childGraph->addChildDFNode(DFLeafNode::Create(NULL, NULL, this));
} }
public: public:
...@@ -206,8 +223,8 @@ class DFLeafNode : public DFNode { ...@@ -206,8 +223,8 @@ class DFLeafNode : public DFNode {
private: private:
// Constructor // Constructor
DFLeafNode(IntrinsicInst* II, Function* FuncPointer, DFNode* Parent, DFLeafNode(IntrinsicInst* II, Function* FuncPointer, DFNode* Parent,
int NumOfDim, std::vector<Value*> DimLimits) : int NumOfDim = 0, std::vector<Value*> DimLimits = std::vector<Value*>())
DFNode(II, FuncPointer, Parent, NumOfDim, DimLimits) {} : DFNode(II, FuncPointer, Parent, NumOfDim, DimLimits) {}
public: public:
...@@ -260,6 +277,7 @@ public: ...@@ -260,6 +277,7 @@ public:
} }
}; };
//===-------------------------- Visitor Classes ---------------------------===// //===-------------------------- Visitor Classes ---------------------------===//
// Visitor for DFNode objects // Visitor for DFNode objects
class DFNodeVisitor { class DFNodeVisitor {
...@@ -318,43 +336,107 @@ class DFEdgeVisitor { ...@@ -318,43 +336,107 @@ 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 // Provide specializations of GraphTraits to be able to treat a DFNode as a
// graph of DFNodes... // 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 DFNode::successor_iterator ChildIteratorType; typedef typename DFNode::successor_iterator ChildIteratorType;
static NodeType *getEntryNode(DFNode *N) { return N; }
static inline ChildIteratorType child_begin(NodeType *N) { static inline ChildIteratorType child_begin(NodeType *N) {
return N->successors_begin(); return N->successors_begin();
} }
static inline ChildIteratorType child_end(NodeType *N) { static inline ChildIteratorType child_end(NodeType *N) {
return N->successors_end(); return N->successors_end();
} }
}; };
template <> struct GraphTraits<const DFNode*> { template <> struct GraphTraits<DFGraph*> : public GraphTraits<DFNode*> {
typedef const DFNode NodeType; typedef typename DFGraph::children_iterator nodes_iterator;
typedef DFNode::const_successor_iterator ChildIteratorType;
static NodeType *getEntryNode(const DFNode *N) { return N; } static NodeType *getEntryNode(DFGraph* G) {
return G->front();
}
static inline ChildIteratorType child_begin(NodeType *N) { static nodes_iterator nodes_begin(DFGraph *G) {
return N->successors_begin(); return G->begin();
} }
static inline ChildIteratorType child_end(NodeType *N) {
return N->successors_end(); static inline nodes_iterator nodes_end(DFGraph *G) {
return G->end();
} }
}; };
template<>
struct DOTGraphTraits<DFGraph*> : public DefaultDOTGraphTraits {
DOTGraphTraits (bool isSimple=false)
: DefaultDOTGraphTraits(isSimple) {}
static std::string getGraphName(DFGraph* G) {
DFInternalNode* Parent = G->getParent();
if(Parent != NULL)
return Parent->getFuncPointer()->getName();
else
return "Dataflow Graph";
}
std::string getNodeLabel (DFNode* N, DFGraph* G) {
return N->getFuncPointer()->getName();
}
void addCustomGraphFeatures(DFGraph* G, GraphWriter<DFGraph*> &GW) {
}
};
void viewDFGraph(DFGraph *G) {
llvm::WriteGraph(G, "DataflowGrpah");
llvm::ViewGraph(G, "DataflowGraph");
}
} // End llvm namespace } // End llvm namespace
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/*
#include "llvm/IR/DFGraph.h" #include "llvm/IR/DFGraph.h"
using namespace llvm; using namespace llvm;
...@@ -40,4 +40,4 @@ void DFInternalNode::applyDFEdgeVisitor(DFEdgeVisitor &V) { ...@@ -40,4 +40,4 @@ void DFInternalNode::applyDFEdgeVisitor(DFEdgeVisitor &V) {
void DFLeafNode::applyDFEdgeVisitor(DFEdgeVisitor &V) { void DFLeafNode::applyDFEdgeVisitor(DFEdgeVisitor &V) {
return; return;
} }
*/
...@@ -69,6 +69,8 @@ namespace { ...@@ -69,6 +69,8 @@ namespace {
errs() << "Root Node not found yet :( \n"; errs() << "Root Node not found yet :( \n";
} }
} }
viewDFGraph(Root->getChildGraph());
return false; //TODO: What does returning "false" mean? return false; //TODO: What does returning "false" mean?
} }
...@@ -128,18 +130,28 @@ namespace { ...@@ -128,18 +130,28 @@ namespace {
void BuildDFG::handleCreateEdge (DFInternalNode* N, IntrinsicInst* II) { void BuildDFG::handleCreateEdge (DFInternalNode* N, IntrinsicInst* II) {
// The DFNode structures must be in the map before the edge is processed // The DFNode structures must be in the map before the edge is processed
HandleToDFNode::iterator DFI = HandleToDFNodeMap.find(II->getOperand(0)); HandleToDFNode::iterator DFI = HandleToDFNodeMap.find(II->getOperand(0));
errs() << "\n1";
assert(DFI != HandleToDFNodeMap.end()); assert(DFI != HandleToDFNodeMap.end());
errs() << " 2 ";
DFI = HandleToDFNodeMap.find(II->getOperand(1)); DFI = HandleToDFNodeMap.find(II->getOperand(1));
errs() << " 3 ";
assert(DFI != HandleToDFNodeMap.end()); assert(DFI != HandleToDFNodeMap.end());
errs() << " 4 ";
DFNode* SrcDF = HandleToDFNodeMap[II->getOperand(0)]; DFNode* SrcDF = HandleToDFNodeMap[II->getOperand(0)];
errs() << " 5 ";
DFNode* DestDF = HandleToDFNodeMap[II->getOperand(1)]; DFNode* DestDF = HandleToDFNodeMap[II->getOperand(1)];
Function* DFMapFunc = cast<Function>(II->getOperand(2)); errs() << " 6 ";
Function* ArgMapFunc = cast<Function>(II->getOperand(3)); Function* DFMapFunc = cast<Function>((II->getOperand(2))->stripPointerCasts());
errs() << " 7 ";
Function* ArgMapFunc = cast<Function>((II->getOperand(3))->stripPointerCasts());
errs() << " 8 ";
DFEdge* NewDFEdge = DFEdge::Create(SrcDF, DestDF, DFMapFunc, ArgMapFunc); DFEdge* NewDFEdge = DFEdge::Create(SrcDF, DestDF, DFMapFunc, ArgMapFunc);
errs() << " 9 ";
// FIXME Need interface of DFNode for the following: // FIXME Need interface of DFNode for the following:
N->addEdgeToDFGraph(NewDFEdge); N->addEdgeToDFGraph(NewDFEdge);
errs() << " 10 ";
SrcDF->addSuccessor(DestDF); SrcDF->addSuccessor(DestDF);
errs() << " 11 ";
} }
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