[m-rev.] diff: fix --deep-profile-tail-recursion

Zoltan Somogyi zs at csse.unimelb.edu.au
Wed Jul 6 07:59:07 AEST 2011


Fix bugs that prevented the compiler from bootstrapping in deep profiling
grades with --deep-profile-tail-recursion enabled.

compiler/deep_profiler.m:
	Apply the tail recursion optimization only to procedures that are
	not mutually recursive with any other procedure. (The transformation
	cannot keep track of invocation counts in such cases.) Apply this
	restriction even when the possible mutual recursion is not visible
	to dependency_graph.m.

	Refer to the call_site_nums_N type constructors with the correct arity.

compiler/proc_gen.m:
	The procedures generated by the tail recursion transformation
	do not have their own proc_static structures; they use those
	of the original procedure (whose clones they are). Do not
	insist on them having their own proc_static structure.

tools/unary:
	Add this new tool, which was instrumental in tracking down
	the problems above.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/extra
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/extra
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/doc
cvs diff: Diffing boehm_gc/libatomic_ops/src
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/armcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops/tests
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/m4
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.113
diff -u -b -r1.113 deep_profiling.m
--- compiler/deep_profiling.m	23 May 2011 05:08:01 -0000	1.113
+++ compiler/deep_profiling.m	5 Jul 2011 21:25:57 -0000
@@ -125,7 +125,15 @@
 
 apply_deep_prof_tail_rec_transform_to_scc(SCC, !ModuleInfo) :-
     % For the time being, we only look for self-tail-recursive calls.
-    list.foldl(apply_deep_prof_tail_rec_transform_to_proc, SCC, !ModuleInfo).
+    % If the SCC contains more than one procedure, a self-tail-recursive
+    % call in Proc A could end up calling the other procedure Proc B
+    % in the SCC, which could then call back to Proc A. This would screw up
+    % our bookkeeping.
+    ( SCC = [PredProcId] ->
+        apply_deep_prof_tail_rec_transform_to_proc(PredProcId, !ModuleInfo)
+    ;
+        true
+    ).
 
 :- pred apply_deep_prof_tail_rec_transform_to_proc(pred_proc_id::in,
     module_info::in, module_info::out) is det.
@@ -135,6 +143,7 @@
     module_info_get_preds(!.ModuleInfo, PredTable0),
     map.lookup(PredTable0, PredId, PredInfo0),
     pred_info_get_arg_types(PredInfo0, Types),
+    pred_info_get_origin(PredInfo0, Origin),
     pred_info_get_procedures(PredInfo0, ProcTable0),
     map.lookup(ProcTable0, ProcId, ProcInfo0),
     proc_info_get_goal(ProcInfo0, Goal0),
@@ -152,10 +161,20 @@
             [PredProcId - ClonePredProcId], Detism, Outputs),
         apply_deep_prof_tail_rec_to_goal(Goal0, Goal, TailRecInfo,
             no, FoundTailCall, _Continue),
-        FoundTailCall = yes
+        FoundTailCall = yes,
+        % The unification or comparison procedure for a type can be called
+        % from builtin.unify or builtin.compare respectively, through the
+        % type_ctor_info of an argument type. This means that we cannot
+        % guarantee that a unification or comparison procedure is alone
+        % in its SCC unless it cannot call builtin.unify and builtin.compare.
+        (
+            Origin = origin_special_pred(_)
+        =>
+            goal_contains_builtin_unify_or_compare(Goal) = no
+        )
     ->
         proc_info_set_goal(Goal, ProcInfo0, ProcInfo1),
-        figure_out_rec_call_numbers(Goal, 0, _N, [], TailCallSites),
+        figure_out_rec_call_numbers(Goal, 0, _Num, [], TailCallSites),
         OrigDeepRecInfo = yes(deep_recursion_info(
             deep_prof_outer_proc(ClonePredProcId),
             [visible_scc_data(PredProcId, ClonePredProcId, TailCallSites)])),
@@ -208,6 +227,82 @@
         Outputs = [Var | LaterOutputs]
     ).
 
