mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 23:35:25 +00:00
Optimize away unifications with dead variables.
modes.m: Optimize away unifications with dead variables. (The code generator already does that, but by that time we have already allocated unnecessary stack slots for them.) code_exprn.m: Avoid generating sequences such as `r2 = r3; r3 = r2;' when a register already contains the correct value. (This change was in fact at least as much Tom's work as mine.) store_alloc.m: For disjunctions, we only want to allocate registers for the variables that are output by the disjunction. The inputs should go in framevars, not in registers. This avoids much of the register-shuffling in the code generated for e.g. list__member(out, in). (This change was in fact at least as much Tom's work as mine.)
This commit is contained in:
@@ -842,6 +842,20 @@ code_exprn__place_var_2(cached(Exprn0), Var, Lval, Code) -->
|
||||
{ ExprnCode = node([
|
||||
assign(Lval, Exprn) - Comment
|
||||
]) }
|
||||
;
|
||||
% if the variable already has its value stored in the
|
||||
% right place, we don't need to generated any code
|
||||
{ Exprn0 = var(Var1) },
|
||||
code_exprn__get_vars(Vars0),
|
||||
{ map__search(Vars0, Var1, Stat0) },
|
||||
{ Stat0 = evaled(VarRvals) },
|
||||
{ set__member(lval(Lval), VarRvals) }
|
||||
->
|
||||
{ ClearCode = empty },
|
||||
{ ExprnCode = empty },
|
||||
code_exprn__add_lval_reg_dependencies(Lval),
|
||||
{ set__singleton_set(LvalSet, lval(Lval)) },
|
||||
{ Stat = evaled(LvalSet) }
|
||||
;
|
||||
% move stuff out of the way
|
||||
code_exprn__clear_lval(Lval, Exprn0, Exprn1, ClearCode),
|
||||
@@ -855,6 +869,7 @@ code_exprn__place_var_2(cached(Exprn0), Var, Lval, Code) -->
|
||||
(
|
||||
{ Exprn2 = create(_, _, _) }
|
||||
->
|
||||
% XXX why is this necessary?
|
||||
code_exprn__get_var_rvals(Var, Rvals7),
|
||||
{ set__to_sorted_list(Rvals7, RvalList7) },
|
||||
{ code_exprn__select_rval(RvalList7, Exprn3) },
|
||||
|
||||
Reference in New Issue
Block a user