/home/travis/build/MoarVM/MoarVM/src/jit/graph.h
Line | Count | Source |
1 | | /* The MVMJitGraph is - for now - really a linked list of instructions. |
2 | | * It's likely I'll add complexity when it's needed */ |
3 | | struct MVMJitGraph { |
4 | | MVMSpeshGraph *sg; |
5 | | MVMJitNode *first_node; |
6 | | MVMJitNode *last_node; |
7 | | |
8 | | /* total number of labels, including deopt labels, handler labels, |
9 | | and inline start-stops labels */ |
10 | | MVMint32 num_labels; |
11 | | /* bb labels are all basic block label numbers, indexed by basic |
12 | | block number */ |
13 | | MVMint32 num_bbs; |
14 | | MVMint32 *bb_labels; |
15 | | |
16 | | MVMint32 num_deopts; |
17 | | MVMJitDeopt *deopts; |
18 | | |
19 | | MVMint32 num_handlers; |
20 | | MVMJitHandler *handlers; |
21 | | |
22 | | MVMint32 num_inlines; |
23 | | MVMJitInline *inlines; |
24 | | }; |
25 | | |
26 | | struct MVMJitDeopt { |
27 | | MVMint32 idx; |
28 | | MVMint32 label; |
29 | | }; |
30 | | |
31 | | struct MVMJitHandler { |
32 | | MVMint32 start_label; |
33 | | MVMint32 end_label; |
34 | | MVMint32 goto_label; |
35 | | }; |
36 | | |
37 | | struct MVMJitInline { |
38 | | MVMint32 start_label; |
39 | | MVMint32 end_label; |
40 | | }; |
41 | | |
42 | | /* A label (no more than a number) */ |
43 | | struct MVMJitLabel { |
44 | | MVMint32 name; |
45 | | }; |
46 | | |
47 | | struct MVMJitPrimitive { |
48 | | MVMSpeshIns * ins; |
49 | | }; |
50 | | |
51 | | struct MVMJitGuard { |
52 | | MVMSpeshIns * ins; |
53 | | MVMint32 deopt_target; |
54 | | MVMint32 deopt_offset; |
55 | | }; |
56 | | |
57 | | |
58 | 1.86M | #define MVM_JIT_INFO_INVOKISH 1 |
59 | 1.82M | #define MVM_JIT_INFO_THROWISH 2 |
60 | | |
61 | | typedef enum { |
62 | | MVM_JIT_CONTROL_INVOKISH, |
63 | | MVM_JIT_CONTROL_DYNAMIC_LABEL, |
64 | | MVM_JIT_CONTROL_THROWISH_PRE, |
65 | | MVM_JIT_CONTROL_THROWISH_POST, |
66 | | MVM_JIT_CONTROL_BREAKPOINT, |
67 | | } MVMJitControlType; |
68 | | |
69 | | struct MVMJitControl { |
70 | | MVMSpeshIns *ins; |
71 | | MVMJitControlType type; |
72 | | }; |
73 | | |
74 | | /* Special branch target for the exit */ |
75 | 59.0k | #define MVM_JIT_BRANCH_EXIT -1 |
76 | | #define MVM_JIT_BRANCH_OUT -2 |
77 | | |
78 | | /* What does a branch need? a label to go to, an instruction to read */ |
79 | | struct MVMJitBranch { |
80 | | MVMint32 dest; |
81 | | MVMSpeshIns *ins; |
82 | | }; |
83 | | |
84 | | typedef enum { |
85 | | MVM_JIT_INTERP_TC, |
86 | | MVM_JIT_INTERP_CU, |
87 | | MVM_JIT_INTERP_FRAME, |
88 | | MVM_JIT_INTERP_PARAMS, |
89 | | MVM_JIT_INTERP_CALLER, |
90 | | } MVMJitInterpVar; |
91 | | |
92 | | typedef enum { |
93 | | MVM_JIT_INTERP_VAR, |
94 | | MVM_JIT_REG_VAL, |
95 | | MVM_JIT_REG_VAL_F, |
96 | | MVM_JIT_REG_ADDR, |
97 | | MVM_JIT_STR_IDX, |
98 | | MVM_JIT_LITERAL, |
99 | | MVM_JIT_LITERAL_F, |
100 | | MVM_JIT_LITERAL_64, |
101 | | MVM_JIT_LITERAL_PTR, |
102 | | MVM_JIT_REG_STABLE, |
103 | | MVM_JIT_REG_OBJBODY, |
104 | | MVM_JIT_DATA_LABEL, |
105 | | } MVMJitArgType; |
106 | | |
107 | | struct MVMJitCallArg { |
108 | | MVMJitArgType type; |
109 | | union { |
110 | | MVMint64 lit_i64; |
111 | | MVMnum64 lit_n64; |
112 | | MVMJitInterpVar ivar; |
113 | | MVMint16 reg; |
114 | | void *ptr; |
115 | | } v; |
116 | | }; |
117 | | |
118 | | |
119 | | typedef enum { |
120 | | MVM_JIT_RV_VOID, |
121 | | /* ptr and int are mostly the same, but they might not be on all |
122 | | platforms */ |
123 | | MVM_JIT_RV_INT, |
124 | | MVM_JIT_RV_PTR, |
125 | | /* floats aren't */ |
126 | | MVM_JIT_RV_NUM, |
127 | | /* dereference and store */ |
128 | | MVM_JIT_RV_DEREF, |
129 | | /* store local at address */ |
130 | | MVM_JIT_RV_ADDR |
131 | | } MVMJitRVMode; |
132 | | |
133 | | |
134 | | struct MVMJitCallC { |
135 | | void *func_ptr; |
136 | | MVMJitCallArg *args; |
137 | | MVMuint16 num_args; |
138 | | MVMuint16 has_vargs; |
139 | | MVMJitRVMode rv_mode; |
140 | | MVMint16 rv_idx; |
141 | | }; |
142 | | |
143 | | struct MVMJitInvoke { |
144 | | MVMint16 callsite_idx; |
145 | | MVMint16 arg_count; |
146 | | MVMSpeshIns **arg_ins; |
147 | | MVMReturnType return_type; |
148 | | MVMint16 return_register; |
149 | | MVMint16 code_register; |
150 | | MVMint16 spesh_cand; |
151 | | MVMint8 is_fast; |
152 | | MVMint32 reentry_label; |
153 | | }; |
154 | | |
155 | | struct MVMJitJumpList { |
156 | | MVMint64 num_labels; |
157 | | MVMint16 reg; |
158 | | /* labels of the goto's / jump instructions themselves */ |
159 | | MVMint32 *in_labels; |
160 | | /* labels the goto's jump to */ |
161 | | MVMint32 *out_labels; |
162 | | }; |
163 | | |
164 | | struct MVMJitData { |
165 | | MVMint32 label; |
166 | | void *data; |
167 | | size_t size; |
168 | | }; |
169 | | |
170 | | /* Node types */ |
171 | | typedef enum { |
172 | | MVM_JIT_NODE_PRIMITIVE, |
173 | | MVM_JIT_NODE_CALL_C, |
174 | | MVM_JIT_NODE_BRANCH, |
175 | | MVM_JIT_NODE_LABEL, |
176 | | MVM_JIT_NODE_GUARD, |
177 | | MVM_JIT_NODE_INVOKE, |
178 | | MVM_JIT_NODE_JUMPLIST, |
179 | | MVM_JIT_NODE_CONTROL, |
180 | | MVM_JIT_NODE_DATA, |
181 | | } MVMJitNodeType; |
182 | | |
183 | | struct MVMJitNode { |
184 | | MVMJitNode * next; /* linked list */ |
185 | | MVMJitNodeType type; /* tag */ |
186 | | union { |
187 | | MVMJitPrimitive prim; |
188 | | MVMJitCallC call; |
189 | | MVMJitBranch branch; |
190 | | MVMJitLabel label; |
191 | | MVMJitGuard guard; |
192 | | MVMJitInvoke invoke; |
193 | | MVMJitJumpList jumplist; |
194 | | MVMJitControl control; |
195 | | MVMJitData data; |
196 | | } u; |
197 | | }; |
198 | | |
199 | | MVMJitGraph* MVM_jit_try_make_graph(MVMThreadContext *tc, MVMSpeshGraph *sg); |