Java Reference
In-Depth Information
r i
1
while r i N do
r j
1
while r j N do
r A
( Addr ( A )
+
((( r i
1)
× N +
( r j
1)))
×
4)
( r a )
0
r k
1
r sum ←−
while r k N do
r A
( Addr ( A )
+
((( r i
1)
× N +
( r j
1)))
×
4)
9
r B
( Addr ( B )
+
((( r i
1)
× N +
( r k
1)))
×
4)
r C
( Addr ( C )
+
((( r k
1)
× N +
( r j
1)))
×
4)
r sum r A
r prod r B × r C
r sum r sum + r prod
r A
( Addr ( A )
+
((( i
1)
× N +
( j
1)))
×
4)
10
r sum
r k r k +
( r a )
1
k r k
r j r j +
11
1
j r j
r i r i +
12
1
i r i
13
Figure 14.4: Low-level code sequence. The
operator denotes
indirection:
x causes its operand x to be evaluated and then
treated as an address.
Artifacts of Program Translation
In the process of translating a program from a source to a target language,
compilers can introduce spurious computations. As discussed in Chapter 13,
compilers try to keep frequently accessed variables in fast registers. For exam-
ple, it is likely that the iteration variables in Figure 14.3 are kept in registers.
Figure 14.4 shows the results of straightforward code generation for the loops
in Figure 14.3.
The loops contain instructions at Markers 11 , 12 ,and 13 that store the
iteration variable register in the named variable. However, this particular
programdoes not require a value for the iteration variables when the loops are
finished. Thus, such stores are unnecessary. In Chapter 13, register allocation
can avoid such saves if the iteration variable can be allocated a register without
spilling.
Because code generation is mechanically invoked for each program ele-
Search WWH ::




Custom Search