summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2020-02-19 16:50:32 +0100
committerAndy Wingo <wingo@pobox.com>2020-02-19 16:50:32 +0100
commit18e9366142c74172fd9fcc10f21688d94249f505 (patch)
treec2e3239729a173f6e80d3e373b7f3febfe20a3ae
parent74eafacff030b88981111a7e90c95aa5a4e0ea8f (diff)
downloadguile-18e9366142c74172fd9fcc10f21688d94249f505.tar.gz
Better debugging in jit.c
* libguile/jit.c (emit_direct_tail_call): Assert self-tail call has mcode. (opcodes_seen, bitvector_ref, bitvector_set, compile1): Make the opcodes_seen set more compact, and log all instruction emissions at level 3. (compute_mcode): Don't overwrite mcode if compilation fails.
-rw-r--r--libguile/jit.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/libguile/jit.c b/libguile/jit.c
index 1a2728af1..56bc30bb6 100644
--- a/libguile/jit.c
+++ b/libguile/jit.c
@@ -819,7 +819,9 @@ emit_direct_tail_call (scm_jit_state *j, const uint32_t *vcode)
if (vcode == j->start)
{
- jit_jmpi (j->jit, j->labels[inline_label_offset (0)]);
+ uint8_t *mcode = j->labels[inline_label_offset (0)];
+ ASSERT (mcode);
+ jit_jmpi (j->jit, mcode);
}
else
{
@@ -5359,14 +5361,28 @@ compile_s64_to_f64_slow (scm_jit_state *j, uint16_t dst, uint16_t src)
comp (j, a, b, c, d, e); \
}
-static uint8_t first_seen[256];
+static uintptr_t opcodes_seen[256 / (SCM_SIZEOF_UINTPTR_T * 8)];
+
+static uintptr_t
+bitvector_ref (const uintptr_t *bv, size_t n)
+{
+ uintptr_t word = bv[n / (SCM_SIZEOF_UINTPTR_T * 8)];
+ return word & (((uintptr_t) 1) << (n & (SCM_SIZEOF_UINTPTR_T * 8 - 1)));
+}
+
+static void
+bitvector_set (uintptr_t *bv, size_t n)
+{
+ uintptr_t *word_loc = &bv[n / (SCM_SIZEOF_UINTPTR_T * 8)];
+ *word_loc |= ((uintptr_t) 1) << (n & (SCM_SIZEOF_UINTPTR_T * 8 - 1));
+}
static void
compile1 (scm_jit_state *j)
{
uint8_t opcode = j->ip[0] & 0xff;
- if (!first_seen[opcode])
+ if (jit_log_level >= LOG_LEVEL_DEBUG)
{
const char *n;
switch (opcode)
@@ -5377,8 +5393,14 @@ compile1 (scm_jit_state *j)
default:
UNREACHABLE ();
}
- first_seen[opcode] = 1;
- DEBUG ("Instruction first seen at vcode %p: %s\n", j->ip, n);
+
+ if (!bitvector_ref (opcodes_seen, opcode))
+ {
+ bitvector_set (opcodes_seen, opcode);
+ DEBUG ("Instruction first seen at vcode %p: %s\n", j->ip, n);
+ }
+
+ LOG ("Instruction at vcode %p: %s\n", j->ip, n);
}
j->next_ip = j->ip + op_lengths[opcode];
@@ -5646,11 +5668,16 @@ compute_mcode (scm_thread *thread, uint32_t *entry_ip,
analyze (j);
- data->mcode = emit_code (j, compile);
- if (data->mcode)
- entry_mcode = j->labels[inline_label_offset (j->entry - j->start)];
+ uint8_t *mcode = emit_code (j, compile);
+ if (mcode)
+ {
+ entry_mcode = j->labels[inline_label_offset (j->entry - j->start)];
+ data->mcode = mcode;
+ }
else
- entry_mcode = NULL;
+ {
+ entry_mcode = NULL;
+ }
free (j->op_attrs);
j->op_attrs = NULL;