Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.
COPYING.LIB:
Add a special linking exception to the LGPL.
*:
Update references to COPYING.LIB.
Clean up some minor errors that have accumulated in copyright
messages.
runtime/mercury_int.h:
Add macros to create double-word int64s/uint64s from two words,
and to access each word of a double-word int64 or uint64.
Put the int64 and uint64 versions of the same macro next to each other.
Add parentheses where this clarifies code.
runtime/mercury_float.h:
Note the parallel to the new code in mercury_int.h.
Add comments to #elses and #endifs that repeat the condition of the
initial #if, to make the code easier to read.
Put macro definitions into a consistent order.
Use lower-case names for macro parameters, since this is standard.
Add parentheses where this clarifies code.
Delete a macro definition that is now in mercury_std.h.
runtime/mercury_std.h:
Move a macro here from mercury_float.h, since mercury_int.h now
uses it too.
runtime/mercury_memory.h:
Improve some comments.
compiler/builtin_ops.m:
Add operations to create double-word int64s/uint64s from two words,
and to access each word of a double-word int64 or uint64.
These correspond to the new macros in mercury_int.h.
The new operations are not used yet.
compiler/bytecode.m:
compiler/c_util.m:
compiler/erl_call_gen.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/ml_global_data.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
Conform to the change to builtin_ops.m.
compiler/builtin_ops.m:
Replace the float_word_bits binary op with two unary ops,
dword_float_get_word[01]. The unchanged operand represents the address
of the double word. The only two values of the deleted operand that
made sense were the constants 0 and 1. Replacing the binary op
with two unary ops encodes this invariant in the types.
runtime/mercury_float.h:
Define two new macros/functions, MR_dword_float_get_word[01],
which get the two halves respectively of a double-word float.
These are the implementations of the two new unary ops.
compiler/bytecode.m:
compiler/c_util.m:
compiler/erl_call_gen.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/ml_global_data.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
compiler/unify_gen.m:
compiler/var_locn.m:
Conform to the change above.
runtime/*.[ch]:
trace/*.[chyl]:
As above. In some places, improve comments, e.g. by expanding contractions
such as "we've". Add #ifndef guards against double inclusion around
the trace/*.h files that did not already have them.
tools/*:
Make the corresponding changes in shell scripts that generate .[ch] files
in the runtime.
tests/*:
Conform to a slight change in the text of a message.
Move all .h and .c files to four-space indentation without tabs,
if they weren't there already.
Use the same vim line for all .h and .c files.
Align all backslashes at the ends of lines in macro definitions.
Align close comment signs.
In some places, fix inconsistent indentation.
Fix a bunch of comments. Add XXXs to a few of them.
This is a follow-up to commit fff5759. If we are using C99 we define
MR_is_{nan,infinite,finite} as macros. We should do the same for MSVC version
1800 (VS2013) and onwards and the only reason we didn't already is that MSVC
doesn't define the __STDC_VERSION__ macro appropriately.
runtime/mercury_float.h:
Define MR_is_{nan,infinite,finite} as macros with MSVC version 1800
and onwards.
isnan(), isinf() and isfinite() are type-generic in C99: simplify some
existing code accordingly.
Add the predicates is_finite/1 and is_zero/1 to the float module.
In C grades the implementation of the former maps down to the isfinite macro
(with C99).
configure.ac:
runtime/mercury_confg.h.in:
Check if the C99 macro isfinite is available.
runtime/mercury_float.h:
Add the macro MR_is_finite for testing if a floating point
number is finite. If the C stdlib provides this operation
directly we use that, otherwise we define it in terms of
MR_is_infinite and MR_is_nan.
library/float.m:
Add the predicates is_finite/2 and is_zero/2.
Expand tabs in this file.
Fix capitalization in documentation.
library/int.m:
Fix inconsistent capitalization in a spot.
library/string.m:
Use is_finite/1 in place of negating is_nan_or_infinite/1.
The Mercury runtime procedures MR_is_{inf,nan} are defined as functions, even
on systems (e.g. all those that support the relevant bits of C99), where the
underlying C stdlib uses macros to implement those operations. Define the
above runtime procedures as macros speeds up an artificial test case (counting
infinities in a list of floats) by ~3.5%.
Change the name of MR_is_inf to MR_is_infinite.
runtime/mercury_float.h:
Rename MR_is_inf to MR_is_infinite.
Define MR_is_{infinite,nan} as macros on systems that support C99.
This avoids some unnecessary function call overhead.
Rename the function versions of MR_is_infinite and MR_is_nan to
MR_is_infinite_func and MR_is_nan_func.
runtime/mercury_float.c:
library/float.m:
Conform to the above changes.
runtime/mercury_float.h:
Define MR_float_to_word and MR_word_to_float as macros using GCC's
cast to union extension with clang, since it also supports that
extension.
runtime/mercury_float.h:
Avoid warnings from MSVC about the types of the formal and actual parameters
of calls to MR_float_from_dword differing. The formal parameters have type
MR_Word, but the Mercury compiler doesn't emit casts for the arguments.
(For GCC and clang, MR_float_from_dword is defined as a macro and the
necessary casts occur in its body.) The fix is to rename the function
version of MR_float_from_dword and make MR_float_from_dword a forwarding macro
that inserts the necessary casts.
On some 32-bit architectures, we were violating memory alignment
requirements for double-precision floats, in cell fields and on det and
nondet stacks. Bug #299.
We now only take the address of a double field when it occurs on an
aligned memory address, i.e. when it starts at an even word offset from
the start of a cell (this assumption is incompatible with term-size
profiling which adds a hidden word before the start of the cell).
For the det stack, we can round up allocations to keep the stack pointer
double-aligned, then allocate slots for doubles at even word offsets
from the stack pointer.
It would be trickier for the nondet stack. Multiple frame types exist
on the nondet stack, and the different frame types are identified by
their sizes: 3-word and 4-word temporary frames, and 5/6+ word ordinary
frames. Rather than rounding up frame sizes to even numbers of words,
we would probably want to dynamically pad ordinary frame allocations,
such that any doubles in the frame will be at aligned addresses.
However, in this change, we simply store box floats on the nondet stack.
compiler/globals.m:
Add predicate which returns whether double-width floats
should be stored on the det stack.
compiler/handle_options.m:
Disable double-word fields in term-size profiling grades.
compiler/code_info.m:
Add a predicate to round up det stack frame sizes.
Remember the width of floats stored on the det stack in
exprn_opts.
compiler/hlds_llds.m:
compiler/llds.m:
compiler/stack_layout.m:
Delete the possibility of double-width slots on the nondet
stack.
Remember det_stack_float_width in exprn_opts.
compiler/llds_out_data.m:
Add wrapper macro `MR_dword_ptr' when taking the address of a
double.
Only take the address of doubles on the det stack.
compiler/llds_out_instr.m:
compiler/llds_out_util.m:
Only assign a double field in a single C statement when it is
aligned.
Assert that the stack pointer is incremented by an even number,
if necessary.
compiler/mlds_to_c.m:
Only take the address of doubles when aligned.
compiler/middle_rec.m:
compiler/proc_gen.m:
Round up det stack frame allocations to even numbers of words
when necessary.
compiler/stack_alloc.m:
Add padding as required so that double-word variables will
be allocated at even-word offsets from the stack pointer.
compiler/opt_debug.m:
compiler/par_conj_gen.m:
Conform to changes.
runtime/mercury_conf_param.h:
runtime/mercury_float.h:
Add macro `MR_dword_ptr' to be wrapped around instances where
the address of a double is taken. When `MR_DEBUG_DWORD_ALIGNMENT'
is defined (and using gcc or clang) the address is checked to be
properly aligned. Almost all our development is done on x86 or
x86-64 architecture which do not have strict memory alignment
requirements, making violations hard to check otherwise.
runtime/mercury_deconstruct.c:
runtime/mercury_layout_util.c:
Use `MR_float_from_dword' over `MR_float_from_dword_ptr' as the
former does not require dword alignment.
Related fix: looking up `double' variables on the nondet stack
used the stack pointer for the det stack instead. Fix it,
though the code now won't be executed after this change.
tests/debugger/nondet_stack.exp5:
Add new expected output. This is the same as nondet_stack.exp
except that det stack frames have been rounded up.
Branches: main
Fix bug #240 and bug #211. When MR_Float is wider than MR_Word, the C compiler
may introduce padding for the structure field following the MR_Float. When
MR_Float is narrower than MR_Word the C compiler may pack consecutive MR_Float
fields. In both cases the C structure layout does not match what was intended
by the Mercury compiler.
A test case was committed earlier.
runtime/mercury_float.h:
Add a typedef `MR_Float_Aligned' which forces word alignment using
C extensions provided by gcc/clang/MSVC.
compiler/llds_out_global.m:
compiler/mlds_to_c.m:
Use `MR_Float_Aligned' in place of `MR_Float' in structure definitions.
Output #pragma pack directives around scalar cell group structures.
This is for MSVC.
compiler/c_util.m:
Add helper predicates to output #pragma pack directives for MSVC.
runtime/mercury_conf.h.in:
Define MR_BYTES_PER_WORD. The necessary code in configure.in already
exists.
Branches: main
Fix the other part of bug #228: the MR_float_word_bits macro does not
work with MSVC since it does not support casting to a union type.
Provide a function that does the same thing for use with MSVC.
(For GCC and clang we still use the macro version.)
runtime/mercury_float.h:
As above.
Branches: main
Add float registers to the Mercury abstract machine, implemented as an
array of MR_Float in the Mercury engine structure.
Float registers are only useful if a Mercury `float' is wider than a word
(i.e. when using double precision floats on 32-bit platforms) so we let them
exist only then. In other cases floats may simply be passed via the regular
registers, as before.
Currently, higher order calls still require the use of the regular registers
for all arguments. As all exported procedures are potentially the target of
higher order calls, exported procedures must use only the regular registers for
argument passing. This can lead to more (un)boxing than if floats were simply
always boxed. Until this is solved, float registers must be enabled explicitly
with the developer only option `--use-float-registers'.
The other aspect of this change is using two consecutive stack slots to hold a
single double variable. Without that, the benefit of passing unboxed floats
via dedicated float registers would be largely eroded.
compiler/options.m:
Add developer option `--use-float-registers'.
compiler/handle_options.m:
Disable `--use-float-registers' if floats are not wider than words.
compiler/make_hlds_passes.m:
If `--use-float-registers' is in effect, enable a previous change that
allows float constructor arguments to be stored unboxed in structures.
compiler/hlds_llds.m:
Move `reg_type' here from llds.m and `reg_f' option.
Add stack slot width to `stack_slot' type.
Add register type and stack slot width to `abs_locn' type.
Remember next available float register in `abs_follow_vars'.
compiler/hlds_pred.m:
Add register type to `arg_loc' type.
compiler/llds.m:
Add a new kind of lval: double-width stack slots.
These are used to hold double-precision floating point values only.
Record setting of `--use-float-registers' in exprn_opts.
Conform to addition of float registers and double stack slots.
compiler/code_info.m:
Make predicates take the register type as an argument,
where it can no longer be assumed.
Remember whether float registers are being used.
Remember max float register for calls to MR_trace.
Count double width stack slots as two slots.
compiler/arg_info.m:
Allocate float registers for procedure arguments when appropriate.
Delete unused predicates.
compiler/var_locn.m:
Make predicates working with registers either take the register type as
an argument, or handle both register types at once.
Select float registers for variables when appropriate.
compiler/call_gen.m:
Explicitly use regular registers for all higher-order calls,
which was implicit before.
compiler/pragma_c_gen.m:
Use float registers, when available, at the interface between Mercury
code and C foreign_procs.
compiler/export.m:
Whether a float rval needs to be boxed/unboxed when assigned to/from a
register depends on the register type.
compiler/fact_table.m:
Use float registers for arguments to predicates defined by fact tables.
compiler/stack_alloc.m:
Allocate two consecutive stack slots for float variables when
appropriate.
compiler/stack_layout.m:
Represent double-width stack slots in procedure layout structures.
Conform to changes.
compiler/store_alloc.m:
Allocate float registers (if they exist) for float variables.
compiler/use_local_vars.m:
Substitute float abstract machine registers with MR_Float local
variables.
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
Output float registers and double stack slots.
compiler/code_util.m:
compiler/follow_vars.m:
Count float registers separately from regular registers.
compiler/layout.m:
compiler/layout_out.m:
compiler/trace_gen.m:
Remember the max used float register for calls to MR_trace().
compiler/builtin_lib_types.m:
Fix incorrect definition of float_type_ctor.
compiler/bytecode_gen.m:
compiler/continuation_info.m:
compiler/disj_gen.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/hlds_out_goal.m:
compiler/jumpopt.m:
compiler/llds_to_x86_64.m:
compiler/lookup_switch.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
compiler/tupling.m:
compiler/x86_64_regs.m:
Conform to changes.
runtime/mercury_engine.h:
Add an array of fake float "registers" to the Mercury engine structure,
when MR_Float is wider than MR_Word.
runtime/mercury_regs.h:
Document float registers in the Mercury abstract machine.
Add macros to access float registers in the Mercury engine.
runtime/mercury_stack_layout.h:
Add new MR_LongLval cases to represent double-width stack slots.
MR_LONG_LVAL_TAGBITS had to be increased to accomodate the new cases,
which increases the number of integers in [0, 2^MR_LONG_LVAL_TAGBITS)
equal to 0 modulo 4. These are the new MR_LONG_LVAL_TYPE_CONS_n cases.
Add max float register field to MR_ExecTrace.
runtime/mercury_layout_util.c:
runtime/mercury_layout_util.h:
Extend MR_copy_regs_to_saved_regs and MR_copy_saved_regs_to_regs
for float registers.
Understand how to look up new kinds of MR_LongLval: MR_LONG_LVAL_TYPE_F
(previously unused), MR_LONG_LVAL_TYPE_DOUBLE_STACKVAR,
MR_LONG_LVAL_TYPE_DOUBLE_FRAMEVAR.
Conform to the new MR_LONG_LVAL_TYPE_CONS_n cases.
runtime/mercury_float.h:
Delete redundant #ifdef.
runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
Conform to changes (untested).
trace/mercury_trace.c:
trace/mercury_trace.h:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.c:
trace/mercury_trace_vars.c:
trace/mercury_trace_vars.h:
Handle float registers in the trace subsystem. This is mostly a matter
of saving/restoring them as with regular registers.
Branches: main
Store double-precision `float' constructor arguments in unboxed form,
in high-level C grades on 32-bit platforms, i.e. `float' (and equivalent)
arguments may occupy two machine words.
As the C code generated by the MLDS back-end makes use of MR_Float variables
and parameters, float (un)boxing may be reduced substantially in many programs.
compiler/prog_data.m:
Add `double_word' as a new option for constructor argument widths,
only used for float arguments as yet.
compiler/make_hlds_passes.m:
Set constructor arguments to have `double_word' width if required,
and possible.
compiler/type_util.m:
Add helper predicate.
compiler/builtin_ops.m:
compiler/c_util.m:
compiler/llds.m:
Add two new binary operators used by the MLDS back-end.
compiler/arg_pack.m:
Handle `double_word' arguments.
compiler/ml_code_util.m:
Deciding whether or not a float constructor argument requires boxing
now depends on the width of the field.
compiler/ml_global_data.m:
When a float constant appears as an initialiser of a generic array
element, it is now always unboxed, irrespective of --unboxed-float.
compiler/ml_type_gen.m:
Take double-word arguments into account when generating structure
fields.
compiler/ml_unify_gen.m:
Handle double-word float constructor arguments in (de)constructions.
In some cases we break a float argument into its two words, so
generating two assignments statements or two separate rvals.
Take double-word arguments into account when calculating field offsets.
compiler/mlds_to_c.m:
The new binary operators require no changes here.
As a special case, write `MR_float_from_dword_ptr(&X)' instead of
`MR_float_from_dword(X, Y)' when X, Y are consecutive words within a
field. The definition of `MR_float_from_dword_ptr' is more
straightforward, and gcc produces better code than if we use the more
general `MR_float_from_dword'.
compiler/rtti_out.m:
For double-word arguments, generate MR_DuArgLocn structures with
MR_arg_bits set to -1.
compiler/rtti_to_mlds.m:
Handle double-word arguments in field offset calculation.
compiler/unify_gen.m:
Partially handle double_word arguments in LLDS back-end.
compiler/handle_options.m:
Set --unboxed-float when targetting Java, C# and Erlang.
compiler/structure_reuse.direct.choose_reuse.m:
Rename a predicate.
compiler/bytecode.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/llds_to_x86_64.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/opt_debug.m:
Conform to changes.
library/construct.m:
library/store.m:
Handle double-word constructor arguments.
runtime/mercury_conf.h.in:
Clarify what `MR_BOXED_FLOAT' now means.
runtime/mercury_float.h:
Add helper macros for converting between doubles and word/dwords.
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct.h:
Add a macro `MR_arg_value' and a helper function to extract a
constructor argument value. This replaces `MR_unpack_arg'.
runtime/mercury_type_info.h:
Remove `MR_unpack_arg'.
Document that MR_DuArgLocn.MR_arg_bits may be -1.
runtime/mercury_deconstruct_macros.h:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
Handle double-word constructor arguments.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/lco_double.exp:
tests/hard_coded/lco_double.m:
tests/hard_coded/pack_args_float.exp:
tests/hard_coded/pack_args_float.m:
Add test cases.
trace/mercury_trace_vars.c:
Conform to changes.
Branches: main
Support unboxed float fields in high-level C grades.
When the representation of `float' is no wider than a machine word, d.u.
functor arguments of type `float' (or equivalent) will be stored directly
within cells constructed for that functor, instead of a pointer to the box
containing the value. This was already so for low-level C grades.
compiler/mlds.m:
Add an option to mlds_type, equivalent to
`mlds_array_type(mlds_generic_type)' except that some elements are
known to be floats.
Update some comments.
compiler/ml_global_data.m:
Remember the `--unboxed-float' option in `ml_global_data'.
Special case generic arrays in `ml_gen_static_scalar_const_addr' and
`ml_gen_static_scalar_const_value'. Float literals cannot be used to
initialize an element of a generic array in C. If any appear, replace
the generic array type by an instance of
`mlds_mostly_generic_array_type' with float fields in the positions
which have float initializers.
compiler/ml_code_util.m:
Make `ml_must_box_field_type' and `ml_gen_box_const_rval' depend on the
`--unboxed-float' option.
Delete some now-misleading comments.
Delete an unused predicate.
compiler/mlds_to_c.m:
Update code that writes out scalar static data to handle
`mlds_mostly_generic_array_type'.
In one case, for `--high-level-data' only, output float constants by
their integer representation, so that they may be cast to pointer
types.
compiler/ml_unify_gen.m:
Rename some predicates for clarity.
compiler/ml_accurate_gc.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
Conform to changes.
library/float.m:
Add hidden functions to return the integer representation of the bit
layout of floating point values.
library/exception.m:
Delete mention of MR_AVOID_MACROS.
runtime/mercury.c:
runtime/mercury.h:
Make MR_box_float/MR_unbox_float act like "casts" when MR_BOXED_FLOAT
is undefined, and only define them in high-level grades. I think they
should be replaced by MR_float_to_word/MR_word_to_float (which have
less confusing names when there is no boxing) but that would require
some header file reshuffling which I don't want to undertake yet.
Delete references to MR_AVOID_MACROS. Apparently it existed to support
the defunct gcc back-end but I cannot see it ever being defined.
runtime/mercury_conf_param.h:
MR_HIGHLEVEL_CODE no longer implies MR_BOXED_FLOAT.
Delete mention of MR_AVOID_MACROS.
runtime/mercury_float.h:
Fix a comment.
tests/hard_coded/Mmakefile:
tests/hard_coded/float_ground_term.exp:
tests/hard_coded/float_ground_term.m:
Add a test case.
Branches: main, 11.07
Avoid using the __GNUC__ macro in the runtime as a test for the presence of
gcc, since clang also defines that macro. Since clang doesn't support all
of the GNU C extensions, we can't actually use __GNUC__ without also checking
whether we are actually using clang.
runtime/mercury_conf_param.h:
Add three new macros, MR_CLANG, MR_GNUC and MR_MSVC that are defined
only when the C compiler is clang, gcc, or Visual C respectively.
(In particular, MR_GNUC will _not_ be defined when the C compiler
is clang.)
runtime/mercury.c:
runtime/mercury.h:
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h
runtime/mercury_bitmap.h:
runtime/mercury_float.h:
runtime/mercury_getopt.c:
runtime/mercury_goto.h:
runtime/mercury_heap.h:
runtime/mercury_std.h:
Replace uses of the __GNUC__ and __clang__ macros with the above.
runtime/mercury_regs.h:
As above, also #include mercury_conf_param.h directly since
this file is #included by some of the tests in the configure
script.
Branches: main
Implement a new form of memory profiling, which tells the user what memory
is being retained during a program run. This is done by allocating an extra
word before each cell, which is used to "attribute" the cell to an
allocation site. The attribution, or "allocation id", is an address to an
MR_AllocSiteInfo structure generated by the Mercury compiler, giving the
procedure, filename and line number of the allocation, and the type
constructor and arity of the cell that it allocates.
The user must manually instrument the program with calls to
`benchmarking.report_memory_attribution', which forces a GC and summarises
the live objects on the heap using the attributions. The mprof tool is
extended with a new mode to parse and present that data.
Objects which are unattributed (e.g. by hand-written C code which hasn't
been updated) are still accounted for, but show up in profiles as "unknown".
Currently this profiling mode only works in conjunction with the Boehm
garbage collector, though in principle it can work with any memory allocator
for which we can access a list of the live objects. Since term size
profiling relies on the same technique of using an extra word per memory
cell, the two profiling modes are incompatible.
The output from `mprof -s' looks like this:
------ [1] some label ------
cells words cumul procedure / type (location)
14150 38872 total
* 1949/ 13.8% 4872/ 12.5% 12.5% <predicate `parser.parse_rest/7' mode 0>
975/ 6.9% 1950/ 5.0% list.list/1 (parser.m:502)
487/ 3.4% 1948/ 5.0% term.term/1 (parser.m:501)
487/ 3.4% 974/ 2.5% term.const/0 (parser.m:501)
* 1424/ 10.1% 4272/ 11.0% 23.5% <predicate `parser.parse_simple_term_2/6' mode 0>
708/ 5.0% 2832/ 7.3% term.term/1 (parser.m:643)
708/ 5.0% 1416/ 3.6% term.const/0 (parser.m:643)
...
boehm_gc/alloc.c:
boehm_gc/include/gc.h:
boehm_gc/misc.c:
boehm_gc/reclaim.c:
Add a callback function to be called for every live object after a GC.
Add a function to write out the GC_size_map array.
compiler/layout.m:
Define the alloc_site_info type which is equivalent to the
MR_AllocSiteInfo C structure.
Add alloc_site_array as a kind of "layout" array.
compiler/llds.m:
Add allocation sites to `cfile' structure.
Replace TypeMsg argument (which was also for profiling) on `incr_hp'
instructions by an allocation site identifier.
Add a new foreign_proc_component for allocation site ids.
compiler/code_info.m:
compiler/global_data.m:
compiler/proc_gen.m:
Keep the set of allocation sites in the code_info and global_data
structures.
compiler/unify_gen.m:
Add allocation sites to LLDS allocation instructions.
compiler/layout_out.m:
compiler/llds_out_file.m:
compiler/llds_out_instr.m:
Output MR_AllocSiteInfo arrays in generated C files.
Output code to register the MR_AllocSiteInfo array with the Mercury
runtime.
Output allocation site ids for memory allocation instructions.
compiler/llds_out_util.m:
Add allocation sites to llds_out_info.
compiler/pragma_c_gen.m:
compiler/ml_foreign_proc_gen.m:
Generate a macro MR_ALLOC_ID which resolves to an allocation site
structure, for every foreign_proc whose C code contains the string
"MR_ALLOC_ID". This is to be used by hand-written C code which
allocates memory.
MR_PROC_LABELs are retained for backwards compatibility. Though
they were introduced for profiling, they seem to have been co-opted
for printf-debugging since then.
compiler/ml_global_data.m:
Add allocation site structures to the MLDS global data.
compiler/mlds.m:
compiler/ml_unify_gen.m:
Add allocation site id to `new_object' instruction.
compiler/mlds_to_c.m:
Output allocation site arrays and allocation ids in high-level C code.
Output a call to register the allocation site array with the Mercury
runtime.
Delete an unused predicate.
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
Conform to changes.
compiler/pickle.m:
compiler/prog_event.m:
compiler/timestamp.m:
Conform to changes in memory allocation macros.
library/benchmarking.m:
Add the `report_memory_attribution' instrumentation predicates.
Conform to changes to MR_memprof_record.
library/array.m:
library/bit_buffer.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/io.m:
library/mutvar.m:
library/store.m:
library/string.m:
library/thread.semaphore.m:
library/version_array.m:
Use attributed memory allocation throughout the standard library so
that objects don't show up in the memory profile as "unknown".
Replace MR_PROC_LABEL by MR_ALLOC_ID.
mdbcomp/program_representation.m:
mdbcomp/rtti_access.m:
Replace MR_PROC_LABEL by MR_ALLOC_ID.
profiler/Mercury.options:
profiler/globals.m:
profiler/mercury_profile.m:
profiler/options.m:
profiler/output.m:
profiler/snapshots.m:
Add a new mode to `mprof' to parse and present the data from
`Prof.Snapshots' files.
Add options for the new profiling mode.
profiler/process_file.m:
Fix a typo.
runtime/mercury_conf_param.h:
#define MR_MPROF_PROFILE_MEMORY_ATTRIBUTION if memory profiling
is enabled and we are using Boehm GC.
runtime/mercury.h:
Make MR_new_object take an allocation id argument.
Conform to changes in memory allocation macros.
runtime/mercury_memory.c:
runtime/mercury_memory.h:
runtime/mercury_types.h:
Define MR_AllocSiteInfo.
Add memory allocation functions and macros which take into the
account the additional word necessary for the new profiling mode.
These should be used in preferences to the raw memory allocation
functions wherever possible so that objects do not show up in the
profile as "unknown".
Add analogues of realloc/free which take into account the offset
introduced by the attribution word.
Add function versions of the MR_new_object macros, which can't be
written in standard C. They are only used when necessary.
Add built-in allocation site ids, to be used in the runtime and
other hand-written code when context-specific ids are unavailable.
runtime/mercury_heap.h:
Make MR_tag_offset_incr_hp_msg and MR_tag_offset_incr_hp_atomic_msg
allocate an extra word when memory attribution is desired, and store
the allocation id there.
Similarly for MR_create{1,2,3}_msg.
Replace proclabel arguments in allocation macros by alloc_id
arguments.
Replace MR_hp_alloc_atomic by MR_hp_alloc_atomic_msg. It was only
used for boxing floats.
Conform to change to MR_new_object macro.
runtime/mercury_bootstrap.h:
Delete obsolete macro hp_alloc_atomic.
runtime/mercury_heap_profile.c:
runtime/mercury_heap_profile.h:
Add the code to summarise the live objects on the Boehm GC heap and
writes out the data to `Prof.Snapshots', for display by mprof.
Don't store the procedure name in MR_memprof_record: the procedure
address is enough and faster to compare.
runtime/mercury_prof.c:
Finish and close the `Prof.Snapshots' file when the program
terminates.
Conform to changes in MR_memprof_record.
runtime/mercury_misc.h:
Add a macro to expand to the name of the allocation sites array
in LLDS grades.
runtime/mercury_bitmap.c:
runtime/mercury_bitmap.h:
Pass allocation id through bitmap allocation functions.
Delete unused function MR_string_to_bitmap.
runtime/mercury_string.h:
Add MR_make_aligned_string_copy_msg.
Make string allocation macros take allocation id arguments.
runtime/mercury.c:
runtime/mercury_array_macros.h:
runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_dlist.c:
runtime/mercury_engine.c:
runtime/mercury_float.h:
runtime/mercury_hash_table.c:
runtime/mercury_ho_call.c:
runtime/mercury_label.c:
runtime/mercury_prof_mem.c:
runtime/mercury_stacks.c:
runtime/mercury_stm.c:
runtime/mercury_string.c:
runtime/mercury_thread.c:
runtime/mercury_trace_base.c:
runtime/mercury_trail.c:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_wsdeque.c:
Use attributed memory allocation throughout the runtime so that
objects don't show up in the profile as "unknown".
runtime/mercury_memory_zones.c:
Attribute memory zones to the Mercury runtime.
runtime/mercury_tabling.c:
runtime/mercury_tabling.h:
Use attributed memory allocation macros for tabling structures.
Delete unused MR_table_realloc_* and MR_table_copy_bytes macros.
runtime/mercury_deep_copy_body.h:
Try to retain the original attribution word when copying values.
runtime/mercury_ml_expand_body.h:
Conform to changes in memory allocation macros.
runtime/mercury_tags.h:
Replace proclabel arguments by alloc_id arguments in allocation macros.
runtime/mercury_wrapper.c:
If memory attribution is enabled, tell Boehm GC that pointers may be
displaced by an extra word.
trace/mercury_trace.c:
trace/mercury_trace_tables.c:
Conform to changes in memory allocation macros.
extras/net/tcp.m:
extras/solver_types/library/any_array.m:
extras/trailed_update/tr_array.m:
Conform to changes in memory allocation macros.
doc/user_guide.texi:
Document the new profiling mode.
doc/reference_manual.texi:
Update a commented out example.
Estimated hours taken: 5
Branches: main
Make it easy for the user to select single-precision floats instead of the
default double-precision floats. This can be done by using the `.spf' grade
component, or the option `--single-prec-float'. Code using unboxed floats is
incompatible with code using boxed doubles, so we should have a grade for this.
NEWS:
Mention the changes.
compiler/options.m:
Add the `--single-prec-float' option (also `--single-precision-float').
Comment out the documentation for `--unboxed-float'. It shouldn't be
necessary for users to use it directly any more.
compiler/handle_options.m:
Handle the `.spf' grade component.
Make `--single-prec-float' imply `--unboxed-float'.
compiler/compile_target_code.m:
Pass `-DMR_USE_SINGLE_PREC_FLOAT' to the C compiler when
single-precision floats are enabled.
doc/reference_manual.texi:
doc/user_guide.texi:
Document `.spf' and `--single-prec-float'.
runtime/mercury_conf_param.h:
Document `MR_USE_SINGLE_PREC_FLOAT' differently now that it is
documented in the mmc help and manual.
runtime/mercury_float.h:
Undefine `MR_BOXED_FLOAT' if `MR_USE_SINGLE_PREC_FLOAT' is defined.
runtime/mercury_grade.h:
Update the macros that define the MR_GRADE macro to include "_spf"
if `MR_USE_SINGLE_PREC_FLOAT' is defined.
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
Update these scripts to support the `.spf' grade component and
`--single-prec-float' command-line option.
Estimated hours taken: 0.25
Branches: main
Fix a bug that broke the stage 1 build with lcc in grade hlc.gc.
runtime/mercury_float.h:
Add a missing #include of mercury_std.h, needed for MR_bool.
Estimated hours taken: 0.5
Branches: main
Move implementation of is_nan and is_inf into the runtime.
This avoids problems with warnings about implicit declarations of
functions isnan and isinf when compiling with --ansi.
library/float.m:
runtime/mercury_float.c:
runtime/mercury_float.h:
Move the bodies of is_nan and is_inf into the runtime.
Estimated hours taken: 1
Branches: main
Fix a bug where we weren't outputting floats to enough precision when
deconstructing them.
runtime/mercury_ml_expand_body.h:
Use MR_sprintf_float to determine the representation of the
deconstructed float.
library/string.m:
library/io.m:
runtime/mercury_float.c:
runtime/mercury_float.h:
Move ML_sprintf_float to mercury_float.h.
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
Adapt the test case to test floats which require 17 digits of
precision.
Estimated hours taken: 2
Branches: main
runtime/mercury_float.h:
Fix a bug: there was no definition of MR_make_hp_float_algned()
for the unboxed float case. It should be defined as a NOP for
that case.
Estimated hours taken: 20
Branches: main
Add support for interfacing Mercury with the MPS garbage collector.
This change is broken into three parts:
1. Import version 1.100.1 of the MPS kit into the Mercury
CVS repository, in the directory `mps_gc'.
2. Make some changes to the MPS kit for Mercury,
to support fully-conservative collection and tagged pointers,
and to wrap it in an interface that is similar to that of
the Boehm collector.
3. Modify the rest of the Mercury implementation
to support linking with the MPS kit instead
of the Boehm collector. This involved defining
`mps' as a new GC method and a new grade component.
This is part 3 of 3.
Mmake.workspace:
Include the MPS directories in the header file and library search
paths.
tools/bootcheck:
Link the mps_gc directory into the stage2 and stage3 directories.
Mmake.workspace:
runtime/Mmakefile:
scripts/ml.in:
For *.mps grades, link in mps.a.
(XXX ml.in is linking in libmps.a, which is wrong.)
runtime/Mmakefile:
trace/Mmakefile:
In the rule for `check_headers', which checks macro namespace
cleanliness, allow names to start with `MPS_' or `mps_'.
runtime/RESERVED_MACRO_NAMES:
Add `mercury_mps_h', which is used by mps_gc/code/mercury_mps.h
for its header guard. (Normally it would be better to use
uppercase for header guard macro names, but that would be
inconsistent with the coding style used in mps_gc/code.)
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
Handle the new `mps' GC method and grade component.
compiler/globals.m:
compiler/options.m:
doc/user_guide.texi:
Replace gc_method `conservative' with two alternatives
`boehm' and `mps'. ("--gc conservative" is still allowed,
and treated as equivalent to "--gc boehm".)
Add new function `gc_is_conservative' to globals.m.
compiler/mercury_compile.m:
compiler/handle_options.m:
Use `gc_is_conservative' rather than `= conservative'.
compiler/handle_options.m:
Handle the "mps" grade component.
(XXX need to document this in options.m and user_guide.texi)
compiler/compile_target_code.m:
Pass the appropriate C defines for the new GC methods.
compiler/mercury_compile.m:
Wrap the work-around for a Boehm GC bug inside `#ifndef MR_MPS_GC'.
library/array.m:
Use GC_FREE() rather than GC_free().
This is needed for two reasons:
- so that it works with MPS, which only defines GC_FREE
- so that it works with then Boehm collector when
GC debugging is enabled
library/benchmarking.m:
Output GC statistics for the MPS collector.
runtime/mercury.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
If MR_MPS_GC is defined, use mercury_mps.h rather than gc.h.
runtime/mercury_conf_param.h:
Add configuration macros MR_BOEHM_GC and MR_MPS_GC.
Set MR_CONSERVATIVE_GC if either of these is set.
Default to MR_BOEHM_GC if only MR_CONSERVATIVE_GC is set.
runtime/mercury_context.h:
runtime/mercury_deep_copy.h:
runtime/mercury_engine.h:
runtime/mercury_float.h:
runtime/mercury_heap.h:
Explictly #include "mercury_conf.h", so that
MR_CONSERVATIVE_GC will be set properly before it is tested.
runtime/mercury_grade.h:
Handle the .mps grade component.
runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
runtime/mercury_memory_handlers.c:
Move the call to MR_setup_signals() earlier in the
initialization sequence, so that the MPS signal handlers
get installed after our signal handlers. This is needed
because our signal handlers assume that any signals that
they can't handle are fatal errors, which interfere's
with MPS's use of signal handlers for memory barriers.
runtime/mercury_wrapper.c:
Add code to initialize the MPS collector.
Put code which is specific to the Boehm collector inside
#ifdef MR_BOEHM_GC rather than #ifdef MR_CONSERVATIVE_GC.
runtime/mercury_wrapper.h:
Update a comment.
Estimated hours taken: 2.5
Branches: main
Add MR_ prefixes to uses of configuration macros.
Bootcheck now succeeds with MR_NO_CONF_BACKWARDS_COMPAT.
Mmake.common.in:
Define MR_NO_CONF_BACKWARDS_COMPAT when checking
for namespace cleanliness.
RESERVED_MACRO_NAMES:
Remove the configuration macros.
runtime/mercury_conf_bootstrap.h:
Remove a duplicate definition of BOXED_FLOAT.
configure.in:
*/*.c:
*/*.h:
*/*.m:
Add MR_ prefixes.
Estimated hours taken: 8
Branches: main
Add support for `--gc none' to the MLDS->C back-end,
i.e. support the `hlc' and `hl' grades.
runtime/mercury_float.h:
Extra some of the code from MR_float_to_word() out into
a new macro MR_make_hp_float_aligned(), for use in
MR_box_float().
runtime/mercury.h:
If CONSERVATIVE_GC is not defined, include "mercury_regs.h" and
"mercury_engine.h", so that we get the definition of MR_hp,
and "mercury_overflow.h", for MR_heap_overflow_check().
Define MR_new_object() and MR_box_float() correctly for
the !CONSERVATIVE_GC case.
runtime/mercury_context.h:
runtime/mercury_context.c:
runtime/mercury_engine.c:
runtime/mercury_debug.c:
runtime/mercury_thread.c:
runtime/mercury_stack_trace.c:
trace/mercury_trace_util.c:
Add `#ifndef MR_HIGHLEVEL_CODE ... #endif' wrappers around
sections of code that are specific to the LLDS back-end.
runtime/mercury_wrapper.c:
library/benchmarking.m:
Initialize (in mercury_wrapper.c) and use (in benchmarking.m)
the MercuryEngine struct in the !CONSERVATIVE_GC case, as well
as in the !MR_HIGHLEVEL_CODE case. The MercuryEngine struct
is needed because that is where the heap pointer and heap zone
are stored.
library/table_builtin.m:
Use the correct names for type_ctor_infos when MR_HIGHLEVEL_CODE
is enabled. (Previously this was not an issue because these
type_ctor_infos were only being used in the !CONSERVATIVE_GC case.)
tests/hard_coded/Mmakefile:
For the test cases which use lots of memory, increase the heap
size (using the MERCURY_OPTIONS environment variable) rather
than compiling them with `--gc conservative'. This avoids
spurious test case failures when running the tests via
`tools/bootcheck --grade hlc --no-bootcheck'.
Estimated hours taken: 10
Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.
runtime/mercury_*.[ch]
Add MR_ prefixes to all functions, global variables and almost all
macros that could pollute the namespace. The (intentional) exceptions
are
1. some function, variable, type and label names that already start
with MR_, mercury_, Mercury or _entry;
2. some standard C macros in mercury_std.h;
3. the macros used in autoconfiguration (since they are used in scripts
as well as the runtime, the MR_ prefix may not be appropriate for
those).
In some cases, I deleted things instead of adding prefixes
if the "things" were obsolete and not user visible.
runtime/mercury_bootstrap.h:
Provide MR_-less forms of the macros for bootstrapping and for
backward compatibility for user code.
runtime/mercury_debug.[ch]:
Add a FILE * parameter to a function that needs it.
compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
Add MR_ prefixes to the C code generated by the compiler.
library/*.m:
Add MR_ prefixes to handwritten code.
trace/mercury_trace_*.c:
util/mkinit.c:
Add MR_ prefixes as necessary.
extras/concurrency/semaphore.m:
Add MR_ prefixes as necessary.
Estimated hours taken: 4
Add MR_ prefixes to the types used when generating C code.
This means types such as Word, String, Bool, Float become MR_Word,
MR_String, MR_Bool, MR_Float. Also define MR_Box for both the LLDS and
MLDS backends so we can use it uniformly.
This is very important in environments where String or Bool have already
been used as system types (for example, managed C++). And besides, we
should do it anyway as part of the grand namespace cleanup.
I have fixed all of the uses of the non-prefixed types in the runtime
and trace directories. I haven't done it for the library and compiler
directories yet (no promises that I will do it in future either). But
if you see a non-prefixed type in code from now on, please consider it a
bug and fix it.
mercury_bootstrap.h contains #defines to map the non-prefixed types into
the prefixed ones. Like many of the other namespace cleaning backwards
compatibility macros, this can be turned off with
MR_NO_BACKWARDS_COMPAT.
This shouldn't break any code, but this kind of change affects so many
things that of course there could be problems lurking in there somewhere.
If you start getting errors from the C compiler after this change is
installed, you will want to make sure you at least have the runtime
system updated so that you are getting the backwards compatibility
definitions in mercury_bootstrap.h. Then if you continue to have
problems you can bug me about it.
compiler/export.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
Use MR_Word, MR_Float, MR_Bool, etc when generating C.
doc/reference_manual.texi:
Update the reference manual to talk about MR_Word, MR_String,
MR_Char, etc.
runtime/mercury_bootstrap.h:
Add bootstrapping typedefs.
runtime/*:
trace/*:
Change Word, Float, Bool, Code, String, etc to
MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.
Estimated hours taken: 0.25
runtime/mercury_float.h:
Ensure that we allocate floating point numbers with
hp_alloc_atomic(), which calls GC_malloc_atomic(),
rather than hp_alloc(), which calls GC_malloc().
The aim of this change is to reduce the likelihood of
false hits for the conservative collector.
Estimated hours taken: 2
Cleaned up runtime directory.
runtime/*.c:
- Renamed all .c files as mercury_*.c
Some have been renamed to make their purpose clearer.
call.mod -> mercury_ho_call.c
runtime/*.h:
- Moved contents of .h files to mercury_*.h
- *.h now contain #include mercury_*.h. They be removed later.
- Updated references to conf.h -> mercury_conf.h
runtime/conf.h.in:
- Renamed conf.h.in as mercury_conf.h.in.
Didn't leave a forwarding header for this one, as conf.h was
never part of the repository anyway.
runtime/Mmakefile:
- Convert lists to one-per-line lists.
- Add mercury_accurate_gc.h to HDRS.
- Remove all .mod files
- Make sure runtime.init uses the ORIG_CS not MOD_CS.
- Fix the rules for "clean_o" and "clean_mod_c", which used
wildcards like "*.o" to remove files. The one that removed
all .c files corresponding with *.mod, instead of using MOD_CS
was particularly vicious.
- Cope with the file renamings.
configure.in:
- Cope with the file renamings.
Estimated hours taken: 5
This diff starts migrating global variables into virtual registers,
removes some junk code to do with parallelism, and renames the
special registers with MR_ prefixes.
compiler/llds_out.m:
rename hp, etc as MR_hp, etc.
library/std_util.m:
rename hp and solutions_heap_pointer.
runtime/*:
- remove old parallelism stuff that will change completely when
we use posix threads.
- rename the various special registers (hp, sp, etc) with a MR_
prefix.
- make the solutions heap pointer and the minimum heap reclaimation
point virtual registers rather than global variables.
Estimated hours taken: 0.25
runtime/mercury_float.h:
Fix a bug in the code for word_to_float() and float_to_word()
for non-gcc compilers that prevented it from compiling.
Estimated hours taken: 4
Add new predicate `float__hash' to the standard library for computing a
non-negative integer hash value for a float.
Add a C function to the runtime to do the actual hashing. This
function is in the runtime so that it can be called from both
the library and from C code generated for `pragma fact_table'
indexing.
library/float.m
Add a new predicate `float__hash' that calls the runtime
function `hash_float()'.
runtime/mercury_float.h
Add a declaration for `hash_float()'.
runtime/mercury_float.c
Add new file mercury_float.c for runtime code related to
floats.
Add a new function `hash_float()' for hashing floats.
Estimated hours taken: 6
A general cleanup of the code in the runtime directory, aimed at
formulating a more coherent header file inclusion policy. This change
fixes a couple of bugs that prevented the runtime from compiling in
certain configurations (e.g. on muse) due to missing #includes, and
also fixes a few minor unrelated things such as the use of `size_t'
instead of `unsigned'.
Our header file inclusion policy is that every header file should
#include any other header files needed by the declarations or by the
macros it defines. Cyclic interface dependencies, where two header
files each #include the other, must be avoided (by splitting up header
files into smaller indepdent units, if necessary).
At some stage in the future we should rename all the header files to
`mercury_*.h', to avoid any possible name clashes with system or user
header files.
runtime/Mmake:
Add a new target `check_headers' to check that each
header file is syntactically valid in isolation.
runtime/imp.h:
runtime/mercury_float.h:
runtime/mercury_string.h:
runtime/mercury_types.h:
runtime/calls.h:
Move the code in "imp.h" into new header files.
"imp.h" now contains nothing but #includes.
runtime/conf.h.in:
runtime/*.h:
runtime/{label,prof,prof_mem}.c:
runtime/*.mod:
Update the #includes to reflect the new header file structure.
Add some missing header guards. Add some comments.
Put the correct years in most of the copyright notices.
runtime/heap.h:
Fix a bug: add #include "context.h", needed for
min_heap_reclamation_point.
runtime/context.h:
Fix a bug: add #include "memory.h", needed for MemoryZone.
Move the general description comment to the top of the file.
Fix the indentation of some comments. Add a couple of new comments.
runtime/context.mod:
Delete a couple of unnecessary declarations.
runtime/wrapper.mod:
Change the type used for memory sizes from `unsigned' to `size_t'.
Change the `-p' (primary cache size) option so that it is always
a size in kilobytes, rather than being schitzophrenic about
whether it is bytes or kilobytes.
runtime/regorder_base.h:
Removed, since it not used (and constitutes a
double-maintenance problem).