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
| /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Machine Code Emitter *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
uint64_t BPFMCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
static const uint64_t InstBits[] = {
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(0),
UINT64_C(504403158265495552), // ADD_ri
UINT64_C(288230376151711744), // ADD_ri_32
UINT64_C(1080863910568919040), // ADD_rr
UINT64_C(864691128455135232), // ADD_rr_32
UINT64_C(6269010681299730432), // AND_ri
UINT64_C(6052837899185946624), // AND_ri_32
UINT64_C(6845471433603153920), // AND_rr
UINT64_C(6629298651489370112), // AND_rr_32
UINT64_C(15852670688344145936), // BE16
UINT64_C(15852670688344145952), // BE32
UINT64_C(15852670688344145984), // BE64
UINT64_C(3963167672086036480), // DIV_ri
UINT64_C(3746994889972252672), // DIV_ri_32
UINT64_C(4539628424389459968), // DIV_rr
UINT64_C(4323455642275676160), // DIV_rr_32
UINT64_C(1738389456165011456), // FI_ri
UINT64_C(9583660007044415488), // JAL
UINT64_C(10160120759347838976), // JALX
UINT64_C(1513209474796486656), // JEQ_ri
UINT64_C(1585267068834414592), // JEQ_ri_32
UINT64_C(2089670227099910144), // JEQ_rr
UINT64_C(2161727821137838080), // JEQ_rr_32
UINT64_C(360287970189639680), // JMP
UINT64_C(6124895493223874560), // JNE_ri
UINT64_C(6196953087261802496), // JNE_ri_32
UINT64_C(6701356245527298048), // JNE_rr
UINT64_C(6773413839565225984), // JNE_rr_32
UINT64_C(8430738502437568512), // JSGE_ri
UINT64_C(8502796096475496448), // JSGE_ri_32
UINT64_C(9007199254740992000), // JSGE_rr
UINT64_C(9079256848778919936), // JSGE_rr_32
UINT64_C(7277816997830721536), // JSGT_ri
UINT64_C(7349874591868649472), // JSGT_ri_32
UINT64_C(7854277750134145024), // JSGT_rr
UINT64_C(7926335344172072960), // JSGT_rr_32
UINT64_C(15348267530078650368), // JSLE_ri
UINT64_C(15420325124116578304), // JSLE_ri_32
UINT64_C(15924728282382073856), // JSLE_rr
UINT64_C(15996785876420001792), // JSLE_rr_32
UINT64_C(14195346025471803392), // JSLT_ri
UINT64_C(14267403619509731328), // JSLT_ri_32
UINT64_C(14771806777775226880), // JSLT_rr
UINT64_C(14843864371813154816), // JSLT_rr_32
UINT64_C(3819052484010180608), // JUGE_ri
UINT64_C(3891110078048108544), // JUGE_ri_32
UINT64_C(4395513236313604096), // JUGE_rr
UINT64_C(4467570830351532032), // JUGE_rr_32
UINT64_C(2666130979403333632), // JUGT_ri
UINT64_C(2738188573441261568), // JUGT_ri_32
UINT64_C(3242591731706757120), // JUGT_rr
UINT64_C(3314649325744685056), // JUGT_rr_32
UINT64_C(13042424520864956416), // JULE_ri
UINT64_C(13114482114902884352), // JULE_ri_32
UINT64_C(13618885273168379904), // JULE_rr
UINT64_C(13690942867206307840), // JULE_rr_32
UINT64_C(11889503016258109440), // JULT_ri
UINT64_C(11961560610296037376), // JULT_ri_32
UINT64_C(12465963768561532928), // JULT_rr
UINT64_C(12538021362599460864), // JULT_rr_32
UINT64_C(8142508126285856768), // LDB
UINT64_C(8142508126285856768), // LDB32
UINT64_C(8718968878589280256), // LDD
UINT64_C(7566047373982433280), // LDH
UINT64_C(7566047373982433280), // LDH32
UINT64_C(6989586621679009792), // LDW
UINT64_C(6989586621679009792), // LDW32
UINT64_C(3458764513820540928), // LD_ABS_B
UINT64_C(2882303761517117440), // LD_ABS_H
UINT64_C(2305843009213693952), // LD_ABS_W
UINT64_C(5764607523034234880), // LD_IND_B
UINT64_C(5188146770730811392), // LD_IND_H
UINT64_C(4611686018427387904), // LD_IND_W
UINT64_C(1729382256910270464), // LD_imm64
UINT64_C(1729382256910270464), // LD_pseudo
UINT64_C(15276209936040722448), // LE16
UINT64_C(15276209936040722464), // LE32
UINT64_C(15276209936040722496), // LE64
UINT64_C(13546827679130451968), // MOV_32_64
UINT64_C(13186539708940812288), // MOV_ri
UINT64_C(12970366926827028480), // MOV_ri_32
UINT64_C(13763000461244235776), // MOV_rr
UINT64_C(13546827679130451968), // MOV_rr_32
UINT64_C(2810246167479189504), // MUL_ri
UINT64_C(2594073385365405696), // MUL_ri_32
UINT64_C(3386706919782612992), // MUL_rr
UINT64_C(3170534137668829184), // MUL_rr_32
UINT64_C(9511602413006487552), // NEG_32
UINT64_C(9727775195120271360), // NEG_64
UINT64_C(13763000461244235776), // NOP
UINT64_C(5116089176692883456), // OR_ri
UINT64_C(4899916394579099648), // OR_ri_32
UINT64_C(5692549928996306944), // OR_rr
UINT64_C(5476377146882523136), // OR_rr_32
UINT64_C(10736581511651262464), // RET
UINT64_C(7421932185906577408), // SLL_ri
UINT64_C(7205759403792793600), // SLL_ri_32
UINT64_C(7998392938210000896), // SLL_rr
UINT64_C(7782220156096217088), // SLL_rr_32
UINT64_C(14339461213547659264), // SRA_ri
UINT64_C(14123288431433875456), // SRA_ri_32
UINT64_C(14915921965851082752), // SRA_rr
UINT64_C(14699749183737298944), // SRA_rr_32
UINT64_C(8574853690513424384), // SRL_ri
UINT64_C(8358680908399640576), // SRL_ri_32
UINT64_C(9151314442816847872), // SRL_rr
UINT64_C(8935141660703064064), // SRL_rr_32
UINT64_C(8286623314361712640), // STB
UINT64_C(8286623314361712640), // STB32
UINT64_C(8863084066665136128), // STD
UINT64_C(7710162562058289152), // STH
UINT64_C(7710162562058289152), // STH32
UINT64_C(7133701809754865664), // STW
UINT64_C(7133701809754865664), // STW32
UINT64_C(1657324662872342528), // SUB_ri
UINT64_C(1441151880758558720), // SUB_ri_32
UINT64_C(2233785415175766016), // SUB_rr
UINT64_C(2017612633061982208), // SUB_rr_32
UINT64_C(15780613094306217984), // XADDD
UINT64_C(14051230837395947520), // XADDW
UINT64_C(14051230837395947520), // XADDW32
UINT64_C(12033618204333965312), // XOR_ri
UINT64_C(11817445422220181504), // XOR_ri_32
UINT64_C(12610078956637388800), // XOR_rr
UINT64_C(12393906174523604992), // XOR_rr_32
UINT64_C(0)
};
const unsigned opcode = MI.getOpcode();
uint64_t Value = InstBits[opcode];
uint64_t op = 0;
(void)op; // suppress warning
switch (opcode) {
case BPF::FI_ri:
case BPF::NOP:
case BPF::RET: {
break;
}
case BPF::JAL:
case BPF::JALX: {
// op: BrDst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
break;
}
case BPF::JMP: {
// op: BrDst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(65535);
op <<= 32;
Value |= op;
break;
}
case BPF::BE16:
case BPF::BE32:
case BPF::BE64:
case BPF::LE16:
case BPF::LE32:
case BPF::LE64:
case BPF::NEG_32:
case BPF::NEG_64: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
break;
}
case BPF::JEQ_ri:
case BPF::JEQ_ri_32:
case BPF::JNE_ri:
case BPF::JNE_ri_32:
case BPF::JSGE_ri:
case BPF::JSGE_ri_32:
case BPF::JSGT_ri:
case BPF::JSGT_ri_32:
case BPF::JSLE_ri:
case BPF::JSLE_ri_32:
case BPF::JSLT_ri:
case BPF::JSLT_ri_32:
case BPF::JUGE_ri:
case BPF::JUGE_ri_32:
case BPF::JUGT_ri:
case BPF::JUGT_ri_32:
case BPF::JULE_ri:
case BPF::JULE_ri_32:
case BPF::JULT_ri:
case BPF::JULT_ri_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: BrDst
op = getMachineOpValue(MI, MI.getOperand(2), Fixups, STI);
op &= UINT64_C(65535);
op <<= 32;
Value |= op;
// op: imm
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
break;
}
case BPF::LDB:
case BPF::LDB32:
case BPF::LDD:
case BPF::LDH:
case BPF::LDH32:
case BPF::LDW:
case BPF::LDW32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: addr
op = getMemoryOpValue(MI, 1, Fixups, STI);
Value |= (op & UINT64_C(983040)) << 36;
Value |= (op & UINT64_C(65535)) << 32;
break;
}
case BPF::LD_imm64:
case BPF::MOV_ri:
case BPF::MOV_ri_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: imm
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
break;
}
case BPF::ADD_ri:
case BPF::ADD_ri_32:
case BPF::AND_ri:
case BPF::AND_ri_32:
case BPF::DIV_ri:
case BPF::DIV_ri_32:
case BPF::MUL_ri:
case BPF::MUL_ri_32:
case BPF::OR_ri:
case BPF::OR_ri_32:
case BPF::SLL_ri:
case BPF::SLL_ri_32:
case BPF::SRA_ri:
case BPF::SRA_ri_32:
case BPF::SRL_ri:
case BPF::SRL_ri_32:
case BPF::SUB_ri:
case BPF::SUB_ri_32:
case BPF::XOR_ri:
case BPF::XOR_ri_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: imm
op = getMachineOpValue(MI, MI.getOperand(2), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
break;
}
case BPF::LD_pseudo: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: imm
op = getMachineOpValue(MI, MI.getOperand(2), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
// op: pseudo
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
break;
}
case BPF::MOV_32_64:
case BPF::MOV_rr:
case BPF::MOV_rr_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: src
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
break;
}
case BPF::JEQ_rr:
case BPF::JEQ_rr_32:
case BPF::JNE_rr:
case BPF::JNE_rr_32:
case BPF::JSGE_rr:
case BPF::JSGE_rr_32:
case BPF::JSGT_rr:
case BPF::JSGT_rr_32:
case BPF::JSLE_rr:
case BPF::JSLE_rr_32:
case BPF::JSLT_rr:
case BPF::JSLT_rr_32:
case BPF::JUGE_rr:
case BPF::JUGE_rr_32:
case BPF::JUGT_rr:
case BPF::JUGT_rr_32:
case BPF::JULE_rr:
case BPF::JULE_rr_32:
case BPF::JULT_rr:
case BPF::JULT_rr_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: src
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
// op: BrDst
op = getMachineOpValue(MI, MI.getOperand(2), Fixups, STI);
op &= UINT64_C(65535);
op <<= 32;
Value |= op;
break;
}
case BPF::ADD_rr:
case BPF::ADD_rr_32:
case BPF::AND_rr:
case BPF::AND_rr_32:
case BPF::DIV_rr:
case BPF::DIV_rr_32:
case BPF::MUL_rr:
case BPF::MUL_rr_32:
case BPF::OR_rr:
case BPF::OR_rr_32:
case BPF::SLL_rr:
case BPF::SLL_rr_32:
case BPF::SRA_rr:
case BPF::SRA_rr_32:
case BPF::SRL_rr:
case BPF::SRL_rr_32:
case BPF::SUB_rr:
case BPF::SUB_rr_32:
case BPF::XOR_rr:
case BPF::XOR_rr_32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 48;
Value |= op;
// op: src
op = getMachineOpValue(MI, MI.getOperand(2), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
break;
}
case BPF::XADDD:
case BPF::XADDW:
case BPF::XADDW32: {
// op: dst
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
// op: addr
op = getMemoryOpValue(MI, 1, Fixups, STI);
op &= UINT64_C(1048575);
op <<= 32;
Value |= op;
break;
}
case BPF::LD_ABS_B:
case BPF::LD_ABS_H:
case BPF::LD_ABS_W: {
// op: imm
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(4294967295);
Value |= op;
break;
}
case BPF::STB:
case BPF::STB32:
case BPF::STD:
case BPF::STH:
case BPF::STH32:
case BPF::STW:
case BPF::STW32: {
// op: src
op = getMachineOpValue(MI, MI.getOperand(0), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
// op: addr
op = getMemoryOpValue(MI, 1, Fixups, STI);
op &= UINT64_C(1048575);
op <<= 32;
Value |= op;
break;
}
case BPF::LD_IND_B:
case BPF::LD_IND_H:
case BPF::LD_IND_W: {
// op: val
op = getMachineOpValue(MI, MI.getOperand(1), Fixups, STI);
op &= UINT64_C(15);
op <<= 52;
Value |= op;
break;
}
default:
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Not supported instr: " << MI;
report_fatal_error(Msg.str());
}
return Value;
}
#ifdef ENABLE_INSTR_PREDICATE_VERIFIER
#undef ENABLE_INSTR_PREDICATE_VERIFIER
#include <sstream>
// Bits for subtarget features that participate in instruction matching.
enum SubtargetFeatureBits : uint8_t {
};
#ifndef NDEBUG
static const char *SubtargetFeatureNames[] = {
nullptr
};
#endif // NDEBUG
FeatureBitset BPFMCCodeEmitter::
computeAvailableFeatures(const FeatureBitset& FB) const {
FeatureBitset Features;
return Features;
}
#ifndef NDEBUG
// Feature bitsets.
enum : uint8_t {
CEFBS_None,
};
static constexpr FeatureBitset FeatureBitsets[] = {
{}, // CEFBS_None
};
#endif // NDEBUG
void BPFMCCodeEmitter::verifyInstructionPredicates(
const MCInst &Inst, const FeatureBitset &AvailableFeatures) const {
#ifndef NDEBUG
static uint8_t RequiredFeaturesRefs[] = {
CEFBS_None, // PHI = 0
CEFBS_None, // INLINEASM = 1
CEFBS_None, // INLINEASM_BR = 2
CEFBS_None, // CFI_INSTRUCTION = 3
CEFBS_None, // EH_LABEL = 4
CEFBS_None, // GC_LABEL = 5
CEFBS_None, // ANNOTATION_LABEL = 6
CEFBS_None, // KILL = 7
CEFBS_None, // EXTRACT_SUBREG = 8
CEFBS_None, // INSERT_SUBREG = 9
CEFBS_None, // IMPLICIT_DEF = 10
CEFBS_None, // SUBREG_TO_REG = 11
CEFBS_None, // COPY_TO_REGCLASS = 12
CEFBS_None, // DBG_VALUE = 13
CEFBS_None, // DBG_LABEL = 14
CEFBS_None, // REG_SEQUENCE = 15
CEFBS_None, // COPY = 16
CEFBS_None, // BUNDLE = 17
CEFBS_None, // LIFETIME_START = 18
CEFBS_None, // LIFETIME_END = 19
CEFBS_None, // STACKMAP = 20
CEFBS_None, // FENTRY_CALL = 21
CEFBS_None, // PATCHPOINT = 22
CEFBS_None, // LOAD_STACK_GUARD = 23
CEFBS_None, // STATEPOINT = 24
CEFBS_None, // LOCAL_ESCAPE = 25
CEFBS_None, // FAULTING_OP = 26
CEFBS_None, // PATCHABLE_OP = 27
CEFBS_None, // PATCHABLE_FUNCTION_ENTER = 28
CEFBS_None, // PATCHABLE_RET = 29
CEFBS_None, // PATCHABLE_FUNCTION_EXIT = 30
CEFBS_None, // PATCHABLE_TAIL_CALL = 31
CEFBS_None, // PATCHABLE_EVENT_CALL = 32
CEFBS_None, // PATCHABLE_TYPED_EVENT_CALL = 33
CEFBS_None, // ICALL_BRANCH_FUNNEL = 34
CEFBS_None, // G_ADD = 35
CEFBS_None, // G_SUB = 36
CEFBS_None, // G_MUL = 37
CEFBS_None, // G_SDIV = 38
CEFBS_None, // G_UDIV = 39
CEFBS_None, // G_SREM = 40
CEFBS_None, // G_UREM = 41
CEFBS_None, // G_AND = 42
CEFBS_None, // G_OR = 43
CEFBS_None, // G_XOR = 44
CEFBS_None, // G_IMPLICIT_DEF = 45
CEFBS_None, // G_PHI = 46
CEFBS_None, // G_FRAME_INDEX = 47
CEFBS_None, // G_GLOBAL_VALUE = 48
CEFBS_None, // G_EXTRACT = 49
CEFBS_None, // G_UNMERGE_VALUES = 50
CEFBS_None, // G_INSERT = 51
CEFBS_None, // G_MERGE_VALUES = 52
CEFBS_None, // G_BUILD_VECTOR = 53
CEFBS_None, // G_BUILD_VECTOR_TRUNC = 54
CEFBS_None, // G_CONCAT_VECTORS = 55
CEFBS_None, // G_PTRTOINT = 56
CEFBS_None, // G_INTTOPTR = 57
CEFBS_None, // G_BITCAST = 58
CEFBS_None, // G_INTRINSIC_TRUNC = 59
CEFBS_None, // G_INTRINSIC_ROUND = 60
CEFBS_None, // G_LOAD = 61
CEFBS_None, // G_SEXTLOAD = 62
CEFBS_None, // G_ZEXTLOAD = 63
CEFBS_None, // G_INDEXED_LOAD = 64
CEFBS_None, // G_INDEXED_SEXTLOAD = 65
CEFBS_None, // G_INDEXED_ZEXTLOAD = 66
CEFBS_None, // G_STORE = 67
CEFBS_None, // G_INDEXED_STORE = 68
CEFBS_None, // G_ATOMIC_CMPXCHG_WITH_SUCCESS = 69
CEFBS_None, // G_ATOMIC_CMPXCHG = 70
CEFBS_None, // G_ATOMICRMW_XCHG = 71
CEFBS_None, // G_ATOMICRMW_ADD = 72
CEFBS_None, // G_ATOMICRMW_SUB = 73
CEFBS_None, // G_ATOMICRMW_AND = 74
CEFBS_None, // G_ATOMICRMW_NAND = 75
CEFBS_None, // G_ATOMICRMW_OR = 76
CEFBS_None, // G_ATOMICRMW_XOR = 77
CEFBS_None, // G_ATOMICRMW_MAX = 78
CEFBS_None, // G_ATOMICRMW_MIN = 79
CEFBS_None, // G_ATOMICRMW_UMAX = 80
CEFBS_None, // G_ATOMICRMW_UMIN = 81
CEFBS_None, // G_ATOMICRMW_FADD = 82
CEFBS_None, // G_ATOMICRMW_FSUB = 83
CEFBS_None, // G_FENCE = 84
CEFBS_None, // G_BRCOND = 85
CEFBS_None, // G_BRINDIRECT = 86
CEFBS_None, // G_INTRINSIC = 87
CEFBS_None, // G_INTRINSIC_W_SIDE_EFFECTS = 88
CEFBS_None, // G_ANYEXT = 89
CEFBS_None, // G_TRUNC = 90
CEFBS_None, // G_CONSTANT = 91
CEFBS_None, // G_FCONSTANT = 92
CEFBS_None, // G_VASTART = 93
CEFBS_None, // G_VAARG = 94
CEFBS_None, // G_SEXT = 95
CEFBS_None, // G_SEXT_INREG = 96
CEFBS_None, // G_ZEXT = 97
CEFBS_None, // G_SHL = 98
CEFBS_None, // G_LSHR = 99
CEFBS_None, // G_ASHR = 100
CEFBS_None, // G_ICMP = 101
CEFBS_None, // G_FCMP = 102
CEFBS_None, // G_SELECT = 103
CEFBS_None, // G_UADDO = 104
CEFBS_None, // G_UADDE = 105
CEFBS_None, // G_USUBO = 106
CEFBS_None, // G_USUBE = 107
CEFBS_None, // G_SADDO = 108
CEFBS_None, // G_SADDE = 109
CEFBS_None, // G_SSUBO = 110
CEFBS_None, // G_SSUBE = 111
CEFBS_None, // G_UMULO = 112
CEFBS_None, // G_SMULO = 113
CEFBS_None, // G_UMULH = 114
CEFBS_None, // G_SMULH = 115
CEFBS_None, // G_FADD = 116
CEFBS_None, // G_FSUB = 117
CEFBS_None, // G_FMUL = 118
CEFBS_None, // G_FMA = 119
CEFBS_None, // G_FMAD = 120
CEFBS_None, // G_FDIV = 121
CEFBS_None, // G_FREM = 122
CEFBS_None, // G_FPOW = 123
CEFBS_None, // G_FEXP = 124
CEFBS_None, // G_FEXP2 = 125
CEFBS_None, // G_FLOG = 126
CEFBS_None, // G_FLOG2 = 127
CEFBS_None, // G_FLOG10 = 128
CEFBS_None, // G_FNEG = 129
CEFBS_None, // G_FPEXT = 130
CEFBS_None, // G_FPTRUNC = 131
CEFBS_None, // G_FPTOSI = 132
CEFBS_None, // G_FPTOUI = 133
CEFBS_None, // G_SITOFP = 134
CEFBS_None, // G_UITOFP = 135
CEFBS_None, // G_FABS = 136
CEFBS_None, // G_FCOPYSIGN = 137
CEFBS_None, // G_FCANONICALIZE = 138
CEFBS_None, // G_FMINNUM = 139
CEFBS_None, // G_FMAXNUM = 140
CEFBS_None, // G_FMINNUM_IEEE = 141
CEFBS_None, // G_FMAXNUM_IEEE = 142
CEFBS_None, // G_FMINIMUM = 143
CEFBS_None, // G_FMAXIMUM = 144
CEFBS_None, // G_GEP = 145
CEFBS_None, // G_PTR_MASK = 146
CEFBS_None, // G_SMIN = 147
CEFBS_None, // G_SMAX = 148
CEFBS_None, // G_UMIN = 149
CEFBS_None, // G_UMAX = 150
CEFBS_None, // G_BR = 151
CEFBS_None, // G_BRJT = 152
CEFBS_None, // G_INSERT_VECTOR_ELT = 153
CEFBS_None, // G_EXTRACT_VECTOR_ELT = 154
CEFBS_None, // G_SHUFFLE_VECTOR = 155
CEFBS_None, // G_CTTZ = 156
CEFBS_None, // G_CTTZ_ZERO_UNDEF = 157
CEFBS_None, // G_CTLZ = 158
CEFBS_None, // G_CTLZ_ZERO_UNDEF = 159
CEFBS_None, // G_CTPOP = 160
CEFBS_None, // G_BSWAP = 161
CEFBS_None, // G_BITREVERSE = 162
CEFBS_None, // G_FCEIL = 163
CEFBS_None, // G_FCOS = 164
CEFBS_None, // G_FSIN = 165
CEFBS_None, // G_FSQRT = 166
CEFBS_None, // G_FFLOOR = 167
CEFBS_None, // G_FRINT = 168
CEFBS_None, // G_FNEARBYINT = 169
CEFBS_None, // G_ADDRSPACE_CAST = 170
CEFBS_None, // G_BLOCK_ADDR = 171
CEFBS_None, // G_JUMP_TABLE = 172
CEFBS_None, // G_DYN_STACKALLOC = 173
CEFBS_None, // ADJCALLSTACKDOWN = 174
CEFBS_None, // ADJCALLSTACKUP = 175
CEFBS_None, // MEMCPY = 176
CEFBS_None, // Select = 177
CEFBS_None, // Select_32 = 178
CEFBS_None, // Select_32_64 = 179
CEFBS_None, // Select_64_32 = 180
CEFBS_None, // Select_Ri = 181
CEFBS_None, // Select_Ri_32 = 182
CEFBS_None, // Select_Ri_32_64 = 183
CEFBS_None, // Select_Ri_64_32 = 184
CEFBS_None, // ADD_ri = 185
CEFBS_None, // ADD_ri_32 = 186
CEFBS_None, // ADD_rr = 187
CEFBS_None, // ADD_rr_32 = 188
CEFBS_None, // AND_ri = 189
CEFBS_None, // AND_ri_32 = 190
CEFBS_None, // AND_rr = 191
CEFBS_None, // AND_rr_32 = 192
CEFBS_None, // BE16 = 193
CEFBS_None, // BE32 = 194
CEFBS_None, // BE64 = 195
CEFBS_None, // DIV_ri = 196
CEFBS_None, // DIV_ri_32 = 197
CEFBS_None, // DIV_rr = 198
CEFBS_None, // DIV_rr_32 = 199
CEFBS_None, // FI_ri = 200
CEFBS_None, // JAL = 201
CEFBS_None, // JALX = 202
CEFBS_None, // JEQ_ri = 203
CEFBS_None, // JEQ_ri_32 = 204
CEFBS_None, // JEQ_rr = 205
CEFBS_None, // JEQ_rr_32 = 206
CEFBS_None, // JMP = 207
CEFBS_None, // JNE_ri = 208
CEFBS_None, // JNE_ri_32 = 209
CEFBS_None, // JNE_rr = 210
CEFBS_None, // JNE_rr_32 = 211
CEFBS_None, // JSGE_ri = 212
CEFBS_None, // JSGE_ri_32 = 213
CEFBS_None, // JSGE_rr = 214
CEFBS_None, // JSGE_rr_32 = 215
CEFBS_None, // JSGT_ri = 216
CEFBS_None, // JSGT_ri_32 = 217
CEFBS_None, // JSGT_rr = 218
CEFBS_None, // JSGT_rr_32 = 219
CEFBS_None, // JSLE_ri = 220
CEFBS_None, // JSLE_ri_32 = 221
CEFBS_None, // JSLE_rr = 222
CEFBS_None, // JSLE_rr_32 = 223
CEFBS_None, // JSLT_ri = 224
CEFBS_None, // JSLT_ri_32 = 225
CEFBS_None, // JSLT_rr = 226
CEFBS_None, // JSLT_rr_32 = 227
CEFBS_None, // JUGE_ri = 228
CEFBS_None, // JUGE_ri_32 = 229
CEFBS_None, // JUGE_rr = 230
CEFBS_None, // JUGE_rr_32 = 231
CEFBS_None, // JUGT_ri = 232
CEFBS_None, // JUGT_ri_32 = 233
CEFBS_None, // JUGT_rr = 234
CEFBS_None, // JUGT_rr_32 = 235
CEFBS_None, // JULE_ri = 236
CEFBS_None, // JULE_ri_32 = 237
CEFBS_None, // JULE_rr = 238
CEFBS_None, // JULE_rr_32 = 239
CEFBS_None, // JULT_ri = 240
CEFBS_None, // JULT_ri_32 = 241
CEFBS_None, // JULT_rr = 242
CEFBS_None, // JULT_rr_32 = 243
CEFBS_None, // LDB = 244
CEFBS_None, // LDB32 = 245
CEFBS_None, // LDD = 246
CEFBS_None, // LDH = 247
CEFBS_None, // LDH32 = 248
CEFBS_None, // LDW = 249
CEFBS_None, // LDW32 = 250
CEFBS_None, // LD_ABS_B = 251
CEFBS_None, // LD_ABS_H = 252
CEFBS_None, // LD_ABS_W = 253
CEFBS_None, // LD_IND_B = 254
CEFBS_None, // LD_IND_H = 255
CEFBS_None, // LD_IND_W = 256
CEFBS_None, // LD_imm64 = 257
CEFBS_None, // LD_pseudo = 258
CEFBS_None, // LE16 = 259
CEFBS_None, // LE32 = 260
CEFBS_None, // LE64 = 261
CEFBS_None, // MOV_32_64 = 262
CEFBS_None, // MOV_ri = 263
CEFBS_None, // MOV_ri_32 = 264
CEFBS_None, // MOV_rr = 265
CEFBS_None, // MOV_rr_32 = 266
CEFBS_None, // MUL_ri = 267
CEFBS_None, // MUL_ri_32 = 268
CEFBS_None, // MUL_rr = 269
CEFBS_None, // MUL_rr_32 = 270
CEFBS_None, // NEG_32 = 271
CEFBS_None, // NEG_64 = 272
CEFBS_None, // NOP = 273
CEFBS_None, // OR_ri = 274
CEFBS_None, // OR_ri_32 = 275
CEFBS_None, // OR_rr = 276
CEFBS_None, // OR_rr_32 = 277
CEFBS_None, // RET = 278
CEFBS_None, // SLL_ri = 279
CEFBS_None, // SLL_ri_32 = 280
CEFBS_None, // SLL_rr = 281
CEFBS_None, // SLL_rr_32 = 282
CEFBS_None, // SRA_ri = 283
CEFBS_None, // SRA_ri_32 = 284
CEFBS_None, // SRA_rr = 285
CEFBS_None, // SRA_rr_32 = 286
CEFBS_None, // SRL_ri = 287
CEFBS_None, // SRL_ri_32 = 288
CEFBS_None, // SRL_rr = 289
CEFBS_None, // SRL_rr_32 = 290
CEFBS_None, // STB = 291
CEFBS_None, // STB32 = 292
CEFBS_None, // STD = 293
CEFBS_None, // STH = 294
CEFBS_None, // STH32 = 295
CEFBS_None, // STW = 296
CEFBS_None, // STW32 = 297
CEFBS_None, // SUB_ri = 298
CEFBS_None, // SUB_ri_32 = 299
CEFBS_None, // SUB_rr = 300
CEFBS_None, // SUB_rr_32 = 301
CEFBS_None, // XADDD = 302
CEFBS_None, // XADDW = 303
CEFBS_None, // XADDW32 = 304
CEFBS_None, // XOR_ri = 305
CEFBS_None, // XOR_ri_32 = 306
CEFBS_None, // XOR_rr = 307
CEFBS_None, // XOR_rr_32 = 308
};
assert(Inst.getOpcode() < 309);
const FeatureBitset &RequiredFeatures = FeatureBitsets[RequiredFeaturesRefs[Inst.getOpcode()]];
FeatureBitset MissingFeatures =
(AvailableFeatures & RequiredFeatures) ^
RequiredFeatures;
if (MissingFeatures.any()) {
std::ostringstream Msg;
Msg << "Attempting to emit " << MCII.getName(Inst.getOpcode()).str()
<< " instruction but the ";
for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
if (MissingFeatures.test(i))
Msg << SubtargetFeatureNames[i] << " ";
Msg << "predicate(s) are not met";
report_fatal_error(Msg.str());
}
#else
// Silence unused variable warning on targets that don't use MCII for other purposes (e.g. BPF).
(void)MCII;
#endif // NDEBUG
}
#endif
|