Commit Graph

40 Commits

Author SHA1 Message Date
Zoltan Somogyi
0715d500bd Make the module comment more readable. 2023-03-16 03:01:44 +08:00
Zoltan Somogyi
ee8589d111 Harmonize the two main backends' packages. 2018-07-09 20:22:10 +02:00
Zoltan Somogyi
1fb59caa47 Split up ml_unify_gen.m.
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
    Carve these four modules out of ml_unify_gen.m. The first two handle
    the construction and deconstruction of terms, the third tests whether
    a variable is bound to a given cons_id, and the fourth contains utility
    types and predicates needed by more than one of the other modules.

compiler/ml_unify_gen.m:
    Remove the code moved to the modules above.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Add and document the new modules.

compiler/Mercury.options:
    Require the new modules to have consistency between the order of predicate
    declarations and the order of predicate definitions.

compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_top_gen.m:
    Conform to the change above.
2018-07-09 14:36:54 +02:00
Zoltan Somogyi
18bafbd70d Split up mlds_to_cs.m.
compiler/mlds_to_cs.m:
    Delete this module. Move its contents to the following ten modules.

compiler/mlds_to_cs_class.m:
    Code to output class definitions.

compiler/mlds_to_cs_data.m:
    Code to output lvals, rvals and initializers.

compiler/mlds_to_cs_export.m:
    Code to output entities (e.g. enums) exported to Java.

compiler/mlds_to_cs_file.m:
    The top level code, generating whole Java files.

compiler/mlds_to_cs_func.m:
    Code to output function definitions.

compiler/mlds_to_cs_global.m:
    Code to output the definitions of global variables.

compiler/mlds_to_cs_name.m:
    Code to output various kinds of names.

compiler/mlds_to_cs_stmt.m:
    Code to output statements.

compiler/mlds_to_cs_type.m:
    Code to output types.

compiler/mlds_to_cs_util.m:
    Utilities used by the other mlds_to_cs_*.m modules.

compiler/ml_backend.m:
    Delete the old module, add the new modules.

compiler/Mercury.options:
    Require the new modules to have the declarations and definitions
    of their predicates in a consistent order.

compiler/mercury_compile_mlds_back_end.m:
    Import mlds_to_cs_file.m instead of mlds_to_cs.m.

compiler/handle_options.m:
compiler/ml_target_util.m:
compiler/mlds.m:
    Update some references to the deleted file.
2018-06-30 01:00:51 +02:00
Zoltan Somogyi
4404d7d884 Split up mlds_to_java.m.
compiler/mlds_to_java.m:
    Delete this module. Move its contents to the following eleven modules.

compiler/mlds_to_java_class.m:
    Code to output class definitions.

compiler/mlds_to_java_data.m:
    Code to output lvals, rvals and initializers.

compiler/mlds_to_java_export.m:
    Code to output entities (e.g. enums) exported to Java.

compiler/mlds_to_java_file.m:
    The top level code, generating whole Java files.

compiler/mlds_to_java_func.m:
    Code to output function definitions.

compiler/mlds_to_java_global.m:
    Code to output the definitions of global variables.

compiler/mlds_to_java_name.m:
    Code to output various kinds of names.

compiler/mlds_to_java_stmt.m:
    Code to output statements.

compiler/mlds_to_java_type.m:
    Code to output types.

compiler/mlds_to_java_util.m:
    Utilities used by the other mlds_to_java_*.m modules.

compiler/mlds_to_java_wrap.m:
    Code to create wrapper classes, to help implement function pointers.

compiler/ml_backend.m:
    Delete the old module, add the new modules.

compiler/Mercury.options:
    Require the new modules to have the declarations and definitions
    of their predicates in a consistent order.

compiler/mercury_compile_mlds_back_end.m:
    Import mlds_to_java_file.m instead of mlds_to_java.m.

compiler/mlds.m:
compiler/mlds_to_cs.m:
    Update some references to the deleted file.

compiler/mlds_to_c_class.m:
    Delete some stray ZZZs.
2018-06-29 18:13:12 +02:00
Zoltan Somogyi
17c19ba120 Add mlds_dump.m.
compiler/mlds_dump.m:
    New module to dump out MLDS code in a format suitable for debugging.
    Unlike e.g. mlds_to_c_*.m, using the new module does not require
    any setup, the generated output is not cluttered with rarely-relevant
    details, and the format is clean, simple and direct.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Add and document the new module.

compiler/ml_optimize.m:
    Use the new module if the right compile-time flag is set.
    (This is mostly needed so that we can import the new moule
    without getting an unused import warning.)
2018-06-02 16:22:49 +02:00
Zoltan Somogyi
bd0c5c9dcb Break up mlds_to_c.m into smaller modules.
It has always been one of the compiler's biggest modules, and its size
has recently even further recently. It was over 5600 lines long, and
keeping types and predicates in some kind of organized order has long
been a hard slog.

This diff replaces mlds_to_c.m with ten modules ranging in size
from about 230 lines to about 1200 lines. Each has much better cohesion
than mlds_to_c.m. did.

compiler/mlds_to_c.m:
    Delete this module. Replace it with the following.

compiler/mlds_to_c_file.m:
    The top level; this prints out .c and .h files.

compiler/mlds_to_c_export.m:
    Output things being exported to C code.

compiler/mlds_to_c_func.m:
compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_global.m:
    These output MLDS functions, statements, types, classes and global data
    respectively.

compiler/mlds_to_c_data.m:
    Output MLDS rvals and lvals.

compiler/mlds_to_c_name.m:
    Output various kinds of MLDS names, which are needed
    by more than one module above.

compiler/mlds_to_c_util.m:
    Utility code, mostly to control the output process itself.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Add and document the new modules.

compiler/Mercury.options:
    Keep the declarations and definitions of predicates in the new modules
    in a consistent order.

compiler/mercury_compile_mlds_back_end.m:
compiler/add_pragma_tabling.m:
    Import one of the new modules instead of mlds_to_c.m.
2018-05-15 00:38:41 +02:00
Zoltan Somogyi
fcefbb948d Delete assignments to dead variables in the MLDS.
At the moment, we tend not to generate such assignments, with the exception
of assignments to the MLDS versions of HLDS variables of dummy types.
The reason I am nevertheless adding this optimization is that I intend
to soon add code to ml_unify_gen.m that *will* generate assignments
to dead variables.

The idea is to optimize field updates involving packed arguments.
Given a type such as

:- type t
    --->    f(
                f1      :: bool,
                f2      :: bool,
                f3      :: enum1,
                f4      :: int
            ).

we currently implement a field update such as "T = T0 ^ f4 := 42",
whose HLDS representation is the two unifications

    T0 = f(T0f1, T0f2, T0f3, _),
    T = f(T0f1, T0f2, T0f3, 42)

using code that looks like this:

    T0f1 = (T0[0] >> ...) & ...
    T0f2 = (T0[0] >> ...) & ...
    T0f3 = (T0[0] >> ...) & ...
    T = allocate memory for new memory cell, put on primary tag
    T[0] = (T0f1 << ...) | (T0f2 << ...) | (T0f3 << ...)
    T[1] = 42

I want to implement it using code that looks like this:

    T0w0 = T0[0]
    T = allocate memory for new memory cell, put on primary tag
    T[0] = T0w0
    T[1] = 42

where T0w0 contains the entire first word of the memory cell of T0.
This code avoids a bunch of shifts, ORs and ANDs.

I propose to translate the T0 = f(T0f1, T0f2, T0f3, _) unification into

    T0w0 = T0[0]
    T0f1 = (T0[0] >> ...) & ...
    T0f2 = (T0[0] >> ...) & ...
    T0f3 = (T0[0] >> ...) & ...

while recording in the ml_gen_info/code_info that this *specific* packing of
T0f1, T0f2 and T0f3 is available in T0w0. When translating the following
unification, the code generator will see this, and this will allow it to
generate

    T[0] = T0w0

instead of

    T[0] = (T0f1 << ...) | (T0f2 << ...) | (T0f3 << ...)

However, by this time the assignments to T0f1, T0f2 and T0f3 have already
been generated. Whether or not they are dead assignments depends on whether
other code needs the values of those fields of T0. Deciding this
requires knowledge that the code generator can't have when translating
the deconstruction of T0. Hence the need for a new MLDS-to-MLDS optimization.

compiler/ml_unused_assign.m:
    A new compiler module implementing the new optimization.
    It is not part of ml_optimize.m because ml_optimize.m traverses
    the MLDS forwards, while this optimization requires a backwards traversal:
    you cannot know whether an assignment is dead unless you know that the
    following code does not need the value of the variable it assigns to.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Include the new module.

compiler/mlds.m:
    The new optimization needs extra information about loops.
    When it enters into the loop body, it knows which variables
    are needed *after* the loop, but it does not know which variables
    the loop body first reads and then writes. Without this knowledge,
    it would optimize away assignments to loop control variables,
    such as the increment of i in the loop

    i = 0;
    while (...) {
        ...; i = i+1; ...
    }

    Traditionally, compilers have solved this problem by doing fixpoint
    iteration, adding to the live set at each program point until
    no more additions are possible. We can do better, because we generate
    loops in the MLDS in only two kinds of cases:

    - loops implementing tail recursion, in which case the only extra
      variables that we need to preserve assignments to in the loop body
      are the input arguments of the procedure, and
    - loops created by the compiler itself to loop over a set of alternatives,
      for which the only extra variables that we need to preserve assignments
      to in the loop body are the variables the compiler uses to control
      the loop.

    To make it possible for ml_unused_assign.m to do its job without
    a fixpoint iteration, include in the MLDS representation of every
    while loop a list of these variables.

    Add a type to represent the identify of an MLDS local var,
    for use by some of the modules below. They used to store this info
    in the form of mlds_lvals, but that is not specific enough
    to be used to fill in the new field in while loops.

