mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 21:04:00 +00:00
63c8afdad77664ec37f64ad831ec2580c76eda15
57 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2ccac171dd |
Add float registers to the Mercury abstract machine, implemented as an
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. |
||
|
|
f1779bd1e8 |
Improve work stealing. Spark deques have been associated with contexts so far.
This is a problem for the following reasons:
The work stealing code must take a lock to access the resizeable array of
work stealing dequeues. This adds global contention that can be avoided if
this array has a fixed size.
If a context is blocked on a future then that engine cannot execute the
sparks from that context, instead it tries to find global work, this is
more expensive than necessary.
If there are a few dozen contexts then there may be just as many work
stealing queues to take work from, the density of these queues will be
higher if they are fewer. Therefore work stealing will be more successful
on average.
This change associates spark deques with Mercury Engines rather than Contexts
to avoid these problems.
This has invalidated some invariants that allowed the runtime system to make
some worth-while optimisations. These optimisations have been maintained.
Mercury's idle loop has been reimplemented to allow for this. This
re-implementation has allowed for a number of other improvements:
Polling was used to check for new global sparks. This has been removed and
each engine now sleeps using it's own semaphore.
Checks for work can be done in different orders depending on how an engine
joins the idle loop.
When global work becomes available a particular engine can be woken up
rather than any arbitrary engine. We take advantage of this when making
contexts runnable, we try to schedule them on the engine that last executed
them.
When an engine is woken up it can be instructed with what it should do upon
waking up.
When a engine looks for a context to run, it will try to pick a context
that was last executed on it. This may avoid cache misses when the context
begins to run.
In the future we should consider:
Experiment with telling engines which context to run.
Improve the selection of which engine work should be scheduled on to be
hardware and memory-hierarchy aware.
Things that need doing next (probably next week):
./configure should check for POSIX semaphore support.
Profiling times have been broken by this change, they will need fixing.
The threadscope event long now breaks an invariants that the threadscope
graphical tool requires.
Semaphores are setup but never released, this is not a big problem but the
manual page says that some implementations may leak resources.
runtime/mercury_context.h:
runtime/mercury_context.c:
Remove the spark deque field from the MR_Context structure.
Export the new array of spark deques so that other modules may fill in
elements as engines are setup.
Modify the resume_owner_thread field of the MR_Context structure, this was
used to ensure that a context returning through C code would be resumed on
the engine with the correct C stack and depth. This field is now an engine
id and has been renamed to resume_owner_engine, it is advisory unless
resume_engine_required is also set. This way it is used to advise which
engine most recently executed this context and therefore may have a warm
cache.
Remove code that dynamically resized the array of spark deques. Including
the lock that protected against updating this array while it was being read
from other thread.
Introduce code that initialises the statically sized array of spark deques.
Reimplement the idle loop. This replaces MR_runnext and MR_do_runnext with
MR_idle and MR_do_idle respectively. There are also two new entry points
into the idle loop. Which one to use depends on the state of the engine.
Introduce new mechanisms for waking a particular engine. For example the
engine that last executed a context that is now runnable.
Change the algorithm for selecting which context to run, try to select
contexts that where last used on the current engine to avoid cache misses.
Use an engine's victim counter rather than a global victim counter when
trying to steal work.
Introduce some conditionally-compiled code that can be used to profile how
quickly new contexts can be created.
Rename MR_init_thread_stuff and MR_finalize_thread_stuff. The term thread
has been replaced with context since they're in mercury_context.c. This
allows the creation of a new function MR_init_thread_stuff() in
mercury_thread.c I also found the mismatch between the function names and
file name confusing. Move some of the code from MR_init_context_stuff to
the new MR_init_thread_stuff function where it belongs.
Refactor the thread pinning code so that even when thread pinning is
disabled it can be used to allocate each thread to a CPU but not actually
pin them.
Fix some whitespace errors.
runtime/mercury_thread.h:
runtime/mercury_thread.c:
In MR_init_engine():
Allocate an engine id for each engine.
A number of arrays had one slot per engine and where setup using a
lock. Now engine ids are used to index each array and setup is done
without a lock, each engine simply sets up its own slot.
Setup the new per-engine work stealing deques.
The MR_all_engine_bases array has been moved to this file.
Implement a new MR_init_thread_stuff function which initialises some global
variables and locks. Some of MR_init_thread_stuff has been moved from
mercury_context.c
Pin threads as part of MR_init_thread, excluding the primordial thread
which must be pinned before threadscope is initialised.
Add functions for debugging the use of semaphores.
Add corresponding macros that can be used to redirect semaphore calls to
debugging functions as above.
Improved thread debugging code, ensured that stderr is flushed after every
use, and that logging is done after calls return as well as before they're
called.
Conform to changes in mercury_context.h
runtime/mercury_engine.h:
runtime/mercury_engine.c:
Add spark deque and victim counter fields to the MercuryEngine structure.
Make the MR_eng_id field of the MercuryEngine structure available in all
thread safe grades, formerly it was used in only threadscope grades.
Move the MR_all_engine_bases variable to mercury_thread.[ch]
Put a reference to the engine's spark queue into the global array. This is
done here, so that it is after thread pinning because the original plan was
to have this array sorted by CPU rather then engine - we may yet do this in
the future.
Initialise an engine's spark deque when an engine is initialised.
Setup the engine specific threadscope data in mercury_thread.c
Conform to changes in mercury_context.h
runtime/mercury_wrapper.c:
The engine base array is no longer setup here, that code has been moved to
mercury_thread.c
Conform to changes in mercury_context.h and mercury_thread.h
runtime/mercury_wsdeque.h:
runtime/mercury_wsdeque.c:
The original implementation allocated an array for a spark queue only if
one wasn't already allocated, which could happen when a context was reused.
Now that spark queues are associated with engines arrays are always
allocated.
Replaced two macros with a single macro since there's no-longer a
distinction between global and local work queues, all work queues are
local.
runtime/mercury_wsdeque.c:
runtime/mercury_wsdeque.h:
Remove the --worksteal-max-attempts and --worksteal-sleep-msecs options as
they are no-longer used.
runtime/mercury_threadscope.h:
runtime/mercury_threadscope.c:
The MR_EngineId type has been moved to mercury_types.h
Engine IDs are no-longer allocated here, this is done in mercury_thread.c
The run spark and steal spark messages now write 0xFFFFFFFF for the context
id if there is no current context. Previously this would dereference a
null pointer.
runtime/mercury_memory_zones.c:
When checking for an existing memory zone check the free_zones_list
variable before taking a lock. This can prevent taking the lock in cases
where there are no free zones.
Introduce some conditionally-compiled code that can be used to profile how
quickly new contexts can be created.
runtime/mercury_bootstrap.h:
Remove macros that no-longer resolve to functions due to changes in the
runtime system.
runtime/mercury_types.h:
Move the MR_EngineId type from mercury_threadscope.h to mercury_types.h
runtime/mercury_grade.h:
Introduce a parallel grade version number, this change brakes binary
compatibility with existing parallel code.
runtime/mercury_backjump.c:
runtime/mercury_par_builtin.c:
runtime/mercury_mm_own_stacks.c:
library/stm_builtin.m:
library/thread.m:
library/thread.semaphore.m:
Conform to changes in mercury_context.h.
library/io.m:
Make this module compatible with MR_debug_threads.
doc/user_guide.texi
Remove the documentation for the --worksteal-max-attempts and
--worksteal-sleep-msecs options. The documentation was already commented
out.
|
||
|
|
322feaf217 |
Add more threadscope instrumentation.
This change introduces instrumentation that tracks sparks as well as parallel
conjunctions and their conjuncts. This should hopefully give us more
information to diagnose runtime performance issues.
As of this date the ThreadScope program hasn't been updated to read or
understand these new events.
runtime/mercury_threadscope.[ch]:
Added a function and types to register all the threadscope strings from an
array.
Add functions to post the new events (see below).
runtime/mercury_threadscope.c:
Added support for 5 new threadscope events.
Registering a string so that other messages may refer to a constant
string.
Marking the beginning and ends of parallel conjunctions.
Creating a spark for a parallel conjunct.
Finishing a parallel conjunct.
Re-arranged event IDs, I've started allocating IDs from 38 onwards for
general purposes and 100 onwards for mercury specific events after talking
with Duncan Coutts.
Trimmed excess whitespace from the end of lines.
runtime/mercury_context.h:
Post a beginning parallel conjunction message when the sync term for the
parallel conjunction is initialized.
Post an event when creating a spark for a parallel conjunction.
Add a MR_spark_id field to the MR_Spark structure, these identify sparks to
threadscope.
runtime/mercury_context.c:
Post threadscope messages when a spark is about to be executed.
Post a threadscope event when a parallel conjunct is completed.
Add a missing memory barrier.
runtime/mercury_wrapper.[ch]:
Create a global function pointer for the code that registers strings in the
threadscope string table, this is filled in by mkinit.
Call this function pointer immediatly after setting up threadscope.
runtime/mercury_wsdeque.[ch]:
Modify MR_wsdeque_pop_bottom to return the spark pointer (which points onto
the queue) rather then returning a result through a pointer and bool if the
operation was successful. This pointer is safe to dereference until
MR_wsdeque_push_bottom is used.
runtime/mercury_wsdeque.c:
Corrected a code comment.
runtime/mercury_engine.h:
Documented some of the fields of the engine structure that hadn't been
documented.
Add a next spark ID field to the engine structure.
Change the type of the engine ID field to MR_uint_least16_t
compiler/llds.m:
Add a third field to the init_sync_term instruction that stores the index
into the threadscope string table of the static conjunction ID.
Add a field to the c_file structure containing the threadscope string
table.
compiler/layout.m:
Added a new layout array name for the threadscope string table.
compiler/layout_out.m:
Implement code to write out the threadscope string table.
compiler/llds_out_file.m:
Write out the threadscope string table when writing out the c_file.
compiler/par_conj_gen.m:
Create strings that statically identify parallel conjunctions for each
init_sync_term LLDS instruction. These strings are added to a table in the
!CodeInfo and the index of the string is added to the init_sync_term
instruction.
Add an extra instruction after a parallel conjunction to post the message
that the parallel conjunction has completed.
compiler/global_data.m:
Add fields to the global data structure to represent the threadscope string
table and its current size.
Add predicates to update and retrieve the table.
Handle merging of threadscope string tables in global data by allowing the
references to the strings to be remapped.
Refactored remapping code so that a caller such as proc_gen only needs to
call one remapping predicate after merging global data..
compiler/code_info.m:
Add a table of strings for use with threadscope to the code_info_persistent
type.
Modify the code_info_init to initialise the threadscope string table fields.
Add a predicate to get the string table and another to update it.
compiler/proc_gen.m:
Build the containing goal map before code generation for procedures with
parallel conjunctions in a parallel grade. par_conj_gen.m depends on this.
Conform to changes in code_info.m and global_data.m
compiler/llds_out_instr.m:
Write out the extra parameter in the init_sync_term instruction.
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
Conform to changes in llds.m
compiler/opt_debug.m:
Conform to changes in layout.m
compiler/mercury_compile_llds_back_end.m:
Fix some trailing whitespace.
util/mkinit.c:
Build an initialisation function that registers all the strings in
threadscope string tables.
Correct the layout of a comment.
|
||
|
|
df31fc6f94 |
Fix hlc.gc.par.
The hlc.gc.par grade was broken after committing my fix for the stack segment
parallel grades. The problem is that hlc grades use Mercury engines but don't
follow the same code paths as the low-level C grades. This means that they
expect that the MR_all_engine_bases array isn't allocated by the time the
engine structures are being created.
This change set makes the MR_all_engine_bases array only available in low-level
C parallel grades making problems involving this array impossible in high level
C grades.
runtime/mercury_engine.h:
runtime/mercury_engine.c:
Only make MR_all_engine_bases available in thread safe low-level C grades.
runtime/mercury_thread.h:
runtime/mercury_thread.c:
Only make MR_init_engine_array_lock available in thread safe low-level C
grades.
Only try to populate MR_all_engine_bases in thread safe low-level C grades.
runtime/mercury_context.c:
Only initialise MR_init_engine_array_lock in thread safe low-level C
grades.
|
||
|
|
f6e5c3c647 |
Fix a crash that can occur in low-level C, parallel, stack-segment grades.
MR_destroy_context will cache contexts in case the runtime needs a context in
the near future. Because the context no-longer represents an on-going
computation MR_destroy_context did not copy context-data out of the
MercuryEngine and real machine registers into the context before caching it.
However in a stack segments grade a one of these values is the current stack
segment, this means that a context may be cached and later re-used which refers
to a stack segment that another context is now using, the cached context will
then trash the other context's stack.
The solution is to save the context before caching it.
This change also contains code that was helpful in diagnosing this problem.
runtime/mercury_context.c:
Fix the bug (as above).
Initialise the MR_init_engine_array_lock in MR_setup_thread_stuff.
Print out logging messages if MR_DEBUG_STACK_SEGMENTS is defined in various
places.
runtime/mercury_debug.h:
runtime/mercury_debug.c:
Write code for printing out debug log messages in a grade appropriate-way.
runtime/mercury_memory_handlers.c:
When exiting a signal handler flush the threadscope buffers of all engines
before re-raising the signal.
runtime/mercury_engine.h:
runtime/mercury_engine.c:
In thread safe grades provide an array of pointers to Mercury engines in
the runtime. This is used to flush the threadscope buffers in the signal
handlers. It may be used to improve work stealing in the future.
runtime/mercury_thread.h:
runtime/mercury_thread.c:
When creating threads add each one's engine to the array of engine pointers.
runtime/mercury_wrapper.c:
Allocate the array of engine pointers when the runtime starts up.
|
||
|
|
83a6f14708 |
Create a threadscope grade component.
Threadscope grades are enabled by using the grade component 'threadscope'.
They are supported only with low-lavel C parallel grades. Support for
threadscope in high level C grades is intended in the future but does not work
now.
runtime/mercury_conf_param.h:
Create the MR_THREADSCOPE macro that is defined if the grade is a
threadscope grade.
Define MR_PROFILE_FOR_PARALLEL_EXECUTION if MR_THREADSCOPE is defined.
Emit an error if MR_LL_PARALLEL_CONJ is defined before it is implied by
MR_THREADSAFE and ! MR_HIGHLEVEL_CODE
runtime/mercury_grade.h
Update the grade symbol for the threadscope grade component.
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h:
runtime/mercury_context.c:
runtime/mercury_context.h:
runtime/mercury_engine.c:
runtime/mercury_engine.h:
runtime/mercury_thread.c:
runtime/mercury_threadscope.c:
runtime/mercury_threadscope.h:
runtime/mercury_wrapper.c:
Now that MR_PROFILE_FOR_IMPLICIT_PARALLELISM is implied by MR_THREADSAFE we
don't need to test for MR_THREADSAFE when we test for
MR_PROFILE_FOR_IMPLICIT_PARALLELISM. The same is true for
MR_LL_PARALLEL_CONJ which is implied by MR_THREADSAFE &&
!MR_HIGHLEVEL_CODE.
Replace some occurances of MR_PROFILE_FOR_IMPLICIT_PARALLELISM with
MR_THREADSCOPE where the conditionally compiled code is used to support
threadscope profiling.
scripts/init_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/mgnuc.in:
compiler/handle_options.m:
compiler/options.m:
compiler/compile_target_code.m:
configure.in:
Add support for the new grade component.
Pass -DMR_THREADSCOPE to the C compiler when using a threadscope grade.
Add assertions to ensure that the 'threadscope' grade component is used
only with the 'par' grade component.
doc/user_guide.texi:
Added commented-out documentation for the threadscope greate component.
Adjusted documentation of the --profile-parallel-execution runtime option
to describe the correct prerequisite compile time options.
Added my name to the authors list.
runtime/mercury_context.c:
Corrected grammar and prose in comments in the MR_do_join_and_continue code.
|
||
|
|
92afa23af5 |
Support for threadscope profiling of the parallel runtime.
This change adds support for threadscope profiling of the parallel runtime in
low level C grades. It can be enabled by compiling _all_ code with the
MR_PROFILE_PARALLEL_EXECUTION_SUPPORT C macro defined. The runtime, libraries
and applications must all have this flag defined as it alters the MercuryEngine
and MR_Context structures.
See Don Jones Jr, Simon Marlow, Satnam Singh - Parallel Performance Tuning for
Haskell.
This change also includes:
Smarter thread pinning (the primordial thread is pinned to the thread that
it is currently running on).
The addition of callbacks from the Boehm GC to notify the runtime of
stop the world garbage collections.
Implement some userspace spin loops and conditions. These are cheaper than
their POSIX equivalents, do not support sleeping, and are signal handler
safe.
boehm_gc/alloc.h:
boehm_gc/alloc.c:
Declare and define the new callback functions.
boehm_gc/alloc.c:
Call the start and stop collect callbacks when we start and stop a
stop-the-world collection.
Correct how we record the time spent collecting, it now includes
collections that stop prematurely.
boehm_gc/pthread_stop_world.c:
Call the pause and resume thread callbacks in each thread where the GC
arranges for that thread to be stopped during a stop-the-world collection.
runtime/mercury_threadscope.c:
runtime/mercury_threadscope.h:
New files implementing the threadscope support.
runtime/mercury_atomic_ops.c:
runtime/mercury_atomic_ops.h:
Rename MR_configure_profiling_timers to MR_do_cpu_feature_detection.
Add a new function MR_read_cpu_tsc() to read the TSC register from the CPU,
this simply abstracts the static MR_rdtsc function.
runtime/mercury_atomic_ops.h:
Modify the C inline assembler to ensure we tell the C compiler that the
value in the register mapped to the 'old' parameter is also an output from
the instructions. That is, the C compiler must not depend on the value of
'old' being the same before and after the instruction is executed. This
has never been a problem in practice though.
Implement some cheap userspace mutual exclusion locks and condition
variables. These will be faster than pthread's mutexes when critical
sections are short and threads are pinned to separate CPUs.
runtime/mercury_context.c:
runtime/mercury_context.h:
Add a new function for pinning the primordial thread. If the OS supports
sched_getcpu we use it to determine which CPU the primordial thread should
use. No other thread will be pinned to this CPU.
Add a numeric id field to each context, this id is uniquely assigned and
identifies each context for threadscope.
MR_schedule_context posts the 'context runnable' threadscope event.
MR_do_runnext has been modified to destroy engines differently, it ensures
they cleanup properly so that their threadscope events are flushed properly
and then calls pthread_exit(0)
MR_do_runnext posts events for threadscope.
MR_do_join_and_continue posts events for threadscope.
runtime/mercury_engine.h:
Add new fields to the MercuryEngine structure including a buffer of
threadscope events, a clock offset (used to synchronize the TSC clocks) and
a unique identifier for the engine,
runtime/mercury_engine.c:
Call MR_threadscope_setup_engine() and MR_threadscope_finalize_engine for
newly created and about-to-be-destroyed engines.
When the main context finishes on a thread that's not the primordial thread
post a 'context is yielding' message before re-scheduling the context on
the primordial thread.
runtime/mercury_thread.c:
Added an XXX comment about a potential problem, it's only relevant for
programs using thread.spawn.
Added calls to the TSC synchronisation code used for threadscope profiling.
It appears that this is not necessary on modern x86 machines, it has been
commented out.
Post a threadscope event when we create a new context.
Don't call pthread_exit in MR_destroy_thread, we now do this in
MR_do_runnext so that we can unlock the runqueue mutex after cleaning up.
runtime/mercury_wrapper.c:
Conform to changes in mercury_atomic_ops.[ch]
Post an event immediately before calling main to mark the beginning of the
program in the threadscope profile.
Post a "context finished" event at the end of the program.
Wait until all engines have exited before cleaning up global data, this is
important for finishing writing the threadscope data file.
configure.in:
runtime/mercury_conf.h.in:
Test for the sched_getcpu C function and utmpx.h header file, these are
used for thread pinning.
runtime/Mmakefile:
Include the mercury_threadscope.[hc] files in the list of runtime headers
and sources respectively.
|
||
|
|
d4bbcda309 |
Move all the frequently occurring layout structures and components of layout
Estimated hours taken: 40 Branches: main Move all the frequently occurring layout structures and components of layout structures into arrays where possible. By replacing N global variables holding individual layout structures or layout structure components with one global variable holding an array of them, we reduce the sizes of the symbol tables stored in object files, which should speed up both the C compiler and the linker. Measured on the modules of the library, mdbcomp and compiler directories compiled in grade asm_fast.gc.debug, this diff reduces the size of the generated C source files by 7.8%, the size of the generated object files by 10.4%, and the number of symbols in the symbol tables of those object files by a whopping 42.8%. (These improvements include, and are not on top of, the improvements in my previous similar diff.) runtime/mercury_stack_layout.h: Each label layout structure has information about the type and location of every variable that is live at that label. We store this information in three arrays: an array of pseudo-typeinfos giving the types of all these variables, and two arrays MR_ShortLvals and MR_LongLvals respectively giving their locations. (Most of the time, the location's encoded form fits into one byte (the MR_ShortLval) but sometimes it needs more bits (this is when we use MR_LongLval)). We used to store these three arrays, whose elements are different types, in a single occurrence-specific common structure, one after the other, with a cumbersome mechanism being required to access them. We now store them as segments of three separate arrays, of pseudo-typeinfos, MR_ShortLvals and MR_LongLvals respectively. This makes access simpler and faster (which will matter more to any accurate garbage collector than it does to the debugger). It also allows more scope for compression, since reusing an existing segment of one of the three arrays is easier than reusing an entire common structure, which would require the equivalent of exact matches on all three arrays. Since most label layout structures that have information about variables can encode the variables' locations using only MR_ShortLvals, create a version of the label layout structure type that omits the field used to record the whereabouts of the long location descriptors. Add macros now generated by the compiler to initialize layout structures. Simplify a one-field struct. runtime/mercury_grade.h: Increment the binary compatibility version number for debuggable executables, since .c and .o files from before and after the change to label layout structures are NOT compatible. runtime/mercury_type_info.h: Fix some binary-compatibility-related bit rot. runtime/mercury_misc.h: Move here the existing macros used by the compiler when generating references to layout arrays, and add new ones. runtime/mercury_goto.h: Delete the macros moved to mercury_misc.h. Conform to the changes in mercury_stack_layout.h. runtime/Mmakefile: Prevent the unnecessary rebuilding of mercury_conf.h. runtime/mercury_accurate_gc.c: runtime/mercury_agc_debug.c: runtime/mercury_layout_util.c: runtime/mercury_stack_trace.c: runtime/mercury_types.h: trace/mercury_trace.c: trace/mercury_trace_vars.c: Conform to the changes in mercury_stack_layout.h. runtime/mercury_wrapper.c: Improve the debug support a bit. runtime/mercury_engine.h: Fix style. compiler/layout.m: Make the change described at the top. Almost all layout structures are now in arrays. The only exceptions are those that occur rarely, and proc layouts, whose names need to be derivable from the name of the procedure itself. Instead of having a single type "layout_data" that can represent different kinds of single global variables (not array slots), have different kinds for different purposes. This makes the code clearer and allows traversals that do not have to skip over inapplicable kinds of layout structures. compiler/layout_out.m: Output the new arrays. compiler/stack_layout.m: Generate the new arrays. Previously, an individual term generated by stack_layout.m could represent several components of a layout structure, with the components separated by layout_out.m. We now do the separation in stack_layout.m itself, adding each component to the array to which it belongs. Instead of passing around a single stack_layout_info structure, pass around several smaller one. This is preferable, since I found out the hard way that including everything in one structure would give the structure 51 fields. Most parts of the module work with only one or two of these structures, which makes their role clearer. Cluster related predicates together. compiler/options.m: doc/user_guide.texi: Add an option that control whether stack_layout.m will attempt to compress the layout arrays that can meaningfully be comressed. compiler/llds.m: Remove the old distinction between a data_addr and a data_name, replacing both types with a single new one: data_id. Since different kinds of data_names were treated differently in many places, the distinction in types (which was intended to allow us to process data_addrs that wrapped data_names differently from other kinds of data_addrs) wasn't buying us anything anymore. The new data_id type allows for the possibility that the code generator wants to generate a reference to an address it does not know yet, because it is a slot in a layout array, and the slot has not been allocated yet. Add the information from which the new layout array structures will be generated to the LLDS. compiler/llds_out.m: Call layout_out.m to output the new layout arrays. Adapt the decl_id type to the replacement of data_addrs by data_ids. Don't both keeping track of the have-vs-have-not-declared status of structures that are always declared at the start. When writing out a data_addr, for some kinds of data_addr, llds_out.m would write out the name of the relevant variable, while for some other kinds, it would write out its address. This diff separates out those those things into separate predicates, each of which behaves consistently. compiler/mercury_compile_llds_back_end.m: Convey the intended contents of the new layout arrays from stack_layout.m to llds_out.m. compiler/continuation_info.m: Add a type required by the way we now generate proc_static structures for deep profiling. compiler/hlds_rtti.m: Add distinguishing prefixes to the field names of the rtti_proc_label type. compiler/code_info.m: compiler/code_util.m: compiler/erl_rtti.m: compiler/exprn_aux.m: compiler/global_data.m: compiler/ll_pseudo_type_info.m: compiler/ml_code_util.m: compiler/opt_debug.m: compiler/proc_gen.m: compiler/prog_rep.m: compiler/rtti_out.m: compiler/unify_gen.m: Conform to the changes above. tests/debugger/declarative/track_through_catch.exp: Expect procedures to be listed in the proper order. tests/EXPECT_FAIL_TESTS.asm_fast.gc.debug: tests/EXPECT_FAIL_TESTS.asm_fast.gc.profdeep: Add these files to ignore expected failues in these grades. |
||
|
|
fa80b9a01a |
Make the parallel conjunction execution mechanism more efficient.
Branches: main Make the parallel conjunction execution mechanism more efficient. 1. Don't allocate sync terms on the heap. Sync terms are now allocated in the stack frame of the procedure call which originates a parallel conjunction. 2. Don't allocate individual sparks on the heap. Sparks are now stored in preallocated, growing arrays using an algorithm that doesn't use locks. 3. Don't have one mutex per sync term. Just use one mutex to protect concurrent accesses to all sync terms (it's is rarely needed anyway). This makes sync terms smaller and saves initialising a mutex for each parallel conjunction encountered. 4. We don't bother to acquire the global sync term lock if we know a parallel conjunction couldn't be executing in parallel. In a highly parallel program, the majority of parallel conjunctions will be executed sequentially so protecting the sync terms from concurrent accesses is unnecessary. par_fib(39) is ~8.4 times faster (user time) on my laptop (Linux 2.6, x86_64), which is ~3.5 as slow as sequential execution. configure.in: Update the configuration for a changed MR_SyncTerm structure. compiler/llds.m: Make the fork instruction take a second argument, which is the base stack slot of the sync term. Rename it to fork_new_child to match the macro name in the runtime. compiler/par_conj_gen.m: Change the generated code for parallel conjunctions to allocate sync terms on the stack and to pass the sync term to fork_new_child. compiler/dupelim.m: compiler/dupproc.m: compiler/exprn_aux.m: compiler/global_data.m: compiler/jumpopt.m: compiler/livemap.m: compiler/llds_out.m: compiler/llds_to_x86_64.m: compiler/middle_rec.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/reassign.m: compiler/use_local_vars.m: Conform to the change in the fork instruction. compiler/liveness.m: compiler/proc_gen.m: Disable use of the parallel conjunction operator in the compiler as older versions of the compiler will generate code incompatible with the new runtime. runtime/mercury_context.c: runtime/mercury_context.h: Remove the next pointer field from MR_Spark as it's no longer needed. Remove the mutex from MR_SyncTerm. Add a field to record if a spark belonging to the sync term was scheduled globally, i.e. if the parallel conjunction might be executed in parallel. Define MR_SparkDeque and MR_SparkArray. Use MR_SparkDeques to hold per-context sparks and global sparks. Change the abstract machine instructions MR_init_sync_term, MR_fork_new_child, MR_join_and_continue as per the main change log. Use a preprocessor macro MR_LL_PARALLEL_CONJ as a shorthand for !MR_HIGHLEVEL_CODE && MR_THREAD_SAFE. Take the opportunity to clean things up a bit. runtime/mercury_wsdeque.c: runtime/mercury_wsdeque.h: New files containing an implementation of work-stealing deques. We don't do work stealing yet but we use the underlying data structure. runtime/mercury_atomic.c: runtime/mercury_atomic.h: New files to contain atomic operations. Currently it just contains compare-and-swap for gcc/x86_64, gcc/x86 and gcc-4.1. runtime/Mmakefile: Add the new files. runtime/mercury_engine.h: runtime/mercury_mm_own_stacks.c: runtime/mercury_wrapper.c: Conform to runtime changes. runtime/mercury_conf_param.h: Update an outdated comment. |
||
|
|
1d50d41883 |
Add support for thread local trailing in grades that support parallel
Estimated hours taken: 14 Branches: main Add support for thread local trailing in grades that support parallel execution. Previously the trail state for each context was copied into the global variables defined in mercury_trail.[ch] when the context was loaded, i.e. we had thread-local trailing in grades that did not support parallel execution. This change extends the runtime to support thread local trailing in the presence of parallel execution. We do this by adding the relevant fields to the MercuryEngine structure and redefining the abstract registers related to trailing to make accesses to the trail state go via the relevant engine. This also works for parallel trailing grades with the high-level C backend because in those grades the trail state is stored in a thread-local dummy engine and context. (The context, and its attached trail state, are created when the thread is spawned.) XXX the coupling between the high-level and low-level versions of the runtimes w.r.t trailing is not good. I intend to fix it as a separate change. (It also affects thread local mutables.) runtime/mercury_context.h: Fix a comment: a context's trail_zone field should be accessed via MR_eng_context, not via the an abstract machine register. runtime/mercury_engine.h: Extend engines so that in parallel trailing grades they contain the information necessary to keep track of the state of the trail. runtime/mercury_regs.h: In parallel grades MR_trail_ptr, MR_ticket_counter and MR_ticket_high_water need to be accessed w.r.t the engine that the context is being executed on. Modify the definition of MR_restore_trail_registers() so that it accesses the trail state via abstract registers rather than manipulating the global variables defined in mercury_trail.[ch] directly. runtime/mercury_trail.[ch]: Only define global variables to hold the trail state in non-parallel grades. Document the difference between parallel and non-parallel trailing grades. library/benchmarking.m: In .par.tr grades, ML_report_stats should print the size of the trail for the current context. NEWS: Announce support for thread local trailing in parallel grades. |
||
|
|
7989f17311 |
Fix some software rot that prevented I/O operations from working in mmos
Estimated hours taken: 6
Branches: main
Fix some software rot that prevented I/O operations from working in mmos
grades. The problem was the change to the I/O module to make it use thread
local storage via a new field of the MR_Context structure which was accessed
via the MR_eng_this_context field of the engine, instead of via the
MR_eng_context field. The new field was not set by the code for initializing
the contexts used by own stack minimal model tabling.
runtime/mercury_context.h:
runtime/mercury_engine.h:
Add significant new documentation about how fields of the MR_Context
structure are accessed, both because the documentation is useful and to
make similar mistakes less likely in future.
Add a macro for use by own stack minimal model tabling.
runtime/mercury_thread.c:
Add a comment about a link to mercury_engine.h.
runtime/mercury_thread.h:
Convert to four-space indentation, and fix some formatting.
runtime/mercury_mm_own_stacks.c:
Add code for filling in the missing fields of newly created contexts.
runtime/mercury_wrapper.c:
In own stack minimal model grades, set up the main context properly.
The previous code was based on a flawed understanding of the
relationalship between MR_eng_context and MR_eng_this_context.
tests/debugger/mmos_print.{m,inp,exp}:
Add a new test case (which we don't yet pass due to a problem with
formatting of mdb output) to test the fix. The old versions of the
compiler don't pass this test case, because the "p *" commands of the
debugger invoke I/O code in the Mercury standard library, which fails
with a segfault due to the thread local fields of generators' contexts
being uninitialized.
Note that the .inp aborts execution, because without the abort the
execution would go into an infinite loop since mmos grades don't yet
have code for detecting completion.
tests/debugger/Mmakefile:
Enable the new test case in mmos grades.
Fix inconsistent indentation.
tests/tabling/Mmakefile:
Do not try to execute minimal tests in mmos grades, since we don't pass
them yet, and the symptom is in many cases an infinite loop.
|
||
|
|
b2f14e1afa |
Some bug fixes to do with threads.
Branches: main Some bug fixes to do with threads. library/io.m: ML_maybe_make_err_msg() was not thread-safe but was called from some `thread_safe' foreign_procs. Make ML_maybe_make_err_msg() acquire the global lock if the caller does not acquire the global lock itself. library/thread.m: runtime/mercury_thread.c: Create threads in the detached state so that resources will be automatically freed when threads terminate (we don't call pthread_join() anywhere). library/thread.semaphore.m: Wake up waiting threads in FIFO order, instead of LIFO order. runtime/mercury_context.c: runtime/mercury_context.h: runtime/mercury_engine.c: runtime/mercury_engine.h: Change the way we enforce that a Mercury context returning from Mercury code back into a C function runs on the original Mercury engine that called the C function. Previously, if a C function called into Mercury code, the Mercury context would be "owned" by that Mercury engine until the C function finished. If the Mercury code suspended (e.g. waiting on a semaphore), it could not be resumed by another Mercury engine. This was unnecessarily conservative. Now any Mercury engine can resume a suspended context. Just before returning into C functions, we check that the context is actually running on the Mercury engine in which the C function was started. If not, *then* we reschedule the context so that it will only be picked up by the right Mercury engine. Add a comment that none of this is implemented for grades not using gcc non-local gotos (nor was it implemented before). runtime/mercury_memory_zones.c: Fix an off-by-one bug and a thread-safety bug in MR_next_offset(). |
||
|
|
cff0019b0b |
Make the system compile programs using minimal model tabling cleanly
Estimated hours taken: 10 Branches: main Make the system compile programs using minimal model tabling cleanly in .mmos grades. (They still do not work, since the .mmos grade's implementation is not yet complete.) compiler/prog_data.m: Split the eval method for own stack minimal model tabling in two: one for the consumer predicate, and one for the generator, since they have distinct properties. Add a utility predicate for use by llds_out and ml_code_gen. compiler/prog_out.m: Split the predicate for converting an eval method to a string into two: one used for debugging purposes (which must be full of information), and one used for generating the names of pragmas (which must conform to the user-level syntax). compiler/table_gen.m: Have the own stack transformation generate the proc_table_info now required to generate the variable containing the root of the call table, as well as the information describing the structure of the call and answer tables. Fix some software rot. compiler/hlds_out.m: Print out the tabling information that may be attached to proc_infos. compiler/llds_out.m: compiler/ml_code_gen.m: Factor out some common code from these modules, and move it to prog_data.m. compiler/add_pragma.m: compiler/hlds_pred.m: compiler/layout_out.m: Conform to the changes above. runtime/mercury_mm_own_stacks.[ch]: Record the name of the predicate in generator and consumer structures, for debugging purposes (they can be taken out once the system works). Record the context in each consumer. Fix a link error by providing a dummy statistics printing predicate. Fix a cut-and-paste bug (wrong macro name guarding the handwritten C module). runtime/mercury_tabling_preds.h: Implement some predicates needed by the own stack transformation. Fix some software rot. runtime/mercury_debug.c: Avoid warnings from the C compiler. runtime/mercury_context.c: runtime/mercury_engine.h: runtime/mercury_wrapper.c: Minor style fixes. runtime/mercury_stack_layout.h: trace/mercury_trace.c: trace/mercury_trace_cmd_developer.c: Conform to the splitting of the own stack eval method into two. |
||
|
|
82eab0e65e |
Add an optional pass that tries to avoid generating too many parallel goals.
Estimated hours taken: 12
Branches: main
Add an optional pass that tries to avoid generating too many parallel goals.
The first transformation implemented by this pass is to transform parallel
conjunctions into goals of the form
( queues already contain lot of work ->
sequential version of parallel conjunction
;
parallel conjunction as before
)
if they contain recursive calls.
The effect of this transformation is to reduce the overhead of the new par_fib
test case from:
fib(35): sequential 189 vs parallel 5770
to
fib(35): sequential 189 vs parallel 1090
i.e. a speedup of more than a factor of five.
compiler/granularity.m:
New module that implements this transformation. I intend to add other,
more sophisticated transformations in the future.
compiler/transform_hlds.m:
Add granularity.m as one of the submodules of transform_hlds.m.
compiler/mercury_compile.m:
Invoke the new pass.
Invoke dep_par_conj only if needed.
Fix some stage numbers.
compiler/notes/compiler_design.html:
Document the new module.
Document some modules that should have been documented earlier.
Fix a hurried deletion of a reference to the Aditi backend.
compiler/goal_util.m:
Add some utility functions for use by the new module.
compiler/simplify.m:
Record the information mercury_compile.m needs in order to check
whether we have any parallelism for granularity.m and dep_par_conj.m
to process.
compiler/hlds_module.m:
Add a slot to the module_info to record the information from
simplify.m. Clean up some interfaces.
compiler/add_type.m:
Conform to the change to hlds_module.m.
compiler/dependency_graph.m:
Delete unnecessary module qualifications, and rename some predicates
to avoid potential ambiguities.
compiler/options.m:
Add the options required for controlling the new transformation.
Rename an option's internal name to avoid conflict with a language
keyword (the user-visible name remains unchanged).
Move some options around to put them in logical groups.
doc/user_guide.texi:
Document the new options.
Fix some omissions in some earlier options.
compiler/handle_options.m:
compiler/termination.m:
Conform to the option rename.
compiler/quantification.m:
Rename some predicates to avoid ambiguities.
library/par_builtin.m:
Add a predicate for use by the new transformation.
tests/par_conj/par_fib.{m,exp}:
A new test case: a version of fib for use in testing parallelism.
tests/par_conj/Mmakefile:
Enable the new test case.
|
||
|
|
ecf1ee3117 |
Add a mechanism for growing the stacks on demand by adding new segments
Estimated hours taken: 20 Branches: main Add a mechanism for growing the stacks on demand by adding new segments to them. You can ask for the new mechanism via a new grade component, stseg (short for "stack segments"). The mechanism works by adding a test to each increment of a stack pointer (sp or maxfr). If the test indicates that we are about to run out of stack, we allocate a new stack segment, allocate a placeholder frame on the new segment, and then allocate the frame we wanted in the first place on top of the placeholder. We also override succip to make it point code that will (1) release the new segment when the newly created stack frame returns, and then (2) go to the place indicated by the original, overridden succip. For leaf procedures on the det stack, we optimize away the check of the stack pointer. We can do this because we reserve some space on each stack for the use of such stack frames. My intention is that doc/user_guide.texi and NEWS will be updated once we have used the feature ourselves for a while and it seems to be stable. runtime/mercury_grade.h: Add the new grade component. runtime/mercury_conf_param.h: Document the new grade component, and the option used to debug stack segments. runtime/mercury_context.[ch]: Add new fields to contexts to hold the list of previous segments of the det and nondet stacks. runtime/mercury_memory_zones.[ch]: Include a threshold in all zones, for use in stack segments. Set it when a zone is allocated. Restore the previous #ifdef'd out function MR_unget_zone, for use when freeing stack segments execution has fallen out of. runtime/mercury_debug.[ch]: When printing the offsets of pointers into the det and nondet stacks, print the number of the segment the pointer points into (unless it is the first, in which case we suppress this in the interest of brevity and simplicity). Make all the functions in this module take a FILE * as an input argument; don't print to stdout by default. runtime/mercury_stacks.[ch]: Modify the macros that allocate stack frames to invoke the code for adding new stack segments when we are about to run out of stack. Standardize on "nondet" over "nond" as the abbreviation referring to the nondet stack. Conform to the changes in mercury_debug.c. runtime/mercury_stack_trace.c: When traversing the stack, step over the placeholder stack frames at the bottoms of stack segments. Conform to the changes in mercury_debug.c. runtime/mercury_wrapper.[ch]: Make the default stack size small in grades that support stack segments. Standardize on "nondet" over "nond" as the abbreviation referring to the nondet stack. Conform to the changes in mercury_debug.c. runtime/mercury_memory.c: Standardize on "nondet" over "nond" as the abbreviation referring to the nondet stack. runtime/mercury_engine.[ch]: runtime/mercury_overflow.h: Standardize on "nondet" over "nond" as the abbreviation referring to the nondet stack. Convert these files to four-space indentation. runtime/mercury_minimal_model.c: trace/mercury_trace.c: trace/mercury_trace_util.c: Conform to the changes in mercury_debug.c. compiler/options.m: Add the new grade option for stack segments. compiler/compile_target_code.m: compiler/handle_options.m: Add the new grade component, and handle its exclusions with other grade components and optimizations. compiler/llds.m: Extend the incr_sp instruction to record whether the stack frame is for a leaf procedure. compiler/llds_out.m: Output the extended incr_sp instruction. compiler/proc_gen.m: Fill in the extra slot in incr_sp instructions. compiler/goal_util.m: Provide a predicate for testing whether a procedure body is a leaf. compiler/delay_slot.m: compiler/dupelim.m: compiler/dupproc.m: compiler/exprn_aux.m: compiler/frameopt.m: compiler/global_data.m: compiler/jumpopt.m: compiler/middle_rec.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/peephole.m: compiler/reassign.m: compiler/use_local_vars.m: Conform to the change in llds.m. scripts/canonicate_grade.sh-subr: scripts/init_grade_options.sh-subr: scripts/parse_grade_options.sh-subr: scripts/final_grade_options.sh-subr: scripts/mgnuc.in: Handle the new grade component. Convert parse_grade_options.sh-subr to four-space indentation. Mmake.workspace: Fix an old bug that prevented bootcheck from working in the new grade: when computing the gc grade, use the workspace's version of ml (which in this case understands the new grade components), rather than the installed ml (which does not). (This was a devil to track down, because neither make --debug nor strace on make revealed how the installed ml was being invoked, and there was no explicit invocation in the Makefile either; the error message appeared to come out of thin air just before the completion of the stage 2 library. It turned out the invocation happened implicitly, as a result of expanding a make variable.) |
||
|
|
712027f307 |
This patch changes the parallel execution mechanism in the low level backend.
Estimated hours taken: 100 Branches: main This patch changes the parallel execution mechanism in the low level backend. The main idea is that, even in programs with only moderate parallelism, we won't have enough processors to exploit it all. We should try to reduce the cost in the common case, i.e. when a parallel conjunction gets executed sequentially. This patch does two things along those lines: (1) Instead of unconditionally executing all parallel conjuncts (but the last) in separate Mercury contexts, we allow a context to continue execution of the next conjunct of a parallel conjunction if it has just finished executing the previous conjunct. This saves on allocating unnecessary contexts, which can be a big reduction in memory usage. We also try to execute conjuncts left-to-right so as to minimise the need to suspend contexts when there are dependencies between conjuncts. (2) Conjuncts that *are* executed in parallel still need separate contexts. We used to pass variable bindings to those conjuncts by flushing input variable values to stack slots and copying the procedure's stack frame to the new context. When the conjunct finished, we would copy new variable bindings back to stack slots in the original context. What happens now is that we don't do any copying back and forth. We introduce a new abstract machine register `parent_sp' which points to the location of the stack pointer at the time that a parallel conjunction began. In parallel conjuncts we refer to all stack slots via the `parent_sp' pointer, since we could be running on a different context altogether and `sp' would be pointing into a new detstack. Since parallel conjuncts now share the procedure's stack frame, we have to allocate stack slots such that all parallel conjuncts in a procedure that could be executing simultaneously have distinct sets of stack slots. We currently use the simplest possible strategy, i.e. don't allow variables in parallel conjuncts to reuse stack slots. Note: in effect parent_sp is a frame pointer which is only set for and used by the code of parallel conjuncts. We don't call it a frame pointer as it can be confused with "frame variables" which have to do with the nondet stack. compiler/code_info.m: Add functionality to keep track of how deep inside of nested parallel conjunctions the code generator is. Add functionality to acquire and release "persistent" temporary stack slots. Unlike normal temporary stack slots, these don't get implicitly released when the code generator's location-dependent state is reset. Conform to additions of `parent_sp' and parent stack variables. compiler/exprn_aux.m: Generalise the `substitute_lval_in_*' predicates by `transform_lval_in_*' predicates. Instead of performing a fixed substitution, these take a higher order predicate which performs some operation on each lval. Redefine the substitution predicates in terms of the transformation predicates. Conform to changes in `fork', `join_and_terminate' and `join_and_continue' instructions. Conform to additions of `parent_sp' and parent stack variables. Remove `substitute_rval_in_args' and `substitute_rval_in_arg' which were unused. compiler/live_vars.m: Introduce a new type `parallel_stackvars' which is threaded through `build_live_sets_in_goal'. We accumulate the sets of variables which are assigned stack slots in each parallel conjunct. At the end of processing a parallel conjunction, use this information to force variables which are assigned stack slots to have distinct slots. compiler/llds.m: Change the semantics of the `fork' instruction. It now takes a single argument: the label of the next conjunct after the current one. The instruction now "sparks" the next conjunct to be run, either in a different context (possibly in parallel, on another Mercury engine) or is queued to be executed in the current context after the current conjunct is finished. Change the semantics of the `join_and_continue' instruction. This instruction now serves to end all parallel conjuncts, not just the last one in a parallel conjunction. Remove the `join_and_terminate' instruction (no longer used). Add the new abstract machine register `parent_sp'. Introduce "parent stack slots", which are similar to normal stack slots but relative to the `parent_sp' register. compiler/par_conj_gen.m: Change the code generated for parallel conjunctions. That is: - use the new `fork' instruction at the beginning of a parallel conjunct; - use the `join_and_continue' instruction at the end of all parallel conjuncts; - keep track of how deep the code generator currently is in parallel conjunctions; - set and restore the `parent_sp' register when entering a non-nested parallel conjunction; - after generating the code of a parallel conjunct, replace all references to stack slots by parent stack slots; - remove code to copy back output variables when a parallel conjunct finishes. Update some comments. runtime/mercury_context.c: runtime/mercury_context.h: Add the type `MR_Spark'. Sparks are allocated on the heap and contain enough information to begin execution of a single parallel conjunct. Add globals `MR_spark_queue_head' and `MR_spark_queue_tail'. These are pointers to the start and end of a global queue of sparks. Idle engines can pick up work from this queue in the same way that they can pick up work from the global context queue (the "run queue"). Add new fields to the MR_Context structure. `MR_ctxt_parent_sp' is a saved copy of the `parent_sp' register for when the context is suspended. `MR_ctxt_spark_stack' is a stack of sparks that we decided not to put on the global spark queue. Update `MR_load_context' and `MR_save_context' to save and restore `MR_ctxt_parent_sp'. Add the counters `MR_num_idle_engines' and `MR_num_outstanding_contexts_and_sparks'. These are used to decide, when a `fork' instruction is reached, whether a spark should be put on the global spark queue (with potential for parallelism but also more overhead) or on the calling context's spark stack (no parallelism and less overhead). Rename `MR_init_context' to `MR_init_context_maybe_generator'. When initialising contexts, don't reset redzones of already allocated stacks. It seems to be unnecessary (and the reset implementation is buggy anyway, though it's fine on Linux). Rename `MR_schedule' to `MR_schedule_context'. Add new functions `MR_schedule_spark_globally' and `MR_schedule_spark_locally'. In `MR_do_runnext', add code for idle engines to get work from the global spark queue. Resuming contexts are prioritised over sparks. Rename `MR_fork_new_context' to `MR_fork_new_child'. Change the definitions of `MR_fork_new_child' and `MR_join_and_continue' as per the new behaviour of the `fork' and `join_and_continue' instructions. Delete `MR_join_and_terminate'. Add a new field `MR_st_orig_context' to the MR_SyncTerm structure to record which context originated the parallel conjunction instance represented by a MR_SyncTerm instance, and update `MR_init_sync_term'. This is needed by the new behaviour of `MR_join_and_continue'. Update some comments. runtime/mercury_engine.h: runtime/mercury_regs.c: runtime/mercury_regs.h: runtime/mercury_stacks.h: Add the abstract machine register `parent_sp' and code to copy it to and from the fake_reg array. Add a macro `MR_parent_sv' to access stack slots via `parent_sp'. Add `MR_eng_parent_sp' to the MercuryEngine structure. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Add Mercury runtime option `--max-contexts-per-thread' which is saved in the global variable `MR_max_contexts_per_thread'. The number `MR_max_outstanding_contexts' is derived from this. It sets a soft limit on the number of sparks we put in the global spark queue, relative to the number of threads we are running. We don't want to put too many sparks on the global queue if there are plenty of ready contexts or sparks already on the global queues, as they are likely to result in new contexts being allocated. When initially creating worker engines, wait until all the worker engines have acknowledged that they are idle before continuing. This is mainly so programs (especially benchmarks and test cases) with only a few fork instructions near the beginning of the program don't execute the forks before any worker engines are ready, resulting in no parallelism. runtime/mercury_engine.c: runtime/mercury_thread.c: Don't allocate a context at the time a Mercury engine is created. An engine only needs a new context when it is about to pick up a spark. configure.in: compiler/options.m: scripts/Mercury.config.in: Update to reflect the extra field in MR_SyncTerm. Add the option `--sync-term-size' and actually make use the result of the sync term size calculated during configuration. compiler/code_util.m: compiler/continuation_info.m: compiler/dupelim.m: compiler/dupproc.m: compiler/global_data.m: compiler/hlds_llds.m: compiler/jumpopt.m: compiler/livemap.m: compiler/llds_out.m: compiler/middle_rec.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/reassign.m: compiler/stack_layout.m: compiler/use_local_vars.m: compiler/var_locn.m: Conform to changes in `fork', `join_and_terminate' and `join_and_continue' instructions. Conform to additions of `parent_sp' and parent stack variables. XXX not sure about the changes in stack_layout.m library/par_builtin.m: Conform to changes in the runtime system. |
||
|
|
19a9967641 |
Replace the three lines of output after every label to support
Estimated hours taken: 0.5 Branches: main compiler/llds_out.m: Replace the three lines of output after every label to support `--local-thread-engine-base' by a macro call to MR_MAYBE_INIT_LOCAL_THREAD_ENGINE_BASE. runtime/mercury_engine.h: #define MR_MAYBE_INIT_LOCAL_THREAD_ENGINE_BASE. |
||
|
|
0988d4919d |
In low-level, parallel grades which don't use gcc global registers, each
Estimated hours taken: 6 Branches: main In low-level, parallel grades which don't use gcc global registers, each reference to a Mercury register (etc.) references a thread-specific Mercury engine base address `MR_thread_engine_base'. This is either a thread-specific variable or a call to pthread_getspecific(). This patch improves performance in these grades by copying `MR_thread_engine_base' once at the start of each basic block into a local variable, then using the local copy for the rest of the basic block. compiler/options.m: doc/user_guide.texi: Add `--local-thread-engine-base' option, enabled by default. compiler/llds_out.m: When `--local-thread-enabled-base' is enabled, emit code to redefine `MR_maybe_local_thread_engine_base' to `MR_local_thread_engine_base' before the code of a procedure, and undo it afterwards. After each label instruction initialise a local variable `MR_local_thread_engine_base' with a copy of `MR_thread_engine_base'. runtime/mercury_engine.h: If gcc global registers are not used then #define `MR_engine_base' in terms of `MR_maybe_local_thread_engine_base', and initially #define `MR_maybe_local_thread_engine_base' to `MR_thread_engine_base'. |
||
|
|
61a6cc518e |
When possible, make use of the gcc `__thread' extension for introducing
Estimated hours taken: 5 Branches: main When possible, make use of the gcc `__thread' extension for introducing thread-local variables. Currently we use the POSIX thread facility for storing the address of the Mercury engine that is running on the current thread, i.e. pthread_getspecific/pthread_setspecific. If gcc global registers are not used, then each access of a Mercury register incurs a call to `pthread_getspecific'. Using the `__thread' extension is very much faster. (If gcc global registers are used then the address of the Mercury engine is kept in a hardward register.) configure.in: Check if compiler has the `__thread' extension. runtime/mercury_conf.h.in: #define MR_THREAD_LOCAL_STORAGE if `__thread' can be used. runtime/mercury_context.c: runtime/mercury_engine.h: runtime/mercury_thread.c: Make `MR_thread_engine_base' a thread-local variable if possible, instead of using pthread_getspecific(). #define MR_set_thread_engine_base() to hide the differences between when `__thread' is used or not. |
||
|
|
575ef85fb6 |
Fix some typos in the runtime that broke the ODBC binding.
Estimated hours taken: 0.5 Branches: main Fix some typos in the runtime that broke the ODBC binding. runtime/mercury_engine.h: Delete extraneous '\'s introduced when this module was converted to four-space indentation. |
||
|
|
1ed891b7b1 |
Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main
Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").
While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.
The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.
compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
Handle the new grade component.
runtime/mercury_memory_zones.h:
Add MR_ prefixes to the names of the fields of the zone structure.
Record not just the actual size of each zone, which includes various
kinds of buffers, but also the desired size of the zone exclusive of
buffers.
Format the documentation of the zone structure fields more
comprehensibly.
runtime/mercury_memory_zones.c:
Instead of implementing memalign if it is not provided by the operating
system, implement a function that allows us to reallocate the returned
area of memory.
Provide a prototype implementation of memory zone extension. It doesn't
work yet.
Factor out the code for setting up redzones, since it is now needed
in more than place.
Convert to four space indentation.
Make the debugging functions a bit more flexible.
runtime/mercury_wrapper.c:
Conform to the improved interface of the debugging functions.
runtime/mercury_overflow.h:
runtime/mercury_std.h:
Move a generally useful macro from mercury_overflow.h to mercury_std.h.
runtime/mercury_stacks.c:
Add functions to extend the stacks.
runtime/mercury_stacks.h:
Add the tests required to invoke the functions that extend the stacks.
Add the macros needed by the change to compiler/llds.m.
Convert to four space indentation.
runtime/mercury_conf.h.in:
Prepare for the use of the posix_memalign function, which is the
current replacement of the obsolete memalign library function.
We don't yet use it.
runtime/mercury_context.h:
Format the documentation of the context structure fields more
comprehensibly.
Put MR_ prefixes on the names of the fields of some structures
that didn't previously have them.
Conform to the new names of the fields of the zone structure.
runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
Conform to the new names of the fields of the zone structure.
In some cases, add missing MR_ prefixes to function names
and/or convert to four space indentation.
runtime/mercury_engine.h:
Add a new low level debug flag for debugging stack extensions.
Format the documentation of the engine structure fields more
comprehensibly.
Convert to four space indentation.
runtime/mercury_conf_param.h:
Document a new low level debug flag for debugging stack extensions.
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
Handle the new grade component.
compiler/llds.m:
Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
These are needed because the nondet stack may be relocated between
saving and the restoring of maxfr, and the saved maxfr may point to
the old stack. In .exts grades, these instructions will save not a
pointer but the offset of maxfr from the start of the nondet stack,
since offsets are not affected by the movement of the nondet stack.
compiler/code_info.m:
Use the new instructions where relevant. (Some more work may be
needed on this score; the relevant places are marked with XXX.)
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
Handle the new LLDS instructions.
tools/bootcheck:
Provide a mechanism for setting the initial stack sizes for a
bootcheck.
|
||
|
|
e854a5f9d9 |
Major improvements to tabling, of two types.
Estimated hours taken: 32
Branches: main
Major improvements to tabling, of two types. The first is the implementation
of the loopcheck and memo forms of tabling for model_non procedures, and the
second is a start on the implementation of a new method of implementing
minimal model tabling, one that has the potential for a proper fix of the
problem that we currently merely detect with the pneg stack (the detection
is followed by a runtime abort). Since this new method relies on giving each
own generator its own stack, the grade component denoting it is "mmos"
(minimal model own stack). The true name of the existing method is changed
from "mm" to "mmsc" (minimal model stack copy). The grade component "mm"
is now a shorthand for "mmsc"; when the new method works, "mm" will be changed
to be a shorthand for "mmos".
configure.in:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
compiler/options.m:
Handle the new way of handling minimal model grades.
scripts/mgnuc.in:
compiler/compile_target_code.m:
Conform to the changes in minimal model grade options.
compiler/table_gen.m:
Implement the transformations required by the loopcheck and memo
tabling of model_non procedures, and the minimal model own stack
transformation.
The new implementation transformations use foreign_procs with extra
args, since there is no point in implementing them both that way and
with separate calls to library predicates. This required making the
choice of which method to use at the top level of each transformation.
Fix an oversight that hasn't caused problems yet but may in the future:
mark goals wrapping the original goals as not impure for determinism
computations.
compiler/handle_options.m:
Handle the new arrangement of the options for minimal model tabling.
Detect simultaneous calls for both forms of minimal model tabling,
and generate an error message. Allow for more than one error message
generated at once; report them all once rather than separately.
compiler/globals.m:
Add a mechanism to allow a fix a problem detected by the changes
to handle_options: the fact that we currently may generate a usage
message more than once for invocations with more than one error.
compiler/mercury_compile.m:
compiler/make.program_target.m:
compiler/make.util.m:
Use the new mechanism in handle_options to avoid generating duplicate
usage messages.
compiler/error_util.m:
Add a utility predicate for use by handle_options.
compiler/hlds_pred.m:
Allow memo tabling for model_non predicates, and handle own stack
tabling.
compiler/hlds_out.m:
Print information about the modes of the arguments of foreign_procs,
since this is useful in debugging transformations such as tabling
that generate them.
compiler/prog_data.m:
compiler/layout_out.m:
compiler/prog_out.m:
runtime/mercury_stack_layout.h:
Mention the new evaluation method.
compiler/goal_util.m:
Change the predicates for creating calls and foreign_procs to allow
more than one goal feature to be attached to the new goal. table_gen.m
now uses this capability.
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/typecheck.m:
compiler/unify_proc.m:
Conform to the changes in goal_util.
compiler/code_info.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
Conform to the new the options controlling minimal model
tabling.
compiler/prog_util.m:
Add a utility predicate for use by table_gen.m.
library/std_util.m:
Conform to the changes in the macros for minimal model tabling grades.
library/table_builtin.m:
Add the types and predicates required by the new transformations.
Delete an obsolete comment.
runtime/mercury_grade.h:
Handle the new minimal model grade component.
runtime/mercury_conf_param.h:
List macros controlling minimal model grades.
runtime/mercury_tabling.[ch]:
Define the types needed by the new transformations,
Implement the performance-critical predicates that need to be
hand-written for memo tabling of model_non predicates.
Add utility predicates for debugging.
runtime/mercury_tabling_preds.h:
Add the implementations of the predicates required by the new
transformations.
runtime/mercury_mm_own_stacks.[ch]:
This new module contains the first draft of the implementation
of the own stack implementation of minimal model tabling.
runtime/mercury_imp.h:
Include the new file if the grade needs it.
runtime/Mmakefile:
Mention the new files, and sort the lists of filenames.
runtime/mercury_tabling_macros.h:
Add a macro for allocating answer blocks without requiring them to be
pointed to directly by trie nodes.
runtime/mercury_minimal_model.[ch]:
The structure type holding answer lists is now in mercury_tabling.h,
since it is now also needed by memo tabling of model_non predicates.
It no longer has a field for an answer num, because while it is ok
to require a separate grade for debugging minimal model tabling,
it is not ok to require a separate grade for debugging memo tabling
of model_non predicates. Instead of printing the answer numbers,
print the answers themselves when we need to identify solutions
for debugging.
Change function names, macro names, error messages etc where this is
useful to distinguish the two kinds of minimal model tabling.
Fix some oversights wrt transient registers.
runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_memory.[ch]:
runtime/mercury_wrapper.[ch]:
With own stack tabling, each subgoal has its own context, so record
the identity of the subgoal owning a context in the context itself.
The main computation's context is the exception: it has no owner.
Record not just the main context, but also the contexts of subgoals
in the engine.
Add variables for holding the sizes of the det and nondet stacks
of the contexts of subgoals (which should in general be smaller
than the sizes of the corresponding stacks of the main context),
and initialize them as needed.
Initialize the variables holding the sizes of the gen, cut and pneg
stacks, even in grades where the stacks are not used, for safety.
Fix some out-of-date documentation, and conform to our coding
guidelines.
runtime/mercury_memory_zones.[ch]:
Add a function to test whether a pointer is in a zone, to help
debugging.
runtime/mercury_debug.[ch]:
Add some functions to help debugging in the presence of multiple
contexts, and factor out some common code to help with this.
Delete the obsolete, unused function MR_printdetslot_as_label.
runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
Move a bootstrapping #define from mercury_context.h to
mercury_bootstrap.h.
runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
Move a bootstrapping #define from mercury_context.h to
mercury_bootstrap.h.
runtime/mercury_types.h:
Add some more forward declarations of type names.
runtime/mercury_dlist.[ch]:
Rename a field to avoid assignments that dereference NULL.
runtime/mercury_debug.c:
runtime/mercury_memory.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_stacks.[ch]:
trace/mercury_trace_util.c
Update uses of the macros that control minimal model tabling.
runtime/mercury_stack_trace.c:
Provide a mechanism to allow stack traces to be suppressed entirely.
The intention is that by using this mechanism, by the testing system
won't have to provide separate .exp files for hlc grades, nondebug
LLDS grades and debug LLDS grades, as we do currently. The mechanism
is the environment variable MERCURY_SUPPRESS_STACK_TRACE.
tools/bootcheck:
tools/test_mercury:
Specify MERCURY_SUPPRESS_STACK_TRACE.
trace/mercury_trace.c:
When performing retries across tabled calls, handle memo tabled
model_non predicates, for which the call table tip variable holds
a record with a back pointer to a trie node, instead of the trie node
itself.
trace/mercury_trace_internal.c:
When printing tables, handle memo tabled model_non predicates. Delete
the code now moved to runtime/mercury_tabling.c.
Add functions for printing the data structures for own stack minimal
model tabling.
tests/debugger/print_table.{m,inp,exp}:
Update this test case to also test the printing of tables for
memo tabled model_non predicates.
tests/debugger/retry.{m,inp,exp}:
Update this test case to also test retries across memo tabled
model_non predicates.
tests/tabling/loopcheck_nondet.{m,exp}:
tests/tabling/loopcheck_nondet_non_loop.{m,exp}:
New test cases to test loopcheck tabled model_non predicates.
One test case has a loop to detect, one doesn't.
tests/tabling/memo_non.{m,exp}:
tests/tabling/tc_memo.{m,exp}:
tests/tabling/tc_memo2.{m,exp}:
New test cases to test memo tabled model_non predicates.
One test case has a loop to detect, one has a need for minimal model
tabling to detect, and the third doesn't have either.
tests/tabling/Mmakefile:
Add the new test cases, and reenable the existing tc_loop test case.
Rename some make variables and targets to make them better reflect
their meaning.
tests/tabling/test_mercury:
Conform to the change in the name of the make target.
|
||
|
|
8190c16181 |
Get Mercury to work with gcc 3.4. This required fixing several problems.
Estimated hours taken: 16 Branches: main Get Mercury to work with gcc 3.4. This required fixing several problems. One problem that caused errors is that gcc 3.4 is smart enough to figure out that in LLDS grades with gcc gotos, the C functions containing our code are not referred to, and so it optimizes them away. The fix is to ensure that mercury_<module>_init is defined always to call those functions, even if the macro that usually controls this, MR_MAY_NEED_INITIALIZATION, is not defined. The mercury_<module>_init won't be called from the init_modules function in the program's _init.c file, so there is no impact on initialization time, but gcc doesn't know this when compiling a module's .c file, so it doesn't optimize away the code we need. The cost of this change is thus only a small amount of code space. It is worth paying this cost even with compilers other than gcc 3.4 for simplicity. Actually, this size increase seems to be slightly smaller than the size reduction due to the better optimization capabilities of gcc 3.4 compared to gcc 3.2.2. A second problem is that gcc 3.4 warns about casts in lvalues being a deprecated feature. This gave lots of warnings, since we used to define several Mercury abstract machine registers, including MR_succip, MR_hp, MR_sp, MR_maxfr and MR_curfr using lvalue casts. The fix is to have two macros for each of these abstract machine registers, one of type MR_Word that you can assign to (e.g. MR_sp_word), and one of the original type that is of the right type but not an lvalue (e.g. MR_sp). The lvalue itself can't be made the right type, because MR_sp isn't a variable in its own right, but possibly defined to be a machine register. The machine register could made the right type, but only at the cost of a lot of complexity. This problem doesn't apply to the special-purpose Mercury abstract machine registers that can't be allocated to machine registers. Instead of #defining these to slots in MR_fake_reg, we make them global variables of the natural type. This should also make it easier to debug code using these registers. We treat these global variables as if they were machine registers in that MR_save_registers copies values from these global variables to slots reserved for them in the MR_fake_reg array, to allow code to loop over all Mercury abstract machine registers. These saved slots must of course be of type MR_Word, so we again need two macros to refer to them, a lvalue of type MR_Word and an rvalue with the right type. A third problem is that gcc 3.4 warns about conditionals in lvalues being a deprecated feature. This gave a few warnings, since we used to define MR_virtual_reg and MR_saved_reg using lvalues using conditionals. The fix is to have one macro (MR_virtual_reg_value) for use in rvalues and a separate macro which uses an if-then-else instead of a conditional expression (MR_virtual_reg_assign), for assignments. A fourth problem is that gcc 3.4 warns about comma operators in lvalues being a deprecated feature. This gave warnings in the few places where we refer to MR_r(N) for values of N that can map to fake registers directly, since in those cases we preceded the reference to the fake_reg array with a range check of the array index. The fix to this is to move the test to compile time for compiler-generated code. Hand-written code never refers to MR_r(N) for these values, and is very unlikely to do so in the future; instead, it refers to the underlying fake_reg array directly, since that way it doesn't have to worry about which fake registers have their own MR_rN macro and which don't. Therefore no check mechanism for hand-written code is necessary. This change mean that changing the number of MR_rN registers now requires change to the compiler as well as to the runtime system. A fifth problem is that gcc 3.4 by default assumes -fstrict-aliasing at -O2. Since we cast between integers and pointers of different types all the time, and changing that is not practical, at least in the short term, we need to disable -fstrict-aliasing when we enable -O2. NEWS: Note that Mercury now works with gcc 3.4. configure.in: scripts/mgnuc.in: Detect whether the compiler supports -fstrict-aliasing, and if so, whether it assumes it by default with -O2. If the answer is yes to both, make mgnuc specify -fno-strict-aliasing when it specifies -O2. By including it in CFLAGS_FOR_OPT, which gets put into Mercury.config, we also get -f-no-strict-aliasing when mmc invokes the C compiler directly. compiler/llds_out.m: Don't generate #ifdef MR_MAY_NEED_INITIALIZATION around the definitions and calls to the bunch functions, which call the functions we don't want the C compiler to optimize away. Generate the newly required lvalues on the left sides of assignments. We still have code to generate LVALUE_CASTs in some cases, but I don't think those cases ever arise. Add a compile-time check of register numbers. Ideally, the code generator should use stack slots instead of registers beyond the max number, but I don't recall us ever bumping into this limit by accident. compiler/fact_table.m: Use the newly required lvalues on the left sides of assignments in some hand-written C code included in generated .c files. runtime/mercury_regs.h: Make the changes described above to fix the second, third and fourth problems. We still use comma operators in lvalues when counting references to registers, but it is OK to require anyone who wants to enable this feature to use a compiler version that supports comma operators in lvalues or to ignore the warnings. Use the same mapping from Mercury abstract machine registers to the register count array as to the MR_fake_reg array. Have this mapping depend as little as possible on whether we need a real machine register to store MR_engine base, even if it costs a wasted slot in MR_fake_reg. Fix an old inconsistency: treat the Mercury abstract machine registers used for trailing the same way as the other Mercury abstract machine registers, by making MR_save_registers/MR_restore_registers copy them to and from their global variable homes. Document the requirement for the match between the runtime's and the compiler's notions of the maximum MR_rN register number. This requirement makes it harder for users to increase the number of virtual registers, but as far as I know noone has wanted to do this. Change the names of some of the macros to make them clearer. Reorder some parts of this file, and add some documentation, also in the interest of clarity. runtime/mercury_regorder.h: Delete this file after moving its contents, in much modified form, to mercury_regs.h. mercury_regorder.h was always logically part of mercury_regs.h, but was separated out to make it easier to change the mapping from Mercury abstract machine registers to machine registers. However, the cost of incompatibility caused by any such changes would be much greater that any likely performance benefit. runtime/Mmakefile: Remove the reference to mercury_regorder.h. runtime/mercury_regs.[ch]: runtime/mercury_memory_zones.[ch]: Move some functionality dealing with registers from mercury_memory_zones to mercury_regs, since it belongs there. runtime/mercury_regs.[ch]: Add a function to make it easiler to debug changes to map from Mercury abstract machine to MR_fake_reg slots. runtime/mercury_regs.[ch]: runtime/mercury_wrapper.c: Move the code to print counts of register uses from mercury_wrapper.c to mercury_regs.c. Make mercury_wrapper.c call the debugging function in mercury_regs.c if -X is specified in MERCURY_OPTIONS. runtime/mercury_bootstrap.h: Move the old MR_saved_reg and MR_virtual_reg macros from mercury_regs.h to mercury_bootstrap.h to prevent their accidental use. Since they shouldn't be used by user code, move them to the section that is not enabled by default. runtime/mercury_stacks.[ch]: Add _word versions of the macros for stack slots, for the same reason why we need them for Mercury abstract machine registers, and use them. Add global variables for the Mercury abstract machine registers for the gen, cut and pneg stacks. runtime/mercury_heap.h: Change the macros for allocating memory to assign to MR_hp_word instead of MR_hp. runtime/mercury_string.h: Change the macros for allocating strings to accomodate the updates to mercury_heap.h. Also change the expected type of the target to make it MR_String instead of MR_ConstString, since the latter requires casts in the caller. runtime/mercury_trail.h: runtime/mercury_types.h: Move the definition of the type MR_TrailEntry from mercury_trail.h to mercury_types.h, since it is now used in mercury_regs.h. runtime/mercury_accurate_gc.c: runtime/mercury_agc_debug.c: runtime/mercury_calls.h: runtime/mercury_context.[ch]: runtime/mercury_deconstruct_macros.h: runtime/mercury_deep_copy_body.h: runtime/mercury_engine.[ch]: runtime/mercury_hand_compare_body.h: runtime/mercury_hand_unify_body.h: runtime/mercury_ho_call.c: runtime/mercury_layout_util.c: runtime/mercury_make_type_info_body.h: runtime/mercury_minimal_model.c: runtime/mercury_ml_deconstruct_body.h: runtime/mercury_ml_functor_body.h: runtime/mercury_stack_layout.h: runtime/mercury_type_desc.c: runtime/mercury_type_info.c: runtime/mercury_unify_compare_body.h: runtime/mercury_wrapper.c: Conform to the changes in the rest of the runtime. In some cases, fix inconsistencies in indentation. runtime/mercury_stack_trace.c: Add some conditionally compiled debugging code controlled by the macro MR_ADDR_DEBUG, to help debug some problems with stored stack pointers. runtime/mercury_grade.h: Increment the binary compatibility version number. This is needed to avoid potential problems when a Mercury module and the debugger are compiled with different versions of the macros in mercury_regs.h. library/exception.m: Update the code that assigns to abstract machine registers. library/array.m: library/construct.m: library/dir.m: library/io.m: library/string.m: Conform to the new definitions of allocation macros. library/time.m: Delete an unnecessary #include. trace/mercury_trace.c: trace/mercury_trace_declarative.c: trace/mercury_trace_util.c: Conform to the changes in the rest of the runtime. tests/hard_coded/qual_test_is_imported.m: tests/hard_coded/aditi_private_builtin.m: Remove an unnecessary import to avoid a warning. tools/makebatch: Add an option --save-stage2-on-error, that saves the stage2 directory if a bootcheck fails. scripts/ml.in: Make ml more robust in the face of garbage files. |
||
|
|
c80d143cc8 |
The following change is only 98% complete, not 100%.
Estimated hours taken: 120
Branches: main
The following change is only 98% complete, not 100%. I am committing it in
this state because (1) we pass many more test cases in deep profiling grade
with it than without it, and (2) the double maintanance involved in fixing
CVS conflicts is preventing me from doing the last 2%.
Get the deep profiler to work for code that sets up to catch exceptions,
which for the last year or more has included the compiler, and to get it
almost working for code that actually catching exceptions.
The basic problem is that code that throws exceptions will in general cause
several calls to "return" without executing the exit or fail port codes that
the deep profiling transformation inserted into their bodies, and this leaves
the data structure being built by the deep profiling inconsistent. The solution
uses the same approach as we have adopted for the debugger: have the code that
handles the throwing of exceptions simulate a return from each call between
the throw and the catch, updating the deep profiling data structures as needed.
This requires us to be able to walk the stack at runtime not just in debugging
grades but also in deep profiling grades. Since the debugger already has the
mechanisms required for this, we reuse them. The procedure layouts used by the
debugger were designed to have three segments: the procedure stack walk
information, the procedure id, and the execution tracing information. We now
modify this design to make the third segment contain two pointers: to the
execution tracing information (for use by the debugger), and to the procedure's
proc_static structure (for use by deep profiling). Each pointer will be null
unless the pointed-to structure is required by compile-time options.
This common use by the debugger and by deep profiling of the stack-walk
structure and the procedure id structure (which deep profiling used to
generate independently and possibly redundantly) required some rearrangement
of the compiler's version of these data structures.
To make this rearrangement simpler, this diff removes a capability that
we theoretically supported but never used: turning on stack traces without
turning on execution tracing and vice versa. After this diff, stack tracing
is enabled if and only if either execution tracing or deep profiling is
enabled.
The diff also includes improvements in the debugging infrastructure for
debugging deep profiling, which were necessary for the implementation of the
rest of the changes.
compiler/deep_profiling.m:
The code in exception.m needs to know the locations of the variables
that we would pass to the exit or fail port code, so it can simulate
leaving the procedure invocation through the exception port. Without
this information, throwing an exception leaves the deep profiling
data structures of the procedure invocations between throw and catch
in an inconsistent state.
Deep_profiling.m creates these variables, but it doesn't know where
they will be at runtime, so it records their identities; the code
generator will allocate them stack slots and record the numbers of
these stack slots for placement in the now expanded proc layout
structures. Deep profiling used to generate static data structures
separately from the HLDS, but since the code generator now needs
access to them, we store their information in proc_infos in the HLDS.
Instead of passing the addresses of proc_static structures to the deep
profiling port procedures, pass the address of proc_layout structures,
since the information about the identities of procedures are now stored
not in the proc_static structure, but in the proc_layout structure
that points to the proc_static structure.
compiler/hlds_pred.m:
compiler/layout.m:
Move the definitions of the static data structures generated by deep
profiling from layout.m to hlds_pred.m, to allow deep_profiling.m
to store them in proc_infos.
compiler/hlds_pred.m:
compiler/rtti.m:
Move the definition of rtti_proc_label from rtti.m to hlds_pred.m,
since some of the new data structures in hlds_pred.m need it. Despite
its name, the rtti_proc_label type doesn't contain any info that
doesn't belong in the HLDS.
Add some information to the rtti_proc_label type that is now needed
by deep profiling, e.g. record determinisms instead of just code
models. Record explicitly the outcome of some tests that used to be
duplicated in more than one place in the compiler, e.g. for whether
the procedure (as opposed to the predicate) is imported. Change some
of the field names to be more precise about the field's meaning.
compiler/code_gen.m:
Transmit the contents of the deep profiling data structures stored in
the proc_info by deep_profiling.m to continuation_info.m, together
with the layout structures created for execution tracing and the
identities of the variables needed for handling exceptions,
when code generation for a procedure is complete.
After the goal that generates these variables, save them to stack
for use by the exception handler.
compiler/hlds_goal.m:
Add a feature to mark the goal that generates the deep profiling
variables needed by the exception handler.
compiler/hlds_llds.m:
Add a utility predicate for new code in code_gen.m
compiler/continuation_info.m:
Hold the deep profiling information computed by code_gen.m for use by
stack_layout.m.
compiler/layout.m:
compiler/layout_out.m:
Update the definitions of the data structures describing procedure
layouts, and the code writing them out, to reflect the use of some
parts of procedure layouts by deep profiling as well as debugging.
Change the layout structures generated by deep profiling to use
rtti_proc_labels, which are backend independent, instead of
proc_labels, which are specific to the LLDS backend.
Conform to the changes in runtime/mercury_stack_layout.h.
compiler/stack_layout.m:
Generate the updated version of proc_layout structures.
compiler/mercury_compile.m:
compiler/global_data.m:
Conform to the fact that deep profiling no longer generates layout
structures separate from proc_infos.
compiler/llds_out.m:
Register proc_layout structures instead of proc_static structures
for use by runtime/mercury_deep_profiling.c.
compiler/options.m:
compiler/handle_options.m:
Rename the require_tracing option as exec_trace, since this more
directly reflects its meaning.
Instead of having --debug set both require_tracing and stack_trace,
make it set (be the user-visible name of) just exec_trace;
the value of stack_trace is implied.
Turn off the specialization of deep profiling for self-tail-recursive
procedures for now. Due to the changes made by this diff in the data
structures involved in debugging, it cannot be debugged until this
change has been installed. Handling the full language is more important
than a specialization that reduces only stack space overheads, not
runtime overheads.
compiler/compile_target_code.m:
Conform to the changes in options.m and runtime/mercury_grade.h.
compiler/hlds_data.m:
Replace the deep_profiling_proc_static cons_id, and its associated tag,
to deep_profiling_proc_layout, since we now generate addresses of proc
layout structures, not of proc_static structures.
compiler/code_util.m:
Simplify some code based on the new info in rtti_proc_labels.
compiler/bytecode_gen.m:
compiler/dependency_graph.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/proc_label.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/switch_util.m:
compiler/unify_gen.m:
Minor changes to conform to the change from deep_profiling_proc_static
to deep_profiling_proc_layout, to the change in the structure of
rtti_proc_labels, to the changes in types of layout.m, and/or to the
new goal feature.
deep_profiler/measurements.m:
Reserve space for exception counts.
deep_profiler/html_format.m:
Add a column for exception counts.
deep_profiler/profile.m:
deep_profiler/read_profile.m:
Rename the data structures referring to compiler generated unify,
compare and index predicates to avoid misleading names: they are
not the only compiler generated predicates.
deep_profiler/read_profile.m:
runtime/mercury_deep_profiling.c:
Update the string that identifies deep profiling data files.
This is necessary because the format has changed: it now includes
information about exception port counts.
library/exception.m:
In deep profiling grades, execute the exception port code for every
procedure invocation between a throw and a catch, using the procedure
layout structures now generated by the compiler for every procedure.
Rename the function involved to reflect its new, more general purpose.
Update the definitions of the hand-written proc_static and proc_layout
structures for the procedures implemented via hand-written C code.
Indent C preprocessor directives and foreign_procs according to our
coding standards.
library/profiling_builtin.m:
Change the parameters of the call port code procedures from proc_static
to proc_layout. Reach the proc_static structure from the proc_layout
structure when needed. Include the proc_layout structure in any
messages from assertion failures.
Add some conditionally compiled debugging code.
Give some variables better names.
runtime/mercury_type_info.h:
runtime/mercury_builtin_types.c:
Move the macros required to create the proc_static structures
of unify and compare predicates from mercury_type_info.h
to mercury_builtin_types.c, since the latter is the only file
that needs them.
Use the same macros for creating the proc_static structures
of hand-written unify, compare and compare_reprentation predicates
as for user defined predicates. This required changing their naming
scheme.
runtime/mercury_unify_compare_body.h:
Conform to the new naming scheme.
runtime/mercury_ho_call.c:
Provide the mechanism for mercury_unify_compare_body.h to conform
to the new naming scheme.
Remove the definitions of the proc_static structures for
hand-written unify, compare and compare_reprentation predicates,
since these now have to be defined together with the corresponding
proc_layout structures in mercury_builtin_types.c.
runtime/mercury_builtin_types.[ch]:
Update the definitions of the hand-written proc_static and proc_layout
structures for the procedures implemented via hand-written C code,
and add the required declarations first.
Handle deep profiling of compare_representation as well as unify
and compare predicates on builtin types.
Handle deep profiling of compare_representation on user-defined types,
since this is done entirely in the runtime, not by compiler generated
predicates.
runtime/mercury_builtin_types_proc_layouts.h:
New header file containing the declarations of the proc layout
structures of the unify, compare and index predicates of builtin types.
Logically, these declarations belong in mercury_builtin_types.h,
but putting them there causes problems for the linker; the details
are explained in the file itself.
runtime/Mmakefile:
Add the new header file.
runtime/mercury_minimal_model.[ch]:
Update the definitions of the hand-written proc_static and proc_layout
structures for the procedures implemented via hand-written C code,
and add the required declarations first.
runtime/mercury_grade.h:
Replace the MR_REQUIRE_TRACING grade option with MR_EXEC_TRACING.
Besides being better named, the MR_EXEC_TRACING option implies
MR_STACK_TRACE.
Besides the overall binary compatibility version number, add subsidiary
version numbers for binary compatibility in deep profiling and
debugging grades. These will make it easier to bootstrap changes
(such as this) that affect binary compatibility only in such grades.
runtime/mercury_trace_base.c:
trace/mercury_trace.c:
Conform to the new names of the configuration parameters.
runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_unify_compare_body.h:
runtime/mercury_ho_call.c:
tools/make_port_code:
Pass proc_layout structures instead of proc_static structures
to deep profiling port routines.
runtime/mercury_conf_param.h:
Make MR_DEEP_PROFILING as well as MR_EXEC_TRACING imply MR_STACK_TRACE,
since deep profiling now needs stack tracing. (MR_STACK_TRACE needs
to be set in this file, because tests in this file depend on knowing
its value, and this file is among the first files included (in this
case indirectly) in mercury_imp.h.)
Document the macros controlling the debugging of deep profiling.
Enable printing of label names when the relevant deep profiling
debugging macro is set.
runtime/mercury_debug.c:
runtime/mercury_deep_rec_depth_actions.h:
runtime/mercury_deep_rec_depth_body.h:
runtime/mercury_exception_catch_body.h:
Get to proc_statics via proc_layouts.
runtime/mercury_deep_call_port_body.c:
runtime/mercury_deep_leave_port_body.c:
Get to proc_statics via proc_layouts.
Allow the debugger to disable deep profiling in Mercury code that is
part of the debugger, not of the user program being executed.
Add some more assertions.
runtime/mercury_engine.[ch]:
Add a new debugging flag that controls at runtime whether we generate
a human readable Deep.debug equivalent to the binary Deep.data files.
(We already had a mechanism for controlling this at compile time,
but this isn't flexible enough.)
runtime/mercury_wrapper.c:
Allow this new debugging flag to be set from MERCURY_OPTIONS.
runtime/mercury_deep_profiling.[ch]:
Respect this new debugging flag.
Update the hand-written proc_static structures representing the runtime
system.
Print out addresses of proc_layout as well as proc_static structures
when assertions fail.
Add a field to the measurement structure for exception port counts,
and write out this field with the other port counts.
Remove procedure id information from proc_static structures,
deep profiling now uses the procedure id in the proc_layout structure.
Add to proc_static structures fields that specify where, if anywhere,
the variables needed by exception.m to executed the exception port code
are in the procedure's stack frame.
Define a global flag that allows the debugger to disable deep
profiling in Mercury code that is part of the debugger, not of the
user program being executed.
Increase type safety by providing two versions of the function
for registering proc_layouts, one for the proc_layout structures
of user-defined predicates and one for unify, compare and index
predicates.
Fix a bug that occurs only if MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS is
defined (which it usually isn't): the initial call count was wrong.
runtime/mercury_deep_profiling_hand.h:
Fix a bug: the handwritten code saving deep profiling variables was
saving them in slots that didn't belong to the relevant stack frame.
Update to conform to the modified definitions of proc_static structures
and the fact that we now reach them via proc_layout structures.
runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
Fix the other side of the bug in mercury_deep_profiling_hand.h
by reserving the right number of stack slots in the stack frames
of the various modes of exception__catch. Make it harder to make
the same bug in the future by getting the needed info from the
place in mercury_stacks.h that defines the structure of the relevant
stack frame.
runtime/mercury_proc_id.h:
Rename the procedure id structure fields referring to compiler
generated unify, compare and index predicates: they are not the only
compiler-generated predicates.
runtime/mercury_stack_layout.h:
Change procedure layout structures to allow them to be used for deep
profiling as well as for debugging, as described in the prologue above.
We don't need the capability to support label layout structures with
links to misnamed proc layout structures, and supporting it is
inconvenient, so delete the capability.
runtime/mercury_debug.c:
runtime/mercury_deep_profiling_hand.h:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace_external.c:
Conform to the new names of the procedure id structure fields.
runtime/mercury_std.h:
Add some more arities for MR_PASTE for use in some of the modified
modules in the runtime.
trace/mercury_trace_internal.c:
Disable deep profiling actions in Mercury code that is part of the
debugger, not of the program being debugged.
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
Make changes parallel to the ones in runtime/mercury_grade.h: delete
--stack-trace as an independent option, and make --debug set its
own option, not --require-tracing.
scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/c2init.in:
scripts/mgnuc.in:
scripts/ml.in:
Conform to the changes in grade options for debugging and for deep
profiling.
tools/bootcheck:
If Mmake.stage.{browser,deep,library,runtime,trace}.params exist,
copy them to become the file Mmake.$dir.params in stage2/$dir
(where dir is derived from the name of the original file in the obvious
way). This allows more flexibility in the creation of the stage2;
for example, it allows some directories (e.g. runtime or library)
to be compiled with more debugging than other directories (e.g.
compiler). This may be required because compiling all directories
with lots of debugging may cause the linker to thrash.
Add an option, --disable-debug-libs, that clobbers the libraries
that should be linked in only in debugging grades.
To conserve disk space, remove Deep.data files created by the bootcheck
by default. Add an option, --keep-deep-data, to preserve these files.
Use a consistent mechanism (test -f) for testing the existence of
all files whose existence is tested.
When recording modification times, record the modification times
of some more files.
tests/hard_coded/Mmakefile:
In deep profiling grades, disable the test cases that we don't now
pass in such grades, and document the reasons for their failure.
Fix the misclassification of the write_binary test case.
|
||
|
|
8b9d436cbb |
More improvements for minimal model tabling.
Estimated hours taken: 12
Branches: main
More improvements for minimal model tabling.
runtime/mercury_engine.[ch]:
Provide a debug flag to control the printing of debug stack slots
in nondet stack dumps.
runtime/mercury_stack_trace.[ch]:
Provide a mechanism that allows a dump of the nondet stack to print
the principal debugging stack slots of the stack frames of procedures
that were compiled with debugging, to help debug problems where
these are overwritten during stack segment saves/restores.
Add a mechanism for limiting the output of a nondet stack trace
to a segment of the nondet stack.
runtime/mercury_minimal_model.[ch]:
Limit the output of a diagnostic nondet stack trace to just the
segment being saved or restored.
Provide a label layout structure for the entry point of the suspend
predicate, since this is necessary for correct nondet stack traces
at suspensions and resumptions.
Store the layout structure of the top nondet stack frame with each
saved state, to allow the saved nondet stack segment to be dumped
at resumptions as well as suspensions.
Fix an old bug: when extending a saved stack segment, use the same
algorithm for determining its lower bound as when the stack segment
was created in the first place.
Factor out some repeated definitions.
Note problems to be fixed later.
Improve debugging output.
runtime/mercury_stacks.[ch]:
Move the documentation of the generator stack, the cut stack and the
pneg stack from the source file to the header file, and expand it
considerably.
Make the routines for printing entries of these stacks generate more
consistently formatted output.
Simplify some code.
runtime/mercury_stack_layout.h:
Provide a macro for use by mercury_minimal_model.c.
runtime/mercury_trace_base.[ch]:
Save and restore the global variables holding event numbers,
call sequence numbers and call depths across debugging Mercury code.
We already used to do this for Mercury code invoked by the debugger,
but now that we can invoke Mercury code to print the values of
variables as diagnostics from within the suspend and resume predicates
*outside* the debugger, we need to do it more generally.
trace/mercury_trace.c:
Fix a bug: provide the layout structure of the current procedure
to the diagnostic routines for minimal model tabling even if the
debugger doesn't stop at that procedure.
trace/mercury_trace_internal.c:
Add two new mdb commands to help debug minimal model tabling.
The "mm_stack" command has the same effect as the existing commands
"gen_stack", "cut_stack" and "pneg_stack" executed in sequence.
The "debug_vars" command prints the counters for event numbers,
call sequence numbers and call depths, both from their global variables
and their saved copies, for debugging problems where they are
overwritten, such as the one fixed by the changes to
mercury_trace_base.[ch] above.
Reorder some code for consistency.
trace/mercury_trace_util.[ch]:
Add a function to implement the "debug_vars" command.
doc/user_guide.texi:
Document the new mdb commands.
doc/mdb_categories:
Add the new mdb commands to the list of developer commands, as well
some others previously left out.
tests/debugger/mdb_command_test.inp:
Test the documentation of the new mdb commands.
tests/tabling/combine.m:
Change the code of this test case to what was intended, so that it now
matches the old expected output.
tests/tabling/completed_consumer_in_solutions.{m,exp}:
New test case, an easier version of consumer_in_solutions.
tests/tabling/consumer_in_commit.{m,exp}:
Extend this test case and update the expected output; we can execute
both the original code and the extension without runtime exceptions.
tests/tabling/seq2.m:
Fix Kostis's new test case.
tests/tabling/seq4.exp:
Fix the expected output of Kostis's new test case.
tests/tabling/Mmakefile:
Enable the new test cases, and some old test cases that we now pass.
|
||
|
|
579f7ff40e |
Define a new debugging flag whose purpose is to allow an mdb command,
Estimated hours taken: 0.2 Branches: main runtime/mercury_engine.[ch]: Define a new debugging flag whose purpose is to allow an mdb command, "flag enabled on", to turn on low level debugging if the executable was compiled with the appropriate options. runtime/mercury_debug.c: When recomputing MR_lld_print_enabled, respect the new debugging flag. runtime/mercury_wrapper.c: Document the new condition for enabling low level debugging implemented by the change to mercury_debug.c. |
||
|
|
bccbda7fd7 |
Add a flag, settable from the debugger, that allows experimentation
Estimated hours taken: 0.2 Branches: main runtime/mercury_engine.[ch]: Add a flag, settable from the debugger, that allows experimentation with a variant form of minimal model tabling. runtime/mercury_minimal_model.c: Pay attention to the new flag. |
||
|
|
ab5a7c7acf |
Fix two bugs in the printing of goals where the predicate concerned is an
Estimated hours taken: 6
Branches: main
Fix two bugs in the printing of goals where the predicate concerned is an
compiler-generated unify, compare or index predicate. Improve the mechanisms
for debugging bugs like this.
runtime/mercury_layout_util.[ch]:
Fix bug one: do not return the arity of a type constructor as
the arity of the unify, compare or index predicate of that
type constructor; return the actual arity. When the falsely
returned arity was greater than the actual arity, we could get
core dumps; when it was smaller, the mdb command "print goal"
printed wrong output.
Provide a mechanism for fixing bug two: add a utility function
for computing *correctly* a procedure's original arity and the number
of type_info and/or typeclass_info arguments added by the compiler.
(For convenience, it also returns a predicate/function indication.)
runtime/mercury_stack_layout.h:
Rename the MR_comp_arity field of MR_Compiler_Proc_Id to
MR_comp_type_arity, to make clear that it gives the arity of the type
constructor, not the arity of the predicate, and thus avoid bugs such
as those above.
runtime/mercury_stack_trace.c:
Use the new name of the MR_comp_type_arity field.
trace/mercury_trace_declarative.c:
trace/mercury_trace_vars.c:
Call the new, correct utility function in runtime/mercury_layout_util
to compute how many typeinfo and/or typeclassinfo arguments are added
by the compiler to a unify, compare, or index procedure's arguments,
instead of the different, but logically equivalent and equally wrong
pieces of code here.
trace/mercury_trace_external.c:
Use the new name of the MR_comp_type_arity field. Leave an XXX, since
I am not sure whether Morphine interprets the arity as the arity of the
type constructor or as the arity of the predicate.
runtime/mercury_engine.[ch]:
runtime/mercury_layout_util.c:
Make the printing of locations obtained from RTTI data structures
switchable from mdb, to make problems like this easier to debug.
tests/debugger/uci.{m,inp,exp}:
A new test case to test the proper handling of unify, compare and index
predicates.
tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
Enable the new test case.
|
||
|
|
168500343c |
This change adds new facilities for debugging minimal model tabling, and
Estimated hours taken: 160 Branches: main This change adds new facilities for debugging minimal model tabling, and has several bug fixes found with the aid of those facilities. Most of the diff affects the behavior of the system only in minimal model grades and/or when debugging flags are defined. compiler/ite_gen.m: In minimal model grades, surround the conditions of if-then-elses with calls to three functions. These functions detect when a condition fails due to one or more suspensions, and abort the program. (After resumptions, the condition may actually have solutions, but by then the computation has committed to the wrong path.) compiler/table_gen.m: Change the program transformation for model_non predicates to use a switch instead of nested if-then-elses, to avoid the overhead of wrapping the condition. The version with switches is also a bit easier to debug. The transformation for model_det and model_semi predicates stays as before, because for such predicates finding the status (which we want to switch on) requires computation, not just a lookup. Switch to state variable syntax in the affected predicates. Make the error message for an internal error in loopcheck predicates more precise. Mark the code fragments that modify tabling data structures as impure and code fragments that examine tabling data structures as semipure. runtime/mercury_stacks.[ch]: Implement the new stack of possibly negated contexts that we use to detect false failures due to suspensions in negated contexts. Fix a bug: don't refer to MR_cut_stack[-1]. Shorten the name of the generator stack. runtime/mercury_context.[ch]: runtime/mercury_memory.c: runtime/mercury_wrapper.[ch]: Allocate memory for the new stack of possibly negated contexts. Use the shortened name of the generator stack. runtime/mercury_regorder.h: Allocate a pointer for the new stack of possibly negated contexts. runtime/mercury_minimal_model.[ch]: A new module holding the part of mercury_tabling.[ch] that is specific to minimal model tabling. This version contains tools to help debugging of minimal model tabling, as well as some bug fixes found with the aid of those tools. runtime/mercury_tabling.[ch]: Remove the code moved to mercury_minimal_model.[ch], and add the code moved here from trace/mercury_trace_internal.c. Add prefixes to a bunch of structure fields to make it easier to read code accessing those fields. Add mechanisms to allocate and copy tabling structures with type safety. runtime/mercury_imp.h: #include the new header file, if it is needed. runtime/Mmakefile: Mention the new module, and fix sortedness errors. runtime/mercury_stack_trace.c: Fix a bug that sometimes caused stack traces to abort in minimal model grades: they were trying to get layout information from labels that do not have them, such as do_fail. If MR_TABLE_DEBUG is defined, print the locations of stack frames when doing stack dumps. runtime/mercury_trace_base.h: Export to mercury_stack_trace.c the labels that we use to let the debugger get control at redos and fails, since they don't have layout information. runtime/mercury_types.h: Move typedefs here from mercury_tabling.h, and add typedefs for some newly added types. runtime/mercury_engine.[ch]: Add a table mapping debugging flags to their offsets in the MR_debugflag array, for use in the debugger. runtime/mercury_misc.c: Make the formatting of det stack pointers the same as nondet stack pointers in debugging output. runtime/mercury_debug.[ch]: Add conditionally compiled debugging output when creating temp frames on the nondet stack. library/table_builtin.m: Conform to the new names of some fields. Add a predicate to return the status of a subgoal. Add conditionally compiled debugging code. library/Mmakefile: Make table_builtin.m depend on runtime/mercury_minimal_model.h. trace/mercury_trace.c: Conform to the new names of some fields. trace/mercury_trace_internal.c: Add two new mdb commands, to print the cut stack and the new possibly negated context stack. Add two new mdb commands to print a subgoal and a consumer. Move some of the code to print tabling-related data structures to runtime/mercury_tabling.[ch]. Add a new mdb command to report the values of debugging flags and to set and clear them. Previously, one had to turn on these debugging flags with environment variables, which were problematic because they turned on diagnostic printouts even in Mercury programs that *weren't* being debugged, such as the Mercury compiler when being used to generate the program to be debugged. Now the flags can be turned on from a .mdbrc file, which eliminates much setting and unsetting of environment variables. doc/user_guide.tex: Document the new mdb commands. tests/debugger/mdb_command_test.inp: Test the documentation of the new mdb commands. tests/debugger/completion.exp: Expect the new commands in the command completion test. tests/debugger//nondet_stack.exp*: Expect the new format of det stack pointers. tests/debugger/all_solutions.exp3: tests/debugger/exception_value.exp3: tests/debugger/declarative/catch.exp3: tests/debugger/declarative/ho5.exp3: tests/debugger/declarative/throw.exp3: New expected test cases for use in minimal model grades. They differ from existing expected output files only in the precise phrasing of error messages. tests/debugger/declarative/Mmakefile: Disable the untraced_subgoal test case in .mm grades, since we don't pass it yet. tests/tabling/Mmakefile: Enable the mday test case, now that we pass it. |
||
|
|
57b9d92601 |
Ensure that the global heap and solutions heap are not used
Estimated hours taken: 4 Branches: main Ensure that the global heap and solutions heap are not used in accurate GC grades. runtime/mercury_conf_param.h: Define new parameters MR_RECLAIM_HP_ON_FAILURE and MR_MIGHT_RECLAIM_HP_ON_FAILURE. These will not be defined for accurate GC grades. runtime/mercury_engine.h: runtime/mercury_engine.c: Only allocate the solutions heap and the global heap if MR_MIGHT_RECLAIM_HP_ON_FAILURE is set. library/std_util.m: Don't define MR_RECLAIM_HP_ON_FAILURE, since it is now defined in runtime/mercury_conf_param.h. library/exception.m: When an exception is throw, reset the heap iff MR_RECLAIM_HP_ON_FAILURE is set, rather than iff MR_CONSERVATIVE_GC is not set. runtime/mercury_deep_copy.h: runtime/mercury_deep_copy.c: Change MR_make_permanent() and MR_make_long_lived() so that they copy data to the global heap iff MR_MIGHT_RECLAIM_HP_ON_FAILURE is set, rather than iff MR_CONSERVATIVE_GC is not set. |
||
|
|
17d5aa732e |
Add support for interfacing Mercury with the MPS garbage collector.
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.
|
||
|
|
010a9ecf74 |
Fix several bugs in deep profiling. These allow the compiler to bootstrap
Estimated hours taken: 30
Branches: main
Fix several bugs in deep profiling. These allow the compiler to bootstrap
again, *including* writing out the profiling data, with sanity checks enabled.
Some test cases still fail, but significantly fewer than before.
These fixes required several improvements in the infrastructure for low
level debugging in the LLDS grades.
compiler/deep_profiling.m:
Mark calls that have a prepare_for_{normal,ho,...}_call inserted before
them as impure, to prevent simplify from optimizing them away, e.g. as
duplicate calls. This is needed because a prepare_for_{...}_call that
is not followed immediately by the call port code of the callee leaves
the profiling tree in a state that violates its invariants.
Mark the redo port code of model_non predicates as needing to be
preserved, even if determinism analysis would normally cause it to be
cut by marking the disjunction it is part of (whose two disjuncts are
the det exit port code and the failure redo port code) as det.
Fix the generation of goal paths to match what the rest of the compiler
does. Start number conjuncts, disjuncts and switch arms from 1, not 0,
and do not reverse goal paths before attaching them to goals; they will
be reversed when they are converted to strings.
compiler/det_analysis.m:
If a disjunct has determinism failure but is impure, treat it as being
able to succeed when computing the max number of solutions of the
disjunction as a whole, *provided* that some earlier disjuct could
succeed. The idea is that ( impure failure ; det ) should be treated
as det, since all backtracking is local within it, while disjunctions
of the form ( det ; impure failure ) should be treated as multi, since
we want to be able to backtrack to the second disjunct from *outside*
the disjunction.
At the moment, we do this not for all impure goals, but only for the
impure goals that deep_profiling marks with the preserve_backtrack_into
feature.
compiler/hlds_goal.m:
Add the preserve_backtrack_into feature.
Add utility predicates for handling the features of a goal directly,
without explicitly dealing with its goal_info.
runtime/mercury_debug.[ch]:
Add mechanisms for turning the printing of low level debugging messages
on and off. Without this, enabling low level debugging can generate
literally gigabytes of debugging output.
The mechanisms all depend on numbering calls.
One mechanism allows messages to be printed starting from calls in
given ranges, by including e.g. -di100-200,300-400 in MERCURY_OPTIONS.
Another mechanism allows N messages to be printed starting from calls
to a given procedure or from calls at which next_call_site_dynamic
has a given value. The value of N (the size of the block of calls)
can be specified by include -dB<num> in MERCURY_OPTIONS. The name of
the given procedure (actually the name of its entry label) can be
specified by including -dj<entrylabel> in MERCURY_OPTIONS. The address
of the call_site_dynamic structure to watch for is specified with the
-dW<addr> option in MERCURY_OPTIONS, as before.
runtime/mercury_wrapper.[ch]:
Add the global variables required to implement the new low level
debugging functionality, as well as the option processing code required
to set those global variables.
Separate the flags controlling the printing of the values of stack
control registers (sp, curfr etc) and ordinary registers (r1, r2 etc).
Print ordinary registers only if explicitly requested.
runtime/mercury_engine.h:
Add the required global flags.
runtime/mercury_deep_profiling.[ch]:
Add two extra arguments to MR_deep_assert, and print them if an
assertion fails. This makes it easier to decide what parameters to give
to the new low level debugging mechanisms.
runtime/mercury_deep_*_port_body.h:
runtime/mercury_deep_rec_depth_*.h:
library/profiling_builtin.m:
Pass the extra arguments to MR_deep_assert, and print low level
debugging messages only if the relevant flag is set.
tools/lmc:
Add mechanisms to add to the list of C compiler flags the program is
compiled with by lmc.
|
||
|
|
22d1aa615d |
Make the accurate GC debugging code a run-time option
Estimated hours taken: 1 Branches: main Make the accurate GC debugging code a run-time option rather than a compile-time option. The run-time cost of this is very small -- just a few `if' statements per garbage collection -- and it is more convenient if agc debugging can be enabled by setting MERCURY_OPTIONS rather than by having to recompile the Mercury runtime. runtime/mercury_engine.h: Add a new debug flag `MR_agc_debug', for debugging accurate GC. runtime/mercury_wrapper.c: Set the flag if the -dA or -dG options are specified in MERCURY_OPTIONS. runtime/mercury_accurate_gc.c: Change the code which was using `#ifdef MR_AGC_DEBUG_COLLECTION' to instead use `if (MR_agc_debug)'. runtime/mercury_conf_param.h: Delete the documentation of the now unused configuration macro MR_AGC_DEBUG_COLLECTION, and add a mention of the -dG option. |
||
|
|
b7c4a317e9 |
Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4 Branches: main Add MR_ prefixes to the remaining non-prefixed symbols. This change will require all workspaces to be updated The compiler will start generating references to MR_TRUE, MR_bool, etc., which are not defined in the old runtime header files. runtime/mercury_std.h: Add MR_ prefixes to bool, TRUE, FALSE, max, min, streq, strdiff, strtest, strntest, strneq, strndiff, strntest, NO_RETURN. Delete a commented out definition of `reg'. runtime/mercury_tags.h: Add an MR_ prefix to TAGBITS. configure.in: runtime/mercury_goto.h: runtime/machdeps/i386_regs.h/mercury_goto.h: Add an MR_ prefix to PIC. runtime/mercury_conf_param.h: Allow non-prefixed PIC and HIGHTAGS to be defined on the command line. runtime/mercury_bootstrap.h: Add backwards compatibility definitions. RESERVED_MACRO_NAMES: Remove the renamed macros. compiler/export.m: compiler/ml_code_gen.m: Use MR_bool rather than MR_Bool (MR_Bool is meant to be for references to the Mercury type bool__bool). runtime/mercury_types.h: Add a comment the MR_Bool is for references to bool__bool. */*.c: */*.h: */*.m: Add MR_ prefixes. |
||
|
|
c66cea0665 |
Add MR_ prefixes to uses of configuration macros.
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. |
||
|
|
04e614485d |
Implement deep profiling; merge the changes on the deep2 branch back
Estimated hours taken: 500 Branches: main Implement deep profiling; merge the changes on the deep2 branch back onto the trunk. The main documentation on the general architecture of the deep profiler is the deep profiling paper. doc/user_guide.texi: Document how to use the deep profiler. deep_profiler: deep_profiler/Mmakefile: A new directory holding the deep profiler and its mmakefile. Mmakefile: Add targets for the new directory. Add support for removing inappropriate files from directories. deep_profiler/interface.m: The deep profiler consists of two programs: mdprof_cgi.m, which acts as a CGI "script", and mdprof_server.m, which implements the server process that the CGI script talks to. Interface.m defines the interface between them. script/mdprof.in: A shell script template. ../configure uses it to generate mdprof, which is a wrapper around mdprof_cgi that tells it how to find mdprof_server. deep_profiler/mdprof_cgi.m: The CGI "script" program. deep_profiler/mdprof_server.m: The top level predicates of the server. deep_profiler/profile.m: The main data structures of the server and their operations. deep_profiler/read_profile.m: Code for reading in profiling data files. deep_profiler/startup.m: Code for post-processing the information in profiling data files, propagating costs from procedures to their ancestors and performing various kinds of summaries. deep_profiler/server.m: Code for responding to requests from the CGI script. deep_profiler/cliques.m: Code to find cliques in graphs. deep_profiler/array_util.m: deep_profiler/util.m: Utility predicates. deep_profiler/dense_bitset.m: An implementation of (part of) the set ADT with dense bit vectors. deep_profiler/measurements.m: Operations on profiling measurements. deep_profiler/timeout.m: An implementation of a timeout facility. deep_profiler/conf.m: Functions that depend on autoconfigured settings. configure.in: Find out what command to use to find the name of the local host. Install deep profiling versions of the standard library along with the other profiling versions. runtime/mercury_conf.h.in: Add some macros for deep_profiler/conf.m to use. library/profiling_builtin.m: runtime/mercury_deep_call_port_body.h: runtime/mercury_deep_leave_port_body.h: runtime/mercury_deep_redo_port_body.h: A new library module that implements deep profiling primitives. Some of these primitives have many versions, whose common code is factor is factored out in three new include files in the runtime. compiler/deep_profiling.m: New module to perform the program transformations described in the paper. compiler/notes/compiler_design.html: Document the new compiler module. compiler/mercury_compiler.m: Invoke the new module in deep profiling grades. Allow global static data to be generated by deep_profiling.m. compiler/options.m: Add options to turn on deep profiling and (for benchmarking purposes) control its implementation. Add an optiooption disable tailcall optimization in the LLDS backend, to help benchmarking deep profiling. compiler/jumpopt.m: compiler/optimize.m: Obey the option to disable tailcalls. compiler/handle_options.m: Handle the implications of deep profiling. compiler/modules.m: In deep profiling grades, automatically import profiling_builtin.m. compiler/prog_util.m: doc/Makefile: library/library.m: Handle the new builtin module. compiler/export.m: In deep profiling grades, wrap deep profiling code around exported procedures to handle the "unscheduled call" aspects of callbacks to Mercury from the foreign language. compiler/higher_order.m: profiler/demangle.m: util/demangle.c: When creating a name for a higher-order-specialized predicate, include the mode number in the name. compiler/add_trail_ops.m: compiler/type_util.m: Move c_pointer_type from add_trail_ops to type_util, so it can also be used by deep_profiling.m. compiler/hlds_goal.m: Add a new goal feature that marks a tail call, for use by deep_profiling.m. compiler/hlds_pred.m: Add a new field to proc_info structures for use by deep_profiling.m. Add a mechanism for getting proc_ids for procedure clones. Remove next_proc_id, an obsolete and unused predicate. compiler/hlds_data.m: Add a new cons_id to refer to the proc_static structure of a procedure. compiler/bytecode_gen.m: compiler/code_util.m: compiler/dependency_graph.m: compiler/hlds_out.m: compiler/mercury_to_mercury.m: compiler/ml_unify_gen.m: compiler/opt_debug.m: compiler/prog_rep.m: compiler/rl_exprn.m: compiler/switch_util.m: compiler/unify_gen.m: Trivial changes to handle the new cons_id, goal feature and/or proc_info argument. compiler/rtti.m: Add a utility predicate for extracting pred_id and proc_id from an rtti_proc_label, for use by hlds_out.m compiler/layout.m: compiler/layout_out.m: compiler/llds.m: compiler/llds_common.m: Add support for proc_static and call_site_static structures. compiler/layout_out.m: compiler/llds_out.m: Add code for the output of proc_static structures. compiler/code_util.m: Make code_util__make_proc_label_from_rtti a function, and export it. util/mkinit.c: compiler/llds_out.m: compiler/layout.m: compiler/modules.m: Add support for a fourth per-module C function, for writing out proc_static structures (and the call_site_static structures they contains). Since proc_static structures can be referred to from LLDS code (and not just from other static structures and compiler-generated C code), reorganize the declarations of static structures slightly. Change the schema for the name of the first per-module C function slightly, to make it the addition of the fourth function easier. The scheme now is: mercury__<modulename>__init mercury__<modulename>__init_type_tables mercury__<modulename>__init_debugger mercury__<modulename>__write_out_proc_statics Improve formatting of the generated C code. library/*.m: runtime/mercury.c: runtime/mercury_context.c: runtime/mercury_engine.c: runtime/mercury_ho_call.c: runtime/mercury_tabling.c: runtime/mercury_trace_base.c: runtime/mercury_wrapper.c: trace/mercrury_trace.[ch]: trace/mercrury_trace_declarative.c: trace/mercrury_trace_external.c: trace/mercrury_trace_internal.c: Conform to the new scheme for initialization functions for hand-written modules. compiler/mercury_compile.m: library/benchmarking.m: runtime/mercury_conf_param.h: runtime/mercury.h: runtime/mercury_engine.c: runtime/mercury_goto.c: runtime/mercury_grade.h: runtime/mercury_ho_call.c: runtime/mercury_label.[ch]: runtime/mercury_prof.[ch]: Add an MR_MPROF_ prefix in front of the C macros used to control the old profiler. compiler/handle_options.m: runtime/mercury_grade.h: scripts/canonical_grade.sh-subr: scripts/init_grade_options.sh-subr: scripts/parse_grade_options.sh-subr: Make deep profiling completely separate from the old profiling system, by making the deep profiling grade independent of MR_MPROF_PROFILE_TIME and the compiler option --profile-time. library/array.m: library/builtin.m: library/std_util.m: runtime/mercury_hand_unify_body.h: runtime/mercury_hand_compare_body.h: In deep profiling grades, wrap the deep profiling call, exit, fail and redo codes around the bodies of hand-written unification and comparison procedures. Make the reporting of array bounds violations switchable between making them fatal errors, as we currently, and reporting them by throwing an exception. Throwing an exception makes debugging code using arrays easier, but since exceptions aren't (yet) propagated across engine boundaries, we keep the old behaviour as the default; the new behaviour is for implementors. runtime/mercury_deep_profiling_hand.h: New file that defines macros for use in Mercury predicates whose definition is in hand-written C code. library/exception.m: runtime/mercury_exception_catch_body.h: runtime/mercury_stacks.h: In deep profiling grades, wrap the deep profiling call, exit, fail and redo codes around the bodies of the various modes of builtin_catch. Provide a function that C code can use to throw exceptions. library/benchmarking.m: library/exception.m: library/gc.m: library/std_util.m: runtime/mercury_context.[ch]: runtime/mercury_engine.[ch]: runtime/mercury_debug.c: runtime/mercury_deep_copy.c: runtime/mercury_overflow.h: runtime/mercury_regs.h: runtime/mercury_stacks.h: runtime/mercury_thread.c: runtime/mercury_wrapper.c: Add prefixes to the names of the fields in the engine and context structures, to make code using them easier to understand and modify. runtime/mercury_deep_profiling.[ch]: New module containing support functions for deep profiling and functions for writing out a deep profiling data file at the end of execution. runtime/mercury_debug.[ch]: Add support for debugging deep profiling. Add support for watching the value at a given address. Make the buffered/unbuffered nature of debugging output controllable via the -du option. Print register contents only if -dr is specified. runtime/mercury_goto.h: runtime/mercury_std.h: Use the macros in mercury_std.h instead of defining local variants. runtime/mercury_goto.h: runtime/mercury_stack_layout.h: runtime/mercury_stack_trace.c: runtime/mercury_tabling.c: trace/mercury_trace.c: trace/mercury_trace_declarative.c: trace/mercury_trace_external.c: trace/mercury_trace_vars.c: Standardize some of the macro names with those used in the debugger paper. runtime/mercury_heap.h: Add support for memory profiling with the deep profiler. runtime/mercury_prof.[ch]: runtime/mercury_prof_time.[ch]: Move the functionality that both the old profiler and the deep profiler need into the new module mercury_prof_time. Leave mercury_prof containing stuff that is only relevant to the old profiler. runtime/mercury_prof.[ch]: runtime/mercury_strerror.[ch]: Move the definition of strerror from mercury_prof to its own file. runtime/mercury_wrapper.[ch]: Add support for deep profiling. Add suppory for controlling whether debugging output is buffered or not. Add support for watching the value at a given address. runtime/Mmakefile: Mention all the added files. scripts/mgnuc.in: Add an option for turning on deep profiling. Add options for controlling the details of deep profiling. These are not documented because they are intended only for benchmarking the deep profiler itself, for the paper; they are not for general use. tools/bootcheck: Compile the deep_profiler directory as well as the other directories containing Mercury code. Turn off the creation of deep profiling data files during bootcheck, since all but one of these in each directory will be overwritten anyway. Add support for turning on --keep-objs by default in a workspace. tools/speedtest: Preserve any deep profiling data files created by the tests. trace/mercury_trace.c: Trap attempts to perform retries in deep profiling grades, since they would lead to core dumps otherwise. util/Mmakefile: Avoid compile-time warnings when compiling getopt. tests/*/Mmakefile: tests/*/*/Mmakefile: In deep profiling grades, switch off the tests that test features that don't work with deep profiling, either by design or because the combination hasn't been implemented yet. |
||
|
|
2f737704b9 |
Add some Mmake rules to the runtime and some code to tools/bootcheck
Estimated hours taken: 16 Add some Mmake rules to the runtime and some code to tools/bootcheck so that we automatically check that the namespace remains clean. Also add some `MR_' prefixes that Zoltan missed in his earlier change. tools/bootcheck: Add an option, which is enabled by default, to build the check_namespace target in the runtime. runtime/RESERVED_MACRO_NAMES: New file. Contains a list of the macros names that don't start with `MR_' or the like. runtime/Mmakefile: Change the rule for `check_headers' so that it checks for macros that don't occur in the RESERVED_MACRO_NAMES files, as well as not starting with `MR_' prefixes, and reports errors for such macros. Also add a rule for check_objs that checks whether the object files define any global symbols that don't have the right prefixes, and a rule `check_namespace' that does both of the above. runtime/mercury_bootstrap.h: #include "mercury_types.h" and "mercury_float.h", to ensure that this header file is self-contained. Also make sure that all the old names are disabled if you compile with `-DMR_NO_BACKWARDS_COMPAT'. runtime/mercury_context.c: runtime/mercury_thread.h: runtime/mercury_thread.c: Use `bool' rather than `MR_Bool' for the argument to MR_check_pending_contexts() and the return type of MR_init_thread(), since these are C bools, not Mercury bools, and there's no requirement that they have the same size as MR_Integer. runtime/mercury_type_info.h: runtime/mercury_deep_copy_body.h: runtime/mercury_tabling.c: library/std_util.m: trace/mercury_trace_declarative.c: trace/mercury_trace_external.c: trace/mercury_trace_internal.c: tests/hard_coded/existential_types_test.m: Add MR_ prefixes to UNIV_OFFSET_FOR_TYPEINFO and UNIV_OFFSET_FOR_VALUE. trace/mercury_trace_external.c: trace/mercury_trace_internal.c: trace/mercury_trace_tables.c: Add MR_ prefixes to do_init_modules(). runtime/mercury_tabling.h: runtime/mercury_tabling.c: runtime/mercury_overflow.h: runtime/mercury_debug.h: Add MR_ prefixes to table_*. runtime/mercury_overflow.h: runtime/mercury_debug.h: Add MR_ prefixes to IF(). runtime/mercury_context.h: Add MR_ prefixes to IF_MR_THREAD_SAFE(). runtime/mercury_engine.h: Add MR_ prefixes to IF_NOT_CONSERVATIVE_GC(). runtime/mercury_engine.h: runtime/mercury_engine.c: extras/aditi/aditi.m: Add MR_ prefixs to do_fail, do_redo, do_not_reached, etc. compiler/trace.m: compiler/fact_table.m: compiler/llds_out.m: Add MR_ prefixes to the generated code. |
||
|
|
210a596aaf |
Make even things used only in grade none use MR_ prefixes.
Estimated hours taken: 2 Make even things used only in grade none use MR_ prefixes. runtime/mercury_memory.c: Delete some obsolete global variables that were replaced by fields of the engine structure ages ago. Their declaration gets a syntax error in grade none. runtime/mercury_engine.h: Remove some confusing macros for referring to these fields. runtime/mercury_*.[ch] Add MR_ prefixes as necessary. Get rid of references to the confusing macros. library/exception.m: Add MR_ prefixes as necessary. Get rid of references to the confusing macros. library/std_util.m: Add MR_ prefixes as necessary. |
||
|
|
090552c993 |
Make everything in the runtime use MR_ prefixes, and make the compiler
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. |
||
|
|
db64a3588d |
Add MR_ prefixes to the types used when generating C code.
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. |
||
|
|
95b6cf00f2 |
Make the types of the fields in the MR_jmp_buf structure
Estimated hours taken: 0.1 runtime/mercury_engine.h: Make the types of the fields in the MR_jmp_buf structure which correspond to the trail global variables match the types of those variables. |
||
|
|
84c8146d0d |
Fix several bugs in the trail handling.
Estimated hours taken: 20
Fix several bugs in the trail handling.
Also improve the documentation of trailing, and add a new macro
MR_choicepoint_newer() to the public trailing interface.
The bugs which this change fixes are:
- choice point ids were being reused after commits,
rather than only after backtracking;
- for if-then-elses with nondet conditions, the generated code was
using MR_commit rather than MR_solve as the MR_untrail_reason;
- for semidet disjunctions, when committing to a particular disjunct
the generated code was not calling MR_reset_ticket(..., MR_commit)
to invoke function trail entries, and was also leaking a trail ticket
- the all-solutions predicates in std_util.m were leaking trail
tickets (i.e. allocating them but not pruning or discarding them).
runtime/mercury_trail.h:
runtime/mercury_regorder.h:
runtime/mercury_regs.h:
runtime/mercury_wrapper.c:
runtime/mercury_context.h:
runtime/mercury_engine.h:
A bunch of changes to add a new virtual register
`MR_ticket_high_water':
- in mercury_trail.h, add MR_ticket_high_water_var variable;
- in mercury_regorder.h, add MR_ticket_high_water macro;
- in mercury_regs.h, add MR_TICKET_HIGH_WATER_RN macro;
- in mercury_wrapper.c, change
print_register_usage_counts() to handle
MR_TICKET_HIGH_WATER_RN.
- in mercury_context.h and mercury_engine.h,
add code to save/restore this new register when
appropriate.
runtime/mercury_trail.h:
- Change MR_store_ticket() so that it does
`MR_ticket_counter = ++MR_ticket_high_water'
rather than just `MR_ticket_counter++'.
- Add new macros MR_prune_ticket() and MR_prune_tickets_to(),
which only reset MR_ticket_counter, not MR_ticket_high_water.
- Change the old macros MR_discard_ticket() and MR_discard_tickets_to()
so that they reset both MR_ticket_high_water and MR_ticket_counter.
- Add new macro MR_choicepoint_newer().
- Enclose macro arguments in parentheses.
- Some minor changes to the documentation.
doc/reference_manual.texi:
Document MR_choicepoint_newer().
Update the documentation to reflect the fact that exceptions
are now a standard part of Mercury.
Clarify the documentation in the "Avoiding Redundant Trailing"
section, and add a longish example.
compiler/notes/trailing.html:
Add some documentation on the trail and how we manage it.
compiler/llds.m:
compiler/mlds.m:
Add new `prune_ticket' and `prune_tickets_to' instructions,
corresponding to the new macros defined in runtime/mercury_trail.h.
Comment out the `discard_tickets_to' instruction, since it
is no longer used in the compiler (the MR_discard_tickets_to()
macro is only used by library/exception.m and the debugger's
retry command).
Replace the duplicated documentation in mlds.m with a pointer
to llds.m.
compiler/ite_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
Change the trail handling code generated after commits
so that the ticket is pruned rather than discarded.
compiler/ite_gen.m:
When generating the reset_ticket instruction for
if-then-elses with nondet conditions, use `solve'
rather than `commit' as the reset_trail_reason.
compiler/disj_gen.m:
Add code to generate a reset_ticket(..., commit)
instruction at the end of every non-last disjunct
in semidet disjunctions.
compiler/dupelim.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/ml_elim_nested.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/value_number.m:
compiler/vn_*.m:
Trivial modifications to handle the changes to the
trailing instructions.
library/exception.m:
Change the trail handling code so that when the goal in an
exception handler succeeds (rather than failing or throwing an
exception), the trail ticket we created on entry to the
handler is pruned rather than discarded.
library/std_util.m:
Add a new impure predicate `discard_trail_ticket', which calls
MR_discard_ticket(), and call it in `builtin_aggregate' and
`do_while' to discard the ticket that gets allocated by the
call to MR_store_ticket() in `get_registers'.
|
||
|
|
fa1b8e7888 |
Fix bugs that caused compilation errors in grade `none.gc.par'.
Estimated hours taken: 0.75 Fix bugs that caused compilation errors in grade `none.gc.par'. runtime/mercury_engine.h: Add a new macro MR_cur_engine() which returns a pointer to the current engine struct. runtime/mercury_thread.c: runtime/mercury_context.c: Use MR_cur_engine() rather than MR_engine_base or &MR_engine_base. Also fix the code in mercury_thread.c to handle the case when MR_THREAD_SAFE is set but MR_ENGINE_BASE_REGISTER is not. |
||
|
|
1eb831eb34 |
A major cleanup of the internals of tabling.
Estimated hours taken: 40
A major cleanup of the internals of tabling.
Tabling builds up two kinds of tables, both conceptually tries. For call
tables, there is one layer in the trie for each input argument; for answer
tables, there is one layer in the trie for each output argument. However,
the way each trie node is implemented depends on the type of the relevant
argument. In addition, what is stored at the tips of the call and answer tables
also depends on what kind of tabling (e.g. loopcheck, memo, minimal model)
is being performed on the current predicate, and (in some cases) on what
stage the execution of the current predicate has reached.
Previously, all trie nodes were declared with the C type Word **, and were
cast to their actual types at the point of use, with the casts mostly being
hidden inside macros. This arrangement lacked readability and was highly
error prone. I have replaced it with a system in which trie nodes are declared
with a C type which is a pointer to a union of all the possible actual types.
There are very few casts left in the internals of the tabling system; this
change replaces them with casts at the interface (in the predicates of
private_builtin.m) and the use of the various fields of the union.
library/private_builtin.m:
Changes to conform to the changed types in mercury_tabling.h.
In some cases, improve the debugging support.
Do not table the typeinfos of polymorphic types in the
table_lookup_insert_poly predicate; since those typeinfos
are also arguments, and since they appear before the polymorphic
arguments, they have already been tabled by the time
table_lookup_insert_poly is called.
library/private_builtin.m:
library/io.m:
Add an interface to a new function in the runtime to report
statistics about the operation of the tabling system.
runtime/mercury_tabling.h:
Define and document the new types.
Add macros for allocating memory for holding one or more structures.
Make the existing macros call the versions that check for malloc
returning NULL.
runtime/mercury_tabling_macros.h:
This new file contains macros that used to be part of the file
mercury_tabling.h. The macros call the functions defined in
mercury_tabling.c, but they also optionally print debugging messages.
runtime/Mmakefile:
Add mercury_tabling_macros.h to the list of header files.
runtime/mercury_tabling.c:
Conform to the new system of C types.
Recode the hash table routines to achieve code commonality, better
debugging and statistics gathering support, much greater readability,
and the following three performance benefits:
1. The old code used open addressing to resolve collisions. In many
uses of tabling, successive searches specify keys that have
neighboring hash values, which frequently leads to very long
searches (I have observed searches that searched more than half
the slots of the hash table.) The new code uses separate chaining
to resolve collisions.
2. The old code called GC_malloc whenever it inserted a new element
into the table. The new code amortizes this overhead over a
substantial (and configurable) number of insertions.
3. In order to check whether the hash table should be expanded, the
old code was executing a float multiplication and a float comparison
on every hash table access. The new code executes the float
multiplication only when the table size is changed; in the usual
case it only executes an integer comparison, which is much cheaper.
Recode the routines for tabling typeinfos for higher speed. Instead
of storing them in a binary search tree, which requires lots of
comparisons, store the address of the type_ctor_info in a hash table
and chain its argument typeinfos from that.
Add support for expandable tables, which are implemented as arrays
indexed by key - start. This is not used yet, but will be used for
I/O tabling soon.
runtime/mercury_stacks.c:
Conform to the new system of C types for tabling.
Improve the debugging support.
runtime/mercury_wrapper.c:
When debugging tabling, set stdout to be line buffered.
runtime/mercury_engine.h:
runtime/mercury_wrapper.c:
Add a new debugging flag, -dH, for debugging the operation of hash
tables.
In mercury_wrapper.c, sort the code fragments for for processing
the arguments of -d.
runtime/mercury_trace_base.c:
Disable the generation of nuisance debugging messages from Mercury
initialization code called before main, which may have been compiled
with MR_TABLE_DEBUG enabled.
runtime/mercury_conf_param.h:
Document MR_TABLE_STATISTICS as well as MR_TABLE_DEBUG.
trace/mercury_trace_internal.c:
Disable the generation of nuisance debugging messages from Mercury
code called by the debugger that may have been compiled with
MR_TABLE_DEBUG enabled, by turning off MR_tabledebug when MR_trace
is entered. We then turn MR_tabledebug back on (even if it wasn't
turned on in the first place) when executing debugger commands
that require it to be turned on in order to work.
tests/tabling/fib.m:
Improve the (commented out) debugging support. Start the search
for the right problem size closer to its probable end point.
tests/tabling/fib_{float,string,list}.{m,exp}:
New test cases to test the low-level routines for tabling floats,
strings, and user-defined types; they are all modified versions of fib.
tests/tabling/expand.{m,exp}:
tests/tabling/expand_float.{m,exp}:
tests/tabling/expand_poly.{m,exp}:
New test cases to test the code for resizing (i.e. expanding)
hash tables, and the code for handling polymorphic arguments.
tests/tabling/Mmakefile:
Enable the new test cases.
|
||
|
|
cd206ed3dc |
Add support for Mercury exception handling to call_engine().
Estimated hours taken: 16 Add support for Mercury exception handling to call_engine(). Currently that support is not yet used, but the idea is to eventually use this to e.g. allow Mercury exceptions to be automatically converted into C++ exceptions when you export a Mercury procedure to C++. runtime/mercury_stacks.h: Add stuff for exception handling, adapted from code in library/exception.m, for use by mercury_engine.c. runtime/mercury_engine.c: Rename call_engine as MR_call_engine(). Add a new parameter `bool catch_exceptions', and change the result type from `void' to `Word *'. If the catch_exceptions is true, then it installs an exception handler to catch Mercury exceptions and returns the Mercury exception thrown, if any. runtime/mercury_engine.h: Add a new field e_exception to the MercuryEngine structure. This thread-local variable is used to hold the Mercury exception object thrown, if any, when call_engine_inner() returns via longjmp(). Update the prototype for call_engine() to match its new MR_call_engine() interface. runtime/mercury_bootstrap.c: Add a definition of call_engine() that calls MR_call_engine(), for bootstrapping. runtime/mercury_wrapper.c: runtime/mercury_thread.c: compiler/export.m: Call MR_call_engine() rather than call_engine(). runtime/mercury_wrapper.c: Ensure that we do not clobber the value of MR_curfr in do_interpreter, since it may be needed for the exception handler frame in MR_call_engine() if do_interpreter were invoked via MR_call_engine(ENTRY(do_interpreter), TRUE). library/exception.m: Simplify the code for the different builtin_catch procedures by using the MR_create_exception_handler() macro defined in mercury_stacks.h (this avoids quite a bit of code duplication in the old code). Modify the code for builtin_throw to allow the exception handler to be C code; in that case, we save the exception object in the e_exception field of the MercuryEngine and then jump to the exception handler using longjmp(). |
||
|
|
dc03496d06 |
Rewrite significant parts of minimal model tabling so that it works
Estimated hours taken: 130
Rewrite significant parts of minimal model tabling so that it works
in a much wider variety of situations, including coups. Also, clean up
the tabling implementation to make it more maintainable, and introduce
a new grade component, .mm, that enables minimal model tabling.
(Minimal model tabling requires distributed fat, and we don't want to
incur such costs unless necessary.)
compiler/options.m:
Add a new option --use-minimal-model, which for now is documented
as "not for general use". This option is a grade option, and is
required if minimal model tabling is to work.
compiler/handle_options.m:
When --use-minimal-model is given, do not allow nondet frame hijacks,
since minimal model tabling cannot cope with hijacks.
Make --use-minimal-model a grade component.
compiler/code_info.m:
When --use-minimal-model is given, insert calls to MR_commit_{mark,cut}
around goals being committed across. This is now necessary, so that we
can detect and handle sitations where a goal being committed across
starts but does not complete a tabled goal.
compiler/table_gen.m:
Rename many of the tabling helper predicates, using a naming scheme
that separates predicates used for model_non procedures from those
used to implement simpler forms of tabling, while bringing out
the parallels between these two sets of predicates.
When calls to two tabling helper predicates always occur
one after the other, merge the two into one.
Generate and use more meaningful variable names; having all of the
several variables inserted by this transformation named TableVar
was quite confusing.
library/private_builtin.m:
Reorganize this file, to separate out the different sections.
The contents of the non-tabling sections were not modified, only
moved around.
Rename the predicates referred to by table_gen.m.
Move most of the type declarations and complex code out of here,
into runtime/mercury_tabling.c. This makes it easier to debug them,
since (a) creating a new executable is quicker, since you don't have
to wait for lots of mercury compiler invocations, and (b) gdb doesn't
get confused by #line directives. It also makes it easier to write
them, since you don't have to !&(*U&( remember to double all your
double quotes and to backslash all your backslashes.
runtime/mercury_grade.h:
Include a grade component reflecting whether MR_USE_MINIMAL_MODEL
is defined.
runtime/mercury_conf_param.h:
Document MR_USE_MINIMAL_MODEL.
runtime/mercury_stacks.[ch]:
The changes to tabling require the addition of two new stacks,
the generator stack and the cut stack. This module defines the
structures of the frames of these stacks and provides the
operations on these stacks.
The header file also contains some additional macros that return
the addresses of fixed nondet stack slots, not their contents,
for use by tabling code.
runtime/mercury_context.[ch]:
runtime/mercury_memory.[ch]:
runtime/mercury_wrapper.[ch]:
Declare and set up the two new stacks, both in saved contexts and in
the active context, if MR_USE_MINIMAL_MODEL is defined.
runtime/mercury_regorder.h:
Add four new global virtual machine registers to hold pointers
to the memory areas of the two new stacks and the current offsets
within them. These are defined whether MR_USE_MINIMAL_MODEL is defined
or not, since the cost is minimal and the potential bugs we avoid
would be hard to track down.
runtime/mercury_engine.h:
runtime/mercury_wrapper.c:
Add support for a new debugging flag, -dS, which prints the contents
of the nondet stack at several points during tabling.
runtime/mercury_tabling.[ch]:
The implementation of the new tabling system. Much of the new code here
is stuff moved from library/private_builtin.m, but in a significantly
rewritten form. There is also substantial new code, e.g. to handle
the extension of saved stack segments, and to manage dependencies
between subgoals in general.
Improve the documentation considerably.
Replace lists stored as Mercury data structures with lists stored
as linked structures in the usual C fashion. This allows us to use
debuggers such as ddd on these data structures, whose complexity
requires this.
Ensure that global names start with MR_.
runtime/mercury_init.h:
Explicitly include mercury_regs.h at the start. Without this,
we get an error, because now mercury_wrappers.h, which mercury_init.h
includes, also includes mercury_regs.h, but not before functions
have been declared.
runtime/Mmakefile:
Refer to the new file mercury_stacks.c (mercury_stacks.h already
existed, but the module consisted entirely of macros.)
Fix a sorting error.
scripts/{init,parse,final}_grade_options.sh-subr:
scripts/mgnuc.in:
Handle the new grade component.
tests/tabling/*
Add several new test cases that we now pass, most of which we couldn't
pass before. Also add some new test cases that we don't pass yet,
due to interactions between tabling and negated contexts.
trace/mercury_trace_internal.c:
If MR_USE_MINIMAL_MODEL is defined, add a new command to print
the generator stack. (The new command is deliberately not documented
in doc/mdb_doc yet, since (a) it is intended for developers only,
and (b) there is no way to test MR_USE_MINIMAL_MODEL in mdb_doc.)
|
||
|
|
c0b84793fe |
Fix a bug that conway introduced a while ago:
Estimated hours taken: 0.1 runtime/mercury_engine.h: Fix a bug that conway introduced a while ago: s/#ifdef SPEED/#ifndef MR_LOWLEVEL_DEBUG/ This bug was basically caused by a cvs conflict, plus of course C's lack of static checking for #ifdefs. |
||
|
|
5ea739d0bd |
Fix some bugs in tabling, to enable the boyer test case to work.
Estimated hours taken: 6 Fix some bugs in tabling, to enable the boyer test case to work. runtime/mercury_tabling.h: Add a new set of macros that optionally print debugging info at tabling actions. Debugging recquires compilation with -DMR_TABLE_DEBUG and -dT in MERCURY_OPTIONS. runtime/mercury_table_any.c: Use the debugging macros. Fix two bugs, one found with their help. One is that a tagged pointer to the table giving information about remote secondary tags did not have its tag stripped before use. The other is that the extraction of local secondary tags from words was done by subtracting the tag, and not by shifting out the tag, leaving the secondary tag value too high by a factor of 4 or 8. runtime/mercury_table_any.[ch]: runtime/mercury_table_enum.[ch]: Change the order of some function arguments to be consistent with the orders in the macros that call these functions. runtime/mercury_table_enum.c: Add an optional sanity check that detects the second bug above. runtime/mercury_engine.[ch]: Add a new debug flag, MR_tabledebug. Rename the flags so they always start with MR_. runtime/mercury_wrapper.c: Allow -dT in MERCURY_OPTIONS to set MR_tabledebug. runtime/*.[ch]: Trivial changes for the new names of the debug flags. runtime/Mmakefile: Reimpose alphabetical order on the list of C files. library/private_builtin.m: Use the new debugging macros in the C code that does tabling. Expose the equivalence between ml_table, ml_subgoal_table_node etc and c_pointer. The reason is % These equivalences should be local to private_builtin. However, % at the moment table_gen.m assumes that it can use a single variable % sometimes as an ml_table and other times as an ml_subgoal_table_node % (e.g. by giving the output of table_lookup_insert_int as input to % table_have_all_ans). The proper fix would be for table_gen.m to % use additional variables and insert unsafe casts. However, this % would require significant work for no real gain, so for now % we fix the problem by exposing the equivalences to code generated % by table_gen.m. library/mercury_builtin.m: Delete the contents of this obsolete file, leaving only a pointer to builtin.m and private_builtin.m. tests/tabling/Mmakefile: Enable the boyer benchmark, since we now pass it. |
||
|
|
2b605fa6e8 |
Fix several bugs in the runtime engine to do with thread-safe execution.
Estimated hours taken: 15
Fix several bugs in the runtime engine to do with thread-safe execution.
Add a new flag to pragma c_code/import to allow programmers to specify
whether or not the C code is thread-safe or not, and modify code generation
to put a lock around C code that isn't thread_safe.
runtime/mercury_thread.{c,h}:
Add a global lock.
Change the handling of thread creation. create_thread now takes
a "closure" (a C struct with a fn pointer and an argument to pass
the function) which it calls in the new thread. (The same mechanism
is used in the Boehm collector), or NULL which causes the thread
to wait for work to appear in the Mercury runqueue.
runtime/mercury_context.c:
initialize the global lock.
runtime/mercury_engine.{c,h}:
Add a new field to the MercuryEngine structre which is used to
store a list of saved thread ids. These were being saved in a
local variable in call_engine_inner which was a bug because
call_engine_inner's (C) stack frame gets scribbled on by Mercury
execution. For more detail see the comments in mercury_engine.h
runtime/mercury_wrapper.c:
Use the new interface to create_thread.
compiler/prog_io_pragma.m:
Parse either a single attribute or a list of attributes instead
of just 'may_call_mercury' in pragma c code and pragma import.
These are stored in an abstract type 'pragma_c_code_attributes'
that uses a bit array (aka int) to store the attributes.
compiler/pragma_c_gen.m:
Get the code generator to emit c code to obtain and release the
global lock for pragma c code that isn't thread_safe.
compiler/<various>.m:
Change may_call_mercury to pragma_c_code_attributes.
doc/reference_manual.m:
Document the change to pragma c code.
scripts/mgnuc.in:
Pass some extra C flags for thread-safe compilation for Linux.
|
||
|
|
376f2c69af |
An initial implementation of the accurate garbage collector.
Estimated hours taken: 90 An initial implementation of the accurate garbage collector. WORK_IN_PROGRESS: Add an entry for the accurate garbage collector. library/builtin.m: library/mercury_builtin.m: library/std_util.m: runtime/mercury_tabling.h: Deep copy terms using the address of the value instead of just the value. library/io.m: Initialize the garbage collector's rootset with the globals. runtime/Mmakefile: Add new files to the Mmakefile. runtime/mercury_accurate_gc.h: runtime/mercury_accurate_gc.c: The new garbage collector. runtime/mercury_agc_debug.c: runtime/mercury_agc_debug.h: Debugging utilities for the new garbage collector. runtime/mercury_deep_copy.c: runtime/mercury_deep_copy.h: runtime/mercury_deep_copy_body.h: Put the deep copy code in mercury_deep_copy_body.h, and #include it with appropriate #defines in order to get a variant for deep_copy(), and one for agc_deep_copy(). agc_deep_copy() forwards pointers as it copies. Also, deep_copy (all variants) have been modified to take a pointer to the data to be copied, because some variants need to be able to modify it. runtime/mercury_engine.c: runtime/mercury_engine.h: Add a second heap_zone which is the to-space of the copying collector. Add a debug_heap_zone, which is used as a scratch heap for debugging. runtime/mercury_label.c: Instead of realloc(entry_table, ....) do entry_table = realloc(entry_table, ....) to avoid horrible bugs. Also, make sure the tables get initialized before looking up an entry label. runtime/mercury_imp.h: Include mercury_debug.h before most of the modules. (mercury_engine.h adds a new MemoryZone only if we are debugging accurate GC). runtime/mercury_memory.c: Setup the debug_memory_zone sizes. Remove an unnecessary prototype. runtime/mercury_memory_handlers.c: Add code to get the program counter and the stack pointer from the signal context. Call MR_schedule_agc() from default_handler() if doing accurate gc. runtime/mercury_memory_zones.c: Setup the hardzone regardless of whether redzones are used. Add some more debugging information. runtime/mercury_regorder.h: runtime/machdeps/alpha_regs.h: runtime/machdeps/i386_regs.h: Add definitions to make the real machine registers name/number for MR_sp available. runtime/mercury_trace_internal.c: runtime/mercury_trace_util.c: runtime/mercury_trace_util.h: Add MR_trace_write_variable(), which writes terms given their value and type_info. runtime/mercury_wrapper.c: runtime/mercury_wrapper.h: Change the size of the heap redzone when doing accurate GC. Use a small heap when debugging agc. runtime/mercury_debug.h: runtime/mercury_conf_param.h: Add new debugging macros and document them. runtime/mercury_type_info.c: Add const to the pointer arguments of MR_make_type_info. |