[m-rev.] diff: four new LLDS instructions for loop_control

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Sep 30 15:52:54 AEST 2011


Paul has already reviewed the new instructions, and the rest of the diff
is relatively straighforward. It has not been tested yet, since that
cannot happen until Paul starts *generating* the new instructions.

Zoltan.

Add four LLDS instructions Paul will soon need to implement the loop control
transformation.

compiler/llds.m:
	Add the new instructions.

compiler/llds_out_instr.m:
	Output the new instructions. Paul may want to change the code
	we generate.

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Handle the new instructions.

	In opt_util.m, fix two old bugs. First, the restore_maxfr instruction
	behaved as if it updated hp, not maxfr. Second, the keep_assign
	instruction wasn't being handled as an assignment operation.

	In peephole.m, fix an old bug, in which assignments through mem_refs
	were not considered to invalidate the cached value of an lval.

	In use_local_vars, fix an old bug: the keep_assign instruction
	wasn't being handled as an assignment operation. Assignments
	themselves weren't being as optimized as they could be.

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/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
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/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/dupelim.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dupelim.m,v
retrieving revision 1.102
diff -u -b -r1.102 dupelim.m
--- compiler/dupelim.m	25 May 2011 08:04:27 -0000	1.102
+++ compiler/dupelim.m	28 Sep 2011 07:51:16 -0000
@@ -441,6 +441,25 @@
         standardize_lval(Lval0, Lval),
         Instr = join_and_continue(Lval, Label)
     ;
+        Instr0 = lc_create_loop_control(NumSlots, Lval0),
+        standardize_lval(Lval0, Lval),
+        Instr = lc_create_loop_control(NumSlots, Lval)
+    ;
+        Instr0 = lc_wait_free_slot(Rval0, Lval0, Label),
+        standardize_rval(Rval0, Rval),
+        standardize_lval(Lval0, Lval),
+        Instr = lc_wait_free_slot(Rval, Lval, Label)
+    ;
+        Instr0 = lc_spawn_off(LCRval0, LCSRval0, Label),
+        standardize_rval(LCRval0, LCRval),
+        standardize_rval(LCSRval0, LCSRval),
+        Instr = lc_spawn_off(LCRval, LCSRval, Label)
+    ;
+        Instr0 = lc_join_and_terminate(LCRval0, LCSRval0),
+        standardize_rval(LCRval0, LCRval),
+        standardize_rval(LCSRval0, LCSRval),
+        Instr = lc_join_and_terminate(LCRval, LCSRval)
+    ;
         ( Instr0 = comment(_)
         ; Instr0 = livevals(_)
         ; Instr0 = block(_, _, _)
@@ -830,6 +849,49 @@
             MaybeInstr = no
         )
     ;
+        InstrA = lc_create_loop_control(NumSlots, LvalA),
+        (
+            InstrB = lc_create_loop_control(NumSlots, LvalB),
+            most_specific_lval(LvalA, LvalB, Lval)
+        ->
+            MaybeInstr = yes(lc_create_loop_control(NumSlots, Lval))
+        ;
+            MaybeInstr = no
+        )
+    ;
+        InstrA = lc_wait_free_slot(RvalA, LvalA, Label),
+        (
+            InstrB = lc_wait_free_slot(RvalB, LvalB, Label),
+            most_specific_rval(RvalA, RvalB, Rval),
+            most_specific_lval(LvalA, LvalB, Lval)
+        ->
+            MaybeInstr = yes(lc_wait_free_slot(Rval, Lval, Label))
+        ;
+            MaybeInstr = no
+        )
+    ;
+        InstrA = lc_spawn_off(LCRvalA, LCSRvalA, Label),
+        (
+            InstrB = lc_spawn_off(LCRvalB, LCSRvalB, Label),
+            most_specific_rval(LCRvalA, LCRvalB, LCRval),
+            most_specific_rval(LCSRvalA, LCSRvalB, LCSRval)
+        ->
+            MaybeInstr = yes(lc_spawn_off(LCRval, LCSRval, Label))
+        ;
+            MaybeInstr = no
+        )
+    ;
+        InstrA = lc_join_and_terminate(LCRvalA, LCSRvalA),
+        (
+            InstrB = lc_join_and_terminate(LCRvalB, LCSRvalB),
+            most_specific_rval(LCRvalA, LCRvalB, LCRval),
+            most_specific_rval(LCSRvalA, LCSRvalB, LCSRval)
+        ->
+            MaybeInstr = yes(lc_join_and_terminate(LCRval, LCSRval))
+        ;
+            MaybeInstr = no
+        )
+    ;
         ( InstrA = livevals(_)
         ; InstrA = block(_, _, _)
         ; InstrA = llcall(_, _, _, _, _, _)
Index: compiler/dupproc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dupproc.m,v
retrieving revision 1.31
diff -u -b -r1.31 dupproc.m
--- compiler/dupproc.m	17 Jun 2011 07:51:17 -0000	1.31
+++ compiler/dupproc.m	28 Sep 2011 08:00:00 -0000
@@ -235,6 +235,22 @@
         Instr = foreign_proc_code(_, _, _, _, _, _, _, _, _, _),
         StdInstr = Instr
     ;
+        Instr = lc_wait_free_slot(Rval, Lval, Label),
+        standardize_rval(Rval, StdRval, DupProcMap),
+        standardize_label(Label, StdLabel, DupProcMap),
+        StdInstr = lc_wait_free_slot(StdRval, Lval, StdLabel)
+    ;
+        Instr = lc_spawn_off(LCRval, LCSRval, Label),
+        standardize_rval(LCRval, StdLCRval, DupProcMap),
+        standardize_rval(LCSRval, StdLCSRval, DupProcMap),
+        standardize_label(Label, StdLabel, DupProcMap),
+        StdInstr = lc_spawn_off(StdLCRval, StdLCSRval, StdLabel)
+    ;
+        Instr = lc_join_and_terminate(LCRval, LCSRval),
+        standardize_rval(LCRval, StdLCRval, DupProcMap),
+        standardize_rval(LCSRval, StdLCSRval, DupProcMap),
+        StdInstr = lc_join_and_terminate(StdLCRval, StdLCSRval)
+    ;
         % These instructions have no labels inside them, or anything else
         % that can be standardized.
         ( Instr = comment(_)
@@ -259,6 +275,7 @@
         ; Instr = decr_sp(_)
         ; Instr = decr_sp_and_return(_)
         ; Instr = init_sync_term(_, _, _)
+        ; Instr = lc_create_loop_control(_, _)
         ),
         StdInstr = Instr
     ).
Index: compiler/exprn_aux.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/exprn_aux.m,v
retrieving revision 1.95
diff -u -b -r1.95 exprn_aux.m
--- compiler/exprn_aux.m	16 Sep 2011 07:03:35 -0000	1.95
+++ compiler/exprn_aux.m	28 Sep 2011 08:03:03 -0000
@@ -417,6 +417,25 @@
         Uinstr0 = join_and_continue(Lval0, Label),
         Transform(Lval0, Lval, !Acc),
         Uinstr = join_and_continue(Lval, Label)
+    ;
+        Uinstr0 = lc_create_loop_control(NumSlots, Lval0),
+        Transform(Lval0, Lval, !Acc),
+        Uinstr = lc_create_loop_control(NumSlots, Lval)
+    ;
+        Uinstr0 = lc_wait_free_slot(LCRval0, LCSLval0, Label),
+        transform_lval_in_rval(Transform, LCRval0, LCRval, !Acc),
+        Transform(LCSLval0, LCSLval, !Acc),
+        Uinstr = lc_wait_free_slot(LCRval, LCSLval, Label)
+    ;
+        Uinstr0 = lc_spawn_off(LCRval0, LCSRval0, Label),
+        transform_lval_in_rval(Transform, LCRval0, LCRval, !Acc),
+        transform_lval_in_rval(Transform, LCSRval0, LCSRval, !Acc),
+        Uinstr = lc_spawn_off(LCRval, LCSRval, Label)
+    ;
+        Uinstr0 = lc_join_and_terminate(LCRval0, LCSRval0),
+        transform_lval_in_rval(Transform, LCRval0, LCRval, !Acc),
+        transform_lval_in_rval(Transform, LCSRval0, LCSRval, !Acc),
+        Uinstr = lc_join_and_terminate(LCRval, LCSRval)
     ).
 
 :- pred transform_lval_in_component(transform_lval(T)::in(transform_lval),
Index: compiler/global_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/global_data.m,v
retrieving revision 1.51
diff -u -b -r1.51 global_data.m
--- compiler/global_data.m	16 Sep 2011 07:03:35 -0000	1.51
+++ compiler/global_data.m	28 Sep 2011 08:13:09 -0000
@@ -1135,6 +1135,25 @@
         remap_lval(StaticCellRemap, Lval0, Lval),
         Instr = join_and_continue(Lval, Label)
     ;
+        Instr0 = lc_create_loop_control(NumSlots, Lval0),
+        remap_lval(StaticCellRemap, Lval0, Lval),
+        Instr = lc_create_loop_control(NumSlots, Lval)
+    ;
+        Instr0 = lc_wait_free_slot(Rval0, Lval0, Label),
+        remap_rval(StaticCellRemap, Rval0, Rval),
+        remap_lval(StaticCellRemap, Lval0, Lval),
+        Instr = lc_wait_free_slot(Rval, Lval, Label)
+    ;
+        Instr0 = lc_spawn_off(LCRval0, LCSRval0, Label),
+        remap_rval(StaticCellRemap, LCRval0, LCRval),
+        remap_rval(StaticCellRemap, LCSRval0, LCSRval),
+        Instr = lc_spawn_off(LCRval, LCSRval, Label)
+    ;
+        Instr0 = lc_join_and_terminate(LCRval0, LCSRval0),
+        remap_rval(StaticCellRemap, LCRval0, LCRval),
+        remap_rval(StaticCellRemap, LCSRval0, LCSRval),
+        Instr = lc_join_and_terminate(LCRval, LCSRval)
+    ;
         ( Instr0 = comment(_)
         ; Instr0 = livevals(_)
         ; Instr0 = llcall(_, _, _, _, _, _)
Index: compiler/jumpopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.120
diff -u -b -r1.120 jumpopt.m
--- compiler/jumpopt.m	27 Sep 2011 00:49:25 -0000	1.120
+++ compiler/jumpopt.m	28 Sep 2011 08:18:21 -0000
@@ -407,6 +407,24 @@
             NewRemain = specified([Instr], Instrs0)
         )
     ;
+        Uinstr0 = lc_wait_free_slot(_, _, _),
+        % The label in the third argument should not be referred to
+        % from any code in the procedure's LLDS instruction sequence,
+        % so there is no way for it to be short circuited.
+        NewRemain = usual_case
+    ;
+        Uinstr0 = lc_spawn_off(LCRval, LCSRval, Child0),
+        InstrMap = JumpOptInfo ^ joi_instr_map,
+        short_label(InstrMap, Child0, Child),
+        ( Child = Child0 ->
+            NewRemain = usual_case
+        ;
+            Uinstr = lc_spawn_off(LCRval, LCSRval, Child),
+            Comment = Comment0 ++ " (redirect)",
+            Instr = llds_instr(Uinstr, Comment),
+            NewRemain = specified([Instr], Instrs0)
+        )
+    ;
         ( Uinstr0 = arbitrary_c_code(_, _, _)
         ; Uinstr0 = comment(_)
         ; Uinstr0 = livevals(_)
@@ -431,6 +449,8 @@
         ; Uinstr0 = incr_hp(_, _, _, _, _, _, _, _)
         ; Uinstr0 = restore_hp(_)
         ; Uinstr0 = init_sync_term(_, _, _)
+        ; Uinstr0 = lc_create_loop_control(_, _)
+        ; Uinstr0 = lc_join_and_terminate(_, _)
         ),
         NewRemain = usual_case
     ),
