more patches to support Anderson's JIT.

This commit is contained in:
Vitor Santos Costa 2009-04-08 00:32:36 +01:00
parent b2ad3bd000
commit b92b026c90
12 changed files with 77 additions and 10 deletions

View File

@ -1969,7 +1969,6 @@ YAP_Init(YAP_init_args *yap_init)
} else {
Heap = yap_init->HeapSize;
}
/* tell the system who should cope with interruptions */
Yap_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts;
Yap_InitWorkspace(Heap, Stack, Trail, Atts,
yap_init->MaxTableSpaceSize,
@ -2010,6 +2009,8 @@ YAP_Init(YAP_init_args *yap_init)
*/
yap_flags[HALT_AFTER_CONSULT_FLAG] = yap_init->HaltAfterConsult;
}
/* tell the system who should cope with interruptions */
Yap_ExecutionMode = yap_init->ExecutionMode;
if (yap_init->SavedState != NULL ||
yap_init->YapPrologBootFile == NULL) {
#if SUPPORT_CONDOR || SUPPORT_THREADS
@ -2131,6 +2132,7 @@ YAP_FastInit(char saved_state[])
init_args.SchedulerLoop = 10;
init_args.DelayedReleaseLoad = 3;
init_args.PrologShouldHandleInterrupts = FALSE;
init_args.ExecutionMode = INTERPRETED;
init_args.Argc = 0;
init_args.Argv = NULL;
init_args.ErrorNo = 0;

View File

@ -2098,6 +2098,8 @@ c_head(Term t, compiler_struct *cglobs)
Yap_emit(run_op,Zero,(unsigned long) cglobs->cint.CurrentPred,&cglobs->cint);
}
#endif
if (Yap_ExecutionMode == MIXED_MODE_USER)
Yap_emit(native_op, 0, 0, &cglobs->cint);
c_args(t, 0, cglobs);
}

View File

