Made to work with troff
This commit is contained in:
@@ -16,13 +16,16 @@ done by the EM Peephole Optimizer.
|
||||
Strength reduction can also be applied
|
||||
more generally to operators used in a loop.
|
||||
.DS
|
||||
i := 1; i := 1;
|
||||
while i < 100 loop --> TMP := i * 118;
|
||||
put(i * 118); while i < 100 loop
|
||||
i := i + 1; put(TMP);
|
||||
end loop; i := i + 1;
|
||||
TMP := TMP + 118;
|
||||
end loop;
|
||||
.TS
|
||||
l l.
|
||||
i := 1; i := 1;
|
||||
while i < 100 loop\ \ \ \ \ \ \ --> TMP := i * 118;
|
||||
put(i * 118); while i < 100 loop
|
||||
i := i + 1; put(TMP);
|
||||
end loop; i := i + 1;
|
||||
TMP := TMP + 118;
|
||||
end loop;
|
||||
.TE
|
||||
|
||||
Fig. 6.1 An example of Strenght Reduction
|
||||
.DE
|
||||
|
||||
@@ -105,11 +105,11 @@ iv_expression * constant
|
||||
.IP (2)
|
||||
constant * iv_expression
|
||||
.IP (3)
|
||||
A[iv-expression] := (assign to array element)
|
||||
A[iv-expression] := \kx(assign to array element)
|
||||
.IP (4)
|
||||
A[iv-expression] (use array element)
|
||||
A[iv-expression] \h'|\nxu'(use array element)
|
||||
.IP (5)
|
||||
& A[iv-expression] (take address of array element)
|
||||
& A[iv-expression] \h'|\nxu'(take address of array element)
|
||||
.LP
|
||||
(Note that EM has different instructions to use an array element,
|
||||
store into one, or take the address of one, resp. LAR, SAR, and AAR).
|
||||
@@ -171,10 +171,13 @@ replaced by TMP.
|
||||
For array optimizations, the replacement
|
||||
depends on the form:
|
||||
.DS
|
||||
\fIform\fR \fIreplacement\fR
|
||||
(3) A[iv-expr] := *TMP := (assign indirect)
|
||||
(4) A[iv-expr] *TMP (use indirect)
|
||||
(5) &A[iv-expr] TMP
|
||||
.TS
|
||||
l l l.
|
||||
\fIform\fR \fIreplacement\fR
|
||||
(3) A[iv-expr] := *TMP := (assign indirect)
|
||||
(4) A[iv-expr] *TMP (use indirect)
|
||||
(5) &A[iv-expr] TMP
|
||||
.TE
|
||||
.DE
|
||||
The '*' denotes the indirect operator. (Note that
|
||||
EM has different instructions to do
|
||||
@@ -199,14 +202,17 @@ must be negated.
|
||||
.PP
|
||||
The transformations are demonstrated by an example.
|
||||
.DS
|
||||
i := 100; i := 100;
|
||||
while i > 1 loop TMP := (6-i) * 5;
|
||||
X := (6-i) * 5 + 2; while i > 1 loop
|
||||
Y := (6-i) * 5 - 8; --> X := TMP + 2;
|
||||
i := i - 3; Y := TMP - 8;
|
||||
end loop; i := i - 3;
|
||||
TMP := TMP + 15;
|
||||
end loop;
|
||||
.TS
|
||||
l l.
|
||||
i := 100; i := 100;
|
||||
while i > 1 loop TMP := (6-i) * 5;
|
||||
X := (6-i) * 5 + 2; while i > 1 loop
|
||||
Y := (6-i) * 5 - 8;\ \ \ \ \ \ \ --> X := TMP + 2;
|
||||
i := i - 3; Y := TMP - 8;
|
||||
end loop; i := i - 3;
|
||||
TMP := TMP + 15;
|
||||
end loop;
|
||||
.TE
|
||||
|
||||
Fig. 6.2 Example of complex Strength Reduction transformations
|
||||
.DE
|
||||
|
||||
104
doc/ego/sr/sr3
104
doc/ego/sr/sr3
@@ -64,12 +64,15 @@ The assignment must match one of the EM patterns below.
|
||||
('x' is the candidate. 'ws' is the word size of the target machine.
|
||||
'n' is any number.)
|
||||
.DS
|
||||
\fIpattern\fR \fIstep size\fR
|
||||
INL x | +1
|
||||
DEL x | -1
|
||||
LOL x ; (INC | DEC) ; STL x | +1 | -1
|
||||
LOL x ; LOC n ; (ADI ws | SBI ws) ; STL x | +n | -n
|
||||
LOC n ; LOL x ; ADI ws ; STL x. +n
|
||||
.TS
|
||||
l l.
|
||||
\fIpattern\fR \fIstep size\fR
|
||||
INL x | +1
|
||||
DEL x | -1
|
||||
LOL x ; (INC | DEC) ; STL x | +1 | -1
|
||||
LOL x ; LOC n ; (ADI ws | SBI ws) ; STL x | +n | -n
|
||||
LOC n ; LOL x ; ADI ws ; STL x +n
|
||||
.TE
|
||||
.DE
|
||||
From the patterns the step size of the induction variable
|
||||
can also be determined.
|
||||
@@ -95,19 +98,22 @@ code in front of it.
|
||||
If an expression is to be optimized, it must
|
||||
be generated by the following syntax rules.
|
||||
.DS
|
||||
optimizable_expr:
|
||||
iv_expr const mult |
|
||||
const iv_expr mult |
|
||||
address iv_expr address array_instr;
|
||||
mult:
|
||||
MLI ws |
|
||||
MLU ws ;
|
||||
array_instr:
|
||||
LAR ws |
|
||||
SAR ws |
|
||||
AAR ws ;
|
||||
const:
|
||||
LOC n ;
|
||||
.TS
|
||||
l l.
|
||||
optimizable_expr:
|
||||
iv_expr const mult |
|
||||
const iv_expr mult |
|
||||
address iv_expr address array_instr;
|
||||
mult:
|
||||
MLI ws |
|
||||
MLU ws ;
|
||||
array_instr:
|
||||
LAR ws |
|
||||
SAR ws |
|
||||
AAR ws ;
|
||||
const:
|
||||
LOC n ;
|
||||
.TE
|
||||
.DE
|
||||
An 'address' is an EM instruction that loads an
|
||||
address on the stack.
|
||||
@@ -120,36 +126,42 @@ instructions like LDL are an 'address'.
|
||||
denote resp. the array address and the
|
||||
array descriptor address).
|
||||
.DS
|
||||
address:
|
||||
LAE |
|
||||
LAL |
|
||||
LOL if ps=ws |
|
||||
LOE ,, |
|
||||
LIL ,, |
|
||||
LDL if ps=2*ws |
|
||||
LDE ,, ;
|
||||
.TS
|
||||
l l.
|
||||
address:
|
||||
LAE |
|
||||
LAL |
|
||||
LOL if ps=ws |
|
||||
LOE ,, |
|
||||
LIL ,, |
|
||||
LDL if ps=2*ws |
|
||||
LDE ,, ;
|
||||
.TE
|
||||
.DE
|
||||
The notion of an iv-expression was introduced earlier.
|
||||
.DS
|
||||
iv_expr:
|
||||
iv_expr unair_op |
|
||||
iv_expr iv_expr binary_op |
|
||||
loopconst |
|
||||
iv ;
|
||||
unair_op:
|
||||
NGI ws |
|
||||
INC |
|
||||
DEC ;
|
||||
binary_op:
|
||||
ADI ws |
|
||||
ADU ws |
|
||||
SBI ws |
|
||||
SBU ws ;
|
||||
loopconst:
|
||||
const |
|
||||
LOL x if x is not changed in loop ;
|
||||
iv:
|
||||
LOL x if x is an induction variable ;
|
||||
.TS
|
||||
l l.
|
||||
iv_expr:
|
||||
iv_expr unair_op |
|
||||
iv_expr iv_expr binary_op |
|
||||
loopconst |
|
||||
iv ;
|
||||
unair_op:
|
||||
NGI ws |
|
||||
INC |
|
||||
DEC ;
|
||||
binary_op:
|
||||
ADI ws |
|
||||
ADU ws |
|
||||
SBI ws |
|
||||
SBU ws ;
|
||||
loopconst:
|
||||
const |
|
||||
LOL x if x is not changed in loop ;
|
||||
iv:
|
||||
LOL x if x is an induction variable ;
|
||||
.TE
|
||||
.DE
|
||||
An iv_expression must satisfy one additional constraint:
|
||||
it must use exactly one operand that is an induction
|
||||
|
||||
Reference in New Issue
Block a user