compiler/ml_proc_gen.m:
    Compute the information needed by the new pass, and invoke it
    if the relevant option is set.

compiler/options.m:
    Add this option. It is for developers only, so it is undocumented.

compiler/ml_util.m:
    Add a utility function needed in several places.

compiler/ml_accurate_gc.m:
compiler/ml_disj_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_lookup_switch.m:
compiler/ml_optimize.m:
compiler/ml_rename_classes.m:
compiler/ml_string_switch.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mlds_to_target_util.m:
    Conform to the changes in mlds.m.
2018-05-09 23:56:28 +02:00
Zoltan Somogyi
234501be75 Remove ml_tailcall.m and associated code.
Now that we can optimize tail recursion for all MLDS targets better via
the MLDS code generator than via ml_tailcall.m, we don't need it anymore.

compiler/ml_tailcall.m:
    Delete this module.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Delete the inclusion and the documentation of the deleted module.

compiler/mark_tail_calls.m:
    Update old references to the deleted module, as well as some comments.

compiler/mercury_compile_mlds_back_end.m:
    Don't invoke the deleted module.

compiler/options.m:
    Delete the (developer-only) options that used to control whether
    we did tail call optimization (TCO) via ml_tailcall.m or not.

compiler/ml_optimize.m:
    Delete the parts of this module that worked in concert with ml_tailcall.m
    to implement TCO.

compiler/mlds.m:
    Delete the field from ml_call_stmts that was needed only by ml_tailcall.m.

compiler/ml_call_gen.m:
    Don't fill in the deleted field.

    Shift here the only part of the old contents of ml_tailcall.m that is
    still needed, the check for whether rvals would become dangling references
    if we discarded the current call's stack frame.

compiler/ml_elim_nested.m:
    Conform to the change to mlds.m, and eliminate an unused field
    in elim_info.

compiler/ml_accurate_gc.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_proc_gen.m:
compiler/ml_rename_classes.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mlds_to_target_util.m:
    Conform to the changes above.
2017-11-10 14:26:32 +11:00
Zoltan Somogyi
bbd6c44a26 Create ml_args_util.m.
Both ml_code_util.m and ml_call_gen.m had predicates that used the same logic
to process lists of arguments. This is not a coincidence; they both process
argument lists, one from the point of the callee, the other from the point
of view of the caller. These have to be kept in lockstep. This is easier
if they are next to each other. This diff therefore moves those predicates
to the same module, a new module named ml_args_util.m.

compiler/ml_call_gen.m:
compiler/ml_code_util.m:
    Delete the new code now in ml_args_util.m.

compiler/ml_args_util.m:
    The new module.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Mention the new module.

compiler/ml_closure_gen.m:
compiler/ml_proc_gen.m:
compiler/ml_top_gen.m:
compiler/rtti_to_mlds.m:
    Conform to the changes above.
2017-08-13 02:06:26 +02:00
Zoltan Somogyi
99696cd31b Carve ml_top_gen.m out of ml_proc_gen.m.
compiler/ml_top_gen.m:
    New module containing the parts of the old ml_proc_gen.m that
    did not translate HLDS procedure definitions.

compiler/ml_proc_gen.m:
    Delete the stuff now in ml_top_gen.m.

    Switch to standard terminology in variable names in some predicates.
    Simplify some of those predicates.

compiler/mercury_compile_mlds_back_end.m:
    Import ml_top_gen.m instead of ml_proc_gen.m.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Add the new module.
2017-08-10 05:30:21 +02:00
Zoltan Somogyi
1c01ed85eb Fix lines. 2017-07-29 14:15:15 +02:00
Zoltan Somogyi
b726980f7d Carve ml_rename_classes.m out of mlds_to_java.m.
compiler/ml_rename_classes.m:
compiler/mlds_to_java.m:
    As above.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Mention the new module.
2017-07-26 14:14:25 +02:00
Zoltan Somogyi
4738ccaef8 Create mlds_to_target_util.m.
compiler/mlds_to_target_util.m:
    Create this new module to contain the common code that can be
    factored out of mlds_to_{cs,java}.m, and (to a much lesser extent)
    mlds_to_c.m.

    In a few cases, give predicates better names, and/or generalize
    their operation.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
    Mention the new module.

compiler/ml_util.m:
    Move some common code from mlds_to_{cs,java}.m to here (rather than
    mlds_to_target_util.m) because it belongs with other procedures
    that are already here.

compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
    Delete the common code that has been factored out and moved to
    the other modules.

    To avoid ambiguity, in mlds_to_{cs,java.m}, add a "_for_java" or
    "_for_csharp" suffix to the names of all the remaining types and
    predicates that exist in both modules but with different definitions.
    There were a lot of these, since mlds_to_cs.m was apparently created
    by copy-and-paste from mlds_to_java.m.
2017-05-30 01:30:07 +02:00
Julien Fischer
1ab13edca6 Switch over unary and binary ops in Java and C# code generators.
Fix more failing test cases in the non-C grades.

compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
    Always switch over unary and binary ops.  The existing code predates
    the addition of multi-arm switches to the language and was intended to
    the code duplication that would result in the absence of that feature.
    Since we now have multi-arm switches it is by far preferable to use
    a switch in these places.

    XXX for binary ops the above change replicates what the existing code
    did; I think it should actually abort in some cases.

    Fix spelling.

    Delete trailing whitespace.

compiler/java_util.m:
    Delete this module, it isn't used anymore.

compiler/ml_backend.m:
    Delete the include of the java_util module.

compiler/c_util.m:
    Update a comment.

tests/exceptions/Mmakefile:
    Fix the failure of 'test_uncaught_exception' in the java grade by
    filtering out the stack trace generated by the JVM.

tests/hard_coded/float_reg.exp4:
    Alternative expected output for this due to the way floats are
    printed.

tests/invalid_purity/purity.m:
tests/invalid_purity/purity.err_exp:
    Add C# and Java foreign_procs and updated the expected output.

tests/warnings/Mmakefile:
    Fix my previous change, which broke things in non-Erlang grades.
2016-02-07 22:38:16 +11:00
Zoltan Somogyi
cc9912faa8 Don't import anything in packages.
Packages are modules whose only job is to serve as a container for submodules.
Modules like top_level.m, hlds.m, parse_tree.m and ll_backend.m are packages
in this (informal) sense.

Besides the include_module declarations for their submodules, most of the
packages in the compiler used to import some modules, mostly other packages
whose component modules their submodules may need. For example, ll_backend.m
used to import parse_tree.m. This meant that modules in the ll_backend package
did not have to import parse_tree.m before importing modules in the parse_tree
package.

However, this had a price. When we add a new module to the parse_tree package,
parse_tree.int would change, and this would require the recompilation of ALL
the modules in the ll_backend package, even the ones that did NOT import ANY
of the modules in the parse_tree package.

This happened even at one remove. Pretty much all modules in every one
of the backend have to import one or more modules in the hlds package,
and they therefore have import hlds.m. Since hlds.m imported transform_hlds.m,
any addition of a new middle pass to the transform_hlds package required
the recompilation of all backend modules, even in the usual case of the two
having nothing to do with each other.

This diff removes all import_module declarations from the packages,
and replaces them with import_module declarations in the modules that need
them. This includes only a SUBSET of their child modules and of the non-child
modules that import them.
2015-11-13 15:03:20 +11:00
Julien Fischer
f1d8a3ba8c Update a comment.
compiler/ml_backend.m:
    Update the list of MLDS backends at the head of this file.
2015-11-04 22:45:44 +11:00
Julien Fischer
3dd02876a5 Delete the MLDS->IL backend.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_managed.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/ilds.m:
    Delete the modules making up the MLDS->IL code generator.

compiler/globals.m:
compiler/prog_data.m:
    Delete IL as a target and foreign language.

compiler/prog_io_pragma.m:
    Delete the max_stack_size/1 foreign proc attribute.  This was only
    ever required by the IL backend.

compiler/options.m
    Delete options used for the IL backend.

compiler/write_deps_file.m:
    Don't generate mmake targets for .il files etc.

