summaryrefslogtreecommitdiff
path: root/yjit_core.c
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2021-04-06 12:19:45 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:32 -0400
commit0881e018b567362ba6405eeb788d76d770653978 (patch)
tree02fe0bbd8d85217147521fbc7b6d0366d81c4612 /yjit_core.c
parentd1e9e4566f93e219314f361b88b4a0e003a25241 (diff)
Add comments and asserts for clarity
Diffstat (limited to 'yjit_core.c')
-rw-r--r--yjit_core.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/yjit_core.c b/yjit_core.c
index 9add2b5f29..f74c5e9318 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -455,18 +455,6 @@ branch_stub_hit(const uint32_t branch_idx, const uint32_t target_idx, rb_executi
// If this block hasn't yet been compiled
if (!p_block) {
- // If the new block will be placed next right after the branch
- if (cb->write_pos == branch->end_pos) {
- //fprintf(stderr, "target idx %d will be placed next\n", target_idx);
- branch->shape = (uint8_t)target_idx;
-
- // Rewrite the branch with the new, potentially more compact shape
- cb_set_pos(cb, branch->start_pos);
- branch->gen_fn(cb, branch->dst_addrs[0], branch->dst_addrs[1], branch->shape);
- RUBY_ASSERT(cb->write_pos <= branch->end_pos && "can't enlarge branches");
- branch->end_pos = cb->write_pos;
- }
-
// Limit the number of block versions
ctx_t generic_ctx = DEFAULT_CTX;
generic_ctx.stack_size = target_ctx->stack_size;
@@ -478,7 +466,21 @@ branch_stub_hit(const uint32_t branch_idx, const uint32_t target_idx, rb_executi
}
}
+ // If the new block can be generated right after the branch (at cb->write_pos)
+ if (cb->write_pos == branch->end_pos) {
+ // Change the branch shape to indicate the target block will be placed next
+ branch->shape = (uint8_t)target_idx;
+
+ // Rewrite the branch with the new, potentially more compact shape
+ cb_set_pos(cb, branch->start_pos);
+ branch->gen_fn(cb, branch->dst_addrs[0], branch->dst_addrs[1], branch->shape);
+ RUBY_ASSERT(cb->write_pos <= branch->end_pos && "can't enlarge branches");
+ branch->end_pos = cb->write_pos;
+ }
+
p_block = gen_block_version(target, target_ctx, ec);
+ RUBY_ASSERT(p_block);
+ RUBY_ASSERT(branch->shape != (uint8_t)target_idx || p_block->start_pos == branch->end_pos);
}
// Add this branch to the list of incoming branches for the target