diff --git a/C/absmi.c b/C/absmi.c index bcb62b3f6..766409ccf 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -968,27 +968,6 @@ Yap_absmi(int inp) * Profiled try - retry - trust instructions * *****************************************************************/ - /* profiled_enter_me Pred */ - Op(enter_profiling, p); - LOCK(PREG->u.p.p->StatisticsForPred.lock); - PREG->u.p.p->StatisticsForPred.NOfEntries++; - UNLOCK(PREG->u.p.p->StatisticsForPred.lock); - PREG = NEXTOP(PREG, p); - GONext(); - ENDOp(); - - /* profiled_enter */ - Op(enter_a_profiling, e); - { - PredEntry *pen = RepPredProp((Prop)IntegerOfTerm(ENV[-EnvSizeInCells-2])); - PREG = NEXTOP(PREG, e); - LOCK(pen->StatisticsForPred.lock); - pen->StatisticsForPred.NOfEntries++; - UNLOCK(pen->StatisticsForPred.lock); - } - GONext(); - ENDOp(); - /* profiled_retry Label,NArgs */ Op(retry_profiled, p); LOCK(PREG->u.p.p->StatisticsForPred.lock); @@ -1191,55 +1170,6 @@ Yap_absmi(int inp) * Call count instructions * *****************************************************************/ - /* count_enter_me Label,NArgs */ - Op(count_call, p); - LOCK(PREG->u.p.p->StatisticsForPred.lock); - PREG->u.p.p->StatisticsForPred.NOfEntries++; - UNLOCK(PREG->u.p.p->StatisticsForPred.lock); - ReductionsCounter--; - if (ReductionsCounter == 0 && ReductionsCounterOn) { - saveregs(); - Yap_Error(CALL_COUNTER_UNDERFLOW,TermNil,""); - setregs(); - JMPNext(); - } - PredEntriesCounter--; - if (PredEntriesCounter == 0 && PredEntriesCounterOn) { - saveregs(); - Yap_Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,""); - setregs(); - JMPNext(); - } - PREG = NEXTOP(PREG, p); - GONext(); - ENDOp(); - - /* count_enter_me Label,NArgs */ - Op(count_a_call, e); - { - PredEntry *pen = RepPredProp((Prop)IntegerOfTerm(ENV[-EnvSizeInCells-2])); - PREG = NEXTOP(PREG, e); - LOCK(pen->StatisticsForPred.lock); - pen->StatisticsForPred.NOfEntries++; - UNLOCK(pen->StatisticsForPred.lock); - ReductionsCounter--; - if (ReductionsCounter == 0 && ReductionsCounterOn) { - saveregs(); - Yap_Error(CALL_COUNTER_UNDERFLOW,TermNil,""); - setregs(); - JMPNext(); - } - PredEntriesCounter--; - if (PredEntriesCounter == 0 && PredEntriesCounterOn) { - saveregs(); - Yap_Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,""); - setregs(); - JMPNext(); - } - } - GONext(); - ENDOp(); - /* count_retry Label,NArgs */ Op(count_retry, p); LOCK(PREG->u.p.p->StatisticsForPred.lock); @@ -8057,6 +7987,41 @@ Yap_absmi(int inp) /* IPred can generate errors, it thus must get rid of the lock itself */ setregs(); } + /* first check if we need to increase the counter */ + if ((pe->PredFlags & CountPredFlag)) { + LOCK(pe->StatisticsForPred.lock); + pe->StatisticsForPred.NOfEntries++; + UNLOCK(pe->StatisticsForPred.lock); + ReductionsCounter--; + if (ReductionsCounter == 0 && ReductionsCounterOn) { + saveregs(); + Yap_Error(CALL_COUNTER_UNDERFLOW,TermNil,""); + setregs(); + JMPNext(); + } + PredEntriesCounter--; + if (PredEntriesCounter == 0 && PredEntriesCounterOn) { + saveregs(); + Yap_Error(PRED_ENTRY_COUNTER_UNDERFLOW,TermNil,""); + setregs(); + JMPNext(); + } + PREG = pe->cs.p_code.TrueCodeOfPred; + if ((pe->PredFlags & (CountPredFlag|ProfiledPredFlag|SpiedPredFlag)) == + CountPredFlag) { + JMPNext(); + } + } + /* standard profiler */ + if ((pe->PredFlags & ProfiledPredFlag)) { + LOCK(pe->StatisticsForPred.lock); + pe->StatisticsForPred.NOfEntries++; + UNLOCK(pe->StatisticsForPred.lock); + if (!(pe->PredFlags & SpiedPredFlag)) { + PREG = pe->cs.p_code.TrueCodeOfPred; + } + JMPNext(); + } if (!DebugOn) { PREG = pe->cs.p_code.TrueCodeOfPred; UNLOCK(pe->PELock); diff --git a/C/amasm.c b/C/amasm.c index 6b1318e9a..c85883186 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -3664,15 +3664,9 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp case f_0_op: code_p = a_f2(TRUE, &cmp_info, code_p, pass_no, cip); break; - case enter_profiling_op: - code_p = a_pl(_enter_profiling, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no); - break; case retry_profiled_op: code_p = a_pl(_retry_profiled, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no); break; - case count_call_op: - code_p = a_pl(_count_call, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no); - break; case count_retry_op: code_p = a_pl(_count_retry, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no); break; @@ -3925,14 +3919,6 @@ Yap_InitComma(void) code_p->u.p.p = PredMetaCall; GONEXT(p); } else { - if (PROFILING) { - code_p->opc = opcode(_enter_a_profiling); - GONEXT(e); - } - if (CALL_COUNTING) { - code_p->opc = opcode(_count_a_call); - GONEXT(e); - } code_p->opc = opcode(_p_execute_tail); code_p->u.Osbpp.s = emit_count(-Signed(RealEnvSize)-3*sizeof(CELL)); code_p->u.Osbpp.bmap = NULL; diff --git a/C/cdmgr.c b/C/cdmgr.c index 093c437bb..34ef0b351 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -965,7 +965,7 @@ IPred(PredEntry *ap, UInt NSlots) ap->cs.p_code.TrueCodeOfPred = BaseAddr; ap->PredFlags |= IndexedPredFlag; } - if (ap->PredFlags & SpiedPredFlag) { + if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { ap->OpcodeOfPred = Yap_opcode(_spy_pred); ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) @@ -996,7 +996,7 @@ static void RemoveMainIndex(PredEntry *ap) { yamop *First = ap->cs.p_code.FirstClause; - int spied = ap->PredFlags & SpiedPredFlag; + int spied = ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag); ap->PredFlags &= ~IndexedPredFlag; if (First == NULL) { @@ -1753,7 +1753,7 @@ asserta_stat_clause(PredEntry *p, yamop *q, int spy_flag) clq->ClNext = clp; clp->ClPrev = clq; p->cs.p_code.FirstClause = q; - if (p->PredFlags & SpiedPredFlag) { + if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { p->OpcodeOfPred = Yap_opcode(_spy_pred); p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } else if (!(p->PredFlags & IndexedPredFlag)) { @@ -1771,7 +1771,7 @@ asserta_stat_clause(PredEntry *p, yamop *q, int spy_flag) cl->ClNext = ClauseCodeToStaticClause(p->cs.p_code.FirstClause); p->cs.p_code.FirstClause = q; p->cs.p_code.TrueCodeOfPred = q; - if (p->PredFlags & SpiedPredFlag) { + if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { p->OpcodeOfPred = Yap_opcode(_spy_pred); p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } else if (!(p->PredFlags & IndexedPredFlag)) { @@ -1840,7 +1840,7 @@ assertz_stat_clause(PredEntry *p, yamop *cp, int spy_flag) p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } #endif - if (p->PredFlags & SpiedPredFlag) { + if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { p->OpcodeOfPred = Yap_opcode(_spy_pred); p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } @@ -1851,7 +1851,7 @@ assertz_stat_clause(PredEntry *p, yamop *cp, int spy_flag) cl->ClNext = ClauseCodeToStaticClause(cp); } if (p->cs.p_code.FirstClause == p->cs.p_code.LastClause) { - if (!(p->PredFlags & SpiedPredFlag)) { + if (!(p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag))) { p->OpcodeOfPred = INDEX_OPCODE; p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } @@ -2075,7 +2075,7 @@ addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref) if (pflags & IndexedPredFlag) { Yap_AddClauseToIndex(p, cp, mode == asserta); } - if (pflags & SpiedPredFlag) + if (pflags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) spy_flag = TRUE; if (p == PredGoalExpansion) { Term tg = ArgOfTerm(1, tf); @@ -2315,7 +2315,7 @@ Yap_EraseStaticClause(StaticClause *cl, Term mod) { } else if (ap->cs.p_code.NOfClauses > 1) { ap->OpcodeOfPred = INDEX_OPCODE; ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); - } else if (ap->PredFlags & SpiedPredFlag) { + } else if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { ap->OpcodeOfPred = Yap_opcode(_spy_pred); ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); } else { @@ -2770,24 +2770,26 @@ p_rmspy(void) return TRUE; } #endif - if (!(pred->PredFlags & DynamicPredFlag)) { + if (!(pred->PredFlags & (CountPredFlag|ProfiledPredFlag))) { + if (!(pred->PredFlags & DynamicPredFlag)) { #if defined(YAPOR) || defined(THREADS) - if (pred->PredFlags & LogUpdatePredFlag && - pred->ModuleOfPred != IDB_MODULE) { - pred->OpcodeOfPred = LOCKPRED_OPCODE; - pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred)); + if (pred->PredFlags & LogUpdatePredFlag && + pred->ModuleOfPred != IDB_MODULE) { + pred->OpcodeOfPred = LOCKPRED_OPCODE; + pred->CodeOfPred = (yamop *)(&(pred->OpcodeOfPred)); + } else { +#endif + pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred; + pred->OpcodeOfPred = pred->CodeOfPred->opc; +#if defined(YAPOR) || defined(THREADS) + } +#endif + } else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) { + pred->OpcodeOfPred = Yap_opcode(_try_and_mark); } else { -#endif - pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred; - pred->OpcodeOfPred = pred->CodeOfPred->opc; -#if defined(YAPOR) || defined(THREADS) + UNLOCK(pred->PELock); + return FALSE; } -#endif - } else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) { - pred->OpcodeOfPred = Yap_opcode(_try_and_mark); - } else { - UNLOCK(pred->PELock); - return FALSE; } pred->PredFlags ^= SpiedPredFlag; UNLOCK(pred->PELock); diff --git a/C/compiler.c b/C/compiler.c index 5671b2a8c..8142128ae 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -1090,10 +1090,6 @@ c_bifun(Int Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler_struct save_machine_regs(); longjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); } - if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint); c_args(Goal, 0, cglobs); Yap_emit(safe_call_op, (CELL)p0 , Zero, &cglobs->cint); Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); @@ -1329,10 +1325,6 @@ c_functor(Term Goal, Term mod, compiler_struct *cglobs) save_machine_regs(); longjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); } - if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint); c_args(Goal, 0, cglobs); Yap_emit(safe_call_op, (CELL)p0 , Zero, &cglobs->cint); Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); @@ -1469,10 +1461,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) return; } else if (atom == AtomCut) { - if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(PredPropByAtom(AtomCut,0)), Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(PredPropByAtom(AtomCut,0)), Zero, &cglobs->cint); if (cglobs->onlast) { /* never a problem here with a -> b, !, c ; d */ Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); @@ -1505,10 +1493,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) /* I need an either_me */ cglobs->needs_env = TRUE; - if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(PredPropByAtom(AtomRepeat,0)), Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(PredPropByAtom(AtomRepeat,0)), Zero, &cglobs->cint); cglobs->or_found = TRUE; push_branch(cglobs->onbranch, TermNil, cglobs); cglobs->curbranch++; @@ -1548,11 +1532,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) save_machine_regs(); longjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); } - /* if we are profiling, make sure we register we entered this predicate */ - if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); - if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); } else { f = FunctorOfTerm(Goal); @@ -1763,10 +1742,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) return; } else if (f == FunctorEq) { - if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); c_eq(ArgOfTerm(1, Goal), ArgOfTerm(2, Goal), cglobs); if (cglobs->onlast) { Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); @@ -1792,10 +1767,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) else if (p->PredFlags & AsmPredFlag) { int op = p->PredFlags & 0x7f; - if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); if (op >= _atom && op <= _primitive) { c_test(op, ArgOfTerm(1, Goal), cglobs); if (cglobs->onlast) { @@ -1924,10 +1895,6 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) } return; } else { - if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); if (f == FunctorExecuteInMod) { /* compile the first argument only */ c_arg(1, ArgOfTerm(1,Goal), 1, 0, cglobs); diff --git a/C/computils.c b/C/computils.c index 1f4fbad93..51a3939eb 100644 --- a/C/computils.c +++ b/C/computils.c @@ -696,9 +696,7 @@ static char *opformat[] = "fetch_reg_constant\t%l,%N", "fetch_integer_reg\t%d,%N", "fetch_reg_integer\t%d,%N", - "enter_profiling\t\t%g", "retry_profiled\t\t%g", - "count_call_op\t\t%g", "count_retry_op\t\t%g", "restore_temps\t\t%l", "restore_temps_and_skip\t\t%l", diff --git a/C/dbase.c b/C/dbase.c index 74b910cf8..d13e3611a 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -4253,7 +4253,7 @@ PrepareToEraseLogUpdClause(LogUpdClause *clau, DBRef dbr) code_p = p->cs.p_code.FirstClause; code_p->u.Otapl.d = p->cs.p_code.FirstClause; p->cs.p_code.TrueCodeOfPred = NEXTOP(code_p, Otapl); - if (p->PredFlags & SpiedPredFlag) { + if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { p->OpcodeOfPred = Yap_opcode(_spy_pred); p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) @@ -4275,7 +4275,7 @@ PrepareToEraseLogUpdClause(LogUpdClause *clau, DBRef dbr) p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); } } else { - if (p->PredFlags & SpiedPredFlag) { + if (p->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { p->OpcodeOfPred = Yap_opcode(_spy_pred); p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) diff --git a/C/grow.c b/C/grow.c index 846f03f81..affb84318 100644 --- a/C/grow.c +++ b/C/grow.c @@ -1027,9 +1027,7 @@ fix_compiler_instructions(PInstr *pcpc) case write_last_struct_op: case mark_initialised_pvars_op: case mark_live_regs_op: - case enter_profiling_op: case retry_profiled_op: - case count_call_op: case count_retry_op: case restore_tmps_op: case restore_tmps_and_skip_op: diff --git a/C/index.c b/C/index.c index 7231e46ae..5924dbc97 100644 --- a/C/index.c +++ b/C/index.c @@ -5997,7 +5997,7 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg return; } ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause; - if (ap->PredFlags & SpiedPredFlag) { + if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) { ap->OpcodeOfPred = Yap_opcode(_spy_pred); ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred)); #if defined(YAPOR) || defined(THREADS) diff --git a/H/YapOpcodes.h b/H/YapOpcodes.h index 26ea57d6c..fa7e34369 100644 --- a/H/YapOpcodes.h +++ b/H/YapOpcodes.h @@ -7,15 +7,11 @@ OPCODE(try_me ,Otapl), OPCODE(retry_me ,Otapl), OPCODE(trust_me ,Otapl), - OPCODE(enter_profiling ,p), - OPCODE(enter_a_profiling ,e), OPCODE(retry_profiled ,p), OPCODE(profiled_retry_me ,Otapl), OPCODE(profiled_trust_me ,Otapl), OPCODE(profiled_retry_logical ,OtaLl), OPCODE(profiled_trust_logical ,OtILl), - OPCODE(count_call ,p), - OPCODE(count_a_call ,e), OPCODE(count_retry ,p), OPCODE(count_retry_me ,Otapl), OPCODE(count_trust_me ,Otapl), diff --git a/H/compile.h b/H/compile.h index 5e858ea31..11fb87ebd 100644 --- a/H/compile.h +++ b/H/compile.h @@ -136,9 +136,7 @@ typedef enum compiler_op { fetch_args_vc_op, fetch_args_iv_op, fetch_args_vi_op, - enter_profiling_op, retry_profiled_op, - count_call_op, count_retry_op, restore_tmps_op, restore_tmps_and_skip_op, diff --git a/H/findclause.h b/H/findclause.h index 2b5eefa45..ba7a4265a 100644 --- a/H/findclause.h +++ b/H/findclause.h @@ -141,12 +141,6 @@ return; cl = NEXTOP(cl,e); break; - case _count_a_call: - cl = NEXTOP(cl,e); - break; - case _enter_a_profiling: - cl = NEXTOP(cl,e); - break; case _pop: cl = NEXTOP(cl,e); break; diff --git a/H/rclause.h b/H/rclause.h index 75fbd016f..ccbaea261 100644 --- a/H/rclause.h +++ b/H/rclause.h @@ -194,11 +194,9 @@ restore_opcodes(yamop *pc) case _Nstop: case _allocate: case _copy_idb_term: - case _count_a_call: case _cut: case _cut_e: case _cut_t: - case _enter_a_profiling: case _expand_index: case _index_blob: case _index_dbref: @@ -406,10 +404,8 @@ restore_opcodes(yamop *pc) pc = NEXTOP(pc,oy); break; /* instructions type p */ - case _count_call: case _count_retry: case _deallocate: - case _enter_profiling: case _lock_lu: case _procceed: case _retry_profiled: diff --git a/H/walkclause.h b/H/walkclause.h index ccaef903b..447553ed9 100644 --- a/H/walkclause.h +++ b/H/walkclause.h @@ -154,11 +154,9 @@ case _unify_idb_term: return found_idb_clause(pc, startp, endp); case _allocate: - case _count_a_call: case _cut: case _cut_e: case _cut_t: - case _enter_a_profiling: case _index_blob: case _index_dbref: case _index_long: @@ -328,10 +326,8 @@ clause_code = TRUE; pc = NEXTOP(pc,p); break; - case _count_call: case _count_retry: case _deallocate: - case _enter_profiling: case _retry_profiled: pc = NEXTOP(pc,p); break;