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 #include <alloca.h>
00058 #include <math.h>
00059 #include "defs.h"
00060 #include "config.h"
00061 #include "config_targ_opt.h"
00062 #include "mempool.h"
00063 #include "bb.h"
00064 #include "bb_set.h"
00065 #include "tracing.h"
00066 #include "timing.h"
00067 #include "cgir.h"
00068 #include "glob.h"
00069 #include "tn_map.h"
00070 #include "cg.h"
00071 #include "cg_flags.h"
00072 #include "cg_thr.h"
00073 #include "ercg.h"
00074 #include "cgtarget.h"
00075 #include "cxx_memory.h"
00076 #include "cg_spill.h"
00077 #include "targ_isa_enums.h"
00078
00079
00080
00081
00082
00083 #define OP_visited_thr(o) OP_flag1(o)
00084 #define Set_OP_visited_thr(o) Set_OP_flag1(o)
00085 #define Reset_OP_visited_thr(o) Reset_OP_flag1(o)
00086
00087 BOOL Trace_THR = FALSE;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 void
00098 Remove_Unnecessary_Check_Instrs(BB *bb)
00099 {
00100 OP *op;
00101
00102 FOR_ALL_BB_OPs_REV(bb, op) {
00103
00104
00105 if (OP_load(op) && CGTARG_Is_OP_Check_Load(op)) {
00106 OP *prev_op;
00107 BOOL store_present = FALSE;
00108
00109
00110
00111
00112 for (prev_op = OP_prev(op); prev_op; prev_op = OP_prev(prev_op)) {
00113
00114 if (OP_store(prev_op)) {store_present = TRUE; break; }
00115
00116 if (OP_load(prev_op) &&
00117 CGTARG_Is_OP_Advanced_Load(prev_op) && !store_present) {
00118
00119 CGTARG_Perform_THR_Code_Generation(prev_op, op,
00120 THR_DATA_SPECULATION_NO_RB_CLEANUP);
00121
00122 Reset_BB_scheduled(bb);
00123 }
00124 }
00125 }
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 void
00140 CG_THR::Check_THR_Profitability ()
00141 {
00142 OP *op;
00143 std::list<ARC*> arc_list;
00144 ARC *arc;
00145
00146 _candidate_list.clear();
00147
00148 FOR_ALL_BB_OPs_FWD (_bb, op) {
00149 Reset_OP_visited_thr(op);
00150 if (_thr_type & THR_DATA_SPECULATION_NO_RB) {
00151 if (OP_store(op)) {
00152
00153 ARC_LIST *arcs;
00154 for (arcs = OP_succs(op); arcs != NULL; arcs = ARC_LIST_rest(arcs)) {
00155 arc = ARC_LIST_first(arcs);
00156 OP *succ_op = ARC_succ(arc);
00157
00158
00159
00160 if (ARC_is_dotted(arc) && OP_load(succ_op) &&
00161 !OP_mem_fill_type(succ_op))
00162 arc_list.push_back(arc);
00163 }
00164 }
00165 }
00166 }
00167
00168
00169
00170
00171
00172 std::list<ARC*>::iterator arc_iter;
00173 for (arc_iter = arc_list.begin(); arc_iter != arc_list.end(); arc_iter++) {
00174 if (_thr_type & THR_DATA_SPECULATION_NO_RB) {
00175 OP *pred_op = ARC_pred(*arc_iter);
00176 OP *succ_op = ARC_succ(*arc_iter);
00177
00178 if (OP_Has_Restrictions(pred_op,succ_op,_thr_before_regalloc)) continue;
00179
00180 OPSCH *pred_opsch = OP_opsch(pred_op, _thr_map);
00181 OPSCH *succ_opsch = OP_opsch(succ_op, _thr_map);
00182
00183 INT old_pred_ltime = OPSCH_lstart (pred_opsch);
00184 INT old_succ_ltime = OPSCH_lstart (succ_opsch);
00185
00186 INT new_succ_etime = old_pred_ltime + ARC_latency(*arc_iter);
00187
00188 if (new_succ_etime > old_succ_ltime) {
00189 _candidate_list.push_back(*arc_iter);
00190 } else {
00191 Set_ARC_is_dotted(arc, FALSE);
00192 }
00193 }
00194 }
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204 void
00205 CG_THR::Perform_THR_Code_Generation ()
00206 {
00207 if (_thr_type & THR_DATA_SPECULATION_NO_RB) {
00208 std::list<ARC*>::iterator arc_iter;
00209 for (arc_iter = _candidate_list.begin();
00210 arc_iter != _candidate_list.end(); arc_iter++) {
00211
00212 OP *succ_op = ARC_succ(*arc_iter);
00213 if (OP_visited_thr(succ_op)) continue;
00214
00215 CGTARG_Perform_THR_Code_Generation(succ_op, NULL, _thr_type);
00216 Set_OP_visited_thr(succ_op);
00217 _chk_instr_inserted = TRUE;
00218 }
00219 }
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229 BOOL
00230 CG_THR::OP_Has_Restrictions(OP *pred_op, OP *succ_op, BOOL before_regalloc)
00231 {
00232 if (_thr_type & THR_DATA_SPECULATION_NO_RB) {
00233 if (!before_regalloc && OP_load(succ_op)) {
00234 INT succ_base_idx = TOP_Find_Operand_Use(OP_code(succ_op), OU_base);
00235 TN *succ_base_tn = OP_opnd(succ_op, succ_base_idx);
00236 TN *succ_result_tn = OP_result(succ_op, 0);
00237
00238 if (TNs_Are_Equivalent(succ_result_tn, succ_base_tn)) return TRUE;
00239 }
00240
00241 #if !defined(TARG_MIPS) && !defined(TARG_X8664)
00242
00243 if (OP_load(succ_op) &&
00244 TOP_Find_Operand_Use(OP_code(succ_op), OU_postincr) >= 0)
00245 return TRUE;
00246 #endif
00247 }
00248
00249 return FALSE;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 void
00259 CG_THR::Perform_THR()
00260 {
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 if (_thr_type & THR_DATA_SPECULATION_NO_RB) {
00292 if (BB_length(_bb) > 1) {
00293
00294
00295
00296 CG_DEP_Compute_Graph(
00297 _bb,
00298 INCLUDE_ASSIGNED_REG_DEPS,
00299 NON_CYCLIC,
00300 NO_MEMREAD_ARCS,
00301 #ifndef TARG_MIPS
00302 (Is_Target_Itanium()) ? NO_MEMIN_ARCS :
00303 #endif
00304 INCLUDE_MEMIN_ARCS,
00305 #ifndef TARG_MIPS
00306 (Is_Target_Itanium()) ? INCLUDE_CONTROL_ARCS :
00307 #endif
00308 NO_CONTROL_ARCS,
00309 NULL);
00310
00311
00312
00313 Compute_OPSCH (_bb, _thr_map, &_thr_pool);
00314
00315
00316 Check_THR_Profitability ();
00317
00318
00319 Perform_THR_Code_Generation ();
00320
00321
00322 if (_chk_instr_inserted) Reset_BB_scheduled(_bb);
00323
00324 CG_DEP_Delete_Graph (_bb);
00325 }
00326 }
00327 }
00328
00329 CG_THR::CG_THR()
00330 {
00331
00332
00333 MEM_POOL_Initialize (&_thr_pool, "CG_THR_pool", FALSE);
00334 MEM_POOL_Initialize (&_thr_map_pool, "CG_THR_map_pool", FALSE);
00335 MEM_POOL_Push(&_thr_pool);
00336 MEM_POOL_Push (&_thr_map_pool);
00337
00338 _thr_map = BB_MAP_Create ();
00339 Trace_THR = Get_Trace (TP_SCHED, 0);
00340 }
00341
00342 void
00343 CG_THR::Init(BB *bb, THR_TYPE thr_type, BOOL before_regalloc)
00344 {
00345 _thr_type = thr_type;
00346 _bb = bb;
00347 BB_OP_MAP omap = BB_OP_MAP_Create(bb, &_thr_map_pool);
00348 BB_MAP_Set(_thr_map, bb, omap);
00349 _chk_instr_inserted = FALSE;
00350 _thr_before_regalloc = before_regalloc;
00351 }
00352
00353 CG_THR::~CG_THR()
00354 {
00355 BB_MAP_Delete(_thr_map);
00356
00357 MEM_POOL_Pop (&_thr_pool);
00358 MEM_POOL_Pop (&_thr_map_pool);
00359 MEM_POOL_Delete (&_thr_pool);
00360 MEM_POOL_Delete (&_thr_map_pool);
00361 }