[m-dev.] for review: runtime changes
Thomas Charles CONWAY
conway at students.cs.mu.oz.au
Tue Nov 11 14:54:08 AEDT 1997
Fergus Henderson, you write:
>
> Thomas Charles CONWAY, you wrote:
> > This diff starts migrating global variables into virtual registers,
> > removes some junk code to do with parallelism, and renames the
> > special registers with mr_ prefixes.
>
> Please s/mr_/MR_/g
>
Done.
> > + if (free_context_list == NULL) {
> > + c = (Context *) malloc(sizeof(Context));
> > + assert(c);
>
> That's not the right way to allocate memory.
> Probably you should use the make() macro, which calls newmem().
>
> c = make(Context);
>
Done.
> > -do_runnext:
> ...
> > -do_schedule:
> ...
> > -do_join_and_terminate:
> ...
>
> Won't these still be needed?
Only maybe, eventually. As currently implemented they rely on
global variables. This will need changing. As of this diff
they are only referenced by macros which currently call fatal_error.
Revised diff follows.
Thomas
--
ZZ:wq!
^X^C
Thomas Conway conway at cs.mu.oz.au
AD DEUM ET VINUM Every sword has two edges.
This diff starts migrating global variables into virtual registers,
removes some junk code to do with parallelism, and renames the
special registers with MR_ prefixes.
compiler/llds_out.m:
rename hp, etc as MR_hp, etc.
library/std_util.m:
rename hp and solutions_heap_pointer.
runtime/*:
- remove old parallelism stuff that will change completely when
we use posix threads.
- rename the various special registers (hp, sp, etc) with a MR_
prefix.
- make the solutions heap pointer and the minimum heap reclaimation
point virtual registers rather than global variables.
cvs diff: Diffing .
Index: call.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/call.mod,v
retrieving revision 1.30
diff -u -r1.30 call.mod
--- call.mod 1997/07/27 15:08:00 1.30
+++ call.mod 1997/11/10 23:13:32
@@ -41,7 +41,7 @@
push(r3); /* The number of output args to unpack */
push(num_in_args + num_extra_args); /* The number of input args */
- push(succip);
+ push(MR_succip);
save_registers();
@@ -68,7 +68,7 @@
{
int i, num_in_args, num_out_args;
- succip = pop(); /* restore succip */
+ MR_succip = pop(); /* restore succip */
num_in_args = pop(); /* restore the input arg counter */
num_out_args = pop(); /* restore the ouput arg counter */
@@ -97,7 +97,7 @@
push(r3); /* The number of output args to unpack */
push(num_in_args + num_extra_args); /* The number of input args */
- push(succip);
+ push(MR_succip);
save_registers();
@@ -140,7 +140,7 @@
{
int i, num_in_args, num_out_args;
- succip = pop(); /* restore succip */
+ MR_succip = pop(); /* restore succip */
num_in_args = pop(); /* restore the input arg counter */
num_out_args = pop(); /* restore the ouput arg counter */
@@ -329,7 +329,7 @@
#ifdef COMPACT_ARGS
tailcall(index_pred, LABEL(mercury__index_2_0));
#else
- push(succip);
+ push(MR_succip);
push(type_arity);
call(index_pred, LABEL(mercury__index_2_0_i1),
LABEL(mercury__index_2_0));
@@ -347,7 +347,7 @@
int type_arity;
type_arity = pop();
- succip = pop();
+ MR_succip = pop();
save_registers();
r3 = virtual_reg(type_arity + 2);
proceed();
@@ -438,7 +438,7 @@
#ifdef COMPACT_ARGS
tailcall(compare_pred, LABEL(mercury__compare_3_3));
#else
- push(succip);
+ push(MR_succip);
push(type_arity);
call(compare_pred, LABEL(mercury__compare_3_0_i1),
LABEL(mercury__compare_3_3));
@@ -456,7 +456,7 @@
int type_arity;
type_arity = pop();
- succip = pop();
+ MR_succip = pop();
save_registers();
r2 = virtual_reg(type_arity + 1);
proceed();
Index: calls.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/calls.h,v
retrieving revision 1.4
diff -u -r1.4 calls.h
--- calls.h 1997/07/27 15:08:02 1.4
+++ calls.h 1997/11/10 23:10:25
@@ -9,7 +9,7 @@
#ifndef CALLS_H
#define CALLS_H
-#include "regs.h" /* for succip */
+#include "regs.h" /* for MR_succip */
#include "goto.h" /* calls are implemented using gotos */
#include "debug.h" /* we need to debug them */
#include "prof.h" /* we need to profile them */
@@ -17,7 +17,7 @@
#define noprof_localcall(label, succ_cont) \
do { \
debugcall(LABEL(label), (succ_cont)); \
- succip = (succ_cont); \
+ MR_succip = (succ_cont); \
set_prof_current_proc(LABEL(label)); \
GOTO_LABEL(label); \
} while (0)
@@ -32,7 +32,7 @@
({ \
__label__ fixup_gp; \
debugcall((proc), (succ_cont)); \
- succip = (&&fixup_gp); \
+ MR_succip = (&&fixup_gp); \
set_prof_current_proc(proc); \
GOTO(proc); \
fixup_gp: \
@@ -44,7 +44,7 @@
({ \
__label__ fixup_gp; \
debugcall((proc), (succ_cont)); \
- succip = (&&fixup_gp); \
+ MR_succip = (&&fixup_gp); \
set_prof_current_proc(proc); \
GOTO(proc); \
fixup_gp: \
@@ -55,7 +55,7 @@
#define noprof_call(proc, succ_cont) \
do { \
debugcall((proc), (succ_cont)); \
- succip = (succ_cont); \
+ MR_succip = (succ_cont); \
set_prof_current_proc(proc); \
GOTO(proc); \
} while (0)
@@ -66,7 +66,7 @@
#define localcall(label, succ_cont, current_label) \
do { \
debugcall(LABEL(label), (succ_cont)); \
- succip = (succ_cont); \
+ MR_succip = (succ_cont); \
PROFILE(LABEL(label), (current_label)); \
set_prof_current_proc(LABEL(label)); \
GOTO_LABEL(label); \
@@ -81,7 +81,7 @@
#define call_localret(proc, succ_cont, current_label) \
do { \
PROFILE((proc), (current_label)); \
- noprof_call_localret(proc, succ_cont); \
+ noprof_call_localret(proc, succ_cont); \
} while (0)
#define call_det_closure(succ_cont, current_label) \
@@ -124,7 +124,7 @@
#define proceed() \
do { \
debugproceed(); \
- GOTO(succip); \
+ GOTO(MR_succip); \
} while (0)
#endif /* not CALLS_H */
Index: context.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/context.h,v
retrieving revision 1.8
diff -u -r1.8 context.h
--- context.h 1997/09/05 23:19:52 1.8
+++ context.h 1997/11/11 03:52:29
@@ -122,7 +122,7 @@
Word *context_hp;
/* saved hp for this context */
- Word *min_heap_reclamation_point;
+ Word *min_hp_rec;
/*
** this pointer marks the minimum value of hp to which we can
** truncate the heap on backtracking. See comments before the
@@ -232,30 +232,15 @@
extern int my_procnum;
extern pid_t my_procid;
-/*
-** The minimum value of hp to which the current context
-** may truncate the heap on backtracking. see the comments
-** below next to the set_min_heap_reclamation_point macro.
-*/
-extern Word *min_heap_reclamation_point;
-
/* do a context switch */
Declare_entry(do_runnext);
#define runnext() GOTO(ENTRY(do_runnext));
/*
** schedule(Context *cptr, Code *resume):
-** setup a call to do_schedule which
-** adds the context pointed to by `cptr' to the runqueue then
-** branches to `resume'.
-*/
-Declare_entry(do_schedule);
-extern Context *do_schedule_cptr;
-extern Code *do_schedule_resume;
-#define schedule(cptr, resume) do { \
- do_schedule_cptr = (Context *)(cptr); \
- do_schedule_resume = (Code *)(resume); \
- GOTO(ENTRY(do_schedule)); \
+*/
+#define schedule(cptr, resume) do { \
+ fatal_error("schedule not implemented"); \
} while(0)
/*
@@ -292,7 +277,7 @@
**
** If hp > context_hp, another context has allocated data on the heap since
** we were last scheduled, so the furthest back that we can reclaim is to
-** the current value of hp, so we set min_heap_reclamation_point and the
+** the current value of hp, so we set MR_min_hp_rec and the
** field of the same name in our context structure.
**
** If hp < context_hp, then another context has truncated the heap on failure.
@@ -314,20 +299,18 @@
if (hp != (ctxt)->context_hp \
|| (ctxt)->context_hp == NULL) \
{ \
- min_heap_reclamation_point = hp; \
- (ctxt)->min_heap_reclamation_point = hp;\
+ MR_min_hp_rec = hp; \
+ (ctxt)->min_hp_rec = hp;\
} \
else \
{ \
- min_heap_reclamation_point = \
- (ctxt)->min_heap_reclamation_point;\
+ MR_min_hp_rec = (ctxt)->min_hp_rec; \
} \
} while (0)
#define save_hp_in_context(ctxt) do { \
(ctxt)->context_hp = hp; \
- (ctxt)->min_heap_reclamation_point = \
- min_heap_reclamation_point; \
+ (ctxt)->min_hp_rec = MR_min_hp_rec; \
} while (0)
#else
@@ -347,12 +330,12 @@
#define load_context(cptr) do { \
Context *load_context_c; \
load_context_c = (cptr); \
- succip = load_context_c->context_succip; \
+ MR_succip = load_context_c->context_succip; \
detstack_zone = load_context_c->detstack_zone; \
- sp = load_context_c->context_sp; \
+ MR_sp = load_context_c->context_sp; \
nondetstack_zone = load_context_c->nondetstack_zone; \
- maxfr = load_context_c->context_maxfr; \
- curfr = load_context_c->context_curfr; \
+ MR_maxfr = load_context_c->context_maxfr; \
+ MR_curfr = load_context_c->context_curfr; \
MR_IF_USE_TRAIL( \
MR_trail_zone = load_context_c->trail_zone; \
MR_trail_ptr = load_context_c->context_trail_ptr; \
@@ -365,12 +348,12 @@
#define save_context(cptr) do { \
Context *save_context_c; \
save_context_c = (cptr); \
- save_context_c->context_succip = succip; \
+ save_context_c->context_succip = MR_succip; \
save_context_c->detstack_zone = detstack_zone; \
- save_context_c->context_sp = sp; \
+ save_context_c->context_sp = MR_sp; \
save_context_c->nondetstack_zone = nondetstack_zone; \
- save_context_c->context_maxfr = maxfr; \
- save_context_c->context_curfr = curfr; \
+ save_context_c->context_maxfr = MR_maxfr; \
+ save_context_c->context_curfr = MR_curfr; \
MR_IF_USE_TRAIL( \
save_context_c->trail_zone = MR_trail_zone; \
save_context_c->context_trail_ptr = MR_trail_ptr; \
@@ -400,20 +383,12 @@
#define SYNC_TERM_COUNTER 1
#define SYNC_TERM_PARENT 2
-Declare_entry(do_join_and_terminate);
-extern Word *do_join_and_terminate_sync_term;
#define join_and_terminate(sync_term) do { \
- do_join_and_terminate_sync_term = (Word *)(sync_term); \
- GOTO(ENTRY(do_join_and_terminate)); \
+ fatal_error("join_and_terminate not implemented"); \
} while (0)
-Declare_entry(do_join_and_continue);
-extern Word *do_join_and_continue_sync_term;
-extern Code *do_join_and_continue_where_to;
#define join_and_continue(sync_term, where_to) do { \
- do_join_and_continue_sync_term = (Word *)(sync_term); \
- do_join_and_continue_where_to = (Code *)(where_to); \
- GOTO(ENTRY(do_join_and_continue)); \
+ fatal_error("join_and_continue not implemented"); \
} while (0)
#endif
Index: context.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/context.mod,v
retrieving revision 1.11
diff -u -r1.11 context.mod
--- context.mod 1997/10/12 13:41:32 1.11
+++ context.mod 1997/11/11 03:48:59
@@ -17,125 +17,21 @@
#include "context.h"
#include "engine.h" /* for `memdebug' */
-#ifdef PARALLEL
-unsigned numprocs = 1;
-#endif
-
-#ifdef PARALLEL
-pid_t *procid;
-AtomicBool *procwaiting;
-#endif
-int my_procnum;
-pid_t my_procid;
-Word *min_heap_reclamation_point;
-
Context *this_context;
-Context **runqueue_ptr;
-Context **free_context_list_ptr;
-SpinLock *runqueue_lock;
-SpinLock *free_context_list_lock;
-
-Context *do_schedule_cptr;
-Code *do_schedule_resume;
-Word *do_join_and_terminate_sync_term;
-Word *do_join_and_continue_sync_term;
-Code *do_join_and_continue_where_to;
-
-static void init_free_context_list(void);
-
-void
-init_processes(void)
-{
- int i;
- pid_t pid;
-
- my_procnum = 0;
- my_procid = getpid();
-
- runqueue_lock = allocate_lock();
- runqueue_ptr = allocate_object(Context *);
- *runqueue_ptr = NULL;
-
-#ifdef PARALLEL
- procid = allocate_array(pid_t, numprocs);
- procwaiting = allocate_array(AtomicBool, numprocs);
- procid[0] = my_procid;
- procwaiting[0] = FALSE;
-
- for (i = 1; i < numprocs; i++) {
- if ((pid = fork()) < 0) {
- fatal_error("failed to fork()");
- }
- if (pid == 0) { /* child */
- my_procnum = i;
- procid[i] = my_procid = getpid();
- procwaiting[i] = FALSE;
- return;
- }
- }
-#endif
-
-}
-
-void
-shutdown_processes(void)
-{
-#ifdef PARALLEL
- /* XXX not yet implemented */
- if (numprocs > 1) {
- fprintf(stderr, "Mercury runtime: shutdown_processes()"
- " not yet implemented\n");
- }
-#endif
-}
+static Context *free_context_list = NULL;
void
init_process_context(void)
{
- /*
- ** Each process has its own heap, in shared memory;
- ** each process may only allocate from its own heap,
- ** although it may access or modify data allocated
- ** by other processes in different heaps.
- */
init_heap();
- if (my_procnum == 0) { /* the original process */
- init_free_context_list();
- this_context = new_context();
- /* load the registers so we don't clobber hp */
- restore_transient_registers();
- load_context(this_context);
- save_transient_registers();
-
- if (memdebug) debug_memory();
- }
-}
-
-static void
-init_free_context_list(void)
-{
- int i;
- Context *tmp;
+ this_context = new_context();
+ /* load the registers so we don't clobber hp */
+ restore_transient_registers();
+ load_context(this_context);
+ save_transient_registers();
- free_context_list_lock = allocate_lock();
- free_context_list_ptr = allocate_object(Context *);
- *free_context_list_ptr = allocate_array(Context, INITIAL_NUM_CONTEXTS);
- tmp = *free_context_list_ptr;
- for (i = 0; i < INITIAL_NUM_CONTEXTS; i++) {
- if (i != INITIAL_NUM_CONTEXTS - 1) {
- tmp[i].next = &(tmp[i+1]);
- } else {
- tmp[i].next = NULL;
- }
- tmp[i].resume = NULL;
- tmp[i].context_succip = NULL;
- tmp[i].detstack_zone = NULL;
- tmp[i].context_sp = NULL;
- tmp[i].nondetstack_zone = NULL;
- tmp[i].context_curfr = NULL;
- tmp[i].context_maxfr = NULL;
- }
+ if (memdebug) debug_memory();
}
Context *
@@ -143,16 +39,17 @@
{
Context *c;
- get_lock(free_context_list_lock);
-
- MR_assert(free_context_list_ptr != NULL);
- if (*free_context_list_ptr == NULL) {
- fatal_error("no free contexts");
+ if (free_context_list == NULL) {
+ c = (Context *) make(Context);
+ c->detstack_zone = NULL;
+ c->nondetstack_zone = NULL;
+#ifdef MR_USE_TRAIL
+ c->trail_zone = NULL;
+#endif
} else {
- c = *free_context_list_ptr;
- *free_context_list_ptr = c->next;
+ c = free_context_list;
+ free_context_list = c->next;
}
- release_lock(free_context_list_lock);
c->next = NULL;
c->resume = NULL;
@@ -201,11 +98,8 @@
void
delete_context(Context *c)
{
- get_lock(free_context_list_lock);
- MR_assert(free_context_list_ptr != NULL);
- c->next = *free_context_list_ptr;
- *free_context_list_ptr = c;
- release_lock(free_context_list_lock);
+ c->next = free_context_list;
+ free_context_list = c;
}
void
@@ -214,184 +108,3 @@
fatal_error("computation floundered");
}
-BEGIN_MODULE(context_module)
-
-BEGIN_CODE
-
- /*
- ** do a context switch: the previous context is assumed to have
- ** been saved or deallocated or whatever.
- */
-do_runnext:
- while(1) {
-#ifdef PARALLEL
- /* If we're running in parallel, then we need to
- ** do some signal magic in order to avoid a race-
- ** condition if we have to suspend, waiting for
- ** the runqueue to become non-empty.
- ** The following algorithm is adapted from
- ** "Advanced Programming in the UNIX Environment",
- ** Stevens:
- ** - use sigprocmask to block SIGUSR1
- ** - obtain the spinlock on the runqueue
- ** - if the runqueue is not empty, get the
- ** next context off the queue, release the
- ** lock and reset the signal mask.
- ** - if the runqueue is empty, mark this process
- ** as waiting, release the lock and then
- ** use sigsuspend to atomically renable SIGUSR1
- ** and suspend the process. When we get a
- ** SIGUSR1 we resume and mark the process as not
- ** waiting, then try again to get a context off
- ** the runqueue.
- ** - this relies on the schedule code to send the
- ** SIGUSR1 signal while it has the spinlock to
- ** ensure that this process will only get sent
- ** a single signal.
- */
- sigset_t newset, oldset, emptyset;
- sigemptyset(&newset);
- sigemptyset(&emptyset);
- sigaddset(&newset, SIGUSR1);
- /* block SIGUSR1 while we're in the critical region */
- sigprocmask(SIG_BLOCK, &newset, &oldset);
-#endif
- get_lock(runqueue_lock);
- if (*runqueue_ptr != NULL) {
- this_context = *runqueue_ptr;
- *runqueue_ptr = (*runqueue_ptr)->next;
- release_lock(runqueue_lock);
-#ifdef PARALLEL
- /* restore the original set of signals */
- sigprocmask(SIG_SETMASK, &oldset, NULL);
-#endif
- load_context(this_context);
- GOTO(this_context->resume);
- }
- else
- {
-#ifdef PARALLEL
- int i;
- bool is_runnable;
-
- procwaiting[my_procnum] = TRUE;
-
- /*
- ** check to see that at least one process
- ** is currently runnable. If none are, then
- ** we've just floundered.
- */
- is_runnable = FALSE;
- for(i = 0; i < numprocs; i++)
- {
- if (procwaiting[i] == FALSE)
- {
- is_runnable = TRUE;
- break;
- }
- }
- if (!is_runnable)
- flounder();
-
-#endif
- release_lock(runqueue_lock);
-#ifdef PARALLEL
- sigsuspend(&emptyset);
- procwaiting[my_procnum] = FALSE;
-#else
- /* if we're not using parallelism, then
- ** the runqueue should never be empty.
- */
- flounder();
-#endif
- }
- }
-
- /*
- ** do_schedule adds the context pointed to by do_schedule_cptr
- ** to the runqueue, signalling a sleeping process to wake it if
- ** the runqueue was previously empty.
- */
-do_schedule:
-{
- Context *old;
-
- get_lock(runqueue_lock);
- old = *runqueue_ptr;
- do_schedule_cptr->next = *runqueue_ptr;
- *runqueue_ptr = do_schedule_cptr;
-#ifdef PARALLEL
- /* Check to see if we need to signal a sleeping process */
- if (old == NULL) {
- int i;
- for(i = 0; i < numprocs; i++) {
- if (procwaiting[i] == TRUE) {
- kill(procid[i], SIGUSR1);
- break;
- }
- }
- }
-#endif
- release_lock(runqueue_lock);
- GOTO(do_schedule_resume);
-}
-
- /*
- ** do_join_and_terminate synchronises with the structure pointed to
- ** by do_join_and_terminate_sync_term, then terminates the current
- ** context and does a context switch. If the current context was the
- ** last context to arrive at the synchronisation point, then we
- ** resume the parent context rather than do a context switch.
- */
-do_join_and_terminate:
-{
- register Word *sync_term;
- Context *ctxt;
-
- sync_term = do_join_and_terminate_sync_term;
-
- get_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- if (--(sync_term[SYNC_TERM_COUNTER]) == 0) {
- MR_assert(sync_term[SYNC_TERM_PARENT] != NULL);
- release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- ctxt = (Context *) sync_term[SYNC_TERM_PARENT];
- delete_context(this_context);
- this_context = ctxt;
- load_context(this_context);
- GOTO(this_context->resume);
- } else {
- release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- delete_context(this_context);
- runnext();
- }
-}
-
- /*
- ** do_join_and_continue synchronises with the structure pointed to
- ** by do_join_and_continue_sync_term. If we are the last context to
- ** arrive here, then we branch to the continuation stored in
- ** do_join_and_continue_where_to. If we have to wait for other contexts
- ** to arrive, then we save the current context and store a pointer
- ** to it in the synchronisation term before doing a context switch.
- */
-do_join_and_continue:
-{
- register Word *sync_term;
-
- sync_term = do_join_and_continue_sync_term;
-
- get_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- if (--(sync_term[SYNC_TERM_COUNTER]) == 0) {
- MR_assert(sync_term[SYNC_TERM_PARENT] == NULL);
- release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- GOTO(do_join_and_continue_where_to);
- } else {
- save_context(this_context);
- this_context->resume = do_join_and_continue_where_to;
- sync_term[SYNC_TERM_PARENT] = (Word) this_context;
- release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
- runnext();
- }
-}
-
-END_MODULE
Index: engine.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/engine.h,v
retrieving revision 1.15
diff -u -r1.15 engine.h
--- engine.h 1997/10/02 01:50:24 1.15
+++ engine.h 1997/11/10 01:39:02
@@ -89,7 +89,7 @@
** - The general-purpose registers r1, r2... are not restored and must
** be saved by the caller.
** - In grades without conservative garbage collection, the caller
- ** must save and restore hp, solutions_heap_pointer, heap_zone
+ ** must save and restore hp, sol_hp, heap_zone
** and solutions_heap_zone.
*/
#define MR_setjmp(setjmp_env, longjmp_label) \
Index: engine.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/engine.mod,v
retrieving revision 1.44
diff -u -r1.44 engine.mod
--- engine.mod 1997/10/02 01:50:27 1.44
+++ engine.mod 1997/11/10 23:13:39
@@ -61,16 +61,8 @@
make_label("engine_done", LABEL(engine_done));
#endif
- init_processes();
init_process_context();
- if (my_procnum == 0) {
- return;
- } else {
- call_engine(ENTRY(do_runnext));
- /* not reached */
- MR_assert(FALSE);
- }
}
/*---------------------------------------------------------------------------*/
@@ -302,7 +294,7 @@
engine_init_registers(void)
{
restore_transient_registers();
- succip = engine_done;
+ MR_succip = engine_done;
return NULL;
}
@@ -390,8 +382,6 @@
** we don't bother to deallocate memory...
** that will happen automatically on process exit anyway.
*/
-
- shutdown_processes();
}
/*---------------------------------------------------------------------------*/
Index: heap.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/heap.h,v
retrieving revision 1.13
diff -u -r1.13 heap.h
--- heap.h 1997/07/27 15:08:18 1.13
+++ heap.h 1997/11/10 23:11:05
@@ -74,23 +74,23 @@
#define restore_hp(src) ((void)0)
/* we use `hp' as a convenient temporary here */
-#define hp_alloc(count) (incr_hp(hp,(count)), hp += (count), (void)0)
+#define hp_alloc(count) (incr_hp(MR_hp,(count)), MR_hp += (count), (void)0)
#define hp_alloc_atomic(count) \
- (incr_hp_atomic(hp,(count)), hp += (count), (void)0)
+ (incr_hp_atomic(MR_hp,(count)), MR_hp += (count), (void)0)
#else /* not CONSERVATIVE_GC */
#define tag_incr_hp(dest,tag,count) ( \
- (dest) = (Word)mkword(tag, (Word)hp), \
- debugincrhp(count, hp), \
- hp += (count), \
+ (dest) = (Word)mkword(tag, (Word)MR_hp), \
+ debugincrhp(count, MR_hp), \
+ MR_hp += (count), \
heap_overflow_check(), \
(void)0 \
)
#define tag_incr_hp_atomic(dest,tag,count) tag_incr_hp((dest),(tag),(count))
#define mark_hp(dest) ( \
- (dest) = (Word)hp, \
+ (dest) = (Word)MR_hp, \
(void)0 \
)
@@ -101,9 +101,9 @@
** the set_min_heap_reclamation_point() macro.
*/
#define restore_hp(src) ( \
- LVALUE_CAST(Word,hp) = \
- ( (Word) min_heap_reclamation_point < (src) ? \
- (src) : (Word) min_heap_reclamation_point ), \
+ LVALUE_CAST(Word,MR_hp) = \
+ ( (Word) MR_min_hp_rec < (src) ? \
+ (src) : (Word) MR_min_hp_rec ), \
(void)0 \
)
@@ -126,47 +126,47 @@
/* not by the automatically generated code */
#define create1(w1) ( \
hp_alloc(1), \
- hp[-1] = (Word) (w1), \
- debugcr1(hp[-1], hp), \
- /* return */ (Word) (hp - 1) \
+ MR_hp[-1] = (Word) (w1), \
+ debugcr1(MR_hp[-1], MR_hp), \
+ /* return */ (Word) (MR_hp - 1) \
)
/* used only by the hand-written example programs */
/* not by the automatically generated code */
#define create2(w1, w2) ( \
hp_alloc(2), \
- hp[-2] = (Word) (w1), \
- hp[-1] = (Word) (w2), \
- debugcr2(hp[-2], hp[-1], hp), \
- /* return */ (Word) (hp - 2) \
+ MR_hp[-2] = (Word) (w1), \
+ MR_hp[-1] = (Word) (w2), \
+ debugcr2(MR_hp[-2], MR_hp[-1], MR_hp), \
+ /* return */ (Word) (MR_hp - 2) \
)
/* used only by the hand-written example programs */
/* not by the automatically generated code */
#define create3(w1, w2, w3) ( \
hp_alloc(3), \
- hp[-3] = (Word) (w1), \
- hp[-2] = (Word) (w2), \
- hp[-1] = (Word) (w3), \
- /* return */ (Word) (hp - 3) \
+ MR_hp[-3] = (Word) (w1), \
+ MR_hp[-2] = (Word) (w2), \
+ MR_hp[-1] = (Word) (w3), \
+ /* return */ (Word) (MR_hp - 3) \
)
/* used only by the hand-written example programs */
/* not by the automatically generated code */
#define create2_bf(w1) ( \
- hp = hp + 2, \
- hp[-2] = (Word) (w1), \
+ MR_hp = MR_hp + 2, \
+ MR_hp[-2] = (Word) (w1), \
heap_overflow_check(), \
- /* return */ (Word) (hp - 2) \
+ /* return */ (Word) (MR_hp - 2) \
)
/* used only by the hand-written example programs */
/* not by the automatically generated code */
#define create2_fb(w2) ( \
- hp = hp + 2, \
- hp[-1] = (Word) (w2), \
+ MR_hp = MR_hp + 2, \
+ MR_hp[-1] = (Word) (w2), \
heap_overflow_check(), \
- /* return */ (Word) (hp - 2) \
+ /* return */ (Word) (MR_hp - 2) \
)
/*
Index: memory.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/memory.c,v
retrieving revision 1.77
diff -u -r1.77 memory.c
--- memory.c 1997/09/05 23:20:01 1.77
+++ memory.c 1997/11/10 23:15:04
@@ -183,7 +183,6 @@
#ifndef CONSERVATIVE_GC
MemoryZone *heap_zone;
MemoryZone *solutions_heap_zone;
- Word *solutions_heap_pointer;
#endif
#ifndef SPEED
MemoryZone *dumpstack_zone;
@@ -415,13 +414,15 @@
heap_zone_size, default_handler);
restore_transient_registers();
- hp = heap_zone->min;
+ MR_hp = heap_zone->min;
save_transient_registers();
solutions_heap_zone = create_zone("solutions_heap", 1,
solutions_heap_size, next_offset(),
solutions_heap_zone_size, default_handler);
- solutions_heap_pointer = solutions_heap_zone->min;
+ restore_transient_registers();
+ MR_sol_hp = solutions_heap_zone->min;
+ save_transient_registers();
#endif
Index: memory.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/memory.h,v
retrieving revision 1.28
diff -u -r1.28 memory.h
--- memory.h 1997/09/05 23:20:04 1.28
+++ memory.h 1997/11/10 01:38:36
@@ -130,7 +130,6 @@
#ifndef CONSERVATIVE_GC
extern MemoryZone *heap_zone;
extern MemoryZone *solutions_heap_zone;
-extern Word *solutions_heap_pointer;
#endif
#ifndef SPEED
Index: mercury_float.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_float.h,v
retrieving revision 1.6
diff -u -r1.6 mercury_float.h
--- mercury_float.h 1997/07/27 15:08:29 1.6
+++ mercury_float.h 1997/11/10 23:11:31
@@ -27,17 +27,17 @@
#ifdef CONSERVATIVE_GC
#define float_to_word(f) ( \
hp_alloc(FLOAT_WORDS), \
- *(Float *)(void *)(hp - FLOAT_WORDS) = (f), \
- /* return */ (Word) (hp - FLOAT_WORDS) \
+ *(Float *)(void *)(MR_hp - FLOAT_WORDS) = (f), \
+ /* return */ (Word) (MR_hp - FLOAT_WORDS) \
)
#else
/* we need to ensure that what we allocated on the heap is properly
aligned */
#define float_to_word(f) ( \
- ( (Word)hp & (sizeof(Float) - 1) ? hp_alloc(1) : (void)0 ), \
+ ( (Word)MR_hp & (sizeof(Float) - 1) ? hp_alloc(1) : (void)0 ), \
hp_alloc(FLOAT_WORDS), \
- *(Float *)(void *)(hp - FLOAT_WORDS) = (f), \
- /* return */ (Word) (hp - FLOAT_WORDS) \
+ *(Float *)(void *)(MR_hp - FLOAT_WORDS) = (f), \
+ /* return */ (Word) (MR_hp - FLOAT_WORDS) \
)
#endif
Index: overflow.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/overflow.h,v
retrieving revision 1.7
diff -u -r1.7 overflow.h
--- overflow.h 1997/07/27 15:08:34 1.7
+++ overflow.h 1997/11/10 23:12:43
@@ -26,29 +26,29 @@
#define heap_overflow_check() \
( \
- IF (hp >= heap_zone->top,( \
+ IF (MR_hp >= heap_zone->top,( \
fatal_error("heap overflow") \
)), \
- IF (hp > heap_zone->max,( \
- heap_zone->max = hp \
+ IF (MR_hp > heap_zone->max,( \
+ heap_zone->max = MR_hp \
)), \
(void)0 \
)
#define detstack_overflow_check() \
( \
- IF (sp >= detstack_zone->top,( \
+ IF (MR_sp >= detstack_zone->top,( \
fatal_error("stack overflow") \
)), \
- IF (sp > detstack_zone->max,( \
- detstack_zone->max = sp \
+ IF (MR_sp > detstack_zone->max,( \
+ detstack_zone->max = MR_sp \
)), \
(void)0 \
)
#define detstack_underflow_check() \
( \
- IF (sp < detstack_zone->min,( \
+ IF (MR_sp < detstack_zone->min,( \
fatal_error("stack underflow") \
)), \
(void)0 \
@@ -56,18 +56,18 @@
#define nondstack_overflow_check() \
( \
- IF (maxfr >= nondetstack_zone->top,( \
+ IF (MR_maxfr >= nondetstack_zone->top,( \
fatal_error("nondetstack overflow") \
)), \
- IF (maxfr > nondetstack_zone->max,( \
- nondetstack_zone->max = maxfr \
+ IF (MR_maxfr > nondetstack_zone->max,( \
+ nondetstack_zone->max = MR_maxfr \
)), \
(void)0 \
)
#define nondstack_underflow_check() \
( \
- IF (maxfr < nondetstack_zone->min,( \
+ IF (MR_maxfr < nondetstack_zone->min,( \
fatal_error("nondetstack underflow") \
)), \
(void)0 \
Index: regorder.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/regorder.h,v
retrieving revision 1.18
diff -u -r1.18 regorder.h
--- regorder.h 1997/08/23 22:34:18 1.18
+++ regorder.h 1997/11/10 23:12:54
@@ -55,11 +55,20 @@
#define r31 count_usage(R_RN(31), mr35)
#define r32 count_usage(R_RN(32), mr36)
-#define succip LVALUE_CAST(Code *, count_usage(SI_RN, mr1))
-#define hp LVALUE_CAST(Word *, count_usage(HP_RN, mr5))
-#define sp LVALUE_CAST(Word *, count_usage(SP_RN, mr0))
-#define curfr LVALUE_CAST(Word *, count_usage(CF_RN, mr8))
-#define maxfr LVALUE_CAST(Word *, count_usage(MF_RN, mr9))
+#define MR_succip LVALUE_CAST(Code *, count_usage(MR_SI_RN, mr1))
+#define succip MR_succip
+#define MR_hp LVALUE_CAST(Word *, count_usage(MR_HP_RN, mr5))
+#define hp MR_hp
+#define MR_sp LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
+#define sp MR_sp
+#define MR_curfr LVALUE_CAST(Word *, count_usage(MR_CF_RN, mr8))
+#define curfr MR_curfr
+#define MR_maxfr LVALUE_CAST(Word *, count_usage(MR_MF_RN, mr9))
+#define maxfr MR_maxfr
+#define MR_sol_hp LVALUE_CAST(Word *, count_usage(MR_SOL_HP_RN, mr(37)))
+#define MR_min_hp_rec LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, mr(38)))
+#define MR_min_sol_hp_rec LVALUE_CAST(Word *, \
+ count_usage(MR_MIN_HP_REC, mr39))
#define MR_trail_ptr count_usage(MR_TRAIL_PTR_RN, MR_trail_ptr_var)
#define MR_ticket_counter \
Index: regs.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/regs.h,v
retrieving revision 1.31
diff -u -r1.31 regs.h
--- regs.h 1997/08/23 22:34:17 1.31
+++ regs.h 1997/11/04 01:18:22
@@ -148,15 +148,18 @@
** print_register_usage_counts() in wrapper.mod.
*/
-#define SI_RN 0
-#define R_RN(n) (n)
-#define ORD_RN MAX_REAL_REG
-#define HP_RN (ORD_RN + 1)
-#define SP_RN (ORD_RN + 2)
-#define CF_RN (ORD_RN + 3)
-#define MF_RN (ORD_RN + 4)
-#define MR_TRAIL_PTR_RN (ORD_RN + 5)
-#define MR_TICKET_COUNTER_RN (ORD_RN + 6)
-#define MAX_RN (ORD_RN + 7)
+#define MR_SI_RN 0
+#define MR_R_RN(n) (n)
+#define MR_ORD_RN MAX_REAL_REG
+#define MR_HP_RN (MR_ORD_RN + 1)
+#define MR_SP_RN (MR_ORD_RN + 2)
+#define MR_CF_RN (MR_ORD_RN + 3)
+#define MR_MF_RN (MR_ORD_RN + 4)
+#define MR_TRAIL_PTR_RN (MR_ORD_RN + 5)
+#define MR_TICKET_COUNTER_RN (MR_ORD_RN + 6)
+#define MR_SOL_HP_RN (MR_ORD_RN + 7)
+#define MR_MIN_HP_REC (MR_ORD_RN + 8)
+#define MR_MIN_SOL_HP_REC (MR_ORD_RN + 9)
+#define MAX_RN (MR_ORD_RN + 10)
#endif /* not REGS_H */
Index: stacks.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/stacks.h,v
retrieving revision 1.9
diff -u -r1.9 stacks.h
--- stacks.h 1997/07/27 15:08:43 1.9
+++ stacks.h 1997/11/10 23:13:05
@@ -17,53 +17,53 @@
/* DEFINITIONS FOR MANIPULATING THE DET STACK */
-#define detstackvar(n) sp[-n]
+#define detstackvar(n) (MR_sp[-n])
#define incr_sp_push_msg(n, msg) \
( \
- debugincrsp(n, sp), \
+ debugincrsp(n, MR_sp), \
dump_push_msg(msg), \
- sp = sp + (n), \
+ MR_sp = MR_sp + (n), \
detstack_overflow_check(), \
(void)0 \
)
#define decr_sp_pop_msg(n) \
( \
- debugdecrsp(n, sp), \
+ debugdecrsp(n, MR_sp), \
dump_pop_msg(), \
- sp = sp - (n), \
+ MR_sp = MR_sp - (n), \
detstack_underflow_check(), \
(void)0 \
)
#define incr_sp(n) ( \
- debugincrsp(n, sp), \
- sp = sp + (n), \
+ debugincrsp(n, MR_sp), \
+ MR_sp = MR_sp + (n), \
detstack_overflow_check(), \
(void)0 \
)
#define decr_sp(n) ( \
- debugdecrsp(n, sp), \
- sp = sp - (n), \
+ debugdecrsp(n, MR_sp), \
+ MR_sp = MR_sp - (n), \
detstack_underflow_check(), \
(void)0 \
)
#define push(w) ( \
- *sp = (Word) (w), \
- debugpush(*sp, sp), \
- sp = sp + 1, \
+ *MR_sp = (Word) (w), \
+ debugpush(*sp, MR_sp), \
+ MR_sp = MR_sp + 1, \
detstack_overflow_check(), \
(void)0 \
)
#define pop() ( \
- sp = sp - 1, \
- debugpop(*sp, sp), \
+ MR_sp = MR_sp - 1, \
+ debugpop(*MR_sp, MR_sp), \
detstack_underflow_check(), \
- /* return */ *sp \
+ /* return */ *MR_sp \
)
/* DEFINITIONS FOR NONDET STACK FRAMES */
@@ -93,12 +93,12 @@
#define bt_succfr(fr) LVALUE_CAST(Word *, ((Word *) (fr))[SUCCFR])
#define bt_var(fr,n) (((Word *) (fr))[SAVEVAL-(n)])
-#define curprednm bt_prednm(curfr)
-#define curredoip bt_redoip(curfr)
-#define curprevfr bt_prevfr(curfr)
-#define cursuccip bt_succip(curfr)
-#define cursuccfr bt_succfr(curfr)
-#define framevar(n) bt_var(curfr,n)
+#define curprednm bt_prednm(MR_curfr)
+#define curredoip bt_redoip(MR_curfr)
+#define curprevfr bt_prevfr(MR_curfr)
+#define curMR_succip bt_succip(MR_curfr)
+#define cursuccfr bt_succfr(MR_curfr)
+#define framevar(n) bt_var(MR_curfr,n)
/* DEFINITIONS FOR MANIPULATING THE NONDET STACK */
@@ -114,13 +114,13 @@
reg Word *prevfr; \
reg Word *succfr; \
\
- prevfr = maxfr; \
- succfr = curfr; \
- maxfr += (NONDET_FIXED_SIZE + numslots);\
- curfr = maxfr; \
+ prevfr = MR_maxfr; \
+ succfr = MR_curfr; \
+ MR_maxfr += (NONDET_FIXED_SIZE + numslots);\
+ MR_curfr = MR_maxfr; \
curredoip = redoip; \
curprevfr = prevfr; \
- cursuccip = succip; \
+ curMR_succip = MR_succip; \
cursuccfr = succfr; \
mkframe_save_prednm(prednm); \
debugmkframe(); \
@@ -140,8 +140,8 @@
reg Word *childfr; \
\
debugsucceed(); \
- childfr = curfr; \
- curfr = cursuccfr; \
+ childfr = MR_curfr; \
+ MR_curfr = cursuccfr; \
GOTO(bt_succip(childfr)); \
} while (0)
@@ -150,17 +150,17 @@
reg Word *childfr; \
\
debugsucceeddiscard(); \
- childfr = curfr; \
- maxfr = curprevfr; \
- curfr = cursuccfr; \
+ childfr = MR_curfr; \
+ MR_maxfr = curprevfr; \
+ MR_curfr = cursuccfr; \
GOTO(bt_succip(childfr)); \
} while (0)
#define fail() do { \
debugfail(); \
- maxfr = curprevfr; \
- curfr = maxfr; \
+ MR_maxfr = curprevfr; \
+ MR_curfr = MR_maxfr; \
nondstack_underflow_check(); \
GOTO(curredoip); \
} while (0)
@@ -168,7 +168,7 @@
#define redo() do { \
debugredo(); \
- curfr = maxfr; \
+ MR_curfr = MR_maxfr; \
GOTO(curredoip); \
} while (0)
Index: wrapper.mod
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/wrapper.mod,v
retrieving revision 1.81
diff -u -r1.81 wrapper.mod
--- wrapper.mod 1997/10/01 13:22:27 1.81
+++ wrapper.mod 1997/11/10 23:13:46
@@ -830,9 +830,9 @@
BEGIN_CODE
do_interpreter:
- push(hp);
- push(succip);
- push(maxfr);
+ push(MR_hp);
+ push(MR_succip);
+ push(MR_maxfr);
mkframe("interpreter", 1, LABEL(global_fail));
if (program_entry_point == NULL) {
@@ -880,9 +880,9 @@
prof_output_addr_pair_table();
#endif
- maxfr = (Word *) pop();
- succip = (Code *) pop();
- hp = (Word *) pop();
+ MR_maxfr = (Word *) pop();
+ MR_succip = (Code *) pop();
+ MR_hp = (Word *) pop();
#ifndef SPEED
if (finaldebug && detaildebug) {
cvs diff: Diffing machdeps
More information about the developers
mailing list