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

ShDomTree.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 00028 #ifndef SHDOMTREE_HPP 00029 #define SHDOMTREE_HPP 00030 00031 #include <set> 00032 #include <map> 00033 #include <vector> 00034 #include <algorithm> 00035 #include "ShDllExport.hpp" 00036 #include "ShCtrlGraph.hpp" 00037 #include "ShRefCount.hpp" 00038 00039 namespace SH { 00040 00043 class 00044 SH_DLLEXPORT ShDomTree { 00045 public: 00046 ShDomTree(ShCtrlGraphPtr ctrlGraph); 00047 00049 template<typename T> void postorder(T& f); 00050 00052 template<typename T> void preorder(T& f); 00053 00054 void debugDump(); 00055 00056 int numbering(ShCtrlGraphNodePtr node) const { 00057 return (int)(std::find( m_vertex.begin(), m_vertex.end(), node) - m_vertex.begin()); 00058 } 00059 00060 private: 00061 void dfs(ShCtrlGraphNodePtr v); 00062 ShCtrlGraphNodePtr eval(ShCtrlGraphNodePtr v); 00063 void compress(ShCtrlGraphNodePtr v); 00064 void link(ShCtrlGraphNodePtr v, ShCtrlGraphNodePtr w); 00065 00066 ShCtrlGraphPtr m_graph; 00067 00068 // See [TODO Ref Langauer & Tarjan pg 127] for more information on these 00069 00070 typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> ParentMap; 00071 ParentMap m_parent; 00072 typedef std::set<ShCtrlGraphNodePtr> PredSet; 00073 typedef std::map<ShCtrlGraphNodePtr, PredSet> PredMap; 00074 PredMap m_pred; 00075 typedef std::map<ShCtrlGraphNodePtr, int> SemiMap; 00076 SemiMap m_semi; 00077 std::vector<ShCtrlGraphNodePtr> m_vertex; 00078 typedef std::set<ShCtrlGraphNodePtr> BucketSet; 00079 typedef std::map<ShCtrlGraphNodePtr, BucketSet> BucketMap; 00080 BucketMap m_bucket; 00081 typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> DomMap; 00082 DomMap m_dom; 00083 00084 typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> AncestorMap; 00085 AncestorMap m_ancestor; 00086 typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> LabelMap; 00087 LabelMap m_label; 00088 00089 typedef std::set<ShCtrlGraphNodePtr> ChildrenSet; 00090 typedef std::map<ShCtrlGraphNodePtr, ChildrenSet> ChildrenMap; 00091 ChildrenMap m_children; 00092 00093 int m_n; 00094 00095 template<typename T> void postorderNode(T& f, ShCtrlGraphNodePtr root, int level = 0); 00096 template<typename T> void preorderNode(T& f, ShCtrlGraphNodePtr root, int level = 0); 00097 }; 00098 00099 template<typename T> 00100 void ShDomTree::postorder(T& f) 00101 { 00102 postorderNode(f, m_graph->entry()); 00103 } 00104 00105 template<typename T> 00106 void ShDomTree::postorderNode(T& f, ShCtrlGraphNodePtr root, int level) 00107 { 00108 ChildrenSet& children = m_children[root]; 00109 for (ChildrenSet::iterator I = children.begin(); I != children.end(); ++I) { 00110 postorderNode(f, *I, level + 1); 00111 } 00112 f(root, level); 00113 } 00114 00115 template<typename T> 00116 void ShDomTree::preorder(T& f) 00117 { 00118 preorderNode(f, m_graph->entry()); 00119 } 00120 00121 template<typename T> 00122 void ShDomTree::preorderNode(T& f, ShCtrlGraphNodePtr root, int level) 00123 { 00124 f(root, level); 00125 ChildrenSet& children = m_children[root]; 00126 for (ChildrenSet::iterator I = children.begin(); I != children.end(); ++I) { 00127 preorderNode(f, *I, level + 1); 00128 } 00129 } 00130 00131 } 00132 00133 #endif

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