Index: compiler/livemap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/livemap.m,v
retrieving revision 1.101
diff -u -b -r1.101 livemap.m
--- compiler/livemap.m	25 May 2011 08:04:27 -0000	1.101
+++ compiler/livemap.m	28 Sep 2011 08:56:13 -0000
@@ -51,6 +51,7 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
+build_livemap(Instrs, MaybeLivemap) :-
     % The method we follow is a backward scan of the instruction list,
     % keeping track of the set of live lvals as we go. We update this set
     % at each instruction. When we get to a label, we know that this set
@@ -59,11 +60,10 @@
     % At instructions that can branch away, every lval that is live at
     % any possible target is live before that instruction. Since some
     % branches may be backward branches, we may not have seen the branch
-    % target when we process the branch. Therefore we have to repeat the
-    % scan, this time with more knowledge about more labels, until we
-    % get to a fixpoint.
+    % target when we process the branch. Therefore we have to repeat the scan,
+    % this time with more knowledge about more labels, until we get to
+    % a fixpoint.
 
-build_livemap(Instrs, MaybeLivemap) :-
     map.init(Livemap0),
     list.reverse(Instrs, BackInstrs),
     build_livemap_fixpoint(BackInstrs, Livemap0, 0, MaybeLivemap).
@@ -71,9 +71,9 @@
 :- pred build_livemap_fixpoint(list(instruction)::in, livemap::in, int::in,
     maybe(livemap)::out) is det.
 
-build_livemap_fixpoint(Backinstrs, Livemap0, CurIteration, MaybeLivemap) :-
+build_livemap_fixpoint(BackInstrs, Livemap0, CurIteration, MaybeLivemap) :-
     set.init(Livevals0),
