From b92b026c90c33a97c485ae0dc28cdb37e9b44c1f Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 8 Apr 2009 00:32:36 +0100 Subject: [PATCH] more patches to support Anderson's JIT. --- C/c_interface.c | 4 +++- C/compiler.c | 2 ++ C/index.c | 9 +++++++++ C/init.c | 1 + H/Heap.h | 2 ++ H/Yap.h | 12 ++++++++++++ H/amidefs.h | 14 ++++++++------ H/findclause.h | 3 +++ H/headclause.h | 3 +++ H/rclause.h | 2 +- console/yap.c | 32 ++++++++++++++++++++++++++++++++ misc/buildops | 3 +-- 12 files changed, 77 insertions(+), 10 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 81520fddc..0801fef96 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -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; diff --git a/C/compiler.c b/C/compiler.c index 6e6e00a7a..4699e1e95 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -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); } diff --git a/C/index.c b/C/index.c index 1f8aea3fb..a318f0251 100644 --- a/C/index.c +++ b/C/index.c @@ -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) { diff --git a/C/init.c b/C/init.c index a704684aa..2c9907649 100644 --- a/C/init.c +++ b/C/init.c @@ -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" diff --git a/H/Heap.h b/H/Heap.h index 357c45f17..f0cb581fc 100644 --- a/H/Heap.h +++ b/H/Heap.h @@ -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 diff --git a/H/Yap.h b/H/Yap.h index 67baeea26..e7334e78a 100644 --- a/H/Yap.h +++ b/H/Yap.h @@ -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; + + diff --git a/H/amidefs.h b/H/amidefs.h index 70f3b3bc2..2493864d4 100644 --- a/H/amidefs.h +++ b/H/amidefs.h @@ -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. */ diff --git a/H/findclause.h b/H/findclause.h index e859f879d..b8600b307 100644 --- a/H/findclause.h +++ b/H/findclause.h @@ -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; diff --git a/H/headclause.h b/H/headclause.h index 727e0ec39..f60ca3946 100644 --- a/H/headclause.h +++ b/H/headclause.h @@ -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; diff --git a/H/rclause.h b/H/rclause.h index 3ca33d3a5..75fbd016f 100644 --- a/H/rclause.h +++ b/H/rclause.h @@ -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 */ diff --git a/console/yap.c b/console/yap.c index 2d2e198fe..93101de5f 100644 --- a/console/yap.c +++ b/console/yap.c @@ -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 diff --git a/misc/buildops b/misc/buildops index e92c8191f..db8bcd984 100644 --- a/misc/buildops +++ b/misc/buildops @@ -1053,5 +1053,4 @@ opinfo("retry_eam",[body]). opinfo("alloc_for_logical_pred",[body]). opinfo("deallocate",[body]). opinfo("table_try_single",[]). - - +opinfo("native_me",[]).