This is the mail archive of the
dwarf2@corp.sgi.com
mailing list for the dwarf2 project.
Re: Re: Modifies vs. Replaces
- To: DWARF2 at corp dot sgi dot com, BRENDER at gemgrp dot zko dot dec dot com
- Subject: Re: Re: Modifies vs. Replaces
- From: brender at gemgrp dot zko dot dec dot com (Ron 603-884-2088)
- Date: Tue, 27 Mar 2001 16:56:50 -0500
- Reply-To: brender at gemgrp dot zko dot dec dot com (Ron 603-884-2088)
Michael Eager wrote:
>If Compaq's compilers generate code which has lifetime holes for
>global variables, could you provide a reasonable example? Perhaps
>with both the source and assembly code for the example?
Following is a compilation listing that should illustrate lifetime holes
for global variables.
Lines begining with ">>>" are annotations that I added to help explain
what is going on in the code.
I believe everything shown is consistent with what Jim Denhert described
(and what I was trying to describe, perhaps less well).
The listing is 132-columns wide...
Source Listing 27-Mar-2001 16:26:20 Compaq C++ X6.3-221-48B3R Page 1
27-Mar-2001 16:17:12 global-holes.c
1
2 int i, j, k, l;
3
4 extern void init(void);
5 extern void doprint(void);
6
7 main(void) {
8
9 init();
10
11 k = i + 1;
12 j = k/2;
13 j = i + k;
14 l = k * 5;
15
16 doprint();
17 }
18
Machine Code Listing 27-Mar-2001 16:26:20 Compaq C++ X6.3-221-48B3R Page 2
main 27-Mar-2001 16:17:12 global-holes.c
.globl main
.ent main
0000 main:
27BB0000 0000 ldah gp, main # gp, (r27)
23BD0000 0004 lda gp, main # gp, (gp)
0008 L$2:
23DEFFF0 0008 lda sp, -16(sp)
B75E0000 000C stq r26, (sp)
.mask 0x04000000,-16
.fmask 0x00000000,0
.frame $sp, 16, $26
.prologue 1
>>>
>>> All prologue up to here
>>>
A77D0000 0010 ldq r27, init__Xv # r27, (gp) # 000009
6B5B4000 0014 jsr r26, init__Xv # r26, (r27)
>>>
>>> Load the address of init from the GOT and call it
>>>
27BA0000 0018 ldah gp, main # gp, (r26)
23BD0000 001C lda gp, main # gp, (gp)
>>>
>>> Restablish local got pointer
>>>
A41D0000 0020 ldq r0, i # r0, (gp) # 000011
A4FD0000 0024 ldq r7, j # r7, (gp) # 000013
A4DD0000 0028 ldq r6, l # r6, (gp) # 000014
A47D0000 002C ldq r3, k # r3, (gp) # 000011
>>>
>>> Load the addresses of i, j, k, and l respectively from the GOT
>>>
A77D0000 0030 ldq r27, doprint__Xv # r27, (gp) # 000016
>>>
>>> Load the address of doprint from the GOT
>>>
A0200000 0034 ldl r1, i # r1, (r0) # 000011
>>>
>>> Load value of i into r1
>>>
40203002 0038 addl r1, 1, r2
>>>
>>> Add 1 to the value of i and store it in k
>>> At this point r2 is *the* location of k; the global location is irrelevant for a while
>>>
40220001 003C addl r1, r2, r1 # 000013
>>>
>>> Add the value of i (from r1) to the value of k (from r2) and store result in j (using r1 for a new purpose)
>>> At this point r1 is *the* location of j; the global location is irrelevant for a while
>>>
>>> Note that the first assignment to j (line 12) is dead and optimized away
>>> Also, the copy of i previously in r1 is no longer of interest
>>>
40420045 0040 s4addl r2, r2, r5 # 000014
>>>
>>> Multiply the value of k (from r2) by 5 (using scale by 2 and add of itself) and store result in l (in r5)
>>> At this point r5 is *the* location of l; the global location is irrelevant
>>>
B0430000 0044 stl r2, k # r2, (r3) # 000011
B0270000 0048 stl r1, j # r1, (r7) # 000013
B0A60000 004C stl r5, l # r5, (r6) # 000014
>>>
>>> Copy the values of k, j, and l back to their global locations
>>>
6B5B4000 0050 jsr r26, doprint__Xv # r26, (r27) # 000016
>>>
>>> Call doprint
>>>
27BA0000 0054 ldah gp, main # gp, (r26)
A75E0000 0058 ldq r26, (sp) # 000017
23DE0010 005C lda sp, 16(sp)
47FF0400 0060 clr r0
23BD0000 0064 lda gp, main # gp, (gp) # 000016
6BFA8001 0068 ret (r26) # 000017
>>>
>>> Restore gp pointer for main, tear down the stack and return
>>>
.end main
Routine Size: 108 bytes, Routine Base: .text + 0000
.comm i 4
.comm j 4
.comm k 4
.comm l 4