diff: code generation bug fix
Fergus Henderson
fjh at cs.mu.oz.au
Sat Nov 22 02:33:25 AEDT 1997
Tom and Zoltan, can you both please review this change?
Fix a code generation bug that broke Tom's mediancut.m program.
compiler/code_exprn.m:
Change code_exprn__lval_in_use/3 to also check the registers marked
in use, not just the variables marked in use.
This avoids problems in the following case:
- a register R was marked in use, since it was the target
register we decided to use to compute variable X;
- before variable X was given status `evaled(R)' we had to
first produce some other variable Y that X depended on;
- Y was placed in register R (since that was not considered
in use);
- we then assigned X to R, because that was
the location we had decided to place X in,
thus clobbering Y;
- subsequently we used R, expecting it to hold Y.
This change increases the code size of the compiler on DEC Alpha
by 100k (2.7%). :-(
Index: code_exprn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_exprn.m,v
retrieving revision 1.51
diff -u -u -r1.51 code_exprn.m
--- code_exprn.m 1997/07/27 14:59:55 1.51
+++ code_exprn.m 1997/11/21 15:32:25
@@ -494,33 +494,21 @@
%------------------------------------------------------------------------------%
code_exprn__lval_in_use(Lval) -->
- code_exprn__lval_in_use_except(Lval, no).
-
-:- pred code_exprn__lval_in_use_except(lval, maybe(var),
- exprn_info, exprn_info).
-:- mode code_exprn__lval_in_use_except(in, in, in, out) is semidet.
-
-code_exprn__lval_in_use_except(Lval, MaybeVar) -->
code_exprn__get_vars(Vars),
- { map__to_assoc_list(Vars, VarStatList) },
- { code_exprn__lval_in_use_2(Lval, MaybeVar, VarStatList) }.
-
- % The auxiliary predicate is needed to allow Mercury to recognize
- % that the subcomputation has no outputs without using existential
- % quantification, whose syntax SICStus doesn't like.
+ code_exprn__get_regs(Regs),
+ (
+ { bag__contains(Regs, Lval) }
+ ;
+ { map__to_assoc_list(Vars, VarStatList) },
+ { code_exprn__lval_in_use_by_vars(Lval, VarStatList) }
+ ).
-:- pred code_exprn__lval_in_use_2(lval, maybe(var), assoc_list(var, var_stat)).
-:- mode code_exprn__lval_in_use_2(in, in, in) is semidet.
+:- pred code_exprn__lval_in_use_by_vars(lval, assoc_list(var, var_stat)).
+:- mode code_exprn__lval_in_use_by_vars(in, in) is semidet.
-code_exprn__lval_in_use_2(Lval, MaybeVar, VarStatList) :-
+code_exprn__lval_in_use_by_vars(Lval, VarStatList) :-
list__member(VarStat, VarStatList),
- VarStat = Var - Stat,
- (
- MaybeVar = no
- ;
- MaybeVar = yes(ExceptionVar),
- \+ Var = ExceptionVar
- ),
+ VarStat = _Var - Stat,
(
Stat = cached(Rval),
exprn_aux__rval_contains_lval(Rval, Lval)
@@ -1163,7 +1151,7 @@
code_exprn__add_lval_reg_dependencies(Lval),
code_exprn__maybe_get_var_name(MaybeVar, VarName),
( { IsConst = yes } ->
- { string__append("Assigning from ", VarName, Comment) },
+ { string__append("Assigning from const ", VarName, Comment) },
{ ExprnCode = node([assign(Lval, Rval2) - Comment]) }
;
( { StandAlone = yes } ->
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list