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_MERGEPOINTS_H 00038 #define CBZ_MERGEPOINTS_H 00039 00040 #include "memoryblock.h" 00041 #include "proceduredb.h" 00042 00043 // ------------------------------------------------------------ 00044 // mergePoints : Holds all the merge points for the system -- 00045 // essentially, all the phi functions. Each entry holds the list of 00046 // objects whose states should be merged at a particular point in the 00047 // program. 00048 00049 // mergepoint_pair (df element, predecessors) : given a basic block, 00050 // we use the DFPreds class to find its dominance frontier. For each 00051 // element of the dominance frontier, we also return the list of basic 00052 // blocks that come immediately before that element. 00053 00054 typedef pair< basicblockLocation *, basicblock_set > mergepoint_pair; 00055 typedef list< mergepoint_pair > mergepoint_list; 00056 typedef mergepoint_list::iterator mergepoint_list_p; 00057 00058 // mergepoint_map : for each merge point, record the objects that need 00059 // to be merged there. 00060 00061 typedef map< basicblockLocation *, memoryblock_set > mergepoint_map; 00062 typedef mergepoint_map::iterator mergepoint_map_p; 00063 00064 class mergePoints : public mergepoint_map 00065 { 00066 private: 00067 00068 procedureDB * Procedures; 00069 bool _debug; 00070 00071 public: 00072 00073 mergePoints(procedureDB * procedures, bool debug = false) 00074 : mergepoint_map(), 00075 Procedures(procedures), 00076 _debug(debug) 00077 {} 00078 00079 00080 00081 // --- Given a list of definitions and their location, find the set 00082 // of merge points (dominance frontier) and record the objects at 00083 // those points. This is equivalent to the SSA process that adds phi 00084 // functions for a particular set of definitions. 00085 00086 void add_merge_points(basicblockLocation * location_of_def, 00087 int last_stmt_num, 00088 const memoryblock_set & defs); 00089 00090 // --- Find the dominance frontier for a particular program 00091 // point. We do this interprocedurally by searching up the call 00092 // stack until we find a suitable place for the merge. 00093 00094 void find_merge_points(basicblockLocation * cur, 00095 mergepoint_list & merge_points); 00096 00097 // --- Add a block to the list of blocks that need to be merged at 00098 // the given merge point. 00099 00100 void add_block_to_merge_point(mergepoint_pair & merge_point, 00101 memoryBlock * block); 00102 00103 // --- Lookup a merge point: given a particular basic block, see if 00104 // there are any objects to be merged at its entry. 00105 00106 memoryblock_set * lookup_merge_point(basicblockLocation * where); 00107 00108 // --- Print some statistics 00109 00110 void stats(); 00111 }; 00112 00113 #endif // CBZ_MERGEPOINTS_H