forked from GitHub/gf-core
an optimization in the jitter for generating more compact code
This commit is contained in:
@@ -41,15 +41,12 @@ pgf_jit_finalize_page(GuFinalizer* self)
|
|||||||
free(fin->page);
|
free(fin->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t total_size = 0;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgf_jit_alloc_page(PgfJitState* state)
|
pgf_jit_alloc_page(PgfJitState* state)
|
||||||
{
|
{
|
||||||
void *page;
|
void *page;
|
||||||
|
|
||||||
size_t page_size = getpagesize();
|
size_t page_size = getpagesize();
|
||||||
total_size += page_size;
|
|
||||||
|
|
||||||
if (posix_memalign(&page, page_size, page_size) != 0) {
|
if (posix_memalign(&page, page_size, page_size) != 0) {
|
||||||
gu_fatal("Memory allocation failed");
|
gu_fatal("Memory allocation failed");
|
||||||
@@ -166,6 +163,9 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
jit_getarg_p(JIT_V1, rs_arg);
|
jit_getarg_p(JIT_V1, rs_arg);
|
||||||
jit_getarg_p(JIT_V2, st_arg);
|
jit_getarg_p(JIT_V2, st_arg);
|
||||||
|
|
||||||
|
size_t n_hypos = gu_seq_length(absfun->type->hypos);
|
||||||
|
|
||||||
|
if (n_hypos > 0) {
|
||||||
if (i+1 < n_funs) {
|
if (i+1 < n_funs) {
|
||||||
PgfAbsFun* absfun =
|
PgfAbsFun* absfun =
|
||||||
gu_buf_get(abscat->functions, PgfAbsFun*, i+1);
|
gu_buf_get(abscat->functions, PgfAbsFun*, i+1);
|
||||||
@@ -185,7 +185,6 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
jit_finish(pgf_try_else);
|
jit_finish(pgf_try_else);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t n_hypos = gu_seq_length(absfun->type->hypos);
|
|
||||||
for (size_t i = 0; i < n_hypos; i++) {
|
for (size_t i = 0; i < n_hypos; i++) {
|
||||||
PgfHypo* hypo = gu_seq_index(absfun->type->hypos, PgfHypo, i);
|
PgfHypo* hypo = gu_seq_index(absfun->type->hypos, PgfHypo, i);
|
||||||
|
|
||||||
@@ -198,7 +197,11 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
#ifdef PGF_JIT_DEBUG
|
#ifdef PGF_JIT_DEBUG
|
||||||
gu_puts(" CALL ", wtr, err);
|
gu_puts(" CALL ", wtr, err);
|
||||||
gu_string_write(hypo->type->cid, wtr, err);
|
gu_string_write(hypo->type->cid, wtr, err);
|
||||||
|
if (i+1 < n_hypos) {
|
||||||
gu_printf(wtr, err, " L%d\n", label);
|
gu_printf(wtr, err, " L%d\n", label);
|
||||||
|
} else {
|
||||||
|
gu_printf(wtr, err, " COMPLETE\n");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// compile CALL
|
// compile CALL
|
||||||
@@ -218,12 +221,15 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
|
|
||||||
#ifdef PGF_JIT_DEBUG
|
#ifdef PGF_JIT_DEBUG
|
||||||
gu_puts(" RET\n", wtr, err);
|
gu_puts(" RET\n", wtr, err);
|
||||||
|
if (i+1 < n_hypos) {
|
||||||
gu_printf(wtr, err, "L%d:\n", label++);
|
gu_printf(wtr, err, "L%d:\n", label++);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// compile RET
|
// compile RET
|
||||||
jit_ret();
|
jit_ret();
|
||||||
|
|
||||||
|
if (i+1 < n_hypos) {
|
||||||
pgf_jit_make_space(state);
|
pgf_jit_make_space(state);
|
||||||
|
|
||||||
jit_patch_movi(ref,jit_get_label());
|
jit_patch_movi(ref,jit_get_label());
|
||||||
@@ -233,8 +239,29 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
st_arg = jit_arg_p();
|
st_arg = jit_arg_p();
|
||||||
jit_getarg_p(JIT_V1, rs_arg);
|
jit_getarg_p(JIT_V1, rs_arg);
|
||||||
jit_getarg_p(JIT_V2, st_arg);
|
jit_getarg_p(JIT_V2, st_arg);
|
||||||
|
} else {
|
||||||
|
jit_patch_movi(ref,pgf_complete);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i+1 < n_funs) {
|
||||||
|
PgfAbsFun* absfun =
|
||||||
|
gu_buf_get(abscat->functions, PgfAbsFun*, i+1);
|
||||||
|
|
||||||
|
#ifdef PGF_JIT_DEBUG
|
||||||
|
gu_puts(" TRY_CONSTANT ", wtr, err);
|
||||||
|
gu_string_write(absfun->name, wtr, err);
|
||||||
|
gu_puts("\n", wtr, err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// compile TRY_CONSTANT
|
||||||
|
jit_prepare(3);
|
||||||
|
jit_movi_p(JIT_V0, absfun);
|
||||||
|
jit_pusharg_p(JIT_V0);
|
||||||
|
jit_pusharg_p(JIT_V2);
|
||||||
|
jit_pusharg_p(JIT_V1);
|
||||||
|
jit_finish(pgf_try_constant);
|
||||||
|
} else {
|
||||||
#ifdef PGF_JIT_DEBUG
|
#ifdef PGF_JIT_DEBUG
|
||||||
gu_puts(" COMPLETE\n", wtr, err);
|
gu_puts(" COMPLETE\n", wtr, err);
|
||||||
#endif
|
#endif
|
||||||
@@ -244,6 +271,7 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
jit_pusharg_p(JIT_V2);
|
jit_pusharg_p(JIT_V2);
|
||||||
jit_pusharg_p(JIT_V1);
|
jit_pusharg_p(JIT_V1);
|
||||||
jit_finish(pgf_complete);
|
jit_finish(pgf_complete);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PGF_JIT_DEBUG
|
#ifdef PGF_JIT_DEBUG
|
||||||
gu_puts(" RET\n", wtr, err);
|
gu_puts(" RET\n", wtr, err);
|
||||||
@@ -251,6 +279,7 @@ pgf_jit_predicate(PgfJitState* state,
|
|||||||
|
|
||||||
// compile RET
|
// compile RET
|
||||||
jit_ret();
|
jit_ret();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PGF_JIT_DEBUG
|
#ifdef PGF_JIT_DEBUG
|
||||||
if (i+1 < n_funs) {
|
if (i+1 < n_funs) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct PgfExprState {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// base must be the first field in order to be able to cast
|
// base must be the first field in order to be able to cast
|
||||||
// from PgfCombine2State to PgfReasonerState
|
// from PgfCombine1State to PgfReasonerState
|
||||||
PgfReasonerState base;
|
PgfReasonerState base;
|
||||||
GuBuf* exprs;
|
GuBuf* exprs;
|
||||||
PgfExprState* parent;
|
PgfExprState* parent;
|
||||||
@@ -331,6 +331,13 @@ pgf_complete(PgfReasoner* rs, PgfExprState* st)
|
|||||||
nst->base.continuation(rs, &nst->base);
|
nst->base.continuation(rs, &nst->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pgf_try_constant(PgfReasoner* rs, PgfExprState* prev, PgfAbsFun* absfun)
|
||||||
|
{
|
||||||
|
pgf_try_else(rs, prev, absfun);
|
||||||
|
pgf_complete(rs, prev);
|
||||||
|
}
|
||||||
|
|
||||||
static PgfExprProb*
|
static PgfExprProb*
|
||||||
pgf_reasoner_next(PgfReasoner* rs)
|
pgf_reasoner_next(PgfReasoner* rs)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user