Ruby 3.2.3p157 (2024-01-18 revision 52bb2ac0a6971d0391efa2275f7a66bff319087c)
mjit_c.h
1// This file is parsed by tool/mjit/generate.rb to generate mjit_c.rb
2#ifndef MJIT_C_H
3#define MJIT_C_H
4
5#include "ruby/internal/config.h"
6#include "vm_core.h"
7#include "vm_callinfo.h"
8#include "builtin.h"
9#include "ccan/list/list.h"
10#include "mjit.h"
11#include "shape.h"
12
13// Macros to check if a position is already compiled using compile_status.stack_size_for_pos
14#define NOT_COMPILED_STACK_SIZE -1
15#define ALREADY_COMPILED_P(status, pos) (status->stack_size_for_pos[pos] != NOT_COMPILED_STACK_SIZE)
16
17// Linked list of struct rb_mjit_unit.
19 struct ccan_list_head head;
20 int length; // the list length
21};
22
23enum rb_mjit_unit_type {
24 // Single-ISEQ unit for unit_queue
25 MJIT_UNIT_ISEQ = 0,
26 // Multi-ISEQ unit for mjit_batch
27 MJIT_UNIT_BATCH = 1,
28 // All-ISEQ unit for mjit_compact
29 MJIT_UNIT_COMPACT = 2,
30};
31
32// The unit structure that holds metadata of ISeq for MJIT.
33// TODO: Use different structs for ISEQ and BATCH/COMPACT
35 struct ccan_list_node unode;
36 // Unique order number of unit.
37 int id;
38 // Type of this unit
39 enum rb_mjit_unit_type type;
40
41 /* MJIT_UNIT_ISEQ */
42 // ISEQ for a non-batch unit
43 rb_iseq_t *iseq;
44 // Only used by unload_units. Flag to check this unit is currently on stack or not.
45 bool used_code_p;
46 // mjit_compile's optimization switches
47 struct rb_mjit_compile_info compile_info;
48 // captured CC values, they should be marked with iseq.
49 const struct rb_callcache **cc_entries;
50 // ISEQ_BODY(iseq)->ci_size + ones of inlined iseqs
51 unsigned int cc_entries_size;
52
53 /* MJIT_UNIT_BATCH, MJIT_UNIT_COMPACT */
54 // Dlopen handle of the loaded object file.
55 void *handle;
56 // Units compacted by this batch
57 struct rb_mjit_unit_list units; // MJIT_UNIT_BATCH only
58};
59
60// Storage to keep data which is consistent in each conditional branch.
61// This is created and used for one `compile_insns` call and its values
62// should be copied for extra `compile_insns` call.
64 unsigned int stack_size; // this simulates sp (stack pointer) of YARV
65 bool finish_p; // if true, compilation in this branch should stop and let another branch to be compiled
66};
67
68// For propagating information needed for lazily pushing a frame.
70 int orig_argc; // ci->orig_argc
71 VALUE me; // vm_cc_cme(cc)
72 int param_size; // def_iseq_ptr(vm_cc_cme(cc)->def)->body->param.size
73 int local_size; // def_iseq_ptr(vm_cc_cme(cc)->def)->body->local_table_size
74};
75
76// Storage to keep compiler's status. This should have information
77// which is global during one `mjit_compile` call. Ones conditional
78// in each branch should be stored in `compile_branch`.
80 bool success; // has true if compilation has had no issue
81 int *stack_size_for_pos; // stack_size_for_pos[pos] has stack size for the position (otherwise -1)
82 // If true, JIT-ed code will use local variables to store pushed values instead of
83 // using VM's stack and moving stack pointer.
84 bool local_stack_p;
85 // Index of call cache entries captured to compiled_iseq to be marked on GC
86 int cc_entries_index;
87 // A pointer to root (i.e. not inlined) iseq being compiled.
88 const struct rb_iseq_constant_body *compiled_iseq;
89 int compiled_id; // Just a copy of compiled_iseq->jit_unit->id
90 // Mutated optimization levels
91 struct rb_mjit_compile_info *compile_info;
92 // If `inlined_iseqs[pos]` is not NULL, `mjit_compile_body` tries to inline ISeq there.
93 const struct rb_iseq_constant_body **inlined_iseqs;
94 struct inlined_call_context inline_context;
95};
96
97#endif /* MJIT_C_H */
VALUE type(ANYARGS)
ANYARGS-ed function type.
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40