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
00041
00042
00043
00044
00045
00047
00048
00049
00050
00051
00052
00053
00054 #ifdef USE_PCH
00055 #include "cg_pch.h"
00056 #endif // USE_PCH
00057 #pragma hdrstop
00058
00059 #ifdef _KEEP_RCS_ID
00060 static char *rcs_id = "$Source: /scratch/mee/2.4-65/kpro64-pending/be/cg/gra_mon/SCCS/s.gra_grant.cxx $ $Revision: 1.7 $";
00061 #endif
00062
00063 #include "tracing.h"
00064 #include "defs.h"
00065 #include "mempool.h"
00066 #include "bb.h"
00067 #include "bb_map.h"
00068 #include "gra_grant.h"
00069 #include "register.h"
00070 #include "gra_bb.h"
00071 #include "gra_trace.h"
00072 #ifdef TARG_SL2 //minor_reg_alloc
00073 #include "gra_para_region.h"
00074 #endif
00075
00076 MEM_POOL grant_pool;
00077 BB_MAP grant_map;
00078
00079 #ifndef Is_True_On
00080 #define GRANT_INLINE inline
00081 #else
00082 #define GRANT_INLINE static
00083 #endif
00084
00086 typedef REGISTER_SET GRANT;
00088
00089
00090
00092
00094 GRANT_INLINE void
00095 GRANT_REGISTER_SET_Set( GRANT* grant, ISA_REGISTER_CLASS rc, REGISTER_SET set )
00097
00099 {
00100 grant[rc-ISA_REGISTER_CLASS_MIN] = set;
00101 }
00102
00104 GRANT_INLINE REGISTER_SET
00105 GRANT_REGISTER_SET_Get( GRANT* grant, ISA_REGISTER_CLASS rc )
00107
00108
00109
00111 {
00112 return grant[rc-ISA_REGISTER_CLASS_MIN];
00113 }
00114
00116 GRANT_INLINE void
00117 GRANT_Union1D( GRANT* grant, ISA_REGISTER_CLASS rc, REGISTER reg )
00119
00120
00121
00123 {
00124 GRANT_REGISTER_SET_Set(
00125 grant,
00126 rc,
00127 REGISTER_SET_Union1(GRANT_REGISTER_SET_Get(grant,rc),reg)
00128 );
00129 }
00130
00132 GRANT_INLINE void
00133 GRANT_UnionD( GRANT* grant, ISA_REGISTER_CLASS rc, REGISTER_SET register_set )
00135
00136
00137
00139 {
00140 GRANT_REGISTER_SET_Set(
00141 grant,
00142 rc,
00143 REGISTER_SET_Union(GRANT_REGISTER_SET_Get(grant,rc),register_set)
00144 );
00145 }
00146
00148 void
00149 GRA_GRANT_Initialize(void)
00151
00153 {
00154 BB *bb;
00155 GRANT* grant_mem;
00156 static BOOL grant_pool_initialized = FALSE;
00157
00158 if ( ! grant_pool_initialized ) {
00159 grant_pool_initialized = TRUE;
00160 MEM_POOL_Initialize(&grant_pool,"GRA register to LRA",FALSE);
00161 MEM_POOL_Push(&grant_pool);
00162 }
00163
00164 grant_mem =
00165 TYPE_MEM_POOL_ALLOC_N(REGISTER_SET,&grant_pool,
00166 ISA_REGISTER_CLASS_COUNT*PU_BB_Count + 2);
00167 bzero(grant_mem,sizeof(GRANT)*ISA_REGISTER_CLASS_COUNT*PU_BB_Count + 2);
00168 grant_map = BB_MAP_Create();
00169
00170 for ( bb = REGION_First_BB; bb != NULL; bb = BB_next(bb) ) {
00171 BB_MAP_Set(grant_map,bb,(void*) grant_mem);
00172 grant_mem += ISA_REGISTER_CLASS_COUNT;
00173 }
00174 }
00175
00177 void
00178 GRA_GRANT_Transfer( BB* from_bb, BB* to_bb )
00180
00182 {
00183 ISA_REGISTER_CLASS rc;
00184 GRANT* from_grant = (GRANT*)BB_MAP_Get(grant_map,from_bb);
00185 GRANT* to_grant = (GRANT*)BB_MAP_Get(grant_map,to_bb);
00186
00187 FOR_ALL_ISA_REGISTER_CLASS( rc )
00188 GRANT_UnionD(to_grant,rc,GRANT_REGISTER_SET_Get(from_grant,rc));
00189 }
00190
00192 void
00193 GRA_GRANT_Local_Register( GRA_BB* gbb, ISA_REGISTER_CLASS rc, REGISTER reg )
00195
00197 {
00198 GRANT* gr = (GRANT*)BB_MAP_Get(grant_map,gbb->Bb());
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 #if !defined (TARG_X8664)
00221 if (!REGISTER_SET_MemberP(REGISTER_CLASS_function_value(rc), reg) ||
00222 !BB_call(gbb->Bb()) &&
00223 !GTN_SET_MemberP(BB_live_in (gbb->Bb()),Build_Dedicated_TN(rc, reg, 8)) ||
00224 !GTN_SET_MemberP(BB_live_out(gbb->Bb()),Build_Dedicated_TN(rc, reg, 8)))
00225 #else
00226 #if defined (TARG_SL)
00227 if ((REGISTER_SET_MemberP(REGISTER_CLASS_function_value(rc), reg))) {
00228 if (BB_call(gbb->Bb()))
00229 if (GTN_SET_MemberP(BB_live_out(gbb->Bb()),Build_Dedicated_TN(rc, reg, 8)))
00230 return;
00231 else if (GTN_SET_MemberP(BB_live_in (gbb->Bb()),Build_Dedicated_TN(rc, reg, 8)))
00232 return;
00233 }
00234 else
00235 #endif
00236 #endif
00237 {
00238 GRA_Trace_Grant(gbb,rc,reg);
00239 GRANT_Union1D(gr,rc,reg);
00240 }
00241 }
00242
00243
00244 #ifdef TARG_SL2 //minor_reg_alloc
00246 void
00247 GRA_GRANT_REGISTER_SET_Set_For_BB( BB* bb, ISA_REGISTER_CLASS rc, REGISTER_SET reg_set )
00248 {
00249 GRANT* gr = (GRANT*)BB_MAP_Get(grant_map, bb);
00250 GRANT_REGISTER_SET_Set(gr, rc, reg_set);
00251 }
00252 #endif
00253
00255 REGISTER_SET
00256 GRA_GRANT_Get_Local_Registers( BB* bb, ISA_REGISTER_CLASS rc )
00258
00259
00261 {
00262 return GRANT_REGISTER_SET_Get((GRANT*) BB_MAP_Get(grant_map,bb),rc);
00263 }
00264
00266 void
00267 GRA_GRANT_Finalize(void)
00269
00271 {
00272 MEM_POOL_Push(&grant_pool);
00273 BB_MAP_Delete(grant_map);
00274 }
00275
00277 void
00278 GRA_GRANT_Unused_Caller_Saved(void)
00280
00282 {
00283 ISA_REGISTER_CLASS rc;
00284
00285 GRA_Trace_Grant_Unused_Caller_Saved();
00286 for (BB* bb = REGION_First_BB; bb != NULL; bb = BB_next(bb) ) {
00287 GRA_BB* gbb = gbb_mgr.Get(bb);
00288 FOR_ALL_ISA_REGISTER_CLASS( rc ) {
00289 REGISTER_SET free_regs;
00290 REGISTER reg;
00291
00292 free_regs = REGISTER_SET_Difference(REGISTER_CLASS_caller_saves(rc),
00293 gbb->Registers_Used(rc));
00294 FOR_ALL_REGISTER_SET_members(free_regs, reg) {
00295 #ifdef TARG_SL2 //minor_reg_alloc
00296 if(BB_rid(gbb->Bb()) && RID_TYPE_minor(BB_rid(gbb->Bb())))
00297 {
00298 GRA_PARA_REGION* region = gra_para_region_mgr.Get(BB_rid(gbb->Bb()));
00299 if( !REGISTER_SET_Intersection1(region->Registers_Exclude(rc), reg))
00300 GRA_GRANT_Local_Register(gbb, rc, reg);
00301 }
00302 else
00303 #endif
00304 GRA_GRANT_Local_Register(gbb, rc, reg);
00305 }
00306 }
00307 }
00308 }
00309
00310
00311
00312