@ -995,6 +995,13 @@ has_cut(yamop *pc)
break;
case _execute:
case _dexecute:
case _p_execute_cpred:
pc = NEXTOP(pc,pp);
break;
case _native_me:
pc = NEXTOP(pc,aFlp);
break;
case _dexecute:
case _p_execute_cpred:
pc = NEXTOP(pc,pp);
break;
@ -1539,6 +1546,8 @@ move_next(ClauseDef *clause, UInt regno)
op_numbers op = Yap_op_from_opcode(cl->opc);
switch (op) {
case _native_me:
return;
case _p_db_ref_x:
case _p_float_x:
if (wreg == cl->u.xl.x) {

View File

@ -964,6 +964,7 @@ static void
InitCodes(void)
{
/* initialise invisible chain */
Yap_heap_regs->execution_mode = INTERPRETED;
Yap_heap_regs->invisiblechain.Entry = NIL;
INIT_RWLOCK(Yap_heap_regs->invisiblechain.AERWLock);
#include "iatoms.h"

View File

@ -224,6 +224,7 @@ typedef struct various_codes {
UInt hole_size;
struct malloc_state *av_;
yap_exec_mode execution_mode;
UInt atts_size;
UInt clause_space, index_space_Tree, index_space_EXT, index_space_SW;
UInt lu_clause_space, lu_index_space_Tree, lu_index_space_CP, lu_index_space_EXT, lu_index_space_SW;
@ -471,6 +472,7 @@ extern struct various_codes *Yap_heap_regs;
#define Yap_HoleSize Yap_heap_regs->hole_size
#define Yap_av Yap_heap_regs->av_
#define Yap_ExecutionMode Yap_heap_regs->execution_mode
#define Yap_AttsSize Yap_heap_regs->atts_size
#define Yap_ClauseSpace Yap_heap_regs->clause_space
#define Yap_IndexSpace_Tree Yap_heap_regs->index_space_Tree

12
H/Yap.h
View File

@ -1284,3 +1284,15 @@ extern char emacs_tmp[], emacs_tmp2[];
#include "sbaunify.h"
#endif
/********* execution mode ***********************/
typedef enum
{
INTERPRETED, /* interpreted */
MIXED_MODE_USER, /* mixed mode only for user predicates */
MIXED_MODE_ALL, /* mixed mode for all predicates */
COMPILE_USER, /* compile all user predicates*/
COMPILE_ALL /* compile all predicates */
} yap_exec_mode;

View File

@ -331,12 +331,14 @@ typedef struct yami {
CELL next;
} Otapl;
struct {
COUNT n; /* call counter */
CPredicate native; /* native code pointer */
struct yami *native_next; /* next instruction to execute
after native code
if the predicate was not fully compiled */
struct pred_entry *p; /* Pointer to pred */
/* call counter */
COUNT n;
/* native code pointer */
CPredicate native;
/* next instruction to execute after native code if the predicate was not fully compiled */
struct yami *native_next;
/* Pointer to pred */
struct pred_entry *p;
CELL next;
} aFlp;
/* The next two instructions are twin: they both correspond to the old ldd. */

View File

@ -9,6 +9,9 @@
case _alloc_for_logical_pred:
cl = NEXTOP(cl,L);
break;
case _native_me:
cl = NEXTOP(cl,aFlp);
break;
case _write_atom:
cl = NEXTOP(cl,c);
break;

View File

@ -6,6 +6,9 @@
while (TRUE) {
op_numbers op = Yap_op_from_opcode(cl->opc);
switch (op) {
case _native_me:
cl = NEXTOP(cl,aFlp);
break;
case _get_2atoms:
if (iarg == Yap_regnotoreg(1)) {
clause->Tag = cl->u.cc.c1;

View File

@ -129,7 +129,7 @@ restore_opcodes(yamop *pc)
pc->u.aFlp.n = ArityAdjust(pc->u.aFlp.n);
pc->u.aFlp.native = ExternalFunctionAdjust(pc->u.aFlp.native);
pc->u.aFlp.native_next = PtoOpAdjust(pc->u.aFlp.native_next);
pc->u.aFlp.native = PtoPredAdjust(pc->u.aFlp.native);
pc->u.aFlp.p = PtoPredAdjust(pc->u.aFlp.p);
pc = NEXTOP(pc,aFlp);
break;
/* instructions type c */

View File

@ -237,6 +237,13 @@ print_usage(void)
DefStackSpace, MinStackSpace);
fprintf(stderr," -t Trail area in Kbytes (default: %d, minimum: %d)\n",
DefTrailSpace, MinTrailSpace);
fprintf(stderr,"\n[Execution Modes]\n");
fprintf(stderr," -J0 Interpreted mode (default)\n");
fprintf(stderr," -J1 Mixed mode only for user predicates\n");
fprintf(stderr," -J2 Mixed mode for all predicates\n");
fprintf(stderr," -J3 Compile all user predicates\n");
fprintf(stderr," -J4 Compile all predicates\n");
#ifdef TABLING
fprintf(stderr," -ts Maximum table space area in Mbytes (default: unlimited)\n");
#endif /* TABLING */
@ -422,6 +429,30 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
mpwshell = TRUE;
break;
#endif
// execution mode
case 'J':
switch (p[1]) {
case '0':
iap->ExecutionMode = YAPC_INTERPRETED;
break;
case '1':
iap->ExecutionMode = YAPC_MIXED_MODE_USER;
break;
case '2':
iap->ExecutionMode = YAPC_MIXED_MODE_ALL;
break;
case '3':
iap->ExecutionMode = YAPC_COMPILE_USER;
break;
case '4':
iap->ExecutionMode = YAPC_COMPILE_ALL;
break;
default:
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c%c ]\n", *p, p[1]);
exit(EXIT_FAILURE);
}
p++;
break;
case 's':
case 'S':
case 'G':
@ -691,6 +722,7 @@ init_standard_system(int argc, char *argv[], YAP_init_args *iap)
iap->SchedulerLoop = DEFAULT_SCHEDULERLOOP;
iap->DelayedReleaseLoad = DEFAULT_DELAYEDRELEASELOAD;
iap->PrologShouldHandleInterrupts = TRUE;
iap->ExecutionMode = YAPC_INTERPRETED;
iap->Argc = argc;
iap->Argv = argv;
#ifdef MYDDAS_MYSQL

View File

@ -1053,5 +1053,4 @@ opinfo("retry_eam",[body]).
opinfo("alloc_for_logical_pred",[body]).
opinfo("deallocate",[body]).
opinfo("table_try_single",[]).
opinfo("native_me",[]).