summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-11-25 15:27:09 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2022-11-25 15:27:27 -0800
commit3c16f33ffdfb96bfdd45bc6067175dcd2eb3f090 (patch)
treead5b91885abb58dea18a7445b13b23bf0ebb49bb /lib
parent89a98ee1e1008588962ab444cee7d51fa46ebcf0 (diff)
MJIT: Refactor source_shape_id extraction
I'm not comfortable indenting code that deeply.
Diffstat (limited to 'lib')
-rw-r--r--lib/mjit/compiler.rb27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/mjit/compiler.rb b/lib/mjit/compiler.rb
index e7989ee073..a7546a340d 100644
--- a/lib/mjit/compiler.rb
+++ b/lib/mjit/compiler.rb
@@ -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)