compiler/*.m:
    Conform to the above changes.

compiler/notes/compiler_design.html
compiler/notes/work_in_progress.html
    Conform to the above changes.

library/*.m:
    Delete IL foreign_proc and foreign_export pragmas.

README.DotNet:
    Delete this file.

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
    Conform the above changes.

configure.ac:
    Don't check that IL is a supported foreign language when performing the
    up-to-date check.

    Delete the '--enable-dotnet-grades' option.

scripts/Mmake.vars.in:
    Delete variables used for the IL backend (and in on case by the Aditi
    backend).

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.rules:
scripts/canonical_grade.sh-subr:
tools/bootcheck:
    Delete stuff related to the 'il' and 'ilc' grades.

doc/reference_manual.texi:
     Delete the documentation of the 'max_stack_size' option.

doc/user_guide.texi:
     Delete stuff related to the IL backend.

tests/hard_coded/csharp_test.{m,exp}:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/valid/csharp_hello.m:
	Delete these tests: they are no longer relevant.

tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/intermod_foreign_type2.m:
tests/hard_coded/lp.m:
tests/hard_coded/user_compare.m:
tests/invalid/foreign_type_2.m:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/invalid/foreign_type_visibility.m:
tests/invalid/illtyped_compare.{m,err_exp}:
tests/submodules/external_unification_pred.m
tests/valid/big_foreign_type.m
tests/valid/solver_type_bug.m
tests/valid_seq/foreign_type_spec.m
tests/valid_seq/intermod_impure2.m
    Delete IL foreign_procs where necessary.

tests/hard_coded/Mmakefile
tests/invalid/Mercury.options
tests/invalid/Mmakefile
tests/submodules/Mmakefile
tests/valid/Mercury.options
tests/valid/Mmake.valid.common
tests/valid/Mmakefile
tests/valid_seq/Mmakefile
tests/valid_seq/Mercury.options
    Conform to the above changes.
2015-09-21 11:34:46 +10:00
Julien Fischer
623f1a73c0 Delete an out-of-date comment.
compiler/ml_backend.m:
    Delete a left over reference to the GCC backend.
2015-09-18 16:41:25 +10:00
Zoltan Somogyi
13b6f03f46 Module qualify end_module declarations.
compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

compiler/table_gen.m:
    Remove an unused predicate, and inline another in the only place
    where it is used.

compiler/add_pragma.m:
    Give some predicates more meaningful names.
2014-09-04 00:24:52 +02:00
Julien Fischer
f6bdd99a80 Delete the MLDS->GCC (assembler) backend.
As discussed in the recent Mercury meeting, remove support for the GCC backend.
It was very much out of date and supporting it proprerly would means having to
track changes to GCC's internals.  Furthermore, its presence complicates
building the compiler.

The main thing this change does not address is the fact that we invoke
the compiler through C code, e.g. main.c in the top-level of the source
tree.  This was required by the GCC backend and can now be removed, but
I will do that as a separate change.

configure.ac:
Mmake.common.in:
scripts/Mmake.rules:
compiler/Mercury.options:
compiler/Mmakefile:

compiler/gcc.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mlds_to_gcc.m:
    Delete the files containing the GCC backend.

compiler/options.m:
compiler/handle_options.m:
    Delete support for `--target asm' and `--pic'.
    (The latter was only used by the GCC backend.)

compiler/*.m:
doc/user_guide.texi:
compiler/notes/comiler_design.html:
compiler/notes/work_in_progress.m:
    Conform to the above change.

README.gcc-backend.m:
    Delete this file.
2013-01-16 15:31:10 +11:00
Zoltan Somogyi
7ca1a07296 Allow the MLDS backend to generate indexing switches (switches implemented
Estimated hours taken: 16
Branches: main

Allow the MLDS backend to generate indexing switches (switches implemented
more efficiently than just a if-then-else chain) for strings even if the target
language does not support gotos.

Previously, we use always used gotos to break out of search loops
after we found a match:

    do {
        if (we have a match) {
            ... handle the match ...
            goto end
        } else {
            ... handle nonmatches ...
        }
    } while (loop should continue);
    maybe some code to handle the failure of the search
end:

Now, if the "maybe some code" is empty, we prefer to use break statements
if the target language supports this:

    do {
        if (we have a match) {
            ... handle the match ...
            break;
        } else {
            ... handle nonmatches ...
        }
    } while (loop should continue)

If we cannot use either gotos or break statements, we instead use
a boolean variable named "stop_loop":

    stop_loop = 0;
    do {
        if (we have a match) {
            ... handle the match ...
            stop_loop = 1;
        } else {
            ... handle nonmatches ...
        }
    } while (stop_loop == 0 && loop should continue)
    if (stop_loop == 0) {
    	maybe some code to handle the failure of the search
    }

We omit the final if statement if the then-part would be empty.

The break method generates the smallest code, followed by the goto code.
I don't have information on speed, since we don't have a benchmark that
runs long enough, and the compiler itself does not spend any significant
amount of time on string switches. Probably the break method is also the
fastest, simply because it leaves the code looking most like normal C code.
(Some optimizations are harder to apply to code containing gotos, and some
optimizer writers do not bother.)

For C, we now normally prefer to generate code using the second method
(breaks), if we can, though normally "maybe some code" is not empty,
in which case we use the first method (goto).

However, if the value of the --experiment option is set to "use_stop_loop",
we always use the third method, and if it is set to "use_end_label", we always
use the first, even when we could use the second. This allow us to test all
three approaches using the C back end.

With backends that support neither gotos nor break, we always use the third
method (stop_loop).

With backends that don't support gotos but do support breaks, we also always
use the third method. This is because trying to use the second method would
require us to commit to not creating the stop_loop variable BEFORE we know
that the "maybe some code to handle the failure of the search" is empty,
and if it isn't empty, then we don't have the goto method to fall back on.

compiler/ml_string_switch.m:
	Make the change described above. Where possible, make the required
	change not to the original code, but to a version in which common
	parts have been factored out. (Previously, the duplicated code was
	small; now, it would be big.)

compiler/ml_target_util.m:
	A new module containing existing functions that test various properties
	of the target language. Keeping some of those functions in their
	original modules would have introduced a circular dependency.

compiler/ml_switch_gen.m:
	Enable the new functionality by removing the tests that previously
	prevented the compiler from using indexing switches on strings
	if the target language did not support gotos.

	Remove the code moved to ml_target_util.m.

compiler/ml_optimize.m:
compiler/ml_unify_gen.m:
	Remove the code moved to ml_target_util.m.

compiler/ml_backend.m:
compiler/notes/compiler_design.m:
	Add the new module.

compiler/ml_proc_gen.m:
	Delete a predicate that hasn't been used for a long time.

tools/makebatch:
	Fix an old pair of typos.
2011-08-15 06:23:20 +00:00
Peter Wang
57f9013259 Start a C# backend, adapted from mlds_to_java.m.
Branches: main

Start a C# backend, adapted from mlds_to_java.m.

Some `pragma foreign_*' declarations are commented out in this change because
no bootstrap compiler will yet accept "C#" in the language specification.

The compiler already supported C# foreign_procs for the IL backend, but the IL
backend and this new backend do not agree on naming and calling conventions so
the changes to the existing C# foreign_procs will further break the IL backend.
Nobody cares.

Only tested so far with Mono on Linux.

compiler/mlds_to_cs.m:
        New module.  In the CVS Attic there exists an obsolete file named
        mlds_to_csharp.m (replaced by mlds_to_managed.m) which we don't want to
        conflict with.

        For C# we need to know if a `pragma foreign_type' is a value or
        reference type.  Currently this is done by accepting a fake keyword
        `valuetype' before the type name, like for IL.

compiler/ml_backend.m:
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
        Hook up the C# backend.

compiler/globals.m:
        Add `target_csharp' as a target language.

compiler/options.m:
        Add `--csharp' and `--csharp-only' options and their synonyms.

compiler/handle_options.m:
        Handle `target_csharp' like `target_java', except for features which
        are still to be implemented.

compiler/add_pragma.m:
        Allow C# as a `pragma foreign_export' language.

        Allow C# for `pragma foreign_export_enum'.

        Conform to changes.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
        Accept C# as a language for `pragma foreign_type'.

        Accept `csharp' as the name of a grade in trace parameters.

compiler/make_hlds_passes.m:
        Reuse most of the code for implementing mutables on Java for C#.

compiler/mlds.m:
        Add a new MLDS target language, `ml_target_csharp'.

        Conform to changes.

compiler/ml_foreign_proc_gen.m:
        Generate foreign_procs for C#.

compiler/foreign.m:
        Update predicates to support C# targets.

compiler/c_util.m:
        Make `quote_string' use hexadecimal escapes in C# string literals.

compiler/parse_tree.m:
compiler/java_names.m:
        Add C# equivalents for predicates in this module.  `java_names' is a
        misleading module name, but the predicates for C# and Java share some
        code and may possibly be combined in the future.

compiler/rtti.m:
        Add predicates to return the names of RTTI structures in C#.

compiler/simplify.m:
        Handle the trace parameter `grade(csharp)'.

compiler/compile_target_code.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
        Add some support for building of executables and libraries with
        `--target csharp'.

compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/granularity.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modules.m:
compiler/pragma_c_gen.m:
compiler/prog_foreign.m:
compiler/special_pred.m:
compiler/write_deps_file.m:
        Conform to changes.

library/builtin.m:
library/rtti_implementation.m:
library/type_desc.m:
        Implement RTTI procedures for the new backend, which uses a high-level
        data representation (like the Java backend).  The existing C# code was
        designed for the IL backend, which used a low-level representation of
        the RTTI data structures.

        Most (if not all) of the the "new" code is exactly the same as the Java
        versions, with only syntactic changes.

        Rename the C# class `void_0' to `Void_0' to match the naming convention
        used by mlds_to_cs.m.

library/array.m:
        Update the existing C# code to work with the new backend.

        Use `object[]' as the type of all array of non-primitive types.
        The problem is one we encountered on the Java backend: when creating a
        new array based on the type of a single element, we don't know whether
        the new array should contain elements of the class or superclass.

library/bool.m:
        Export `bool' constants to C#.

library/exception.m:
        Update the existing C# code to work with the new backend.

        Move the `mercury.runtime.Exception' C# class to mercury_dotnet.cs.

library/float.m:
        Add C# implementations of `is_nan' and `is_inf'.

library/list.m:
        Add methods for manipulating lists from hand-written C# code.

library/string.m:
        Add C# implementations of string procedures which were missing.

library/dir.m:
library/io.m:
library/library.m:
        Update the existing C# code to work with the new backend.

library/private_builtin.m:
        Update the existing C# code to work with the new backend.

        Delete the static constants which are duplicated in mercury_dotnet.cs.
        The mlds_to_cs.m will emit references to the constants in the latter
        only.

library/backjump.m:
library/bitmap.m:
library/mutvar.m:
library/par_builtin.m:
library/region_builtin.m:
library/store.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/univ.m:
        Make these modules compile with the C# backend.

runtime/mercury_dotnet.cs.in:
        Add RTTI classes to the `mercury.runtime' namespace, equivalent to
        those on the Java backend.

        Use enumerations `MR_TYPECTOR_REP_*' and `MR_SECTAG_*' constants so we
        can switch on them.

        Add the `UnreachableDefault' exception class.

        Hide old classes which are unused with the new backend behind
        #ifdef !MR_HIGHLEVEL_DATA.
2010-09-16 00:39:12 +00:00
Zoltan Somogyi
4ebe3d0d7e Stop storing globals in the I/O state, and divide mercury_compile.m
Estimated hours taken: 60
Branches: main

Stop storing globals in the I/O state, and divide mercury_compile.m
into smaller, more cohesive modules. (This diff started out as doing
only the latter, but it became clear that this was effectively impossible
without the former, and the former ended up accounting for the bulk of the
changes.)

Taking the globals out of the I/O state required figuring out how globals
data flowed between pieces of code that were often widely separated.
Such flows were invisible when globals could be hidden in the I/O state,
but now they are visible, because the affected code now passes around
globals structures explicitly.

In some cases, the old flow looked buggy, as when one job invoked by
mmc --make could affect the globals value of its parent or the globals value
passed to the next job. I tried to fix such problems when I saw them. I am
not 100% sure I succeeded in every case (I may have replaced old bugs with
new ones), but at least now the flow is out in the open, and any bugs
should be much easier to track down and fix.

In most cases, changes the globals after the initial setup are intended to be
in effect only during the invocation of a few calls. This used to be done
by remembering the initial values of the to-be-changed options, changing their
values in the globals in the I/O state, making the calls, and restoring the old
values of the options. We now simply create a new version of the globals
structure, pass it to the calls to be affected, and then discard it.

In two cases, when discovering reasons why (1) smart recompilation should
not be done or (2) item version numbers should not be generated, the record
of the discovery needs to survive this discarding. This is why in those cases,
we record the discovery by setting a mutable attached to the I/O state.
We use pure code (with I/O states) both to read and to write the mutables,
so this is no worse semantically than storing the information in the globals
structure inside the I/O state. (Also, we were already using such a mutable
for recording whether -E could add more information.)

In many modules, the globals information had to be threaded through
several predicates in the module. In some places, this was made more
difficult by predicates being defined by many clauses. In those cases,
this diff converts those predicates to using explicit disjunctions.

compiler/globals.m:
	Stop storing the globals structure in the I/O state, and remove
	the predicates that accessed it there.

	Move a mutable and its access predicate here from handle_options.m,
	since here is when the mutables treated the same way are.

	In a couple of cases, the value of an option is available in a mutable
	for speed of access from inside performance-critical code. Set the
	values of those mutables from the option when the processing of option
	values is finished, not when it is starting, since otherwise the copies
	of each option could end up inconsistent.

	Validate the reuse strategy option here, since doing it during ctgc
	analysis (a) is too late, and (b) would require an update to the
	globals to be done at an otherwise inconvenient place in the code.
	Put the reuse strategy into the globals structure.

	Two fields in the globals structure were unused. One
	(have_printed_usage) was made redundant when the one predicate
	that used it itself became unused; the other (source_file_map)
	was effectively replaced by a mutable some time ago. Delete
	these fields from the globals.

	Give the fields of the globals structure a distinguishing prefix.

	Put the type declarations, predicate declarations and predicate
	definitions in a consistent order.

compiler/source_file_map.m:
	Record this module's results only in the mutable (it serves as a
	cache), not in globals structure. Use explicitly passed globals
	structure for other purposes.

compiler/handle_options.m:
	Rename handle_options as handle_given_options, since it does not
	process THE options to the program, but the options it is given,
	and even during the processing of a single module, it can be invoked
	up the three times in a row, each time being given different options.
	(It was up to four times in a row before this diff.)

	Make handle_given_options explicitly return the globals structure it
	creates. Since it does not take an old global structure as input
	and globals are not stored in the I/O state, it is now clear that
	the globals structure it returns is affected only by the default values
	of the options and the options it processes. Before this diff,
	in the presence of errors in the options, handle_options *could*
	return (implicitly, in the I/O state) the globals structure that
	happened to be in the I/O state when it was invoked.

	Provide a separate predicate for generating a dummy globals based only
	on the default values of options. This allows by mercury_compile.m
	to stop abusing a more general-purpose predicate from handle_options.m,
	which we no longer export.

	Remove the mutable and access predicate moved to globals.m.

compiler/options.m:
	Document the fact that two options, smart_recompilation and
	generate_item_version_numbers, should not be used without seeing
	whether the functionalities they call for have been disabled.

compiler/mercury_compile_front_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mercury_compile_erl_back_end.m:
	New modules carved out of the old mercury_compile.m. They each cover
	exactly the areas suggested by their names.

	Each of the modules is more cohesive than the old mercury_compile.m.
	Their code is also arranged in a more logical order, with predicates
	representing compiler passes being defined in the order of their
	invocation.

	Some of these modules export predicates for use by their siblings,
	showing the dependencies between the groups of passes.

compiler/top_level.m:
compiler/notes/compiler_design.html:
	Add the new modules.

compiler/mark_static_terms.m:
	Move this module from the ml_backend package to the hlds package,
	since (a) it does not depend on the MLDS in any way, and (b) it is
	also needed by a compiler pass (loop invariants) in the middle passes.

compiler/hlds.m:
compiler/ml_backend.m:
compiler/notes/compiler_design.html:
	Reflect mark_static_terms.m's change of package.

compiler/passes_aux.m:
	Move the predicates for dumping out the hLDS here from
	mercury_compile.m, since the new modules also need them.

	Look up globals in the HLDS, not the I/O state.

compiler/hlds_module.m:
	Store the prefix (common part) of HLDS dump file names in the HLDS
	itself, so that the code moved to passes_aux.m can figure out the
	file name for a HLDS dump without doing system calls.

	Give the field names of some structures prefixes to avoid ambiguity.

compiler/mercury_compile.m:
	Remove the code moved to the other modules. This module now looks
	after only option handling (such as deciding whether to generate .int3
	files, .int files, .opt files etc), and the compilation passes
	up to and including the creation of the first version of the HLDS.
	Everything after that is subcontracted to the new modules.

	Simplify and make explicit the flow of globals information.
	When invoking predicates that could disable smart recompilation,
	check whether they have done so, and if yes, update the globals
	accordingly.

	When compiling via gcc, we need to link into the executable
	the object files of any separate C files we generate for C code
	foreign_procs, which we cannot translate into gcc's internal
	structures without becoming a C compiler as well as a Mercury compiler.
	Instead of adding such files to the accumulating option for extra
	object files in the globals structure, we return their names using
	the already existing mechanism we have always used to link the object
	files of fact tables into the executable.

	Give several predicates more descriptive names. Put predicates
	in a more logical order.

compiler/make.m:
compiler/make.dependencies.m:
compiler/make.module_target.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
	Require callers to supply globals structures explicitly, not via the
	I/O state. Afterward pass them around explicitly, passing modified
	versions to mercury_compile.m when invoking it with module- and/or
	task-specific options.

	Due the extensive use of partial application for higher order code
	in these modules, passing around the globals structures explicitly
	is quite tricky here. There may be cases where a predicate uses
	an old globals structure it got from a closure instead of the updated
	module- and/or task-specific globals it should be using, or vice versa.
	However, it is just as likely that, this diff fixes old problems
	by preventing the implicit flow of updated-only-for-one-invocation
	globals structures back to the original invoking context.

	Although I have tried to be careful about this, it is also possible
	that in some places, the code is using an updated-for-an-invocation
	globals structure in some but not all of the places where it
	SHOULD be used.

compiler/c_util.m:
compiler/compile_target_code.m:
compiler/compiler_util.m:
compiler/error_util.m:
compiler/file_names.m:
compiler/file_util.m:
compiler/ilasm.m:
compiler/ml_optimize.m:
compiler/mlds_to_managed.m:
compiler/module_cmds.m:
compiler/modules.m:
compiler/options_file.m:
compiler/pd_debug.m:
compiler/prog_io.m:
compiler/transform_llds.m:
compiler/write_deps_file.m:
	Require callers to supply globals structures explicitly, not via the
	I/O state.

	In some cases, the explicit globals structure argument allows
	a predicate to dispense with the I/O states previously passed to it.

	In some modules, rename some predicates, types and/or function symbols
	to avoid ambiguity.

compiler/read_modules.m:
	Require callers to supply globals structures explicitly, not via the
	I/O state.

	Record when smart recompilation and the generation of item version
	numbers should be disabled.

compiler/opt_debug.m:
compiler/process_util.m:
	Require callers to supply the needed options explicitly, not via the
	globals in the I/O state.

compiler/analysis.m:
compiler/analysis.file.m:
compiler/mmc_analysis.m:
	Make the analysis framework's methods take their global structures
	as explicit arguments, not as implicit data stored in the I/O state.

	Stop using `with_type` and `with_inst` declarations unnecessarily.

	Rename some predicates to avoid ambiguity.

compiler/hlds_out.m:
compiler/llds_out.m:
compiler/mercury_to_mercury.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/optimize.m:
	Make these modules stop accessing the globals from the I/O state.
	Do this by requiring the callers of their top predicates to explicitly
	supply a globals structure. To compensate for the cost of having to
	pass around a representation of the options, look up the values of the
	options of interest just once, to make further access much faster.

	(In the case of mlds_to_c.m, the code already did much of this,
	but it still had a few accesses to globals in the I/O state that
	this diff eliminates.)

	If the module exports a predicate that needs these pre-looked-up
	options, then export the type of this data structure and its
	initialization function.

compiler/frameopt.m:
	Since this module needs only one option from the globals, pass that
	option instead of the globals.

compiler/accumulator.m:
compiler/add_clause.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/elds_to_erlang.m:
compiler/exception_analysis.m:
compiler/fact_table.m:
compiler/intermod.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/pd_util.m:
compiler/post_term_analysis.m:
compiler/recompilation.usage.m:
compiler/size_prof.usage.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_errors.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_util.m:
compiler/trailing_analysis.m:
compiler/trans_opt.m:
compiler/typecheck_info.m:
	Look up globals information from the HLDS, not the I/O state.

	Conform to the changes above.

compiler/gcc.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mlds_to_gcc.m:
	Look up globals information from the HLDS, not the I/O state.

	Conform to the changes above.

	Convert these modules to our current programming style.

compiler/termination.m:
	Look up globals information from the HLDS, not the I/O state.

	Conform to the changes above.

	Report some warnings with error_specs, instead of immediately
	printing them out.

compiler/export.m:
compiler/il_peephole.m:
compiler/layout_out.m:
compiler/rtti_out.m:
compiler/liveness.m:
compiler/make_hlds.m:
compiler/make_hlds_passes.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/recompilation.check.m:
compiler/stack_opt.m:
compiler/superhomogeneous.m:
compiler/tupling..m:
compiler/unneeded_code.m:
compiler/unused_args.m:
compiler/unused_import.m:
compiler/xml_documentation.m:
	Conform to the changes above.

compiler/equiv_type_hlds.m:
	Give the field names of a structure prefixes to avoid ambiguity.

	Stop using `with_type` and `with_inst` declarations unnecessarily.

compiler/loop_inv.m:
compiler/pd_info.m:
compiler/stack_layout.m:
	Give the field names of some structures prefixes to avoid ambiguity.

compiler/add_pragma.m:
	Add notes.

compiler/string.m:
NEWS:
	Add a det version of remove_suffix, for use by new code above.
2009-10-14 05:28:53 +00:00
Zoltan Somogyi
bea43284e7 Implement lookup disjunctions and model_non lookup switches.
Estimated hours taken: 24
Branches: main

Implement lookup disjunctions and model_non lookup switches.

compiler/ml_disj_gen.m:
	New module that looks after code generation for disjunctions.
	Note the link to disj_gen.m.

	Part of the code in it comes from ml_code_gen.m, but the part that
	implements lookup disjunctions is new, and its bulk is what justifies
	a separate module.

	Even the old code has been restructured to make the decision
	about whether this is a model_non disj or not just once, instead
	of once for every single disjunct.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
	Mention the new module.

compiler/mlds.m:
	Use a purpose-specific type instead of a bool to represent
	whether a loop can loop zero times.

compiler/ml_code_gen.m:
	Remove the code moved to ml_disj_gen.m.

	Improve the style of the ml_gen_maybe_convert_goal_code_model
	predicate.

compiler/ml_lookup_switch.m:
	Implement model_non lookup switches.

	Note the link to lookup_switch.m.

	Give better names to some predicates and variables.

	Remove the predicates moved to ml_code_util.m, goal_form.m and
	ml_util.m.

compiler/switch_util.m:
	When a switch arm has several solutions, store the first solution
	separately. This assures statically that there IS a first solution
	(which a simple list of solutions does not), and prepares the first
	solution for its special treatment (it is stored in a different vector
	than the later solutions, and in the LLDS backend, we take the liveness
	after the arms from it).

compiler/ml_code_util.m:
	Move here the predicates previously in ml_lookup_switch.m that are now
	needed by ml_disj_gen.m as well. Make it possible to generate
	constants for individual arms, as well as individual field assigns,
	since ml_disj_gen.m now needs this capability.

compiler/goal_form.m:
	Move here a suitably generalized version of the two previously
	backend-specific versions of the predicates that test goals to see
	if they can be part of a lookup switch or disjunction.

compiler/ml_util.m:
	Move here from ml_lookup_switch.m a predicate now needed by
	ml_disj_gen.m as well.

compiler/lookup_util.m:
	Remove the predicate moved to goal_form.m.

	Make it possible to generate constants for a single disjunct.

	Avoid uselessly wrapping up a return argument in a yes().

compiler/disj_gen.m:
compiler/lookup_switch.m:
	Move a cheap test significantly earlier, to avoid wasting time
	on disjunctions on which it would fail.

	Conform to the changes in the backend libraries.

	In lookup_switch.m, note the paper that describes the code generation
	scheme followed by the module.

compiler/mlds_to_c.m:
	Conform to the changes above.

	When generating scalar and vector static cells, indicate the row
	numbers in comments, since without this, it is too difficult to check
	visually whether the generated code is correct.

compiler/mlds_to_java.m:
	Conform to the changes above.

	Improve the style of a big predicate.

compiler/ml_accurate_gc.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
	Conform to the changes above.

tests/hard_coded/dense_lookup_switch_non.{m,exp}:
	Make this test case significantly more comprehensive, by making it
	test all combinations of the presence and absence of both range checks
	and bit vector checks.

tests/hard_coded/lookup_switch_simple_bitvec.{m,exp}:
	This test was not doing its job, because the switch had too few arms
	for ml_switch_gen.m to decide that a lookup switch was worthwhile.
	It succeeded, but did not exercise the lookup switch code that existed
	in the MLDS backend before this diff. Fix this by adding more arms.
2009-10-02 03:55:36 +00:00
Zoltan Somogyi
439e9d474d Divide the old 4100, 2900 and 4600 line modules ml_code_gen.m, ml_code_util.m
Estimated hours taken: 4
Branches: main

Divide the old 4100, 2900 and 4600 line modules ml_code_gen.m, ml_code_util.m
and modes.m into smaller, more cohesive modules. In the process, put
related predicates next to each other. There are no algorithmic changes.

compiler/ml_proc_gen.m:
	New module that looks after code generation tasks that affect a
	procedure as a whole. Its code is taken from the old ml_code_gen.m.
	Analogous to proc_gen.m, which does the same job for the LLDS backend.

compiler/ml_foreign_proc_gen.m:
	New module that generates code for foreign_proc goals.
	Its code is taken from the old ml_code_gen.m.
	Analogous to pragma_c_gen.m in the LLDS backend.

compiler/ml_commit_gen.m:
	New module that generates code for commit goals.
	Its code is taken from the old ml_code_gen.m.
	Analogous to commit_gen.m in the LLDS backend.

compiler/ml_gen_info.m:
	New module that encapsulates the ml_gen_info structure.
	Its code is taken from the old ml_code_util.m.
	Analogous to code_info.m in the LLDS backend.

compiler/ml_accurate_gc.m:
	New module that generates the data and goals needed for accurate gc.
	Its code is taken from the old ml_code_util.m.

compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
	Move some predicates that are used by other modules of the MLDS backend
	to ml_code_util, in order to avoid otherwise unneeded dependencies.

compiler/mode_util.m:
	Move a predicate here from ml_code_util.m, since it is needed by
	several MLDS backend modules but is not MLDS specific.

compiler/ml_code_gen.m:
	Remove the code moved to other modules.

	Delete an old note about a problem fixed long ago.

compiler/ml_code_util.m:
	Remove the code moved to other modules.

	Add the code moved here from other modules.

compiler/modecheck_conj.m:
	New module that handles mode analysis of conjunctions.
	Its code is taken from the old modes.m.

compiler/modecheck_goal.m:
	New module that handles mode analysis of most types of goals,
	except conjunctions, unifications and calls.
	Its code is taken from the old modes.m.

compiler/modecheck_util.m:
	New module containing utility predicates used more one of the modules
	do mode analysis. Its code is taken from the old modes.m.

compiler/mode_util.m:
	Move a predicate here from modes.m, since this is where a related
	predicate already is.

	Give a predicate a more meaningful name.

compiler/goal_util.m:
	Move a predicate here from modes.m, since this is where a related
	predicate already is.

compiler/modes.m:
	Remove the code moved to other modules.

compiler/ml_backend.m:
compiler/check_hlds.m:
	Add the new modules.

compiler/notes/compiler_design.html:
	Document the new modules.

compiler/prog_data.m:
	Give some function symbols disambiguating prefixes.

compiler/add_solver.m:
compiler/deforest.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_string.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_unify_gen.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/prog_io_type_defn.m:
compiler/rtti_to_mlds.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
	Conform to the changes above.
2009-09-25 05:13:23 +00:00
Zoltan Somogyi
00ea415659 Implement scalar and vector global data for the MLDS backend, modelled on
Estimated hours taken: 32
Branches: main

Implement scalar and vector global data for the MLDS backend, modelled on
the implementation of global data for the LLDS backend. Use scalar global
data to eliminate redundant copies of static memory cells. Use vector global
data to implement lookup switches, and to implement string switches more
efficiently.

The diff reduces the compiler executable's size by 3.3% by eliminating
duplicate copies of static cells. The diff can reduce the sizes of object files
not only through this reduction in the size of read-only data, but also through
reductions in the size of the needed relocation info: even in the absence of
duplicated cells, using one global variable that holds an array of all the
cells of the same type requires less relocation info than a whole bunch of
separate global variables each holding one cell. If C debugging is enabled,
we can also expect a significant reduction in the size of the debug information
stored in object files AND in executables, for the same reason. (This was the
original motivation for scalar static data on the LLDS backend; the large
amount of relocation information in object files, especially if Mercury
debugging was enabled, led to long link times.)

compiler/ml_global_data.m:
	Make the changes described above.

compiler/ml_lookup_switch.m:
	This new module implements lookup switches for the MLDS backend.
	For now, it implements only model_det and model_semi switches.

compiler/ml_switch_gen.m:
	Call the new module when appropriate.

	Do not require the switch generation methods that never generate
	definitions to return an empty list of definitions.

compiler/ml_backend.m:
	Add the new module.

compiler/notes/compiler_design.html:
	Mention the new module, and fix some documentation rot.

compiler/mlds.m:
	Extend the relevant types to allow the generated MLDS code to refer
	to both scalar and vector global data.

	Move a predicate that belongs here from ml_code_util.m.

	Rename a predicate to avoid ambiguity with its own return type.

	Give the functors of some types distinguishing prefixes.

compiler/ml_util.m:
	Replace some semidet predicates with functions returning bool,
	since the semidet predicates silently did the wrong thing on the new
	additions to the MLDS.

compiler/ml_code_gen.m:
	Ensure that we do not generate references to scalar and vector common
	cells on platforms which do not (yet) support them. At the moment,
	they are supported only when generating C.

	Put some code into a predicate of its own.

compiler/builtin_ops.m:
	Extend the type that represents array elements to allow them to be
	structures, which they are for vector globals.

compiler/ml_code_util.m:
	Add some new utility predicates and functions.

	Move some predicates that are now needed in more than one module here.

	Remove the predicates moved to mlds.m.

	Conform to the changes above.

compiler/ml_string_switch.m:
compiler/string_switch.m:
	Instead of two separate arrays, use one array of structures (a static
	vector), since they way, the string and the next slot indicator,
	which are accesses together, are next to each other and thus
	in the same cache block.

compiler/lookup_switch.m:
compiler/switch_util.m:
	Move several predicates from lookup_switch.m to switch_util.m,
	since now ml_lookup_switch.m needs them too. Parameterize the moved
	predicates as needed.

	Conform to the changes above.

compiler/llds.m:
	Add prefixes to some functor names to avoid ambiguities.

compiler/llds_out.m:
compiler/lookup_util.m:
compiler/mercury_compile.m:
	Minor style improvements.

compiler/global_data.m:
	Minor cleanups. Give names to some data types, and add prefixes to some
	field names.

	Conform to the changes above.

compiler/jumpopt.m:
	Minor style improvements.

	Conform to the changes above.

compiler/opt_debug.m:
	Fix some misleading variable names.

compiler/reassign.m:
	Factor out some duplicated code.

compiler/ll_pseudo_type_info.m:
compiler/ml_closure_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tag_switch.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/rtti_to_mlds.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
	Conform to the changes above.

tests/hard_coded/lookup_switch_simple.{m,exp}:
tests/hard_coded/lookup_switch_simple_bitvec.{m,exp}:
tests/hard_coded/lookup_switch_simple_non.{m,exp}:
tests/hard_coded/lookup_switch_simple_opt.{m,exp}:
	New test cases to exercise the new functionality.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
	Enable the new tests.
2009-09-21 04:09:06 +00:00
Zoltan Somogyi
cc9423e35d Rationalize the way the MLDS code generator handles global data structures.
Estimated hours taken: 80
Branches: main

Rationalize the way the MLDS code generator handles global data structures.
The previous way was somewhat perverse in several respects.

The first respect was that static Mercury terms were translated into global
MLDS definitions, those MLDS definitions were turned into local definitions,
and then later turned back into global definitions. However, while they were
local definitions, they were part of the list of definitions processed
by ml_elim_nested. Since the complexity of ml_elim_nested is at least O(n^2)
and probably O(n^3) or worse, and since the definitions representing static
terms could increase the value of n from dozens or hundred to many thousands,
this was a BAD IDEA, especially since by construction, the MLDS definitions
representing ground terms cannot have other definitions nested inside them.
This problem was the main reason why previously the compiler took effectively
forever to compile any program with large tables of facts in MLDS grades.

The second respect has to do with the fact that terms are represented as tagged
pointers to memory cells. When generating an MLDS definition (a static cell)
for a ground term, ml_unify_gen.m remembered the name of the MLDS variable
representing the static cell, but forgot the tag on the pointer. So when
that ground term was used as an argument in another, bigger ground term,
it had to figure out the tag all over again. The argument of the
construct_statically functor in construct unifications had as its sole purpose
the provision of the data needed by this recomputation.

The third respect was that the code generator could generate duplicate
definitions (same variable name, same content) when two conjoined goals
referred to two or more type_infos or pseudo_type_infos for the same type.
The code generator used to handle it by wrapping a scope around the later
definitions, which (a) wasted memory, and (b) could yield warnings from
the C compiler about shadowed declarations. This problem used to prevent
the compiler from bootchecking in grade hlc_nest.gc; with this diff,
we can again bootcheck in grade hlc_nest.gc.

The fourth respect was that the code generator's record of which variables are
bound to constant terms was inaccurate, because it was never reset. If a
variable was bound to a constant term in one branch of a control structure,
the MLDS code generator state's record of this binding was still there
when the compiler generated code for the later branches of that control
structure. It did not use the record, but it was still there.

The MLDS code generator also used a horribly inefficient algorithm for figuring
out which Mercury variables should have their corresponding MLDS variables
declared at a given goal. It gathered up all the goals's variables, and then
gathered up all the variables in the goal's immediate subgoals. This meant
that the entire goal had to be traversed TWICE, with the second traversal
being needed only because the first one gathered too much information.
Those traversals were a huge performance problem on programs with large static
terms, since their representation is large conjunctions of unifications,
which have large numbers of variables. To add insult to injury, the traversals
used ordered lists to represent the sets, which meant that (given the ascending
variable numbers in from_ground_term scopes), adding the n'th unification's
new variable to the set took O(n) time, with the complexity of the whole
algorithm being quadratic.

Besides fixing these problems, this diff makes the MLDS code generator
handle from_ground_term_construct scopes specially, in a streamlined fashion,
just as the LLDS backend has done for a while now. It also fixes a bunch
of other performance problems pointed out by profiling.

This diff reduces the compilation time on the training_cars_150.m benchmark,
which has nothing but ground terms, from 94+ seconds to less than 2 seconds,
a 98% speedup. (This is with from_ground_term scopes enabled, as is
appropriate.) For ordinary programs, compilation time in grade hlc.gc
is reduced by about 3%.

compiler/ml_global_data.m:
	A new module that manages the MLDS code generator's records about
	static definitions. It separates those definitions into different
	categories based on what kind of processing they need. At the moment,
	the categories are: definitions of cells for ground terms and
	definitions of cells for RTTI, with the latter being subdivided
	into those that may need to be processed by ml_elim_nested
	and those that are known not to need such processing.

	It also records whether we have generated representation for a
	type_info or pseudo_type yet, so that we can avoid generating duplicate
	definitions. This, and the code that uses this, fixes the third
	problem.

compiler/ml_backend.m:
compiler/notes/compiler_design.html:
	Add the new module.

compiler/goal_util.m:
	Add a warning about the bad complexity of goal_vars.

compiler/hlds_goal.m:
	Remove the static_cons type, since it is no longer needed.
	Remove the static_cons argument of the construct_statically
	functor of the how_to_construct type.

	Fix an out-of-date comment about from_ground_term scopes.

compiler/mark_static_terms.m:
	Change the data structure being threaded through this module
	from being a map(prog_var, static_cons) to a set_tree234(prog_var),
	since we no longer need the information stored in static_conses.

compiler/modes.m:
	Do not compute static_conses.

compiler/mlds.m:
	Put the information about global data into a separate field of
	the MLDS, since some classes of such data can have their treatment
	optimized.

	Put the arguments of some functions into a more logical order.

	Give some function symbol names prefixes to avoid ambiguities.

	Change or add some field name prefixes to avoid ambiguities.

	Avoid the unnecessary use of higher order code in handling the flags of
	MLDS definitions. The new code is simpler as well as faster than the
	old.

compiler/ml_code_util.m:
	Make ml_global_data a part of the MLDS code generator state. This
	allows a bunch of predicates in the MLDS code generator to no longer
	return lists of definitions, since those definitions are now put
	into this new part of ml_gen_info, which ml_elim_nested won't touch.
	This is part of the solution of the first problem.

	Replace the field that mapped vars to the name of the global static
	definition involved in representing the ground term bound to that var
	with a field that maps the var to the actual rval (which will be a
	tagged pointer to that static definition), though we also remember
	the variable's type, since this is needed for making decisions about
	boxing. This is part of the solution for the second problem.

	Rename the extra_defns field of the ml_gen_info to the
	closure_wrapper_defns field, since this is the only thing that
	it is used for.

	Add fields to the ml_gen_info holding the value of the --highlevel-data
	option and the compilation target, since these are needed very often,
	and looking them up in the globals is too slow.

	Access all fields of ml_gen_info via access predicates, not via field
        notation, so that the number of accesses to each field can be measured
        by deep profiling.

        Separate the ml_gen_info structure into a main structure whose fields
        are frequently updated and which fits into an 8-word block of memory,
        and a substructure whose fields are read-only or rarely updated.
        This should help improve memory performance.

	Provide more useful access predicates to some of the counters,
	and make them harder to confuse by using fewer type synonyms.

	Provide some more convenient predicates for creating auxiliary MLDS
	variables (those that do not correspond to Mercury variables).

	Delete ml_join_decls, since fixing the third problem means that it is
	no longer needed.

	Delete some other predicates whose job has been taken over by
	ml_global_data.m.

	Put the arguments of some predicates into a more logical order.

	Rename some predicates to avoid ambiguities.

compiler/ml_code_gen.m:
	As part of the fix for the repeated traversals of parts of the
	procedure body with goal_vars, we now have to run quantification
	before generating MLDS for a procedure. Quantification does in
	one optimized pass what the old code used to do in many unoptimized
	passes. However, since quantification can change the HLDS, this
	requires a small change in the module's interface. HLDS dump 499
	now dumps to the HLDS version *output* by MLDS code generation,
	not the HLDS version that is its input.

	Use the (now guaranteed accurate) nonlocals fields of the goal and
	its immediate subgoals to figure out what variables need to declared at
	each goal. This fixes the fifth problem.

	Special case from_ground_term_construct scopes. (This code recognizes
	such scopes; the code that handles them is in ml_unify_gen.m.)

	Use trace goals to print progress messages.

	Avoid the use of io.format and string.format (see below).

	Group the predicates of this module a bit more meaningfully.
	(A really good order requires more reordering, but that will be
	a separate change.)

	Give some predicates more meaningful names.

	Add predicates that allow the convenient implementation of branched
	control structures.

	Use them in the implementation of the branched control structures
	handled in this module

	Together, these solve the fourth problem.

compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
	Use them in the implementation of the branched control structures
	handled in these modules.

	Use the new module to generate constant data.

compiler/ml_unify_gen.m:
	Implement the changes described at the top.

	Divide ml_gen_new_object, a predicate that used to be 220 lines long,
        into several pieces, one for each different method of constructing new
	objects (memory cells).

	Delete the (extensive) code that used to recreate the tags on
	pointers to static cells. This code used to also recreate static
	arguments in their entirety if they were NOT pointers to cells,
	e.g. if they were integers or floats or strings, so we now record
	the values of such non-tagged-pointer constant terms also.

	Put the arguments of some predicates into a more logical order.
	In addition, some predicates now need ml_global_data threaded through
	them, but avoid returning lists of definitions.

compiler/ml_call_gen.m:
	Simplify the interface of the predicate that decides on boxing and
	unboxing, making it callable from places that do not have a full code
	generator state (such as the streamlined code in ml_unify_gen handling
	from_ground_term_construct scopes).

	Avoid the unnecessary use of higher order code.

	Rename a predicate to avoid ambiguity.

compiler/ml_closure_gen.m;
	Generate the closure layout information as static global data.

compiler/ml_elim_nested.m:
	Thread the globals through this module instead of the I/O state,
	since the only thing the I/O state was used for was accessing the
	globals.

	Traverse only the small subset of global data that needs to be
	traversed.

compiler/ml_type_gen.m:
	Use trace goals to print progress messages.

	Replace a semidet predicate  with a function returning a tailored type,
	for improved robustness.

	Look up stuff in the globals structure less frequently, by reusing the
	results of past lookups.

compiler/rtti_to_mlds.m:
	Restructure the code in this module in two respects.

	First, instead of having predicates returning lists of
	MLDS definitions, make them add those definitions to a ml_global_data
	data structure threaded through the module. Since the ml_global_data
	structure records which type_infos and pseudo_type_infos we have
	already generated definitions for, this allows us to avoid generating
	duplicate static cells for them. This allows us to avoid the old
	code's roundabout way of handling of such cells.

	Second, several predicates of this module returned initializers,
	which their caller then stuck into a static definition. This diff
	changes things so that wherever possible, the predicate that computes
	the initializers also creates the cell definition. This improves the
	code's cohesion.

	Also, rename some predicates where, after the above changes, their old
	names are no longer appropriate.

compiler/mlds_to_c.m:
	Avoid the use of io.format and string.format, since (after the more
	extensive changes described at the top of this log message) this
	turned out to account for a nontrivial percentage of the compiler's
	runtime.

	Instead of repeatedly looking up the values of some options
	in a copy of the globals obtained from the I/O state, thread
	through this module a term that records all the information
	that this module needs from globals.

	Threading this data through this module instead of looking something
	upo in the I/O state leads to a slight slowdown, but not having to do
	option lookups in large trees leads to a larger speedup.

	Rename some predicates to ambiguity.

	Convert some predicate definitions from multiple clauses into one,
	for clarity.

	Conform to the changes in the structure of the MLDS.

compiler/mlds_to_gcc.m:
	Conform to the changes in the structure of the MLDS.

compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
	Conform to the changes in the structure of the MLDS.

	Pass the globals to this module instead of looking it up in the
	I/O state.

	Rename some predicates to ambiguity.

	Avoid the unnecessary use of higher order code.

	In mlds_to_managed.m, thread a previously frequently-looked-up value
	through the module.

compiler/typecheck_info.m:
	The code for expanding equivalence types in a procedure's vartypes
	field used to iterate on the keys of the vartypes map, and then
	looked up the associated values in the map. This diff replaces hat
	with new code that iterates on an association list that puts the
	value right next to its key (a list that the old code just threw away).

	The var/type assoc list we compute is still sorted on the variables,
	so create the new vartypes map not by repeated insertion, but
	directly (using map.from_sorted_assoc_list).

compiler/purity.m:
	Add a note about a possible future speedup.

compiler/prog_io_sym_name.m:
	Rename a predicate to avoid an ambiguity, and to make its purpose
	clearer.

compiler/globals.m:
compiler/handle_options.m:
compiler/mlds_to_il.m:
	Check whether the mmc option that specifies the IL version number is
	well formed at the start of the compilation, in handle_options.m,
	when all the other option values are checked if needed, rather than
	when generating IL code. This way, we can generate an error message,
	not a compiler abort.

	The IL version number is now recorded in the globals structure.

compiler/make_hlds_warn.m:
	Do not descend into from_ground_term scopes, since by construction,
	they cannot contain singleton variables.

compiler/analysis.file.m:
compiler/deep_profiling..m:
compiler/field_access.m:
compiler/hlds_out.m:
compiler/interval.m:
compiler/liveness.m:
compiler/loop_inv.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile.m:
compiler/loop_inv.m:
compiler/ml_tailcall.m:
compiler/module_qual.m:
compiler/prog_ctgc.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
compiler/quantification.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/structure_reuse.indirect.m:
compiler/superhomogeneous.m:
compiler/var_locn.m:
	Conform to the changes above.

compiler/unused_args.m:
	Fix an ambiguous predicate name.

tests/hard_coded/float_field.{m,exp}:
	Add some more test situations to this test case. These test
	the handling of notag types in static terms more thoroughly
	than before.
2009-09-02 00:30:35 +00:00
Zoltan Somogyi
5af71b60ac Remove support for the Aditi backend. It is a pain to have to update it every
Estimated hours taken: 2
Branches: main

Remove support for the Aditi backend. It is a pain to have to update it every
time a data structure changes when we don't see any benefit from it, and its
presence makes compilation of the compiler directory take about 10% longer
(since the Aditi backend modules are roughly 10% of the code in the compiler
directory). Deleting the Aditi-specific data structures from the HLDS should
also speed up compilation a little bit.

I have spoken to Rao and he is fine with this step.

Aditi users, if there are any, can continue to use the Aditi support in
release 0.12.*. I also tagged the last version on the trunk to support aditi
with the name "last_aditi". The need for modifications in this Aditi support
is likely to be very rare to nonexistent, if the recent past is any guide:
the Aditi backend hasn't seen a nontrivial modification in a year or more.

This diff removes a net 31492 lines.

compiler/add_aditi.m:
compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/context.m:
compiler/dnf.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/rl.m:
compiler/rl_analyse.m:
compiler/rl_block.m:
compiler/rl_block_opt.m:
compiler/rl_code.m:
compiler/rl_dump.m:
compiler/rl_exprn.m:
compiler/rl_file.pp:
compiler/rl_gen.m:
compiler/rl_info.m:
compiler/rl_key.m:
compiler/rl_liveness.m:
compiler/rl_loop.m:
compiler/rl_opt.m:
compiler/rl_out.pp:
compiler/rl_relops.m:
compiler/rl_sort.m:
compiler/rl_stream.m:
	Remove these compiler modules, since they existed only to support the
	Aditi backend.

compiler/hlds_goal.m:
	Delete the Aditi-specific components of goals (e.g. the aditi-builtin
	kind of generic calls and Aditi-evaluated lambdas).

compiler/hlds_pred.m:
	Delete the Aditi-specific components of pred_infos.

compiler/prog_data.m:
	Delete the Aditi-specific items.

compiler/passes_aux.m:
	Don't worry about processing all procedures or just all non-Aditi
	procedures.

compiler/add_clause.m:
	Add a predicate from a deleted module that is now used only here.

compiler/*.m:
	Conform to the data structure changes above.

compiler/notes/*.html:
	Remove references to the Aditi backend.

tests/invalid/aditi.m:
tests/invalid/aditi_errors.err_exp:
tests/invalid/aditi_errors.m:
tests/invalid/aditi_private_builtin.m:
tests/invalid/aditi_state_errors.err_exp:
tests/invalid/aditi_state_errors.m:
tests/invalid/aditi_update_derived_relation.err_exp:
tests/invalid/aditi_update_derived_relation.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/valid/aditi.m:
tests/valid/aditi_calls_mercury.m:
tests/valid/aditi_error_bug.m:
tests/valid/aditi_error_bug2.m:
tests/valid/aditi_error_bug3.m:
tests/valid/aditi_private_builtin.m:
tests/valid/aditi_query.m:
tests/valid/aditi_update.m:
tests/valid/base_relation.m:
tests/valid/base_relation2.m:
tests/valid/ite_to_disj.m:
	Remove these Aditi-specific tests.

tests/*/Mmakefile:
	Remove the references to these Aditi-specific tests.
