summaryrefslogtreecommitdiff
path: root/zjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2025-03-03 13:46:53 -0800
committerTakashi Kokubun <[email protected]>2025-04-18 21:52:59 +0900
commit0a543daf15e995ad12b0884bf89ea89b6b480dd2 (patch)
tree8cadafeccd9da51ea8c11014c3b2ab8701848387 /zjit.c
parent30db473389ca5bb6c68bec72de49330a72a2541c (diff)
Add zjit_* instructions to profile the interpreter (https://github.com/Shopify/zjit/pull/16)
* Add zjit_* instructions to profile the interpreter * Rename FixnumPlus to FixnumAdd * Update a comment about Invalidate * Rename Guard to GuardType * Rename Invalidate to PatchPoint * Drop unneeded debug!() * Plan on profiling the types * Use the output of GuardType as type refined outputs
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
Diffstat (limited to 'zjit.c')
-rw-r--r--zjit.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/zjit.c b/zjit.c
index 8cb4776351..027f4ae7d2 100644
--- a/zjit.c
+++ b/zjit.c
@@ -22,6 +22,7 @@
#include "iseq.h"
#include "ruby/debug.h"
#include "internal/cont.h"
+#include "zjit.h"
// For mmapp(), sysconf()
#ifndef _WIN32
@@ -634,3 +635,45 @@ rb_RCLASS_ORIGIN(VALUE c)
{
return RCLASS_ORIGIN(c);
}
+
+// Convert a given ISEQ's instructions to zjit_* instructions
+void
+rb_zjit_profile_iseq(const rb_iseq_t *iseq)
+{
+ // This table encodes an opcode into the instruction's address
+ const void *const *insn_table = rb_vm_get_insns_address_table();
+
+ unsigned int insn_idx = 0;
+ while (insn_idx < iseq->body->iseq_size) {
+ int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[insn_idx]);
+ int zjit_insn = vm_insn_to_zjit_insn(insn);
+ if (insn != zjit_insn) {
+ iseq->body->iseq_encoded[insn_idx] = (VALUE)insn_table[zjit_insn];
+ }
+ insn_idx += insn_len(insn);
+ }
+}
+
+// Get profiling information for ISEQ
+void *
+rb_iseq_get_zjit_payload(const rb_iseq_t *iseq)
+{
+ RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
+ if (iseq->body) {
+ return iseq->body->zjit_payload;
+ }
+ else {
+ // Body is NULL when constructing the iseq.
+ return NULL;
+ }
+}
+
+// Set profiling information for ISEQ
+void
+rb_iseq_set_zjit_payload(const rb_iseq_t *iseq, void *payload)
+{
+ RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
+ RUBY_ASSERT_ALWAYS(iseq->body);
+ RUBY_ASSERT_ALWAYS(NULL == iseq->body->zjit_payload);
+ iseq->body->zjit_payload = payload;
+}