-    livemap_do_build(Backinstrs, Livevals0, no, ContainsBadUserCode,
+    livemap_do_build(BackInstrs, Livevals0, no, ContainsBadUserCode,
         Livemap0, Livemap1),
     (
         ContainsBadUserCode = yes,
@@ -84,7 +84,7 @@
             MaybeLivemap = yes(Livemap1)
         ;
             ( CurIteration < livemap_iteration_limit ->
-                build_livemap_fixpoint(Backinstrs, Livemap1, CurIteration + 1,
+                build_livemap_fixpoint(BackInstrs, Livemap1, CurIteration + 1,
                     MaybeLivemap)
             ;
                 MaybeLivemap = no
@@ -170,6 +170,24 @@
         opt_util.lval_access_rvals(Lval, Rvals),
         livemap.make_live_in_rvals([Rval | Rvals], !Livevals)
     ;
+        Uinstr0 = lc_create_loop_control(_NumSlots, Lval),
+        set.delete(Lval, !Livevals)
+    ;
+        Uinstr0 = lc_wait_free_slot(LCRval, LCSLval, _InternalLabel),
+        set.delete(LCSLval, !Livevals),
+        opt_util.lval_access_rvals(LCSLval, LCSAccessRvals),
+        livemap.make_live_in_rvals([LCRval | LCSAccessRvals], !Livevals)
+    ;
+        Uinstr0 = lc_spawn_off(LCRval, LCSRval, Child),
+        livemap.make_live_in_rvals([LCRval, LCSRval], !Livevals),
+        % Everything that is live at Child is live before this instruction.
+        livemap_insert_label_livevals(!.Livemap, Child, !Livevals)
+    ;
+        Uinstr0 = lc_join_and_terminate(LCRval, LCSRval),
+        % Since this instruction terminates its context, nothing is live
+        % before it except its arguments and their components.
+        livemap.make_live_in_rvals([LCRval, LCSRval], set.init, !:Livevals)
+    ;
         Uinstr0 = llcall(_, _, _, _, _, _),
         livemap.look_for_livevals(!Instrs, !Livevals, "call", yes, _)
     ;
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.379
diff -u -b -r1.379 llds.m
--- compiler/llds.m	27 Sep 2011 00:49:25 -0000	1.379
+++ compiler/llds.m	28 Sep 2011 07:02:01 -0000
@@ -639,7 +639,7 @@
             % the synchronisation term. Control continues at the next
             % instruction.
 
-    ;       join_and_continue(lval, label).
+    ;       join_and_continue(lval, label)
             % Signal that this thread of execution has finished in the current
             % parallel conjunct. For details of how we at the end of a parallel
             % conjunct see runtime/mercury_context.{c,h}.
@@ -647,6 +647,37 @@
             % The label gives the address of the code following the parallel
             % conjunction. 
 
+    ;       lc_create_loop_control(int, lval)
+            % Create a loop control structure with the given number of slots,
+            % and put its address in the given lval.
+
+    ;       lc_wait_free_slot(rval, lval, label)
+            % Given an rval that holds the address of a loop control structure,
+            % return the index of a free slot in that structure, waiting for
+            % one to become free if necessary. The label acts as a resumption
+            % point if the context suspends. It will be both defined and used
+            % in the C code generated for this instruction, and should not
+            % be referred to from anywhere else.
+
+    ;       lc_spawn_off(rval, rval, label)
+            % Spawn off an independent computation whose execution starts
+            % at the given label and which will terminate by executing
+            % a join_and_terminate_lc instruction. The first rval should
+            % hold the address of the loop control structure that controls
+            % the spawned-off computation, and the second should hold
+            % the index of the slot occupied by that computation.
+            %
+            % After spawning off that computation, the original thread
+            % will just fall through.
+
+    ;       lc_join_and_terminate(rval, rval).
+            % Terminate the current context, which was spawned off by a
+            % spawn_off instruction. The first rval gives the address of
+            % the loop control structure, and the second is the index of
+            % this goal's slot in it. These two rvals should be exactly
+            % the same as the two rval arguments in the original lc_spawn_off
+            % instruction.
+
 :- inst instr_llcall
     --->    llcall(ground, ground, ground, ground, ground, ground).
 :- inst instr_goto
Index: compiler/llds_out_instr.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out_instr.m,v
retrieving revision 1.11
diff -u -b -r1.11 llds_out_instr.m
--- compiler/llds_out_instr.m	16 Sep 2011 07:03:35 -0000	1.11
+++ compiler/llds_out_instr.m	28 Sep 2011 09:20:06 -0000
@@ -208,6 +208,25 @@
         Instr = join_and_continue(Lval, Label),
         output_record_lval_decls(Info, Lval, !DeclSet, !IO),
         output_record_code_addr_decls(Info, code_label(Label), !DeclSet, !IO)
+    ;
+        Instr = lc_create_loop_control(_, LCLval),
+        output_record_lval_decls(Info, LCLval, !DeclSet, !IO)
+    ;
+        Instr = lc_wait_free_slot(LCRval, LCSLval, InternalLabel),
+        output_record_rval_decls(Info, LCRval, !DeclSet, !IO),
+        output_record_lval_decls(Info, LCSLval, !DeclSet, !IO),
+        output_record_code_addr_decls(Info, code_label(InternalLabel),
+            !DeclSet, !IO)
+    ;
+        Instr = lc_spawn_off(LCRval, LCSRval, ChildLabel),
+        output_record_rval_decls(Info, LCRval, !DeclSet, !IO),
+        output_record_rval_decls(Info, LCSRval, !DeclSet, !IO),
+        output_record_code_addr_decls(Info, code_label(ChildLabel),
+            !DeclSet, !IO)
+    ;
+        Instr = lc_join_and_terminate(LCRval, LCSRval),
+        output_record_rval_decls(Info, LCRval, !DeclSet, !IO),
+        output_record_rval_decls(Info, LCSRval, !DeclSet, !IO)
     ).
 
 :- pred output_record_foreign_proc_component_decls(llds_out_info::in,
@@ -899,6 +918,42 @@
         io.write_string(", ", !IO),
         output_label_as_code_addr(Label, !IO),
         io.write_string(");\n", !IO)
+    ;
+        Instr = lc_create_loop_control(NumSlots, Lval),
+        % XXX placeholder for pbone to fill in
+        io.write_string("\tMR_lc_create_loop_control(", !IO),
+        io.write_int(NumSlots, !IO),
+        io.write_string(", ", !IO),
+        output_lval(Info, Lval, !IO),
+        io.write_string(");\n", !IO)
+    ;
+        Instr = lc_wait_free_slot(LCRval, LCSLval, InternalLabel),
+        % XXX placeholder for pbone to fill in
+        io.write_string("\tMR_lc_wait_free_slot(", !IO),
+        output_rval(Info, LCRval, !IO),
+        io.write_string(", ", !IO),
+        output_lval(Info, LCSLval, !IO),
+        io.write_string(", ", !IO),
+        output_label(InternalLabel, !IO),
+        io.write_string(");\n", !IO)
+    ;
+        Instr = lc_spawn_off(LCRval, LCSRval, ChildLabel),
+        % XXX placeholder for pbone to fill in
+        io.write_string("\tMR_lc_spawn_off(", !IO),
+        output_rval(Info, LCRval, !IO),
+        io.write_string(", ", !IO),
+        output_rval(Info, LCSRval, !IO),
+        io.write_string(", ", !IO),
+        output_label(ChildLabel, !IO),
+        io.write_string(");\n", !IO)
+    ;
+        Instr = lc_join_and_terminate(LCRval, LCSRval),
+        % XXX placeholder for pbone to fill in
+        io.write_string("\tMR_lc_join_and_terminate(", !IO),
+        output_rval(Info, LCRval, !IO),
+        io.write_string(", ", !IO),
+        output_rval(Info, LCSRval, !IO),
+        io.write_string(");\n", !IO)
     ).
 
 %----------------------------------------------------------------------------%
Index: compiler/llds_to_x86_64.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_to_x86_64.m,v
retrieving revision 1.22
diff -u -b -r1.22 llds_to_x86_64.m
--- compiler/llds_to_x86_64.m	16 Sep 2011 07:03:35 -0000	1.22
+++ compiler/llds_to_x86_64.m	28 Sep 2011 09:32:08 -0000
@@ -183,15 +183,20 @@
 :- pred instr_to_x86_64(reg_map::in, reg_map::out,
     instr::in, list(x86_64_instr)::out) is det.
 
-instr_to_x86_64(!RegMap, comment(Comment), [x86_64_comment(Comment)]).
-instr_to_x86_64(!RegMap, livevals(RegsAndStackLocs), Instrs) :-
+instr_to_x86_64(!RegMap, Uinstr, Instrs) :-
+    (
+        Uinstr = comment(Comment),
+        Instrs = [x86_64_comment(Comment)]
+    ;
+        Uinstr = livevals(RegsAndStackLocs),
     set.to_sorted_list(RegsAndStackLocs, List),
-    transform_livevals(!.RegMap, List, Instrs).
-instr_to_x86_64(!RegMap, block(_, _, CInstrs), Instrs) :-
-    transform_block_instr(!.RegMap, CInstrs, Instrs).
-instr_to_x86_64(!RegMap, Op, Instrs) :-
-    ( Op = assign(Lval, Rval)
-    ; Op = keep_assign(Lval, Rval)
+        transform_livevals(!.RegMap, List, Instrs)
+    ;
+        Uinstr = block(_, _, CInstrs),
+        transform_block_instr(!.RegMap, CInstrs, Instrs)
+    ;
+        ( Uinstr = assign(Lval, Rval)
+        ; Uinstr = keep_assign(Lval, Rval)
     ),
     transform_lval(!RegMap, Lval, Res0, Res1),
     transform_rval(!RegMap, Rval, Res2, Res3),
@@ -237,8 +242,9 @@
             Res1 = no,
             unexpected($module, $pred, "assign: unexpected: Lval")
         )
-    ).
-instr_to_x86_64(!RegMap, llcall(Target0, Continuation0, _, _, _, _), Instrs) :-
+        )
+    ;
+        Uinstr = llcall(Target0, Continuation0, _, _, _, _),
     code_addr_type(Target0, Target1),
     code_addr_type(Continuation0, Continuation1),
     lval_reg_locn(!.RegMap, succip, Op0, Instr0),
@@ -257,15 +263,20 @@
     ),
     Instr1 = x86_64_instr(mov(operand_label(Continuation1), Op)),
     Instr2 = x86_64_instr(jmp(operand_label(Target1))),
-    Instrs = [Instr1, Instr2].
-instr_to_x86_64(!RegMap, mkframe(_, _), [x86_64_comment("<<mkframe>>")]).
-instr_to_x86_64(!RegMap, label(Label), Instrs) :-
+        Instrs = [Instr1, Instr2]
+    ;
+        Uinstr = mkframe(_, _),
+        Instrs = [x86_64_comment("<<mkframe>>")]
+    ;
+        Uinstr = label(Label),
     LabelStr = label_to_c_string(Label, no),
-    Instrs = [x86_64_label(LabelStr)].
-instr_to_x86_64(!RegMap, goto(CodeAddr), Instrs) :-
+        Instrs = [x86_64_label(LabelStr)]
+    ;
+        Uinstr = goto(CodeAddr),
     code_addr_type(CodeAddr, Label),
-    Instrs = [x86_64_instr(jmp(operand_label(Label)))].
-instr_to_x86_64(!RegMap, computed_goto(Rval, Labels), Instrs) :-
+        Instrs = [x86_64_instr(jmp(operand_label(Label)))]
+    ;
+        Uinstr = computed_goto(Rval, Labels),
     transform_rval(!RegMap, Rval, Res0, Res1),
     (
         Res0 = yes(RvalOp),
@@ -285,14 +296,16 @@
     ScratchReg = ll_backend.x86_64_regs.reg_map_get_scratch_reg(!.RegMap),
     ll_backend.x86_64_regs.reg_map_remove_scratch_reg(!RegMap),
     TempReg = operand_reg(ScratchReg),
-    Instr0 = x86_64_instr(mov(operand_mem_ref(mem_abs(base_expr(LabelStr))),
-        TempReg)),
+        Instr0 = x86_64_instr(
+            mov(operand_mem_ref(mem_abs(base_expr(LabelStr))), TempReg)),
     Instr1 = x86_64_instr(add(RvalOp, TempReg)),
     Instr2 = x86_64_instr(jmp(TempReg)),
-    Instrs = RvalInstrs ++ [Instr0] ++ [Instr1] ++ [Instr2].
-instr_to_x86_64(!RegMap, arbitrary_c_code(_, _, _), Instrs) :-
-    Instrs = [x86_64_comment("<<arbitrary_c_code>>")].
-instr_to_x86_64(!RegMap, if_val(Rval, CodeAddr), Instrs) :-
+        Instrs = RvalInstrs ++ [Instr0] ++ [Instr1] ++ [Instr2]
+    ;
+        Uinstr = arbitrary_c_code(_, _, _),
+        Instrs = [x86_64_comment("<<arbitrary_c_code>>")]
+    ;
+        Uinstr = if_val(Rval, CodeAddr),
     code_addr_type(CodeAddr, Target),
     transform_rval(!RegMap, Rval, Res0, Res1),
     (
@@ -309,14 +322,16 @@
     ),
     ll_backend.x86_64_out.operand_to_string(RvalOp, RvalStr),
     Instrs = [x86_64_directive(x86_64_pseudo_if(RvalStr)),
-        x86_64_instr(j(operand_label(Target), e)), x86_64_directive(endif)].
-instr_to_x86_64(!RegMap, save_maxfr(_), Instr) :-
-    Instr = [x86_64_comment("<<save_maxfr>>")].
-instr_to_x86_64(!RegMap, restore_maxfr(_), Instr) :-
-    Instr = [x86_64_comment("<<restore_maxfr>>")].
-instr_to_x86_64(!RegMap,
-        incr_hp(Lval, Tag0, Words0, Rval, _, _, MaybeRegionRval,
-            MaybeReuse), Instrs) :-
+            x86_64_instr(j(operand_label(Target), e)), x86_64_directive(endif)]
+    ;
+        Uinstr = save_maxfr(_),
+        Instrs = [x86_64_comment("<<save_maxfr>>")]
+    ;
+        Uinstr = restore_maxfr(_),
+        Instrs = [x86_64_comment("<<restore_maxfr>>")]
+    ;
+        Uinstr = incr_hp(Lval, Tag0, Words0, Rval, _, _, MaybeRegionRval,
+            MaybeReuse),
     (
         MaybeRegionRval = no
     ;
@@ -358,7 +373,8 @@
     (
         Words0 = yes(Words),
         IncrVal = operand_imm(imm32(int32(Words))),
-        ScratchReg0 = ll_backend.x86_64_regs.reg_map_get_scratch_reg(!.RegMap),
+            ScratchReg0 =
+                ll_backend.x86_64_regs.reg_map_get_scratch_reg(!.RegMap),
         reg_map_remove_scratch_reg(!RegMap),
         TempReg1 = operand_reg(ScratchReg0),
         ll_backend.x86_64_out.operand_to_string(RvalOp, RvalStr),
@@ -382,55 +398,87 @@
     ImmToReg = x86_64_instr(mov(RvalOp, TempReg2)),
     SetTag = x86_64_instr(or(operand_imm(imm32(int32(Tag))), TempReg2)),
     Instr1 = x86_64_instr(mov(TempReg2, LvalOp)),
-    Instrs = IncrAddrInstrs ++ [ImmToReg] ++ [SetTag] ++ [Instr1].
-instr_to_x86_64(!RegMap, mark_hp(_), Instr) :-
-    Instr = [x86_64_comment("<<mark_hp>>")].
-instr_to_x86_64(!RegMap, restore_hp(_), Instr) :-
-    Instr = [x86_64_comment("<<restore_hp>>")].
-instr_to_x86_64(!RegMap, free_heap(_), Instr) :-
-    Instr = [x86_64_comment("<<free_heap>>")].
-instr_to_x86_64(!RegMap, push_region_frame(_, _), Instr) :-
-    Instr = [x86_64_comment("<<push_region_frame>>")].
-instr_to_x86_64(!RegMap, region_fill_frame(_, _, _, _, _), Instr) :-
-    Instr = [x86_64_comment("<<region_fill_frame>>")].
-instr_to_x86_64(!RegMap, region_set_fixed_slot(_, _, _), Instr) :-
-    Instr = [x86_64_comment("<<region_set_fixed_slot>>")].
-instr_to_x86_64(!RegMap, use_and_maybe_pop_region_frame(_, _), Instr) :-
-    Instr = [x86_64_comment("<<use_and_maybe_pop_region_frame>>")].
-instr_to_x86_64(!RegMap, store_ticket(_), Instr) :-
-    Instr = [x86_64_comment("<<store_ticket>>")].
-instr_to_x86_64(!RegMap, reset_ticket(_, _), Instr) :-
-    Instr = [x86_64_comment("<<reset_ticket>>")].
-instr_to_x86_64(!RegMap, prune_ticket, Instr) :-
-    Instr = [x86_64_comment("<<prune_ticket>>")].
-instr_to_x86_64(!RegMap, discard_ticket, Instr) :-
-    Instr = [x86_64_comment("<<discard_ticket>>")].
-instr_to_x86_64(!RegMap, mark_ticket_stack(_), Instr) :-
-    Instr = [x86_64_comment("<<mark_ticket_stack>>")].
-instr_to_x86_64(!RegMap, prune_tickets_to(_), Instr) :-
-    Instr = [x86_64_comment("<<prune_tickets_to>>")].
-instr_to_x86_64(!RegMap, incr_sp(NumSlots, ProcName, _), Instrs) :-
+        Instrs = IncrAddrInstrs ++ [ImmToReg] ++ [SetTag] ++ [Instr1]
+    ;
+        Uinstr = mark_hp(_),
+        Instrs = [x86_64_comment("<<mark_hp>>")]
+    ;
+        Uinstr = restore_hp(_),
+        Instrs = [x86_64_comment("<<restore_hp>>")]
+    ;
+        Uinstr = free_heap(_),
+        Instrs = [x86_64_comment("<<free_heap>>")]
+    ;
+        Uinstr = push_region_frame(_, _),
+        Instrs = [x86_64_comment("<<push_region_frame>>")]
+    ;
+        Uinstr = region_fill_frame(_, _, _, _, _),
+        Instrs = [x86_64_comment("<<region_fill_frame>>")]
+    ;
+        Uinstr = region_set_fixed_slot(_, _, _),
+        Instrs = [x86_64_comment("<<region_set_fixed_slot>>")]
+    ;
+        Uinstr = use_and_maybe_pop_region_frame(_, _),
+        Instrs = [x86_64_comment("<<use_and_maybe_pop_region_frame>>")]
+    ;
+        Uinstr = store_ticket(_),
+        Instrs = [x86_64_comment("<<store_ticket>>")]
+    ;
+        Uinstr = reset_ticket(_, _),
+        Instrs = [x86_64_comment("<<reset_ticket>>")]
+    ;
+        Uinstr = prune_ticket,
+        Instrs = [x86_64_comment("<<prune_ticket>>")]
+    ;
+        Uinstr = discard_ticket,
+        Instrs = [x86_64_comment("<<discard_ticket>>")]
+    ;
+        Uinstr = mark_ticket_stack(_),
+        Instrs = [x86_64_comment("<<mark_ticket_stack>>")]
+    ;
+        Uinstr = prune_tickets_to(_),
+        Instrs = [x86_64_comment("<<prune_tickets_to>>")]
+    ;
+        Uinstr = incr_sp(NumSlots, ProcName, _),
     Instr1 = x86_64_comment("<<incr_sp>> " ++ ProcName),
     Instr2 = x86_64_instr(enter(uint16(NumSlots), uint8(0))),
-    Instrs = [Instr1, Instr2].
-instr_to_x86_64(!RegMap, decr_sp(NumSlots), Instrs) :-
+        Instrs = [Instr1, Instr2]
+    ;
+        Uinstr = decr_sp(NumSlots),
     DecrOp = operand_imm(imm32(int32(NumSlots))),
     ScratchReg = ll_backend.x86_64_regs.reg_map_get_scratch_reg(!.RegMap),
     ll_backend.x86_64_regs.reg_map_remove_scratch_reg(!RegMap),
     Instr = x86_64_instr(sub(DecrOp, operand_reg(ScratchReg))),
-    Instrs = [x86_64_comment("<<decr_sp>> "), Instr].
-instr_to_x86_64(!RegMap, decr_sp_and_return(NumSlots), Instrs) :-
+        Instrs = [x86_64_comment("<<decr_sp>> "), Instr]
+    ;
+        Uinstr = decr_sp_and_return(NumSlots),
     Instrs = [x86_64_comment("<<decr_sp_and_return>> " ++
-        string.int_to_string(NumSlots))].
-instr_to_x86_64(!RegMap, foreign_proc_code(_, _, _, _, _, _, _, _, _, _),
-        Instr) :-
-    Instr = [x86_64_comment("<<foreign_proc_code>>")].
-instr_to_x86_64(!RegMap, init_sync_term(_, _, _), Instr) :-
-    Instr = [x86_64_comment("<<init_sync_term>>")].
-instr_to_x86_64(!RegMap, fork_new_child(_, _), Instr) :-
-    Instr = [x86_64_comment("<<fork_new_child>>")].
-instr_to_x86_64(!RegMap, join_and_continue(_, _), Instr) :-
-    Instr = [x86_64_comment("<<join_and_continue>>")].
+            string.int_to_string(NumSlots))]
+    ;
+        Uinstr = foreign_proc_code(_, _, _, _, _, _, _, _, _, _),
+        Instrs = [x86_64_comment("<<foreign_proc_code>>")]
+    ;
+        Uinstr = init_sync_term(_, _, _),
+        Instrs = [x86_64_comment("<<init_sync_term>>")]
+    ;
+        Uinstr = fork_new_child(_, _),
+        Instrs = [x86_64_comment("<<fork_new_child>>")]
+    ;
+        Uinstr = join_and_continue(_, _),
+        Instrs = [x86_64_comment("<<join_and_continue>>")]
+    ;
+        Uinstr = lc_create_loop_control(_, _),
+        Instrs = [x86_64_comment("<<lc_create_loop_control>>")]
+    ;
+        Uinstr = lc_wait_free_slot(_, _, _),
+        Instrs = [x86_64_comment("<<lc_wait_free_slot>>")]
+    ;
+        Uinstr = lc_spawn_off(_, _, _),
+        Instrs = [x86_64_comment("<<lc_spawn_off>>")]
+    ;
+        Uinstr = lc_join_and_terminate(_, _),
+        Instrs = [x86_64_comment("<<lc_join_and_terminate>>")]
+    ).
 
     % Transform lval into either an x86_64 operand or x86_64 instructions.
     %
