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 #ifndef sched_heur_INCLUDED
00050 #define sched_heur_INCLUDED
00051
00052 #include "targ_issue_port.h"
00053
00054
00055 #include <vector>
00056
00057 #include "tracing.h"
00058 #include "bb.h"
00059 #include "op.h"
00060 #include "errors.h"
00061
00062
00063 #include "mempool.h"
00064 #include "mempool_allocator.h"
00065
00066 #include "region.h"
00067 #include "sched_util.h"
00068 #include "sched_cand.h"
00069
00070
00071 #define COLD_PATH_EXEC_PROB (0.1f)
00072 #define HOT_PATH_EXEC_PROB (0.7f)
00073
00074 #define DONATE_P_READY_CAND_BB_REACH_PROB (0.7f * REACH_PROB_SCALE)
00075
00076
00077
00078
00079
00080 typedef enum {
00081 NO_LATER,
00082 AS_EARLY_AS_POSSIBLE,
00083 } E_TIME_CONSTRAIT ;
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 typedef struct tagE_Time_Constraint {
00108
00109 CYCLE threshold;
00110 E_TIME_CONSTRAIT constraint;
00111
00112 } E_Time_Constraint ;
00113
00114
00115
00116 class FAVOR_DELAY_HEUR {
00117
00118 private:
00119 MEM_POOL* _mp ;
00120
00121 REGION* _rgn_scope ;
00122 BB* _bb_scope ;
00123 BB* _target_block;
00124 BB* _significant_pred;
00125 OP* _xfer_op ;
00126 char* _describe ;
00127
00128
00129 BOOL _initialize ;
00130
00131 BOOL _stress_spec ;
00132
00133
00134
00135
00136 RGN_CFLOW_MGR* _cflow_mgr;
00137
00138
00139
00140
00141
00142
00143 #define OP_HEUR_INFO_MAGIC_NUM (0x55aa)
00144 typedef struct tagOP_HEUR_INFO {
00145
00146 OP* _op;
00147 BB* _etime_set_by_which_bb ;
00148 INT32 _fan_out ;
00149 INT32 _issuable_port_num ;
00150 float _delay ;
00151 CYCLE _e_time ;
00152 mINT16 _magic_num ;
00153
00154 tagOP_HEUR_INFO (OP *op) : _op(op) {
00155 _etime_set_by_which_bb = NULL;
00156 _delay = 0.0f ;
00157 _e_time = (CYCLE)0;
00158 _magic_num = OP_HEUR_INFO_MAGIC_NUM ;
00159
00160 _fan_out = 0;
00161 _issuable_port_num = 0;
00162 PORT_SET port_set = TSI_Issue_Ports(OP_code(op));
00163 while (port_set.Body()) {
00164
00165 if (port_set.Body() & 1) { ++ _issuable_port_num ; }
00166 port_set = (PORT_SET)((port_set.Body() >> 1));
00167 }
00168 }
00169
00170 void Dump (FILE *f=stderr,BOOL verbose=FALSE) ;
00171
00172 } OP_HEUR_INFO ;
00173
00174
00175
00176 typedef struct tagBB_HEUR_STUFF {
00177
00178 mBOOL _heur_need_adjust;
00179 BB* _bb;
00180 BB_OP_MAP _op_2_op_heur_info;
00181 MEM_POOL* _mp;
00182
00183 void Set_OP_Heur_Info (OP* op, OP_HEUR_INFO * info) {
00184
00185 if (info) {
00186 Is_True (op == info->_op,
00187 ("corrupted heuristic structure!"));
00188
00189 Is_True (OP_bb(info->_op) == _bb,
00190 ("BB:%d is not op's home bb",
00191 BB_id (OP_bb(info->_op))));
00192 }
00193
00194 BB_OP_MAP_Set (_op_2_op_heur_info, op, (void*)info);
00195 }
00196
00197 OP_HEUR_INFO * Get_OP_Heur_Info (OP * op) {
00198 return (OP_HEUR_INFO *)
00199 BB_OP_MAP_Get (_op_2_op_heur_info, op);
00200 }
00201
00202 tagBB_HEUR_STUFF (BB* bb, MEM_POOL *mp) :
00203 _bb(bb), _mp(mp) {
00204
00205 _op_2_op_heur_info = BB_OP_MAP_Create (_bb, _mp);
00206
00207 _heur_need_adjust = TRUE ;
00208
00209 OP * op ;
00210 FOR_ALL_BB_OPs (_bb, op) {
00211
00212 OP_HEUR_INFO *tmp = CXX_NEW(OP_HEUR_INFO(op),_mp);
00213 BB_OP_MAP_Set (_op_2_op_heur_info, op, tmp);
00214 }
00215
00216 }
00217 } BB_HEUR_STUFF;
00218
00219 CFG_NODE_MAP _heur_map;
00220
00221
00222
00223 BOOL _trace_cand_sel;
00224 FILE* _trace_file;
00225
00226 typedef struct { BB* succ ; float reach_prob ; float max_delay ;
00227 INT32 flow_shift_latency ;
00228 } SUCC_INFO ;
00229
00230 void Alloc_Heur_Data (BB* bb);
00231 void Alloc_Heur_Data (REGION* rgn);
00232
00233 BB_HEUR_STUFF* Get_BB_Heur_Stuff (BB* bb) {
00234 return (BB_HEUR_STUFF*)_heur_map.Get_Map (bb);
00235 }
00236
00237 OP_HEUR_INFO* Get_OP_Heur_Info (OP* op) {
00238
00239 BB_HEUR_STUFF* bb_heur_stuff =
00240 Get_BB_Heur_Stuff (OP_bb(op));
00241
00242 Is_True (bb_heur_stuff,
00243 ("Fail to get BB:%d's heuristic stuff",
00244 BB_id(OP_bb(op))));
00245
00246 return (OP_HEUR_INFO*)BB_OP_MAP_Get (
00247 bb_heur_stuff->_op_2_op_heur_info, op);
00248 }
00249
00250
00251 void Reset_BB_OPs_etime (const BB_VECTOR *bbs) ;
00252 void Reset_BB_OPs_etime (BB *bb);
00253 void Set_OP_etime (OP* op, CYCLE cyc) {
00254
00255 OP_HEUR_INFO* heur = Get_OP_Heur_Info (op);
00256 Is_True (heur, ("OP[%d] of BB:%d has no heuristic information"));
00257
00258 heur->_e_time = cyc ;
00259 }
00260 void Find_Significant_Pred_For_Target_Blk (void);
00261 void Adjust_Etime_For_Target_Block (void);
00262
00263 BOOL BB_Need_Adjusting_Delay (BB* bb);
00264 void Set_BB_Need_Adjusting_Delay (BB* bb);
00265 void Set_BB_Need_Not_Adjusting_Delay (BB* bb);
00266
00267 void Compute_Delay (OP* op, SUCC_INFO* succ_info, INT32 succ_num) ;
00268 void Compute_Delay (BB* bb);
00269 void Compute_Delay (REGION* rgn);
00270
00271 void Adjust_Delay (BB* bb);
00272 void Adjust_Delay (REGION* rgn);
00273
00274 void Compute_FanOut (OP* op);
00275 void Compute_FanOut_For_All_OP (BB* bb);
00276 void Compute_FanOut_For_All_OP (REGION* rgn);
00277
00278 CYCLE Exclude_Unqualifed_Cand_Under_Etime_Constraint
00279 (CAND_LIST& cand_lst, E_Time_Constraint* constraint) ;
00280
00281 CANDIDATE* Choose_Better_Of_Tie (
00282 CANDIDATE*, OP_HEUR_INFO* ,
00283 CANDIDATE* , OP_HEUR_INFO* ,
00284 BOOL comes_from_targ_bb) ;
00285
00286 CANDIDATE* Select_Best_Candidate (
00287 CAND_LIST& cand_lst,
00288 BB* targ,
00289 E_Time_Constraint* etime_constraint);
00290
00291 void Initialize (REGION* rgn);
00292 void Initialize (BB* bb);
00293
00294
00295 BOOL Is_In_Global_Scope (void) {
00296 Is_True (_initialize, ("have not been initialized!"));
00297 return _rgn_scope != NULL;
00298 }
00299
00300
00301
00302
00303
00304 inline BOOL Cntl_Spec_Ld_In_Normal_Form_Is_Profitable (OP* op) ;
00305
00306 BOOL Upward_Code_Motion_Inc_Live_Range_Greatly
00307 (CANDIDATE* cand, SRC_BB_INFO* bb_info,
00308 RGN_CFLOW_MGR* cflow_info) ;
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 CANDIDATE* Select_Best_Candidate_For_Stress_Spec_Purpose (
00325 CAND_LIST& m_ready_cand_lst,
00326 CAND_LIST& p_ready_cand_lst,
00327 BB* targ,
00328 E_Time_Constraint* etime_constraint);
00329
00330 CANDIDATE* Select_Best_Candidate_For_Stress_Spec_Purpose (
00331 CAND_LIST& cand_lst,
00332 BB* targ,
00333 E_Time_Constraint* etime_constraint);
00334
00335 public:
00336
00337
00338
00339
00340
00341
00342
00343 FAVOR_DELAY_HEUR (MEM_POOL *mp) ;
00344
00345 ~FAVOR_DELAY_HEUR (void) ;
00346
00347
00348
00349 void Initialize (REGION *rgn,RGN_CFLOW_MGR* rgn_cflow_mgr) ;
00350 void Initialize (BB *bb,RGN_CFLOW_MGR* rgn_cflow_mgr) ;
00351 void Finialize (void) ;
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 CANDIDATE * Select_Best_Candidate (
00363 CAND_LIST& m_ready_cand_lst,
00364 CAND_LIST& p_ready_cand_lst,
00365 BB * targ,
00366 E_Time_Constraint * etime_constraint);
00367
00368
00369
00370 CYCLE Get_Cand_Issue_Cyc (CANDIDATE *cand);
00371
00372
00373
00374 void Adjust_Heur_Stuff_When_BB_Changed
00375 (BB * new_target,SRC_BB_MGR& src_bb_mgr);
00376
00377
00378
00379
00380 void Adjust_Heur_After_Cand_Sched
00381 (OP *cand,CYCLE issue_cyc);
00382
00383
00384
00385
00386
00387
00388
00389
00390 void Adjust_Heur_After_Sched_One_Cyc
00391 (OP_Vector& op_vect, CYCLE issue_cyc);
00392
00393
00394
00395
00396 void Compute_Heur_Data_For_Inserted_OP (OP* op) ;
00397 void Compute_Heur_Data_For_Appended_OP (OP* op) ;
00398 void Compute_Heur_Data_For_Prepended_OP (OP* op);
00399
00400
00401
00402 void * Detach_OP_Heur_Info (OP* op) ;
00403
00404
00405
00406
00407 void Attach_OP_Heur_Info (OP* op, void* Heur_Data);
00408
00409 BOOL Upward_Global_Sched_Inc_Live_Range_Greatly
00410 (CANDIDATE* cand,
00411 SRC_BB_INFO* bb_info,
00412 RGN_CFLOW_MGR* cflow_info);
00413
00414 BOOL Upward_Spec_Global_Sched_Is_Profitable
00415 (CANDIDATE* cand, SRC_BB_INFO* bb_info,
00416 RGN_CFLOW_MGR* cflow_info);
00417
00418 BOOL Upward_Useful_Sched_Is_Profitable
00419 (CANDIDATE* cand, SRC_BB_INFO* bb_info,
00420 RGN_CFLOW_MGR* cflow_info) ;
00421
00422 BOOL Upward_Global_Sched_Is_Profitable
00423 (CANDIDATE* cand,
00424 SRC_BB_INFO* bb_info,
00425 RGN_CFLOW_MGR* cflow_info);
00426
00427 BOOL Renaming_Is_Profitable(CANDIDATE * cand);
00428
00429
00430
00431
00432 BOOL It_is_Better_No_New_Cycle_For_Cur_BB (void) ;
00433 BOOL BB_Can_Potentially_Donate_P_Ready_Cand (BB* src, BB* targ);
00434
00435
00436 void Estimate_Cand_Etime (OP* op) ;
00437
00438
00439 void Dump_OP_Heur_Info (OP* op, FILE* f=stderr,
00440 BOOL verbose=FALSE);
00441 void Dump_OP_Heur_Info (BB* bb, FILE* f=stderr,
00442 BOOL verbose=FALSE);
00443 void Dump (FILE* f=stderr, BOOL verbose=TRUE);
00444
00445
00446
00447 void Enable_Trace_Cand_Sel_Process (FILE* f) ;
00448 void Disable_Trace_Cand_Sel_Process (void);
00449 BOOL Trace_Cand_Sel_Enabled (void) { return _trace_cand_sel; }
00450 void Trace_Cand_Sel_Process (const char* fmt, ...);
00451
00452 #ifdef Is_True_On
00453 void gdb_dump(void);
00454 #endif
00455
00456 };
00457
00458
00459 #endif