2006-02-23 09:37:30 +00:00
Zoltan Somogyi
45aa3aad8a Convert these modules to four space indentation, and clean up
Estimated hours taken: 2
Branches: main

compiler/ml_*.m:
	Convert these modules to four space indentation, and clean up
	departures from our coding standards.
2005-09-13 01:19:57 +00:00
Zoltan Somogyi
3c60c0e485 Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Change a bunch of modules to import only one module per line, even
	from the library.

compiler/mlds_to_il.m:
compiler/mlds_to_managed.m:
	Convert these modules to our current coding style. Use state variables
	where appropriate. Use predmode declarations where possible.
2005-03-22 06:40:32 +00:00
Julien Fischer
b7aa52bb90 Remove another unnecessary package dependency in the compiler.
Estimated hours taken: 0.5
Branches: main

Remove another unnecessary package dependency in the compiler.

compiler/ml_backend.m:
	Don't import the transform_hlds package, it isn't needed.

	Document why the check_hlds package need to be imported.
2005-03-21 22:17:33 +00:00
Peter Wang
59d2d4a573 This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17
Branches: main

This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.

As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module.  This required bringing some types from the
compiler into a new module within mdbcomp.

browser/trace_counts.m:
	New module for reading execution trace summaries.

browser/prim_data.m:
	New module holding types and predicates moved in from the compiler.
	Types:
		pred_or_func, sym_name, module_name, proc_label,
		special_pred_id, trace_port
	Predicates:
		string_to_sym_name, insert_module_qualifier

	The mode field of proc_label is now an int instead of a proc_id
	to avoid pulling proc_id into mdbcomp.