@@ -560,7 +608,8 @@
     MemRef = operand_mem_ref(mem_abs(base_expr(RvalStr1))),
     LoadAddr = x86_64_instr(lea(MemRef, TempReg1)),
     FieldNum = x86_64_instr(add(RvalOp2, TempReg1)),
-    Instrs3 = Instrs1 ++ Instrs2 ++ [x86_64_comment("<<field>>")] ++ [LoadAddr],
+    Instrs3 = Instrs1 ++ Instrs2 ++ [x86_64_comment("<<field>>")] ++
+        [LoadAddr],
     (
         Tag0 = yes(Tag),
         Mrbody = x86_64_instr(sub(operand_imm(imm32(int32(Tag))), TempReg1)),
@@ -692,7 +741,8 @@
     transform_rval(!RegMap, Rval, Op, _).
 transform_rval(!RegMap, mem_addr(framevar_ref(Rval)), Op, no) :-
     transform_rval(!RegMap, Rval, Op, _).
-transform_rval(!RegMap, mem_addr(heap_ref(Rval1, MaybeTag, Rval2)), no, Instrs) :-
+transform_rval(!RegMap, mem_addr(heap_ref(Rval1, MaybeTag, Rval2)), no,
+        Instrs) :-
     transform_rval(!RegMap, Rval1, Res0, Res1),
     transform_rval(!RegMap, Rval2, Res2, Res3),
     (
Index: compiler/middle_rec.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/middle_rec.m,v
retrieving revision 1.146
diff -u -b -r1.146 middle_rec.m
--- compiler/middle_rec.m	31 Aug 2011 07:59:33 -0000	1.146
+++ compiler/middle_rec.m	30 Sep 2011 04:40:01 -0000
@@ -544,8 +544,7 @@
         find_used_registers_lval(Lval, !Used),
         find_used_registers_rval(Rval, !Used)
     ;
-        Uinstr = incr_hp(Lval, _, _, Rval, _, _, MaybeRegionRval,
-            MaybeReuse),
+        Uinstr = incr_hp(Lval, _, _, Rval, _, _, MaybeRegionRval, MaybeReuse),
         find_used_registers_lval(Lval, !Used),
         find_used_registers_rval(Rval, !Used),
         (
@@ -598,6 +597,21 @@
         ; Uinstr = join_and_continue(Lval, _)
         ),
         find_used_registers_lval(Lval, !Used)
+    ;
+        Uinstr = lc_create_loop_control(_, LCLval),
+        find_used_registers_lval(LCLval, !Used)
+    ;
+        Uinstr = lc_wait_free_slot(LCRval, LCSLval, _),
+        find_used_registers_rval(LCRval, !Used),
+        find_used_registers_lval(LCSLval, !Used)
+    ;
+        Uinstr = lc_spawn_off(LCRval, LCSRval, _),
+        find_used_registers_rval(LCRval, !Used),
+        find_used_registers_rval(LCSRval, !Used)
+    ;
+        Uinstr = lc_join_and_terminate(LCRval, LCSRval),
+        find_used_registers_rval(LCRval, !Used),
+        find_used_registers_rval(LCSRval, !Used)
     ).
 
 :- pred find_used_registers_components(
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.224
diff -u -b -r1.224 opt_debug.m
--- compiler/opt_debug.m	27 Sep 2011 00:49:25 -0000	1.224
+++ compiler/opt_debug.m	28 Sep 2011 09:44:42 -0000
@@ -1074,18 +1074,6 @@
         Instr = decr_sp_and_return(Size),
         Str = "decr_sp_and_return(" ++ int_to_string(Size) ++ ")"
     ;
-        Instr = init_sync_term(Lval, N, TSStringIndex),
-        Str = "init_sync_term(" ++ dump_lval(MaybeProcLabel, Lval) ++ ", "
-            ++ int_to_string(N) ++ ", " ++ int_to_string(TSStringIndex) ++ ")"
-    ;
-        Instr = fork_new_child(Lval, Child),
-        Str = "fork_new_child(" ++ dump_lval(MaybeProcLabel, Lval)
-            ++ dump_label(MaybeProcLabel, Child) ++ ", " ++ ")"
-    ;
-        Instr = join_and_continue(Lval, Label),
-        Str = "join_and_continue(" ++ dump_lval(MaybeProcLabel, Lval) ++ ", "
-            ++ dump_label(MaybeProcLabel, Label) ++ ")"
-    ;
         Instr = foreign_proc_code(Decls, Comps, MCM, MFNL, MFL, MFOL, MNF, MDL,
             SSR, MD),
         Str = "foreign_proc_code(\n"
@@ -1100,6 +1088,36 @@
             ++ dump_bool_msg("stack slot ref:", SSR)
             ++ dump_may_duplicate(MD) ++ "\n"
             ++ ")"
+    ;
+        Instr = init_sync_term(Lval, N, TSStringIndex),
+        Str = "init_sync_term(" ++ dump_lval(MaybeProcLabel, Lval) ++ ", "
+            ++ int_to_string(N) ++ ", " ++ int_to_string(TSStringIndex) ++ ")"
+    ;
+        Instr = fork_new_child(Lval, Child),
+        Str = "fork_new_child(" ++ dump_lval(MaybeProcLabel, Lval)
+            ++ dump_label(MaybeProcLabel, Child) ++ ", " ++ ")"
+    ;
+        Instr = join_and_continue(Lval, Label),
+        Str = "join_and_continue(" ++ dump_lval(MaybeProcLabel, Lval) ++ ", "
+            ++ dump_label(MaybeProcLabel, Label) ++ ")"
+    ;
+        Instr = lc_create_loop_control(NumSlots, LCLval),
+        Str = "lc_create_loop_control(" ++ int_to_string(NumSlots) ++ ", "
+            ++ dump_lval(MaybeProcLabel, LCLval) ++ ")"
+    ;
+        Instr = lc_wait_free_slot(LCRval, LCSLval, Label),
+        Str = "lc_wait_free_slot(" ++ dump_rval(MaybeProcLabel, LCRval)
+            ++ dump_lval(MaybeProcLabel, LCSLval)
+            ++ dump_label(MaybeProcLabel, Label) ++ ")"
+    ;
+        Instr = lc_spawn_off(LCRval, LCSRval, Label),
+        Str = "lc_spawn_off(" ++ dump_rval(MaybeProcLabel, LCRval)
+            ++ dump_rval(MaybeProcLabel, LCSRval)
+            ++ dump_label(MaybeProcLabel, Label) ++ ")"
+    ;
+        Instr = lc_join_and_terminate(LCRval, LCSRval),
+        Str = "lc_join_and_terminate(" ++ dump_rval(MaybeProcLabel, LCRval)
+            ++ dump_rval(MaybeProcLabel, LCSRval) ++ ")"
     ).
 
 :- func dump_embedded_stack_frame_id(embedded_stack_frame_id) = string.
Index: compiler/opt_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_util.m,v
retrieving revision 1.178
diff -u -b -r1.178 opt_util.m
--- compiler/opt_util.m	16 Sep 2011 07:03:35 -0000	1.178
+++ compiler/opt_util.m	30 Sep 2011 04:42:22 -0000
@@ -872,6 +872,7 @@
         ; Uinstr = arbitrary_c_code(_, _, _)
         ; Uinstr = discard_ticket
         ; Uinstr = prune_ticket
+        ; Uinstr = lc_join_and_terminate(_, _)
         ),
         Refers = no
     ;
