Files
mercury/compiler/wrap_blocks.m
Julien Fischer 459847a064 Move the univ, maybe, pair and unit types from std_util into their own
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.
2006-03-29 08:09:58 +00:00

106 lines
4.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2001, 2003, 2005-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: wrap_blocks.m
% Author: zs.
% The optimizations in use_local_vars.m insert into instruction sequences
% references to temporary variables whose values need be preserved only within
% an extended basic block. The wrap_blocks pass looks for references to
% temporaries and introduces block instructions whenever it sees them. These
% block instructions go from the first reference to a temporary to the end of
% its extended basic block.
%-----------------------------------------------------------------------------%
:- module ll_backend.wrap_blocks.
:- interface.
:- import_module ll_backend.llds.
:- import_module list.
%-----------------------------------------------------------------------------%
:- pred wrap_blocks(list(instruction)::in, list(instruction)::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module libs.compiler_util.
:- import_module ll_backend.opt_util.
:- import_module bool.
:- import_module int.
:- import_module pair.
%-----------------------------------------------------------------------------%
wrap_blocks(Instrs0, Instrs) :-
wrap_instrs(Instrs0, 0, 0, [], Instrs).
% R is the number of the highest numbered tempr variable seen so far;
% R = 0 means we haven't seen any temp variables. Similarly, F is the
% highest numbered tempf variable seen so far. RevSofar is a
% reversed list of instructions starting with the first instruction
% in this block that accesses a temp variable. Invariant: RevSofar
% is always empty if R = 0 and F = 0.
%
:- pred wrap_instrs(list(instruction)::in, int::in, int::in,
list(instruction)::in, list(instruction)::out) is det.
wrap_instrs([], R, F, RevSofar, []) :-
( RevSofar = [_ | _] ->
unexpected(this_file, "procedure ends with fallthrough")
; ( R > 0 ; F > 0 ) ->
unexpected(this_file, "procedure ends without closing block")
;
true
).
wrap_instrs([Instr0 | Instrs0], R0, F0, RevSofar, Instrs) :-
Instr0 = Uinstr0 - _Comment0,
opt_util.count_temps_instr(Uinstr0, R0, R1, F0, F1),
( ( R1 > 0 ; F1 > 0) ->
% We must close the block before a label, since you can jump
% to a label from other blocks.
%
% Call instructions cannot fall through, but they cannot refer
% to the temp variables declared by the block either, so we
% close the block either just before or just after the call
% instruction. We close the block before the call instruction,
% because including it in the block causes the test case
% debugger/all_solutions to fail.
( ( Uinstr0 = label(_) ; Uinstr0 = call(_, _, _, _, _, _) ) ->
list.reverse(RevSofar, BlockInstrs),
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
Instrs = [block(R1, F1, BlockInstrs) - "", Instr0 | Instrs1]
; opt_util.can_instr_fall_through(Uinstr0, no) ->
list.reverse([Instr0 | RevSofar], BlockInstrs),
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
Instrs = [block(R1, F1, BlockInstrs) - "" | Instrs1]
;
wrap_instrs(Instrs0, R1, F1, [Instr0 | RevSofar], Instrs)
)
;
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
Instrs = [Instr0 | Instrs1]
).
%-----------------------------------------------------------------------------%
:- func this_file = string.
this_file = "wrap_blocks.m".
%-----------------------------------------------------------------------------%
:- end_module wrap_blocks.
%-----------------------------------------------------------------------------%