browser/mdbcomp.m:
	Add trace_counts and prim_data to the mdbcomp module.

browser/declarative_execution.m:
	Renamed mdb's definition of module_name to flat_module_name
	to avoid conflicts with the definition in mdbcomp__prim_data.

runtime/mercury_trace_base.c:
	In the format of .mercury_trace_counts, write module and predicate
	names now use quoted atom syntax so that names with spaces and
	non-printable characters can be machine-parsed.

browser/:
compiler/:
	Many changes to account for movement of types, and the change to
	proc_label.
2005-01-19 03:11:22 +00:00
Zoltan Somogyi
5d6fd3bd6f Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4
Branches: main

Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.

There are no changes in algorithms, only functionality being moved around.

compiler/code_model.m:
	Change this module from being a submodule of backend_libs.m to being a
	submodule of hlds.m, since nothing in it is dependent on any backend.

compiler/arg_info.m:
compiler/code_util.m:
	Change arg_info.m from being a submodule of ll_backend.m to being a
	submodule of hlds.m, since most of it is applicable to all current
	and foreseeable backends. Move the one exported predicate that is
	ll_backend dependent, and its support predicates, to code_util.m.

compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
	Update include_module declarations in accordance with the above.

compiler/prog_data.m:
compiler/term_util.m:
	Instead of defining two separate types for holding argument size and
	termination information, one including HLDS-specific information (in
	term_util.m) and one not (in prog_data.m), use a polymorphic type
	defined in prog_data.m and two monomorphic instances.