@@ -887,6 +888,7 @@
         ; Uinstr = init_sync_term(_, _, _)
         ; Uinstr = fork_new_child(_, _)
         ; Uinstr = join_and_continue(_, _)
+        ; Uinstr = lc_spawn_off(_, _, _)
         ),
         Refers = yes
     ;
@@ -903,19 +905,27 @@
         Uinstr = goto(CodeAddr),
         Refers = code_addr_refers_to_stack(CodeAddr)
     ;
-        Uinstr = computed_goto(Rval, _Labels),
-        Refers = rval_refers_stackvars(Rval)
-    ;
         Uinstr = if_val(Rval, CodeAddr),
         Refers = bool.or(
             rval_refers_stackvars(Rval),
             code_addr_refers_to_stack(CodeAddr))
     ;
-        Uinstr = save_maxfr(Lval),
+        ( Uinstr = save_maxfr(Lval)
+        ; Uinstr = restore_maxfr(Lval)
+        ; Uinstr = mark_hp(Lval)
+        ; Uinstr = store_ticket(Lval)
+        ; Uinstr = mark_ticket_stack(Lval)
+        ; Uinstr = lc_create_loop_control(_, Lval)
+        ),
         Refers = lval_refers_stackvars(Lval)
     ;
-        Uinstr = restore_maxfr(Lval),
-        Refers = lval_refers_stackvars(Lval)
+        ( Uinstr = computed_goto(Rval, _Labels)
+        ; Uinstr = restore_hp(Rval)
+        ; Uinstr = free_heap(Rval)
+        ; Uinstr = reset_ticket(Rval, _Reason)
+        ; Uinstr = prune_tickets_to(Rval)
+        ),
+        Refers = rval_refers_stackvars(Rval)
     ;
         Uinstr = incr_hp(Lval, _, _, Rval, _, _, MaybeRegionRval,
             MaybeReuse),
@@ -944,30 +954,14 @@
             Refers = !.Refers
         )
     ;
-        Uinstr = mark_hp(Lval),
-        Refers = lval_refers_stackvars(Lval)
-    ;
-        Uinstr = restore_hp(Rval),
-        Refers = rval_refers_stackvars(Rval)
-    ;
-        Uinstr = free_heap(Rval),
-        Refers = rval_refers_stackvars(Rval)
-    ;
-        Uinstr = store_ticket(Lval),
-        Refers = lval_refers_stackvars(Lval)
-    ;
-        Uinstr = reset_ticket(Rval, _Reason),
-        Refers = rval_refers_stackvars(Rval)
-    ;
-        Uinstr = mark_ticket_stack(Lval),
-        Refers = lval_refers_stackvars(Lval)
-    ;
-        Uinstr = prune_tickets_to(Rval),
-        Refers = rval_refers_stackvars(Rval)
-    ;
         Uinstr = foreign_proc_code(_, Components, _, _, _, _, _, _, _, _),
         Refers = bool.or_list(list.map(foreign_proc_component_refers_stackvars,
             Components))
+    ;
+        Uinstr = lc_wait_free_slot(Rval, Lval, _),
+        Refers = bool.or(
+            rval_refers_stackvars(Rval),
+            lval_refers_stackvars(Lval))
     ).
 
 :- func foreign_proc_component_refers_stackvars(foreign_proc_component) = bool.
@@ -1079,42 +1073,55 @@
     Rval1 = Rval2,
     Taken = yes.
 
-can_instr_branch_away(comment(_)) = no.
-can_instr_branch_away(livevals(_)) = no.
-can_instr_branch_away(block(_, _, _)) = yes.
-can_instr_branch_away(assign(_, _)) = no.
-can_instr_branch_away(keep_assign(_, _)) = no.
-can_instr_branch_away(llcall(_, _, _, _, _, _)) = yes.
-can_instr_branch_away(mkframe(_, _)) = no.
-can_instr_branch_away(label(_)) = no.
-can_instr_branch_away(goto(_)) = yes.
-can_instr_branch_away(computed_goto(_, _)) = yes.
-can_instr_branch_away(arbitrary_c_code(_, _, _)) = no.
-can_instr_branch_away(if_val(_, _)) = yes.
-can_instr_branch_away(save_maxfr(_)) = no.
-can_instr_branch_away(restore_maxfr(_)) = no.
-can_instr_branch_away(incr_hp(_, _, _, _, _, _, _, _)) = no.
-can_instr_branch_away(mark_hp(_)) = no.
-can_instr_branch_away(restore_hp(_)) = no.
-can_instr_branch_away(free_heap(_)) = no.
-can_instr_branch_away(push_region_frame(_, _)) = no.
-can_instr_branch_away(region_fill_frame(_, _, _, _, _)) = no.
-can_instr_branch_away(region_set_fixed_slot(_, _, _)) = no.
-can_instr_branch_away(use_and_maybe_pop_region_frame(_, _)) = no.
-can_instr_branch_away(store_ticket(_)) = no.
-can_instr_branch_away(reset_ticket(_, _)) = no.
-can_instr_branch_away(discard_ticket) = no.
-can_instr_branch_away(prune_ticket) = no.
-can_instr_branch_away(mark_ticket_stack(_)) = no.
-can_instr_branch_away(prune_tickets_to(_)) = no.
-can_instr_branch_away(incr_sp(_, _, _)) = no.
-can_instr_branch_away(decr_sp(_)) = no.
-can_instr_branch_away(decr_sp_and_return(_)) = yes.
-can_instr_branch_away(init_sync_term(_, _, _)) = no.
-can_instr_branch_away(fork_new_child(_, _)) = no.
-can_instr_branch_away(join_and_continue(_, _)) = yes.
-can_instr_branch_away(foreign_proc_code(_, Comps, _, _, _, _, _, _, _, _)) =
-    can_components_branch_away(Comps).
+can_instr_branch_away(Uinstr) = CanBranchAway :-
+    (
+        ( Uinstr = comment(_)
+        ; Uinstr = livevals(_)
+        ; Uinstr = assign(_, _)
+        ; Uinstr = keep_assign(_, _)
+        ; Uinstr = mkframe(_, _)
+        ; Uinstr = label(_)
+        ; Uinstr = arbitrary_c_code(_, _, _)
+        ; Uinstr = save_maxfr(_)
+        ; Uinstr = restore_maxfr(_)
+        ; Uinstr = incr_hp(_, _, _, _, _, _, _, _)
+        ; Uinstr = mark_hp(_)
+        ; Uinstr = restore_hp(_)
+        ; Uinstr = free_heap(_)
+        ; Uinstr = push_region_frame(_, _)
+        ; Uinstr = region_fill_frame(_, _, _, _, _)
+        ; Uinstr = region_set_fixed_slot(_, _, _)
+        ; Uinstr = use_and_maybe_pop_region_frame(_, _)
+        ; Uinstr = store_ticket(_)
+        ; Uinstr = reset_ticket(_, _)
+        ; Uinstr = discard_ticket
+        ; Uinstr = prune_ticket
+        ; Uinstr = mark_ticket_stack(_)
+        ; Uinstr = prune_tickets_to(_)
+        ; Uinstr = incr_sp(_, _, _)
+        ; Uinstr = decr_sp(_)
+        ; Uinstr = init_sync_term(_, _, _)
+        ; Uinstr = fork_new_child(_, _)
+        ; Uinstr = lc_create_loop_control(_, _)
+        ; Uinstr = lc_wait_free_slot(_, _, _)
+        ; Uinstr = lc_join_and_terminate(_, _)
+        ),
+        CanBranchAway = no
+    ;
+        ( Uinstr = block(_, _, _)
+        ; Uinstr = llcall(_, _, _, _, _, _)
+        ; Uinstr = goto(_)
+        ; Uinstr = computed_goto(_, _)
+        ; Uinstr = if_val(_, _)
+        ; Uinstr = decr_sp_and_return(_)
+        ; Uinstr = join_and_continue(_, _)
+        ; Uinstr = lc_spawn_off(_, _, _)
+        ),
+        CanBranchAway = yes
+    ;
+        Uinstr = foreign_proc_code(_, Comps, _, _, _, _, _, _, _, _),
+        CanBranchAway = can_components_branch_away(Comps)
+    ).
 
 :- func can_components_branch_away(list(foreign_proc_component)) = bool.
 
