00001 // ---------------------------------------------------------------------- 00002 // 00003 // C-Breeze 00004 // C Compiler Framework 00005 // 00006 // Copyright (c) 2000 University of Texas at Austin 00007 // 00008 // Samuel Z. Guyer 00009 // Daniel A. Jimenez 00010 // Calvin Lin 00011 // 00012 // Permission is hereby granted, free of charge, to any person 00013 // obtaining a copy of this software and associated documentation 00014 // files (the "Software"), to deal in the Software without 00015 // restriction, including without limitation the rights to use, copy, 00016 // modify, merge, publish, distribute, sublicense, and/or sell copies 00017 // of the Software, and to permit persons to whom the Software is 00018 // furnished to do so, subject to the following conditions: 00019 // 00020 // The above copyright notice and this permission notice shall be 00021 // included in all copies or substantial portions of the Software. 00022 // 00023 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00024 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00025 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00026 // NONINFRINGEMENT. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT 00027 // AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00028 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00029 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00030 // THE SOFTWARE. 00031 // 00032 // We acknowledge the C-to-C Translator from MIT Laboratory for 00033 // Computer Science for inspiring parts of the C-Breeze design. 00034 // 00035 // ---------------------------------------------------------------------- 00036 00037 #ifndef CBZ_DOMINATORS_H 00038 #define CBZ_DOMINATORS_H 00039 00040 #include <bitset> 00041 #include "dismantle.h" 00042 00043 typedef bitset<1024> basicblock_bitset; 00044 00045 class dominator_info : public algorithm_info 00046 { 00047 public: 00048 00049 // --- Used in computing dominator tree 00050 00051 basicblockNode * label; 00052 basicblockNode * parent; 00053 basicblockNode * ancestor; 00054 basicblockNode * child; 00055 int sdno; 00056 int size; 00057 basicblock_bitset bucket; 00058 00059 dominator_info(basicblockNode * node, int depth_first_num); 00060 }; 00061 00062 00063 class Dominators 00064 { 00065 friend class dominator_info; 00066 00067 public: 00068 // --- Some useful types 00069 00070 typedef vector<basicblockNode *> basicblock_vec; 00071 typedef map<basicblockNode *, int> index_map; 00072 typedef map<basicblockNode *, basicblockNode *> basicblock_map; 00073 typedef map<basicblockNode *, basicblock_bitset> basicblockset_map; 00074 00075 private: 00076 00077 // --- Procedure 00078 00079 procNode * _proc; 00080 00081 // --- The root node 00082 00083 basicblockNode * _root; 00084 00085 // --- If true, build post-dominators information 00086 // _forward = true --> successors --> dominators 00087 // _forward = false --> predecessors --> post-dominators 00088 00089 const bool _forward; 00090 00091 // --- Map from basic blocks to df order 00092 00093 index_map node_index; 00094 00095 // --- Basic blocks in depth first order 00096 00097 basicblock_vec df_vec; 00098 00099 // --- A special basic block: not in any cfg 00100 00101 static basicblockNode * None; 00102 00103 int _index; 00104 00105 // ---------------------------------------- 00106 00107 00108 // --- Compute dominator tree 00109 00110 void dominator_tree(); 00111 void depth_first_search(basicblockNode * node, 00112 basicblockNode * par); 00113 void compress(basicblockNode * v); 00114 basicblockNode * eval(basicblockNode * v); 00115 void link(basicblockNode * v, basicblockNode * w); 00116 00117 public: 00118 00119 Dominators(procNode * proc, bool forward); 00120 00121 ~Dominators(); 00122 00123 // --- Check if A dominates B 00124 00125 static bool dominates(basicblockNode * A, basicblockNode * B); 00126 00127 00128 void print(); 00129 00130 }; 00131 00132 #endif // CBZ_DOMINATORS_H