compiler/termination.m:
compiler/mercury_to_mercury.m:
	Change the predicates for writing out argument size and termination
	information to handle the polymorphic type (we don't need special
	handling of the monomorphic versions), and move them from termination.m
	to mercury_to_mercury.m, since this allows us to avoid some
	undesirable dependencies.

compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
	Move the predicate make_instance_string from base_typeclass_info.m
	to hlds_code_util.m, again because it allows us to remove some
	undesirable dependencies.

compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
	Delete some import_module declarations of other top level modules
	in these top level modules. Some imports were totally unnecessary.
	Some imports were useful in only a small minority of submodules;
	those submodules now import the necessary top level modules directly.

	Move remaining import_module declarations to the implementation section
	where this is feasible.

	Where we still need to import modules we ideally shouldn't, note why.

compiler/*.m:
	Update imports of code_util and arg_info.

	In some cases, import top level modules no longer imported by the
	parent module.

	In some cases, delete unnecessary imports.
2004-03-23 10:52:14 +00:00
Simon Taylor
82c6cdb55e Make definitions of abstract types available when generating
Estimated hours taken: 100
Branches: main

Make definitions of abstract types available when generating
code for importing modules.  This is necessary for the .NET
back-end, and for `:- pragma export' on the C back-end.

compiler/prog_data.m:
compiler/modules.m:
compiler/make.dependencies.m:
compiler/recompilation.version.m:
	Handle implementation sections in interface files.

	There is a new pseudo-declaration `abstract_imported'
	which is applied to items from the implementation
	section of an interface file.  `abstract_imported'
	items may not be used in the error checking passes
	for the curent module.

compiler/equiv_type_hlds.m:
compiler/notes/compiler_design.html:
	New file.

	Go over the HLDS expanding all types fully after
	semantic checking has been run.

compiler/mercury_compile.m:
	Add the new pass.

	Don't write the `.opt' file if there are any errors.

compiler/instmap.m:
	Add a predicate instmap_delta_map_foldl to apply
	a procedure to all insts in an instmap.

compiler/equiv_type.m:
	Export predicates for use by equiv_type_hlds.m

	Reorder arguments so state variables and higher-order
	programming can be used.

compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
	Handle `:- pragma foreign_type' as a form of type
	declaration rather than a pragma.

compiler/hlds_data.m:
compiler/*.m:
	Add a field to the type_info_cell_constructor cons_id
	to identify the type_ctor, which is needed by
	equiv_type_hlds.m.

compiler/module_qual.m:
	Donn't allow items from the implementation section of
	interface files to match items in the current module.

compiler/*.m:
tests/*/*.m:
	Add missing imports which only became apparent with
	the bug fixes above.

	Remove unnecessary imports which only became apparent with
	the bug fixes above.

