-
Notifications
You must be signed in to change notification settings - Fork 171
/
graph.c
3865 lines (3694 loc) · 175 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"
#include "platform/sys.h"
#include "platform/time.h"
static void jg_append_node(MVMJitGraph *jg, MVMJitNode *node) {
if (jg->last_node) {
jg->last_node->next = node;
jg->last_node = node;
} else {
jg->first_node = node;
jg->last_node = node;
}
node->next = NULL;
}
static void jg_append_primitive(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIns * ins) {
MVMJitNode * node = MVM_spesh_alloc(tc, jg->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_PRIMITIVE;
node->u.prim.ins = ins;
jg_append_node(jg, node);
}
static void jg_append_call_c(MVMThreadContext *tc, MVMJitGraph *jg,
void * func_ptr, MVMint16 num_args,
MVMJitCallArg *call_args,
MVMJitRVMode rv_mode, MVMint16 rv_idx) {
MVMJitNode * node = MVM_spesh_alloc(tc, jg->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;
/* Call argument array is typically stack allocated,
* so they need to be copied */
node->u.call.args = MVM_spesh_alloc(tc, jg->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;
jg_append_node(jg, node);
}
static void add_deopt_idx(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label_name, MVMint32 deopt_idx) {
MVMJitDeopt deopt;
deopt.label = label_name;
deopt.idx = deopt_idx;
MVM_VECTOR_PUSH(jg->deopts, deopt);
}
static void jg_append_branch(MVMThreadContext *tc, MVMJitGraph *jg,
MVMint32 name, MVMSpeshIns *ins) {
MVMJitNode * node = MVM_spesh_alloc(tc, jg->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 = MVM_jit_label_before_bb(tc, jg, bb);
}
jg_append_node(jg, node);
}
static void jg_append_label(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 name) {
MVMJitNode *node;
/* does this label already exist? */
MVM_VECTOR_ENSURE_SIZE(jg->label_nodes, name);
if (jg->label_nodes[name] != NULL)
return;
node = MVM_spesh_alloc(tc, jg->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_LABEL;
node->u.label.name = name;
jg_append_node(jg, node);
jg->label_nodes[name] = node;
}
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_captureinnerlex: return MVM_frame_capture_inner;
case MVM_OP_takeclosure: return MVM_frame_takeclosure;
case MVM_OP_usecapture: return MVM_args_use_capture;
case MVM_OP_savecapture: return MVM_args_save_capture;
case MVM_OP_captureposprimspec: return MVM_capture_pos_primspec;
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_us: return MVM_coerce_u_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_coerce_nI: return MVM_bigint_from_num;
case MVM_OP_coerce_sI: return MVM_coerce_sI;
case MVM_OP_coerce_II: return MVM_bigint_from_bigint;
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_throwdyn:
case MVM_OP_throwlex:
case MVM_OP_throwlexotic:
case MVM_OP_rethrow: return MVM_exception_throwobj;
case MVM_OP_throwcatdyn:
case MVM_OP_throwcatlex:
case MVM_OP_throwcatlexotic: return MVM_exception_throwcat;
case MVM_OP_throwpayloadlex: return MVM_exception_throwpayload;
case MVM_OP_bindexpayload: return MVM_bind_exception_payload;
case MVM_OP_getexpayload: return MVM_get_exception_payload;
case MVM_OP_resume: return MVM_exception_resume;
case MVM_OP_continuationreset: return MVM_continuation_reset;
case MVM_OP_continuationcontrol: return MVM_continuation_control;
case MVM_OP_continuationinvoke: return MVM_continuation_invoke;
case MVM_OP_smrt_numify: return MVM_coerce_smart_numify;
case MVM_OP_smrt_strify: return MVM_coerce_smart_stringify;
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_u: return MVM_repr_get_uint;
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_scgetobjidx: return MVM_sc_find_object_idx_jit;
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_getlexcaller: return MVM_frame_find_lexical_by_name_rel_caller;
case MVM_OP_findmeth: case MVM_OP_findmeth_s: return MVM_6model_find_method;
case MVM_OP_tryfindmeth: case MVM_OP_tryfindmeth_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_i: return MVM_repr_unshift_i;
case MVM_OP_unshift_n: return MVM_repr_unshift_n;
case MVM_OP_unshift_s: return MVM_repr_unshift_s;
case MVM_OP_unshift_o: return MVM_repr_unshift_o;
case MVM_OP_pop_i: return MVM_repr_pop_i;
case MVM_OP_pop_n: return MVM_repr_pop_n;
case MVM_OP_pop_s: return MVM_repr_pop_s;
case MVM_OP_pop_o: return MVM_repr_pop_o;
case MVM_OP_shift_i: return MVM_repr_shift_i;
case MVM_OP_shift_n: return MVM_repr_shift_n;
case MVM_OP_shift_s: return MVM_repr_shift_s;
case MVM_OP_shift_o: return MVM_repr_shift_o;
case MVM_OP_setelemspos: return MVM_repr_pos_set_elems;
case MVM_OP_slice: return MVM_repr_pos_slice;
case MVM_OP_splice: return MVM_repr_pos_splice;
case MVM_OP_existskey: return MVM_repr_exists_key;
case MVM_OP_deletekey: return MVM_repr_delete_key;
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_i: return MVM_repr_at_key_i;
case MVM_OP_atkey_n: return MVM_repr_at_key_n;
case MVM_OP_atkey_s: return MVM_repr_at_key_s;
case MVM_OP_atkey_o: return MVM_repr_at_key_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_bindpos_o: return MVM_repr_bind_pos_o;
case MVM_OP_writeint: return MVM_repr_write_buf;
case MVM_OP_writeuint: return MVM_repr_write_buf;
case MVM_OP_readint: return MVM_repr_read_buf;
case MVM_OP_readuint: return MVM_repr_read_buf;
case MVM_OP_bindkey_i: return MVM_repr_bind_key_i;
case MVM_OP_bindkey_n: return MVM_repr_bind_key_n;
case MVM_OP_bindkey_s: return MVM_repr_bind_key_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_attrinited: return MVM_repr_attribute_inited;
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_hintfor: return MVM_repr_hint_for;
case MVM_OP_gt_s: case MVM_OP_ge_s: case MVM_OP_lt_s: case MVM_OP_le_s: case MVM_OP_cmp_s: return MVM_string_compare;
case MVM_OP_queuepoll: return MVM_concblockingqueue_jit_poll;
case MVM_OP_open_fh: return MVM_file_open_fh;
case MVM_OP_close_fh: return MVM_io_close;
case MVM_OP_eof_fh: return MVM_io_eof;
case MVM_OP_write_fhb: return MVM_io_write_bytes;
case MVM_OP_read_fhb: return MVM_io_read_bytes;
case MVM_OP_encode: return MVM_string_encode_to_buf;
case MVM_OP_decoderaddbytes: return MVM_decoder_add_bytes;
case MVM_OP_decodertakeline: return MVM_decoder_take_line;
case MVM_OP_decodertakeallchars: return MVM_decoder_take_all_chars;
case MVM_OP_decodertakebytes: return MVM_decoder_take_bytes;
case MVM_OP_decoderempty: return MVM_decoder_empty;
case MVM_OP_elems: return MVM_repr_elems;
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_fc: return MVM_string_fc;
case MVM_OP_eq_s: return MVM_string_equal;
case MVM_OP_eqat_s: return MVM_string_equal_at;
case MVM_OP_eqatic_s: return MVM_string_equal_at_ignore_case;
case MVM_OP_eqatim_s: return MVM_string_equal_at_ignore_mark;
case MVM_OP_eqaticim_s: return MVM_string_equal_at_ignore_case_ignore_mark;
case MVM_OP_chars: case MVM_OP_graphs_s: return MVM_string_graphs;
case MVM_OP_chr: return MVM_string_chr;
case MVM_OP_codes_s: return MVM_string_codes;
case MVM_OP_getcp_s: return MVM_string_get_grapheme_at;
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_replace: return MVM_string_replace;
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_gethllsym: return MVM_hll_sym_get;
case MVM_OP_clone: return MVM_repr_clone;
case MVM_OP_create: return MVM_repr_alloc_init;
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_neg_I: return MVM_bigint_neg;
case MVM_OP_abs_I: return MVM_bigint_abs;
case MVM_OP_bor_I: return MVM_bigint_or;
case MVM_OP_band_I: return MVM_bigint_and;
case MVM_OP_bxor_I: return MVM_bigint_xor;
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_isprime_I: return MVM_bigint_is_prime;
case MVM_OP_brshift_I: return MVM_bigint_shr;
case MVM_OP_blshift_I: return MVM_bigint_shl;
case MVM_OP_bnot_I: return MVM_bigint_not;
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: return MVM_radix;
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_floor_n: return floor;
case MVM_OP_pow_I: return MVM_bigint_pow;
case MVM_OP_rand_I: return MVM_bigint_rand;
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_nativecallcast: return MVM_nativecall_cast;
case MVM_OP_nativecallinvoke: return MVM_nativecall_invoke;
case MVM_OP_nativeinvoke_o: return MVM_nativecall_invoke_jit;
case MVM_OP_typeparameterized: return MVM_6model_parametric_type_parameterized;
case MVM_OP_typeparameters: return MVM_6model_parametric_type_parameters;
case MVM_OP_typeparameterat: return MVM_6model_parametric_type_parameter_at;
case MVM_OP_objectid: return MVM_gc_object_id;
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_isrwcont: return MVM_6model_container_iscont_rw;
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_getrusage: return MVM_proc_getrusage;
case MVM_OP_cpucores: return MVM_platform_cpu_count;
case MVM_OP_getsignals: return MVM_io_get_signals;
case MVM_OP_sleep: return MVM_platform_sleep;
case MVM_OP_getlexref_i32: case MVM_OP_getlexref_i16: case MVM_OP_getlexref_i8: case MVM_OP_getlexref_i: return MVM_nativeref_lex_i;
case MVM_OP_getlexref_n32: case MVM_OP_getlexref_n: return MVM_nativeref_lex_n;
case MVM_OP_getlexref_s: return MVM_nativeref_lex_s;
case MVM_OP_getattrref_i: return MVM_nativeref_attr_i;
case MVM_OP_getattrref_n: return MVM_nativeref_attr_n;
case MVM_OP_getattrref_s: return MVM_nativeref_attr_s;
case MVM_OP_getattrsref_i: return MVM_nativeref_attr_i;
case MVM_OP_getattrsref_n: return MVM_nativeref_attr_n;
case MVM_OP_getattrsref_s: return MVM_nativeref_attr_s;
case MVM_OP_atposref_i: return MVM_nativeref_pos_i;
case MVM_OP_atposref_n: return MVM_nativeref_pos_n;
case MVM_OP_atposref_s: return MVM_nativeref_pos_s;
case MVM_OP_indexingoptimized: return MVM_string_indexing_optimized;
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;
case MVM_OP_sp_resolvecode: return MVM_frame_resolve_invokee_spesh;
case MVM_OP_cas_o: return MVM_6model_container_cas;
case MVM_OP_cas_i: return MVM_6model_container_cas_i;
case MVM_OP_atomicinc_i: return MVM_6model_container_atomic_inc;
case MVM_OP_atomicdec_i: return MVM_6model_container_atomic_dec;
case MVM_OP_atomicadd_i: return MVM_6model_container_atomic_add;
case MVM_OP_atomicload_o: return MVM_6model_container_atomic_load;
case MVM_OP_atomicload_i: return MVM_6model_container_atomic_load_i;
case MVM_OP_atomicstore_o: return MVM_6model_container_atomic_store;
case MVM_OP_atomicstore_i: return MVM_6model_container_atomic_store_i;
case MVM_OP_lock: return MVM_reentrantmutex_lock_checked;
case MVM_OP_unlock: return MVM_reentrantmutex_unlock_checked;
case MVM_OP_getexcategory: return MVM_get_exception_category;
case MVM_OP_bindexcategory: return MVM_bind_exception_category;
case MVM_OP_exreturnafterunwind: return MVM_exception_returnafterunwind;
case MVM_OP_breakpoint: return MVM_debugserver_breakpoint_check;
case MVM_OP_sp_getstringfrom: return MVM_cu_string;
case MVM_OP_encoderepconf: return MVM_string_encode_to_buf_config;
case MVM_OP_strfromname: return MVM_unicode_string_from_name;
case MVM_OP_callercode: return MVM_frame_caller_code;
default:
MVM_oops(tc, "JIT: No function for op %d in op_to_func (%s)", opcode, MVM_op_get_op(opcode)->name);
}
}
static void jg_append_guard(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIns *ins, MVMuint32 target_operand) {
MVMSpeshAnn *ann = ins->annotations;
MVMJitNode *node = MVM_spesh_alloc(tc, jg->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_oops(tc, "Can't find deopt idx annotation on spesh ins <%s>",
ins->info->name);
}
node->u.guard.deopt_target = ins->operands[target_operand].lit_ui32;
node->u.guard.deopt_offset = jg->sg->deopt_addrs[2 * deopt_idx + 1];
jg_append_node(jg, node);
}
static MVMint32 consume_invoke(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIterator *iter, MVMSpeshIns *ins) {
MVMCompUnit *cu = iter->graph->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, iter->graph, sizeof(MVMSpeshIns*) * cs->arg_count);
MVMint16 i = 0;
MVMJitNode *node;
MVMint32 reentry_label;
MVMReturnType return_type;
MVMint16 return_register;
MVMint16 code_register_or_name;
MVMint16 spesh_cand_or_sf_slot;
MVMint16 is_fast;
MVMint16 is_resolve = 0;
MVMuint32 resolve_offset = 0;
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:
arg_ins[i++] = ins;
break;
case MVM_OP_invoke_v:
return_type = MVM_RETURN_VOID;
return_register = -1;
code_register_or_name = ins->operands[0].reg.orig;
spesh_cand_or_sf_slot = -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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = -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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = -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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = -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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = -1;
is_fast = 0;
goto checkargs;
case MVM_OP_nativeinvoke_o: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 site = ins->operands[1].reg.orig;
MVMint16 restype = ins->operands[2].reg.orig;
MVMNativeCallBody *body;
MVMJitGraph *nc_jg;
MVMObject *nc_site;
MVMSpeshFacts *object_facts = MVM_spesh_get_facts(tc, iter->graph, ins->operands[1]);
if (!(object_facts->flags & MVM_SPESH_FACT_KNOWN_VALUE)) {
MVM_spesh_graph_add_comment(tc, iter->graph, iter->ins,
"BAIL: op <%s> (Can't find nc_site value on spesh ins)", ins->info->name);
return 0;
}
body = MVM_nativecall_get_nc_body(tc, object_facts->value.o);
nc_jg = MVM_nativecall_jit_graph_for_caller_code(tc, iter->graph, body, restype, dst, arg_ins);
if (nc_jg == NULL)
return 0;
jg->last_node->next = nc_jg->first_node;
jg->last_node = nc_jg->last_node;
goto success;
}
case MVM_OP_sp_fastinvoke_v:
return_type = MVM_RETURN_VOID;
return_register = -1;
code_register_or_name = ins->operands[0].reg.orig;
spesh_cand_or_sf_slot = 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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = 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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = 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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = 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_or_name = ins->operands[1].reg.orig;
spesh_cand_or_sf_slot = ins->operands[2].lit_i16;
is_fast = 1;
goto checkargs;
case MVM_OP_sp_speshresolve:
return_type = MVM_RETURN_OBJ;
return_register = ins->operands[0].reg.orig;;
code_register_or_name = ins->operands[1].lit_ui32;
resolve_offset = ins->operands[2].lit_ui32;
spesh_cand_or_sf_slot = ins->operands[3].lit_i16;
is_fast = 0;
is_resolve = 1;
goto checkargs;
default:
MVM_spesh_graph_add_comment(tc, iter->graph, ins,
"BAIL: Unexpected opcode in invoke sequence: <%s>",
ins->info->name);
return 0;
}
}
checkargs:
if (!ins || i < cs->arg_count) {
MVM_spesh_graph_add_comment(tc, iter->graph, iter->ins,
"BAIL: op <%s>, expected args: %d, num of args: %d",
ins? ins->info->name : "NULL", i, cs->arg_count);
return 0;
}
/* get label /after/ current (invoke) ins, where we'll need to reenter the JIT */
reentry_label = MVM_jit_label_after_ins(tc, jg, iter->bb, ins);
/* create invoke node */
node = MVM_spesh_alloc(tc, jg->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_or_name = code_register_or_name;
node->u.invoke.spesh_cand_or_sf_slot = spesh_cand_or_sf_slot;
node->u.invoke.resolve_offset = resolve_offset;
node->u.invoke.reentry_label = reentry_label;
node->u.invoke.is_fast = is_fast;
node->u.invoke.is_resolve = is_resolve;
jg_append_node(jg, node);
/* append reentry label */
jg_append_label(tc, jg, reentry_label);
success:
/* move forward to invoke ins */
iter->ins = ins;
return 1;
}
static void jg_append_control(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIns *ins, MVMJitControlType ctrl) {
MVMJitNode *node = MVM_spesh_alloc(tc, jg->sg, sizeof(MVMJitNode));
node->type = MVM_JIT_NODE_CONTROL;
node->u.control.ins = ins;
node->u.control.type = ctrl;
jg_append_node(jg, node);
}
static MVMint32 consume_jumplist(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIterator *iter, 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, jg->sg, sizeof(MVMint32) * num_labels);
MVMint32 *out_labels = MVM_spesh_alloc(tc, jg->sg, sizeof(MVMint32) * num_labels);
MVMSpeshBB *bb = iter->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] = MVM_jit_label_before_bb(tc, jg, bb);
out_labels[i] = MVM_jit_label_before_bb(tc, jg, ins->operands[0].ins_bb);
}
/* build the node */
node = MVM_spesh_alloc(tc, jg->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;
jg_append_node(jg, node);
/* set iterator bb and ins to the end of our jumplist */
iter->bb = bb;
iter->ins = ins;
return 1;
}
static MVMString* wrap_MVM_cu_string(MVMThreadContext *tc, MVMCompUnit *cu, MVMuint32 idx) {
return MVM_cu_string(tc, cu, idx);
}
static MVMint32 jg_add_data_node(MVMThreadContext *tc, MVMJitGraph *jg, void *data, size_t size) {
MVMJitNode *node = MVM_spesh_alloc(tc, jg->sg, sizeof(MVMJitNode));
MVMint32 label = MVM_jit_label_for_obj(tc, jg, data);
node->type = MVM_JIT_NODE_DATA;
node->u.data.data = data;
node->u.data.size = size;
node->u.data.label = label;
jg_append_node(jg, node);
return label;
}
static MVMuint16 * try_fake_extop_regs(MVMThreadContext *tc, MVMSpeshGraph *sg, MVMSpeshIns *ins, size_t *bufsize) {
MVMuint16 *regs = MVM_spesh_alloc(tc, sg, (*bufsize = (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 before_ins(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIterator *iter, MVMSpeshIns *ins) {
MVMSpeshBB *bb = iter->bb;
MVMSpeshAnn *ann = ins->annotations;
MVMint32 has_label = 0, label;
/* 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 */
label = MVM_jit_label_before_ins(tc, jg, bb, ins);
add_deopt_idx(tc, jg, label, ann->data.deopt_idx);
has_label = 1;
break;
}
case MVM_SPESH_ANN_FH_START: {
label = MVM_jit_label_before_ins(tc, jg, bb, ins);
jg->handlers[ann->data.frame_handler_index].start_label = label;
has_label = 1;
/* Load the current position into the jit entry label, so that
* when throwing we'll know which handler to use */
break;
}
case MVM_SPESH_ANN_FH_END: {
label = MVM_jit_label_before_ins(tc, jg, bb, ins);
jg->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. */
has_label = 1;
break;
}
case MVM_SPESH_ANN_FH_GOTO: {
label = MVM_jit_label_before_ins(tc, jg, bb, ins);
jg->handlers[ann->data.frame_handler_index].goto_label = label;
has_label = 1;
break;
}
case MVM_SPESH_ANN_INLINE_START: {
label = MVM_jit_label_before_ins(tc, jg, bb, ins);
jg->inlines[ann->data.inline_idx].start_label = label;
has_label = 1;
break;
}
} /* switch */
ann = ann->next;
}
if (has_label) {
jg_append_label(tc, jg, label);
}
}
static void after_ins(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIterator *iter, MVMSpeshIns *ins) {
MVMSpeshBB *bb = iter->bb;
MVMSpeshAnn *ann = ins->annotations;
/* 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. */
while (ann) {
if (ann->type == MVM_SPESH_ANN_INLINE_END) {
MVMint32 label = MVM_jit_label_after_ins(tc, jg, bb, ins);
jg_append_label(tc, jg, label);
jg->inlines[ann->data.inline_idx].end_label = label;
} else if (ann->type == MVM_SPESH_ANN_DEOPT_ALL_INS) {
/* 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 = MVM_jit_label_after_ins(tc, jg, bb, ins);
jg_append_label(tc, jg, label);
add_deopt_idx(tc, jg, label, ann->data.deopt_idx);
}
ann = ann->next;
}
}
static void jg_sc_wb(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshOperand check) {
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, check.reg.orig } };
jg_append_call_c(tc, jg, &MVM_SC_WB_OBJ, 2, args, MVM_JIT_RV_VOID, -1);
}
static MVMint32 consume_reprop(MVMThreadContext *tc, MVMJitGraph *jg,
MVMSpeshIterator *iter, MVMSpeshIns *ins) {
MVMint16 op = ins->info->opcode;
MVMSpeshOperand type_operand;
MVMSpeshFacts *type_facts = 0;
MVMint32 alternative = 0;
switch (op) {
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_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_push_i:
case MVM_OP_push_n:
case MVM_OP_push_s:
case MVM_OP_push_o:
case MVM_OP_deletekey:
case MVM_OP_setelemspos:
case MVM_OP_splice:
case MVM_OP_assign_i:
case MVM_OP_assign_n:
case MVM_OP_assign_s:
type_operand = ins->operands[0];
break;
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_pop_i:
case MVM_OP_pop_n:
case MVM_OP_pop_s:
case MVM_OP_pop_o:
case MVM_OP_existskey:
case MVM_OP_existspos:
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_attrinited:
case MVM_OP_hintfor:
case MVM_OP_slice:
case MVM_OP_decont_i:
case MVM_OP_decont_n:
case MVM_OP_decont_s:
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:
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: not devirtualized (unknown type operand)");
return 0;
}
type_facts = MVM_spesh_get_facts(tc, jg->sg, type_operand);
if (type_facts && type_facts->flags & MVM_SPESH_FACT_KNOWN_TYPE && type_facts->type &&
type_facts->flags & MVM_SPESH_FACT_CONCRETE) {
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 = alternative
? (void *)((MVMObject*)type_facts->type)->st->REPR->ass_funcs.at_key
: (void *)((MVMObject*)type_facts->type)->st->REPR->pos_funcs.at_pos;
/* Can attempt to double-devirt for VMArray */
if (alternative == 0) {
if (REPR(type_facts->type)->ID == MVM_REPR_ID_VMArray) {
void *alternative_function = MVM_VMArray_devirtualize_ins_for_jit(tc, STABLE(type_facts->type), ins);
if (alternative_function != NULL) {
MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, value } };
jg_append_call_c(tc, jg, alternative_function, 3, args, MVM_JIT_RV_PTR, dst);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: double-devirtualized");;
return 1;
}
}
}
{
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 } };
jg_append_call_c(tc, jg, function, 7, args, MVM_JIT_RV_VOID, -1);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: devirtualized");;
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 = alternative
? (void *)((MVMObject*)type_facts->type)->st->REPR->ass_funcs.bind_key
: (void *)((MVMObject*)type_facts->type)->st->REPR->pos_funcs.bind_pos;
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 },
{ 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 } };
jg_append_call_c(tc, jg, function, 7, args, MVM_JIT_RV_VOID, -1);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: devirtualized");;
jg_sc_wb(tc, jg, ins->operands[0]);
return 1;
}
case MVM_OP_elems: {
/*elems w(int64) r(obj) :pure*/
MVMint32 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
void *function = ((MVMObject*)type_facts->type)->st->REPR->elems;
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 } };
jg_append_call_c(tc, jg, function, 4, args, MVM_JIT_RV_INT, dst);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: devirtualized");;
return 1;
}
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: {
/*getattr_i w(int64) r(obj) r(obj) str int16*/
/*getattrs_i w(int64) r(obj) r(obj) r(str)*/
/*static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,*/
/* void *data, MVMObject *class_handle, MVMString *name, MVMint64 hint,*/
/* MVMRegister *result_reg, MVMuint16 kind) {*/
/* reprconv and interp.c check for concreteness, so we'd either
* have to emit a bit of code to check and throw or just rely
* on a concreteness fact */
MVMSpeshFacts *object_facts = MVM_spesh_get_facts(tc, jg->sg, ins->operands[1]);
if (object_facts->flags & MVM_SPESH_FACT_CONCRETE) {
MVMint32 is_name_direct = ins->info->num_operands == 5;
MVMint32 dst = ins->operands[0].reg.orig;
MVMint32 invocant = ins->operands[1].reg.orig;
MVMint32 type = ins->operands[2].reg.orig;
MVMint32 attrname = is_name_direct ? ins->operands[3].lit_str_idx : ins->operands[3].reg.orig;
MVMint32 attrhint = is_name_direct ? ins->operands[4].lit_i16 : -1;
void *function = ((MVMObject*)type_facts->type)->st->REPR->attr_funcs.get_attribute;
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, type },
{ is_name_direct ? MVM_JIT_STR_IDX : MVM_JIT_REG_VAL,
attrname },
{ MVM_JIT_LITERAL, attrhint },
{ MVM_JIT_REG_ADDR, dst },
{ MVM_JIT_LITERAL,
op == MVM_OP_getattr_i || op == MVM_OP_getattrs_i ? MVM_reg_int64 :