@@ -1190,10 +1197,14 @@
 can_instr_fall_through(incr_sp(_, _, _)) = yes.
 can_instr_fall_through(decr_sp(_)) = yes.
 can_instr_fall_through(decr_sp_and_return(_)) = no.
+can_instr_fall_through(foreign_proc_code(_, _, _, _, _, _, _, _, _, _)) = yes.
 can_instr_fall_through(init_sync_term(_, _, _)) = yes.
 can_instr_fall_through(fork_new_child(_, _)) = yes.
 can_instr_fall_through(join_and_continue(_, _)) = no.
-can_instr_fall_through(foreign_proc_code(_, _, _, _, _, _, _, _, _, _)) = yes.
+can_instr_fall_through(lc_create_loop_control(_, _)) = yes.
+can_instr_fall_through(lc_wait_free_slot(_, _, _)) = yes.
+can_instr_fall_through(lc_spawn_off(_, _, _)) = yes.
+can_instr_fall_through(lc_join_and_terminate(_, _)) = no.
 
     % Check whether an instruction sequence can possibly fall through
     % to the next instruction without using its label.
@@ -1241,10 +1252,14 @@
 can_use_livevals(incr_sp(_, _, _), no).
 can_use_livevals(decr_sp(_), no).
 can_use_livevals(decr_sp_and_return(_), yes).
+can_use_livevals(foreign_proc_code(_, _, _, _, _, _, _, _, _, _), no).
 can_use_livevals(init_sync_term(_, _, _), no).
 can_use_livevals(fork_new_child(_, _), no).
 can_use_livevals(join_and_continue(_, _), no).
-can_use_livevals(foreign_proc_code(_, _, _, _, _, _, _, _, _, _), no).
+can_use_livevals(lc_create_loop_control(_, _), no).
+can_use_livevals(lc_wait_free_slot(_, _, _), no).
+can_use_livevals(lc_spawn_off(_, _, _), yes).
+can_use_livevals(lc_join_and_terminate(_, _), no).
 
 instr_labels(Instr, Labels, CodeAddrs) :-
     instr_labels_2(Instr, Labels0, CodeAddrs1),
@@ -1289,6 +1304,8 @@
         ; Uinstr = incr_sp(_, _, _)
         ; Uinstr = decr_sp(_)
         ; Uinstr = init_sync_term(_, _, _)
+        ; Uinstr = lc_create_loop_control(_, _)
+        ; Uinstr = lc_join_and_terminate(_, _)
         ),
         Labels = [],
         CodeAddrs = []
@@ -1316,7 +1333,10 @@
         Labels = [Child],
         CodeAddrs = []
     ;
-        Uinstr = join_and_continue(_, Label),
+        ( Uinstr = join_and_continue(_, Label)
+        ; Uinstr = lc_wait_free_slot(_, _, Label)
+        ; Uinstr = lc_spawn_off(_, _, Label)
+        ),
         Labels = [Label],
         CodeAddrs = []
     ;
@@ -1378,6 +1398,11 @@
         ; Uinstr = decr_sp(_)
         ; Uinstr = init_sync_term(_, _, _)
         ; Uinstr = fork_new_child(_, _)
+        ; Uinstr = lc_create_loop_control(_, _)
+        ; Uinstr = lc_join_and_terminate(_, _)
+        ; Uinstr = lc_wait_free_slot(_, _, _Label)
+        % The label in an lc_wait_free_slot instruction is NOT the possible
+        % target of a branch.
         ),
         Labels = [],
         CodeAddrs = []
@@ -1406,7 +1431,9 @@
         % XXX see the comment in instr_labels_2.
         unexpected($module, $pred, "decr_sp_and_return")
     ;
-        Uinstr = join_and_continue(_, Label),
+        ( Uinstr = join_and_continue(_, Label)
+        ; Uinstr = lc_spawn_off(_, _, Label)
+        ),
         Labels = [Label],
         CodeAddrs = []
     ;
@@ -1544,12 +1571,17 @@
 instr_rvals_and_lvals(incr_sp(_, _, _), [], []).
 instr_rvals_and_lvals(decr_sp(_), [], []).
 instr_rvals_and_lvals(decr_sp_and_return(_), [], []).
-instr_rvals_and_lvals(init_sync_term(Lval, _, _), [], [Lval]).
-instr_rvals_and_lvals(fork_new_child(Lval, _), [], [Lval]).
-instr_rvals_and_lvals(join_and_continue(Lval, _), [], [Lval]).
 instr_rvals_and_lvals(foreign_proc_code(_, Cs, _, _, _, _, _, _, _, _),
         Rvals, Lvals) :-
     foreign_proc_components_get_rvals_and_lvals(Cs, Rvals, Lvals).
+instr_rvals_and_lvals(init_sync_term(Lval, _, _), [], [Lval]).
+instr_rvals_and_lvals(fork_new_child(Lval, _), [], [Lval]).
+instr_rvals_and_lvals(join_and_continue(Lval, _), [], [Lval]).
+instr_rvals_and_lvals(lc_create_loop_control(_, Lval), [], [Lval]).
+instr_rvals_and_lvals(lc_wait_free_slot(Rval, Lval, _), [Rval], [Lval]).
+instr_rvals_and_lvals(lc_spawn_off(LCRval, LCSRval, _), [LCRval, LCSRval], []).
+instr_rvals_and_lvals(lc_join_and_terminate(LCRval, LCSRval),
+    [LCRval, LCSRval], []).
 
     % Extract the rvals and lvals from the foreign_proc_components.
     %
@@ -1724,15 +1756,26 @@
 count_temps_instr(incr_sp(_, _, _), !R, !F).
 count_temps_instr(decr_sp(_), !R, !F).
 count_temps_instr(decr_sp_and_return(_), !R, !F).
+count_temps_instr(foreign_proc_code(_, Comps, _, _, _, _, _, _, _, _),
+        !R, !F) :-
+    count_temps_components(Comps, !R, !F).
 count_temps_instr(init_sync_term(Lval, _, _), !R, !F) :-
     count_temps_lval(Lval, !R, !F).
 count_temps_instr(fork_new_child(Lval, _), !R, !F) :-
     count_temps_lval(Lval, !R, !F).
 count_temps_instr(join_and_continue(Lval, _), !R, !F) :-
     count_temps_lval(Lval, !R, !F).
-count_temps_instr(foreign_proc_code(_, Comps, _, _, _, _, _, _, _, _),
-        !R, !F) :-
-    count_temps_components(Comps, !R, !F).
+count_temps_instr(lc_create_loop_control(_, Lval), !R, !F) :-
+    count_temps_lval(Lval, !R, !F).
+count_temps_instr(lc_wait_free_slot(Rval, Lval, _), !R, !F) :-
+    count_temps_rval(Rval, !R, !F),
+    count_temps_lval(Lval, !R, !F).
+count_temps_instr(lc_spawn_off(LCRval, LCSRval, _), !R, !F) :-
+    count_temps_rval(LCRval, !R, !F),
+    count_temps_rval(LCSRval, !R, !F).
+count_temps_instr(lc_join_and_terminate(LCRval, LCSRval), !R, !F) :-
+    count_temps_rval(LCRval, !R, !F),
+    count_temps_rval(LCSRval, !R, !F).
 
 :- pred count_temps_components(list(foreign_proc_component)::in,
     int::in, int::out, int::in, int::out) is det.
@@ -1926,6 +1969,8 @@
         ; Uinstr = incr_sp(_, _, _)
         ; Uinstr = decr_sp(_)
         ; Uinstr = decr_sp_and_return(_)
