-
Notifications
You must be signed in to change notification settings - Fork 171
/
graph.c
2185 lines (2123 loc) · 92.5 KB
/
graph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "moar.h"
#include "math.h"
typedef struct {
MVMSpeshGraph *sg;
MVMSpeshBB *cur_bb;
MVMSpeshIns *cur_ins;
MVMJitNode *first_node;
MVMJitNode *last_node;
MVMint32 num_labels;
void **labeleds;
MVMint32 num_bbs;
MVMint32 *bb_labels;
MVMint32 num_deopts;
MVMint32 alloc_deopts;
MVMJitDeopt *deopts;
MVMint32 num_handlers;
MVMJitHandler *handlers;
MVMint32 num_inlines;
MVMJitInline *inlines;
} JitGraphBuilder;
static void jgb_append_node(JitGraphBuilder *jgb, MVMJitNode *node) {
if (jgb->last_node) {
jgb->last_node->next = node;
jgb->last_node = node;
} else {
jgb->first_node = node;
jgb->last_node = node;
}
node->next = NULL;
}
static void jgb_append_primitive(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshIns * ins) {
MVMJitNode * node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_PRIMITIVE;
node->u.prim.ins = ins;
jgb_append_node(jgb, node);
}
static void jgb_append_call_c(MVMThreadContext *tc, JitGraphBuilder *jgb,
void * func_ptr, MVMint16 num_args,
MVMJitCallArg *call_args,
MVMJitRVMode rv_mode, MVMint16 rv_idx) {
MVMJitNode * node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
size_t args_size = num_args * sizeof(MVMJitCallArg);
node->type = MVM_JIT_NODE_CALL_C;
node->u.call.func_ptr = func_ptr;
node->u.call.num_args = num_args;
node->u.call.has_vargs = 0; // don't support them yet
/* Call argument array is typically stack allocated,
* so they need to be copied */
node->u.call.args = MVM_spesh_alloc(tc, jgb->sg, args_size);
memcpy(node->u.call.args, call_args, args_size);
node->u.call.rv_mode = rv_mode;
node->u.call.rv_idx = rv_idx;
jgb_append_node(jgb, node);
}
static MVMint32 get_label_for_obj(MVMThreadContext *tc, JitGraphBuilder *jgb,
void * obj) {
MVMint32 i;
for (i = 0; i < jgb->num_labels; i++) {
if (!jgb->labeleds[i])
break;
if (jgb->labeleds[i] == obj)
return i;
}
if (i == jgb->num_labels) {
void **lblds = MVM_spesh_alloc(tc, jgb->sg, sizeof(void*) * jgb->num_labels * 2);
memcpy(lblds, jgb->labeleds, jgb->num_labels * sizeof(void*));
jgb->labeleds = lblds;
jgb->num_labels *= 2;
}
jgb->labeleds[i] = obj;
return i;
}
static MVMint32 get_label_for_bb(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshBB *bb) {
MVMint32 label = get_label_for_obj(tc, jgb, bb);
jgb->bb_labels[bb->idx] = label;
return label;
}
/* This is the label that is appended at the very end */
static MVMint32 get_label_for_graph(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshGraph *sg) {
return get_label_for_obj(tc, jgb, sg);
}
/* The idea here is that labels are always - in principle - meant before a target. */
static MVMint32 get_label_for_ins(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshBB *bb, MVMSpeshIns *ins, MVMint32 post) {
if (!post) {
/* Disregard PHI ops */
while (ins->prev && ins->prev->info->opcode == MVM_SSA_PHI)
ins = ins->prev;
if (ins == bb->first_ins) {
return get_label_for_obj(tc, jgb, bb);
}
return get_label_for_obj(tc, jgb, ins);
}
else {
if (ins->next) {
return get_label_for_obj(tc, jgb, ins->next);
}
else if (bb->linear_next) {
return get_label_for_obj(tc, jgb, bb->linear_next);
}
else { /* end of graph label is identified by the graph itself */
return get_label_for_graph(tc, jgb, jgb->sg);
}
}
}
static void add_deopt_idx(MVMThreadContext *tc, JitGraphBuilder *jgb, MVMint32 label_name, MVMint32 deopt_idx) {
if (jgb->num_deopts == jgb->alloc_deopts) {
MVMJitDeopt *deopts = MVM_spesh_alloc(tc, jgb->sg, jgb->alloc_deopts * 2 * sizeof(MVMJitDeopt));
memcpy(deopts, jgb->deopts, jgb->num_deopts * sizeof(MVMJitDeopt));
jgb->deopts = deopts;
jgb->alloc_deopts *= 2;
}
jgb->deopts[jgb->num_deopts].label = label_name;
jgb->deopts[jgb->num_deopts].idx = deopt_idx;
jgb->num_deopts++;
}
static void jgb_append_branch(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMint32 name, MVMSpeshIns *ins) {
MVMJitNode * node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_BRANCH;
if (ins == NULL) {
node->u.branch.ins = NULL;
node->u.branch.dest = name;
}
else {
MVMSpeshBB *bb;
node->u.branch.ins = ins;
if (ins->info->opcode == MVM_OP_goto) {
bb = ins->operands[0].ins_bb;
}
else if (ins->info->opcode == MVM_OP_indexat ||
ins->info->opcode == MVM_OP_indexnat) {
bb = ins->operands[3].ins_bb;
}
else {
bb = ins->operands[1].ins_bb;
}
node->u.branch.dest = get_label_for_bb(tc, jgb, bb);
}
jgb_append_node(jgb, node);
}
static void jgb_append_label(MVMThreadContext *tc, JitGraphBuilder *jgb, MVMint32 name) {
MVMJitNode *node;
if (jgb->last_node &&
jgb->last_node->type == MVM_JIT_NODE_LABEL &&
jgb->last_node->u.label.name == name)
return; /* don't double-add labels, even if it may be harmless */
node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_LABEL;
node->u.label.name = name;
jgb_append_node(jgb, node);
MVM_jit_log(tc, "append label: %d\n", node->u.label.name);
}
static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
switch(opcode) {
case MVM_OP_checkarity: return &MVM_args_checkarity;
case MVM_OP_say: return &MVM_string_say;
case MVM_OP_print: return &MVM_string_print;
case MVM_OP_isnull: return &MVM_is_null;
case MVM_OP_capturelex: return &MVM_frame_capturelex;
case MVM_OP_takeclosure: return &MVM_frame_takeclosure;
case MVM_OP_newlexotic: return &MVM_exception_newlexotic_from_jit;
case MVM_OP_usecapture: return &MVM_args_use_capture;
case MVM_OP_savecapture: return &MVM_args_save_capture;
case MVM_OP_return: return &MVM_args_assert_void_return_ok;
case MVM_OP_return_i: return &MVM_args_set_result_int;
case MVM_OP_return_s: return &MVM_args_set_result_str;
case MVM_OP_return_o: return &MVM_args_set_result_obj;
case MVM_OP_return_n: return &MVM_args_set_result_num;
case MVM_OP_coerce_is: return &MVM_coerce_i_s;
case MVM_OP_coerce_ns: return &MVM_coerce_n_s;
case MVM_OP_coerce_si: return &MVM_coerce_s_i;
case MVM_OP_coerce_sn: return &MVM_coerce_s_n;
case MVM_OP_coerce_In: return &MVM_bigint_to_num;
case MVM_OP_iterkey_s: return &MVM_iterkey_s;
case MVM_OP_iter: return &MVM_iter;
case MVM_OP_iterval: return &MVM_iterval;
case MVM_OP_die: return &MVM_exception_die;
case MVM_OP_smrt_numify: return &MVM_coerce_smart_numify;
case MVM_OP_smrt_strify: return &MVM_coerce_smart_stringify;
case MVM_OP_write_fhs: return &MVM_io_write_string;
case MVM_OP_gethow: return &MVM_6model_get_how_obj;
case MVM_OP_box_i: return &MVM_box_int;
case MVM_OP_box_s: return &MVM_box_str;
case MVM_OP_box_n: return &MVM_box_num;
case MVM_OP_unbox_i: return &MVM_repr_get_int;
case MVM_OP_unbox_s: return &MVM_repr_get_str;
case MVM_OP_unbox_n: return &MVM_repr_get_num;
case MVM_OP_istrue: case MVM_OP_isfalse: return &MVM_coerce_istrue;
case MVM_OP_istype: return &MVM_6model_istype;
case MVM_OP_isint: case MVM_OP_isnum: case MVM_OP_isstr: // continued
case MVM_OP_islist: case MVM_OP_ishash: return &MVM_repr_compare_repr_id;
case MVM_OP_wval: case MVM_OP_wval_wide: return &MVM_sc_get_sc_object;
case MVM_OP_getdynlex: return &MVM_frame_getdynlex;
case MVM_OP_binddynlex: return &MVM_frame_binddynlex;
case MVM_OP_getlexouter: return &MVM_frame_find_lexical_by_name_outer;
case MVM_OP_findmeth: case MVM_OP_findmeth_s: return &MVM_6model_find_method;
case MVM_OP_multicacheadd: return &MVM_multi_cache_add;
case MVM_OP_multicachefind: return &MVM_multi_cache_find;
case MVM_OP_can: case MVM_OP_can_s: return &MVM_6model_can_method;
case MVM_OP_push_i: return &MVM_repr_push_i;
case MVM_OP_push_n: return &MVM_repr_push_n;
case MVM_OP_push_s: return &MVM_repr_push_s;
case MVM_OP_push_o: return &MVM_repr_push_o;
case MVM_OP_unshift_o: return &MVM_repr_unshift_o;
case MVM_OP_unshift_i: return &MVM_repr_unshift_i;
case MVM_OP_pop_o: return &MVM_repr_pop_o;
case MVM_OP_shift_o: return &MVM_repr_shift_o;
case MVM_OP_pop_i: return &MVM_repr_pop_i;
case MVM_OP_shift_i: return &MVM_repr_shift_i;
case MVM_OP_existskey: return &MVM_repr_exists_key;
case MVM_OP_deletekey: return &MVM_repr_delete_key;
case MVM_OP_setelemspos: return &MVM_repr_pos_set_elems;
case MVM_OP_splice: return &MVM_repr_pos_splice;
case MVM_OP_atpos_i: return &MVM_repr_at_pos_i;
case MVM_OP_atpos_n: return &MVM_repr_at_pos_n;
case MVM_OP_atpos_s: return &MVM_repr_at_pos_s;
case MVM_OP_atpos_o: return &MVM_repr_at_pos_o;
case MVM_OP_existspos: return &MVM_repr_exists_pos;
case MVM_OP_atkey_o: return &MVM_repr_at_key_o;
case MVM_OP_bindpos_o: return &MVM_repr_bind_pos_o;
case MVM_OP_bindpos_i: return &MVM_repr_bind_pos_i;
case MVM_OP_bindpos_n: return &MVM_repr_bind_pos_n;
case MVM_OP_bindpos_s: return &MVM_repr_bind_pos_s;
case MVM_OP_bindkey_o: return &MVM_repr_bind_key_o;
case MVM_OP_getattr_s: return &MVM_repr_get_attr_s;
case MVM_OP_getattr_n: return &MVM_repr_get_attr_n;
case MVM_OP_getattr_i: return &MVM_repr_get_attr_i;
case MVM_OP_getattr_o: return &MVM_repr_get_attr_o;
case MVM_OP_getattrs_s: return &MVM_repr_get_attr_s;
case MVM_OP_getattrs_n: return &MVM_repr_get_attr_n;
case MVM_OP_getattrs_i: return &MVM_repr_get_attr_i;
case MVM_OP_getattrs_o: return &MVM_repr_get_attr_o;
case MVM_OP_bindattr_i: case MVM_OP_bindattr_n: case MVM_OP_bindattr_s: case MVM_OP_bindattr_o: return &MVM_repr_bind_attr_inso;
case MVM_OP_bindattrs_i: case MVM_OP_bindattrs_n: case MVM_OP_bindattrs_s: case MVM_OP_bindattrs_o: return &MVM_repr_bind_attr_inso;
case MVM_OP_elems: return &MVM_repr_elems;
case MVM_OP_flattenropes: return &MVM_string_flatten;
case MVM_OP_concat_s: return &MVM_string_concatenate;
case MVM_OP_repeat_s: return &MVM_string_repeat;
case MVM_OP_flip: return &MVM_string_flip;
case MVM_OP_split: return &MVM_string_split;
case MVM_OP_escape: return &MVM_string_escape;
case MVM_OP_uc: return &MVM_string_uc;
case MVM_OP_tc: return &MVM_string_tc;
case MVM_OP_lc: return &MVM_string_lc;
case MVM_OP_eq_s: return &MVM_string_equal;
case MVM_OP_eqat_s: return &MVM_string_equal_at;
case MVM_OP_ordat: return &MVM_string_get_grapheme_at;
case MVM_OP_chars: case MVM_OP_graphs_s: return &MVM_string_graphs;
case MVM_OP_codes_s: return &MVM_string_codes;
case MVM_OP_index_s: return &MVM_string_index;
case MVM_OP_substr_s: return &MVM_string_substring;
case MVM_OP_join: return &MVM_string_join;
case MVM_OP_iscclass: return &MVM_string_is_cclass;
case MVM_OP_findcclass: return &MVM_string_find_cclass;
case MVM_OP_findnotcclass: return &MVM_string_find_not_cclass;
case MVM_OP_nfarunalt: return &MVM_nfa_run_alt;
case MVM_OP_nfarunproto: return &MVM_nfa_run_proto;
case MVM_OP_nfafromstatelist: return &MVM_nfa_from_statelist;
case MVM_OP_hllize: return &MVM_hll_map;
case MVM_OP_clone: return &MVM_repr_clone;
case MVM_OP_getcodeobj: return &MVM_frame_get_code_object;
case MVM_OP_isbig_I: return &MVM_bigint_is_big;
case MVM_OP_cmp_I: return &MVM_bigint_cmp;
case MVM_OP_add_I: return &MVM_bigint_add;
case MVM_OP_sub_I: return &MVM_bigint_sub;
case MVM_OP_mul_I: return &MVM_bigint_mul;
case MVM_OP_div_I: return &MVM_bigint_div;
case MVM_OP_mod_I: return &MVM_bigint_mod;
case MVM_OP_lcm_I: return &MVM_bigint_lcm;
case MVM_OP_gcd_I: return &MVM_bigint_gcd;
case MVM_OP_bool_I: return &MVM_bigint_bool;
case MVM_OP_div_In: return &MVM_bigint_div_num;
case MVM_OP_coerce_Is: case MVM_OP_base_I: return &MVM_bigint_to_str;
case MVM_OP_radix_I: return &MVM_bigint_radix;
case MVM_OP_sqrt_n: return &sqrt;
case MVM_OP_sin_n: return &sin;
case MVM_OP_cos_n: return &cos;
case MVM_OP_tan_n: return &tan;
case MVM_OP_asin_n: return &asin;
case MVM_OP_acos_n: return &acos;
case MVM_OP_atan_n: return &atan;
case MVM_OP_atan2_n: return &atan2;
case MVM_OP_pow_n: return &pow;
case MVM_OP_time_n: return &MVM_proc_time_n;
case MVM_OP_randscale_n: return &MVM_proc_randscale_n;
case MVM_OP_isnanorinf: return &MVM_num_isnanorinf;
case MVM_OP_nativecallinvoke: return &MVM_nativecall_invoke;
case MVM_OP_iscont_i: return &MVM_6model_container_iscont_i;
case MVM_OP_iscont_n: return &MVM_6model_container_iscont_n;
case MVM_OP_iscont_s: return &MVM_6model_container_iscont_s;
case MVM_OP_assign_i: return &MVM_6model_container_assign_i;
case MVM_OP_assign_n: return &MVM_6model_container_assign_n;
case MVM_OP_assign_s: return &MVM_6model_container_assign_s;
case MVM_OP_decont_i: return &MVM_6model_container_decont_i;
case MVM_OP_decont_n: return &MVM_6model_container_decont_n;
case MVM_OP_decont_s: return &MVM_6model_container_decont_s;
case MVM_OP_getlexref_i: return &MVM_nativeref_lex_i;
case MVM_OP_getlexref_n: return &MVM_nativeref_lex_n;
case MVM_OP_getlexref_s: return &MVM_nativeref_lex_s;
case MVM_OP_sp_boolify_iter: return &MVM_iter_istrue;
case MVM_OP_prof_allocated: return &MVM_profile_log_allocated;
case MVM_OP_prof_exit: return &MVM_profile_log_exit;
default:
MVM_exception_throw_adhoc(tc, "JIT: No function for op %d in op_to_func.", opcode);
}
}
static void jgb_append_guard(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshIns *ins) {
MVMSpeshAnn *ann = ins->annotations;
MVMJitNode *node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
MVMint32 deopt_idx;
node->type = MVM_JIT_NODE_GUARD;
node->u.guard.ins = ins;
while (ann) {
if (ann->type == MVM_SPESH_ANN_DEOPT_ONE_INS ||
ann->type == MVM_SPESH_ANN_DEOPT_INLINE) {
deopt_idx = ann->data.deopt_idx;
break;
}
ann = ann->next;
}
if (!ann) {
MVM_exception_throw_adhoc(tc, "Can't find deopt idx annotation"
" on spesh ins <%s>", ins->info->name);
}
node->u.guard.deopt_target = jgb->sg->deopt_addrs[2 * deopt_idx];
node->u.guard.deopt_offset = jgb->sg->deopt_addrs[2 * deopt_idx + 1];
jgb_append_node(jgb, node);
}
static MVMint32 jgb_consume_invoke(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshIns *ins) {
MVMCompUnit *cu = jgb->sg->sf->body.cu;
MVMint16 callsite_idx = ins->operands[0].callsite_idx;
MVMCallsite *cs = cu->body.callsites[callsite_idx];
MVMSpeshIns **arg_ins = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMSpeshIns*) * cs->arg_count);
MVMint16 i = 0;
MVMJitNode *node;
MVMint32 reentry_label;
MVMReturnType return_type;
MVMint16 return_register;
MVMint16 code_register;
MVMint16 spesh_cand;
MVMint16 is_fast;
while ((ins = ins->next)) {
switch(ins->info->opcode) {
case MVM_OP_arg_i:
case MVM_OP_arg_n:
case MVM_OP_arg_s:
case MVM_OP_arg_o:
case MVM_OP_argconst_i:
case MVM_OP_argconst_n:
case MVM_OP_argconst_s:
MVM_jit_log(tc, "Invoke arg: <%s>\n", ins->info->name);
arg_ins[i++] = ins;
break;
case MVM_OP_invoke_v:
return_type = MVM_RETURN_VOID;
return_register = -1;
code_register = ins->operands[0].reg.orig;
spesh_cand = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_invoke_i:
return_type = MVM_RETURN_INT;
return_register = ins->operands[0].reg.orig;
code_register = ins->operands[1].reg.orig;
spesh_cand = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_invoke_n:
return_type = MVM_RETURN_NUM;
return_register = ins->operands[0].reg.orig;
code_register = ins->operands[1].reg.orig;
spesh_cand = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_invoke_s:
return_type = MVM_RETURN_STR;
return_register = ins->operands[0].reg.orig;
code_register = ins->operands[1].reg.orig;
spesh_cand = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_invoke_o:
return_type = MVM_RETURN_OBJ;
return_register = ins->operands[0].reg.orig;
code_register = ins->operands[1].reg.orig;
spesh_cand = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_sp_fastinvoke_v:
return_type = MVM_RETURN_VOID;
return_register = -1;
code_register = ins->operands[0].reg.orig;
spesh_cand = ins->operands[1].lit_i16;
is_fast = 1;
goto checkargs;
case MVM_OP_sp_fastinvoke_o:
return_type = MVM_RETURN_OBJ;
return_register = ins->operands[0].reg.orig;;
code_register = ins->operands[1].reg.orig;
spesh_cand = ins->operands[2].lit_i16;
is_fast = 1;
goto checkargs;
case MVM_OP_sp_fastinvoke_s:
return_type = MVM_RETURN_STR;
return_register = ins->operands[0].reg.orig;;
code_register = ins->operands[1].reg.orig;
spesh_cand = ins->operands[2].lit_i16;
is_fast = 1;
goto checkargs;
case MVM_OP_sp_fastinvoke_i:
return_type = MVM_RETURN_INT;
return_register = ins->operands[0].reg.orig;;
code_register = ins->operands[1].reg.orig;
spesh_cand = ins->operands[2].lit_i16;
is_fast = 1;
goto checkargs;
case MVM_OP_sp_fastinvoke_n:
return_type = MVM_RETURN_NUM;
return_register = ins->operands[0].reg.orig;;
code_register = ins->operands[1].reg.orig;
spesh_cand = ins->operands[2].lit_i16;
is_fast = 1;
goto checkargs;
default:
MVM_jit_log(tc, "Unexpected opcode in invoke sequence: <%s>\n",
ins->info->name);
return 0;
}
}
checkargs:
if (!ins || i < cs->arg_count) {
MVM_jit_log(tc, "Could not find invoke opcode or enough arguments\n"
"BAIL: op <%s>, expected args: %d, num of args: %d\n",
ins->info->name, i, cs->arg_count);
return 0;
}
MVM_jit_log(tc, "Invoke instruction: <%s>\n", ins->info->name);
/* get label /after/ current (invoke) ins, where we'll need to reenter the JIT */
reentry_label = get_label_for_ins(tc, jgb, jgb->cur_bb, ins, 1);
/* create invoke node */
node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_INVOKE;
node->u.invoke.callsite_idx = callsite_idx;
node->u.invoke.arg_count = cs->arg_count;
node->u.invoke.arg_ins = arg_ins;
node->u.invoke.return_type = return_type;
node->u.invoke.return_register = return_register;
node->u.invoke.code_register = code_register;
node->u.invoke.spesh_cand = spesh_cand;
node->u.invoke.reentry_label = reentry_label;
node->u.invoke.is_fast = is_fast;
jgb_append_node(jgb, node);
/* append reentry label */
jgb_append_label(tc, jgb, reentry_label);
/* move forward to invoke ins */
jgb->cur_ins = ins;
return 1;
}
static void jgb_append_control(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshIns *ins, MVMJitControlType ctrl) {
MVMJitNode *node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_CONTROL;
node->u.control.ins = ins;
node->u.control.type = ctrl;
jgb_append_node(jgb, node);
}
static MVMint32 jgb_consume_jumplist(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshIns *ins) {
MVMint64 num_labels = ins->operands[0].lit_i64;
MVMint16 idx_reg = ins->operands[1].reg.orig;
MVMint32 *in_labels = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMint32) * num_labels);
MVMint32 *out_labels = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMint32) * num_labels);
MVMSpeshBB *bb = jgb->cur_bb;
MVMJitNode *node;
MVMint64 i;
for (i = 0; i < num_labels; i++) {
bb = bb->linear_next; // take the next basic block
if (!bb || bb->first_ins != bb->last_ins) return 0; // which must exist
ins = bb->first_ins; // and it's first and only entry
if (ins->info->opcode != MVM_OP_goto) // which must be a goto
return 0;
in_labels[i] = get_label_for_bb(tc, jgb, bb);
out_labels[i] = get_label_for_bb(tc, jgb, ins->operands[0].ins_bb);
}
/* build the node */
node = MVM_spesh_alloc(tc, jgb->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_JUMPLIST;
node->u.jumplist.num_labels = num_labels;
node->u.jumplist.reg = idx_reg;
node->u.jumplist.in_labels = in_labels;
node->u.jumplist.out_labels = out_labels;
jgb_append_node(jgb, node);
/* set cur_bb and cur_ins to the end of our jumplist */
jgb->cur_bb = bb;
jgb->cur_ins = ins;
return 1;
}
static MVMuint16 * try_fake_extop_regs(MVMThreadContext *tc, MVMSpeshIns *ins) {
/* XXX Need to be able to clear these up, some day. */
MVMuint16 *regs = MVM_calloc(ins->info->num_operands, sizeof(MVMuint16));
MVMuint16 i;
for (i = 0; i < ins->info->num_operands; i++) {
switch (ins->info->operands[i] & MVM_operand_rw_mask) {
case MVM_operand_read_reg:
case MVM_operand_write_reg:
regs[i] = ins->operands[i].reg.orig;
break;
default:
MVM_free(regs);
return NULL;
}
}
return regs;
}
static void log_inline(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMint32 inline_idx, MVMint32 is_entry) {
MVMStaticFrame *sf = sg->inlines[inline_idx].code->body.sf;
char *name = MVM_string_utf8_encode_C_string(tc, sf->body.name);
char *cuuid = MVM_string_utf8_encode_C_string(tc, sf->body.cuuid);
MVM_jit_log(tc, "%s inline %d (name: %s, cuuid: %s)\n", is_entry ? "Entering" : "Leaving",
inline_idx, name, cuuid);
MVM_free(name);
MVM_free(cuuid);
}
static void jgb_before_ins(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshBB *bb, MVMSpeshIns *ins) {
MVMSpeshAnn *ann = ins->annotations;
/* Search annotations for stuff that may need a label. */
while (ann) {
switch(ann->type) {
case MVM_SPESH_ANN_DEOPT_OSR: {
/* get label before our instruction */
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 0);
jgb_append_label(tc, jgb, label);
add_deopt_idx(tc, jgb, label, ann->data.deopt_idx);
break;
}
case MVM_SPESH_ANN_FH_START: {
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 0);
jgb_append_label(tc, jgb, label);
jgb->handlers[ann->data.frame_handler_index].start_label = label;
/* Load the current position into the jit entry label, so that
* when throwing we'll know which handler to use */
jgb_append_control(tc, jgb, ins, MVM_JIT_CONTROL_DYNAMIC_LABEL);
break;
}
case MVM_SPESH_ANN_FH_END: {
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 0);
jgb_append_label(tc, jgb, label);
jgb->handlers[ann->data.frame_handler_index].end_label = label;
/* Same as above. Note that the dynamic label control
* actually loads a position a few bytes away from the
* label appended above. This is in this case intentional
* because the frame handler end is exclusive; once it is
* passed we should not use the same handler again. If we
* loaded the exact same position, we would not be able to
* distinguish between the end of the basic block to which
* the handler applies and the start of the basic block to
* which it doesn't. */
jgb_append_control(tc, jgb, ins, MVM_JIT_CONTROL_DYNAMIC_LABEL);
break;
}
case MVM_SPESH_ANN_FH_GOTO: {
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 0);
jgb_append_label(tc, jgb, label);
jgb->handlers[ann->data.frame_handler_index].goto_label = label;
break;
}
case MVM_SPESH_ANN_INLINE_START: {
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 0);
jgb_append_label(tc, jgb, label);
jgb->inlines[ann->data.inline_idx].start_label = label;
if (tc->instance->jit_log_fh)
log_inline(tc, jgb->sg, ann->data.inline_idx, 1);
break;
}
} /* switch */
ann = ann->next;
}
if (ins->info->jittivity & MVM_JIT_INFO_THROWISH) {
jgb_append_control(tc, jgb, ins, MVM_JIT_CONTROL_THROWISH_PRE);
}
}
static void jgb_after_ins(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshBB *bb, MVMSpeshIns *ins) {
MVMSpeshAnn *ann;
/* If we've consumed an (or throwish) op, we should append a guard */
if (ins->info->jittivity & MVM_JIT_INFO_INVOKISH) {
MVM_jit_log(tc, "append invokish control guard\n");
jgb_append_control(tc, jgb, ins, MVM_JIT_CONTROL_INVOKISH);
}
else if (ins->info->jittivity & MVM_JIT_INFO_THROWISH) {
jgb_append_control(tc, jgb, ins, MVM_JIT_CONTROL_THROWISH_POST);
}
/* This order of processing is necessary to ensure that a label
* calculated by one of the control guards as well as the labels
* calculated below point to the exact same instruction. This is a
* relatively fragile construction! One could argue that the
* control guards should in fact use the same (dynamic) labels. */
ann = ins->annotations;
while (ann) {
if (ann->type == MVM_SPESH_ANN_INLINE_END) {
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 1);
jgb_append_label(tc, jgb, label);
jgb->inlines[ann->data.inline_idx].end_label = label;
if (tc->instance->jit_log_fh)
log_inline(tc, jgb->sg, ann->data.inline_idx, 0);
} else if (ann->type == MVM_SPESH_ANN_DEOPT_ALL_INS /* ||
ann->type == MVM_SPESH_ANN_DEOPT_INLINE */) {
/* An underlying assumption here is that this instruction
* will in fact set the jit_entry_label to a correct
* value. This is clearly true for invoking ops as well
* as invokish ops, and in fact there is no other way
* to get a deopt_all_ins annotation. Still, be warned. */
MVMint32 label = get_label_for_ins(tc, jgb, bb, ins, 1);
jgb_append_label(tc, jgb, label);
add_deopt_idx(tc, jgb, label, ann->data.deopt_idx);
}
ann = ann->next;
}
}
static MVMint32 jgb_consume_reprop(MVMThreadContext *tc, JitGraphBuilder *jgb,
MVMSpeshBB *bb, MVMSpeshIns *ins) {
MVMint16 op = ins->info->opcode;
MVMSpeshOperand type_operand;
MVMSpeshFacts *type_facts;
MVMint32 alternative = 0;
switch (op) {
case MVM_OP_bindattr_i:
case MVM_OP_bindattr_n:
case MVM_OP_bindattr_s:
case MVM_OP_bindattr_o:
case MVM_OP_bindattrs_i:
case MVM_OP_bindattrs_n:
case MVM_OP_bindattrs_s:
case MVM_OP_bindattrs_o:
case MVM_OP_unshift_i:
case MVM_OP_unshift_n:
case MVM_OP_unshift_s:
case MVM_OP_unshift_o:
case MVM_OP_bindkey_i:
case MVM_OP_bindkey_n:
case MVM_OP_bindkey_s:
case MVM_OP_bindkey_o:
case MVM_OP_bindpos_i:
case MVM_OP_bindpos_n:
case MVM_OP_bindpos_s:
case MVM_OP_bindpos_o:
case MVM_OP_pop_i:
case MVM_OP_pop_n:
case MVM_OP_pop_s:
case MVM_OP_pop_o:
type_operand = ins->operands[0];
break;
case MVM_OP_getattr_i:
case MVM_OP_getattr_n:
case MVM_OP_getattr_s:
case MVM_OP_getattr_o:
case MVM_OP_getattrs_i:
case MVM_OP_getattrs_n:
case MVM_OP_getattrs_s:
case MVM_OP_getattrs_o:
case MVM_OP_atpos_i:
case MVM_OP_atpos_n:
case MVM_OP_atpos_s:
case MVM_OP_atpos_o:
case MVM_OP_atkey_i:
case MVM_OP_atkey_n:
case MVM_OP_atkey_s:
case MVM_OP_atkey_o:
case MVM_OP_elems:
case MVM_OP_shift_i:
case MVM_OP_shift_n:
case MVM_OP_shift_s:
case MVM_OP_shift_o:
case MVM_OP_push_i:
case MVM_OP_push_n:
case MVM_OP_push_s:
case MVM_OP_push_o:
type_operand = ins->operands[1];
break;
case MVM_OP_box_i:
case MVM_OP_box_n:
case MVM_OP_box_s:
type_operand = ins->operands[2];
break;
default:
return 0;
}
type_facts = MVM_spesh_get_facts(tc, jgb->sg, type_operand);
if (type_facts && type_facts->flags & MVM_SPESH_FACT_KNOWN_TYPE && type_facts->type) {
switch(op) {
case MVM_OP_atkey_i:
case MVM_OP_atkey_n:
case MVM_OP_atkey_s:
case MVM_OP_atkey_o:
alternative = 1;
case MVM_OP_atpos_i:
case MVM_OP_atpos_n:
case MVM_OP_atpos_s:
case MVM_OP_atpos_o: {
/* atpos_i w(int64) r(obj) r(int64) */
/* atkey_i w(int64) r(obj) r(str)*/
/*void (*at_pos) (MVMThreadContext *tc, MVMSTable *st,
* MVMObject *root, void *data, MVMint64 index,
* MVMRegister *result, MVMuint16 kind);*/
/*REPR(obj)->pos_funcs.at_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
* idx, &value, MVM_reg_int64);*/
MVMint32 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 value = ins->operands[2].reg.orig;
void *function;
if (alternative)
function = ((MVMObject*)type_facts->type)->st->REPR->ass_funcs.at_key;
else
function = ((MVMObject*)type_facts->type)->st->REPR->pos_funcs.at_pos;
MVM_jit_log(tc, "atpos_* or atkey_* %d %d %d\n", dst, invocant, value);
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_STABLE, invocant },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_OBJBODY, invocant },
{ MVM_JIT_REG_VAL, value },
{ MVM_JIT_REG_ADDR, dst },
{ MVM_JIT_LITERAL,
op == MVM_OP_atpos_i || op == MVM_OP_atkey_i ? MVM_reg_int64 :
op == MVM_OP_atpos_n || op == MVM_OP_atkey_n ? MVM_reg_num64 :
op == MVM_OP_atpos_s || op == MVM_OP_atkey_s ? MVM_reg_str :
MVM_reg_obj } };
jgb_append_call_c(tc, jgb, function, 7, args, MVM_JIT_RV_VOID, -1);
MVM_jit_log(tc, "emitted an atpos_* or atkey_* via jgb_consume_reprop\n");
return 1;
}
case MVM_OP_bindkey_i:
case MVM_OP_bindkey_n:
case MVM_OP_bindkey_s:
case MVM_OP_bindkey_o:
alternative = 1;
case MVM_OP_bindpos_i:
case MVM_OP_bindpos_n:
case MVM_OP_bindpos_s:
case MVM_OP_bindpos_o: {
/*bindpos_i r(obj) r(int64) r(int64)*/
/*bindkey_i r(obj) r(str) r(int64)*/
/* void (*bind_pos) (MVMThreadContext *tc, MVMSTable *st,
MVMObject *root, void *data, MVMint64 index,
MVMRegister value, MVMuint16 kind); */
/* void (*bind_key) (MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
void *data, MVMObject *key, MVMRegister value, MVMuint16 kind); */
MVMint32 invocant = ins->operands[0].reg.orig;
MVMint32 key = ins->operands[1].reg.orig;
MVMint32 value = ins->operands[2].reg.orig;
void *function;
if (alternative)
function = ((MVMObject*)type_facts->type)->st->REPR->ass_funcs.bind_key;
else
function = ((MVMObject*)type_facts->type)->st->REPR->pos_funcs.bind_pos;
MVM_jit_log(tc, "bindpos_* or bindkey_* %d %d %d\n", invocant, key, value);
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_STABLE, invocant },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_OBJBODY, invocant },
{ MVM_JIT_REG_VAL, key },
{ MVM_JIT_REG_VAL, value }, // always as a register (= value)
{ MVM_JIT_LITERAL,
op == MVM_OP_bindpos_i || op == MVM_OP_bindkey_i ? MVM_reg_int64 :
op == MVM_OP_bindpos_n || op == MVM_OP_bindkey_n ? MVM_reg_num64 :
op == MVM_OP_bindpos_s || op == MVM_OP_bindkey_s ? MVM_reg_str :
MVM_reg_obj } };
jgb_append_call_c(tc, jgb, function, 7, args, MVM_JIT_RV_VOID, -1);
MVM_jit_log(tc, "emitted a bindpos_* or bindkey_* via jgb_consume_reprop\n");
return 1;
}
}
}
switch(op) {
case MVM_OP_push_i:
case MVM_OP_push_s:
case MVM_OP_push_o:
case MVM_OP_unshift_i:
case MVM_OP_unshift_s:
case MVM_OP_unshift_o: {
MVMint32 invocant = ins->operands[0].reg.orig;
MVMint32 value = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, value } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_VOID, -1);
break;
}
case MVM_OP_unshift_n:
case MVM_OP_push_n: {
MVMint32 invocant = ins->operands[0].reg.orig;
MVMint32 value = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL_F, value } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_VOID, -1);
break;
}
case MVM_OP_shift_s:
case MVM_OP_pop_s:
case MVM_OP_shift_o:
case MVM_OP_pop_o: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 2, args, MVM_JIT_RV_PTR, dst);
break;
}
case MVM_OP_shift_i:
case MVM_OP_pop_i: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 2, args, MVM_JIT_RV_INT, dst);
break;
}
case MVM_OP_shift_n:
case MVM_OP_pop_n: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 2, args, MVM_JIT_RV_NUM, dst);
break;
}
case MVM_OP_deletekey:
case MVM_OP_setelemspos: {
MVMint32 invocant = ins->operands[0].reg.orig;
MVMint32 key_or_val = ins->operands[1].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, key_or_val } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_VOID, -1);
break;
}
case MVM_OP_existskey: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 key = ins->operands[2].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, key } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_INT, dst);
break;
}
case MVM_OP_splice: {
MVMint16 invocant = ins->operands[0].reg.orig;
MVMint16 source = ins->operands[1].reg.orig;
MVMint16 offset = ins->operands[2].reg.orig;
MVMint16 count = ins->operands[3].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, source },
{ MVM_JIT_REG_VAL, offset },
{ MVM_JIT_REG_VAL, count } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 5, args, MVM_JIT_RV_VOID, -1);
break;
}
case MVM_OP_existspos:
case MVM_OP_atkey_i:
case MVM_OP_atpos_i: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 position = ins->operands[2].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, position } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_INT, dst);
break;
}
case MVM_OP_atkey_n:
case MVM_OP_atpos_n: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 position = ins->operands[2].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, position } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_NUM, dst);
break;
}
case MVM_OP_atpos_o:
case MVM_OP_atkey_o:
case MVM_OP_atkey_s:
case MVM_OP_atpos_s: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 position = ins->operands[2].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, position } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 3, args, MVM_JIT_RV_PTR, dst);
break;
}
case MVM_OP_bindpos_i:
case MVM_OP_bindpos_n:
case MVM_OP_bindpos_s:
case MVM_OP_bindpos_o:
case MVM_OP_bindkey_i:
case MVM_OP_bindkey_n:
case MVM_OP_bindkey_s:
case MVM_OP_bindkey_o: {
MVMint32 invocant = ins->operands[0].reg.orig;
MVMint32 key_pos = ins->operands[1].reg.orig;
MVMint32 value = ins->operands[2].reg.orig;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, key_pos },
{ op == MVM_OP_bindpos_n || op == MVM_OP_bindkey_n ? MVM_JIT_REG_VAL_F : MVM_JIT_REG_VAL, value } };
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 4, args, MVM_JIT_RV_VOID, -1);
break;
}
case MVM_OP_getattr_i:
case MVM_OP_getattr_n:
case MVM_OP_getattr_s:
case MVM_OP_getattr_o: {
MVMuint16 kind = op == MVM_OP_getattr_i ? MVM_JIT_RV_INT :
op == MVM_OP_getattr_n ? MVM_JIT_RV_NUM :
op == MVM_OP_getattr_s ? MVM_JIT_RV_PTR :
/* MVM_OP_getattr_o ? */ MVM_JIT_RV_PTR;
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 obj = ins->operands[1].reg.orig;
MVMint16 typ = ins->operands[2].reg.orig;
MVMuint32 str_idx = ins->operands[3].lit_str_idx;
MVMint16 hint = ins->operands[4].lit_i16;
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, obj },
{ MVM_JIT_REG_VAL, typ },
{ MVM_JIT_STR_IDX, str_idx },
{ MVM_JIT_LITERAL, hint }};
jgb_append_call_c(tc, jgb, op_to_func(tc, op), 5, args, kind, dst);
break;
}
case MVM_OP_getattrs_i:
case MVM_OP_getattrs_n:
case MVM_OP_getattrs_s:
case MVM_OP_getattrs_o: {
MVMuint16 kind = op == MVM_OP_getattrs_i ? MVM_JIT_RV_INT :
op == MVM_OP_getattrs_n ? MVM_JIT_RV_NUM :
op == MVM_OP_getattrs_s ? MVM_JIT_RV_PTR :
/* MVM_OP_getattrs_o ? */ MVM_JIT_RV_PTR;