+:- func goal_contains_builtin_unify_or_compare(hlds_goal) = bool.
+
+goal_contains_builtin_unify_or_compare(Goal) = Contains :-
+    Goal = hlds_goal(GoalExpr, _GoalInfo),
+    (
+        GoalExpr = unify(_, _, _, _, _),
+        Contains = no
+    ;
+        ( GoalExpr = generic_call(_, _, _, _)
+        ; GoalExpr = plain_call(_, _, _, _, _, _)
+        ),
+        % Unfortunately, even if the procedure we are calling is neither
+        % builtin.unify nor builtin.compare, we cannot know whether it
+        % can call those predicates directly or indirectly.
+        Contains = yes
+    ;
+        GoalExpr = call_foreign_proc(Attributes, _, _, _, _, _, _),
+        MayCallMercury = get_may_call_mercury(Attributes),
+        (
+            MayCallMercury = proc_will_not_call_mercury,
+            Contains = no
+        ;
+            MayCallMercury = proc_may_call_mercury,
+            % The Mercury code may call builtin.unify or builtin.compare.
+            Contains = yes
+        )
+    ;
+        ( GoalExpr = conj(_, Goals)
+        ; GoalExpr = disj(Goals)
+        ),
+        Contains = goals_contain_builtin_unify_or_compare(Goals)
+    ;
+        GoalExpr = switch(_, _, Cases),
+        Contains = cases_contain_builtin_unify_or_compare(Cases)
+    ;
+        GoalExpr = if_then_else(_, Cond, Then, Else),
+        (
+            goal_contains_builtin_unify_or_compare(Cond) = no,
+            goal_contains_builtin_unify_or_compare(Then) = no,
+            goal_contains_builtin_unify_or_compare(Else) = no
+        ->
+            Contains = no
+        ;
+            Contains = yes
+        )
+    ;
+        ( GoalExpr = negation(SubGoal)
+        ; GoalExpr = scope(_, SubGoal)
+        ),
+        Contains = goal_contains_builtin_unify_or_compare(SubGoal)
+    ;
+        GoalExpr = shorthand(_),
+        unexpected($module, $pred, "shorthand")
+    ).
+
+:- func goals_contain_builtin_unify_or_compare(list(hlds_goal)) = bool.
+
+goals_contain_builtin_unify_or_compare([]) = no.
+goals_contain_builtin_unify_or_compare([Goal | Goals]) = Contains :-
+    ( goal_contains_builtin_unify_or_compare(Goal) = yes ->
+        Contains = yes
+    ;
+        Contains = goals_contain_builtin_unify_or_compare(Goals)
+    ).
+
+:- func cases_contain_builtin_unify_or_compare(list(case)) = bool.
+
+cases_contain_builtin_unify_or_compare([]) = no.
+cases_contain_builtin_unify_or_compare([Case | Cases]) = Contains :-
+    Case = case(_, _, Goal),
+    ( goal_contains_builtin_unify_or_compare(Goal) = yes ->
+        Contains = yes
+    ;
+        Contains = cases_contain_builtin_unify_or_compare(Cases)
+    ).
+
 %-----------------------------------------------------------------------------%
 
 :- type deep_prof_tail_rec_info
@@ -1647,8 +1742,7 @@
     VarInfo0 = !.DeepInfo ^ deep_varinfo,
     ProfilingBuiltin = mercury_profiling_builtin_module,
     CellTypeName = string.format("call_site_nums_%d", [i(Length)]),
-    CellTypeCtor = type_ctor(qualified(ProfilingBuiltin, CellTypeName),
-        Length),
+    CellTypeCtor = type_ctor(qualified(ProfilingBuiltin, CellTypeName), 0),
     construct_type(CellTypeCtor, [], CellType),
     generate_var("CSNCell", CellType, CellVar, VarInfo0, VarInfo),
     !DeepInfo ^ deep_varinfo := VarInfo,
Index: compiler/proc_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/proc_gen.m,v
retrieving revision 1.48
diff -u -b -r1.48 proc_gen.m
--- compiler/proc_gen.m	17 Jun 2011 07:51:18 -0000	1.48
+++ compiler/proc_gen.m	5 Jul 2011 21:25:58 -0000
@@ -446,8 +446,8 @@
         proc_info_get_maybe_deep_profile_info(ProcInfo, MaybeHLDSDeepInfo),
         (
             MaybeHLDSDeepInfo = yes(HLDSDeepInfo),
-            DeepProfInfo = generate_deep_prof_info(ProcInfo, HLDSDeepInfo),
-            MaybeDeepProfInfo = yes(DeepProfInfo)
+            MaybeDeepProfInfo =
+                maybe_generate_deep_prof_info(ProcInfo, HLDSDeepInfo)
         ;
             MaybeHLDSDeepInfo = no,
             MaybeDeepProfInfo = no
@@ -560,17 +560,13 @@
         true
     ).
 