+        ; Uinstr = push_region_frame(_, _)
+        ; Uinstr = use_and_maybe_pop_region_frame(_, _)
         ),
         Touch = no
     ;
@@ -1943,17 +1988,40 @@
         ),
         Touch = yes
     ;
-        Uinstr = block(_, _, _),
-        % Blocks aren't introduced until after the last user of this predicate.
-        unexpected($module, $pred, "block")
+        ( Uinstr = mark_hp(Lval)
+        ; Uinstr = store_ticket(Lval)
+        ; Uinstr = mark_ticket_stack(Lval)
+        ; Uinstr = lc_create_loop_control(_, Lval)
+        ),
+        Touch = touches_nondet_ctrl_lval(Lval)
+    ;
+        ( Uinstr = restore_hp(Rval)
+        ; Uinstr = free_heap(Rval)
+        ; Uinstr = region_set_fixed_slot(_SetOp, _EmbeddedStackFrame, Rval)
+        ; Uinstr = reset_ticket(Rval, _)
+        ; Uinstr = prune_tickets_to(Rval)
+        ),
+        Touch = touches_nondet_ctrl_rval(Rval)
     ;
         ( Uinstr = assign(Lval, Rval)
         ; Uinstr = keep_assign(Lval, Rval)
+        ; Uinstr = lc_wait_free_slot(Rval, Lval, _)
         ),
         TouchLval = touches_nondet_ctrl_lval(Lval),
         TouchRval = touches_nondet_ctrl_rval(Rval),
         bool.or(TouchLval, TouchRval, Touch)
     ;
+        ( Uinstr = lc_spawn_off(LCRval, LCSRval, _)
+        ; Uinstr = lc_join_and_terminate(LCRval, LCSRval)
+        ),
+        TouchLC = touches_nondet_ctrl_rval(LCRval),
+        TouchLCS = touches_nondet_ctrl_rval(LCSRval),
+        bool.or(TouchLC, TouchLCS, Touch)
+    ;
+        Uinstr = block(_, _, _),
+        % Blocks aren't introduced until after the last user of this predicate.
+        unexpected($module, $pred, "block")
+    ;
         Uinstr = incr_hp(Lval, _, _, Rval, _, _, MaybeRegionRval,
             MaybeReuse),
         some [!Touch] (
@@ -1981,18 +2049,6 @@
             Touch = !.Touch
         )
     ;
-        Uinstr = mark_hp(Lval),
-        Touch = touches_nondet_ctrl_lval(Lval)
-    ;
-        Uinstr = restore_hp(Rval),
-        Touch = touches_nondet_ctrl_rval(Rval)
-    ;
-        Uinstr = free_heap(Rval),
-        Touch = touches_nondet_ctrl_rval(Rval)
-    ;
-        Uinstr = push_region_frame(_StackId, _EmbeddedStackFrame),
-        Touch = no
-    ;
         Uinstr = region_fill_frame(_FillOp, _EmbeddedStackFrame, IdRval,
             NumLval, AddrLval),
         Touch = bool.or(
@@ -2001,24 +2057,6 @@
                 touches_nondet_ctrl_lval(NumLval),
                 touches_nondet_ctrl_lval(AddrLval)))
     ;
-        Uinstr = region_set_fixed_slot(_SetOp, _EmbeddedStackFrame, ValueRval),
-        Touch = touches_nondet_ctrl_rval(ValueRval)
-    ;
-        Uinstr = use_and_maybe_pop_region_frame(_UseOp, _EmbeddedStackFrame),
-        Touch = no
-    ;
-        Uinstr = store_ticket(Lval),
-        Touch = touches_nondet_ctrl_lval(Lval)
-    ;
-        Uinstr = reset_ticket(Rval, _),
-        Touch = touches_nondet_ctrl_rval(Rval)
-    ;
-        Uinstr = mark_ticket_stack(Lval),
-        Touch = touches_nondet_ctrl_lval(Lval)
-    ;
-        Uinstr = prune_tickets_to(Rval),
-        Touch = touches_nondet_ctrl_rval(Rval)
-    ;
         Uinstr = foreign_proc_code(_, Components, _, _, _, _, _, _, _, _),
         Touch = touches_nondet_ctrl_components(Components)
     ).
@@ -2489,26 +2527,6 @@
         ),
         Uinstr = prune_tickets_to(Rval)
     ;
-        Uinstr0 = init_sync_term(Lval0, NumConjuncts, TSStringIndex),
-        (
-            ReplData = yes,
-            replace_labels_lval(Lval0, Lval, ReplMap)
-        ;
-            ReplData = no,
-            Lval = Lval0
-        ),
-        Uinstr = init_sync_term(Lval, NumConjuncts, TSStringIndex)
-    ;
-        Uinstr0 = fork_new_child(Lval0, Child0),
-        replace_labels_lval(Lval0, Lval, ReplMap),
-        replace_labels_label(Child0, Child, ReplMap),
-        Uinstr = fork_new_child(Lval, Child)
-    ;
-        Uinstr0 = join_and_continue(Lval0, Label0),
-        replace_labels_label(Label0, Label, ReplMap),
-        replace_labels_lval(Lval0, Lval, ReplMap),
-        Uinstr = join_and_continue(Lval, Label)
-    ;
         Uinstr0 = foreign_proc_code(Decls, Comps0, MayCallMercury,
             MaybeFix, MaybeLayout, MaybeOnlyLayout, MaybeSub0, MaybeDef,
             StackSlotRef, MayDupl),
@@ -2561,6 +2579,47 @@
         Uinstr = foreign_proc_code(Decls, Comps, MayCallMercury,
             MaybeFix, MaybeLayout, MaybeOnlyLayout, MaybeSub, MaybeDef,
             StackSlotRef, MayDupl)
+    ;
+        Uinstr0 = init_sync_term(Lval0, NumConjuncts, TSStringIndex),
+        (
+            ReplData = yes,
+            replace_labels_lval(Lval0, Lval, ReplMap)
+        ;
+            ReplData = no,
+            Lval = Lval0
+        ),
+        Uinstr = init_sync_term(Lval, NumConjuncts, TSStringIndex)
+    ;
+        Uinstr0 = fork_new_child(Lval0, Child0),
+        replace_labels_lval(Lval0, Lval, ReplMap),
+        replace_labels_label(Child0, Child, ReplMap),
+        Uinstr = fork_new_child(Lval, Child)
+    ;
+        Uinstr0 = join_and_continue(Lval0, Label0),
+        replace_labels_lval(Lval0, Lval, ReplMap),
+        replace_labels_label(Label0, Label, ReplMap),
+        Uinstr = join_and_continue(Lval, Label)
+    ;
+        Uinstr0 = lc_create_loop_control(NumSLots, Lval0),
+        replace_labels_lval(Lval0, Lval, ReplMap),
+        Uinstr = lc_create_loop_control(NumSLots, Lval)
+    ;
+        Uinstr0 = lc_wait_free_slot(Rval0, Lval0, Label0),
+        replace_labels_rval(Rval0, Rval, ReplMap),
+        replace_labels_lval(Lval0, Lval, ReplMap),
+        replace_labels_label(Label0, Label, ReplMap),
+        Uinstr = lc_wait_free_slot(Rval, Lval, Label)
+    ;
+        Uinstr0 = lc_spawn_off(LCRval0, LCSRval0, Label0),
+        replace_labels_rval(LCRval0, LCRval, ReplMap),
+        replace_labels_rval(LCSRval0, LCSRval, ReplMap),
+        replace_labels_label(Label0, Label, ReplMap),
+        Uinstr = lc_spawn_off(LCRval, LCSRval, Label)
+    ;
+        Uinstr0 = lc_join_and_terminate(LCRval0, LCSRval0),
+        replace_labels_rval(LCRval0, LCRval, ReplMap),
+        replace_labels_rval(LCSRval0, LCSRval, ReplMap),
+        Uinstr = lc_join_and_terminate(LCRval, LCSRval)
     ).
 
 replace_labels_comps([], [], _).
Index: compiler/peephole.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/peephole.m,v
retrieving revision 1.107
diff -u -b -r1.107 peephole.m
--- compiler/peephole.m	17 Jun 2011 07:51:18 -0000	1.107
+++ compiler/peephole.m	28 Sep 2011 10:16:40 -0000
@@ -539,6 +539,8 @@
             TypeMsg, MayUseAtomicAlloc, MaybeRegionId, MaybeReuse),
         ( Target = OldLval ->
             MaybeInstr = no
+        ; Target = mem_ref(_) ->
+            MaybeInstr = no
         ;
             replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
                 SizeRval0, SizeRval),
@@ -576,13 +578,47 @@
         Instr = llds_instr(Uinstr, Comment),
         MaybeInstr = yes(Instr)
     ;
+        Uinstr0 = lc_wait_free_slot(Rval0, Lval0, Label),
+        ( Lval0 = OldLval ->
+            MaybeInstr = no
+        ; Lval0 = mem_ref(_) ->
+            MaybeInstr = no
+        ;
+            replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
+                Rval0, Rval),
+            Uinstr = lc_wait_free_slot(Rval, Lval0, Label),
+            Instr = llds_instr(Uinstr, Comment),
+            MaybeInstr = yes(Instr)
+        )
+    ;
+        Uinstr0 = lc_spawn_off(LCRval0, LCSRval0, Label),
+        replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
+            LCRval0, LCRval),
+        replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
+            LCSRval0, LCSRval),
+        Uinstr = lc_spawn_off(LCRval, LCSRval, Label),
+        Instr = llds_instr(Uinstr, Comment),
+        MaybeInstr = yes(Instr)
+    ;
+        Uinstr0 = lc_join_and_terminate(LCRval0, LCSRval0),
+        replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
+            LCRval0, LCRval),
+        replace_tagged_ptr_components_in_rval(OldLval, OldTag, OldBase,
+            LCSRval0, LCSRval),
+        Uinstr = lc_join_and_terminate(LCRval, LCSRval),
+        Instr = llds_instr(Uinstr, Comment),
+        MaybeInstr = yes(Instr)
+    ;
         ( Uinstr0 = save_maxfr(Lval0)
         ; Uinstr0 = mark_hp(Lval0)
         ; Uinstr0 = store_ticket(Lval0)
         ; Uinstr0 = mark_ticket_stack(Lval0)
+        ; Uinstr0 = lc_create_loop_control(_NumSlots, Lval0)
         ),
         ( Lval0 = OldLval ->
             MaybeInstr = no
+        ; Lval0 = mem_ref(_) ->
+            MaybeInstr = no
         ;
             MaybeInstr = yes(Instr0)
         )
