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 #ifndef edge_profile_INCLUDED
00031 #define edge_profile_INCLUDED
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "cxx_memory.h"
00045 #include "profile_com.h"
00046 #include "tn.h"
00047 #include "instr_reader.h"
00048 #include "glob.h"
00049 #include "fb_freq.h"
00050 #include "fb_info.h"
00051 #include "const.h"
00052 #include "op.h"
00053 #include "mempool.h"
00054 #include "profile_util.h"
00055 #include "wn.h"
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #define INSTR_INIT_NAME "__profile_init"
00066 #define PU_INIT_NAME "__profile_pu_init"
00067 #define EDGE_INST_NAME "__profile_edge"
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 #define FIRST_INPUT_REG (32+REGISTER_MIN)
00078 #define FIRST_LOCAL_REG (32+REGISTER_MIN)
00079 #define FIRST_OUTPUT_REG (127+REGISTER_MIN)
00080 #define LAST_STACKED_REG (127+REGISTER_MIN)
00081 #define FIRST_ROTATING_INTEGER_REG (32+REGISTER_MIN)
00082 #define FIRST_ROTATING_FLOAT_REG (32+REGISTER_MIN)
00083 #define FIRST_ROTATING_PREDICATE_REG (16+REGISTER_MIN)
00084 #define LAST_ROTATING_INTEGER_REG (127+REGISTER_MIN)
00085 #define LAST_ROTATING_FLOAT_REG (127+REGISTER_MIN)
00086 #define LAST_ROTATING_PREDICATE_REG (63+REGISTER_MIN)
00087
00088 #define RETURN_REG (8+REGISTER_MIN)
00089 #define RETURN_REG1 (8+REGISTER_MIN)
00090 #define RETURN_REG2 (9+REGISTER_MIN)
00091 #define RETURN_REG3 (10+REGISTER_MIN)
00092 #define RETURN_REG4 (11+REGISTER_MIN)
00093
00094 #define FLOAT_RETURN_REG (8+REGISTER_MIN)
00095 #define FLOAT_RETURN_REG1 (8+REGISTER_MIN)
00096 #define FLOAT_RETURN_REG2 (9+REGISTER_MIN)
00097 #define FLOAT_RETURN_REG3 (10+REGISTER_MIN)
00098 #define FLOAT_RETURN_REG4 (11+REGISTER_MIN)
00099 #define FLOAT_RETURN_REG5 (12+REGISTER_MIN)
00100 #define FLOAT_RETURN_REG6 (13+REGISTER_MIN)
00101 #define FLOAT_RETURN_REG7 (14+REGISTER_MIN)
00102 #define FLOAT_RETURN_REG8 (15+REGISTER_MIN)
00103
00104 #define BBlist_Alloc(void) TYPE_PU_ALLOC(BBLIST)
00105 #define ERROR_FREQ(freq) freq < 0.0
00106 #define ERROR_PROB(prob) prob < 0.0
00107 #define UNINIT_FREQ(freq) freq < 0.0
00108 #define UNINIT_PROB(prob) prob < 0.0
00109 #define ZERO_FREQ(freq) freq == 0.0
00110 #define ZERO_PROB(prob) prob == 0.0
00111
00112 #define FB_FREQ_UNINIT -1.0
00113 #define FB_FREQ_UNKNOWN -2.0
00114 #define FB_FREQ_ERROR -3.0
00115 #define LABEL_IDX_NONE 0
00116
00117 extern INT32 current_PU_handle;
00118 extern BOOL CG_PU_Has_Feedback;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 class PROFILE_MEM;
00130 class PROFILE;
00131 class EDGE_PROFILE;
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 class PROFILE_MEM {
00147 protected:
00148 MEM_POOL _m;
00149
00150 PROFILE_MEM() {
00151 MEM_POOL_Initialize( &_m, "PROFILE_MEM", true );
00152 MEM_POOL_Push( &_m );
00153 }
00154
00155 ~PROFILE_MEM() {
00156 MEM_POOL_Pop( &_m );
00157 MEM_POOL_Delete(&_m );
00158 }
00159 };
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 class PROFILE : public PROFILE_MEM{
00175 protected:
00176
00177
00178
00179 PROFILE_PHASE _phase;
00180
00181
00182
00183 BOOL _instrumenting;
00184
00185 public:
00186 PROFILE() {}
00187 ~PROFILE() {}
00188 };
00189
00190 class EDGE_PROFILE : public PROFILE{
00191 private:
00192 CGRIN* _rin;
00193 BB* _pu_first_bb;
00194 BB* _pu_last_bb;
00195
00196 UINT32 _count_branch;
00197 UINT32 _count_indirect_cond_branch;
00198 UINT32 _count_cloop;
00199 UINT32 _count_call;
00200 UINT32 _count_top;
00201
00202
00203
00204 UINT32 _instrument_count;
00205
00206
00207
00208 INT _pu_handle;
00209 PU_PROFILE_HANDLES _fb_handles;
00210
00211 char * _srcfile_pu_name;
00212 TN * _pu_hdr_return_tn;
00213
00214 public:
00215 EDGE_PROFILE( CGRIN* rin, BOOL instru, PROFILE_PHASE phase,
00216 PU_PROFILE_HANDLES fb_handles ) {
00217 _rin = rin;
00218 _instrumenting = instru;
00219 _phase = phase;
00220 _fb_handles = fb_handles;
00221 _pu_first_bb = REGION_First_BB;;
00222 _pu_last_bb = Find_Last_BB(_pu_first_bb);
00223 _pu_handle = current_PU_handle;
00224 _instrument_count = 0;
00225 _srcfile_pu_name = CXX_NEW_ARRAY(char, strlen(Src_File_Name) + strlen("/") + strlen(Cur_PU_Name)
00226 + 1, &_m);
00227 strcpy(_srcfile_pu_name,Src_File_Name);
00228 strcat(_srcfile_pu_name,"/");
00229 strcat(_srcfile_pu_name,Cur_PU_Name);
00230 _pu_hdr_return_tn = Gen_Register_TN( ISA_REGISTER_CLASS_integer, 8 );
00231 }
00232
00233 ~EDGE_PROFILE() {}
00234 PU_PROFILE_HANDLES& FB_Handle() { return _fb_handles; }
00235
00236
00237
00238
00239 void Instrument_Indirect_Cond_Branch( BB *bb );
00240 void Instrument_Ip_Rel_Branch( BB *bb );
00241 void Instrument_Cloop_Branch( BB *bb );
00242 void Instrument_Top_Branch( BB *bb );
00243 void Instrument_Call_Branch( BB *bb );
00244 void Instrument_None_and_Other_Xfer( BB *bb );
00245
00246
00247
00248
00249 void Annotate_Indirect_Cond_Branch( BB *bb );
00250 void Annotate_Ip_Rel_Branch( BB *bb );
00251 void Annotate_Cloop_Branch( BB *bb );
00252 void Annotate_Top_Branch( BB *bb );
00253 void Annotate_Call_Branch( BB *bb );
00254 void Annotate_None_and_Other_Xfer( BB *bb );
00255
00256
00257
00258
00259 inline void Increase_Instru_Counter(void)
00260 {
00261 _instrument_count++;
00262 }
00263
00264 inline void Set_Pu_First_BB(BB* bb)
00265 {
00266 _pu_first_bb = bb;
00267 }
00268
00269 inline BB* Get_Pu_First_BB(void)
00270 {
00271 return _pu_first_bb;
00272 }
00273
00274 inline void Set_Pu_Last_BB(BB* bb)
00275 {
00276 _pu_last_bb = bb;
00277 }
00278
00279 inline BB* Get_Pu_Last_BB(void)
00280 {
00281 return _pu_last_bb;
00282 }
00283
00284 inline char* Get_Srcfile_Pu_Name(void)
00285 {
00286 return _srcfile_pu_name;
00287 }
00288
00289
00290
00291
00292 void CG_Instrument_Node( BB *bb );
00293 void CG_Annotate_Node( BB *bb );
00294
00295
00296 void CG_Instrument(void);
00297 void CG_Annotate(void);
00298
00299
00300 void Dump_Feedback(void);
00301 void Instrument_Entry(void);
00302 void Change_Tgt_Label( op* branch_op,LABEL_IDX old_label,
00303 LABEL_IDX new_label );
00304 void Prepare_Call_Init_Return_BB(BB * bb);
00305 void Gen_Instr_Init_Call_BB(char* function_name,char* outputfile_name,
00306 int phase);
00307 BB* Gen_PU_Init_Call_BB(char* function_name,char* file_pu_name,
00308 INT64 _instrument_count);
00309 BB* Gen_Instru_Call_BB(char* function_name, char* file_pu_name,INT64 id);
00310 BB* Gen_Call_BB(char* function_name, char* str_arg, INT64 int_arg,
00311 int restore_type, int restore_sum = 0 );
00312 BB* Gen_Call_BB(char* function_name, TN * PU_Handle, INT64 int_arg,
00313 int restore_type, int restore_sum = 0 );
00314
00315
00316
00317
00318 TN* Find_TN(TOP opc,int iBB,int i1, TN* t1, int index);
00319 TN* Find_TN_in_BB(TOP opc, BB* in, int i1, TN* t1, int index);
00320
00321
00322 BOOL BB_Is_In_BBLIST(BBLIST* bblst,BB* bb,BB* before_bb);
00323 void Prepare_Instrument(void);
00324 void Require_And_Alloc_Reg(void);
00325
00326 BOOL BB_Is_For_Instru(BB* bb);
00327 void Propagate(void);
00328 void Propagate_Node_In(BB* bb);
00329 void Propagate_Node_Out(BB* bb);
00330 };
00331 extern BOOL CG_PU_Has_Feedback;
00332 extern BOOL FREQ_freqs_computed;
00333 extern void Compute_Edge_Freq_Base_Prob(void);
00334 extern void Compute_Edge_Prob_Base_Freq(void);
00335 extern void CG_Edge_Profile_Annotation( CGRIN* cgrin,PROFILE_PHASE phase );
00336 extern void CG_Edge_Profile_Instrument( CGRIN* cgrin,PROFILE_PHASE phase );
00337 extern WN* Gen_Call( char *name, WN *arg1, WN *arg2, TYPE_ID rtype = MTYPE_V );
00338 extern WN* Gen_Call_Shell( char *name, TYPE_ID rtype, INT32 argc );
00339 extern INT32 Curr_PU_BB_Count(void);
00340 extern void Init_CFG(void);
00341 extern void Change_BB_Label(BB* bb,LABEL_IDX i);
00342 extern BB* First_Branch_BB(void);
00343 extern BOOL Result_Tn_In_BB(BB* bb, TN* tn);
00344 extern BOOL Opnd_Tn_In_BB(BB* bb, TN* tn);
00345 extern LABEL_IDX Get_Br_Op_Tgt_Label(OP* branch_op);
00346 extern INT32 Get_Return_Reg_Sum(BB* bb);
00347 extern INT32 Get_Float_Return_Reg_Sum(BB* bb);
00348 inline WN *
00349 Gen_Param( WN *arg, UINT32 flag )
00350 {
00351 return WN_CreateParm( WN_rtype( arg ), arg,
00352 MTYPE_To_TY( WN_rtype( arg ) ), flag );
00353 }
00354
00355 #endif
00356
00357