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 #ifndef profile_aux_INCLUDED
00053 #define profile_aux_INCLUDED
00054
00055 #include "vector.h"
00056 #include "hash_map.h"
00057 #include <fb_tnv.h>
00058
00059
00060
00061 namespace Instr {
00062
00063 #if defined(TARG_SL) && defined(__SL__)
00064 typedef INT32 FB_NUM_TYPE;
00065 typedef UINT32 FB_VALUE_TYPE;
00066 #else
00067 typedef INT64 FB_NUM_TYPE;
00068 typedef UINT64 FB_VALUE_TYPE;
00069 #endif
00070
00071
00072
00073
00074
00075 struct Invoke_Profile {
00076 FB_NUM_TYPE invoke_count;
00077 Invoke_Profile() : invoke_count(0) {}
00078 };
00079
00080
00081
00082
00083
00084
00085
00086 struct Branch_Profile {
00087 FB_NUM_TYPE taken;
00088 FB_NUM_TYPE not_taken;
00089 Branch_Profile() : taken(0), not_taken(0) {}
00090 };
00091
00092 #ifdef KEY
00093 #define TNV 10
00094
00095
00096
00097
00098
00099 struct Value_Profile {
00100 FB_NUM_TYPE num_values;
00101 FB_NUM_TYPE exe_counter;
00102 FB_NUM_TYPE value[TNV];
00103 FB_NUM_TYPE freq[TNV];
00104 Value_Profile() : num_values(0), exe_counter(0) {}
00105 };
00106
00107
00108
00109
00110
00111
00112 struct Value_FP_Bin_Profile {
00113 INT64 exe_counter;
00114 INT64 zopnd0;
00115 INT64 zopnd1;
00116 INT64 uopnd0;
00117 INT64 uopnd1;
00118 Value_FP_Bin_Profile() : exe_counter(0),
00119 zopnd0(0), zopnd1(0), uopnd0(0), uopnd1(0) {}
00120 };
00121 #endif
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 struct Compgoto_Profile {
00134 typedef vector<FB_NUM_TYPE> value_type;
00135 value_type targets_profile;
00136
00137 value_type& Get_Targets_Profile () {
00138 return targets_profile;
00139 }
00140
00141 INT32 size () const { return targets_profile.size (); }
00142 };
00143
00144
00145
00146
00147
00148 struct Short_Circuit_Profile {
00149 FB_NUM_TYPE right_taken_count;
00150 FB_NUM_TYPE neither_taken_count;
00151
00152 Short_Circuit_Profile() : right_taken_count(0), neither_taken_count(0) {}
00153 };
00154
00155
00156
00157
00158 struct Call_Profile {
00159 FB_NUM_TYPE entry_count;
00160 FB_NUM_TYPE exit_count;
00161
00162 Call_Profile() : entry_count(0), exit_count(0) {}
00163 };
00164
00165 struct Icall_Profile {
00166 FB_TNV fb_tnv;
00167 };
00168
00169
00170
00171
00172 struct Loop_Profile {
00173 FB_NUM_TYPE invocation_count;
00174 FB_NUM_TYPE total_trip_count;
00175 FB_NUM_TYPE last_trip_count;
00176 FB_NUM_TYPE min_trip_count;
00177 FB_NUM_TYPE max_trip_count;
00178 FB_NUM_TYPE num_zero_trips;
00179
00180 Loop_Profile () :
00181 invocation_count(0), total_trip_count(0), last_trip_count(0),
00182 min_trip_count(0), max_trip_count(0), num_zero_trips(0) {}
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 struct Switch_Profile {
00198 typedef vector<FB_NUM_TYPE> value_type;
00199 value_type targets_profile;
00200 value_type targets_case_value;
00201 Switch_Profile() {}
00202
00203 value_type& Get_Targets_Profile() {
00204 return targets_profile;
00205 }
00206
00207 value_type& Get_Targets_Case_Value() {
00208 return targets_case_value;
00209 }
00210
00211 INT32 size () const { return targets_profile.size (); }
00212 };
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 typedef vector<Invoke_Profile> Invoke_Profile_Vector;
00226 typedef vector<Branch_Profile> Branch_Profile_Vector;
00227 typedef vector<Switch_Profile> Switch_Profile_Vector;
00228 typedef vector<Compgoto_Profile> Compgoto_Profile_Vector;
00229 typedef vector<Loop_Profile> Loop_Profile_Vector;
00230 typedef vector<Short_Circuit_Profile> Short_Circuit_Profile_Vector;
00231 typedef vector<Call_Profile> Call_Profile_Vector;
00232 typedef vector<Icall_Profile> Icall_Profile_Vector;
00233 #ifdef KEY
00234 typedef vector<Value_Profile> Value_Profile_Vector;
00235 typedef vector<Value_FP_Bin_Profile> Value_FP_Bin_Profile_Vector;
00236 #endif
00237
00238 struct PU_Profile_Handle {
00239 Invoke_Profile_Vector Invoke_Profile_Table;
00240 Branch_Profile_Vector Branch_Profile_Table;
00241 Switch_Profile_Vector Switch_Profile_Table;
00242 Compgoto_Profile_Vector Compgoto_Profile_Table;
00243 Loop_Profile_Vector Loop_Profile_Table;
00244 Short_Circuit_Profile_Vector Short_Circuit_Profile_Table;
00245 Call_Profile_Vector Call_Profile_Table;
00246 Icall_Profile_Vector Icall_Profile_Table;
00247 #ifdef KEY
00248 Value_Profile_Vector Value_Profile_Table;
00249 Value_FP_Bin_Profile_Vector Value_FP_Bin_Profile_Table;
00250 #endif
00251
00252 INT32 checksum;
00253 char *file_name;
00254 char *pu_name;
00255 INT32 pu_size;
00256 FB_VALUE_TYPE runtime_fun_address;
00257
00258 PU_Profile_Handle() : checksum(0) {}
00259
00260 PU_Profile_Handle(char *fname, char *pname, long current_pc, INT32 pusize, INT32 c_sum) {
00261 checksum = c_sum;
00262 file_name = (char *) malloc (sizeof(char) * (strlen(fname) + 1));
00263 pu_name = (char *) malloc (sizeof(char) * (strlen(pname) + strlen("/") + strlen(fname) + 1));
00264 strcpy(file_name, fname);
00265 strcpy(pu_name, fname);
00266 strcat(pu_name,"/");
00267 strcat(pu_name,pname);
00268 pu_size = pusize;
00269 runtime_fun_address = current_pc;
00270 }
00271
00272 ~PU_Profile_Handle() {
00273 free (file_name);
00274 free (pu_name);
00275 }
00276
00277 Invoke_Profile_Vector& Get_Invoke_Table () {
00278 return Invoke_Profile_Table;
00279 }
00280
00281 Branch_Profile_Vector& Get_Branch_Table () {
00282 return Branch_Profile_Table;
00283 }
00284
00285 Switch_Profile_Vector& Get_Switch_Table () {
00286 return Switch_Profile_Table;
00287 }
00288
00289 Compgoto_Profile_Vector& Get_Compgoto_Table () {
00290 return Compgoto_Profile_Table;
00291 }
00292
00293 Loop_Profile_Vector& Get_Loop_Table () {
00294 return Loop_Profile_Table;
00295 }
00296
00297 Short_Circuit_Profile_Vector& Get_Short_Circuit_Table () {
00298 return Short_Circuit_Profile_Table;
00299 }
00300
00301 Call_Profile_Vector& Get_Call_Table () {
00302 return Call_Profile_Table;
00303 }
00304
00305 Icall_Profile_Vector& Get_Icall_Table () {
00306 return Icall_Profile_Table;
00307 }
00308
00309 #ifdef KEY
00310 Value_Profile_Vector& Get_Value_Table () {
00311 return Value_Profile_Table;
00312 }
00313
00314 Value_FP_Bin_Profile_Vector& Get_Value_FP_Bin_Table () {
00315 return Value_FP_Bin_Profile_Table;
00316 }
00317 #endif
00318
00319 void Set_file_name(char *s);
00320 void Set_pu_name(char *s);
00321
00322 #ifdef KEY
00323 void * operator new (size_t size) {
00324 void * p = malloc (size);
00325 return p;
00326 }
00327
00328 void operator delete (void *p) {
00329 free (p);
00330 }
00331 #endif
00332
00333 };
00334
00335 typedef PU_Profile_Handle * PU_PROFILE_HANDLE;
00336
00337
00338
00339
00340 typedef hash_map<long, PU_PROFILE_HANDLE> HASH_MAP;
00341
00342 extern HASH_MAP PU_Profile_Handle_Table;
00343 }
00344
00345 #endif