mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
Generate shorter code for filling trace slots.
compiler/trace_gen.m:
Given that the standard trace slots are (by design) always the same,
generate code that does not redundantly specify them.
runtime/mercury_trace_base.h:
Add the three macros that trace_gen.m can now generate references to.
This commit is contained in:
@@ -583,8 +583,8 @@ trace_setup(Globals, ProcInfo, EffTraceLevel, MaybeTailRecLabel,
|
||||
then
|
||||
get_next_label(RedoLayoutLabel, !CI),
|
||||
MaybeRedoLayoutLabel = yes(RedoLayoutLabel),
|
||||
% We always reserve slots 1, 2 and 3, and we reserve slot 4
|
||||
% for the redo layout label.
|
||||
% We always reserve slots 1, 2 and 3, and we hereby reserve
|
||||
% slot 4 for the redo layout label.
|
||||
!:NextSlot = 5
|
||||
else
|
||||
MaybeRedoLayoutLabel = no,
|
||||
@@ -686,22 +686,31 @@ trace_setup(Globals, ProcInfo, EffTraceLevel, MaybeTailRecLabel,
|
||||
generate_slot_fill_code(CI, TraceInfo, TraceCode) :-
|
||||
CodeModel = get_proc_model(CI),
|
||||
MaybeFromFullSlot = TraceInfo ^ ti_from_full_lval,
|
||||
MaybeIoSeqSlot = TraceInfo ^ ti_io_seq_lval,
|
||||
MaybeIoSeqSlot0 = TraceInfo ^ ti_io_seq_lval,
|
||||
MaybeTrailLvals = TraceInfo ^ ti_trail_lvals,
|
||||
MaybeMaxfrLval = TraceInfo ^ ti_maxfr_lval,
|
||||
MaybeCallTableLval = TraceInfo ^ ti_call_table_tip_lval,
|
||||
MaybeTailRecInfo = TraceInfo ^ ti_tail_rec_info,
|
||||
MaybeRedoLabel = TraceInfo ^ ti_redo_label,
|
||||
event_num_slot(CodeModel, EventNumLval),
|
||||
call_num_slot(CodeModel, CallNumLval),
|
||||
call_depth_slot(CodeModel, CallDepthLval),
|
||||
stackref_to_string(EventNumLval, EventNumStr),
|
||||
stackref_to_string(CallNumLval, CallNumStr),
|
||||
stackref_to_string(CallDepthLval, CallDepthStr),
|
||||
some [!CodeStr] (
|
||||
% Stage 1.
|
||||
!:CodeStr = "\t\tMR_trace_fill_std_slots(" ++ EventNumStr ++ ", " ++
|
||||
CallNumStr ++ ", " ++ CallDepthStr ++ ");\n",
|
||||
(
|
||||
CodeModel = model_non,
|
||||
!:CodeStr = "\t\tMR_trace_fill_std_slots_fv;\n",
|
||||
MaybeIoSeqSlot = MaybeIoSeqSlot0
|
||||
;
|
||||
( CodeModel = model_det
|
||||
; CodeModel = model_semi
|
||||
),
|
||||
( if MaybeIoSeqSlot0 = yes(stackvar(IoSeqSlotNum0)) then
|
||||
!:CodeStr = "\t\tMR_trace_fill_std_slots_sv_io(" ++
|
||||
string.int_to_string(IoSeqSlotNum0) ++ ");\n",
|
||||
MaybeIoSeqSlot = no
|
||||
else
|
||||
!:CodeStr = "\t\tMR_trace_fill_std_slots_sv;\n",
|
||||
MaybeIoSeqSlot = MaybeIoSeqSlot0
|
||||
)
|
||||
),
|
||||
% Stage 2.
|
||||
(
|
||||
MaybeRedoLabel = yes(RedoLayoutLabel),
|
||||
@@ -745,6 +754,8 @@ generate_slot_fill_code(CI, TraceInfo, TraceCode) :-
|
||||
(
|
||||
MaybeFromFullSlot = yes(CallFromFullSlot),
|
||||
stackref_to_string(CallFromFullSlot, CallFromFullSlotStr),
|
||||
call_depth_slot(CodeModel, CallDepthLval),
|
||||
stackref_to_string(CallDepthLval, CallDepthStr),
|
||||
!:CodeStr =
|
||||
"\t\t" ++ CallFromFullSlotStr ++ " = MR_trace_from_full;\n" ++
|
||||
"\t\tif (MR_trace_from_full) {\n" ++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// vim: ts=4 sw=4 expandtab ft=c
|
||||
|
||||
// Copyright (C) 1997-2009, 2011 The University of Melbourne.
|
||||
// Copyright (C) 2014, 2016, 2018 The Mercury team.
|
||||
// Copyright (C) 2014, 2016, 2018, 2025 The Mercury team.
|
||||
// This file is distributed under the terms specified in COPYING.LIB.
|
||||
|
||||
// mercury_trace_base.h defines the interface between the main part
|
||||
@@ -105,6 +105,14 @@ extern void MR_trace_name_count_port_ensure_init(void);
|
||||
#define MR_trace_incr_seq() ((MR_Word) ++MR_trace_call_seqno)
|
||||
#define MR_trace_incr_depth() ((MR_Word) ++MR_trace_call_depth)
|
||||
|
||||
#define MR_trace_fill_std_slots_sv \
|
||||
MR_trace_fill_std_slots(MR_sv(1), MR_sv(2), MR_sv(3))
|
||||
#define MR_trace_fill_std_slots_fv \
|
||||
MR_trace_fill_std_slots(MR_fv(1), MR_fv(2), MR_fv(3))
|
||||
|
||||
#define MR_trace_fill_std_slots_sv_io(IoSeqSlot) \
|
||||
(MR_trace_fill_std_slots_sv, MR_sv(IoSeqSlot) = MR_io_tabling_counter)
|
||||
|
||||
#define MR_trace_fill_std_slots(s1, s2, s3) \
|
||||
(((s1) = MR_trace_event_number), \
|
||||
((s2) = MR_trace_incr_seq()), \
|
||||
|
||||
Reference in New Issue
Block a user