00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifdef USE_PCH
00059 #include "cg_pch.h"
00060 #endif // USE_PCH
00061 #pragma hdrstop
00062
00063 #define GTN_IMPLEMENTATION
00064
00065 #include "defs.h"
00066 #include "mempool.h"
00067 #include "tracing.h"
00068 #include "erglob.h"
00069 #include "tn.h"
00070 #include "gtn_universe.h"
00071
00072 INT32 GTN_UNIVERSE_size;
00073 INT32 First_REGION_GTN;
00074 INT32 *GTN_UNIVERSE_tn_int_map;
00075 TN **GTN_UNIVERSE_int_tn_map;
00076
00077 static MEM_POOL tn_int_map_pool;
00078 static MEM_POOL int_tn_map_pool;
00079 static BOOL pools_initialized;
00080 INT32 tn_int_map_allocated_size;
00081 INT32 int_tn_map_allocated_size;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 extern void
00093 GTN_UNIVERSE_Pu_Begin(void)
00094 {
00095 if ( ! pools_initialized ) {
00096 MEM_POOL_Initialize(&tn_int_map_pool,
00097 "GTN_tn->int_map",TRUE);
00098 MEM_POOL_Initialize(&int_tn_map_pool,
00099 "GTN_int->tn_map",TRUE);
00100 pools_initialized = TRUE;
00101 }
00102
00103 MEM_POOL_Push(&tn_int_map_pool);
00104 MEM_POOL_Push(&int_tn_map_pool);
00105
00106
00107 GTN_UNIVERSE_size = 1;
00108 First_REGION_GTN = GTN_UNIVERSE_size;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 extern void
00120 GTN_UNIVERSE_REGION_Begin(void)
00121 {
00122 if ( ! pools_initialized ) {
00123 MEM_POOL_Initialize(&tn_int_map_pool,
00124 "GTN_tn->int_map",TRUE);
00125 MEM_POOL_Initialize(&int_tn_map_pool,
00126 "GTN_int->tn_map",TRUE);
00127 pools_initialized = TRUE;
00128 }
00129
00130 First_REGION_GTN = GTN_UNIVERSE_size;
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 extern void
00143 GTN_UNIVERSE_Pu_End(void)
00144 {
00145 MEM_POOL_Pop(&tn_int_map_pool);
00146 MEM_POOL_Pop(&int_tn_map_pool);
00147 tn_int_map_allocated_size = 0;
00148 int_tn_map_allocated_size = 1;
00149 GTN_UNIVERSE_size = -1;
00150 GTN_UNIVERSE_int_tn_map = NULL;
00151 GTN_UNIVERSE_tn_int_map = NULL;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 extern void
00164 GTN_UNIVERSE_Add_TN(
00165 TN *tn
00166 )
00167 {
00168 INT32 tn_num = TN_number(tn);
00169
00170 if (tn_num < tn_int_map_allocated_size && TN_is_global_reg(tn) &&
00171 GTN_UNIVERSE_tn_int_map[tn_num] <= GTN_UNIVERSE_size &&
00172 GTN_UNIVERSE_int_tn_map[GTN_UNIVERSE_tn_int_map[tn_num]] == tn)
00173 {
00174
00175
00176 return;
00177 }
00178
00179
00180
00181
00182
00183 if ( GTN_UNIVERSE_size == 1 ) {
00184 tn_int_map_allocated_size = Last_TN + 1;
00185 int_tn_map_allocated_size = Last_TN + 1;
00186
00187 GTN_UNIVERSE_tn_int_map = TYPE_MEM_POOL_ALLOC_N(INT32,
00188 &tn_int_map_pool,
00189 Last_TN + 1);
00190 GTN_UNIVERSE_int_tn_map = TYPE_MEM_POOL_ALLOC_N(TN *,
00191 &int_tn_map_pool,
00192 Last_TN + 1);
00193 }
00194 else {
00195 if ( GTN_UNIVERSE_size == int_tn_map_allocated_size ) {
00196 INT32 new_size = int_tn_map_allocated_size * 2;
00197
00198 GTN_UNIVERSE_int_tn_map =
00199 TYPE_MEM_POOL_REALLOC_N(TN *,&int_tn_map_pool,
00200 GTN_UNIVERSE_int_tn_map,
00201 int_tn_map_allocated_size,
00202 new_size);
00203
00204 int_tn_map_allocated_size = new_size;
00205 }
00206
00207 if ( TN_number(tn) >= tn_int_map_allocated_size ) {
00208 INT32 new_size = MAX(tn_int_map_allocated_size * 2, Last_TN + 1);
00209
00210 GTN_UNIVERSE_tn_int_map =
00211 TYPE_MEM_POOL_REALLOC_N(INT32,&tn_int_map_pool,
00212 GTN_UNIVERSE_tn_int_map,
00213 tn_int_map_allocated_size,
00214 new_size);
00215 tn_int_map_allocated_size = new_size;
00216 }
00217 }
00218
00219 GTN_UNIVERSE_tn_int_map[tn_num] = GTN_UNIVERSE_size;
00220 Set_TN_is_global_reg (tn);
00221 GTN_UNIVERSE_int_tn_map[GTN_UNIVERSE_size++] = tn;
00222 }