tests/hard_coded/Mmakefile:
tests/hard_coded/export_test2.{m,exp}:
	Test case.

tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
	Test case.
2003-12-01 15:56:15 +00:00
Zoltan Somogyi
804988a5d3 Address Fergus's review comments.
Estimated hours taken: 0.1
Branches: main

compiler/hlds_out.m:
compiler/ml_backend.m:
	Address Fergus's review comments.
2003-03-16 09:28:38 +00:00
Zoltan Somogyi
1cb657b998 Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3
Branches: main

Reduce inappropriate dependencies on ll_backend modules. Except for
simplification of unnecessarily complicated logic in dependency_graph.m,
this change only moves functionality around.

compiler/llds_out.m:
compiler/c_util.m:
compiler/name_mangle.m:
	Move predicates that are used by multiple backends from
	ll_backend__llds_out to backend_libs__c_util and to a new module
	backend_libs__name_mangle. Make the relevant ones functions,
	and give some of them more meaningful names.

compiler/trace.m:
compiler/hlds_goal.m:
	Move a backend-independent predicate from ll_backend__trace
	to hlds__hlds_goal.

compiler/llds.m:
compiler/trace_params.m:
	Move the definition of the trace_port type from ll_backend__llds
	to libs__trace_params to avoid having libs__trace_params depend on
	ll_backend.

