[m-rev.] for review: fix mantis bug 56
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon May 26 12:26:32 AEST 2008
Fix a bug that prevented the compiler from being able to bootstrap in debugging
grades. This was Mantis bug #56. (The bug was not affected by the presence or
absence of trailing, or the issue of debug vs decldebug.)
We have previously found that the problem could be eliminated by compiling
polymorphism.m with --no-common-struct. I isolated the problem to the code
we used to generate at the start of the else case in the only if-then-else
in fixup_pred_polymorphism when --common-struct is enabled:
MR_r1 = MR_sv(20);
/* Placing PredInfo1 */
MR_r1 = MR_sv(28);
/* Placing TypeInfo_34 (depth 1) */
MR_sv(28) = MR_sv(29);
/* Placing TypeInfo_37 */
The bug was of course the second assignment to r1. It was caused not by
anything done by common.m, but was a bug (an over-eager optimization)
in the code generator that just happened to be tickled *extremely* rarely.
compiler/var_locn.m:
The bug was caused by a sometimes-false assumption. The assumption
was that when we need to free up an lval because we are about to
place a value in it, we can move it into the register preferred by
follow_vars for the variable being moved, provided that register isn't
locked.
This is true when we are placing the arguments of a call, because the
preferred location for any value being moved is either a stack slot
(if the value is not an argument), or a register we haven't set yet
(if the value is a following argument). It cannot be a register we have
already set, because in that case there would be no need to move the
value out of a later register.
However, the assumption is false when placing resume vars between
the stack and original resume maps, as in fixup_pred_polymorphism.
In that case, we do not impose any particular order on the sequence
of place_var operations required. The bug was that when we needed
to free up a location (stackvar 28), we moved the value in it into r1,
even though r1 already contained a value we needed.
The fix is to make sure that we never pick a register currently in use.
Since for calls, the in-use check should not fail, this should not
lead to significantly worse code being generated.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/var_locn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.61
diff -u -b -r1.61 var_locn.m
--- compiler/var_locn.m 28 Feb 2008 00:08:33 -0000 1.61
+++ compiler/var_locn.m 25 May 2008 12:24:22 -0000
@@ -859,7 +859,7 @@
Code, !VLI) :-
check_var_is_unknown(!.VLI, Var),
- select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
+ select_preferred_reg_or_stack(!.VLI, Var, Lval),
get_var_name(!.VLI, Var, VarName),
list.length(Vector, Size),
(
@@ -1316,7 +1316,7 @@
Lval = SelectLval,
Code = empty
;
- select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
+ select_preferred_reg_or_stack(!.VLI, Var, Lval),
var_locn_place_var(ModuleInfo, Var, Lval, Code, !VLI)
).
@@ -1527,8 +1527,7 @@
EffAffectedVars = [MovedVar]
),
- CheckInUse = no,
- select_preferred_reg_or_stack(!.VLI, MovedVar, Pref, CheckInUse),
+ select_preferred_reg_or_stack(!.VLI, MovedVar, Pref),
\+ Pref = Lval,
\+ list.member(Pref, ForbiddenLvals),
( \+ var_locn_lval_in_use(!.VLI, Pref) ->
@@ -1878,26 +1877,20 @@
%----------------------------------------------------------------------------%
-:- pred select_preferred_reg_avoid(var_locn_info::in, prog_var::in,
- list(lval)::in, lval::out) is det.
-
-select_preferred_reg_avoid(VLI, Var, Avoid, Lval) :-
- select_preferred_reg(VLI, Var, yes, Avoid, Lval).
-
-:- pred select_preferred_reg(var_locn_info::in, prog_var::in,
- lval::out) is det.
+:- pred select_preferred_reg(var_locn_info::in, prog_var::in, lval::out)
+ is det.
select_preferred_reg(VLI, Var, Lval) :-
- select_preferred_reg(VLI, Var, yes, [], Lval).
+ select_preferred_reg_avoid(VLI, Var, [], Lval).
% Select the register into which Var should be put. If the follow_vars map
% maps Var to a register, then select that register, unless it is already
- % in use, and CheckInUse = yes.
+ % in use.
%
-:- pred select_preferred_reg(var_locn_info::in, prog_var::in,
- bool::in, list(lval)::in, lval::out) is det.
+:- pred select_preferred_reg_avoid(var_locn_info::in, prog_var::in,
+ list(lval)::in, lval::out) is det.
-select_preferred_reg(VLI, Var, CheckInUse, Avoid, Lval) :-
+select_preferred_reg_avoid(VLI, Var, Avoid, Lval) :-
var_locn_get_follow_var_map(VLI, FollowVarMap),
(
map.search(FollowVarMap, Var, PrefLocn),
@@ -1908,12 +1901,7 @@
(
PrefLocn = abs_reg(N),
PrefLval = reg(reg_r, N),
- (
- CheckInUse = yes,
- \+ var_locn_lval_in_use(VLI, PrefLval)
- ;
- CheckInUse = no
- ),
+ \+ var_locn_lval_in_use(VLI, PrefLval),
\+ list.member(PrefLval, Avoid)
->
Lval = PrefLval
@@ -1926,24 +1914,17 @@
% Select the register or stack slot into which Var should be put. If the
% follow_vars map maps Var to a register, then select that register,
- % unless it is already in use and CheckInUse = yes. If the follow_vars map
- % does not contain Var, then Var is not needed in a register in the near
- % future, and this we select Var's stack slot, unless it is in use and
- % CheckInUse = yes. If all else fails, we get spare, unused register.
- % (Note that if the follow_vars pass has not been run, then all follow vars
- % maps will be empty, which would cause this predicate to try to put far
- % too many things in stack slots.)
- %
-:- pred select_preferred_reg_or_stack_check(var_locn_info::in,
- prog_var::in, lval::out) is det.
-
-select_preferred_reg_or_stack_check(VLI, Var, Lval) :-
- select_preferred_reg_or_stack(VLI, Var, Lval, yes).
-
-:- pred select_preferred_reg_or_stack(var_locn_info::in,
- prog_var::in, lval::out, bool::in) is det.
+ % unless it is already in use. If the follow_vars map does not contain Var,
+ % then Var is not needed in a register in the near future, and this we
+ % select Var's stack slot, unless it is in use. If all else fails, we get
+ % a spare, unused register. (Note that if the follow_vars pass has not
+ % been run, then all follow vars maps will be empty, which would cause
+ % this predicate to try to put far too many things in stack slots.)
+ %
+:- pred select_preferred_reg_or_stack(var_locn_info::in, prog_var::in,
+ lval::out) is det.
-select_preferred_reg_or_stack(VLI, Var, Lval, CheckInUse) :-
+select_preferred_reg_or_stack(VLI, Var, Lval) :-
var_locn_get_follow_var_map(VLI, FollowVarMap),
(
map.search(FollowVarMap, Var, PrefLocn),
@@ -1954,12 +1935,7 @@
(
PrefLocn = abs_reg(N),
PrefLval = reg(reg_r, N),
- (
- CheckInUse = yes,
\+ var_locn_lval_in_use(VLI, PrefLval)
- ;
- CheckInUse = no
- )
->
Lval = PrefLval
;
@@ -1970,12 +1946,7 @@
var_locn_get_stack_slots(VLI, StackSlots),
map.search(StackSlots, Var, StackSlotLocn),
StackSlot = stack_slot_to_lval(StackSlotLocn),
- (
- CheckInUse = yes,
\+ var_locn_lval_in_use(VLI, StackSlot)
- ;
- CheckInUse = no
- )
->
Lval = StackSlot
;
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list