mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 18 Branches: main Move the univ, maybe, pair and unit types from std_util into their own modules. std_util still contains the general purpose higher-order programming constructs. library/std_util.m: Move univ, maybe, pair and unit (plus any other related types and procedures) into their own modules. library/maybe.m: New module. This contains the maybe and maybe_error types and the associated procedures. library/pair.m: New module. This contains the pair type and associated procedures. library/unit.m: New module. This contains the types unit/0 and unit/1. library/univ.m: New module. This contains the univ type and associated procedures. library/library.m: Add the new modules. library/private_builtin.m: Update the declaration of the type_ctor_info struct for univ. runtime/mercury.h: Update the declaration for the type_ctor_info struct for univ. runtime/mercury_mcpp.h: runtime/mercury_hlc_types.h: Update the definition of MR_Univ. runtime/mercury_init.h: Fix a comment: ML_type_name is now exported from type_desc.m. compiler/mlds_to_il.m: Update the the name of the module that defines univs (which are handled specially by the il code generator.) library/*.m: compiler/*.m: browser/*.m: mdbcomp/*.m: profiler/*.m: deep_profiler/*.m: Conform to the above changes. Import the new modules where they are needed; don't import std_util where it isn't needed. Fix formatting in lots of modules. Delete duplicate module imports. tests/*: Update the test suite to confrom to the above changes.
93 lines
3.4 KiB
Mathematica
93 lines
3.4 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998, 2003-2006 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% File: delay_slot.m.
|
|
% Main author: zs.
|
|
|
|
% This module attempts to fill the delay slots of branch instructions. Since
|
|
% it assumes the existence of one delay slot after every branch, this module
|
|
% should not be invoked if the architecture we are targeting has no delay
|
|
% slots on its branch instructions.
|
|
|
|
% Since we are generating C code, not assembler, we cannot fill slots
|
|
% directly. However, we can let the C compiler know that the instruction
|
|
% immediately after a condition branch instruction can be safely executed even
|
|
% if the branch is not taken. We can do so by moving the instruction before
|
|
% the conditional branch. This actually requires the instruction to be
|
|
% executed in both continuations, therefore we want to do this only if there
|
|
% is no chance that the C compiler would be able to fill the delay slot any
|
|
% other way.
|
|
|
|
% The only code pattern that we recognize as being both safe and advantageous
|
|
% to transform the code in order to fill a delay slot is this pattern,
|
|
% produced by frameopt:
|
|
%
|
|
% L1:
|
|
% if (cond) goto L2
|
|
% incr_sp(N)
|
|
% stackvar(N) = succip
|
|
% ...
|
|
%
|
|
% We transform this code into:
|
|
%
|
|
% L1:
|
|
% stackvar(0) = succip
|
|
% if (cond) goto L2
|
|
% incr_sp(N)
|
|
% ...
|
|
%
|
|
% The initial store into stackvar(0) is into the first word above the
|
|
% current detstack top. After the incr_sp is executed (if it ever is), this
|
|
% word will become the bottom stack slot of the new frame, i.e. stackvar(N).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module ll_backend.delay_slot.
|
|
:- interface.
|
|
|
|
:- import_module ll_backend.llds.
|
|
|
|
:- import_module list.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred fill_branch_delay_slot(list(instruction)::in, list(instruction)::out)
|
|
is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module pair.
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
fill_branch_delay_slot([], []).
|
|
fill_branch_delay_slot([Instr0 | Instrs0], Instrs) :-
|
|
(
|
|
Instr0 = label(_) - _,
|
|
Instrs0 = [Instr1, Instr2, Instr3 | Tail0],
|
|
Instr1 = if_val(_, _) - _,
|
|
Instr2 = incr_sp(Size, _) - _,
|
|
Instr3 = assign(stackvar(Size), lval(succip)) - C2
|
|
->
|
|
fill_branch_delay_slot(Tail0, Tail1),
|
|
string.append(C2, " (early save in delay slot)", NewC2),
|
|
EarlySave = assign(stackvar(0), lval(succip)) - NewC2,
|
|
Instrs = [Instr0, EarlySave, Instr1, Instr2 | Tail1]
|
|
;
|
|
fill_branch_delay_slot(Instrs0, Instrs1),
|
|
Instrs = [Instr0 | Instrs1]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module delay_slot.
|
|
%-----------------------------------------------------------------------------%
|