[m-rev.] diff: Finalize tail recursive loop controled code.
Paul Bone
pbone at csse.unimelb.edu.au
Thu Oct 20 15:37:19 AEDT 2011
This patch makes Zoltan's work and my work cooperate to provide tail recursion
in loop controlled code.
compiler/par_conj_gen.m:
Make the generated code for copying the stack frame conform to the
macros I've provided in the runtime system.
runtime/par_builtin.h:
Correct bugs in the runtime code for manipulating stack frames.
Index: compiler/par_conj_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/par_conj_gen.m,v
retrieving revision 1.51
diff -u -p -b -r1.51 par_conj_gen.m
--- compiler/par_conj_gen.m 20 Oct 2011 03:35:56 -0000 1.51
+++ compiler/par_conj_gen.m 20 Oct 2011 04:16:57 -0000
@@ -457,24 +457,23 @@ copy_slots_to_child_stack(FrameSize, LCV
unexpected($module, $pred, "cannot convert to string")
),
- BaseVarName = "BaseSp",
FirstLine = "{\n",
- DeclLine = string.format("\tMR_Word *%s;\n", [s(BaseVarName)]),
- AssignLine = string.format("\t%s = MR_lc_child_stack_sp(%s, %s, %d);\n",
- [s(BaseVarName), s(LCVarName), s(LCSVarName), i(FrameSize)]),
- list.map(copy_one_slot_to_child_stack(BaseVarName),
+ IncrLine = string.format("\tMR_lc_inc_worker_sp(%s, %s, %d);\n",
+ [s(LCVarName), s(LCSVarName), i(FrameSize)]),
+ list.map(copy_one_slot_to_child_stack(LCVarName, LCSVarName),
StackSlots, CopyStrs),
string.append_list(CopyStrs, CopyLines),
LastLine = "\t}\n",
- CodeStr = FirstLine ++ DeclLine ++ AssignLine ++ CopyLines ++ LastLine.
+ CodeStr = FirstLine ++ IncrLine ++ CopyLines ++ LastLine.
-:- pred copy_one_slot_to_child_stack(string::in, lval::in, string::out) is det.
+:- pred copy_one_slot_to_child_stack(string::in, string::in, lval::in,
+ string::out) is det.
-copy_one_slot_to_child_stack(BaseVarName, StackSlot, CopyStr) :-
+copy_one_slot_to_child_stack(LCVarName, LCSVarName, StackSlot, CopyStr) :-
( StackSlotName = lval_to_string(StackSlot) ->
( StackSlot = stackvar(N) ->
- CopyStr = string.format("\tMR_based_stackvar(%s, %d) = %s;\n",
- [s(BaseVarName), i(N), s(StackSlotName)])
+ CopyStr = string.format("\tMR_lc_worker_sv(%s, %s, %d) = %s;\n",
+ [s(LCVarName), s(LCSVarName), i(N), s(StackSlotName)])
;
unexpected($module, $pred, "not stack slot")
)
Index: runtime/mercury_par_builtin.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_par_builtin.h,v
retrieving revision 1.15
diff -u -p -b -r1.15 mercury_par_builtin.h
--- runtime/mercury_par_builtin.h 19 Oct 2011 11:57:54 -0000 1.15
+++ runtime/mercury_par_builtin.h 20 Oct 2011 04:24:35 -0000
@@ -530,15 +530,16 @@ extern MR_Bool MR_lc_try_get_free_slot(M
do { \
MR_Context *ctxt; \
\
- ctxt = (lc)->MR_lc_slots[lcs_idx].MR_lcs_context; \
- MR_lcs_context->MR_ctxt_sp += N; \
+ ctxt = ((MR_LoopControl*)lc)->MR_lc_slots[lcs_idx].MR_lcs_context; \
+ ctxt->MR_ctxt_sp += N; \
} while (0);
/*
** Access a slot on the stack of the worker context in the loop control slot.
*/
#define MR_lc_worker_sv(lc, lcs_idx, N) \
- MR_based_stackvar((lc)->MR_lc_slots[lc_idx].MR_lcs_context->MR_ctxt_sp, (N))
+ MR_based_stackvar(((MR_LoopControl*)lc)->MR_lc_slots[lcs_idx]. \
+ MR_lcs_context->MR_ctxt_sp, (N))
/*
** Try to spawn off this code using the free slot.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20111020/e5687cf9/attachment.sig>
More information about the reviews
mailing list