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

ShDomTree.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 
00025 #ifndef SHDOMTREE_HPP
00026 #define SHDOMTREE_HPP
00027 
00028 #include <set>
00029 #include <map>
00030 #include <vector>
00031 #include <algorithm>
00032 #include "ShDllExport.hpp"
00033 #include "ShCtrlGraph.hpp"
00034 #include "ShRefCount.hpp"
00035 
00036 namespace SH {
00037 
00040   class
00041   SH_DLLEXPORT ShDomTree {
00042   public:
00043     ShDomTree(ShCtrlGraphPtr ctrlGraph);
00044 
00046     template<typename T> void postorder(T& f);
00047 
00049     template<typename T> void preorder(T& f);
00050   
00051     void debugDump();
00052 
00053     int numbering(ShCtrlGraphNodePtr node) const {
00054       return (int)(std::find( m_vertex.begin(), m_vertex.end(), node) - m_vertex.begin());
00055     }
00056   
00057   private:
00058     void dfs(ShCtrlGraphNodePtr v);
00059     ShCtrlGraphNodePtr eval(ShCtrlGraphNodePtr v);
00060     void compress(ShCtrlGraphNodePtr v);
00061     void link(ShCtrlGraphNodePtr v, ShCtrlGraphNodePtr w);
00062   
00063     ShCtrlGraphPtr m_graph;
00064 
00065     // See [TODO Ref Langauer & Tarjan pg 127] for more information on these
00066 
00067     typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> ParentMap;
00068     ParentMap m_parent;
00069     typedef std::set<ShCtrlGraphNodePtr> PredSet;
00070     typedef std::map<ShCtrlGraphNodePtr, PredSet> PredMap;
00071     PredMap m_pred;
00072     typedef std::map<ShCtrlGraphNodePtr, int> SemiMap;
00073     SemiMap m_semi;
00074     std::vector<ShCtrlGraphNodePtr> m_vertex;
00075     typedef std::set<ShCtrlGraphNodePtr> BucketSet;
00076     typedef std::map<ShCtrlGraphNodePtr, BucketSet> BucketMap;
00077     BucketMap m_bucket;
00078     typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> DomMap;
00079     DomMap m_dom;
00080 
00081     typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> AncestorMap;
00082     AncestorMap m_ancestor;
00083     typedef std::map<ShCtrlGraphNodePtr, ShCtrlGraphNodePtr> LabelMap;
00084     LabelMap m_label;
00085 
00086     typedef std::set<ShCtrlGraphNodePtr> ChildrenSet;
00087     typedef std::map<ShCtrlGraphNodePtr, ChildrenSet> ChildrenMap;
00088     ChildrenMap m_children;
00089   
00090     int m_n;
00091 
00092     template<typename T> void postorderNode(T& f, ShCtrlGraphNodePtr root, int level = 0);
00093     template<typename T> void preorderNode(T& f, ShCtrlGraphNodePtr root, int level = 0);
00094   };
00095 
00096   template<typename T>
00097   void ShDomTree::postorder(T& f)
00098   {
00099     postorderNode(f, m_graph->entry());
00100   }
00101 
00102   template<typename T>
00103   void ShDomTree::postorderNode(T& f, ShCtrlGraphNodePtr root, int level)
00104   {
00105     ChildrenSet& children = m_children[root];
00106     for (ChildrenSet::iterator I = children.begin(); I != children.end(); ++I) {
00107       postorderNode(f, *I, level + 1);
00108     }
00109     f(root, level);
00110   }
00111 
00112   template<typename T>
00113   void ShDomTree::preorder(T& f)
00114   {
00115     preorderNode(f, m_graph->entry());
00116   }
00117 
00118   template<typename T>
00119   void ShDomTree::preorderNode(T& f, ShCtrlGraphNodePtr root, int level)
00120   {
00121     f(root, level);
00122     ChildrenSet& children = m_children[root];
00123     for (ChildrenSet::iterator I = children.begin(); I != children.end(); ++I) {
00124       preorderNode(f, *I, level + 1);
00125     }
00126   }
00127 
00128 }
00129 
00130 #endif

Generated on Wed Jun 15 18:12:39 2005 for Sh by  doxygen 1.4.3-20050530