@@ -593,9 +629,7 @@
         ; Uinstr0 = prune_ticket
         ; Uinstr0 = discard_ticket
         ),
-        Uinstr = Uinstr0,
-        Instr = llds_instr(Uinstr, Comment),
-        MaybeInstr = yes(Instr)
+        MaybeInstr = yes(Instr0)
     ;
         ( Uinstr0 = block(_, _, _)
         ; Uinstr0 = llcall(_, _, _, _, _, _)
Index: compiler/reassign.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/reassign.m,v
retrieving revision 1.36
diff -u -b -r1.36 reassign.m
--- compiler/reassign.m	23 May 2011 05:08:11 -0000	1.36
+++ compiler/reassign.m	28 Sep 2011 10:45:33 -0000
@@ -76,7 +76,6 @@
 %   ...
 %   MR_field(MR_mktag(1), MR_r5, 1) = r2;
 %
-%
 % The lvals on which TargetLval depends need not include TargetLval itself,
 % since an assignment to TargetLval will in any case override the previous
 % entry for TargetLval in the known contents map. This takes care of code
@@ -209,29 +208,20 @@
         Uinstr0 = if_val(_, _),
         !:RevInstrs = [Instr0 | !.RevInstrs]
     ;
-        Uinstr0 = save_maxfr(Target),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(Target, !KnownContentsMap, !DepLvalMap),
-        map.delete(Target, !KnownContentsMap)
-    ;
-        Uinstr0 = restore_maxfr(_),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(hp, !KnownContentsMap, !DepLvalMap)
-    ;
-        Uinstr0 = incr_hp(Target, _, _, _, _, _, _, _),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(Target, !KnownContentsMap, !DepLvalMap),
-        clobber_dependents(hp, !KnownContentsMap, !DepLvalMap)
-    ;
-        Uinstr0 = mark_hp(Target),
+        ( Uinstr0 = save_maxfr(Target)
+        ; Uinstr0 = incr_hp(Target, _, _, _, _, _, _, _)
+        ; Uinstr0 = mark_hp(Target)
+        ; Uinstr0 = restore_maxfr(_), Target = maxfr
+        ; Uinstr0 = restore_hp(_), Target = hp
+        ; Uinstr0 = store_ticket(Target)
+        ; Uinstr0 = mark_ticket_stack(Target)
+        ; Uinstr0 = lc_create_loop_control(_, Target)
+        ; Uinstr0 = lc_wait_free_slot(_, Target, _)
+        ),
         !:RevInstrs = [Instr0 | !.RevInstrs],
         clobber_dependents(Target, !KnownContentsMap, !DepLvalMap),
         map.delete(Target, !KnownContentsMap)
     ;
-        Uinstr0 = restore_hp(_),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(hp, !KnownContentsMap, !DepLvalMap)
-    ;
         Uinstr0 = free_heap(_),
         !:RevInstrs = [Instr0 | !.RevInstrs]
         % There is no need to update KnownContentsMap since later code
@@ -252,31 +242,20 @@
         map.delete(NumLval, !KnownContentsMap),
         map.delete(AddrLval, !KnownContentsMap)
     ;
-        Uinstr0 = store_ticket(Target),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(Target, !KnownContentsMap, !DepLvalMap)
-    ;
         Uinstr0 = reset_ticket(_, _),
         !:RevInstrs = [Instr0 | !.RevInstrs],
         % The reset operation may modify any lval.
         !:KnownContentsMap = map.init,
         !:DepLvalMap = map.init
     ;
-        Uinstr0 = prune_ticket,
-        !:RevInstrs = [Instr0 | !.RevInstrs]
-    ;
-        Uinstr0 = discard_ticket,
-        !:RevInstrs = [Instr0 | !.RevInstrs]
-    ;
-        Uinstr0 = mark_ticket_stack(Target),
-        !:RevInstrs = [Instr0 | !.RevInstrs],
-        clobber_dependents(Target, !KnownContentsMap, !DepLvalMap)
-    ;
-        Uinstr0 = prune_tickets_to(_),
+        ( Uinstr0 = prune_ticket
+        ; Uinstr0 = discard_ticket
+        ; Uinstr0 = prune_tickets_to(_)
+        % ; Uinstr0 = discard_tickets_to(_)
+        ; Uinstr0 = lc_spawn_off(_, _, _)
+        ; Uinstr0 = lc_join_and_terminate(_, _)
+        ),
         !:RevInstrs = [Instr0 | !.RevInstrs]
-%   ;
-%       Uinstr0 = discard_tickets_to(_),
-%       !:RevInstrs = [Instr0 | !.RevInstrs]
     ;
         Uinstr0 = incr_sp(_, _, _),
         !:RevInstrs = [Instr0 | !.RevInstrs],
Index: compiler/use_local_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/use_local_vars.m,v
retrieving revision 1.48
diff -u -b -r1.48 use_local_vars.m
--- compiler/use_local_vars.m	25 May 2011 08:04:27 -0000	1.48
+++ compiler/use_local_vars.m	30 Sep 2011 05:31:32 -0000
@@ -599,26 +599,59 @@
 :- pred substitute_lval_in_instr_until_defn_2(lval::in, lval::in,
     instruction::in, instruction::out,
     list(instruction)::in, list(instruction)::out, int::in, int::out) is det.
+:- pragma inline(substitute_lval_in_instr_until_defn_2/8).
 
 substitute_lval_in_instr_until_defn_2(OldLval, NewLval, !Instr, !Instrs, !N) :-
-    !.Instr = llds_instr(Uinstr0, _),
+    !.Instr = llds_instr(Uinstr0, Comment),
     (
         Uinstr0 = block(_, _, _),
         unexpected($module, $pred, "block")
     ;
-        Uinstr0 = assign(Lval, _),
+        Uinstr0 = assign(Lval, Rval0),
         ( assignment_updates_oldlval(Lval, OldLval) = yes ->
-            % XXX we should still substitute on the rhs
             % If we alter any lval that occurs in OldLval, we must stop
             % the substitutions.
-            true
+            exprn_aux.substitute_lval_in_rval(OldLval, NewLval, Rval0, Rval),
+            Uinstr = assign(Lval, Rval),
+            !:Instr = llds_instr(Uinstr, Comment)
         ;
             exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N),
             substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N)
         )
     ;
         Uinstr0 = keep_assign(_, _),
-        exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N)
+        ( assignment_updates_oldlval(Lval, OldLval) = yes ->
+            % If we alter any lval that occurs in OldLval, we must stop
+            % the substitutions.
+            exprn_aux.substitute_lval_in_rval(OldLval, NewLval, Rval0, Rval),
+            Uinstr = keep_assign(Lval, Rval),
+            !:Instr = llds_instr(Uinstr, Comment)
+        ;
+            exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N),
+            substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N)
+        )
+    ;
+        Uinstr0 = lc_create_loop_control(_NumSlots, Lval),
+        ( assignment_updates_oldlval(Lval, OldLval) = yes ->
+            % If we alter any lval that occurs in OldLval, we must stop
+            % the substitutions.
+            true
+        ;
+            exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N),
+            substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N)
+        )
+    ;
+        Uinstr0 = lc_wait_free_slot(Rval0, Lval, Label),
+        ( assignment_updates_oldlval(Lval, OldLval) = yes ->
+            % If we alter any lval that occurs in OldLval, we must stop
+            % the substitutions.
+            exprn_aux.substitute_lval_in_rval(OldLval, NewLval, Rval0, Rval),
+            Uinstr = lc_wait_free_slot(Rval, Lval, Label),
+            !:Instr = llds_instr(Uinstr, Comment)
+        ;
+            exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N),
+            substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N)
+        )
     ;
         ( Uinstr0 = incr_hp(Lval, _, _, _, _, _, _, _)
         ; Uinstr0 = save_maxfr(Lval)
@@ -652,6 +685,8 @@
         ; Uinstr0 = push_region_frame(_, _)
         ; Uinstr0 = region_set_fixed_slot(_, _, _)
         ; Uinstr0 = use_and_maybe_pop_region_frame(_, _)
+        ; Uinstr0 = lc_spawn_off(_, _, _)
+        ; Uinstr0 = lc_join_and_terminate(_, _)
         ),
         exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N),
         substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N)
cvs diff: Diffing compiler/notes
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/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_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
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/monte
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/appengine
cvs diff: Diffing samples/appengine/war
cvs diff: Diffing samples/appengine/war/WEB-INF
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/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/lazy_list
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/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
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/stm
cvs diff: Diffing tests/stm/orig
cvs diff: Diffing tests/stm/orig/stm-compiler
cvs diff: Diffing tests/stm/orig/stm-compiler/test1
cvs diff: Diffing tests/stm/orig/stm-compiler/test10
cvs diff: Diffing tests/stm/orig/stm-compiler/test2
cvs diff: Diffing tests/stm/orig/stm-compiler/test3
cvs diff: Diffing tests/stm/orig/stm-compiler/test4
cvs diff: Diffing tests/stm/orig/stm-compiler/test5
cvs diff: Diffing tests/stm/orig/stm-compiler/test6
cvs diff: Diffing tests/stm/orig/stm-compiler/test7
cvs diff: Diffing tests/stm/orig/stm-compiler/test8
cvs diff: Diffing tests/stm/orig/stm-compiler/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/stmqueue
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test10
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test11
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test9
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