Files
mercury/compiler/stdlabel.m
Zoltan Somogyi 1c3bc03415 Make the system compiler with --warn-unused-imports.
Estimated hours taken: 2
Branches: main, release

Make the system compiler with --warn-unused-imports.

browser/*.m:
library/*.m:
compiler/*.m:
	Remove unnecesary imports as flagged by --warn-unused-imports.

	In some files, do some minor cleanup along the way.
2010-12-30 11:18:04 +00:00

93 lines
3.4 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2006-2007, 2010 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: stdlabel.m.
% Author: zs.
%
% Module to rename (actually renumber) all the labels in a procedure so that
% the label numbers are in a dense ascending sequence.
%
% This transformation leaves the performance of the program unaffected.
% However, one can use it make the effect of an optimization much more readily
% apparent. The idea is that enabling --standardize-labels when compiling
% a program both with and without a new or modified optimization cleans up
% the output of the diff between the two sets of resulting .c files, by
% eliminating incidental differences in labels that could otherwise overwhelm
% the real differences made by the optimization.
%
%-----------------------------------------------------------------------------%
:- module ll_backend.stdlabel.
:- interface.
:- import_module ll_backend.llds.
:- import_module counter.
:- import_module list.
%-----------------------------------------------------------------------------%
:- pred standardize_labels(list(instruction)::in, list(instruction)::out,
counter::in, counter::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module ll_backend.opt_util.
:- import_module mdbcomp.prim_data.
:- import_module bool.
:- import_module map.
:- import_module require.
:- import_module svmap.
%-----------------------------------------------------------------------------%
standardize_labels(Instrs0, Instrs, _, !:ProcCounter) :-
opt_util.get_prologue(Instrs0, LabelInstr, Comments, Instrs1),
(
LabelInstr = llds_instr(label(FirstLabel), _),
FirstLabel = entry_label(_, ProcLabel)
->
build_std_map(Instrs1, ProcLabel, counter.init(1), !:ProcCounter,
map.init, Map),
replace_labels_instruction_list(Instrs1, Instrs2, Map, yes, yes),
Instrs = [LabelInstr | Comments] ++ Instrs2
;
unexpected(this_file, "standardize_labels: no proc_label")
).
%-----------------------------------------------------------------------------%
:- pred build_std_map(list(instruction)::in, proc_label::in,
counter::in, counter::out,
map(label, label)::in, map(label, label)::out) is det.
build_std_map([], _, !Counter, !Map).
build_std_map([Instr | Instrs], ProcLabel, !Counter, !Map) :-
( Instr = llds_instr(label(Label), _) ->
counter.allocate(LabelNum, !Counter),
StdLabel = internal_label(LabelNum, ProcLabel),
svmap.det_insert(Label, StdLabel, !Map)
;
true
),
build_std_map(Instrs, ProcLabel, !Counter, !Map).
%-----------------------------------------------------------------------------%
:- func this_file = string.
this_file = "stdlabel.m".
%-----------------------------------------------------------------------------%
:- end_module stdlabel.
%-----------------------------------------------------------------------------%