diff --git a/llvm/include/llvm/IR/DFGraph.h b/llvm/include/llvm/IR/DFGraph.h index b7a11f0dba0631344dd28400062efe4a0630daff..fc48c37662a0991b9a590bc675bb10bc47c981e3 100644 --- a/llvm/include/llvm/IR/DFGraph.h +++ b/llvm/include/llvm/IR/DFGraph.h @@ -21,6 +21,7 @@ #define LLVM_IR_DFGRAPH_H #include "llvm/IR/Function.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Value.h" #include "llvm/Support/Compiler.h" @@ -28,6 +29,8 @@ namespace llvm { class DFNode; class DFEdge; +class DFNodeVisitor; +class DFEdgeVisitor; class DFGraph { @@ -35,7 +38,7 @@ private: typedef std::vector<DFNode*> DFNodeListType; typedef std::vector<DFEdge*> DFEdgeListType; - // Important things taht naje up a Dataflow graph + // Important things that make up a Dataflow graph DFNodeListType ChildrenList; ///< List of children Dataflow Nodes DFEdgeListType DFEdgeList; ///< List of Dataflow edges among children @@ -46,6 +49,48 @@ public: ChildrenList.push_back(child); } + // Iterators + typedef DFNodeListType::iterator children_iterator; + typedef DFNodeListType::const_iterator const_children_iterator; + + typedef DFEdgeListType::iterator dfedge_iterator; + typedef DFEdgeListType::const_iterator const_dfedge_iterator; + + //===--------------------------------------------------------------------===// + // DFNodeList iterator forwarding functions + // + children_iterator begin() { return ChildrenList.begin(); } + const_children_iterator begin() const { return ChildrenList.begin(); } + children_iterator end () { return ChildrenList.end(); } + const_children_iterator end () const { return ChildrenList.end(); } + + size_t size() const { return ChildrenList.size(); } + bool empty() const { return ChildrenList.empty(); } + const DFNode *front() const { return ChildrenList.front(); } + DFNode *front() { return ChildrenList.front(); } + const DFNode *back() const { return ChildrenList.back(); } + DFNode *back() { return ChildrenList.back(); } + + //===--------------------------------------------------------------------===// + + //===--------------------------------------------------------------------===// + // DFEdgeList iterator forwarding functions + // + dfedge_iterator dfedge_begin() { return DFEdgeList.begin(); } + const_dfedge_iterator dfedge_begin() const { return DFEdgeList.begin(); } + dfedge_iterator dfedge_end () { return DFEdgeList.end(); } + const_dfedge_iterator dfedge_end () const { return DFEdgeList.end(); } + + size_t dfedge_size() const { return DFEdgeList.size(); } + bool dfedge_empty() const { return DFEdgeList.empty(); } + const DFEdge *dfedge_front() const { return DFEdgeList.front(); } + DFEdge *dfedge_front() { return DFEdgeList.front(); } + const DFEdge *dfedge_back() const { return DFEdgeList.back(); } + DFEdge *dfedge_back() { return DFEdgeList.back(); } + + //===--------------------------------------------------------------------===// + + }; // DFNode represents a single VISC Dataflow Node in LLVM. @@ -82,6 +127,11 @@ public: std::vector<Value*> DimLimits = std::vector<Value*>()) { return new DFNode(II, FuncPointer, Parent, NumOfDim, DimLimits); } + +// FIXME: When constructor and create method are removed, these should be virtual methods + void applyDFNodeVisitor(DFNodeVisitor &V); + void applyDFEdgeVisitor(DFEdgeVisitor &V); + }; class DFInternalNode : public DFNode { @@ -106,6 +156,10 @@ public: void addChildToDFGraph(DFNode* N) { Graph->addChildDFNode(N); } + + void applyDFNodeVisitor(DFNodeVisitor &V); + void applyDFEdgeVisitor(DFEdgeVisitor &V); + }; class DFLeafNode : public DFNode { @@ -123,6 +177,10 @@ public: std::vector<Value*> DimLimits = std::vector<Value*>()) { return new DFLeafNode(II, FuncPointer, Parent, NumOfDim, DimLimits); } + + void applyDFNodeVisitor(DFNodeVisitor &V); + void applyDFEdgeVisitor(DFEdgeVisitor &V); + }; // DFEdge represents a single VISC Dataflow Edge in LLVM. @@ -162,6 +220,21 @@ public: } }; + +//===-------------------------- Visitor Classes ---------------------------===// +// Visitor for DFNode objects +class DFNodeVisitor { +public: + virtual void visit(DFInternalNode &)=0; + virtual void visit(DFLeafNode &)=0; +}; + +// Visitor for DFEdge objects +class DFEdgeVisitor { +public: + virtual void visit(DFEdge &)=0; +}; + } // End llvm namespace #endif diff --git a/llvm/lib/IR/DFGraph.cpp b/llvm/lib/IR/DFGraph.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7da72bafee91b2e26c388abac1202594c92fbf35 --- /dev/null +++ b/llvm/lib/IR/DFGraph.cpp @@ -0,0 +1,43 @@ +//===--------- llvm/IR/DFGraph.cpp - Dataflow Graph implemetation ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/DFGraph.h" + +using namespace llvm; + +void DFInternalNode::applyDFNodeVisitor(DFNodeVisitor &V) { + + V.visit(*this); + + for (DFGraph::children_iterator CI = Graph->begin(), CE = Graph->end(); + CI != CE; ++CI) + (*CI)->applyDFNodeVisitor(V); + +} + +void DFLeafNode::applyDFNodeVisitor(DFNodeVisitor &V) { + V.visit(*this); +} + +void DFInternalNode::applyDFEdgeVisitor(DFEdgeVisitor &V) { + + for (DFGraph::dfedge_iterator EI = Graph->dfedge_begin(), + EE = Graph->dfedge_end(); EI != EE; ++EI) + V.visit(*(*EI)); + + for (DFGraph::children_iterator CI = Graph->begin(), CE = Graph->end(); + CI != CE; ++CI) + (*CI)->applyDFEdgeVisitor(V); + +} + +void DFLeafNode::applyDFEdgeVisitor(DFEdgeVisitor &V) { + return; +} +