Commit Graph

15 Commits

Author SHA1 Message Date
Zoltan Somogyi
9baadb3d88 Style improvements in browser and deep_profiler.
deep_profiler/var_use_analysis.m:
    Pass never-varying and slower-varying input arguments first.

    Consistently pass goal lists before the position of the first goal
    in the overall list.

browser/declarative_analyser.m:
browser/declarative_edt.m:
deep_profiler/analysis_utils.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_types.m:
deep_profiler/program_representation_utils.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/timeout.m:
deep_profiler/top_procs.m:
deep_profiler/util.m:
    Minor improvements in programming style.
2025-11-18 16:11:20 +11:00
Zoltan Somogyi
0e41d41286 Make mdprof_create_feedback/feedback.m a package.
mdbcomp/feedback.feedback_info.m:
mdbcomp/feedback.m:
    Move all the contents of feedback.m other than include_module items
    into the new module feedback_info.m, leaving feedback.m a package.

mdbcomp/feedback.automatic_parallelism.m:
    Group the types exported by this module into groups of related types.

    Delete a totally unused type.

deep_profiler/Mmakefile:
slice/Mmakefile:
    Copy the new module.

compiler/check_options.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/introduce_parallelism.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_report_feedback.m:
    Import the new module.
2025-07-25 18:52:31 +02:00
Julien Fischer
cfbbf931e8 Update more copyright notices in deep_profiler.
deep_profiler/*.m:
    As above.
2024-12-29 16:53:18 +11:00
Julien Fischer
2424d820f0 Update copyright notices in deep_profiler.
deep_profiler/*.m:
    As above.
2024-12-22 21:33:06 +11:00
Zoltan Somogyi
06f81f1cf0 Add end_module declarations ...
.. to modules which did not yet have them.
2022-01-09 10:36:15 +11:00
Zoltan Somogyi
3c07fc2121 Use explicit streams in deep_profiler/*.m.
deep_profiler/analysis_utils.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/cliques.m:
deep_profiler/coverage.m:
deep_profiler/dump.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/startup.m:
deep_profiler/var_use_analysis.m:
    Replace implicit streams with explicit streams.

    In some places, simplify some code, often using constructs such as
    string.format that either did not exist or were too expensive to use
    when the original code was written.

    Consistenly use the spelling StdErr over Stderr.

    In mdbprof_dump.m, put filename and reason-for-failing-to-open-that-file
    in the right order in an error message.

deep_profiler/DEEP_FLAGS.in:
    Turn on --warn-implicit-stream-calls for the entire deep_profiler
    directory.

mdbcomp/program_representation.m:
mdbcomp/trace_counts.m:
    Replace implicit streams with explicit streams. These are the two mdbcomp
    modules that (a) used to use implicit streams, and (2) are used by the
    deep profiler.

mdbcomp/Mercury.options:
    Turn on --warn-implicit-stream-calls for these two modules.

slice/mcov.m:
slice/mtc_union.m:
    Conform to the changes in mdbcomp.
2021-03-06 18:30:50 +11:00
Zoltan Somogyi
9095985aa8 Fix more warnings from --warn-inconsistent-pred-order-clauses.
deep_profiler/*.m:
    Fix inconsistencies between (a) the order in which functions and predicates
    are declared, and (b) the order in which they are defined.

    In most modules, either the order of the declarations or the order
    of the definitions made sense, and I changed the other to match.
    In some modules, neither made sense, so I changed *both* to an order
    that *does* make sense (i.e. it has related predicates together).

    In query.m, put the various commands in the same sensible order
    as the code processing them.

    In html_format.m, merge two exported functions together, since
    they can't be used separately.

    In some places, put dividers between groups of related
    functions/predicates, to make the groups themselves more visible.

    In some places, fix comments or programming style.

deep_profiler/DEEP_FLAGS.in:
    Since all the modules in this directory are now free from any warnings
    generated by --warn-inconsistent-pred-order-clauses, specify that option
    by default in this directory to keep it that way.
2017-04-30 15:48:13 +10:00
Zoltan Somogyi
270170416d Bring the style of deep_profiler/* up-to-date.
deep_profiler/*.m:
    Replace ( C -> T ; E ) if-then-elses with (if C then T else E ).

    Replace calls to error/1 with calls to unexpected/3.

    Add some module qualifications where this makes the code easier to read.
2015-07-15 15:30:22 +02:00
Zoltan Somogyi
340c5300e6 Fix spelling in the deep profiler.
Fix some other issues as well that I found while fixing the spelling.

mdbcomp/feedback.automatic_parallelism.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/mdprof_create_feedback.m:
    Rename the best_par_algorithm type to alg_for_finding_best_par,
    since the old name was misleading. Perform the same rename for
    another type based on it, and the option specifying it.

    Remove the functor estimate_speedup_by_num_vars, since it hasn't
    been used by anything in a long time, and won't in the future.

deep_profiler/autopar_calc_overlap.m:
deep_profiler/autopar_costs.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/coverage.m:
deep_profiler/create_report.m:
deep_profiler/dump.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/measurement_units.m:
deep_profiler/measurements.m:
deep_profiler/message.m:
deep_profiler/query.m:
deep_profiler/recursion_patterns.m:
deep_profiler/report.m:
deep_profiler/startup.m:
deep_profiler/var_use_analysis.m:
mdbcomp/mdbcomp.goal_path.m:
mdbcomp/program_representation.m:
    Conform to the above. Fix spelling errors. In some places, improve
    comments and/or variable names.
2014-12-20 23:05:38 +11:00
Zoltan Somogyi
f7237359ae Simplify the deep profiler's feedback mechanism.
mdbcomp/feedback.m:
    Accessing the old representation of feedback information required
    using partially instantiated data structures, dynamic type checking,
    and purity promises. Replace this with a straightforward representation,
    a tuple with a separate field for each supported kind of feedback
    information that contains "yes(...)" if feedback of the given type is
    available and "no" if it isn't.

    Document all the places that need to be updated when a new kind
    of feedback information is added.

    Remove the feedback information used by Tannier's old attempt
    at automatic parallelization, since it hasn't been supported for
    a while now, and won't be in the future.

    The feedback_info structure had a field named fi_program_name that
    comments on several predicates have identified as being the name of
    the Mercury system program (such as mdprof_create_report) that created
    the feedback_info structure. It was actually intended to hold the
    name of the program whose execution yielded the profiling data
    that the feedback_info was created from, and therefore the program
    whose recompilation the feedback_info was intended to help. This diff
    switches the documented meaning of the field from the former to the latter.
    To this end:

    - we rename the field;
    - we fix the comments referring to it,
    - we check whether the names match when new feedback data is added;
    - we check whether the actual program name matches the expected program
      name (if any) when reading in a feedback file, instead of delaying
      the check until later; and
    - we make write_feedback_file use the name in the feedback_info structure
      when writing it out, instead of a name redundantly supplied by its
      caller.

    In clients of feedback.m, some code used to put a program name into
    a feedback_info, and then later check whether the name in there was
    still the one it put there earlier. With this diff, we delete the check.
    We can do this because the profiled program name field of each
    feedback_info is set at initialization, and never changed afterwards.

    We now put a wrapper around each piece of feedback information in the
    texts of feedback files, to tell the code reading the file WHAT KIND
    of feedback information it is. We therefore increment the feedback file
    format version number.

    Group related predicates together.

    Give some predicates better (less ambiguous) names.

    Add prefixes to the names of some function symbols that are
    ambiguous without them.

compiler/handle_options.m:
compiler/introduce_parallelism.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_report_feedback.m:
    Conform to the changes in mdbcomp/feedback.m
2014-12-01 22:12:46 +11:00
Zoltan Somogyi
2d0bfc0674 The algorithm that decides whether the order independent state update
Estimated hours taken: 120
Branches: main

The algorithm that decides whether the order independent state update
transformation is applicable in a given module needs access to the list
of oisu pragmas in that module, and to information about the types
of variables in the procedures named in those pragmas. This diff
puts this information in Deep.procrep files, to make them available
to the autoparallelization feedback program, to which that algorithm
will later be added.

Compilers that have this diff will generate Deep.procrep files in a new,
slightly different format, but the deep profiler will be able to read
Deep.procrep files not just in the new format, but in the old format as well.

runtime/mercury_stack_layout.h:
	Add to module layout structures the fields holding the new information
	we want to put into Deep.procrep files. This means three things:

	- a bytecode array in module layout structures encoding the list
	  of oisu pragmas in the module;
	- additions to the bytecode arrays in procedure layout structures
	  mapping the procedure's variables to their types; and
	- a bytecode array containing the encoded versions of those types
	  themselves in the module layout structure. This allows us to
	  represent each type used in the module just once.

	Since there is now information in module layout structures that
	is needed only for deep profiling, as well as information that is
	needed only for debugging, the old arrangement that split a module's
	information between two structures, MR_ModuleLayout (debug specific
	info) and MR_ModuleCommonLayout (info used by both debugging and
	profiling), is no longer approriate. We could add a third structure
	containing profiling-specific info, but it is simpler to move
	all the info into just one structure, some of whose fields
	may not be used. This wastes only a few words of memory per module,
	but allows the runtime system to avoid unnecessary indirections.

runtime/mercury_types.h:
	Remove the type synonym for the deleted type.

runtime/mercury_grade.h:
	The change in mercury_stack_layout.h destroys binary compatibility
	with previous versions of Mercury for debug and deep profiling grades,
	so bump their grade-component-specific version numbers.

runtime/mercury_deep_profiling.c:
	Write out the information in the new fields in module layout
	structures, if they are filled in.

	Since this changes the format of the Deep.procrep file, bump
	its version number.

runtime/mercury_deep_profiling.h:
runtime/mercury_stack_layout.c:
	Conform to the change to mercury_stack_layout.h.

mdbcomp/program_representation.m:
	Add to module representations information about the oisu pragmas
	defined in that module, and the type table of the module.
	Optionally add to procedure representations a map mapping
	the variables of the procedure to their types.

	Rename the old var_table type to be the var_name_table type,
	since it contains just names. Make the var to type map separate,
	since it will be there only for selected procedures.

	Modify the predicates reading in module and procedure representations
	to allow them to read in the new representation, while still accepting
	the old one. Use the version number in the Deep.procrep file to decide
	which format to expect.

mdbcomp/rtti_access.m:
	Add functions to encode the data representations that this module
	also decodes.

	Conform to the changes above.

mdbcomp/feedback.automatic_parallelism.m:
	Conform the changes above.

mdbcomp/prim_data.m:
	Fix layout.

compiler/layout.m:
	Update the compiler's representation of layout structures
	to conform to the change to runtime/mercury_stack_layout.h.

compiler/layout_out.m:
	Output the new parts of module layout structures.

compiler/opt_debug.m:
	Allow the debugging of code referring to the new parts of
	module layout structures.

compiler/llds_out_file.m:
	Conform to the move to a single module layout structure.

compiler/prog_rep_tables.m:
	This new module provided mechanisms for building the string table
	and the type table components of module layouts. The string table
	part is old (it is moved here from stack_layout.m); the type table
	part is new.

	Putting this code in a module of its own allows us to remove
	a circular dependency between prog_rep.m and stack_layout.m;
	instead, both now just depend on prog_rep_tables.m.

compiler/ll_backend.m:
	Add the new module.

compiler/notes/compiler_design.html:
	Describe the new module.

compiler/prog_rep.m:
	When generating the representation of a module for deep profiling,
	include the information needed by the order independent state update
	analysis: the list of oisu pragmas in the module, if any, and
	information about the types of variables in selected procedures.

	To avoid having these additions increasing the size of the bytecode
	representation too much, convert some fixed 32 bit numbers in the
	bytecode to use variable sized numbers, which will usually be 8 or 16
	bits.

	Do not use predicates from bytecode_gen.m to encode numbers,
	since there is nothing keeping these in sync with the code that
	reads them in mdbcomp/program_representation.m. Instead, use
	new predicates in program_representation.m itself.

compiler/stack_layout.m:
	Generate the new parts of module layouts.

	Remove the code moved to prog_rep_tables.m.

compiler/continuation_info.m:
compiler/proc_gen.m:
	Make some more information available to stack_layout.m.

compiler/prog_data.m:
	Fix some formatting.

compiler/introduce_parallelism.m:
	Conform to the renaming of the var_table type.

compiler/follow_code.m:
	Fix the bug that used to cause the failure of the
	hard_coded/mode_check_clauses test case in deep profiling grades.

deep_profiler/program_representation_utils.m:
	Output the new parts of module and procedure representations,
	to allow the correctness of this change to be tested.

deep_profiler/mdprof_create_feedback.m:
	If we cannot read the Deep.procrep file, print a single error message
	and exit, instead of continuing with an analysis that will generate
	a whole bunch of error messages, one for each attempt to access
	a procedure's representation.

deep_profiler/mdprof_procrep.m:
	Give this program an option that specifies what file it is to
	look at; do not hardwire in "Deep.procrep" in the current directory.

deep_profiler/report.m:
	Add a report type that just prints the representation of a module.
	It returns the same information as mdprof_procrep, but from within
	the deep profiler, which can be more convenient.

deep_profiler/create_report.m:
deep_profiler/display_report.m:
	Respectively create and display the new report type.

deep_profiler/query.m:
	Recognize a query asking for the new report type.

deep_profiler/autopar_calc_overlap.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/autopar_types.m:
deep_profiler/branch_and_bound.m:
deep_profiler/coverage.m:
deep_profiler/display.m:
deep_profiler/html_format.m:
deep_profiler/mdprof_test.m:
deep_profiler/measurements.m:
deep_profiler/query.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/top_procs.m:
deep_profiler/top_procs.m:
	Conform to the changes above.

	Fix layout.

tests/debugger/declarative/dependency.exp2:
	Add this file as a possible expected output. It contains the new
	field added to module representations.
2012-10-24 04:59:55 +00:00
Zoltan Somogyi
d013a4cfcf Change the types that represent forward and reverse goal paths from being
Estimated hours taken: 20
Branches: main

Change the types that represent forward and reverse goal paths from being
wrappers around lists of steps, to being full discriminated union types.
This is meant to accomplish two objectives.

First, since taking the wrappers off and putting them back on is inconvenient,
code often dealt with naked lists of steps, with the meaning of those steps
sometimes being unclear.

Second, in a future change I intend to change the way the debugger represents
goal paths from being strings to being statically allocated terms of the
reverse_goal_path type. This should have two benefits. One is reduced memory
consumption, since two different goal path strings cannot share memory
but two different reverse goal paths can share the memory containing their
common tail (the goal paths steps near the root). The other is that the
declarative debugger won't need to do any conversion from string to structure,
and should therefore be faster.

Having the compiler generate static terms of the reverse_goal_path type into
the .c files it generates for every Mercury program being compiled with
debugging requires it to have access to the definition of that type and all
its components. The best way to do this is to put all those types into a new
builtin module in the library (a debugging equivalent of e.g.
profiling_builtin.m). We cannot put the definition of the list type into
that module without causing considerable backward incompatibilities.

mdbcomp/mdbcomp.goal_path.m:
	Make the change described above.

	Add some more predicates implementing abstract operations on goal
	paths.

browser/declarative_tree.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hlds_goal.m:
compiler/introduce_parallelism.m:
compiler/mode_ordering.m:
compiler/push_goals_together.m:
compiler/rbmm.condition_renaming.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/unneeded_code.m:
deep_profiler/autopar_costs.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/create_report.m:
deep_profiler/message.m:
deep_profiler/program_representation_utils.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/var_use_analysis.m:
	Conform to the change in representation. In some cases, remove
	predicates whose only job was to manipulate wrappers. In others,
	replace concrete operations on lists of steps with abstract operations
	on goal paths.

compiler/mode_constraints.m:
	Comment out some code that I do not understand, which I think never
	worked (not surprising, since the whole module has never been
	operational).

mdbcomp/slice_and_dice.m:
	Since this diff changes the types representing goal paths, it also
	changes their default ordering, as implemented by builtin.compare.
	When ordering slices and dices by goal paths, make the ordering
	explicitly work on the forward goal path, since ordering by the
	reverse goal path (the actual data being used) gives nonintuitive
	results.

library/list.m:
	Speed up some code.

mdbcomp/feedback.automatic_parallelism.m:
	Fix some formatting.
2011-09-26 07:08:58 +00:00
Zoltan Somogyi
237be388c1 Replace mdprof_feedback, which currently does two jobs, with
Estimated hours taken: 1
Branches: main

Replace mdprof_feedback, which currently does two jobs, with
mdprof_create_feedback and mdprof_report_feedback, which do one job each.

deep_profiler/mdprof_feedback.m:
	Remove this module.

deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_report_feedback.m:
	Add these two modules. mdprof_create_feedback.m contains most of the
	code originally in mdprof_feedback.m, while mdprof_report_feedback.m
	contains only the code needed for printing out reports.m

deep_profiler/autopar_reports.m:
	Move here some code that would otherwise hav to duplicated in
	mdprof_create_feedback.m and mdprof_report_feedback.m.

	Keep private the previously exported predicates that are not needed
	outside this module after the above move.

deep_profiler/Mmakefile:
	Replace references to the deleted module with references to the new
	modules.

doc/user_guide.texi:
	Update the only reference to mdprof_feedback in this directory.
2011-09-26 05:37:45 +00:00
Paul Bone
84162465c1 Fix the reporting of the number of parallel conjunctions in a feedback file.
deep_profiler/mdprof_feedback.m:
deep_profiler/autopar_reports.m:
    As above.

    Move some autoparallelism specific code from mdprof_feedback.m to
    autopar_reports.m
2011-04-16 03:13:04 +00:00
Zoltan Somogyi
59b0edacbe New module for calculating the overlap between the conjuncts of a
Estimated hours taken: 2

deep_profiler/autopar_calc_overlap.m:
	New module for calculating the overlap between the conjuncts of a
	parallelised conjunction. Its contents are taken from the old
	autopar_search_callgraph.m.

deep_profiler/autopar_costs.m:
	New module for calculating the costs of goals. Its contents
	are taken from the old autopar_search_callgraph.m.

deep_profiler/autopar_reports.m:
	New module for creating reports. Its contents are taken from
	the old autopar_search_callgraph.m.

deep_profiler/autopar_search_goals.m:
	New module for searching goals for parallelizable conjunctions.
	Its contents are taken from the old autopar_search_callgraph.m.

deep_profiler/autopar_search_callgraph.m:
	Remove the code moved to other modules.

deep_profiler/mdprof_fb.automatic_parallelism.m:
	Add the new modules.

deep_profiler/*.m:
	Remove unnecessary imports.
	Fix copyright years on the new modules.

browser/*.m:
compiler/*.m:
mdbcomp/*.m:
	Remove unnecessary imports.

library/Mercury.options:
	Make it possible to compile a whole workspace with
	--warn-unused-imports by turning that option off for type_desc.m
	(which has a necessary import that --warn-unused-imports thinks
	is unused).
2011-01-27 08:03:54 +00:00