00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "bb_edge_profile.h"
00022 #include <stdio.h>
00023 #include "util.h"
00024 #include "cfg.h"
00025 #include "node_table.h"
00026 #include "edge_table.h"
00027 #include "predicate.h"
00028 #include <legoUtil.H>
00029 #include "lego_util.h"
00030 #include "instrument.h"
00031
00032
00033 #ifdef BEDEBUG
00034 #define BELEVEL 1
00035 #define BEdb(my_level,format,args...) emit_message2(BELEVEL,my_level,format,##args)
00036 #else
00037 #define BEdb(my_level,format,args...)
00038 #endif // BEDEBUG
00039
00040 void BB_Edge_Profile::doit(legoModule *module_ptr,int option)
00041 {
00042
00043
00044
00045
00046 Predicate::init_true_predicate_oprd();
00047 _my_instrument.initialize_parameters();
00048
00049
00050 FILE *bb_table_fp=NULL;
00051 FILE *edge_table_fp=NULL;
00052 int bb_start_index;
00053 int edge_start_index;
00054
00055 int proc_count=module_ptr->GetCount();
00056 for(int i=0;i<proc_count;i++)
00057 {
00058 legoProc *proc_ptr;
00059 legoRegion *region_ptr;
00060 proc_ptr=(legoProc *)module_ptr->GetItem(i);
00061 assert(proc_ptr->GetRegionType()==RT_PROC);
00062
00063
00064
00065
00066 _my_instrument.initialize_temp_registers(proc_ptr);
00067
00068
00069
00070
00071
00072 if(strcmp(proc_ptr->GetProcName(),"_main")==0)
00073 {
00074 _my_instrument.rename_main(module_ptr,proc_ptr);
00075 }
00076
00077
00078
00079
00080 CFG *cfg=new CFG();
00081 cfg->build(proc_ptr);
00082
00083
00084
00085
00086
00087 _bb_node_table=new Node_Table();
00088
00089 if(i==0)
00090 {
00091
00092 _bb_node_table->open_file("BBiD_PT");
00093 bb_table_fp=_bb_node_table->node_table_fp();
00094 }
00095 else
00096 {
00097 _bb_node_table->set_node_table_fp(bb_table_fp);
00098 _bb_node_table->set_start_index(bb_start_index);
00099 }
00100
00101 _bb_node_table->build_from_proc(proc_ptr);
00102
00103 _bb_node_table->print(_bb_node_table->node_table_fp());
00104
00105 bb_start_index=_bb_node_table->start_index();
00106
00107
00108
00109
00110 _edge_table=new Edge_Table();
00111
00112 if(i==0)
00113 {
00114 _edge_table->open_new_or_old_file("eDGe_PT");
00115 edge_table_fp=_edge_table->table_fp();
00116 }
00117 else
00118 {
00119 _edge_table->set_table_fp(edge_table_fp);
00120 _edge_table->set_start_index(edge_start_index);
00121 }
00122
00123 _edge_table->build(cfg);
00124 _edge_table->profile_all_edges();
00125 _edge_table->print_to_file(_edge_table->table_fp());
00126
00127 edge_start_index=_edge_table->start_index();
00128 assert(edge_start_index>=0);
00129
00130
00131
00132
00133 reset_bbid_start();
00134 reset_bbid_end();
00135
00136
00137
00138
00139 instrument(proc_ptr);
00140
00141
00142
00143
00144 check_max_op_id(proc_ptr);
00145
00146
00147
00148
00149 delete cfg;
00150 delete _edge_table;
00151 delete _bb_node_table;
00152 }
00153
00154 if(proc_count>0)
00155 {
00156 fclose(bb_table_fp);
00157 fclose(edge_table_fp);
00158
00159 open_main_file(bb_start_index,edge_start_index);
00160 open_header_file();
00161 close_main_file();
00162 close_header_file();
00163 }
00164 }
00165
00166 void BB_Edge_Profile::lego_write(legoModule *module_ptr,char *input_filename)
00167 {
00168 char *output_filename=new char[strlen(input_filename)+9];
00169 strcpy(output_filename,input_filename);
00170
00171 int i=strlen(input_filename)-3;
00172
00173 output_filename[i+0]='_';
00174 output_filename[i+1]='B';
00175 output_filename[i+2]='B';
00176 output_filename[i+3]='_';
00177 output_filename[i+4]='e';
00178 output_filename[i+5]='D';
00179 output_filename[i+6]='G';
00180 output_filename[i+7]='e';
00181 output_filename[i+8]='.';
00182 output_filename[i+9]='e';
00183 output_filename[i+10]='l';
00184 output_filename[i+11]='\0';
00185
00186 LegoWrite(module_ptr,output_filename);
00187 }
00188
00189 void BB_Edge_Profile::instrument(legoProc *proc_ptr)
00190 {
00191 recursive_instrument(proc_ptr,proc_ptr);
00192 }
00193
00194
00195
00196
00197
00198
00199 void BB_Edge_Profile::recursive_instrument(legoProc *proc_ptr,legoRegion *region_ptr)
00200 {
00201 int sub_region_count;
00202 legoRegion *sub_region_ptr;
00203
00204 regionTypes region_type=region_ptr->GetRegionType();
00205
00206 switch(region_type)
00207 {
00208 case RT_PROC:
00209
00210 case RT_LOOP:
00211
00212 case RT_LOOPBODY:
00213
00214 case RT_TRACE:
00215
00216 case RT_TREE:
00217
00218
00219 sub_region_count=region_ptr->GetCount();
00220 for(int i=0;i<sub_region_count;i++)
00221 {
00222 sub_region_ptr=(legoRegion *)region_ptr->GetItem
00223 (i);
00224 recursive_instrument(proc_ptr,sub_region_ptr);
00225 }
00226 break;
00227 case RT_SB:
00228 case RT_HB:
00229 case RT_BB:
00230 insert_probe(proc_ptr,region_ptr);
00231 break;
00232
00233 default:
00234 fprintf(stderr,"ERROR region_type\n");
00235 assert(0);
00236 break;
00237 }
00238 }
00239
00240 void BB_Edge_Profile::insert_probe(legoProc *proc_ptr,legoRegion *region_ptr)
00241 {
00242
00243
00244
00245
00246 int region_id=region_ptr->GetRegionId();
00247 int mapping=_bb_node_table->find(region_id);
00248 opList *entry_op_list=region_ptr->GetEntryOpsPtr();
00249 legoOp *from_op_ptr=entry_op_list->GetOpPtr();
00250 int s_time=from_op_ptr->GetSchedTime();
00251
00252 from_op_ptr=_my_instrument.append_save_and_set_1_param_code(mapping,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),from_op_ptr,s_time);
00253
00254 from_op_ptr=_my_instrument.append_pbrr_code(BB_EDGE_PROFILE_START_PROBE_NAME,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),from_op_ptr,s_time);
00255
00256 from_op_ptr=_my_instrument.append_brl_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),from_op_ptr,1,s_time);
00257
00258 from_op_ptr=_my_instrument.append_restore_1_param_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),from_op_ptr,s_time);
00259
00260
00261
00262
00263 for(opList *exit_op_list=region_ptr->GetExitOpsPtr();exit_op_list!=NULL;exit_op_list=exit_op_list->GetNextListPtr())
00264 {
00265 legoOp *exit_op=exit_op_list->GetOpPtr();
00266 if(exit_op!=NULL)
00267 {
00268 BEdb(3,"exit_op %d %s",exit_op->GetOpId(),ParseMap(exit_op->GetOpcode()));
00269 instrument_exit_op(proc_ptr,region_ptr,exit_op);
00270
00271 }
00272 }
00273 }
00274
00275
00276
00277
00278
00279
00280 int BB_Edge_Profile::bbid_end_has_probe(int region_id)
00281 {
00282 for(int i=0;i<_bbid_end_index;i++)
00283 {
00284 if(_bbid_end[i]==region_id)
00285 return 1;
00286 }
00287 return 0;
00288 }
00289
00290 void BB_Edge_Profile::bbid_end_insert(int region_id)
00291 {
00292 _bbid_end[_bbid_end_index]=region_id;
00293 _bbid_end_index++;
00294 assert(_bbid_end_index<MAX_BB_ENTRY);
00295 }
00296
00297 void BB_Edge_Profile::reset_bbid_start()
00298 {
00299 for(int i=0;i<MAX_BB_ENTRY;i++)
00300 {
00301 _bbid_start[i]=0;
00302 }
00303
00304 _bbid_start_index=0;
00305 }
00306
00307 void BB_Edge_Profile::reset_bbid_end()
00308 {
00309 for(int i=0;i<MAX_BB_ENTRY;i++)
00310 {
00311 _bbid_end[i]=0;
00312 }
00313
00314 _bbid_end_index=0;
00315 }
00316
00317
00318
00319
00320
00321 int BB_Edge_Profile::bbid_start_has_probe(int region_id)
00322 {
00323 for(int i=0;i<_bbid_start_index;i++)
00324 {
00325 if(_bbid_start[i]==region_id)
00326 return 1;
00327 }
00328 return 0;
00329 }
00330
00331 void BB_Edge_Profile::bbid_start_insert(int region_id)
00332 {
00333 _bbid_start[_bbid_start_index]=region_id;
00334 _bbid_start_index++;
00335 assert(_bbid_start_index<MAX_BB_ENTRY);
00336 }
00337
00338
00339
00340
00341
00342
00343 void BB_Edge_Profile::instrument_exit_op(legoProc *proc_ptr,legoRegion *region_ptr,legoOp *exit_op)
00344 {
00345 int exit_opcode=exit_op->GetOpcode();
00346 int s_time=exit_op->GetSchedTime();
00347 BEdb(1,"proc %s region_id %d",proc_ptr->GetProcName(),region_ptr->GetRegionId());
00348 BEdb(1,"exit_op %d %s",exit_op->GetOpId(),ParseMap(exit_opcode));
00349
00350
00351
00352
00353 if(exit_opcode!=DUMMY_BR)
00354 {
00355 legoOprd *exit_op_pred=exit_op->GetPredOprdPtr();
00356 assert(exit_op_pred!=NULL);
00357 assert(exit_op_pred->GetNextOprdPtr()==NULL);
00358 assert(exit_op_pred->GetOprdType()==OT_LITERAL_P && exit_op_pred->GetBooleanVal()==1);
00359 }
00360
00361
00362
00363 opList *out_list=exit_op->GetOutListPtr();
00364 assert(out_list!=NULL);
00365
00366 if(exit_opcode==DUMMY_BR || exit_opcode==BRU)
00367 {
00368
00369
00370
00371
00372
00373
00374
00375 if(out_list->GetNextListPtr()==NULL)
00376 {
00377 legoOp *to_op=out_list->GetOpPtr();
00378 int to_opid=to_op->GetOpId();
00379 BEdb(2,"to %d",to_opid);
00380
00381 edgeList *edge_list=find_edgeList_from_op_to_op(region_ptr,exit_op,to_op);
00382 assert(edge_list!=NULL);
00383 BEdb(3,"edge_id %d",edge_list->GetEdgeId());
00384
00385 Edge *e=_edge_table->find_edge(edge_list->GetEdgeId());
00386 BEdb(2,"%d\t%d\t%d\t%d\n",e->counter_index(),e->profile(),e->edge_id(),e->weight());
00387
00388 int path_mapping=e->counter_index();
00389
00390
00391
00392
00393
00394 _my_instrument.prepend_save_and_set_1_param_code(path_mapping,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00395 _my_instrument.prepend_pbrr_code(BB_EDGE_PROFILE_1_PROBE_NAME,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00396 _my_instrument.prepend_brl_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,1,s_time);
00397 _my_instrument.prepend_restore_1_param_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00398
00399 }
00400
00401
00402
00403
00404
00405
00406
00407 else
00408 {
00409 int exit_opid=exit_op->GetOpId();
00410 fprintf(stderr,"ERROR!!! proc %s region %d:\n",proc_ptr->GetProcName(),region_ptr->GetRegionId());
00411 fprintf(stderr,"exit_op %d %s has more than one out edges (switch statement)\n",exit_opid,ParseMap(exit_opcode));
00412
00413 int exit_op_region_id=region_ptr->GetRegionId();
00414 if(bbid_end_has_probe(exit_op_region_id)==0)
00415 {
00416 fprintf(stderr,"bb %d doesn't have end probe. Insert it.\n",exit_op_region_id);
00417
00418
00419
00420 bbid_end_insert(exit_op_region_id);
00421
00422
00423
00424
00425 int bbid_mapping=_bb_node_table->find(exit_op_region_id);
00426
00427 fprintf(stderr,"bbid_mapping=%d\n",bbid_mapping);
00428
00429
00430
00431 int end_mapping=bbid_mapping+100000;
00432
00433
00434
00435
00436
00437 _my_instrument.prepend_save_and_set_1_param_code(end_mapping,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00438 _my_instrument.prepend_pbrr_code(BB_EDGE_PROFILE_eND_PROBE_NAME,proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00439 _my_instrument.prepend_brl_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,1,s_time);
00440 _my_instrument.prepend_restore_1_param_code(proc_ptr,region_ptr,Predicate::true_predicate_oprd(),exit_op,s_time);
00441
00442 }
00443 else
00444 {
00445 fprintf(stderr,"bb %d has end probe already. Don't need to insert it.\n",exit_op_region_id);
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 }
00472 }
00473
00474
00475
00476 else if(exit_opcode==BRCT)
00477 {
00478 int to_opid1=-1,to_opid2=-1;
00479 Edge *e1=NULL,*e2=NULL;
00480
00481
00482
00483
00484 legoOp *to_op1=out_list->GetOpPtr();
00485 to_opid1=to_op1->GetOpId();
00486 BEdb(2,"1) to %d",to_opid1);
00487
00488 edgeList *edge_list1=find_edgeList_from_op_to_op(region_ptr,exit_op,to_op1);
00489
00490 if(edge_list1!=NULL)
00491 {
00492 BEdb(3,"1) edge_id %d",edge_list1->GetEdgeId());
00493
00494 e1=_edge_table->find_edge(edge_list1->GetEdgeId());
00495 BEdb(2,"1) %d\t%d\t%d\t%d\n",e1->counter_index(),e1->profile(),e1->edge_id(),e1->weight());
00496 }
00497
00498
00499
00500
00501
00502 out_list=out_list->GetNextListPtr();
00503 assert(out_list!=NULL);
00504 assert(out_list->GetNextListPtr()==NULL);
00505
00506 legoOp *to_op2=out_list->GetOpPtr();
00507 to_opid2=to_op2->GetOpId();
00508 BEdb(2,"2) to %d",to_opid2);
00509
00510 edgeList *edge_list2=find_edgeList_from_op_to_op(region_ptr,exit_op,to_op2);
00511 if(edge_list2!=NULL)
00512 {
00513 BEdb(3,"2) edge_id %d",edge_list2->GetEdgeId());
00514 e2=_edge_table->find_edge(edge_list2->GetEdgeId());
00515 BEdb(2,"2) %d\t%d\t%d\t%d\n",e2->counter_index(),e2->profile(),e2->edge_id(),e2->weight());
00516 }
00517
00518
00519
00520
00521
00522 legoOprd *branch_target_oprd=exit_op->GetSrcOprdPtr();
00523 legoOprd *predicate_oprd=branch_target_oprd->GetNextOprdPtr();
00524 assert(predicate_oprd->GetNextOprdPtr()==NULL);
00525
00526 assert(branch_target_oprd->GetOprdType()==OT_REG);
00527 assert(branch_target_oprd->GetOprdRegType()==RT_R);
00528 assert(branch_target_oprd->GetOprdFileType()==FT_BTR);
00529 assert(branch_target_oprd->GetOprdDataType()==DT_B);
00530 BEdb(2,"r<%d:b btr>",branch_target_oprd->GetOprdRegNum());
00531
00532 assert(predicate_oprd->GetOprdType()==OT_REG);
00533 assert(predicate_oprd->GetOprdDataType()==DT_P);
00534 assert(predicate_oprd->GetOprdFileType()==FT_PR);
00535 assert(predicate_oprd->GetOprdRegType()==RT_R);
00536 BEdb(2,"r<%d:p pr>",predicate_oprd->GetOprdRegNum());
00537
00538
00539
00540
00541 legoOp *pbrr_op;
00542
00543 for(pbrr_op=exit_op->GetPrevLink();pbrr_op!=NULL;pbrr_op=pbrr_op->GetPrevLink())
00544 {
00545 if(pbrr_op->GetOpcode()==PBRR)
00546 break;
00547 }
00548
00549 assert(pbrr_op!=NULL);
00550 legoOprd *dest_oprd=pbrr_op->GetDestOprdPtr();
00551 assert(dest_oprd->GetOprdType()==OT_REG);
00552 assert(dest_oprd->GetOprdRegType()==RT_R);
00553 assert(dest_oprd->GetOprdFileType()==FT_BTR);
00554 assert(dest_oprd->GetOprdDataType()==DT_B);
00555
00556 if(dest_oprd->GetOprdRegNum()!=branch_target_oprd->GetOprdRegNum())
00557 {
00558 assert(0);
00559 }
00560
00561 if(edge_list1!=NULL && edge_list2!=NULL)
00562 {
00563
00564
00565
00566 legoOprd *pbrr_src_oprd=pbrr_op->GetSrcOprdPtr();
00567 assert(pbrr_src_oprd->GetOprdType()==OT_LITERAL_CB);
00568 int pbrr_block_id=pbrr_src_oprd->GetLiteralControlBlock();
00569 BEdb(2,"pbrr_block_id=%d",pbrr_block_id);
00570
00571
00572
00573
00574 legoRegion *dest_region=find_lego_block_with_region_id(proc_ptr,pbrr_block_id);
00575 opList *dest_entry_op_list=dest_region->GetEntryOpsPtr();
00576 legoOp *dest_entry_op=dest_entry_op_list->GetOpPtr();
00577 int dest_entry_op_id=dest_entry_op->GetOpId();
00578 BEdb(2,"dest_entry_op_id=%d",dest_entry_op_id);
00579
00580
00581
00582
00583 int true_path_mapping=-1,false_path_mapping=-1;
00584 if(to_opid1==dest_entry_op_id)
00585 {
00586 true_path_mapping=e1->counter_index();
00587 false_path_mapping=e2->counter_index();
00588 }
00589 else if(to_opid2==dest_entry_op_id)
00590 {
00591 true_path_mapping=e2->counter_index();
00592 false_path_mapping=e1->counter_index();
00593 }
00594 else
00595 {
00596 assert(0);
00597 }
00598
00599
00600
00601
00602
00603 _my_instrument.prepend_3_probes(proc_ptr,region_ptr,predicate_oprd,true_path_mapping,false_path_mapping,Predicate::true_predicate_oprd(),exit_op,s_time);
00604
00605
00606 }
00607 else
00608 {
00609
00610
00611
00612 BEdb(2,"Hyperblock");
00613 int path_mapping;
00614
00615 if(e1!=NULL && e2==NULL)
00616 {
00617 path_mapping=e1->counter_index();
00618 }
00619 else if(e2!=NULL && e1==NULL)
00620 {
00621 path_mapping=e2->counter_index();
00622 }
00623 else
00624 {
00625 assert(0);
00626 }
00627
00628
00629
00630
00631
00632 _my_instrument.prepend_save_and_set_1_param_code(path_mapping,proc_ptr,region_ptr,predicate_oprd,exit_op,s_time);
00633 _my_instrument.prepend_pbrr_code(BB_EDGE_PROFILE_1_PROBE_NAME,proc_ptr,region_ptr,predicate_oprd,exit_op,s_time);
00634 _my_instrument.prepend_brl_code(proc_ptr,region_ptr,predicate_oprd,exit_op,1,s_time);
00635 _my_instrument.prepend_restore_1_param_code(proc_ptr,region_ptr,predicate_oprd,exit_op,s_time);
00636
00637
00638
00639 }
00640 }
00641 else if(exit_opcode==RTS)
00642 {
00643
00644 }
00645 else
00646 {
00647 assert(0);
00648 }
00649 }
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 void BB_Edge_Profile::open_header_file()
00824 {
00825 _header_fp=fopen(BB_EDGE_HEADER_FILENAME,"r");
00826
00827 if(_header_fp==NULL)
00828 {
00829 _header_fp=fopen(BB_EDGE_HEADER_FILENAME,"w");
00830 assert(_header_fp!=NULL);
00831
00832 fprintf(_header_fp," extern void MY_1_PRoBe (int);\n");
00833 fprintf(_header_fp," extern void MY_3_PRoBeS (int,int,int);\n");
00834 fprintf(_header_fp," extern void MY_BBiD_eND_PRoBe (int);\n");
00835 fprintf(_header_fp," extern void MY_BBiD_STaRT_PRoBe (int);\n");
00836 }
00837 }
00838
00839 void BB_Edge_Profile::close_header_file()
00840 {
00841 fclose(_header_fp);
00842 }
00843
00844 void BB_Edge_Profile::open_main_file(int bb_max_entry,int edge_max_entry)
00845 {
00846 _main_fp=fopen(BB_EDGE_MAIN_FILENAME,"w");
00847
00848 if(_main_fp==NULL)
00849 {
00850 fprintf(stderr,"Error open file:%s\n",BB_EDGE_MAIN_FILENAME);
00851 exit(0);
00852 }
00853
00854 fprintf(_main_fp,"/*\n\tFile: %s\n",BB_EDGE_MAIN_FILENAME);
00855 fprintf(_main_fp,"\tAuthor: Chao-ying Fu\n");
00856 fprintf(_main_fp,"\tDate: Aug. 28, 1998\n*/\n\n");
00857 fprintf(_main_fp,"#define bbid_max_entry %u\n",bb_max_entry);
00858 fprintf(_main_fp,"#define edge_max_entry %u\n\n",edge_max_entry);
00859
00860 fprintf(_main_fp,"#include <stdio.h>\n\n");
00861
00862 fprintf(_main_fp,"extern unsigned char global_macro_op[1024];\n");
00863 fprintf(_main_fp,"extern void MaiN(int argc,char **argv);\n");
00864 fprintf(_main_fp,"void MY_iNiT();\n");
00865 fprintf(_main_fp,"void MY_eXiT();\n\n");
00866
00867 fprintf(_main_fp,"int bbid_counter[bbid_max_entry];\n");
00868 fprintf(_main_fp,"int edge_counter[edge_max_entry];\n\n");
00869
00870 fprintf(_main_fp,"char bbid_counter_filename[13]=\"BBiD_CouNTeR\";\n");
00871 fprintf(_main_fp,"char edge_counter_filename[13]=\"eDGe_CouNTeR\";\n");
00872 fprintf(_main_fp,"char pair_counter_filename[13]=\"PaiR_CouNTeR\";\n");
00873 fprintf(_main_fp,"FILE *bbid_counter_fp=NULL;\n");
00874 fprintf(_main_fp,"FILE *edge_counter_fp=NULL;\n");
00875 fprintf(_main_fp,"FILE *pair_counter_fp=NULL;\n");
00876 fprintf(_main_fp,"int bb1; // for bb end probe\n");
00877 fprintf(_main_fp,"int bb2; // for bb start probe\n");
00878 fprintf(_main_fp,"int number_of_pair;\n");
00879 fprintf(_main_fp,"#define MAX_EDGE_NUMBER 10000\n\n");
00880
00881 fprintf(_main_fp,"struct Edge_Entry\n");
00882 fprintf(_main_fp,"{\n");
00883 fprintf(_main_fp," int bb1;\n");
00884 fprintf(_main_fp," int bb2;\n");
00885 fprintf(_main_fp," int counter;\n");
00886 fprintf(_main_fp," struct Edge_Entry *next;\n");
00887 fprintf(_main_fp,"} edge_entry[MAX_EDGE_NUMBER];\n\n");
00888
00889 fprintf(_main_fp,"int main(int argc,char **argv)\n");
00890 fprintf(_main_fp,"{\n");
00891 fprintf(_main_fp," MY_iNiT();\n");
00892 fprintf(_main_fp," atexit(MY_eXiT);\n");
00893 fprintf(_main_fp," MaiN(argc,argv);\n");
00894 fprintf(_main_fp,"}\n\n");
00895
00896 fprintf(_main_fp,"void MY_iNiT()\n");
00897 fprintf(_main_fp,"{\n");
00898 fprintf(_main_fp," int i;\n");
00899 fprintf(_main_fp," struct Edge_Entry *ee;\n");
00900 fprintf(_main_fp," for(i=0;i<bbid_max_entry;i++)\n");
00901 fprintf(_main_fp," {\n");
00902 fprintf(_main_fp," bbid_counter[i]=0;\n");
00903 fprintf(_main_fp," }\n");
00904 fprintf(_main_fp," for(i=0;i<edge_max_entry;i++)\n");
00905 fprintf(_main_fp," {\n");
00906 fprintf(_main_fp," edge_counter[i]=0;\n");
00907 fprintf(_main_fp," }\n");
00908 fprintf(_main_fp," bbid_counter_fp=fopen(bbid_counter_filename,\"w\");\n");
00909 fprintf(_main_fp," if(bbid_counter_fp==NULL)\n");
00910 fprintf(_main_fp," {\n");
00911 fprintf(_main_fp," fprintf(stderr,\"Error Open File:%%s\\n\",bbid_counter_filename);\n");
00912 fprintf(_main_fp," exit(0);\n");
00913 fprintf(_main_fp," }\n");
00914 fprintf(_main_fp," edge_counter_fp=fopen(edge_counter_filename,\"w\");\n");
00915 fprintf(_main_fp," if(edge_counter_fp==NULL)\n");
00916 fprintf(_main_fp," {\n");
00917 fprintf(_main_fp," fprintf(stderr,\"Error Open File:%%s\\n\",edge_counter_filename);\n");
00918 fprintf(_main_fp," exit(0);\n");
00919 fprintf(_main_fp," }\n");
00920 fprintf(_main_fp," pair_counter_fp=fopen(pair_counter_filename,\"w\");\n");
00921 fprintf(_main_fp," if(pair_counter_fp==NULL)\n");
00922 fprintf(_main_fp," {\n");
00923 fprintf(_main_fp," fprintf(stderr,\"Error Open File:%%s\\n\",pair_counter_filename);\n");
00924 fprintf(_main_fp," exit(0);\n");
00925 fprintf(_main_fp," }\n");
00926 fprintf(_main_fp," bb1=-1;\n");
00927 fprintf(_main_fp," bb2=-1;\n");
00928 fprintf(_main_fp," for(i=0;i<MAX_EDGE_NUMBER;i++)\n");
00929 fprintf(_main_fp," {\n");
00930 fprintf(_main_fp," ee=&edge_entry[i];\n");
00931 fprintf(_main_fp," ee->bb1=-1;\n");
00932 fprintf(_main_fp," ee->next=NULL;\n");
00933 fprintf(_main_fp," }\n");
00934 fprintf(_main_fp," number_of_pair=0;\n");
00935 fprintf(_main_fp,"}\n\n");
00936
00937 fprintf(_main_fp,"void MY_eXiT()\n");
00938 fprintf(_main_fp,"{\n");
00939 fprintf(_main_fp," struct Edge_Entry *ee;\n");
00940 fprintf(_main_fp," int i;\n");
00941 fprintf(_main_fp," for(i=0;i<bbid_max_entry;i++)\n");
00942 fprintf(_main_fp," {\n");
00943 fprintf(_main_fp," fprintf(bbid_counter_fp,\"%%d %%d\\n\",i,bbid_counter[i]);\n");
00944 fprintf(_main_fp," }\n");
00945 fprintf(_main_fp," fclose(bbid_counter_fp);\n");
00946 fprintf(_main_fp," for(i=0;i<edge_max_entry;i++)\n");
00947 fprintf(_main_fp," {\n");
00948 fprintf(_main_fp," fprintf(edge_counter_fp,\"%%d %%d\\n\",i,edge_counter[i]);\n");
00949 fprintf(_main_fp," }\n");
00950 fprintf(_main_fp," fclose(edge_counter_fp);\n");
00951 fprintf(_main_fp," fprintf(pair_counter_fp,\"number_of_pair=%%d\\n\",number_of_pair);\n");
00952 fprintf(_main_fp," for(i=0;i<MAX_EDGE_NUMBER;i++)\n");
00953 fprintf(_main_fp," {\n");
00954 fprintf(_main_fp," ee=&edge_entry[i];\n");
00955 fprintf(_main_fp," if(ee->bb1!=-1)\n");
00956 fprintf(_main_fp," {\n");
00957 fprintf(_main_fp," do\n");
00958 fprintf(_main_fp," {\n");
00959 fprintf(_main_fp," fprintf(pair_counter_fp,\"(%%d,%%d):%%d\\n\",ee->bb1,ee->bb2,ee->counter);\n");
00960 fprintf(_main_fp," ee=ee->next;\n");
00961 fprintf(_main_fp," }\n");
00962 fprintf(_main_fp," while(ee!=NULL);\n");
00963 fprintf(_main_fp," }\n");
00964 fprintf(_main_fp," }\n");
00965 fprintf(_main_fp," fclose(pair_counter_fp);\n");
00966 fprintf(_main_fp,"}\n\n");
00967
00968 fprintf(_main_fp,"void MY_1_PRoBe(int mapping)\n");
00969 fprintf(_main_fp,"{\n");
00970 fprintf(_main_fp," edge_counter[mapping]++;\n");
00971 fprintf(_main_fp,"}\n\n");
00972
00973 fprintf(_main_fp,"void MY_3_PRoBeS(int predicate,int true_path_mapping,int false_path_mapping)\n");
00974 fprintf(_main_fp,"{\n");
00975 fprintf(_main_fp," if(predicate==1)\n");
00976 fprintf(_main_fp," {\n");
00977 fprintf(_main_fp," edge_counter[true_path_mapping]++;\n");
00978 fprintf(_main_fp," }\n");
00979 fprintf(_main_fp," else if(predicate==0)\n");
00980 fprintf(_main_fp," {\n");
00981 fprintf(_main_fp," edge_counter[false_path_mapping]++;\n");
00982 fprintf(_main_fp," }\n");
00983 fprintf(_main_fp," else\n");
00984 fprintf(_main_fp," {\n");
00985 fprintf(_main_fp," fprintf(stderr,\"ERROR! predicate %%d\\n\",predicate);\n");
00986 fprintf(_main_fp," exit(0);\n");
00987 fprintf(_main_fp," }\n");
00988 fprintf(_main_fp,"}\n\n");
00989
00990 fprintf(_main_fp,"void MY_BBiD_eND_PRoBe(int mapping)\n");
00991 fprintf(_main_fp,"{\n");
00992 fprintf(_main_fp," bb1=mapping;\n");
00993 fprintf(_main_fp,"}\n\n");
00994
00995 fprintf(_main_fp,"void MY_BBiD_STaRT_PRoBe(int mapping)\n");
00996 fprintf(_main_fp,"{\n");
00997 fprintf(_main_fp," struct Edge_Entry *ee,*last_ee;\n");
00998 fprintf(_main_fp," int index;\n");
00999 fprintf(_main_fp," bbid_counter[mapping]++;\n");
01000 fprintf(_main_fp," bb2=mapping;\n");
01001 fprintf(_main_fp," if(bb1>=100000)\n");
01002 fprintf(_main_fp," {\n");
01003 fprintf(_main_fp," bb1=bb1-100000;\n");
01004 fprintf(_main_fp," index=(bb1+bb2)%%MAX_EDGE_NUMBER;\n");
01005 fprintf(_main_fp," ee=&edge_entry[index];\n");
01006 fprintf(_main_fp," //\n");
01007 fprintf(_main_fp," // Search (bb1,bb2)\n");
01008 fprintf(_main_fp," //\n");
01009 fprintf(_main_fp," if(ee->bb1==-1)\n");
01010 fprintf(_main_fp," {\n");
01011 fprintf(_main_fp," //\n");
01012 fprintf(_main_fp," // not match, put it to this ee\n");
01013 fprintf(_main_fp," //\n");
01014 fprintf(_main_fp," ee->bb1=bb1;\n");
01015 fprintf(_main_fp," ee->bb2=bb2;\n");
01016 fprintf(_main_fp," ee->counter=1;\n");
01017 fprintf(_main_fp," number_of_pair++;\n");
01018 fprintf(_main_fp," }\n");
01019 fprintf(_main_fp," else if(ee->bb1==bb1 && ee->bb2==bb2)\n");
01020 fprintf(_main_fp," {\n");
01021 fprintf(_main_fp," // match, increment\n");
01022 fprintf(_main_fp," ee->counter++;\n");
01023 fprintf(_main_fp," }\n");
01024 fprintf(_main_fp," else\n");
01025 fprintf(_main_fp," {\n");
01026 fprintf(_main_fp," // search bucket\n");
01027 fprintf(_main_fp," last_ee=ee;\n");
01028 fprintf(_main_fp," ee=ee->next;\n");
01029 fprintf(_main_fp," while(ee!=NULL)\n");
01030 fprintf(_main_fp," {\n");
01031 fprintf(_main_fp," if(ee->bb1==bb1 && ee->bb2==bb2)\n");
01032 fprintf(_main_fp," break;\n");
01033 fprintf(_main_fp," last_ee=ee;\n");
01034 fprintf(_main_fp," ee=ee->next;\n");
01035 fprintf(_main_fp," }\n");
01036 fprintf(_main_fp," if(ee!=NULL)\n");
01037 fprintf(_main_fp," {\n");
01038 fprintf(_main_fp," // match\n");
01039 fprintf(_main_fp," ee->counter++;\n");
01040 fprintf(_main_fp," }\n");
01041 fprintf(_main_fp," else\n");
01042 fprintf(_main_fp," {\n");
01043 fprintf(_main_fp," // create new ee\n");
01044 fprintf(_main_fp," ee=(struct Edge_Entry *)malloc(sizeof(struct Edge_Entry));\n");
01045 fprintf(_main_fp," last_ee->next=ee;\n");
01046 fprintf(_main_fp," ee->bb1=bb1;\n");
01047 fprintf(_main_fp," ee->bb2=bb2;\n");
01048 fprintf(_main_fp," ee->counter=1;\n");
01049 fprintf(_main_fp," ee->next=NULL;\n");
01050 fprintf(_main_fp," // increment number_of_pair\n");
01051 fprintf(_main_fp," number_of_pair++;\n");
01052 fprintf(_main_fp," }\n");
01053 fprintf(_main_fp," }\n");
01054 fprintf(_main_fp," // Reset bb1\n");
01055 fprintf(_main_fp," bb1=-1;\n");
01056 fprintf(_main_fp," }\n");
01057 fprintf(_main_fp,"}\n");
01058 }
01059
01060 void BB_Edge_Profile::close_main_file()
01061 {
01062 fclose(_main_fp);
01063 }