MJIT: Refactor source_shape_id extraction

I'm not comfortable indenting code that deeply.
This commit is contained in:
Takashi Kokubun 2022-11-25 15:27:09 -08:00
Родитель 89a98ee1e1
Коммит 3c16f33ffd
1 изменённых файлов: 14 добавлений и 13 удалений

Просмотреть файл

@ -349,21 +349,9 @@ module RubyVM::MJIT
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`.
@ -976,6 +964,19 @@ module RubyVM::MJIT
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)