00001 //-*-c++-*- 00002 00003 /* 00004 * Copyright 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00005 */ 00006 00007 // ==================================================================== 00008 // ==================================================================== 00009 // 00010 // Module: opt_base.h 00011 // $Revision: 1.1.1.1 $ 00012 // $Date: 2005/10/21 19:00:00 $ 00013 // $Author: marcel $ 00014 // $Source: /proj/osprey/CVS/open64/osprey1.0/be/opt/opt_base.h,v $ 00015 // 00016 // Revision history: 00017 // 8-SEP-94 shin - Original Version 00018 // 00019 // ==================================================================== 00020 // 00021 // Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00022 // 00023 // This program is free software; you can redistribute it and/or modify 00024 // it under the terms of version 2 of the GNU General Public License as 00025 // published by the Free Software Foundation. 00026 // 00027 // This program is distributed in the hope that it would be useful, but 00028 // WITHOUT ANY WARRANTY; without even the implied warranty of 00029 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00030 // 00031 // Further, this software is distributed without any warranty that it 00032 // is free of the rightful claim of any third person regarding 00033 // infringement or the like. Any license provided herein, whether 00034 // implied or otherwise, applies only to this software file. Patent 00035 // licenses, if any, provided herein do not apply to combinations of 00036 // this program with other software, or any other product whatsoever. 00037 // 00038 // You should have received a copy of the GNU General Public License 00039 // along with this program; if not, write the Free Software Foundation, 00040 // Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00041 // 00042 // Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00043 // Mountain View, CA 94043, or: 00044 // 00045 // http://www.sgi.com 00046 // 00047 // For further information regarding this notice, see: 00048 // 00049 // http://oss.sgi.com/projects/GenInfo/NoticeExplan 00050 // 00051 // ==================================================================== 00052 // 00053 // Description: 00054 // 00055 // This file contains a class and several macros used widely throughout 00056 // the optimizer: 00057 // 00058 // --> THe class MAP, which provides a hash-table based mapping from 00059 // one type to another. 00060 // 00061 // Currently, MAP is only used in opt_cfg.h to map labels to BBs. 00062 // Perhaps it should be replaced by STL hash_map. 00063 // 00064 // --> Macros for iterators including: 00065 // FOR_ALL_ELEM and FOR_ALL_ELEM_REVERSE and FOR_ALL_ELEM_EXCEPT 00066 // FOR_ALL_NODE and FOR_ALL_NODE_REVERSE and FOR_ALL_NODE_EXCEPT 00067 // FOR_ALL_ITEM 00068 // 00069 // ==================================================================== 00070 // ==================================================================== 00071 00072 00073 #ifndef opt_base_INCLUDED 00074 #define opt_base_INCLUDED "opt_base.h" 00075 #ifdef _KEEP_RCS_ID 00076 static char *opt_basercs_id = opt_base_INCLUDED"$Revision: 1.8 $"; 00077 #endif /* _KEEP_RCS_ID */ 00078 00079 #include "cxx_base.h" 00080 #include "cxx_template.h" 00081 00082 00083 // ==================================================================== 00084 // 00085 // Classes MAP (and MAP_LIST) provide a hash-table based mapping from 00086 // one type to another. 00087 // 00088 // ==================================================================== 00089 00090 00091 typedef void * POINTER; 00092 00093 class MAP_LIST : public SLIST_NODE { 00094 private: 00095 POINTER key; 00096 POINTER val; 00097 00098 MAP_LIST(void); 00099 MAP_LIST(const MAP_LIST&); 00100 MAP_LIST& operator = (const MAP_LIST&); 00101 public: 00102 MAP_LIST(POINTER k, POINTER v) { Set_Next(NULL); key = k; val = v; } 00103 ~MAP_LIST(void); 00104 00105 POINTER Key(void) { return key;} 00106 void Set_key(POINTER k) { key = k; } 00107 POINTER Val(void) { return val;} 00108 void Set_val(POINTER v) { val = v; } 00109 }; 00110 00111 typedef MAP_LIST *MAP_LIST_P; 00112 00113 class MAP_LIST_CONTAINER : public SLIST { 00114 DECLARE_SLIST_CLASS( MAP_LIST_CONTAINER, MAP_LIST ) 00115 }; 00116 class MAP_LIST_ITER : public SLIST_ITER { 00117 DECLARE_SLIST_ITER_CLASS( MAP_LIST_ITER, MAP_LIST, MAP_LIST_CONTAINER ) 00118 }; 00119 00120 class MAP { 00121 private: 00122 MEM_POOL *mem_pool; 00123 mUINT32 size; 00124 MAP_LIST_P *hash_vec; 00125 00126 MAP(void); 00127 MAP(const MAP&); 00128 MAP& operator = (const MAP&); 00129 00130 public: 00131 MAP(mUINT32 hash_size, MEM_POOL *pool); 00132 ~MAP(void); 00133 00134 void Alloc_hash_vec(void); 00135 void Free_hash_vec(void); 00136 00137 mUINT32 Hash(POINTER k); 00138 MAP_LIST *Find_map_list(POINTER k); 00139 void Add_map(POINTER k, POINTER v); 00140 POINTER Get_val(POINTER k); 00141 #ifdef Is_True_On 00142 void Dump_map(FILE *fp=stderr); 00143 #endif 00144 }; 00145 00146 00147 // ==================================================================== 00148 // 00149 // MACROS for iterators includes: 00150 // FOR_ALL_ELEM and FOR_ALL_ELEM_REVERSE and FOR_ALL_ELEM_EXCEPT 00151 // FOR_ALL_NODE and FOR_ALL_NODE_REVERSE and FOR_ALL_NODE_EXCEPT 00152 // FOR_ALL_ITEM 00153 // 00154 // ==================================================================== 00155 00156 00157 // MACROS for iterators 00158 // 00159 // FOR_ALL_ELEM(var, iter, init) 00160 // Iterates through a list of elements that may be stored in a 00161 // linked list or an array. It returns the content of the list. 00162 // 00163 // Parameters: 00164 // 00165 // var: the variable to hold the current node in the list 00166 // iter: the iterator that contains the list iteration info 00167 // init: the function that initialize the iterator. 00168 // 00169 // Example: 00170 // 00171 // The following two lines iterates through the successor 00172 // list of a basic block "bb": 00173 // 00174 // BB_NODE *tmp; 00175 // BB_LIST_ITER bb_succ_iter(); 00176 // FOR_ALL_ELEM (tmp, bb_succ_iter, Init(bb->Succ())) { 00177 // 00178 // 00179 // expands to: 00180 // 00181 // BB_LIST_ITER bb_succ_iter( bb->Succ() ); 00182 // //for each successor of bb 00183 // for ( tmp = bb_succ_iter.First_bb(); 00184 // ! bb_succ_iter.Is_Empty(); 00185 // tmp = bb_succ_iter.Next_bb() ) 00186 // 00187 // Note: 00188 // 00189 // Since the iterator is designed to be used as brower, please 00190 // make certain the code in the loop does not change the 00191 // structure of the list. 00192 00193 #define FOR_ALL_ELEM(var, iter, init) \ 00194 iter.init; \ 00195 for (var = iter.First_elem(); \ 00196 !iter.Is_Empty(); \ 00197 var = iter.Next_elem()) 00198 00199 #define FOR_ALL_ELEM_REVERSE(var, iter, init) \ 00200 iter.init; \ 00201 for (var = iter.Last_elem(); \ 00202 !iter.Is_Empty_Reverse(); \ 00203 var = iter.Prev_elem()) 00204 00205 // FOR_ALL_ELEM_EXCEPT(var, iter, init, except) 00206 // Iterates through a list of elements that may be stored in a 00207 // linked list or an array, and skips the "except" element. 00208 // It returns the content of the list. 00209 00210 #define FOR_ALL_ELEM_EXCEPT(var, iter, init, except) \ 00211 FOR_ALL_ELEM(var,iter,init) if ( var != except ) 00212 00213 // FOR_ALL_NODE(var, iter, init) 00214 // Iterates through a list of elements that may be stored in a 00215 // linked list or an array. It returns the linked list nodes if 00216 // it is a linked list, or it returns the index if the list is 00217 // represented as a dynamic array. 00218 // 00219 // Parameters: 00220 // 00221 // var: the variable to hold the current node or index 00222 // iter: the iterator that contains the list iteration info 00223 // init: the function that initialize the iterator. 00224 00225 #define FOR_ALL_NODE(var, iter, init) \ 00226 iter.init; \ 00227 for (var = iter.First(); \ 00228 !iter.Is_Empty(); \ 00229 var = iter.Next()) 00230 00231 #define FOR_ALL_NODE_REVERSE(var, iter, init) \ 00232 iter.init; \ 00233 for (var = iter.Last(); \ 00234 !iter.Is_Empty_Reverse(); \ 00235 var = iter.Prev()) 00236 00237 // FOR_ALL_NODE_EXCEPT(var, iter, init, except) 00238 // Iterates through a list of elements that may be stored in a 00239 // linked list or an array, and skips the "except" node. It 00240 // returns the linked list nodes if it is a linked list, or it 00241 // returns the index if the list is represented as a dynamic array. 00242 00243 #define FOR_ALL_NODE_EXCEPT(var, iter, init, except) \ 00244 FOR_ALL_NODE(var,iter,init) if ( var != except ) 00245 00246 00247 // FOR_ALL_ITEM(iter, init) 00248 // Iterates through a list of elements that may be stored in a 00249 // linked list or an array. It does not return anything. 00250 // The pointer to the current node or the index is internal to 00251 // the iterator. Member functions need to be declared to access 00252 // the current node or index. The difference between FOR_ALL_ITEM 00253 // and FOR_ALL_NODE is that FOR_ALL_ITEM does not require a variable 00254 // to be supplied, which duplicates a similar variable within the 00255 // iterator. 00256 // 00257 // Parameters: 00258 // 00259 // iter: the iterator that contains the list iteration info 00260 // init: the function that initialize the iterator. 00261 00262 #define FOR_ALL_ITEM(iter, init) \ 00263 iter.init; \ 00264 for (iter.First(); \ 00265 !iter.Is_Empty(); \ 00266 iter.Next()) 00267 00268 00269 #endif // opt_base_INCLUDED 00270 00271 00272 // ====================================================================
1.5.6