[Coins-compiler-users] Basic Block Profiler

Back to archive index

Daniel Shapiro dcsha****@gmail*****
2009年 1月 27日 (火) 23:13:45 JST


Hi,

Thank you. This is exactly what I need. I'm trying to get this solution to
work, but I'm getting an error from cygwin:

Warning 3333: /usr/include/stdio.h 516: function '__sgetc_r' is defined
though declared 'extern'
C:\DOCUME~1\DCSHAP~1\LOCALS~1\Temp\COINS61531.tmp:fake:(.text+0x0): multiple
definition of `___sgetc_r'
fft\profile.o:fake:(.text+0x0): first defined here
collect2: ld returned 1 exit status

Any ideas? I looked in the cygwin forums and it seems that this is a linker
error. Perhaps someone also has this error for the debugger?

Thanks.

On Tue, Jan 27, 2009 at 3:23 AM, Tan Watanabe <tan****@watan*****> wrote:

> Hi,
>
> When coins option "debuginfo" is specified as in this case, the internal
> representation
> LIR carries LINE number showing the correspondence of each LIR expression
> and source program.
> By making a small program, you can get the execution count of each basic
> block.
>
> At 23:51 09/01/26, you wrote:
>
>> Hi,
>>
>> I've tried out this solution, and it seems to bind execution counts to
>> line numbers. Is there a quick way to find out the link between basic block
>> numbers and execution count?
>>
>> Thanks,
>>
>> On Sun, Jan 25, 2009 at 1:27 PM, Daniel Shapiro <<mailto:
>> dcsha****@gmail*****>dcsha****@gmail*****> wrote:
>> Thank you. I will try it out and let you know how it goes. We were using
>> MinGW, so I guess we'll switch to cygwin.
>>
>>
>> On Fri, Jan 23, 2009 at 8:27 PM, Tan Watanabe <<mailto:tan****@watan*****
>> >tan****@watan*****> wrote:
>> Thank you for using COINS.
>>
>> In COINS, there is a profiler that output execution count of all
>> executable statements.
>>
>> How to use it in Windows-cygwin:
>>
>>  (1) Add
>>     __flush_profile();
>>   as the last statement to be executed in main().
>>
>>  (2) Execute following command sequence to make executable module
>>    for profiling assuming foo.c as the program to be profiled.
>>
>>   $(COINSCC) -c -coins:debuginfo,profile,target=x86-cygwin,assembler=as
>> foo.c
>>   ./gen-profile-data-cygwin.pl foo.c  > profile_data.c
>>   $(COINSCC) -c -coins:target=x86-cygwin,assembler=as flush_profile.c
>>   $(COINSCC) -coins:target=x86-cygwin,assembler=as foo.o flush_profile.c
>>
>>   where, $(COINSCC) represents the fragment of a command
>>   to execute coins.driver.Driver.
>>
>
> You can confirm the LINE information in LIR by adding
>    trace=LIR to the first command in such way as
>
>    $(COINSCC) -c
> -coins:debuginfo,profile,target=x86-cygwin,assembler=as,trace=LIR foo.c
> > foo.lir.txt
>
> For a source program (with execution count)
>
>   1:         /* tpprime2.c: Get 100 prime numbers (call _flush_profile())
> */
>   2:
>   3:          int printf(char*, ...);
>   4:          int candidat, quotient, remaindr, index, nth, primenum,
> loopend ;
>   5:          int primeNumbers[1000] ;
>   6:
>   7:       1 void getPrime(int primevec[1000], int count)
>   8:         {
>   9:       1  primevec[0] = 2 ;
>  10:       1  nth = 1 ;
>  11:       1  candidat = 3 ;
>  12:       1  while (nth<count) {
>  13:     270    remaindr = 1 ;
>  14:     270    index = 0 ;
>  15:     270    loopend = 0 ;
>  16:     270    while(loopend==0) {
>  17:    1180      primenum = primevec[index] ;
>  18:    1180      quotient = candidat / primenum ;
>  19:    1180      remaindr = candidat - quotient*primenum ;
>  20:    1180      if (remaindr==0)
>  21:     171        loopend = 1 ;
>  22:    1180      if (quotient*quotient<candidat)
>  23:      99        loopend = 1 ;
>  24:    1180      index = index + 1 ;
>  25:    1180      if (index>=nth)
>  26:       1        loopend = 1 ;
>  27:            }
>  28:     270    if (remaindr != 0) {
>  29:      99      primevec[nth] = candidat ;
>  30:      99      nth = nth + 1 ;
>  31:            }
>  32:     270    candidat = candidat + 2 ;
>  33:          }
>  34:       1  nth   = 0 ;
>  35:       1  while (nth<count) {
>  36:     100    printf(" %d", primevec[nth]) ;
>  37:     100    nth   = nth + 1 ;
>  38:          }
>  39:       1  return;
>  40:         }
>  41:
>  42:       1 int main()
>  43:         {
>  44:       1  int n = 100;  /* n <= 1000 */
>  45:       1  printf("Get %d prime numbers \n", n) ;
>  46:       1  primeNumbers[0] = 2 ;
>  47:       1  getPrime(primeNumbers, n);
>  48:       1  printf("\n");
>  49:       1  __flush_profile();
>  50:       1  return 0;
>  51:         }
>  52:
>
> the LIR corresponding to it is devided into basic blocks and each basic
> block
> has LINE information as follows:
>
>
> Function "getPrime":
>
>  Local Symbol table:
>
>  ("primevec.1" FRAME I32 4 0 &syminfo "getPrime_primevec" "tpprime2.c" 7 0)
>
>  ("count.2" FRAME I32 4 0 &syminfo "getPrime_count" "tpprime2.c" 7 0)
>
>  ("functionvalue.4" FRAME I32 4 0)
>
>
>
>  Control Flow Graph:
>
>
>
>  #1 Basic Block (.L1): DFN=(1,1), <-() ->(#2)
>
>    (PROLOGUE (0 0) (MEM I32 (FRAME I32 "primevec.1") &id ("primevec.1" 0))
> (MEM I32 (FRAME I32 "count.2") &id ("count.2" 1)))
>
>    (JUMP (LABEL I32 ".L2"))
>
>
>
>  #2 Basic Block (.L2): DFN=(2,2), parent=#1, <-(#1) ->(#3)
>
>    (LINE 7)
>
>    (LINE 9)
>
>    (SET I32 (MEM I32 (ADD I32 (MEM I32 (FRAME I32 "primevec.1") &id
> ("primevec.1" 2)) (MUL I32 (INTCONST I32 0) (INTCONST I32 4))) &id 3)
> (INTCONST I32 2))
>
>    (LINE 10)
>
>    (SET I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 4)) (INTCONST I32 1))
>
>    (LINE 11)
>
>    (SET I32 (MEM I32 (STATIC I32 "candidat") &id ("candidat" 5)) (INTCONST
> I32 3))
>
>    (LINE 12)
>
>    (JUMP (LABEL I32 ".L3"))
>
>
>
>  #3 Basic Block (.L3): DFN=(3,3), parent=#2, <-(#2,#15) ->(#4,#16)
>
>    (JUMPC (TSTLTS I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 6)) (MEM I32
> (FRAME I32 "count.2") &id ("count.2" 7))) (LABEL I32 ".L4") (LABEL I32
> ".L16"))
>
>
>
>  #4 Basic Block (.L4): DFN=(4,9), parent=#3, <-(#3) ->(#5)
>
>    (LINE 13)
>
>    (SET I32 (MEM I32 (STATIC I32 "remaindr") &id ("remaindr" 8)) (INTCONST
> I32 1))
>
>    (LINE 14)
>
>    (SET I32 (MEM I32 (STATIC I32 "index") &id ("index" 9)) (INTCONST I32
> 0))
>
>    (LINE 15)
>
>    (SET I32 (MEM I32 (STATIC I32 "loopend") &id ("loopend" 10)) (INTCONST
> I32 0))
>
>    (LINE 16)
>
>    (JUMP (LABEL I32 ".L5"))
>
>
>
>  #5 Basic Block (.L5): DFN=(5,10), parent=#4, <-(#4,#12) ->(#6,#13)
>
>    (JUMPC (TSTEQ I32 (MEM I32 (STATIC I32 "loopend") &id ("loopend" 11))
> (INTCONST I32 0)) (LABEL I32 ".L6") (LABEL I32 ".L13"))
>
>
>
>  #6 Basic Block (.L6): DFN=(6,14), parent=#5, <-(#5) ->(#7,#8)
>
>    (LINE 17)
>
>    (SET I32 (MEM I32 (STATIC I32 "primenum") &id ("primenum" 15)) (MEM I32
> (ADD I32 (MEM I32 (FRAME I32 "primevec.1") &id ("primevec.1" 12)) (MUL I32
> (MEM I32 (STATIC I32 "index") &id ("index" 13)) (INTCONST I32 4))) &id 14))
>
>    (LINE 18)
>
>    (SET I32 (MEM I32 (STATIC I32 "quotient") &id ("quotient" 18)) (DIVS I32
> (MEM I32 (STATIC I32 "candidat") &id ("candidat" 16)) (MEM I32 (STATIC I32
> "primenum") &id ("primenum" 17))))
>
>    (LINE 19)
>
>    (SET I32 (MEM I32 (STATIC I32 "remaindr") &id ("remaindr" 22)) (SUB I32
> (MEM I32 (STATIC I32 "candidat") &id ("candidat" 19)) (MUL I32 (MEM I32
> (STATIC I32 "quotient") &id ("quotient" 20)) (MEM I32 (STATIC I32
> "primenum") &id ("primenum" 21)))))
>
>    (LINE 20)
>
>    (JUMPC (TSTEQ I32 (MEM I32 (STATIC I32 "remaindr") &id ("remaindr" 23))
> (INTCONST I32 0)) (LABEL I32 ".L7") (LABEL I32 ".L8"))
>
>
>
>  #7 Basic Block (.L7): DFN=(7,15), parent=#6, <-(#6) ->(#8)
>
>    (LINE 21)
>
>    (SET I32 (MEM I32 (STATIC I32 "loopend") &id ("loopend" 24)) (INTCONST
> I32 1))
>
>    (JUMP (LABEL I32 ".L8"))
>
>
>
>  #8 Basic Block (.L8): DFN=(8,16), parent=#7, <-(#6,#7) ->(#9,#10)
>
>    (LINE 22)
>
>    (JUMPC (TSTLTS I32 (MUL I32 (MEM I32 (STATIC I32 "quotient") &id
> ("quotient" 25)) (MEM I32 (STATIC I32 "quotient") &id ("quotient" 26))) (MEM
> I32 (STATIC I32 "candidat") &id ("candidat" 27))) (LABEL I32 ".L9") (LABEL
> I32 ".L10"))
>
>
>
>  #9 Basic Block (.L9): DFN=(9,17), parent=#8, <-(#8) ->(#10)
>
>    (LINE 23)
>
>    (SET I32 (MEM I32 (STATIC I32 "loopend") &id ("loopend" 28)) (INTCONST
> I32 1))
>
>    (JUMP (LABEL I32 ".L10"))
>
>
>
>  #10 Basic Block (.L10): DFN=(10,18), parent=#9, <-(#8,#9) ->(#11,#12)
>
>    (LINE 24)
>
>    (SET I32 (MEM I32 (STATIC I32 "index") &id ("index" 30)) (ADD I32 (MEM
> I32 (STATIC I32 "index") &id ("index" 29)) (INTCONST I32 1)))
>
>    (LINE 25)
>
>    (JUMPC (TSTGES I32 (MEM I32 (STATIC I32 "index") &id ("index" 31)) (MEM
> I32 (STATIC I32 "nth") &id ("nth" 32))) (LABEL I32 ".L11") (LABEL I32
> ".L12"))
>
>
>
>  #11 Basic Block (.L11): DFN=(11,19), parent=#10, <-(#10) ->(#12)
>
>    (LINE 26)
>
>    (SET I32 (MEM I32 (STATIC I32 "loopend") &id ("loopend" 33)) (INTCONST
> I32 1))
>
>    (JUMP (LABEL I32 ".L12"))
>
>
>
>  #12 Basic Block (.L12): DFN=(12,20), parent=#11, <-(#10,#11) ->(#5)
>
>    (JUMP (LABEL I32 ".L5"))
>
>
>
>  #13 Basic Block (.L13): DFN=(13,11), parent=#5, <-(#5) ->(#14,#15)
>
>    (LINE 28)
>
>    (JUMPC (TSTNE I32 (MEM I32 (STATIC I32 "remaindr") &id ("remaindr" 34))
> (INTCONST I32 0)) (LABEL I32 ".L14") (LABEL I32 ".L15"))
>
>
>
>  #14 Basic Block (.L14): DFN=(14,12), parent=#13, <-(#13) ->(#15)
>
>    (LINE 29)
>
>    (SET I32 (MEM I32 (ADD I32 (MEM I32 (FRAME I32 "primevec.1") &id
> ("primevec.1" 36)) (MUL I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 37))
> (INTCONST I32 4))) &id 38) (MEM I32 (STATIC I32 "candidat") &id ("candidat"
> 35)))
>
>    (LINE 30)
>
>    (SET I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 40)) (ADD I32 (MEM I32
> (STATIC I32 "nth") &id ("nth" 39)) (INTCONST I32 1)))
>
>    (JUMP (LABEL I32 ".L15"))
>
>
>
>  #15 Basic Block (.L15): DFN=(15,13), parent=#14, <-(#13,#14) ->(#3)
>
>    (LINE 32)
>
>    (SET I32 (MEM I32 (STATIC I32 "candidat") &id ("candidat" 42)) (ADD I32
> (MEM I32 (STATIC I32 "candidat") &id ("candidat" 41)) (INTCONST I32 2)))
>
>    (JUMP (LABEL I32 ".L3"))
>
>
>
>  #16 Basic Block (.L16): DFN=(16,4), parent=#3, <-(#3) ->(#17)
>
>    (LINE 34)
>
>    (SET I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 43)) (INTCONST I32 0))
>
>    (LINE 35)
>
>    (JUMP (LABEL I32 ".L17"))
>
>
>
>  #17 Basic Block (.L17): DFN=(17,5), parent=#16, <-(#16,#18) ->(#18,#19)
>
>    (JUMPC (TSTLTS I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 44)) (MEM I32
> (FRAME I32 "count.2") &id ("count.2" 45))) (LABEL I32 ".L18") (LABEL I32
> ".L19"))
>
>
>
>  #18 Basic Block (.L18): DFN=(18,8), parent=#17, <-(#17) ->(#17)
>
>    (LINE 36)
>
>    (CALL (STATIC I32 "printf") ((STATIC I32 "string.5") (MEM I32 (ADD I32
> (MEM I32 (FRAME I32 "primevec.1") &id ("primevec.1" 46)) (MUL I32 (MEM I32
> (STATIC I32 "nth") &id ("nth" 47)) (INTCONST I32 4))) &id 48)) ((MEM I32
> (FRAME I32 "functionvalue.4") &id ("functionvalue.4" 49))) &id ("printf"
> 50))
>
>    (LINE 37)
>
>    (SET I32 (MEM I32 (STATIC I32 "nth") &id ("nth" 52)) (ADD I32 (MEM I32
> (STATIC I32 "nth") &id ("nth" 51)) (INTCONST I32 1)))
>
>    (JUMP (LABEL I32 ".L17"))
>
>
>
>  #19 Basic Block (.L19): DFN=(19,6), parent=#17, <-(#17) ->(#20)
>
>    (LINE 39)
>
>    (JUMP (LABEL I32 ".L20"))
>
>
>
>  #20 Basic Block (.L20): DFN=(20,7), parent=#19, <-(#19) ->()
>
>    (EPILOGUE (0 0))
>
> End Function
>
>
>   (3) Execute following command sequence to output the profile data.
>>
>>   ./a.out                     // not a.exe
>>   ./prof-list-cygwin.pl foo.c
>>
>> On Sparc, replace
>>  gen-profile-data-cygwin.pl with gen-profile-data.pl
>>  prof-list-cygwin.pl with prof-list.pl
>> and eraze target=x86-cygwin.
>>
>
> Tan Watanabe <tan****@watan*****>
>



-- 
Daniel Shapiro, B.A.Sc ., M.A.Sc. (Candidate)

School of Information Technology and Engineering (SITE), University of
Ottawa
Tel: (613) 562-5800 ext. 2189
Office: SITE4009
Email: dshap092 -at- site.uottawa.ca
Website: site.uottawa.ca/~dshap092/
Research Group: carg.site.uottawa.ca/
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



Coins-compiler-users メーリングリストの案内
Back to archive index