Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShStructural.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHSTRUCTURAL_HPP 00028 #define SHSTRUCTURAL_HPP 00029 00030 #include <list> 00031 #include <utility> 00032 #include <iosfwd> 00033 #include "ShDllExport.hpp" 00034 #include "ShRefCount.hpp" 00035 #include "ShCtrlGraph.hpp" 00036 #include "ShVariable.hpp" 00037 00038 namespace SH { 00039 00040 class 00041 SH_DLLEXPORT ShStructuralNode : public ShRefCountable { 00042 public: 00043 friend class ShStructural; 00044 00045 enum NodeType { 00046 UNREDUCED, 00047 BLOCK, 00048 IF, 00049 IFELSE, 00050 SELFLOOP, 00051 WHILELOOP 00052 }; 00053 00054 ShStructuralNode(const ShCtrlGraphNodePtr& node); 00055 ShStructuralNode(NodeType type); 00056 00057 // Graphviz-format dump of this node and its children 00058 std::ostream& dump(std::ostream& out, int nodes = -1) const; 00059 00060 // Structural information 00061 NodeType type; 00062 ShStructuralNode* container; 00063 typedef std::list< ShPointer< ShStructuralNode> > StructNodeList; 00064 StructNodeList structnodes; 00065 00066 // Graph structure 00067 ShCtrlGraphNodePtr cfg_node; 00068 typedef std::pair<ShVariable, ShPointer<ShStructuralNode> > SuccessorEdge; 00069 typedef std::list<SuccessorEdge> SuccessorList; 00070 SuccessorList succs; 00071 typedef std::pair<ShVariable, ShStructuralNode*> PredecessorEdge; 00072 typedef std::list<PredecessorEdge> PredecessorList; 00073 PredecessorList preds; 00074 00075 // Spanning tree 00076 ShStructuralNode* parent; 00077 typedef std::list< ShPointer<ShStructuralNode> > ChildList; 00078 ChildList children; 00079 00080 }; 00081 00082 typedef ShPointer<ShStructuralNode> ShStructuralNodePtr; 00083 typedef ShPointer<const ShStructuralNode> ShStructuralNodeCPtr; 00084 00085 class 00086 SH_DLLEXPORT ShStructural { 00087 public: 00088 ShStructural(const ShCtrlGraphPtr& graph); 00089 00090 // Graphviz-format dump of the structural tree. 00091 std::ostream& dump(std::ostream& out) const; 00092 00093 const ShStructuralNodePtr& head(); 00094 00095 private: 00096 ShCtrlGraphPtr m_graph; 00097 ShStructuralNodePtr m_head; 00098 00099 typedef std::list<ShStructuralNode*> PostorderList; 00100 PostorderList m_postorder; 00101 00102 ShStructuralNodePtr build_tree(const ShCtrlGraphNodePtr& node); 00103 void build_postorder(const ShStructuralNodePtr& node); 00104 }; 00105 00106 } 00107 00108 #endif

Generated on Mon Oct 18 14:17:40 2004 for Sh by doxygen 1.3.7