00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* ======================================================================= 00037 * ======================================================================= 00038 * 00039 * Module: op_map.h 00040 * $Revision: 1.2 $ 00041 * $Date: 02/11/07 23:41:27-00:00 $ 00042 * $Author: fchow@keyresearch.com $ 00043 * $Source: /scratch/mee/2.4-65/kpro64-pending/be/cg/SCCS/s.op_map.h $ 00044 * 00045 * Revision comments: 00046 * 00047 * 5-Apr-1995 - Initial version 00048 * 00049 * Description: 00050 * ============ 00051 * 00052 * General OP-map facility for dynamically attaching information to OPs. 00053 * OP-maps can be instantiated either locally (BB_OP_MAP: limited to OPs 00054 * in a single BB) or globally (OP_MAP: applying to OPs in any BB). 00055 * OP-maps are much more limited in scope than WN_MAPs. They map to 00056 * three types of objects: void *, INT32, and INT64. OP-maps live only 00057 * within CG. 00058 * 00059 * void OP_MAP_Init() 00060 * Initialize the OP_MAP mechanism for a given invocation of CG. 00061 * 00062 * void OP_MAP_Finish() 00063 * Cleanup the OP_MAP mechanism after a given invocation of CG. 00064 * 00065 * 00066 * Global maps (OP_MAP) can contain OPs from any BB as well as OPs that are 00067 * currently not contained in any BB: 00068 * 00069 * OP_MAP OP_MAP_Create(void) 00070 * OP_MAP OP_MAP32_Create(void) 00071 * OP_MAP OP_MAP64_Create(void) 00072 * Create and return a new global OP_MAP. 00073 * 00074 * void OP_MAP_Delete(OP_MAP map) 00075 * Free the storage for <map> so it can be reused within the same 00076 * invocation of CG. 00077 * 00078 * void OP_MAP_Set(OP_MAP map, OP *op, void *value) 00079 * void OP_MAP32_Set(OP_MAP map, OP *op, INT32 value) 00080 * void OP_MAP64_Set(OP_MAP map, OP *op, INT64 value) 00081 * Set the <map> value for <op> to <value>. 00082 * 00083 * void *OP_MAP_Get(OP_MAP map, OP *OP) 00084 * INT32 OP_MAP32_Get(OP_MAP map, OP *OP) 00085 * INT64 OP_MAP64_Get(OP_MAP map, OP *OP) 00086 * Lookup the <map> value for <op>. If no value has been previously 00087 * set, returns the appropriate zero value. 00088 * 00089 * 00090 * Local maps (BB_OP_MAP) are restricted to OPs contained within one 00091 * specified BB (OPs may be added to a BB after instantiating a local 00092 * op map). As a result, they are more space and time efficient than 00093 * global maps: 00094 * 00095 * BB_OP_MAP BB_OP_MAP_Create(BB *bb, MEM_POOL *pool) 00096 * BB_OP_MAP BB_OP_MAP32_Create(BB *bb, MEM_POOL *pool) 00097 * BB_OP_MAP BB_OP_MAP64_Create(BB *bb, MEM_POOL *pool) 00098 * Create and return a new BB_OP_MAP for <bb>. <pool> specifies 00099 * the MEM_POOL used for storage allocation of the BB_OP_MAP 00100 * data structures. Note that there is no corresponding delete 00101 * function -- deallocating the memory from <pool> is sufficient. 00102 * 00103 * void BB_OP_MAP_Set(BB_OP_MAP map, OP *op, void *value) 00104 * void BB_OP_MAP32_Set(BB_OP_MAP map, OP *op, INT32 value) 00105 * void BB_OP_MAP64_Set(BB_OP_MAP map, OP *op, INT64 value) 00106 * Set the <map> value for <op> to <value>. 00107 * 00108 * void *BB_OP_MAP_Get(BB_OP_MAP map, OP *op) 00109 * INT32 BB_OP_MAP32_Get(BB_OP_MAP map, OP *op) 00110 * INT64 BB_OP_MAP32_Get(BB_OP_MAP map, OP *op) 00111 * Lookup the <map> value for <op>. If no value has been previously 00112 * set, or <op> is not contained in the BB for which the map was 00113 * created, returns the appropriate zero value. 00114 * 00115 * 00116 * In addition to OP_MAPs, this module also provides a way of mapping 00117 * 16-bit OP_map_idx's to local OPs. This takes advantage of the 00118 * size limitations on BBs to provide a more space-efficient way of 00119 * referring to local OPs. This is currently tuned to provide 00120 * constant-time access when called with the same BB more than once 00121 * in a row. If necessary, the implementation can be changed to 00122 * easily deal with a working set of more than one BB. 00123 * 00124 * OP *OP_MAP_Idx_Op(BB *bb, UINT16 idx) 00125 * Return the OP in <bb> such that OP_map_idx(op) == <idx>, or NULL 00126 * if there is no OP in <bb> with the given <idx>. 00127 * 00128 * ======================================================================= 00129 * ======================================================================= */ 00130 00131 #ifndef OP_MAP_INCLUDED 00132 #define OP_MAP_INCLUDED 00133 00134 #include "op.h" 00135 #include "bb.h" 00136 00137 00138 /* Initialization and finalization: 00139 */ 00140 extern void OP_MAP_Init(void); 00141 extern void OP_MAP_Finish(void); 00142 00143 00144 /* Global maps: 00145 */ 00146 typedef struct op_map *OP_MAP; 00147 00148 typedef enum { OP_MAP_PTR, OP_MAP_I32, OP_MAP_I64, OP_MAP_DELETED } OP_MAP_KIND; 00149 00150 extern OP_MAP _OP_MAP_Create(OP_MAP_KIND kind); 00151 #define OP_MAP_Create() _OP_MAP_Create(OP_MAP_PTR) 00152 #define OP_MAP32_Create() _OP_MAP_Create(OP_MAP_I32) 00153 #define OP_MAP64_Create() _OP_MAP_Create(OP_MAP_I64) 00154 00155 void OP_MAP_Delete(OP_MAP map); 00156 #ifdef TARG_IA64 00157 BOOL OP_MAP_Is_Delete(OP_MAP map); 00158 #endif 00159 00160 void OP_MAP_Set(OP_MAP map, OP *op, void *value); 00161 void OP_MAP32_Set(OP_MAP map, OP *op, INT32 value); 00162 void OP_MAP64_Set(OP_MAP map, OP *op, INT64 value); 00163 00164 void *OP_MAP_Get(OP_MAP map, const OP *OP); 00165 INT32 OP_MAP32_Get(OP_MAP map, const OP *OP); 00166 INT64 OP_MAP64_Get(OP_MAP map, const OP *OP); 00167 00168 /* Local maps: 00169 */ 00170 typedef struct bb_op_map { 00171 /* -------------------------------------------------- */ 00172 /* All fields are private. */ 00173 /* -------------------------------------------------- */ 00174 BB *bb; 00175 union { 00176 void **ptr; 00177 INT32 *i32; 00178 INT64 *i64; 00179 } themap; 00180 MEM_POOL *pool; 00181 UINT32 nelem; 00182 OP_MAP_KIND kind; 00183 } *BB_OP_MAP; 00184 00185 extern BB_OP_MAP BB_OP_MAP_Create_Kind(BB *bb, 00186 MEM_POOL *pool, 00187 OP_MAP_KIND kind); 00188 00189 #define BB_OP_MAP_Create(bb, pool) BB_OP_MAP_Create_Kind((bb), (pool), OP_MAP_PTR) 00190 #define BB_OP_MAP32_Create(bb, pool) BB_OP_MAP_Create_Kind((bb), (pool), OP_MAP_I32) 00191 #define BB_OP_MAP64_Create(bb, pool) BB_OP_MAP_Create_Kind((bb), (pool), OP_MAP_I64) 00192 00193 /* declare Extend_Map here so inline functions find it with correct name */ 00194 extern void BB_OP_MAP_Extend_Map(BB_OP_MAP map, OP *op); 00195 00196 inline void BB_OP_MAP_Set(BB_OP_MAP map, OP *op, void *value) 00197 { 00198 INT idx = OP_map_idx(op); 00199 00200 Is_True(map->kind == OP_MAP_PTR, ("OP_MAP is of wrong kind")); 00201 if (OP_bb(op) != map->bb || idx >= map->nelem) { 00202 BB_OP_MAP_Extend_Map(map, op); 00203 } 00204 map->themap.ptr[idx] = value; 00205 } 00206 00207 inline void BB_OP_MAP32_Set(BB_OP_MAP map, OP *op, INT32 value) 00208 { 00209 INT idx = OP_map_idx(op); 00210 00211 Is_True(map->kind == OP_MAP_I32, ("OP_MAP is of wrong kind")); 00212 if (OP_bb(op) != map->bb || idx >= map->nelem) { 00213 BB_OP_MAP_Extend_Map(map, op); 00214 } 00215 map->themap.i32[idx] = value; 00216 } 00217 00218 inline void BB_OP_MAP64_Set(BB_OP_MAP map, OP *op, INT64 value) 00219 { 00220 INT idx = OP_map_idx(op); 00221 00222 Is_True(map->kind == OP_MAP_I64, ("OP_MAP is of wrong kind")); 00223 if (OP_bb(op) != map->bb || idx >= map->nelem) { 00224 BB_OP_MAP_Extend_Map(map, op); 00225 } 00226 map->themap.i64[idx] = value; 00227 } 00228 00229 inline void *BB_OP_MAP_Get(BB_OP_MAP map, const OP *op) 00230 { 00231 INT idx = OP_map_idx(op); 00232 Is_True(map->kind == OP_MAP_PTR, ("OP_MAP is of wrong kind")); 00233 return OP_bb(op) == map->bb 00234 && idx < map->nelem 00235 ? map->themap.ptr[idx] : (void *)NULL; 00236 } 00237 00238 inline INT32 BB_OP_MAP32_Get(BB_OP_MAP map, const OP *op) 00239 { 00240 INT idx = OP_map_idx(op); 00241 Is_True(map->kind == OP_MAP_I32, ("OP_MAP is of wrong kind")); 00242 return OP_bb(op) == map->bb 00243 && idx < map->nelem 00244 ? map->themap.i32[idx] : (INT32)0; 00245 } 00246 00247 inline INT64 BB_OP_MAP64_Get(BB_OP_MAP map, const OP *op) 00248 { 00249 INT idx = OP_map_idx(op); 00250 Is_True(map->kind == OP_MAP_I64, ("OP_MAP is of wrong kind")); 00251 return OP_bb(op) == map->bb 00252 && idx < map->nelem 00253 ? map->themap.i64[idx] : (INT64)0; 00254 } 00255 00256 00257 /* Misc: 00258 */ 00259 extern OP *OP_MAP_Idx_Op(BB *bb, UINT16 idx); 00260 00261 #endif /* OP_MAP_INCLUDED */
1.5.6