diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m index 81a3632d4..5decdb236 100644 --- a/compiler/compile_target_code.m +++ b/compiler/compile_target_code.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %-----------------------------------------------------------------------------% -% Copyright (C) 2002-2005 The University of Melbourne. +% Copyright (C) 2002-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. %-----------------------------------------------------------------------------% @@ -865,7 +865,7 @@ make_init_file(ErrorStream, MainModuleName, AllModules, Succeeded, !IO) :- io__close_output(InitFileStream, !IO), module_name_to_file_name(MainModuleName, ".init", yes, InitFileName, !IO), - update_interface(InitFileName, Succeeded1, !IO), + update_interface_return_succeeded(InitFileName, Succeeded1, !IO), Succeeded = Succeeded0 `and` Succeeded1 ; InitFileRes = error(Error), @@ -1071,7 +1071,7 @@ make_init_obj_file(ErrorStream, MustCompile, ModuleName, ModuleNames, Result, maybe_report_stats(Stats, !IO), ( MkInitOK0 = yes, - update_interface(InitCFileName, MkInitOK1, !IO), + update_interface_return_succeeded(InitCFileName, MkInitOK1, !IO), ( MkInitOK1 = yes, ( diff --git a/compiler/handle_options.m b/compiler/handle_options.m index e74fbf0e9..3362fb26f 100644 --- a/compiler/handle_options.m +++ b/compiler/handle_options.m @@ -1707,7 +1707,25 @@ postprocess_options_lowlevel(!Globals) :- option_implies(optimize_frames, optimize_jumps, bool(yes), !Globals), % --optimize-proc-dups is implemented only with --trad-passes. - option_implies(optimize_proc_dups, trad_passes, bool(yes), !Globals). + option_implies(optimize_proc_dups, trad_passes, bool(yes), !Globals), + + globals.lookup_bool_option(!.Globals, optimize_frames, OptFrames), + globals.lookup_bool_option(!.Globals, use_local_vars, OptLocalVars), + globals.lookup_int_option(!.Globals, optimize_repeat, OptRepeat), + ( + ( OptFrames = yes + ; OptLocalVars = yes + ), + OptRepeat < 1 + -> + % The frame optimization and the local vars optimization depend on + % the jump and label optimization having been done. They are turned + % on above, but they still won't be executed unless optimize_repeat + % is at least one. + globals__set_option(optimize_repeat, int(1), !Globals) + ; + true + ). % option_implies(SourceBoolOption, ImpliedOption, ImpliedOptionValue): % If the SourceBoolOption is set to yes, then the ImpliedOption is set diff --git a/compiler/mercury_compile.m b/compiler/mercury_compile.m index aef0f5880..f4b07a019 100644 --- a/compiler/mercury_compile.m +++ b/compiler/mercury_compile.m @@ -2735,7 +2735,7 @@ backend_pass_by_preds_4(PredInfo, !ProcInfo, ProcId, PredId, !HLDS, globals__lookup_bool_option(Globals, optimize, Optimize), ( Optimize = yes, - optimize__proc(!.GlobalData, ProcCode0, ProcCode, !IO) + optimize_proc(!.GlobalData, ProcCode0, ProcCode, !IO) ; Optimize = no, ProcCode = ProcCode0 @@ -4041,7 +4041,7 @@ maybe_do_optimize(GlobalData, Verbose, Stats, !LLDS, !IO) :- Optimize = yes, maybe_write_string(Verbose, "% Doing optimizations...\n", !IO), maybe_flush_output(Verbose, !IO), - optimize_main(GlobalData, !LLDS, !IO), + optimize_procs(GlobalData, !LLDS, !IO), maybe_write_string(Verbose, "% done.\n", !IO), maybe_report_stats(Stats, !IO) ; diff --git a/compiler/modules.m b/compiler/modules.m index faecea7af..2759921ae 100644 --- a/compiler/modules.m +++ b/compiler/modules.m @@ -692,12 +692,13 @@ % :- pred touch_datestamp(file_name::in, io::di, io::uo) is det. - % update_interface(FileName, Succeeded): + % update_interface_return_succeeded(FileName, Succeeded): % % Call the shell script mercury_update_interface to update the % interface file FileName if it has changed. % -:- pred update_interface(file_name::in, bool::out, io::di, io::uo) is det. +:- pred update_interface_return_succeeded(file_name::in, bool::out, + io::di, io::uo) is det. :- pred update_interface(file_name::in, io::di, io::uo) is det. @@ -2242,7 +2243,7 @@ write_interface_file(_SourceFileName, ModuleName, Suffix, MaybeTimestamp, % update .int from .int.tmp if necessary update_interface(OutputFileName, !IO) :- - update_interface(OutputFileName, Succeeded, !IO), + update_interface_return_succeeded(OutputFileName, Succeeded, !IO), ( Succeeded = no, report_error("problem updating interface files.", !IO) @@ -2250,7 +2251,7 @@ update_interface(OutputFileName, !IO) :- Succeeded = yes ). -update_interface(OutputFileName, Succeeded, !IO) :- +update_interface_return_succeeded(OutputFileName, Succeeded, !IO) :- globals__io_lookup_bool_option(verbose, Verbose, !IO), maybe_write_string(Verbose, "% Updating interface:\n", !IO), TmpOutputFileName = OutputFileName ++ ".tmp", diff --git a/compiler/optimize.m b/compiler/optimize.m index 362f03e85..2b327d1c0 100644 --- a/compiler/optimize.m +++ b/compiler/optimize.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %-----------------------------------------------------------------------------% -% Copyright (C) 1996-2005 The University of Melbourne. +% Copyright (C) 1996-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. %-----------------------------------------------------------------------------% @@ -13,7 +13,7 @@ %-----------------------------------------------------------------------------% -:- module ll_backend__optimize. +:- module ll_backend.optimize. :- interface. :- import_module ll_backend.global_data. @@ -24,10 +24,10 @@ %-----------------------------------------------------------------------------% -:- pred optimize_main(global_data::in, +:- pred optimize_procs(global_data::in, list(c_procedure)::in, list(c_procedure)::out, io::di, io::uo) is det. -:- pred optimize__proc(global_data::in, c_procedure::in, c_procedure::out, +:- pred optimize_proc(global_data::in, c_procedure::in, c_procedure::out, io::di, io::uo) is det. %-----------------------------------------------------------------------------% @@ -71,35 +71,35 @@ %-----------------------------------------------------------------------------% -optimize_main(GlobalData, !Procs, !IO) :- - list__map_foldl(optimize__proc(GlobalData), !Procs, !IO). +optimize_procs(GlobalData, !Procs, !IO) :- + list.map_foldl(optimize_proc(GlobalData), !Procs, !IO). -optimize__proc(GlobalData, CProc0, CProc, !IO) :- +optimize_proc(GlobalData, CProc0, CProc, !IO) :- some [!OptDebugInfo, !C, !Instrs] ( CProc0 = c_procedure(Name, Arity, PredProcId, !:Instrs, ProcLabel, !:C, MayAlterRtti), - optimize__init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, + init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, !.Instrs, !.C, !:OptDebugInfo, !IO), - globals__io_lookup_int_option(optimize_repeat, Repeat, !IO), + globals.io_lookup_int_option(optimize_repeat, Repeat, !IO), ( global_data_maybe_get_proc_layout(GlobalData, PredProcId, ProcLayout) -> LabelMap = ProcLayout ^ internal_map, - map__sorted_keys(LabelMap, LayoutLabelNums), - LayoutLabels = list__map(make_internal_label(ProcLabel), + map.sorted_keys(LabelMap, LayoutLabelNums), + LayoutLabels = list.map(make_internal_label(ProcLabel), LayoutLabelNums), - set__sorted_list_to_set(LayoutLabels, LayoutLabelSet) + set.sorted_list_to_set(LayoutLabels, LayoutLabelSet) ; - set__init(LayoutLabelSet) + set.init(LayoutLabelSet) ), - optimize__initial(LayoutLabelSet, ProcLabel, MayAlterRtti, !C, + optimize_initial(LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO), - optimize__repeat(Repeat, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, + optimize_repeat(Repeat, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO), - optimize__middle(yes, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, + optimize_middle(yes, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO), - optimize__last(LayoutLabelSet, ProcLabel, !.C, !.OptDebugInfo, !Instrs, + optimize_last(LayoutLabelSet, ProcLabel, !.C, !.OptDebugInfo, !Instrs, !IO), CProc = c_procedure(Name, Arity, PredProcId, !.Instrs, ProcLabel, !.C, MayAlterRtti) @@ -123,14 +123,14 @@ make_internal_label(ProcLabel, LabelNum) = internal(LabelNum, ProcLabel). ) ; no_opt_debug_info. -:- pred optimize__init_opt_debug_info(string::in, int::in, pred_proc_id::in, +:- pred init_opt_debug_info(string::in, int::in, pred_proc_id::in, proc_label::in, list(instruction)::in, counter::in, opt_debug_info::out, io::di, io::uo) is det. -optimize__init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, Instrs0, - Counter, OptDebugInfo, !IO) :- - globals__io_lookup_bool_option(debug_opt, DebugOpt, !IO), - globals__io_lookup_int_option(debug_opt_pred_id, DebugOptPredId, !IO), +init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, Instrs0, Counter, + OptDebugInfo, !IO) :- + globals.io_lookup_bool_option(debug_opt, DebugOpt, !IO), + globals.io_lookup_int_option(debug_opt_pred_id, DebugOptPredId, !IO), PredProcId = proc(PredId, ProcId), pred_id_to_int(PredId, PredIdInt), proc_id_to_int(ProcId, ProcIdInt), @@ -144,21 +144,21 @@ optimize__init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, Instrs0, ++ ".proc" ++ int_to_string(ProcIdInt), OptDebugInfo = opt_debug_info(BaseName, 0, 0, Instrs0), - io__call_system("mkdir -p " ++ opt_subdir_name, MkdirRes, !IO), + io.call_system("mkdir -p " ++ opt_subdir_name, MkdirRes, !IO), ( MkdirRes = ok(0) -> true ; unexpected(this_file, "cannot make " ++ opt_subdir_name) ), FileName = BaseName ++ ".opt0", - io__open_output(FileName, Res, !IO), + io.open_output(FileName, Res, !IO), ( Res = ok(FileStream) -> - io__set_output_stream(FileStream, OutputStream, !IO), - counter__allocate(NextLabel, Counter, _), - opt_debug__msg(yes, NextLabel, "before optimization", !IO), - opt_debug__maybe_dump_instrs(yes, ProcLabel, Instrs0, !IO), - io__set_output_stream(OutputStream, _, !IO), - io__close_output(FileStream, !IO) + io.set_output_stream(FileStream, OutputStream, !IO), + counter.allocate(NextLabel, Counter, _), + opt_debug.msg(yes, NextLabel, "before optimization", !IO), + opt_debug.maybe_dump_instrs(yes, ProcLabel, Instrs0, !IO), + io.set_output_stream(OutputStream, _, !IO), + io.close_output(FileStream, !IO) ; unexpected(this_file, "cannot open " ++ FileName) ) @@ -170,12 +170,11 @@ optimize__init_opt_debug_info(Name, Arity, PredProcId, ProcLabel, Instrs0, opt_subdir_name = "OptSubdir". -:- pred optimize__maybe_opt_debug(list(instruction)::in, counter::in, - string::in, proc_label::in, opt_debug_info::in, opt_debug_info::out, - io::di, io::uo) is det. +:- pred maybe_opt_debug(list(instruction)::in, counter::in, string::in, + proc_label::in, opt_debug_info::in, opt_debug_info::out, io::di, io::uo) + is det. -optimize__maybe_opt_debug(Instrs, Counter, Msg, ProcLabel, !OptDebugInfo, - !IO) :- +maybe_opt_debug(Instrs, Counter, Msg, ProcLabel, !OptDebugInfo, !IO) :- ( !.OptDebugInfo = opt_debug_info(BaseName, OptNum0, PrevNum, PrevInstrs), @@ -185,25 +184,25 @@ optimize__maybe_opt_debug(Instrs, Counter, Msg, ProcLabel, !OptDebugInfo, Same = no ), OptNum = OptNum0 + 1, - string__int_to_string(PrevNum, PrevNumStr), - string__int_to_string(OptNum, OptNumStr), + string.int_to_string(PrevNum, PrevNumStr), + string.int_to_string(OptNum, OptNumStr), PrevFileName = BaseName ++ ".opt" ++ PrevNumStr, OptFileName = BaseName ++ ".opt" ++ OptNumStr, DiffFileName = BaseName ++ ".diff" ++ OptNumStr, - io__open_output(OptFileName, Res, !IO), + io.open_output(OptFileName, Res, !IO), ( Res = ok(FileStream) -> - io__set_output_stream(FileStream, OutputStream, !IO), - counter__allocate(NextLabel, Counter, _), - opt_debug__msg(yes, NextLabel, Msg, !IO), + io.set_output_stream(FileStream, OutputStream, !IO), + counter.allocate(NextLabel, Counter, _), + opt_debug.msg(yes, NextLabel, Msg, !IO), ( Same = yes, - io__write_string("same as previous version\n", !IO) + io.write_string("same as previous version\n", !IO) ; Same = no, - opt_debug__maybe_dump_instrs(yes, ProcLabel, Instrs, !IO) + opt_debug.maybe_dump_instrs(yes, ProcLabel, Instrs, !IO) ), - io__set_output_stream(OutputStream, _, !IO), - io__close_output(FileStream, !IO) + io.set_output_stream(OutputStream, _, !IO), + io.close_output(FileStream, !IO) ; ErrorMsg = "cannot open " ++ OptFileName, unexpected(this_file, ErrorMsg) @@ -218,7 +217,7 @@ optimize__maybe_opt_debug(Instrs, Counter, Msg, ProcLabel, !OptDebugInfo, % of --debug-opt (zs) strongly prefers -u to -c. DiffCommand = "diff -u '" ++ PrevFileName ++ "' '" ++ OptFileName ++ "' > '" ++ DiffFileName ++ "'", - io__call_system(DiffCommand, _, !IO), + io.call_system(DiffCommand, _, !IO), !:OptDebugInfo = opt_debug_info(BaseName, OptNum, OptNum, Instrs) ) ; @@ -227,29 +226,29 @@ optimize__maybe_opt_debug(Instrs, Counter, Msg, ProcLabel, !OptDebugInfo, %-----------------------------------------------------------------------------% -:- pred optimize__initial(set(label)::in, proc_label::in, may_alter_rtti::in, +:- pred optimize_initial(set(label)::in, proc_label::in, may_alter_rtti::in, counter::in, counter::out, opt_debug_info::in, opt_debug_info::out, list(instruction)::in, list(instruction)::out, io::di, io::uo) is det. -optimize__initial(LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, +optimize_initial(LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO) :- - globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO), - LabelStr = opt_util__format_proc_label(ProcLabel), + globals.io_lookup_bool_option(very_verbose, VeryVerbose, !IO), + LabelStr = opt_util.format_proc_label(ProcLabel), - globals__io_lookup_bool_option(optimize_frames, FrameOpt, !IO), + globals.io_lookup_bool_option(optimize_frames, FrameOpt, !IO), ( FrameOpt = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing nondet frames for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing nondet frames for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), frameopt_nondet(ProcLabel, LayoutLabelSet, MayAlterRtti, !C, !Instrs, _Mod), - optimize__maybe_opt_debug(!.Instrs, !.C, "after nondet frame opt", + maybe_opt_debug(!.Instrs, !.C, "after nondet frame opt", ProcLabel, !OptDebugInfo, !IO) ; FrameOpt = no @@ -257,12 +256,12 @@ optimize__initial(LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, %-----------------------------------------------------------------------------% -:- pred optimize__repeat(int::in, set(label)::in, proc_label::in, +:- pred optimize_repeat(int::in, set(label)::in, proc_label::in, may_alter_rtti::in, counter::in, counter::out, opt_debug_info::in, opt_debug_info::out, list(instruction)::in, list(instruction)::out, io::di, io::uo) is det. -optimize__repeat(CurIter, LayoutLabelSet, ProcLabel, MayAlterRtti, +optimize_repeat(CurIter, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO) :- ( CurIter > 0 -> NextIter = CurIter - 1, @@ -271,11 +270,11 @@ optimize__repeat(CurIter, LayoutLabelSet, ProcLabel, MayAlterRtti, ; Final = no ), - optimize__repeated(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, + optimize_repeated(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, Mod, !IO), ( Mod = yes, - optimize__repeat(NextIter, LayoutLabelSet, ProcLabel, MayAlterRtti, + optimize_repeat(NextIter, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO) ; Mod = no @@ -287,92 +286,92 @@ optimize__repeat(CurIter, LayoutLabelSet, ProcLabel, MayAlterRtti, % We short-circuit jump sequences before normal peepholing % to create more opportunities for use of the tailcall macro. % -:- pred optimize__repeated(bool::in, set(label)::in, proc_label::in, +:- pred optimize_repeated(bool::in, set(label)::in, proc_label::in, may_alter_rtti::in, counter::in, counter::out, opt_debug_info::in, opt_debug_info::out, list(instruction)::in, list(instruction)::out, bool::out, io::di, io::uo) is det. -optimize__repeated(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, +optimize_repeated(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, Mod, !IO) :- InstrsAtStart = !.Instrs, - LabelStr = opt_util__format_proc_label(ProcLabel), - globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO), - globals__io_lookup_bool_option(optimize_jumps, Jumpopt, !IO), - globals__io_lookup_bool_option(optimize_fulljumps, FullJumpopt, !IO), - globals__io_lookup_bool_option(pessimize_tailcalls, + LabelStr = opt_util.format_proc_label(ProcLabel), + globals.io_lookup_bool_option(very_verbose, VeryVerbose, !IO), + globals.io_lookup_bool_option(optimize_jumps, Jumpopt, !IO), + globals.io_lookup_bool_option(optimize_fulljumps, FullJumpopt, !IO), + globals.io_lookup_bool_option(pessimize_tailcalls, PessimizeTailCalls, !IO), - globals__io_lookup_bool_option(checked_nondet_tailcalls, + globals.io_lookup_bool_option(checked_nondet_tailcalls, CheckedNondetTailCalls, !IO), ( Jumpopt = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing jumps for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing jumps for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), jumpopt_main(LayoutLabelSet, MayAlterRtti, ProcLabel, FullJumpopt, Final, PessimizeTailCalls, CheckedNondetTailCalls, !C, !Instrs, Mod1), - optimize__maybe_opt_debug(!.Instrs, !.C, "after jump opt", + maybe_opt_debug(!.Instrs, !.C, "after jump opt", ProcLabel, !OptDebugInfo, !IO) ; Jumpopt = no, Mod1 = no ), - globals__io_lookup_bool_option(optimize_peep, Peephole, !IO), + globals.io_lookup_bool_option(optimize_peep, Peephole, !IO), ( Peephole = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing locally for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing locally for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), - globals__io_get_gc_method(GC_Method, !IO), - peephole__optimize(GC_Method, !Instrs, Mod2), - optimize__maybe_opt_debug(!.Instrs, !.C, "after peephole", + globals.io_get_gc_method(GC_Method, !IO), + peephole.optimize(GC_Method, !Instrs, Mod2), + maybe_opt_debug(!.Instrs, !.C, "after peephole", ProcLabel, !OptDebugInfo, !IO) ; Peephole = no, Mod2 = no ), - globals__io_lookup_bool_option(optimize_labels, LabelElim, !IO), + globals.io_lookup_bool_option(optimize_labels, LabelElim, !IO), ( LabelElim = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing labels for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing labels for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), labelopt_main(Final, LayoutLabelSet, !Instrs, Mod3), - optimize__maybe_opt_debug(!.Instrs, !.C, "after label opt", + maybe_opt_debug(!.Instrs, !.C, "after label opt", ProcLabel, !OptDebugInfo, !IO) ; LabelElim = no, Mod3 = no ), - globals__io_lookup_bool_option(optimize_dups, DupElim, !IO), + globals.io_lookup_bool_option(optimize_dups, DupElim, !IO), ( DupElim = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing duplicates for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing duplicates for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), dupelim_main(ProcLabel, !C, !Instrs), - optimize__maybe_opt_debug(!.Instrs, !.C, "after duplicates", + maybe_opt_debug(!.Instrs, !.C, "after duplicates", ProcLabel, !OptDebugInfo, !IO) ; DupElim = no @@ -382,38 +381,38 @@ optimize__repeated(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, ; Mod = yes ), - globals__io_lookup_bool_option(detailed_statistics, Statistics, !IO), + globals.io_lookup_bool_option(detailed_statistics, Statistics, !IO), maybe_report_stats(Statistics, !IO). -:- pred optimize__middle(bool::in, set(label)::in, proc_label::in, +:- pred optimize_middle(bool::in, set(label)::in, proc_label::in, may_alter_rtti::in, counter::in, counter::out, opt_debug_info::in, opt_debug_info::out, list(instruction)::in, list(instruction)::out, io::di, io::uo) is det. -optimize__middle(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, +optimize_middle(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, !OptDebugInfo, !Instrs, !IO) :- - globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO), - LabelStr = opt_util__format_proc_label(ProcLabel), + globals.io_lookup_bool_option(very_verbose, VeryVerbose, !IO), + LabelStr = opt_util.format_proc_label(ProcLabel), - globals__io_lookup_bool_option(optimize_frames, FrameOpt, !IO), + globals.io_lookup_bool_option(optimize_frames, FrameOpt, !IO), ( FrameOpt = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing frames for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing frames for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), - globals__io_get_globals(Globals, !IO), + globals.io_get_globals(Globals, !IO), frameopt_main(ProcLabel, !C, !Instrs, Globals, Mod1), - optimize__maybe_opt_debug(!.Instrs, !.C, "after frame opt", + maybe_opt_debug(!.Instrs, !.C, "after frame opt", ProcLabel, !OptDebugInfo, !IO), - globals__io_lookup_bool_option(optimize_fulljumps, FullJumpopt, !IO), - globals__io_lookup_bool_option(pessimize_tailcalls, + globals.io_lookup_bool_option(optimize_fulljumps, FullJumpopt, !IO), + globals.io_lookup_bool_option(pessimize_tailcalls, PessimizeTailCalls, !IO), - globals__io_lookup_bool_option(checked_nondet_tailcalls, + globals.io_lookup_bool_option(checked_nondet_tailcalls, CheckedNondetTailCalls, !IO), ( ( FullJumpopt = yes @@ -422,16 +421,16 @@ optimize__middle(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, -> ( VeryVerbose = yes, - io__write_string("% Optimizing jumps for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing jumps for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), jumpopt_main(LayoutLabelSet, MayAlterRtti, ProcLabel, FullJumpopt, Final, PessimizeTailCalls, CheckedNondetTailCalls, !C, !Instrs, _Mod2), - optimize__maybe_opt_debug(!.Instrs, !.C, "after jumps", + maybe_opt_debug(!.Instrs, !.C, "after jumps", ProcLabel, !OptDebugInfo, !IO) ; true @@ -440,14 +439,14 @@ optimize__middle(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, Mod1 = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing labels for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing labels for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), labelopt_main(Final, LayoutLabelSet, !Instrs, _Mod3), - optimize__maybe_opt_debug(!.Instrs, !.C, "after labels", + maybe_opt_debug(!.Instrs, !.C, "after labels", ProcLabel, !OptDebugInfo, !IO) ; Mod1 = no @@ -455,40 +454,40 @@ optimize__middle(Final, LayoutLabelSet, ProcLabel, MayAlterRtti, !C, ; FrameOpt = no ), - globals__io_lookup_bool_option(use_local_vars, UseLocalVars, !IO), + globals.io_lookup_bool_option(use_local_vars, UseLocalVars, !IO), ( UseLocalVars = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing local vars for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing local vars for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), - globals__io_lookup_int_option(num_real_r_regs, NumRealRRegs, !IO), - globals__io_lookup_int_option(local_var_access_threshold, + globals.io_lookup_int_option(num_real_r_regs, NumRealRRegs, !IO), + globals.io_lookup_int_option(local_var_access_threshold, AccessThreshold, !IO), - globals__io_lookup_bool_option(auto_comments, AutoComments, !IO), - use_local_vars__main(!Instrs, NumRealRRegs, AccessThreshold, + globals.io_lookup_bool_option(auto_comments, AutoComments, !IO), + use_local_vars_proc(!Instrs, NumRealRRegs, AccessThreshold, AutoComments, ProcLabel, !C), - optimize__maybe_opt_debug(!.Instrs, !.C, "after use_local_vars", + maybe_opt_debug(!.Instrs, !.C, "after use_local_vars", ProcLabel, !OptDebugInfo, !IO) ; UseLocalVars = no ). -:- pred optimize__last(set(label)::in, proc_label::in, counter::in, +:- pred optimize_last(set(label)::in, proc_label::in, counter::in, opt_debug_info::in, list(instruction)::in, list(instruction)::out, io::di, io::uo) is det. -optimize__last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- - globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO), - LabelStr = opt_util__format_proc_label(ProcLabel), +optimize_last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- + globals.io_lookup_bool_option(very_verbose, VeryVerbose, !IO), + LabelStr = opt_util.format_proc_label(ProcLabel), - globals__io_lookup_bool_option(optimize_reassign, Reassign, !IO), - globals__io_lookup_bool_option(optimize_delay_slot, DelaySlot, !IO), - globals__io_lookup_bool_option(use_local_vars, UseLocalVars, !IO), + globals.io_lookup_bool_option(optimize_reassign, Reassign, !IO), + globals.io_lookup_bool_option(optimize_delay_slot, DelaySlot, !IO), + globals.io_lookup_bool_option(use_local_vars, UseLocalVars, !IO), ( ( Reassign = yes ; DelaySlot = yes @@ -499,14 +498,14 @@ optimize__last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- % since they can confuse reassign, wrap_blocks and delay_slot. ( VeryVerbose = yes, - io__write_string("% Optimizing labels for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing labels for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), labelopt_main(no, LayoutLabelSet, !Instrs, _Mod1), - optimize__maybe_opt_debug(!.Instrs, C, "after label opt", + maybe_opt_debug(!.Instrs, C, "after label opt", ProcLabel, !OptDebugInfo, !IO) ; true @@ -515,14 +514,14 @@ optimize__last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- Reassign = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing reassign for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing reassign for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), remove_reassign(!Instrs), - optimize__maybe_opt_debug(!.Instrs, C, "after reassign", + maybe_opt_debug(!.Instrs, C, "after reassign", ProcLabel, !OptDebugInfo, !IO) ; Reassign = no @@ -531,41 +530,41 @@ optimize__last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- DelaySlot = yes, ( VeryVerbose = yes, - io__write_string("% Optimizing delay slot for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing delay slot for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), fill_branch_delay_slot(!Instrs), - optimize__maybe_opt_debug(!.Instrs, C, "after delay slots", + maybe_opt_debug(!.Instrs, C, "after delay slots", ProcLabel, !OptDebugInfo, !IO) ; DelaySlot = no ), ( VeryVerbose = yes, - io__write_string("% Optimizing returns for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Optimizing returns for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), combine_decr_sp(!Instrs), - optimize__maybe_opt_debug(!.Instrs, C, "after combine decr_sp", + maybe_opt_debug(!.Instrs, C, "after combine decr_sp", ProcLabel, !OptDebugInfo, !IO), ( UseLocalVars = yes, ( VeryVerbose = yes, - io__write_string("% Wrapping blocks for ", !IO), - io__write_string(LabelStr, !IO), - io__write_string("\n", !IO) + io.write_string("% Wrapping blocks for ", !IO), + io.write_string(LabelStr, !IO), + io.write_string("\n", !IO) ; VeryVerbose = no ), wrap_blocks(!Instrs), - optimize__maybe_opt_debug(!.Instrs, C, "after wrap blocks", + maybe_opt_debug(!.Instrs, C, "after wrap blocks", ProcLabel, !.OptDebugInfo, _OptDebugInfo, !IO) ; UseLocalVars = no @@ -579,12 +578,12 @@ optimize__last(LayoutLabelSet, ProcLabel, C, !.OptDebugInfo, !Instrs, !IO) :- :- func mangle_name_as_filename(string) = string. mangle_name_as_filename(Str0) = Str :- - string__foldl(escape_dir_char, Str0, "", Str). + string.foldl(escape_dir_char, Str0, "", Str). :- pred escape_dir_char(char::in, string::in, string::out) is det. escape_dir_char(Char, !Str) :- - ( dir__is_directory_separator(Char) -> + ( dir.is_directory_separator(Char) -> !:Str = !.Str ++ "_slash_" ; !:Str = !.Str ++ char_to_string(Char) diff --git a/compiler/use_local_vars.m b/compiler/use_local_vars.m index 34c1bac85..a897ceb4f 100644 --- a/compiler/use_local_vars.m +++ b/compiler/use_local_vars.m @@ -1,7 +1,7 @@ %-----------------------------------------------------------------------------% % vim: ft=mercury ts=4 sw=4 et %-----------------------------------------------------------------------------% -% Copyright (C) 2001-2005 The University of Melbourne. +% Copyright (C) 2001-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. %-----------------------------------------------------------------------------% @@ -58,7 +58,7 @@ %-----------------------------------------------------------------------------% -:- module ll_backend__use_local_vars. +:- module ll_backend.use_local_vars. :- interface. :- import_module ll_backend.llds. @@ -70,7 +70,7 @@ %-----------------------------------------------------------------------------% -:- pred use_local_vars__main(list(instruction)::in, list(instruction)::out, +:- pred use_local_vars_proc(list(instruction)::in, list(instruction)::out, int::in, int::in, bool::in, proc_label::in, counter::in, counter::out) is det. @@ -96,12 +96,12 @@ %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% -use_local_vars__main(Instrs0, Instrs, NumRealRRegs, AccessThreshold, +use_local_vars_proc(Instrs0, Instrs, NumRealRRegs, AccessThreshold, AutoComments, ProcLabel, !C) :- create_basic_blocks(Instrs0, Comments0, ProcLabel, !C, NewLabels, LabelSeq, BlockMap0), flatten_basic_blocks(LabelSeq, BlockMap0, TentativeInstrs), - livemap__build(TentativeInstrs, MaybeLiveMap), + livemap.build(TentativeInstrs, MaybeLiveMap), ( % Instrs0 must have contained C code which cannot be analyzed MaybeLiveMap = no, @@ -110,7 +110,7 @@ use_local_vars__main(Instrs0, Instrs, NumRealRRegs, AccessThreshold, MaybeLiveMap = yes(LiveMap), extend_basic_blocks(LabelSeq, EBBLabelSeq, BlockMap0, EBBBlockMap0, NewLabels), - list__foldl(use_local_vars_block(LiveMap, NumRealRRegs, + list.foldl(use_local_vars_block(LiveMap, NumRealRRegs, AccessThreshold), EBBLabelSeq, EBBBlockMap0, EBBBlockMap), flatten_basic_blocks(EBBLabelSeq, EBBBlockMap, Instrs1), ( @@ -129,10 +129,10 @@ use_local_vars__main(Instrs0, Instrs, NumRealRRegs, AccessThreshold, use_local_vars_block(LiveMap, NumRealRRegs, AccessThreshold, Label, !BlockMap) :- - map__lookup(!.BlockMap, Label, BlockInfo0), + map.lookup(!.BlockMap, Label, BlockInfo0), BlockInfo0 = block_info(BlockLabel, LabelInstr, RestInstrs0, FallInto, JumpLabels, MaybeFallThrough), - counter__init(1, TempCounter0), + counter.init(1, TempCounter0), use_local_vars_instrs(RestInstrs0, RestInstrs, TempCounter0, TempCounter, NumRealRRegs, AccessThreshold, LiveMap, MaybeFallThrough), ( TempCounter = TempCounter0 -> @@ -140,7 +140,7 @@ use_local_vars_block(LiveMap, NumRealRRegs, AccessThreshold, Label, ; BlockInfo = block_info(BlockLabel, LabelInstr, RestInstrs, FallInto, JumpLabels, MaybeFallThrough), - map__det_update(!.BlockMap, Label, BlockInfo, !:BlockMap) + map.det_update(!.BlockMap, Label, BlockInfo, !:BlockMap) ). %-----------------------------------------------------------------------------% @@ -155,7 +155,7 @@ use_local_vars_instrs(!RestInstrs, !TempCounter, MaybeFallThrough), ( AccessThreshold >= 1 -> opt_access(!RestInstrs, !TempCounter, NumRealRRegs, - set__init, AccessThreshold) + set.init, AccessThreshold) ; true ). @@ -180,19 +180,19 @@ opt_assign([Instr0 | TailInstrs0], Instrs, !TempCounter, NumRealRRegs, find_compulsory_lvals(TailInstrs0, LiveMap, MaybeFallThrough, no, MaybeCompulsoryLvals), MaybeCompulsoryLvals = known(CompulsoryLvals), - not set__member(ToLval, CompulsoryLvals) + not set.member(ToLval, CompulsoryLvals) -> - counter__allocate(TempNum, !TempCounter), + counter.allocate(TempNum, !TempCounter), NewLval = temp(r, TempNum), substitute_lval_in_defn(ToLval, NewLval, Instr0, Instr), - list__map_foldl( - exprn_aux__substitute_lval_in_instr(ToLval, NewLval), + list.map_foldl( + exprn_aux.substitute_lval_in_instr(ToLval, NewLval), TailInstrs0, TailInstrs1, 0, _), opt_assign(TailInstrs1, TailInstrs, !TempCounter, NumRealRRegs, LiveMap, MaybeFallThrough), Instrs = [Instr | TailInstrs] ; - counter__allocate(TempNum, !TempCounter), + counter.allocate(TempNum, !TempCounter), NewLval = temp(r, TempNum), substitute_lval_in_instr_until_defn(ToLval, NewLval, TailInstrs0, TailInstrs1, 0, NumSubst), @@ -227,7 +227,7 @@ find_compulsory_lvals([], LiveMap, MaybeFallThrough, _PrevLivevals, MaybeCompulsoryLvals) :- ( MaybeFallThrough = yes(FallThrough), - map__lookup(LiveMap, FallThrough, CompulsoryLvals), + map.lookup(LiveMap, FallThrough, CompulsoryLvals), MaybeCompulsoryLvals = known(CompulsoryLvals) ; MaybeFallThrough = no, @@ -249,14 +249,14 @@ find_compulsory_lvals([Instr | Instrs], LiveMap, MaybeFallThrough, this_file, "find_compulsory_lvals: call without livevals"), % The livevals instruction will include all the live lvals % in MaybeCompulsoryLvals after we return. - !:MaybeCompulsoryLvals = known(set__init) + !:MaybeCompulsoryLvals = known(set.init) ; Uinstr = goto(_Target), PrevLivevals = yes -> % The livevals instruction will include all the live lvals % in MaybeCompulsoryLvals after we return. - !:MaybeCompulsoryLvals = known(set__init) + !:MaybeCompulsoryLvals = known(set.init) ; possible_targets(Uinstr, Labels, NonLabelCodeAddrs), ( @@ -268,8 +268,8 @@ find_compulsory_lvals([Instr | Instrs], LiveMap, MaybeFallThrough, no, !:MaybeCompulsoryLvals) ; Labels = [_ | _], - list__map(map__lookup(LiveMap), Labels, LabelsLiveLvals), - AllLabelsLiveLvals = set__union_list(LabelsLiveLvals), + list.map(map.lookup(LiveMap), Labels, LabelsLiveLvals), + AllLabelsLiveLvals = set.union_list(LabelsLiveLvals), find_compulsory_lvals(Instrs, LiveMap, MaybeFallThrough, no, !:MaybeCompulsoryLvals), union_maybe_compulsory_lvals(AllLabelsLiveLvals, @@ -287,7 +287,7 @@ find_compulsory_lvals([Instr | Instrs], LiveMap, MaybeFallThrough, union_maybe_compulsory_lvals(New, !MaybeCompulsoryLvals) :- ( !.MaybeCompulsoryLvals = known(OldCompulsoryLvals), - set__union(New, OldCompulsoryLvals, AllCompulsoryLvals), + set.union(New, OldCompulsoryLvals, AllCompulsoryLvals), !:MaybeCompulsoryLvals = known(AllCompulsoryLvals) ; !.MaybeCompulsoryLvals = unknown_must_assume_all @@ -306,21 +306,21 @@ opt_access([Instr0 | TailInstrs0], Instrs, !TempCounter, NumRealRRegs, Uinstr0 = assign(ToLval, FromRval), lvals_in_lval(ToLval, ToSubLvals), lvals_in_rval(FromRval, FromSubLvals), - list__append(ToSubLvals, FromSubLvals, SubLvals), - list__filter( + list.append(ToSubLvals, FromSubLvals, SubLvals), + list.filter( base_lval_worth_replacing_not_tried(AlreadyTried0, NumRealRRegs), SubLvals, ReplaceableSubLvals), ReplaceableSubLvals = [ChosenLval | ChooseableRvals] -> OrigTempCounter = !.TempCounter, - counter__allocate(TempNum, !TempCounter), + counter.allocate(TempNum, !TempCounter), TempLval = temp(r, TempNum), lvals_in_lval(ChosenLval, SubChosenLvals), expect(unify(SubChosenLvals, []), this_file, "opt_access: nonempty SubChosenLvals"), substitute_lval_in_instr_until_defn(ChosenLval, TempLval, [Instr0 | TailInstrs0], Instrs1, 0, NumReplacements), - set__insert(AlreadyTried0, ChosenLval, AlreadyTried1), + set.insert(AlreadyTried0, ChosenLval, AlreadyTried1), ( NumReplacements >= AccessThreshold -> TempAssign = assign(TempLval, lval(ChosenLval)) - "factor out common sub lval", @@ -334,12 +334,12 @@ opt_access([Instr0 | TailInstrs0], Instrs, !TempCounter, NumRealRRegs, ; !:TempCounter = OrigTempCounter, opt_access(TailInstrs0, TailInstrs, !TempCounter, NumRealRRegs, - set__init, AccessThreshold), + set.init, AccessThreshold), Instrs = [Instr0 | TailInstrs] ) ; opt_access(TailInstrs0, TailInstrs, !TempCounter, NumRealRRegs, - set__init, AccessThreshold), + set.init, AccessThreshold), Instrs = [Instr0 | TailInstrs] ). @@ -361,7 +361,7 @@ base_lval_worth_replacing(NumRealRRegs, Lval) :- is semidet. base_lval_worth_replacing_not_tried(AlreadyTried, NumRealRRegs, Lval) :- - \+ set__member(Lval, AlreadyTried), + \+ set.member(Lval, AlreadyTried), base_lval_worth_replacing(NumRealRRegs, Lval). %-----------------------------------------------------------------------------% @@ -460,7 +460,7 @@ substitute_lval_in_instr_until_defn_2(OldLval, NewLval, !Instr, !Instrs, !N) :- % contains is itself. true ; - exprn_aux__substitute_lval_in_instr(OldLval, NewLval, !Instr, !N), + exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N), substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N) ) ; @@ -473,10 +473,10 @@ substitute_lval_in_instr_until_defn_2(OldLval, NewLval, !Instr, !Instrs, !N) :- Uinstr0 = goto(_) ; Uinstr0 = computed_goto(_, _), - exprn_aux__substitute_lval_in_instr(OldLval, NewLval, !Instr, !N) + exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N) ; Uinstr0 = if_val(_, _), - exprn_aux__substitute_lval_in_instr(OldLval, NewLval, !Instr, !N) + exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N) ; Uinstr0 = save_maxfr(_) ; @@ -489,7 +489,7 @@ substitute_lval_in_instr_until_defn_2(OldLval, NewLval, !Instr, !Instrs, !N) :- % contains is itself. true ; - exprn_aux__substitute_lval_in_instr(OldLval, NewLval, !Instr, !N), + exprn_aux.substitute_lval_in_instr(OldLval, NewLval, !Instr, !N), substitute_lval_in_instr_until_defn(OldLval, NewLval, !Instrs, !N) ) ; diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile index fd2c39846..e040dbcec 100644 --- a/tests/valid/Mmakefile +++ b/tests/valid/Mmakefile @@ -87,6 +87,7 @@ OTHER_PROGS= \ empty_bound_inst_list \ empty_switch \ error \ + eval \ existential_cons \ explicit_quant \ export_before_func \ diff --git a/tests/valid/eval.m b/tests/valid/eval.m new file mode 100644 index 000000000..20cdc558c --- /dev/null +++ b/tests/valid/eval.m @@ -0,0 +1,66 @@ +% This is a regression test. The compiler on 29 January, 2006 aborted with +% the message "Software Error: basic_block.m: Unexpected: extend_basic_blocks: +% fall through mismatch" when invoked with -O0 --optimize-repeat=0 +% --optimize-saved-vars on this file. +% +% The contents of this file are an extract from eval.m in the CVS directory +% benchmarks/progs/icfp2000. + +:- module eval. +:- interface. + +:- import_module bool. +:- import_module list. +:- import_module io. + +:- type token_list == list(token_group). + +:- type token_group + ---> single_token(token) + ; function(token_list) + ; array(token_list). + +:- type token + ---> identifier(string) + ; binder(string) + ; boolean(bool) + ; number(int) + ; string(string). + +:- type code == token_list. + +:- pred interpret(code::in, io__state::di, io__state::uo) is det. + +%-----------------------------------------------------------------------------% + +:- implementation. + +:- import_module map. +:- import_module array. + +:- type value + ---> boolean(bool) + ; int(int) + ; real(float) + ; string(string). + +:- type id == string. + +:- type env == map(id, value). + +:- type stack == list(value). + +interpret(Code) --> + initial_setup(Env0, Stack0), + interpret(Code, Env0, Stack0, _Env, _Stack). + +:- pred initial_setup(env::out, stack::out, + io__state::di, io__state::uo) is det. + +initial_setup(Env, []) --> + { map__init(Env) }. + +:- pred interpret(code::in, env::in, stack::in, + env::out, stack::out, io__state::di, io__state::uo) is det. + +interpret(_, Env, Stack, Env, Stack) --> [].