-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathAIE2PSInstrInfo.cpp
More file actions
2383 lines (2238 loc) · 100 KB
/
AIE2PSInstrInfo.cpp
File metadata and controls
2383 lines (2238 loc) · 100 KB
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
//===- AIE2PSInstrInfo.cpp AIE2ps Instruction Information -*------- C++ -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2025-2026 Advanced Micro Devices, Inc. or its affiliates
//
//===----------------------------------------------------------------------===//
//
// This file contains the AIE2ps implementation of the TargetInstrInfo
// class.
//
//===----------------------------------------------------------------------===//
#include "AIE2PSInstrInfo.h"
#include "AIE2PSRegisterInfo.h"
#include "AIE2PSSubtarget.h"
#include "AIE2PSTargetMachine.h"
#include "AIEBaseInstrInfo.h"
#include "AIEHazardRecognizer.h"
#include "AIEMachineFunctionInfo.h"
#include "AIEMachineScheduler.h"
#include "MCTargetDesc/AIEMCFormats.h"
#include "MCTargetDesc/aie2ps/AIE2PSMCTargetDesc.h"
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/MachineScheduler.h"
#include "llvm/IR/IntrinsicsAIE2.h"
#include "llvm/IR/IntrinsicsAIE2PS.h"
#define DEBUG_TYPE "aie-codegen"
using namespace llvm;
#define GET_INSTRINFO_CTOR_DTOR
#include "AIE2PSGenInstrInfo.inc"
#include "AIE2PSGenMemoryCycles.inc"
#include "AIE2PSGenPreSchedLowering.inc"
#include "AIE2PSGenSplitInstrTables.inc"
#include "AIE2PSGenVarInstructionItin.inc"
namespace {
const AIE2PSMCFormats AIE2PSFormats;
} // namespace
AIE2PSInstrInfo::AIE2PSInstrInfo()
: AIE2PSGenInstrInfo(AIE2PS::ADJCALLSTACKUP, AIE2PS::ADJCALLSTACKDOWN) {
FormatInterface = &AIE2PSFormats;
FuncUnitWrapper::setFormatInterface(FormatInterface);
}
unsigned AIE2PSInstrInfo::getReturnOpcode() const { return AIE2PS::PseudoRET; }
unsigned AIE2PSInstrInfo::getNopOpcode() const { return AIE2PS::NOP; }
unsigned AIE2PSInstrInfo::getMvSclOpcode() const {
return AIE2PS::MOV_alu_mv_mv_mv_scl;
}
unsigned AIE2PSInstrInfo::getMvSclMultiSlotPseudoOpcode() const {
return AIE2PS::MOVX_mvx_cr_imm;
}
static MCRegister getLoSubReg(const TargetRegisterInfo &TRI, MCRegister Reg) {
if (AIE2PS::eLRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_l_even);
if (AIE2PS::EXPVEC64RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_lo_exp);
if (AIE2PS::mEYwRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_bfp640_lo);
if (AIE2PS::mFEYwRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_bfp768_lo);
if (AIE2PS::VEC512RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_256_lo);
if (AIE2PS::VEC1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_512_lo);
if (AIE2PS::ACC1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_512_acc_lo);
if (AIE2PS::ACC2048RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_1024_acc_lo);
if (AIE2PS::FIFO1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_lo_fifo);
llvm_unreachable("unhandled case in getLoSubReg");
}
static MCRegister getHiSubReg(const TargetRegisterInfo &TRI, MCRegister Reg) {
if (AIE2PS::eLRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_l_odd);
if (AIE2PS::EXPVEC64RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_hi_exp);
if (AIE2PS::mEYwRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_bfp640_hi);
if (AIE2PS::mFEYwRegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_bfp768_hi);
if (AIE2PS::VEC512RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_256_hi);
if (AIE2PS::VEC1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_512_hi);
if (AIE2PS::ACC1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_512_acc_hi);
if (AIE2PS::ACC2048RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_1024_acc_hi);
if (AIE2PS::FIFO1024RegClass.contains(Reg))
return TRI.getSubReg(Reg, AIE2PS::sub_hi_fifo);
llvm_unreachable("unhandled case in getHiSubReg");
}
unsigned AIE2PSInstrInfo::getAddrIntrinsic2D() const {
return Intrinsic::aie2ps_add_2d;
}
unsigned AIE2PSInstrInfo::getAddrIntrinsic3D() const {
return Intrinsic::aie2ps_add_3d;
}
unsigned AIE2PSInstrInfo::getPtrAdd2DOpcode() const {
return AIE2PS::PADD_2D_pseudo;
}
unsigned AIE2PSInstrInfo::getPtrAdd3DOpcode() const {
return AIE2PS::PADD_3D_pseudo;
}
Register AIE2PSInstrInfo::getVaddSignControlRegister() const {
return AIE2PS::vaddSign0;
}
unsigned AIE2PSInstrInfo::getOpCode(MachineInstr &I) const {
const MachineRegisterInfo &MRI = I.getMF()->getRegInfo();
unsigned IntrinsicID = cast<GIntrinsic>(I).getIntrinsicID();
switch (IntrinsicID) {
// vsrs
case Intrinsic::aie2ps_I256_v16_acc32_srs:
case Intrinsic::aie2ps_I256_v8_acc64_srs:
return AIE2PS::VSRS_2x_mv_w_srs_bm_srsSign0;
case Intrinsic::aie2ps_I512_v32_acc32_srs:
case Intrinsic::aie2ps_I512_v16_acc64_srs:
return AIE2PS::VSRS_2x_mv_x_srs_cm_srsSign0;
case Intrinsic::aie2ps_I512_v64_acc32_srs:
case Intrinsic::aie2ps_I512_v32_acc64_srs:
return AIE2PS::VSRS_4x_mv_x_srs_dm_srsSign0;
case Intrinsic::aie2ps_I256_v32_acc32_srs:
case Intrinsic::aie2ps_I256_v16_acc64_srs:
return AIE2PS::VSRS_4x_mv_w_srs_cm_srsSign0;
// vups
case Intrinsic::aie2ps_acc32_v16_I256_ups:
case Intrinsic::aie2ps_acc64_v8_I256_ups:
return AIE2PS::VUPS_2x_mv_ups_w2b_upsSign0;
case Intrinsic::aie2ps_acc32_v32_I256_ups:
case Intrinsic::aie2ps_acc64_v16_I256_ups:
return AIE2PS::VUPS_4x_mv_ups_w2c_upsSign0;
case Intrinsic::aie2ps_acc32_v32_I512_ups:
case Intrinsic::aie2ps_acc64_v16_I512_ups:
return AIE2PS::VUPS_2x_mv_ups_x2c_upsSign0;
case Intrinsic::aie2ps_acc32_v64_I512_ups:
case Intrinsic::aie2ps_acc64_v32_I512_ups:
return AIE2PS::VUPS_4x_mv_ups_x2d_upsSign0;
// Vmax Intrinsic
case Intrinsic::aie2ps_vmax_lt8:
return AIE2PS::VMAX_LT_8_vaddSign0;
case Intrinsic::aie2ps_vmax_lt16:
return AIE2PS::VMAX_LT_16_vaddSign0;
case Intrinsic::aie2ps_vmax_lt32:
return AIE2PS::VMAX_LT_32_vaddSign0;
// Vmin Intrinsic
case Intrinsic::aie2ps_vmin_ge8:
return AIE2PS::VMIN_GE_8_vaddSign0;
case Intrinsic::aie2ps_vmin_ge16:
return AIE2PS::VMIN_GE_16_vaddSign0;
case Intrinsic::aie2ps_vmin_ge32:
return AIE2PS::VMIN_GE_32_vaddSign0;
// VGE / VLT
case Intrinsic::aie2ps_vlt8:
return AIE2PS::VLT_8_vaddSign0;
case Intrinsic::aie2ps_vlt16:
return AIE2PS::VLT_16_vaddSign0;
case Intrinsic::aie2ps_vlt32:
return AIE2PS::VLT_32_vaddSign0;
case Intrinsic::aie2ps_vge8:
return AIE2PS::VGE_8_vaddSign0;
case Intrinsic::aie2ps_vge16:
return AIE2PS::VGE_16_vaddSign0;
case Intrinsic::aie2ps_vge32:
return AIE2PS::VGE_32_vaddSign0;
// VMAXDIFF_LT
case Intrinsic::aie2ps_vmaxdiff_lt8:
return AIE2PS::VMAXDIFF_LT_8_vaddSign0;
case Intrinsic::aie2ps_vmaxdiff_lt16:
return AIE2PS::VMAXDIFF_LT_16_vaddSign0;
case Intrinsic::aie2ps_vmaxdiff_lt32:
return AIE2PS::VMAXDIFF_LT_32_vaddSign0;
// VABS_GTZ
case Intrinsic::aie2ps_vabs_gtz8:
return AIE2PS::VABS_GTZ8_vaddSign0;
case Intrinsic::aie2ps_vabs_gtz16:
return AIE2PS::VABS_GTZ16_vaddSign0;
case Intrinsic::aie2ps_vabs_gtz32:
return AIE2PS::VABS_GTZ32_vaddSign0;
// VSUB_LT/VSUB_GE
case Intrinsic::aie2ps_vsub_lt8:
return AIE2PS::VSUB_LT_8_vaddSign0;
case Intrinsic::aie2ps_vsub_lt16:
return AIE2PS::VSUB_LT_16_vaddSign0;
case Intrinsic::aie2ps_vsub_lt32:
return AIE2PS::VSUB_LT_32_vaddSign0;
case Intrinsic::aie2ps_vsub_ge8:
return AIE2PS::VSUB_GE_8_vaddSign0;
case Intrinsic::aie2ps_vsub_ge16:
return AIE2PS::VSUB_GE_16_vaddSign0;
case Intrinsic::aie2ps_vsub_ge32:
return AIE2PS::VSUB_GE_32_vaddSign0;
// Pack
case Intrinsic::aie2ps_pack_I1024_I8_I16:
case Intrinsic::aie2ps_pack_I1024_I4_I8:
case Intrinsic::aie2ps_pack_I512_I8_I16:
case Intrinsic::aie2ps_pack_I512_I4_I8: {
Register SignReg = I.getOperand(3).getReg();
auto Sign = getIConstantVRegValWithLookThrough(SignReg, MRI);
bool isSigned = Sign && Sign->Value.getZExtValue();
if (IntrinsicID == Intrinsic::aie2ps_pack_I512_I8_I16 ||
IntrinsicID == Intrinsic::aie2ps_pack_I512_I4_I8)
return isSigned ? AIE2PS::VPACK_mv_pack_w_packSign1
: AIE2PS::VPACK_mv_pack_w_packSign0;
else
return isSigned ? AIE2PS::VPACK_mv_pack_x_packSign1
: AIE2PS::VPACK_mv_pack_x_packSign0;
}
// Unpack
case Intrinsic::aie2ps_unpack_I1024_I16_I8:
case Intrinsic::aie2ps_unpack_I1024_I8_I4:
case Intrinsic::aie2ps_unpack_I512_I16_I8:
case Intrinsic::aie2ps_unpack_I512_I8_I4: {
Register SignReg = I.getOperand(3).getReg();
auto Sign = getIConstantVRegValWithLookThrough(SignReg, MRI);
bool isSigned = Sign && Sign->Value.getZExtValue();
if (IntrinsicID == Intrinsic::aie2ps_unpack_I512_I16_I8 ||
IntrinsicID == Intrinsic::aie2ps_unpack_I512_I8_I4)
return isSigned ? AIE2PS::VUNPACK_mv_unpack_w_unpackSign1
: AIE2PS::VUNPACK_mv_unpack_w_unpackSign0;
else
return isSigned ? AIE2PS::VUNPACK_mv_unpack_x_unpackSign1
: AIE2PS::VUNPACK_mv_unpack_x_unpackSign0;
}
// Cascade stream read (SCD)
case Intrinsic::aie2ps_scd_read_vec:
return AIE2PS::VMOV_alu_mv_alu_mv_scd_x;
case Intrinsic::aie2ps_scd_read_acc32:
return AIE2PS::VMOV_alu_mv_alu_mv_scd_bm;
case Intrinsic::aie2ps_scd_expand_lo:
return AIE2PS::VMOV_0_mv_scd_cm;
case Intrinsic::aie2ps_scd_expand_hi:
return AIE2PS::VMOV_1_mv_scd_cm;
case Intrinsic::aie2ps_scd_ACC2048: {
Register SrcReg = I.getOperand(3).getReg();
if (auto Src = getIConstantVRegValWithLookThrough(SrcReg, MRI)) {
unsigned SrcConstVal = Src->Value.getZExtValue();
switch (SrcConstVal) {
case 0:
return AIE2PS::VMOV_0_mv_scd_dm_imm;
case 1:
return AIE2PS::VMOV_1_mv_scd_dm_imm;
case 2:
return AIE2PS::VMOV_2;
case 3:
return AIE2PS::VMOV_3;
default:
llvm_unreachable("Unexpected SrcConstVal for SCD");
}
}
llvm_unreachable("Unexpected non-constant for SCD");
}
case Intrinsic::aie2ps_scd_expand_ACC1024:
case Intrinsic::aie2ps_scd_expand_ACC2048:
return AIE2PS::VMOV_alu_mv_alu_mv_scd_dm_reg;
case Intrinsic::aie2ps_scd_expand_ACC1024_incr:
case Intrinsic::aie2ps_scd_expand_ACC2048_incr:
return AIE2PS::VMOV_alu_mv_alu_mv_scd_dm_dyn;
// Cascade stream write (MCD)
case Intrinsic::aie2ps_mcd_write_vec:
return AIE2PS::VMOV_st_mv_mcd_x;
case Intrinsic::aie2ps_mcd_write_acc32:
return AIE2PS::VMOV_st_mv_mcd_bm;
// Scalar stream intrinsics
case Intrinsic::aie2ps_get_ss:
return AIE2PS::MOV_lda;
case Intrinsic::aie2ps_get_ss_nb:
return AIE2PS::MOV_nb_lda;
case Intrinsic::aie2ps_put_ms:
return AIE2PS::MOV_st_mMStream_tlast_reg;
case Intrinsic::aie2ps_put_ms_nb:
return AIE2PS::MOV_nb_st_mMStream_tlast_reg;
default:
llvm_unreachable("Unexpected Intrinsic ID");
}
}
// Implement CopyToReg/CopyFromReg
void AIE2PSInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg,
MCRegister SrcReg, bool KillSrc,
bool RenamableDest, bool RenamableSrc) const {
MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
if (AIE2PS::mMvSclSrcRegClass.contains(SrcReg) &&
AIE2PS::mMvSclDstRegClass.contains(DstReg)) {
// Build MultiSlotPseudo in preference
const unsigned MOVSclOpcode = getScalarMovOpcode(DstReg, SrcReg);
BuildMI(MBB, MBBI, DL, get(MOVSclOpcode), DstReg)
.addReg(SrcReg, getKillRegState(KillSrc));
// clang-format off
#define HANDLE_MOV_CASE(SRC_CLASS, DST_CLASS, OPCODE) \
} else if ((AIE2PS::SRC_CLASS##RegClass.contains(SrcReg)) && \
(AIE2PS::DST_CLASS##RegClass.contains(DstReg))) { \
BuildMI(MBB, MBBI, DL, get(AIE2PS::MOV_alu_mv_mv_mv_##OPCODE), DstReg) \
.addReg(SrcReg, getKillRegState(KillSrc));
HANDLE_MOV_CASE(eR, mSCm, sc_r)
HANDLE_MOV_CASE(mSCm, eR, r_sc)
HANDLE_MOV_CASE(mElm, mElm, e_mv_el_to_el)
HANDLE_MOV_CASE(mEhm, mEhm, e_mv_eh_to_eh)
HANDLE_MOV_CASE(mElm, mEhm, e_mv_el_to_eh)
HANDLE_MOV_CASE(mEhm, mElm, e_mv_eh_to_el)
HANDLE_MOV_CASE(eR, mEhm, e_mv_r_to_eh)
HANDLE_MOV_CASE(eR, mElm, e_mv_r_to_el)
HANDLE_MOV_CASE(mEhm, eR, e_mv_eh_to_r)
HANDLE_MOV_CASE(mElm, eR, e_mv_el_to_r)
HANDLE_MOV_CASE(mGlm, mGlm, g_mv_gl_to_gl)
HANDLE_MOV_CASE(mGhm, mGhm, g_mv_gh_to_gh)
HANDLE_MOV_CASE(mGlm, mGhm, g_mv_gl_to_gh)
HANDLE_MOV_CASE(mGhm, mGlm, g_mv_gh_to_gl)
HANDLE_MOV_CASE(eR, mGhm, g_mv_r_to_gh)
HANDLE_MOV_CASE(eR, mGlm, g_mv_r_to_gl)
HANDLE_MOV_CASE(mGhm, eR, g_mv_gh_to_r)
HANDLE_MOV_CASE(mGlm, eR, g_mv_gl_to_r)
#undef HANDLE_MOV_CASE
// clang-format on
} else if ((AIE2PS::eLRegClass.contains(SrcReg)) &&
(AIE2PS::eLRegClass.contains(DstReg))) {
copyThroughSubRegs(MBB, MBBI, DL, DstReg, SrcReg, KillSrc);
} else if ((AIE2PS::eDRegClass.contains(SrcReg)) &&
(AIE2PS::eDRegClass.contains(DstReg))) {
copyThroughSubRegs(MBB, MBBI, DL, DstReg, SrcReg, KillSrc);
} else if ((AIE2PS::eDSRegClass.contains(SrcReg)) &&
(AIE2PS::eDSRegClass.contains(DstReg))) {
copyThroughSubRegs(MBB, MBBI, DL, DstReg, SrcReg, KillSrc);
// clang-format off
#define HANDLE_VMOV_CASE(SRC_CLASS, DST_CLASS, OPCODE) \
} else if ((AIE2PS::SRC_CLASS##RegClass.contains(SrcReg)) && \
(AIE2PS::DST_CLASS##RegClass.contains(DstReg))) { \
BuildMI(MBB, MBBI, DL, get(AIE2PS::VMOV_alu_mv_mv_mv_##OPCODE), DstReg) \
.addReg(SrcReg, getKillRegState(KillSrc));
HANDLE_VMOV_CASE(mFm, mFm, f)
HANDLE_VMOV_CASE(mWm, mWm, w)
HANDLE_VMOV_CASE(mCMm, mCMm, cm)
HANDLE_VMOV_CASE(mEEm, mEEm, ee)
HANDLE_VMOV_CASE(mEGm, mEGm, eg)
HANDLE_VMOV_CASE(mFFm, mFFm, ff)
HANDLE_VMOV_CASE(mGGm, mGGm, gg)
HANDLE_VMOV_CASE(mEWm, mEWm, egw)
HANDLE_VMOV_CASE(mEXm, mEXm, egx)
HANDLE_VMOV_CASE(mEG2m, mEG2m, eg2)
HANDLE_VMOV_CASE(mFEWm, mFEWm, few)
HANDLE_VMOV_CASE(mFEXm, mFEXm, fex)
HANDLE_VMOV_CASE(mFm, mLm, f_to_l)
HANDLE_VMOV_CASE(mLm, mFm, l_to_f)
HANDLE_VMOV_CASE(mWm, mEG2m, w_to_eg2)
HANDLE_VMOV_CASE(mEG2m, mWm, eg2_to_w)
HANDLE_VMOV_CASE(mMvBMXSrc, mMvBMXDst, x)
#undef HANDLE_VMOV_CASE
// clang-format on
} else if ((AIE2PS::eLRegClass.contains(SrcReg)) &&
(AIE2PS::EXPVEC64RegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::EXPVEC64RegClass.contains(SrcReg)) &&
(AIE2PS::eLRegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::mEYwRegClass.contains(SrcReg)) &&
(AIE2PS::mEYwRegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::mFEYwRegClass.contains(SrcReg)) &&
(AIE2PS::mFEYwRegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::ACC1024RegClass.contains(SrcReg) ||
AIE2PS::VEC1024RegClass.contains(SrcReg) ||
AIE2PS::FIFO1024RegClass.contains(SrcReg)) &&
(AIE2PS::ACC1024RegClass.contains(DstReg) ||
AIE2PS::VEC1024RegClass.contains(DstReg) ||
AIE2PS::FIFO1024RegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::ACC2048RegClass.contains(SrcReg)) &&
(AIE2PS::ACC2048RegClass.contains(DstReg))) {
copyPhysReg(MBB, MBBI, DL, getLoSubReg(TRI, DstReg),
getLoSubReg(TRI, SrcReg), KillSrc);
copyPhysReg(MBB, MBBI, DL, getHiSubReg(TRI, DstReg),
getHiSubReg(TRI, SrcReg), KillSrc);
} else if ((AIE2PS::ePSRFLdFRegClass.contains(SrcReg)) &&
(AIE2PS::ePSRFLdFRegClass.contains(DstReg))) {
copyThroughSubRegs(MBB, MBBI, DL, DstReg, SrcReg, KillSrc);
} else {
llvm_unreachable("unhandled case in copyPhysReg");
}
}
static const TargetRegisterClass *
constrainRegClass(MachineRegisterInfo &MRI, const TargetRegisterClass *RC,
unsigned Reg) {
if (RC == nullptr || Register::isPhysicalRegister(Reg))
return RC;
// eP, eM, eDN, eDJ, eDC, eSpecial20
if (auto *NewRC = MRI.constrainRegClass(Reg, &AIE2PS::eP_as_32BitRegClass))
return NewRC;
if (auto *NewRC = MRI.constrainRegClass(Reg, &AIE2PS::eM_as_32BitRegClass))
return NewRC;
if (auto *NewRC = MRI.constrainRegClass(Reg, &AIE2PS::eDN_as_32BitRegClass))
return NewRC;
if (auto *NewRC = MRI.constrainRegClass(Reg, &AIE2PS::eDJ_as_32BitRegClass))
return NewRC;
if (auto *NewRC = MRI.constrainRegClass(Reg, &AIE2PS::eDC_as_32BitRegClass))
return NewRC;
if (auto *NewRC =
MRI.constrainRegClass(Reg, &AIE2PS::eSpecial20_as_32BitRegClass))
return NewRC;
return RC;
}
Register AIE2PSInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
int &FrameIndex) const {
switch (MI.getOpcode()) {
default:
return 0;
case AIE2PS::LDA_R_SPILL:
case AIE2PS::LDA_L_SPILL:
case AIE2PS::LDA_D_SPILL:
case AIE2PS::LDA_DS_SPILL:
case AIE2PS::VLDA_V_SPILL:
case AIE2PS::VLDA_W_SPILL:
case AIE2PS::VLDA_X_SPILL:
case AIE2PS::VLDA_Y_SPILL:
case AIE2PS::VLDA_BM_SPILL:
case AIE2PS::VLDA_CM_SPILL:
case AIE2PS::VLDA_DM_SPILL:
case AIE2PS::VLDA_E_SPILL:
case AIE2PS::VLDA_EE_SPILL:
case AIE2PS::VLDA_F_SPILL:
case AIE2PS::VLDA_FF_SPILL:
case AIE2PS::VLDA_G_SPILL:
case AIE2PS::VLDA_GG_SPILL:
case AIE2PS::VLDA_EG_SPILL:
case AIE2PS::VLDA_EG2_SPILL:
case AIE2PS::VLDA_FEG_SPILL:
case AIE2PS::VLDA_FEG2_SPILL:
case AIE2PS::VLDA_EW_SPILL:
case AIE2PS::VLDA_EX_SPILL:
case AIE2PS::VLDA_EY_SPILL:
case AIE2PS::VLDA_FEW_SPILL:
case AIE2PS::VLDA_FEX_SPILL:
case AIE2PS::VLDA_FEY_SPILL:
break;
}
if (MI.getOperand(1).isFI()) {
FrameIndex = MI.getOperand(1).getIndex();
return MI.getOperand(0).getReg();
}
return 0;
}
Register AIE2PSInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
int &FrameIndex) const {
switch (MI.getOpcode()) {
default:
return 0;
case AIE2PS::ST_R_SPILL:
case AIE2PS::ST_L_SPILL:
case AIE2PS::ST_D_SPILL:
case AIE2PS::ST_DS_SPILL:
case AIE2PS::VST_V_SPILL:
case AIE2PS::VST_W_SPILL:
case AIE2PS::VST_X_SPILL:
case AIE2PS::VST_Y_SPILL:
case AIE2PS::VST_BM_SPILL:
case AIE2PS::VST_CM_SPILL:
case AIE2PS::VST_DM_SPILL:
case AIE2PS::VST_E_SPILL:
case AIE2PS::VST_EE_SPILL:
case AIE2PS::VST_F_SPILL:
case AIE2PS::VST_FF_SPILL:
case AIE2PS::VST_G_SPILL:
case AIE2PS::VST_GG_SPILL:
case AIE2PS::VST_EG_SPILL:
case AIE2PS::VST_EG2_SPILL:
case AIE2PS::VST_FEG_SPILL:
case AIE2PS::VST_FEG2_SPILL:
case AIE2PS::VST_EW_SPILL:
case AIE2PS::VST_EX_SPILL:
case AIE2PS::VST_EY_SPILL:
case AIE2PS::VST_FEW_SPILL:
case AIE2PS::VST_FEX_SPILL:
case AIE2PS::VST_FEY_SPILL:
break;
}
if (MI.getOperand(1).isFI()) {
FrameIndex = MI.getOperand(1).getIndex();
return MI.getOperand(0).getReg();
}
return 0;
}
SmallVector<AIEBaseInstrInfo::AIEPseudoExpandInfo, 4>
AIE2PSInstrInfo::getSpillPseudoExpandInfo(const TargetRegisterInfo &TRI,
MachineInstr &MI) const {
if (!MI.isPseudo())
return {};
switch (MI.getOpcode()) {
case AIE2PS::ST_R_SPILL:
return {{AIE2PS::ST_dms_sts_scalar_spill}};
case AIE2PS::ST_L_SPILL:
return {{AIE2PS::ST_dml_sts_scalar_spill}};
case AIE2PS::ST_D_SPILL:
return {{AIE2PS::ST_dms_sts_scalar_spill, AIE2PS::sub_mod},
{AIE2PS::ST_dms_sts_scalar_spill, AIE2PS::sub_dim_size},
{AIE2PS::ST_dms_sts_scalar_spill, AIE2PS::sub_dim_stride},
{AIE2PS::ST_dms_sts_scalar_spill, AIE2PS::sub_dim_count}};
case AIE2PS::ST_DS_SPILL:
return {{AIE2PS::ST_D_SPILL, AIE2PS::sub_lo_dim},
{AIE2PS::ST_D_SPILL, AIE2PS::sub_hi_dim}};
case AIE2PS::VST_V_SPILL:
return {{AIE2PS::VST_128_dmv_sts_w_spill}};
case AIE2PS::VST_W_SPILL:
return {{AIE2PS::VST_dmw_sts_w_spill}};
case AIE2PS::VST_X_SPILL:
return {{AIE2PS::VST_dmx_sts_x_spill}};
case AIE2PS::VST_Y_SPILL:
return {{AIE2PS::VST_X_SPILL, AIE2PS::sub_512_lo},
{AIE2PS::VST_X_SPILL, AIE2PS::sub_512_hi}};
case AIE2PS::VST_BM_SPILL:
return {{AIE2PS::VST_dmx_sts_bm_spill}};
case AIE2PS::VST_CM_SPILL:
return {{AIE2PS::VST_BM_SPILL, AIE2PS::sub_512_acc_lo},
{AIE2PS::VST_BM_SPILL, AIE2PS::sub_512_acc_hi}};
case AIE2PS::VST_DM_SPILL:
return {{AIE2PS::VST_CM_SPILL, AIE2PS::sub_1024_acc_lo},
{AIE2PS::VST_CM_SPILL, AIE2PS::sub_1024_acc_hi}};
case AIE2PS::VST_E_SPILL:
return {{AIE2PS::ST_dms_sts_scalar_spill}};
case AIE2PS::VST_EE_SPILL:
return {{AIE2PS::ST_dml_sts_scalar_spill}};
case AIE2PS::VST_F_SPILL:
return {{AIE2PS::ST_dml_sts_scalar_spill}};
case AIE2PS::VST_FF_SPILL:
return {{AIE2PS::ST_dmv_sts_f_spill}};
case AIE2PS::VST_G_SPILL:
return {{AIE2PS::ST_dms_sts_g_spill}};
case AIE2PS::VST_GG_SPILL:
return {{AIE2PS::ST_dml_sts_scalar_spill}};
case AIE2PS::VST_EG_SPILL:
return {{AIE2PS::ST_dml_sts_scalar_spill}};
case AIE2PS::VST_EG2_SPILL:
return {{AIE2PS::VST_128_dmv_sts_eg_spill}};
case AIE2PS::VST_FEG_SPILL:
return {{AIE2PS::VST_128_dmv_sts_feg_spill}};
case AIE2PS::VST_FEG2_SPILL:
return {{AIE2PS::VST_dmw_sts_feg2_spill}};
case AIE2PS::VST_EW_SPILL: // FIXME: Use VST_EG_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp_e32}};
case AIE2PS::VST_EX_SPILL: // FIXME: Use VST_X_SPILL and VST_EG2_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_e32}};
case AIE2PS::VST_EY_SPILL: // FIXME: Use 2xVST_X_SPILL and 2xVST_EG2_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_v256},
{AIE2PS::VST_W_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_g32},
{AIE2PS::VST_G_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_e32},
{AIE2PS::VST_E_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_e32}};
case AIE2PS::VST_FEW_SPILL: // FIXME: Use VST_FEG_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_few_bfp_e32}};
case AIE2PS::VST_FEX_SPILL: // FIXME: Use VST_X_SPILL and VST_FEG2_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_few_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_e32}};
case AIE2PS::VST_FEY_SPILL: // FIXME: Use 2xVST_X_SPILL and 2xVST_FEG2_SPILL
return {{AIE2PS::VST_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VST_W_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_w},
{AIE2PS::VST_W_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VST_F_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_f64},
{AIE2PS::VST_F_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VST_G_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_g32},
{AIE2PS::VST_G_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_few_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_e32},
{AIE2PS::VST_E_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_e32},
{AIE2PS::VST_E_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_e32}};
case AIE2PS::LDA_R_SPILL:
return {{AIE2PS::LDA_dms_lda_scalar_spill}};
case AIE2PS::LDA_L_SPILL:
return {{AIE2PS::LDA_dml_lda_scalar_L_spill}};
case AIE2PS::LDA_D_SPILL:
return {{AIE2PS::LDA_dms_lda_scalar_spill, AIE2PS::sub_mod},
{AIE2PS::LDA_dms_lda_scalar_spill, AIE2PS::sub_dim_size},
{AIE2PS::LDA_dms_lda_scalar_spill, AIE2PS::sub_dim_stride},
{AIE2PS::LDA_dms_lda_scalar_spill, AIE2PS::sub_dim_count}};
case AIE2PS::LDA_DS_SPILL:
return {{AIE2PS::LDA_D_SPILL, AIE2PS::sub_lo_dim},
{AIE2PS::LDA_D_SPILL, AIE2PS::sub_hi_dim}};
case AIE2PS::VLDA_V_SPILL:
return {{AIE2PS::VLDA_128_dmv_lda_w_spill}};
case AIE2PS::VLDA_W_SPILL:
return {{AIE2PS::VLDA_dmw_lda_w_spill}};
case AIE2PS::VLDA_X_SPILL:
return {{AIE2PS::VLDA_dmx_lda_x_spill}};
case AIE2PS::VLDA_Y_SPILL:
return {{AIE2PS::VLDA_X_SPILL, AIE2PS::sub_512_lo},
{AIE2PS::VLDA_X_SPILL, AIE2PS::sub_512_hi}};
case AIE2PS::VLDA_BM_SPILL:
return {{AIE2PS::VLDA_dmx_lda_bm_spill}};
case AIE2PS::VLDA_CM_SPILL:
return {{AIE2PS::VLDA_BM_SPILL, AIE2PS::sub_512_acc_lo},
{AIE2PS::VLDA_BM_SPILL, AIE2PS::sub_512_acc_hi}};
case AIE2PS::VLDA_DM_SPILL:
return {{AIE2PS::VLDA_CM_SPILL, AIE2PS::sub_1024_acc_lo},
{AIE2PS::VLDA_CM_SPILL, AIE2PS::sub_1024_acc_hi}};
case AIE2PS::VLDA_E_SPILL:
return {{AIE2PS::LDA_dms_lda_scalar_spill}};
case AIE2PS::VLDA_EE_SPILL:
return {{AIE2PS::LDA_dml_lda2_scalar_EE_spill}};
case AIE2PS::VLDA_F_SPILL:
return {{AIE2PS::LDA_dml_lda_scalar_F_spill}};
case AIE2PS::VLDA_FF_SPILL:
return {{AIE2PS::LDA_dmv_lda_f_spill}};
case AIE2PS::VLDA_G_SPILL:
return {{AIE2PS::LDA_dms_lda_g_spill}};
case AIE2PS::VLDA_GG_SPILL:
return {{AIE2PS::LDA_dml_lda2_scalar_GG_spill}};
case AIE2PS::VLDA_EG_SPILL:
return {{AIE2PS::LDA_dml_lda2_scalar_EG_spill}};
case AIE2PS::VLDA_EG2_SPILL:
return {{AIE2PS::LDA_dmv_lda_eg2_spill}};
case AIE2PS::VLDA_FEG_SPILL:
return {{AIE2PS::LDA_dmv_lda_feg_spill}};
case AIE2PS::VLDA_FEG2_SPILL:
return {{AIE2PS::VLDA_dmw_lda_feg2_spill}};
case AIE2PS::VLDA_EW_SPILL: // FIXME: Use VLDA_EG_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp_e32}};
case AIE2PS::VLDA_EX_SPILL: // FIXME: Use VLDA_EG2_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_e32}};
case AIE2PS::VLDA_EY_SPILL: // FIXME: Use 2xVLDA_X_SPILL and 2xVLDA_EG2_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp_v256},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_v256},
{AIE2PS::VLDA_W_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_v256},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_g32},
{AIE2PS::VLDA_G_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp320_hi_then_sub_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp640_hi_then_sub_bfp_e32},
{AIE2PS::VLDA_E_SPILL,
AIE2PS::sub_bfp640_hi_then_sub_bfp320_hi_then_sub_bfp_e32}};
case AIE2PS::VLDA_FEW_SPILL: // FIXME: Use VLDA_FEG_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_few_bfp_e32}};
case AIE2PS::VLDA_FEX_SPILL: // FIXME: Use VLDA_X_SPILL and VLDA_FEG2_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_few_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_e32}};
case AIE2PS::VLDA_FEY_SPILL: // FIXME: Use 2xVLDA_X_SPILL and
// 2xVLDA_FEG2_SPILL
return {{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_few_bfp_w},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VLDA_W_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_w},
{AIE2PS::VLDA_W_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_w},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_few_bfp_f64},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VLDA_F_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_f64},
{AIE2PS::VLDA_F_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_f64},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_few_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VLDA_G_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_g32},
{AIE2PS::VLDA_G_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_g32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_few_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp384_hi_then_sub_few_bfp_e32},
{AIE2PS::VLDA_E_SPILL, AIE2PS::sub_bfp768_hi_then_sub_few_bfp_e32},
{AIE2PS::VLDA_E_SPILL,
AIE2PS::sub_bfp768_hi_then_sub_bfp384_hi_then_sub_few_bfp_e32}};
default:
// TODO: Implement other pseudos. Unreachable is replaced with return of an
// empty struct to allow testing elimination of frame index. This is
// equivalent to an unimplemented getSpillPseudoExpandInfo.
return {};
// llvm_unreachable("Un-handled spill opcode.");
}
}
/// Create a MachineMemOperand for a sub-register spill/reload at the current
/// ByteOffset within the stack slot. ByteOffset is advanced by the sub-reg
/// size.
static MachineMemOperand *
createSubRegSpillMMO(MachineFunction &MF, const TargetRegisterInfo *TRI,
const TargetRegisterClass *RC, Register Reg, int FI,
unsigned SubRegIdx, unsigned &ByteOffset,
MachineMemOperand::Flags Flag) {
MachineFrameInfo &MFI = MF.getFrameInfo();
if (!RC)
RC = TRI->getMinimalPhysRegClass(Reg);
const TargetRegisterClass *SubRC = TRI->getSubRegisterClass(RC, SubRegIdx);
const unsigned ByteSize = TRI->getSpillSize(*SubRC);
MachinePointerInfo PtrInfo =
MachinePointerInfo::getFixedStack(MF, FI, ByteOffset);
ByteOffset += ByteSize;
return MF.getMachineMemOperand(PtrInfo, Flag, ByteSize,
MFI.getObjectAlign(FI));
}
/// Emit spill/reload instructions for the PSRFL composite register.
/// Sub_fifo is bounced through a VEC1024 temporary; sub_avail and sub_ptr
/// are spilled/reloaded directly via scalar spill instructions.
static void emitPSRFLSpillReload(const AIE2PSInstrInfo &TII,
MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
const DebugLoc &DL, Register Reg, bool IsKill,
int FI, const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI, bool IsStore) {
MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
MachineFunction &MF = *MBB.getParent();
unsigned ByteOffset = 0;
const auto MMOFlag =
IsStore ? MachineMemOperand::MOStore : MachineMemOperand::MOLoad;
auto CreateSubRegMMO = [&](unsigned SubRegIdx) {
return createSubRegSpillMMO(MF, TRI, RC, Reg, FI, SubRegIdx, ByteOffset,
MMOFlag);
};
// Adds Reg with SubRegIdx as a source operand (for stores).
auto addSrcSubReg = [&](MachineInstrBuilder MIB,
unsigned SubRegIdx) -> MachineInstrBuilder {
if (Reg.isPhysical())
return MIB.addReg(TRI->getSubReg(Reg, SubRegIdx),
getKillRegState(IsKill));
return MIB.addReg(Reg, getKillRegState(IsKill), SubRegIdx);
};
// Starts a BuildMI with Reg.SubRegIdx as the def (for loads).
auto buildWithDefSubReg = [&](unsigned Opcode,
unsigned SubRegIdx) -> MachineInstrBuilder {
if (Reg.isPhysical())
return BuildMI(MBB, I, DL, TII.get(Opcode),
TRI->getSubReg(Reg, SubRegIdx));
return BuildMI(MBB, I, DL, TII.get(Opcode))
.addReg(Reg, RegState::DefineNoRead, SubRegIdx);
};
// Bounce sub_fifo through a VEC1024 temporary.
Register TmpReg = MRI.createVirtualRegister(&AIE2PS::VEC1024RegClass);
if (IsStore) {
addSrcSubReg(BuildMI(MBB, I, DL, TII.get(AIE2PS::COPY), TmpReg),
AIE2PS::sub_fifo);
BuildMI(MBB, I, DL, TII.get(AIE2PS::VST_Y_SPILL))
.addReg(TmpReg, getKillRegState(true))
.addFrameIndex(FI)
.addMemOperand(CreateSubRegMMO(AIE2PS::sub_fifo));
} else {
BuildMI(MBB, I, DL, TII.get(AIE2PS::VLDA_Y_SPILL), TmpReg)
.addFrameIndex(FI)
.addMemOperand(CreateSubRegMMO(AIE2PS::sub_fifo));
buildWithDefSubReg(AIE2PS::COPY, AIE2PS::sub_fifo)
.addReg(TmpReg, getKillRegState(true));
}
// Spill/reload sub_avail and sub_ptr directly via scalar instructions.
const unsigned ScalarOpc = IsStore ? AIE2PS::ST_R_SPILL : AIE2PS::LDA_R_SPILL;
for (const unsigned SubIdx : {AIE2PS::sub_avail, AIE2PS::sub_ptr}) {
if (IsStore)
addSrcSubReg(BuildMI(MBB, I, DL, TII.get(ScalarOpc)), SubIdx)
.addFrameIndex(FI)
.addMemOperand(CreateSubRegMMO(SubIdx));
else
buildWithDefSubReg(ScalarOpc, SubIdx)
.addFrameIndex(FI)
.addMemOperand(CreateSubRegMMO(SubIdx));
}
}
// Store a register to a stack slot. Used in eliminating FrameIndex pseduo-ops.
void AIE2PSInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
MachineBasicBlock::iterator I,
Register SrcReg, bool IsKill, int FI,
const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI,
Register VReg,
MachineInstr::MIFlag Flags) const {
DebugLoc DL;
if (I != MBB.end())
DL = I->getDebugLoc();
// Provide a store memory operand for a register store, resolving it
// from other memory refs during scheduler dag generation
auto CreateMMO = [&MF = *MBB.getParent()](int FI) {
MachineFrameInfo &MFI = MF.getFrameInfo();
MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI);
MachineMemOperand *MMO =
MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore,
MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
return MMO;
};
RC = constrainRegClass(MBB.getParent()->getRegInfo(), RC, SrcReg);
unsigned Opcode;
LLVM_DEBUG(dbgs() << "Attempting to Store: " << SrcReg << " To " << FI
<< "\n");
auto bounceViaRegClass = [&](const TargetRegisterClass *BounceRC) {
MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
Register TmpReg = MRI.createVirtualRegister(BounceRC);
BuildMI(MBB, I, DL, get(AIE2PS::COPY), TmpReg)
.addReg(SrcReg, getKillRegState(IsKill));
return storeRegToStackSlot(MBB, I, TmpReg, /*IsKill*/ true, FI, BounceRC,
TRI, VReg, Flags);
};
if (regClassMatches(AIE2PS::eRRegClass, RC, SrcReg)) {
Opcode = AIE2PS::ST_R_SPILL;
} else if (regClassMatches(AIE2PS::eLRegClass, RC, SrcReg)) {
Opcode = AIE2PS::ST_L_SPILL;
} else if (regClassMatches(AIE2PS::eDRegClass, RC, SrcReg)) {
Opcode = AIE2PS::ST_D_SPILL;
} else if (regClassMatches(AIE2PS::eDSRegClass, RC, SrcReg)) {
Opcode = AIE2PS::ST_DS_SPILL;
} else if (regClassMatches(AIE2PS::VEC256RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_W_SPILL;
} else if (regClassMatches(AIE2PS::VEC512RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_X_SPILL;
} else if (regClassMatches(AIE2PS::VEC1024RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_Y_SPILL;
} else if (regClassMatches(AIE2PS::ACC512RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_BM_SPILL;
} else if (regClassMatches(AIE2PS::ACC1024RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_CM_SPILL;
} else if (regClassMatches(AIE2PS::ACC2048RegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_DM_SPILL;
} else if (regClassMatches(AIE2PS::FIFO512RegClass, RC, SrcReg)) {
return bounceViaRegClass(&AIE2PS::VEC512RegClass);
} else if (regClassMatches(AIE2PS::FIFO1024RegClass, RC, SrcReg)) {
return bounceViaRegClass(&AIE2PS::VEC1024RegClass);
} else if (regClassMatches(AIE2PS::ePSRFLdFRegClass, RC, SrcReg)) {
emitPSRFLSpillReload(*this, MBB, I, DL, SrcReg, IsKill, FI, RC, TRI,
/*IsStore=*/true);
return;
} else if (regClassMatches(AIE2PS::mEsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_E_SPILL;
} else if (regClassMatches(AIE2PS::mEEsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EE_SPILL;
} else if (regClassMatches(AIE2PS::mFsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_F_SPILL;
} else if (regClassMatches(AIE2PS::mFFsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FF_SPILL;
} else if (regClassMatches(AIE2PS::mGsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_G_SPILL;
} else if (regClassMatches(AIE2PS::mGGsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_GG_SPILL;
} else if (regClassMatches(AIE2PS::mEGsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EG_SPILL;
} else if (regClassMatches(AIE2PS::mEG2sRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EG2_SPILL;
} else if (regClassMatches(AIE2PS::mFEGsRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FEG_SPILL;
} else if (regClassMatches(AIE2PS::mFEG2sRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FEG2_SPILL;
} else if (regClassMatches(AIE2PS::mEWmRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EW_SPILL;
} else if (regClassMatches(AIE2PS::mEXmRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EX_SPILL;
} else if (regClassMatches(AIE2PS::mEYwRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_EY_SPILL;
} else if (regClassMatches(AIE2PS::mFEWmRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FEW_SPILL;
} else if (regClassMatches(AIE2PS::mFEXmRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FEX_SPILL;
} else if (regClassMatches(AIE2PS::mFEYwRegClass, RC, SrcReg)) {
Opcode = AIE2PS::VST_FEY_SPILL;
} else if (regClassMatches(AIE2PS::mSclStRegClass, RC, SrcReg)) {
// Anything that can be stored in a scalar register can use R_SPILL.
Opcode = AIE2PS::ST_R_SPILL;
} else if (regClassMatches(AIE2PS::eSRegClass, RC, SrcReg) ||
regClassMatches(AIE2PS::spill_eS_to_eRRegClass, RC, SrcReg)) {
// Can't spill these directly. Need to bounce through a GPR.
return bounceViaRegClass(&AIE2PS::eRRegClass);
} else {
LLVM_DEBUG(I->dump());
llvm_unreachable("Can't store this register to stack slot: is it virtual?");
}
// To store a stack slot we generate a store indirect via the stack
// pointer. The actual offset will be an immediate, but for right
// now stuff in a virtual "FrameIndex" argument to represent the
// offset that will be figured out later. The offset is generated
// by AIERegisterInfo::eliminateFrameIndex().
BuildMI(MBB, I, DL, get(Opcode))
.addReg(SrcReg, getKillRegState(IsKill))
.addFrameIndex(FI)
.addMemOperand(CreateMMO(FI));
}
// Load a register to a stack slot. Used in eliminating FrameIndex pseduo-ops.
void AIE2PSInstrInfo::loadRegFromStackSlot(
MachineBasicBlock &MBB, MachineBasicBlock::iterator I, Register DstReg,
int FI, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI,
Register VReg, MachineInstr::MIFlag Flags) const {
DebugLoc DL;
if (I != MBB.end())
DL = I->getDebugLoc();
unsigned Opcode;
// Provide a load memory operand for a register load, resolving it
// from other memory refs during scheduler dag generation
auto CreateMMO = [&MF = *MBB.getParent()](int FI) {
MachineFrameInfo &MFI = MF.getFrameInfo();
MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI);
MachineMemOperand *MMO =