compiler/exprn_aux.m:
compiler/globals.m:
	Move the definition of the imported_is_constant from
	ll_backend__exprn_aux to libs__globals to avoid having libs__globals
	depend on ll_backend.

compiler/*.m:
	Conform to the above changes. This removes many inappropriate
	dependencies on the LLDS backend.
2003-03-16 08:01:31 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Peter Ross
26e14009d2 Output Managed C++ code using the same mechanisms as we do for C#
Estimated hours taken: 40
Branches: main

Output Managed C++ code using the same mechanisms as we do for C#
code, rather than using pragma_c_gen to generate MC++ code.  This
fixes the problem that functions couldn't be defined in MC++, and also
should make the code more maintainable in the future as MC++ is much
more similar to C# than to C.

compiler/mlds.m:
	Add a new field to outline_foreign_proc. This field has
	information which links the mlds variables with the variable
	names used in the foreign code.

compiler/ml_code_gen.m:
	Generate a foreign proc for MC++ the same way we generate a
	foreign proc for C#.
	Generate the data for the new field in outline_foreign_proc.
	Use the context of the string which contains the pragma foreign
	proc body for the context of the foreign proc.  This ensures that
	error messages refer to the correct line number.

compiler/mlds_to_il.m:
	Add to the list of foreign languages defined in the module to
	include those which don't have a foreign_proc defined in them.
	Move the relevant code from atomic_statement_to_il to
	generate_method so that we handle external procedures correctly.

compiler/mlds_to_ilasm.m:
	Call mlds_to_managed.

compiler/ml_backend.m:
	Add the new module and remove mlds_to_mcpp and mlds_to_csharp.

compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
	Minor changes to handling the new field in outline_foreign_proc.

compiler/mlds_to_csharp.m:
compiler/mlds_to_mcpp.m:
	Removed files whose functionality has been subsumed by
	mlds_to_managed.

library/construct.m:
library/float.m:
library/io.m:
library/std_util.m:
library/type_desc.m:
	Changes required to get the library to be able compile in the
	ilc grade.
2002-06-21 13:26:50 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00