Skip to content

Commit

Permalink
MJIT: Refactor source_shape_id extraction
Browse files Browse the repository at this point in the history
I'm not comfortable indenting code that deeply.
  • Loading branch information
k0kubun committed Nov 25, 2022
1 parent 89a98ee commit 3c16f33
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/mjit/compiler.rb
Expand Up @@ -349,21 +349,9 @@ def compile_send(insn, stack_size, sp_inc, local_stack_p, pos, next_pos, status,
def compile_ivar(insn_name, stack_size, pos, status, operands, body)
ic_copy = (status.is_entries + (C.iseq_inline_storage_entry.new(operands[1]) - body.is_entries)).iv_cache
dest_shape_id = ic_copy.value >> C.SHAPE_FLAG_SHIFT
source_shape_id = parent_shape_id(dest_shape_id)
attr_index = ic_copy.value & ((1 << C.SHAPE_FLAG_SHIFT) - 1)

source_shape_id = if dest_shape_id == C.INVALID_SHAPE_ID
dest_shape_id
else
parent_id = C.rb_shape_get_shape_by_id(dest_shape_id).parent_id
parent = C.rb_shape_get_shape_by_id(parent_id)

if parent.type == C.SHAPE_CAPACITY_CHANGE
parent.parent_id
else
parent_id
end
end

src = +''
if !status.compile_info.disable_ivar_cache && source_shape_id != C.INVALID_SHAPE_ID
# JIT: optimize away motion of sp and pc. This path does not call rb_warning() and so it's always leaf and not `handles_sp`.
Expand Down Expand Up @@ -976,6 +964,19 @@ def inlinable_iseq_p(body)
def to_addr(struct)
struct&.to_s || 'NULL'
end

def parent_shape_id(shape_id)
return shape_id if shape_id == C.INVALID_SHAPE_ID

parent_id = C.rb_shape_get_shape_by_id(shape_id).parent_id
parent = C.rb_shape_get_shape_by_id(parent_id)

if parent.type == C.SHAPE_CAPACITY_CHANGE
parent.parent_id
else
parent_id
end
end
end

private_constant(*constants)
Expand Down

0 comments on commit 3c16f33

Please sign in to comment.