-:- func generate_deep_prof_info(proc_info, deep_profile_proc_info)
-    = proc_deep_prof_info.
+:- func maybe_generate_deep_prof_info(proc_info, deep_profile_proc_info)
+    = maybe(proc_deep_prof_info).
 
-generate_deep_prof_info(ProcInfo, HLDSDeepInfo) = DeepProfInfo :-
+maybe_generate_deep_prof_info(ProcInfo, HLDSDeepInfo) = MaybeDeepProfInfo :-
     HLDSDeepInfo ^ deep_layout = MaybeHLDSDeepLayout,
     (
-        MaybeHLDSDeepLayout = yes(HLDSDeepLayout)
-    ;
-        MaybeHLDSDeepLayout = no,
-        unexpected($module, $pred, "no HLDS deep profiling layout info")
-    ),
+        MaybeHLDSDeepLayout = yes(HLDSDeepLayout),
     HLDSDeepLayout = hlds_deep_layout(HLDSProcStatic, HLDSExcpVars),
     HLDSDeepInfo ^ deep_orig_body = OriginalProcBody,
     HLDSExcpVars = hlds_deep_excp_vars(TopCSDVar, MiddleCSDVar,
@@ -596,7 +592,12 @@
     DeepExcpSlots = deep_excp_slots(TopCSDSlotNum, MiddleCSDSlotNum,
         OldOutermostSlotNum),
     DeepProfInfo = proc_deep_prof_info(HLDSProcStatic, DeepExcpSlots,
-        OriginalProcBody).
+            OriginalProcBody),
+        MaybeDeepProfInfo = yes(DeepProfInfo)
+    ;
+        MaybeHLDSDeepLayout = no,
+        MaybeDeepProfInfo = no
+    ).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
cvs diff: Diffing compiler/notes
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_cairo
cvs diff: Diffing extras/graphics/mercury_cairo/samples
cvs diff: Diffing extras/graphics/mercury_cairo/samples/data
cvs diff: Diffing extras/graphics/mercury_cairo/tutorial
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/monte
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/concurrency
cvs diff: Diffing samples/concurrency/dining_philosophers
cvs diff: Diffing samples/concurrency/midimon
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/java_interface
cvs diff: Diffing samples/java_interface/java_calls_mercury
cvs diff: Diffing samples/java_interface/mercury_calls_java
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/stm
cvs diff: Diffing tests/stm/orig
cvs diff: Diffing tests/stm/orig/stm-compiler
cvs diff: Diffing tests/stm/orig/stm-compiler/test1
cvs diff: Diffing tests/stm/orig/stm-compiler/test10
cvs diff: Diffing tests/stm/orig/stm-compiler/test2
cvs diff: Diffing tests/stm/orig/stm-compiler/test3
cvs diff: Diffing tests/stm/orig/stm-compiler/test4
cvs diff: Diffing tests/stm/orig/stm-compiler/test5
cvs diff: Diffing tests/stm/orig/stm-compiler/test6
cvs diff: Diffing tests/stm/orig/stm-compiler/test7
cvs diff: Diffing tests/stm/orig/stm-compiler/test8
cvs diff: Diffing tests/stm/orig/stm-compiler/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/bm2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/stmqueue
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test10
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test11
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par/test9
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test1
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test2
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test3
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test4
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test5
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test6
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test7
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test8
cvs diff: Diffing tests/stm/orig/stm-compiler-par-asm_fast/test9
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
Index: tools/unary
===================================================================
RCS file: tools/unary
diff -N tools/unary
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tools/unary	5 Jul 2011 21:26:01 -0000
@@ -0,0 +1,511 @@
+#!/bin/sh
+#
+# vim: ts=4 sw=4 et
+#
+# This script finds miscompiled procedures in a module after the binary script
+# has identified the module.
+#
+# Given
+#
+# - a stage2 directory that works (stage2.ok), which must have
+#   its object files,
+# - a stage2 directory that does not work (stage2.bad), which must have
+#   its Mmake.params file,
+# - a directory name (library, compiler etc),
+# - the name of the bad module in that directory (list, hlds_data, etc), and
+# - a limit number
+#
+# this script compiles the bad module with the parameters from
+# stage2.bad/Mmake.params plus --experiment=N, varying N from 1 to the limit,
+# and finds out which values of N cause a problem.
+#
+# The test for the cobbled-up stage2 compiler is either bootstrap checking
+# (the default), some initial part of bootstrap checking (making dependencies,
+# compiling the library), the successful execution of all the test cases in
+# one or more subdirectories of the tests directory, or the successful
+# execution of a single command.
+
+usage="\
+Usage: $0 [options] dirname modulename merfilename limit
+Options:
+    -b-, --no-bootcheck
+        Do not perform a bootcheck; check only the tests directory
+        or the single command.
+    -c, --compile-only
+        Check the successful creation of the stage3 .c files,
+        but do not compare stage2.ok and stage3.
+    -C <mmc_command>
+        Use the given string as the command to invoke the Mercury compiler.
+        The string may include options.
+    -d, --dependency-only
+        Make dependencies for stage3 only. Do not compile stage3.
+    -h, --help
+        Display this usage message.
+    -j <num-jobs>, --jobs <num-jobs>
+        Run using <num-jobs> different parallel processes.
+    -l, --library-only
+        Check the successful creation of the stage3 .c files in the
+        library, but do not compile the compiler directory.
+    -m <mmake-args>, --mmake-args <mmake-args>
+        Pass <mmake-args> as options to \`mmake'.
+    -o <filename>, --output-file <filename>
+        Output results to <filename>.
+    -r, --copy-runtime
+        Copy the runtime directory instead of linking it.
+        This is necessary if the test uses a compilation model option
+        that differs from the one used in the main runtime directory.
+    -s <command>, --single-command <command>
+        Execute the given command using each constructed compiler.
+    -t <testdir>, --test-dir <testdir>
+        Execute runtests from the named subdirectory of tests.
+"
+
+# If you change this, you will also need to change the files indicated
+# in scripts/c2init.in.
+STD_LIB_NAME=mer_std
+
+set -x
+
+bootcheck=""
+compile_only=""
+mmc_command="mmc"
+dependency_only=""
+library_only=""
+jfactor=
+mmake_opts=""
+outfile=""
+copy_runtime=false
+single_command=""
+testdirs=""
+alldirs=""
+compare_to_bad=""
+basis="ok"
+
+while [ $# -gt 0 ]; do
+    case "$1" in
+
+    -b-|--no-bootcheck)
+        bootcheck="-b-" ;;
+
+    -c|--compile-only)
+        compile_only="-c" ;;
+
+    -C)
+        mmc_command="$2"; shift ;;
+
+    -d|--dependency-only)
+        dependency_only="-d" ;;
+
+    -h|--help)
+        echo "$usage"
+        exit 0 ;;
+
+    -j|--jobs)
+        jfactor="-j$2"; shift ;;
+    -j*)
+        jfactor="-j` expr $1 : '-j\(.*\)' `" ;;
+    --jobs*)
+        jfactor="--jobs` expr $1 : '--jobs\(.*\)' `" ;;
+
+    -l|--library-only)
+        library_only="-l" ;;
+
+    -m|--mmake)
+        mmake_opts="$mmake_opts $2"; shift ;;
+
+    -o|--output-file)
+        outfile="-o $2"; shift ;;
+    -o*)
+        outfile="-o ` expr $1 : '-o\(.*\)' `"; ;;
+
+    -r|--copy-runtime)
+        copy_runtime=true ;;
+
+    -s|--single-command)
+        single_command="$2"; shift ;;
+    -s*)
+        single_command=` expr "$1" : '-s\(.*\)' ` ;;
+    --single-command*)
+        single_command=` expr "$1" : '--single-command\(.*\)' ` ;;
+
+    -t|--test-dir)
+        testdirs="$testdirs -t$2"; shift ;;
+    -t*)
+        testdirs="$testdirs ` expr $1 : '-t\(.*\)' `" ;;
+
+    -*)
+        echo "$0: unknown option \`$1'" 1>&2
+        echo "$usage" 1>&2
+        exit 1 ;;
+
+    *)
+        break
+        ;;
+    esac
+    shift
+done
+
+case "$#" in
+    4)
+        tested_dir_name="$1"
+        tested_module_name="$2"
+        tested_file_name="$3"
+        limit="$4"
+        ;;
+    *)
+        echo "$usage" 1>&2
+        exit 1 ;;
+esac
+
+base=ok
+trial=bad
+expected=success
+
+if test -d stage2.ok -a -d stage2.bad
+then
+    echo "stage2.ok and stage2.bad both present"
+else
+    echo "at least one of stage2.ok and stage2.bad is missing"
+    exit 1
+fi
+
+if test ! -d stage2.ok/${tested_dir_name}
+then
+    echo stage2.ok/${tested_dir_name} does not exist
+    exit 1
+fi
+
+if test ! -f stage2.ok/${tested_dir_name}/${tested_file_name}.m
+then
+    echo stage2.ok/${tested_dir_name}/${tested_file_name}.m does not exist
+    exit 1
+fi
+
+if test ! -f stage2.ok/${tested_dir_name}/${tested_module_name}.c
+then
+    echo stage2.ok/${tested_dir_name}/${tested_module_name}.c does not exist
+    exit 1
+fi
+
+root=`/bin/pwd`
+trueroot=`echo $root | sed '
+s:/mount/munkora/mercury:/home/mercury:
+s:/mount/munkora/home/mercury:/home/mercury:
+s:/mount/munkora/clp/mercury:/home/mercury:'`
+PATH=$root/tools:$PATH
+export PATH
+
+if test "$RMSTAGECMD" = ""
+then
+    RMSTAGECMD="/bin/rm -fr"
+fi
+
+echo "starting at `date`"
+
+for dir in $base $trial
+do
+    for subdir in library mdbcomp compiler
+    do
+        case $subdir in
+            library)    example_o=builtin.o ;;
+            mdbcomp)    example_o=mdbcomp.prim_data.o ;;
+            compiler)   example_o=check_hlds.cse_detection.o ;;
+        esac
+
+        if test -f stage2.$dir/$subdir/$example_o
+        then
+            echo "stage2.$dir/$subdir seems to have its object files"
+        else
+            echo "reconstructing object files in stage2.$dir/$subdir"
+            ( cd stage2.$dir/$subdir; mmake )
+        fi
+    done
+done
+
+echo "starting unary at `date`"
+
+set +x
+[ -d stage2 ] || mkdir stage2
+$RMSTAGECMD $trueroot/stage2/compiler < /dev/null &
+$RMSTAGECMD $trueroot/stage2/library < /dev/null &
+wait
+$RMSTAGECMD $trueroot/stage2/* < /dev/null
+echo linking stage 2... 1>&2
+cd stage2
+ln -s $root/main.c .
+mkdir compiler
+cd compiler
+ln -s $root/compiler/[a-h]*.m .
+ln -s $root/compiler/[i-o]*.m .
+ln -s $root/compiler/[p-s]*.m .
+ln -s $root/compiler/[t-z]*.m .
+ln -s $root/compiler/*.pp .
+cp $root/compiler/Mmake* .
+cp $root/compiler/Mercury* .
+cp $root/compiler/*FLAGS* .
+cp $root/compiler/.mgnuc* .
+cd $root/stage2
+mkdir library
+cd library
+ln -s $root/library/[a-l]*.m .
+ln -s $root/library/[m-z]*.m .
+ln -s $root/library/*.init .
+cp $root/library/print_extra_inits .
+cp $root/library/Mmake* .
+cp $root/library/Mercury* .
+cp $root/library/*FLAGS* .
+cp $root/library/.mgnuc* .
+cd $root/stage2
+mkdir mdbcomp
+cd mdbcomp
+ln -s $root/mdbcomp/*.m .
+ln -s $root/mdbcomp/*.init .
+cp $root/mdbcomp/Mmake* .
+cp $root/mdbcomp/Mercury* .
+cp $root/mdbcomp/*FLAGS* .
+cp $root/mdbcomp/.mgnuc* .
+cd $root/stage2
+if "$copy_runtime"
+then
+    mkdir runtime
+    cd runtime
+    ln -s $root/runtime/*.h .
+    ln -s $root/runtime/*.c .
+    ln -s $root/runtime/*.in .
+    ln -s $root/runtime/machdeps .
+    cp $root/runtime/Mmake* .
+    cd $root/stage2
+else
+    # $root/runtime may be in a different grade from the stage2 directories.
+    ln -s $root/stage2.ok/runtime .
+fi
+ln -s $root/boehm_gc .
+ln -s $root/browser .
+ln -s $root/ssdb .
+ln -s $root/trace .
+ln -s $root/robdd .
+ln -s $root/doc .
+ln -s $root/scripts .
+ln -s $root/util .
+ln -s $root/profiler .
+ln -s $root/deep_profiler .
+ln -s $root/tools .
+ln -s $root/conf* .
+ln -s $root/aclocal.m4 .
+ln -s $root/VERSION .
+ln -s $root/Mercury.options .
+ln -s $root/.*.in .
+rm -f config*.log
+cp $root/stage2.ok/Mmake* .
+cd $root
+
+# We don't copy the .d files. This prevents mmake from trying to remake any
+# of the .c and .o files, which we provide in the form they should be used.
+
+# cp stage2.ok/library/*.d stage2/library
+cp stage2.ok/library/*.dep stage2/library
+cp stage2.ok/library/*.dv stage2/library
+cp stage2.ok/library/*.int0 stage2/library
+cp stage2.ok/library/*.int3 stage2/library
+cp stage2.ok/library/*.date3 stage2/library
+cp stage2.ok/library/*.int stage2/library
+cp stage2.ok/library/*.int2 stage2/library
+cp stage2.ok/library/*.date stage2/library
+cp stage2.ok/library/*.opt stage2/library
+cp stage2.ok/library/*.optdate stage2/library
+cp stage2.ok/library/*.trans_opt stage2/library
+cp stage2.ok/library/*.trans_opt_date stage2/library
+cp stage2.ok/library/*.mh stage2/library
+cp stage2.ok/library/*.mih stage2/library
+# cp stage2.ok/mdbcomp/*.d stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.dep stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.dv stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.int0 stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.int3 stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.date3 stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.int stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.int2 stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.date stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.mh stage2/mdbcomp
+cp stage2.ok/mdbcomp/*.mih stage2/mdbcomp
+# cp stage2.ok/compiler/*.d stage2/compiler
+cp stage2.ok/compiler/*.dep stage2/compiler
+cp stage2.ok/compiler/*.dv stage2/compiler
+cp stage2.ok/compiler/*.int0 stage2/compiler
+cp stage2.ok/compiler/*.int3 stage2/compiler
+cp stage2.ok/compiler/*.date3 stage2/compiler
+cp stage2.ok/compiler/*.int stage2/compiler
+cp stage2.ok/compiler/*.int2 stage2/compiler
+cp stage2.ok/compiler/*.date stage2/compiler
+cp stage2.ok/compiler/*.mh stage2/compiler
+cp stage2.ok/compiler/*.mih stage2/compiler
+
+if test "$bootcheck" = ""
+then
+    cd $root
+    [ -d stage3 ] || mkdir stage3
+    $RMSTAGECMD $trueroot/stage3/compiler < /dev/null &
+    $RMSTAGECMD $trueroot/stage3/library < /dev/null &
+    wait
+    $RMSTAGECMD $trueroot/stage3/* < /dev/null
+    echo linking stage 3... 1>&2
+    cd stage3
+    ln -s $root/main.c
+    mkdir compiler
+    cd compiler
+    # Break up the links into several chunks.
+    # This is needed to cope with small limits
+    # on the size of argument vectors.
+    ln -s $root/compiler/[a-h]*.m .
+    ln -s $root/compiler/[i-o]*.m .
+    ln -s $root/compiler/[p-s]*.m .
+    ln -s $root/compiler/[t-z]*.m .
+    ln -s $root/compiler/*.pp .
+    cp $root/compiler/Mmake* .
+    cp $root/compiler/Mercury* .
+    cp $root/compiler/*FLAGS* .
+    cp $root/compiler/.mgnuc* .
+    cd $root/stage3
+    mkdir library
+    cd library
+    ln -s $root/library/[a-l]*.m .
+    ln -s $root/library/[m-z]*.m .
+    ln -s $root/library/*.init .
+    cp $root/library/Mercury* .
+    cp $root/library/*FLAGS* .
+    cp $root/library/.mgnuc* .
+    cp $root/library/Mmake* .
+    cd $root/stage3
+    mkdir mdbcomp
+    cd mdbcomp
+    ln -s $root/mdbcomp/*.m .
+    ln -s $root/mdbcomp/*.init .
+    cp $root/mdbcomp/Mercury* .
+    cp $root/mdbcomp/*FLAGS* .
+    cp $root/mdbcomp/.mgnuc* .
+    cp $root/mdbcomp/Mmake* .
+    cd $root/stage3
+    ln -s $root/boehm_gc .
+    ln -s $root/browser .
+    ln -s $root/ssdb .
+    ln -s $root/trace .
+    ln -s $root/doc .
+    ln -s $root/scripts .
+    ln -s $root/util .
+    ln -s $root/profiler .
+    ln -s $root/deep_profiler .
+    ln -s $root/runtime .
+    ln -s $root/tools .
+    ln -s $root/conf* .
+    ln -s $root/aclocal.m4 .
+    ln -s $root/VERSION .
+    ln -s $root/Mercury.options .
+    ln -s $root/.*.in .
+    rm -f config*.log
+    /bin/rm -f Mmake*
+    cp $root/stage2.$basis/Mmake* .
+    # cp $root/stage2.ok/so_locations .
+    cd $root
+fi
+
+set -x
+
+if "$copy_runtime"
+then
+    if (cd stage2 ; mmake $mmake_opts $jfactor runtime)
+    then
+        echo "building of stage 2 runtime successful"
+    else
+        echo "building of stage 2 runtime not successful"
+        exit 1
+    fi
+fi
+
+cp stage2.ok/main.o stage2
+
+for subdir in library mdbcomp
+do
+    echo linking stage2/$subdir from stage2.ok/$subdir 1>&2
+    cp stage2.ok/$subdir/*.[co] stage2/$subdir
+    cp stage2.ok/$subdir/*.pic_o stage2/$subdir
+done
+
+for subdir in compiler
+do
+    echo linking stage2/$subdir from stage2.ok/$subdir 1>&2
+    cp stage2.ok/$subdir/*.[co] stage2/$subdir
+done
+
+# start out with all files in stage2 coming from stage2.$base
+
+set +x
+echo linking stage2 from stage2.$base 1>&2
+cp stage2.$base/library/*.[co] stage2/library
+cp stage2.$base/library/*.pic_o stage2/library
+cp stage2.$base/compiler/*.[co] stage2/compiler
+set -x
+
+# find the set of candidate modules
+
+samen=""
+goodn=""
+badn=""
+/bin/rm -fr $root/SAME_C > /dev/null 2>&1
+/bin/rm -fr $root/GOOD_C > /dev/null 2>&1
+/bin/rm -fr $root/BAD_C  > /dev/null 2>&1
+mkdir $root/SAME_C
+mkdir $root/GOOD_C
+mkdir $root/BAD_C
+
+/bin/rm $root/.unary.progress
+
+n=1
+while test "$n" -le "$limit"
+do
+    # at this point, all the files in stage2 should be from stage2.$base
+    echo "testing $n"
+    echo $n > $root/.unary.checkpoint
+    echo $n >> $root/.unary.progress
+    date >> $root/.unary.progress
+
+    cd $root/stage2/${tested_dir_name}
+    cp $root/stage2.ok/${tested_dir_name}/${tested_module_name}.d .
+    $mmc_command --experiment=$n -C ${tested_file_name}.m
+    /bin/rm ${tested_module_name}.d
+
+    if cmp $root/stage2.ok/${tested_dir_name}/${tested_module_name}.c ${tested_module_name}.c
+    then
+        echo "test $n generated same .c file"
+        samen="$samen $n"
+        cp $root/stage2/${tested_dir_name}/${tested_module_name}.c $root/SAME_C/$n.c
+    else
+        mmake ${tested_module_name}.o
+        if test "${tested_dir_name}" = "library"
+        then
+            mmake ${tested_module_name}.pic_o
+        fi
+
+        cd $root
+
+        if binary_step $bootcheck $compile_only $compare_to_bad $dependency_only $library_only $jfactor -m "$mmake_opts" $outfile $testdirs -s "$single_command"
+        then
+            echo "test $n succeeded"
+            goodn="$goodn $n"
+            cp $root/stage2/${tested_dir_name}/${tested_module_name}.c $root/GOOD_C/$n.c
+        else
+            echo "test $n failed"
+            badn="$badn $n"
+            cp $root/stage2/${tested_dir_name}/${tested_module_name}.c $root/BAD_C/$n.c
+        fi
+    fi
+    n=`expr $n + 1`
+done
+
+echo "the parameter values for same .c are: $samen"
+echo "the parameter values for success are: $goodn"
+echo "the parameter values for failure are: $badn"
+echo
+
+echo
+echo "finishing at `date`"
+exit 0
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list