LLVM 24.0.0git
SIInstrInfo.h
Go to the documentation of this file.
1//===- SIInstrInfo.h - SI Instruction Info Interface ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Interface definition for SIInstrInfo.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_SIINSTRINFO_H
15#define LLVM_LIB_TARGET_AMDGPU_SIINSTRINFO_H
16
17#include "AMDGPUMIRFormatter.h"
19#include "SIRegisterInfo.h"
21#include "llvm/ADT/SetVector.h"
25
26#define GET_INSTRINFO_HEADER
27#include "AMDGPUGenInstrInfo.inc"
28
29namespace llvm {
30
31class APInt;
32class GCNSubtarget;
33class MachineDominatorTree;
34class MachineRegisterInfo;
35class RegScavenger;
36class SIMachineFunctionInfo;
37class MCRegisterClass;
38using TargetRegisterClass = MCRegisterClass;
39class ScheduleHazardRecognizer;
40
41constexpr unsigned DefaultMemoryClusterDWordsLimit = 8;
42
43/// Mark the MMO of a uniform load if there are no potentially clobbering stores
44/// on any path from the start of an entry function to this load.
47
48/// Mark the MMO of a load as the last use.
51
52/// Mark the MMO of cooperative load/store atomics.
55
57 // Operands that need to replaced by waterfall
59 // Target physical registers replacing the MOs
61};
62/// Mark the MMO of accesses to memory locations that are
63/// never written to by other threads.
66
67/// Utility to store machine instructions worklist.
69 SIInstrWorklist() = default;
70
71 void insert(MachineInstr *MI);
72
73 MachineInstr *top() const { return InstrList[Front]; }
74
75 void erase_top() {
76 InSet.erase(InstrList[Front]);
77 ++Front;
78 }
79
80 bool empty() const { return Front == InstrList.size(); }
81
82 void clear() {
83 InstrList.clear();
84 Front = 0;
85 InSet.clear();
86 DeferredList.clear();
87 }
88
90
91 SetVector<MachineInstr *> &getDeferredList() { return DeferredList; }
92
93private:
94 /// InstrList contains the MachineInstrs.
97 unsigned Front = 0;
98 /// Deferred instructions are specific MachineInstr
99 /// that will be added by insert method.
100 SetVector<MachineInstr *> DeferredList;
101};
102
103// In namespace llvm so ADL finds it when SIInstrFlags predicates are
104// instantiated with MachineInstr (MachineInstr is in namespace llvm).
106 return MI.getDesc().TSFlags;
107}
108
109class SIInstrInfo final : public AMDGPUGenInstrInfo {
110 struct ThreeAddressUpdates;
111
112private:
113 const SIRegisterInfo RI;
114 const GCNSubtarget &ST;
115 TargetSchedModel SchedModel;
116 mutable std::unique_ptr<AMDGPUMIRFormatter> Formatter;
117
118 // The inverse predicate should have the negative value.
119 enum BranchPredicate {
120 INVALID_BR = 0,
121 SCC_TRUE = 1,
122 SCC_FALSE = -1,
123 VCCNZ = 2,
124 VCCZ = -2,
125 EXECNZ = -3,
126 EXECZ = 3
127 };
128
129 using SetVectorType = SmallSetVector<MachineInstr *, 32>;
130
131 static unsigned getBranchOpcode(BranchPredicate Cond);
132 static BranchPredicate getBranchPredicate(unsigned Opcode);
133
134public:
137 const MachineOperand &SuperReg,
138 const TargetRegisterClass *SuperRC,
139 unsigned SubIdx,
140 const TargetRegisterClass *SubRC) const;
143 const MachineOperand &SuperReg, const TargetRegisterClass *SuperRC,
144 unsigned SubIdx, const TargetRegisterClass *SubRC) const;
145
146private:
147 bool optimizeSCC(MachineInstr *SCCValid, MachineInstr *SCCRedefine,
148 bool NeedInversion) const;
149
150 bool invertSCCUse(MachineInstr *SCCDef) const;
151
152 void swapOperands(MachineInstr &Inst) const;
153
154 std::pair<bool, MachineBasicBlock *>
155 moveScalarAddSub(SIInstrWorklist &Worklist, MachineInstr &Inst,
156 MachineDominatorTree *MDT = nullptr) const;
157
158 void lowerSelect(SIInstrWorklist &Worklist, MachineInstr &Inst,
159 MachineDominatorTree *MDT = nullptr) const;
160
161 void lowerScalarAbs(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
162
163 void lowerScalarAbsDiff(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
164
165 void lowerScalarXnor(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
166
167 void splitScalarNotBinop(SIInstrWorklist &Worklist, MachineInstr &Inst,
168 unsigned Opcode) const;
169
170 void splitScalarBinOpN2(SIInstrWorklist &Worklist, MachineInstr &Inst,
171 unsigned Opcode) const;
172
173 void splitScalar64BitUnaryOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
174 unsigned Opcode, bool Swap = false) const;
175
176 void splitScalar64BitBinaryOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
177 unsigned Opcode,
178 MachineDominatorTree *MDT = nullptr) const;
179
180 void splitScalarSMulU64(SIInstrWorklist &Worklist, MachineInstr &Inst,
181 MachineDominatorTree *MDT) const;
182
183 void splitScalarSMulPseudo(SIInstrWorklist &Worklist, MachineInstr &Inst,
184 MachineDominatorTree *MDT) const;
185
186 void splitScalar64BitXnor(SIInstrWorklist &Worklist, MachineInstr &Inst,
187 MachineDominatorTree *MDT = nullptr) const;
188
189 void splitScalar64BitBCNT(SIInstrWorklist &Worklist,
190 MachineInstr &Inst) const;
191 void splitScalar64BitBFE(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
192 void splitScalar64BitCountOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
193 unsigned Opcode,
194 MachineDominatorTree *MDT = nullptr) const;
195 void movePackToVALU(SIInstrWorklist &Worklist, MachineRegisterInfo &MRI,
196 MachineInstr &Inst) const;
197
198 void addUsersToMoveToVALUWorklist(Register Reg, MachineRegisterInfo &MRI,
199 SIInstrWorklist &Worklist) const;
200
201 void addSCCDefUsersToVALUWorklist(const MachineOperand &Op,
202 MachineInstr &SCCDefInst,
203 SIInstrWorklist &Worklist,
204 Register NewCond = Register()) const;
205 void addSCCDefsToVALUWorklist(MachineInstr *SCCUseInst,
206 SIInstrWorklist &Worklist) const;
207
208 const TargetRegisterClass *
209 getDestEquivalentVGPRClass(const MachineInstr &Inst) const;
210
211 bool checkInstOffsetsDoNotOverlap(const MachineInstr &MIa,
212 const MachineInstr &MIb) const;
213
214 Register findUsedSGPR(const MachineInstr &MI, int OpIndices[3]) const;
215
216 bool verifyCopy(const MachineInstr &MI, const MachineRegisterInfo &MRI,
217 StringRef &ErrInfo) const;
218
219 bool resultDependsOnExec(const MachineInstr &MI) const;
220
221 MachineInstr *convertToThreeAddressImpl(MachineInstr &MI,
222 ThreeAddressUpdates &Updates) const;
223
224protected:
225 /// If the specific machine instruction is a instruction that moves/copies
226 /// value from one register to another register return destination and source
227 /// registers as machine operands.
228 std::optional<DestSourcePair>
229 isCopyInstrImpl(const MachineInstr &MI) const override;
230
232 AMDGPU::OpName Src0OpName, MachineOperand &Src1,
233 AMDGPU::OpName Src1OpName) const;
234 bool isLegalToSwap(const MachineInstr &MI, unsigned fromIdx,
235 unsigned toIdx) const;
236 bool isNonCommutableDPP(const MachineInstr &MI) const;
238 unsigned OpIdx0,
239 unsigned OpIdx1) const override;
240
241public:
243 MO_MASK = 0xf,
244
246 // MO_GOTPCREL -> symbol@GOTPCREL -> R_AMDGPU_GOTPCREL.
248 // MO_GOTPCREL32_LO -> symbol@gotpcrel32@lo -> R_AMDGPU_GOTPCREL32_LO.
251 // MO_GOTPCREL32_HI -> symbol@gotpcrel32@hi -> R_AMDGPU_GOTPCREL32_HI.
253 // MO_GOTPCREL64 -> symbol@GOTPCREL -> R_AMDGPU_GOTPCREL.
255 // MO_REL32_LO -> symbol@rel32@lo -> R_AMDGPU_REL32_LO.
258 // MO_REL32_HI -> symbol@rel32@hi -> R_AMDGPU_REL32_HI.
261
263
267 };
268
269 explicit SIInstrInfo(const GCNSubtarget &ST);
270
272 return RI;
273 }
274
275 // FIXME: This is inaccurate and needs to account for use context. Normal asm
276 // constraints should use 64-bit pointers.
278 InlineAsm::ConstraintCode C) const override {
279 return &AMDGPU::VGPR_32RegClass;
280 }
281
282 const GCNSubtarget &getSubtarget() const {
283 return ST;
284 }
285
286 bool isReMaterializableImpl(const MachineInstr &MI) const override;
287
288 bool isIgnorableUse(const MachineInstr &MI, unsigned OpIdx) const override;
289
290 bool isSafeToSink(MachineInstr &MI, MachineBasicBlock *SuccToSinkTo,
291 MachineCycleInfo *CI) const override;
292
293 bool areLoadsFromSameBasePtr(SDNode *Load0, SDNode *Load1, int64_t &Offset0,
294 int64_t &Offset1) const override;
295
296 bool isGlobalMemoryObject(const MachineInstr *MI) const override;
297
299 const MachineInstr &LdSt,
301 bool &OffsetIsScalable, LocationSize &Width,
302 const TargetRegisterInfo *TRI) const final;
303
305 int64_t Offset1, bool OffsetIsScalable1,
307 int64_t Offset2, bool OffsetIsScalable2,
308 unsigned ClusterSize,
309 unsigned NumBytes) const override;
310
311 bool shouldScheduleLoadsNear(SDNode *Load0, SDNode *Load1, int64_t Offset0,
312 int64_t Offset1, unsigned NumLoads) const override;
313
315 const DebugLoc &DL, Register DestReg, Register SrcReg,
316 bool KillSrc, bool RenamableDest = false,
317 bool RenamableSrc = false) const override;
318
319private:
320 void storeRegToStackSlotImpl(MachineBasicBlock &MBB,
322 bool isKill, int FrameIndex,
323 const TargetRegisterClass *RC, Register VReg,
324 MachineInstr::MIFlag Flags, bool NeedsCFI) const;
325
326public:
329 bool isKill, int FrameIndex,
330 const TargetRegisterClass *RC) const;
331
333 int64_t &ImmVal) const override;
334
335 std::optional<int64_t>
337 const MachineOperand &Op,
338 MachineInstr **DefMI = nullptr) const;
339 std::optional<int64_t>
341 MachineInstr **DefMI = nullptr) const;
342
344 const TargetRegisterClass *RC,
345 unsigned Size,
346 const SIMachineFunctionInfo &MFI,
347 bool NeedsCFI) const;
348 unsigned
350 unsigned Size,
351 const SIMachineFunctionInfo &MFI) const;
352
355 bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
356 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
357
360 int FrameIndex, const TargetRegisterClass *RC, Register VReg,
361 unsigned SubReg = 0,
362 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
363
364 bool expandPostRAPseudo(MachineInstr &MI) const override;
365
366 void
368 Register DestReg, unsigned SubIdx, const MachineInstr &Orig,
369 LaneBitmask UsedLanes = LaneBitmask::getAll()) const override;
370
371 // Splits a V_MOV_B64_DPP_PSEUDO opcode into a pair of v_mov_b32_dpp
372 // instructions. Returns a pair of generated instructions.
373 // Can split either post-RA with physical registers or pre-RA with
374 // virtual registers. In latter case IR needs to be in SSA form and
375 // and a REG_SEQUENCE is produced to define original register.
376 std::pair<MachineInstr*, MachineInstr*>
378
379 // Returns an opcode that can be used to move a value to a \p DstRC
380 // register. If there is no hardware instruction that can store to \p
381 // DstRC, then AMDGPU::COPY is returned.
382 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
383
384 const MCInstrDesc &getIndirectRegWriteMovRelPseudo(unsigned VecSize,
385 unsigned EltSize,
386 bool IsSGPR) const;
387
388 const MCInstrDesc &getIndirectGPRIDXPseudo(unsigned VecSize,
389 bool IsIndirectSrc) const;
391 int commuteOpcode(unsigned Opc) const;
392
394 inline int commuteOpcode(const MachineInstr &MI) const {
395 return commuteOpcode(MI.getOpcode());
396 }
397
398 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx0,
399 unsigned &SrcOpIdx1) const override;
400
401 bool findCommutedOpIndices(const MCInstrDesc &Desc, unsigned &SrcOpIdx0,
402 unsigned &SrcOpIdx1) const;
403
404 bool isBranchOffsetInRange(unsigned BranchOpc,
405 int64_t BrOffset) const override;
406
407 MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override;
408
409 /// Return whether the block terminate with divergent branch.
410 /// Note this only work before lowering the pseudo control flow instructions.
411 bool hasDivergentBranch(const MachineBasicBlock *MBB) const;
412
414 MachineBasicBlock &NewDestBB,
415 MachineBasicBlock &RestoreBB, const DebugLoc &DL,
416 int64_t BrOffset, RegScavenger *RS) const override;
417
421 MachineBasicBlock *&FBB,
423 bool AllowModify) const;
424
426 MachineBasicBlock *&FBB,
428 bool AllowModify = false) const override;
429
431 int *BytesRemoved = nullptr) const override;
432
435 const DebugLoc &DL,
436 int *BytesAdded = nullptr) const override;
437
439 SmallVectorImpl<MachineOperand> &Cond) const override;
440
441 std::unique_ptr<PipelinerLoopInfo>
442 analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override;
443
446 Register TrueReg, Register FalseReg, int &CondCycles,
447 int &TrueCycles, int &FalseCycles) const override;
448
452 Register TrueReg, Register FalseReg) const override;
453
454 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
455 Register &SrcReg2, int64_t &CmpMask,
456 int64_t &CmpValue) const override;
457
458 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
459 Register SrcReg2, int64_t CmpMask, int64_t CmpValue,
460 const MachineRegisterInfo *MRI) const override;
461
462 bool
464 const MachineInstr &MIb) const override;
465
466 static bool isFoldableCopy(const MachineInstr &MI);
467 static unsigned getFoldableCopySrcIdx(const MachineInstr &MI);
468
469 void removeModOperands(MachineInstr &MI) const;
470
472 const MCInstrDesc &NewDesc) const;
473
474 /// Return the extracted immediate value in a subregister use from a constant
475 /// materialized in a super register.
476 ///
477 /// e.g. %imm = S_MOV_B64 K[0:63]
478 /// USE %imm.sub1
479 /// This will return K[32:63]
480 static std::optional<int64_t> extractSubregFromImm(int64_t ImmVal,
481 unsigned SubRegIndex);
482
484 MachineRegisterInfo *MRI) const final;
485
486 unsigned getMachineCSELookAheadLimit() const override { return 500; }
487
489 LiveIntervals *LIS) const override;
490
492 const MachineBasicBlock *MBB,
493 const MachineFunction &MF) const override;
494
495 static bool isSALU(const MachineInstr &MI) {
496 return SIInstrFlags::isSALU(MI);
497 }
498
499 bool isSALU(uint32_t Opcode) const {
500 return SIInstrFlags::isSALU(get(Opcode));
501 }
502
503 static bool isVALU(const MachineInstr &MI, bool AllowLDSDMA) {
504 if (!AllowLDSDMA && isLDSDMA(MI))
505 return false;
506
507 return SIInstrFlags::isVALU(MI);
508 }
509
510 /// LDSDMA instructions act as both VALU and memory instructions, thus
511 /// we also tag them as VALU. However, in many places, we do not actually want
512 /// to include LDSDMA instructions in this query. By setting \p AllowLDSDMA to
513 /// false, this will return false for LDSDMA instructions.
514 bool isVALU(uint32_t Opcode, bool AllowLDSDMA) const {
515 if (!AllowLDSDMA && isLDSDMA(Opcode))
516 return false;
517
518 return SIInstrFlags::isVALU(get(Opcode));
519 }
520
521 static bool isImage(const MachineInstr &MI) {
523 }
524
525 bool isImage(uint32_t Opcode) const {
526 return SIInstrFlags::isImage(get(Opcode));
527 }
528
529 static bool isVMEM(const MachineInstr &MI) {
530 return SIInstrFlags::isVMEM(MI);
531 }
532
533 bool isVMEM(uint32_t Opcode) const {
534 return SIInstrFlags::isVMEM(get(Opcode));
535 }
536
537 /// True if MI implicitly drains XCNT.
538 static bool isXcntDrain(const MachineInstr &MI);
539
540 static bool isSOP1(const MachineInstr &MI) {
541 return SIInstrFlags::isSOP1(MI);
542 }
543
544 bool isSOP1(uint32_t Opcode) const {
545 return SIInstrFlags::isSOP1(get(Opcode));
546 }
547
548 static bool isSOP2(const MachineInstr &MI) {
549 return SIInstrFlags::isSOP2(MI);
550 }
551
552 bool isSOP2(uint32_t Opcode) const {
553 return SIInstrFlags::isSOP2(get(Opcode));
554 }
555
556 static bool isSOPC(const MachineInstr &MI) {
557 return SIInstrFlags::isSOPC(MI);
558 }
559
560 bool isSOPC(uint32_t Opcode) const {
561 return SIInstrFlags::isSOPC(get(Opcode));
562 }
563
564 static bool isSOPK(const MachineInstr &MI) {
565 return SIInstrFlags::isSOPK(MI);
566 }
567
568 bool isSOPK(uint32_t Opcode) const {
569 return SIInstrFlags::isSOPK(get(Opcode));
570 }
571
572 static bool isSOPP(const MachineInstr &MI) {
573 return SIInstrFlags::isSOPP(MI);
574 }
575
576 bool isSOPP(uint32_t Opcode) const {
577 return SIInstrFlags::isSOPP(get(Opcode));
578 }
579
580 static bool isPacked(const MachineInstr &MI) {
582 }
583
584 bool isPacked(uint32_t Opcode) const {
585 return SIInstrFlags::isPacked(get(Opcode));
586 }
587
588 static bool isVOP1(const MachineInstr &MI) {
589 return SIInstrFlags::isVOP1(MI);
590 }
591
592 bool isVOP1(uint32_t Opcode) const {
593 return SIInstrFlags::isVOP1(get(Opcode));
594 }
595
596 static bool isVOP2(const MachineInstr &MI) {
597 return SIInstrFlags::isVOP2(MI);
598 }
599
600 bool isVOP2(uint32_t Opcode) const {
601 return SIInstrFlags::isVOP2(get(Opcode));
602 }
603
604 static bool isVOP3(const MCInstrDesc &Desc) {
606 }
607
608 static bool isVOP3(const MachineInstr &MI) { return isVOP3(MI.getDesc()); }
609
610 bool isVOP3(uint32_t Opcode) const { return isVOP3(get(Opcode)); }
611
612 static bool isSDWA(const MachineInstr &MI) {
613 return SIInstrFlags::isSDWA(MI);
614 }
615
616 bool isSDWA(uint32_t Opcode) const {
617 return SIInstrFlags::isSDWA(get(Opcode));
618 }
619
620 static bool isVOPC(const MachineInstr &MI) {
621 return SIInstrFlags::isVOPC(MI);
622 }
623
624 bool isVOPC(uint32_t Opcode) const {
625 return SIInstrFlags::isVOPC(get(Opcode));
626 }
627
628 static bool isMUBUF(const MachineInstr &MI) {
630 }
631
632 bool isMUBUF(uint32_t Opcode) const {
633 return SIInstrFlags::isMUBUF(get(Opcode));
634 }
635
636 static bool isMTBUF(const MachineInstr &MI) {
638 }
639
640 bool isMTBUF(uint32_t Opcode) const {
641 return SIInstrFlags::isMTBUF(get(Opcode));
642 }
643
644 static bool isBUF(const MachineInstr &MI) {
645 return isMUBUF(MI) || isMTBUF(MI);
646 }
647
648 static bool isSMRD(const MachineInstr &MI) {
649 return SIInstrFlags::isSMRD(MI);
650 }
651
652 bool isSMRD(uint32_t Opcode) const {
653 return SIInstrFlags::isSMRD(get(Opcode));
654 }
655
656 bool isBufferSMRD(const MachineInstr &MI) const;
657
658 static bool isDS(const MachineInstr &MI) { return SIInstrFlags::isDS(MI); }
659
660 bool isDS(uint32_t Opcode) const { return SIInstrFlags::isDS(get(Opcode)); }
661
662 static bool isLDSDMA(const MachineInstr &MI) {
663 return (SIInstrFlags::isVALU(MI) && (isMUBUF(MI) || isFLAT(MI))) ||
665 }
666
667 bool isLDSDMA(uint32_t Opcode) const {
668 return (SIInstrFlags::isVALU(get(Opcode)) &&
669 (isMUBUF(Opcode) || isFLAT(Opcode))) ||
671 }
672
673 static bool isGWS(const MachineInstr &MI) { return SIInstrFlags::isGWS(MI); }
674
675 bool isGWS(uint32_t Opcode) const { return SIInstrFlags::isGWS(get(Opcode)); }
676
677 bool isAlwaysGDS(uint32_t Opcode) const;
678
679 static bool isMIMG(const MachineInstr &MI) {
680 return SIInstrFlags::isMIMG(MI);
681 }
682
683 bool isMIMG(uint32_t Opcode) const {
684 return SIInstrFlags::isMIMG(get(Opcode));
685 }
686
687 static bool isVIMAGE(const MachineInstr &MI) {
689 }
690
691 bool isVIMAGE(uint32_t Opcode) const {
692 return SIInstrFlags::isVIMAGE(get(Opcode));
693 }
694
695 static bool isVSAMPLE(const MachineInstr &MI) {
697 }
698
699 bool isVSAMPLE(uint32_t Opcode) const {
700 return SIInstrFlags::isVSAMPLE(get(Opcode));
701 }
702
703 static bool isGather4(const MachineInstr &MI) {
705 }
706
707 bool isGather4(uint32_t Opcode) const {
708 return SIInstrFlags::isGather4(get(Opcode));
709 }
710
711 static bool isFLAT(const MachineInstr &MI) {
712 return SIInstrFlags::isFLAT(MI);
713 }
714
715 // Is a FLAT encoded instruction which accesses a specific segment,
716 // i.e. global_* or scratch_*.
720
721 bool isSegmentSpecificFLAT(uint32_t Opcode) const {
723 }
724
725 static bool isFLATGlobal(const MachineInstr &MI) {
727 }
728
729 bool isFLATGlobal(uint32_t Opcode) const {
730 return SIInstrFlags::isFlatGlobal(get(Opcode));
731 }
732
733 static bool isFLATScratch(const MachineInstr &MI) {
735 }
736
737 bool isFLATScratch(uint32_t Opcode) const {
738 return SIInstrFlags::isFlatScratch(get(Opcode));
739 }
740
741 // Any FLAT encoded instruction, including global_* and scratch_*.
742 bool isFLAT(uint32_t Opcode) const {
743 return SIInstrFlags::isFLAT(get(Opcode));
744 }
745
746 /// \returns true for SCRATCH_ instructions, or FLAT/BUF instructions unless
747 /// the MMOs do not include scratch.
748 /// Conservatively correct; will return true if \p MI cannot be proven
749 /// to not hit scratch.
750 bool mayAccessScratch(const MachineInstr &MI) const;
751
752 /// \returns true for FLAT instructions that can access VMEM.
753 bool mayAccessVMEMThroughFlat(const MachineInstr &MI) const;
754
755 /// \returns true for FLAT instructions that can access LDS.
756 bool mayAccessLDSThroughFlat(const MachineInstr &MI, bool TgSplit) const;
757
758 static bool isBlockLoadStore(uint32_t Opcode) {
759 switch (Opcode) {
760 case AMDGPU::SI_BLOCK_SPILL_V1024_SAVE:
761 case AMDGPU::SI_BLOCK_SPILL_V1024_CFI_SAVE:
762 case AMDGPU::SI_BLOCK_SPILL_V1024_RESTORE:
763 case AMDGPU::SCRATCH_STORE_BLOCK_SADDR:
764 case AMDGPU::SCRATCH_LOAD_BLOCK_SADDR:
765 case AMDGPU::SCRATCH_STORE_BLOCK_SVS:
766 case AMDGPU::SCRATCH_LOAD_BLOCK_SVS:
767 return true;
768 default:
769 return false;
770 }
771 }
772
774 switch (MI.getOpcode()) {
775 case AMDGPU::S_ABSDIFF_I32:
776 case AMDGPU::S_ABS_I32:
777 case AMDGPU::S_AND_B32:
778 case AMDGPU::S_AND_B64:
779 case AMDGPU::S_ANDN2_B32:
780 case AMDGPU::S_ANDN2_B64:
781 case AMDGPU::S_ASHR_I32:
782 case AMDGPU::S_ASHR_I64:
783 case AMDGPU::S_BCNT0_I32_B32:
784 case AMDGPU::S_BCNT0_I32_B64:
785 case AMDGPU::S_BCNT1_I32_B32:
786 case AMDGPU::S_BCNT1_I32_B64:
787 case AMDGPU::S_BFE_I32:
788 case AMDGPU::S_BFE_I64:
789 case AMDGPU::S_BFE_U32:
790 case AMDGPU::S_BFE_U64:
791 case AMDGPU::S_LSHL_B32:
792 case AMDGPU::S_LSHL_B64:
793 case AMDGPU::S_LSHR_B32:
794 case AMDGPU::S_LSHR_B64:
795 case AMDGPU::S_NAND_B32:
796 case AMDGPU::S_NAND_B64:
797 case AMDGPU::S_NOR_B32:
798 case AMDGPU::S_NOR_B64:
799 case AMDGPU::S_NOT_B32:
800 case AMDGPU::S_NOT_B64:
801 case AMDGPU::S_OR_B32:
802 case AMDGPU::S_OR_B64:
803 case AMDGPU::S_ORN2_B32:
804 case AMDGPU::S_ORN2_B64:
805 case AMDGPU::S_QUADMASK_B32:
806 case AMDGPU::S_QUADMASK_B64:
807 case AMDGPU::S_WQM_B32:
808 case AMDGPU::S_WQM_B64:
809 case AMDGPU::S_XNOR_B32:
810 case AMDGPU::S_XNOR_B64:
811 case AMDGPU::S_XOR_B32:
812 case AMDGPU::S_XOR_B64:
813 return true;
814 default:
815 return false;
816 }
817 }
818
819 static bool isEXP(const MachineInstr &MI) { return SIInstrFlags::isEXP(MI); }
820
822 if (!isEXP(MI))
823 return false;
824 unsigned Target = MI.getOperand(0).getImm();
827 }
828
829 bool isEXP(uint32_t Opcode) const { return SIInstrFlags::isEXP(get(Opcode)); }
830
831 static bool isAtomicNoRet(const MachineInstr &MI) {
833 }
834
835 bool isAtomicNoRet(uint32_t Opcode) const {
836 return SIInstrFlags::isAtomicNoRet(get(Opcode));
837 }
838
839 static bool isAtomicRet(const MachineInstr &MI) {
841 }
842
843 bool isAtomicRet(uint32_t Opcode) const {
844 return SIInstrFlags::isAtomicRet(get(Opcode));
845 }
846
847 static bool isAtomic(const MachineInstr &MI) {
849 }
850
851 bool isAtomic(uint32_t Opcode) const {
852 return SIInstrFlags::isAtomic(get(Opcode));
853 }
854
856 unsigned Opc = MI.getOpcode();
857 // Exclude instructions that read FROM LDS (not write to it)
858 return isLDSDMA(MI) && Opc != AMDGPU::BUFFER_STORE_LDS_DWORD &&
859 Opc != AMDGPU::TENSOR_STORE_FROM_LDS_d2 &&
860 Opc != AMDGPU::TENSOR_STORE_FROM_LDS_d4;
861 }
862
863 static bool isSBarrierSCCWrite(unsigned Opcode) {
864 return Opcode == AMDGPU::S_BARRIER_LEAVE ||
865 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM ||
866 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_M0;
867 }
868
869 static bool isCBranchVCCZRead(const MachineInstr &MI) {
870 unsigned Opc = MI.getOpcode();
871 return (Opc == AMDGPU::S_CBRANCH_VCCNZ || Opc == AMDGPU::S_CBRANCH_VCCZ) &&
872 !MI.getOperand(1).isUndef();
873 }
874
875 static bool isWQM(const MachineInstr &MI) { return SIInstrFlags::isWQM(MI); }
876
877 bool isWQM(uint32_t Opcode) const { return SIInstrFlags::isWQM(get(Opcode)); }
878
879 static bool isDisableWQM(const MachineInstr &MI) {
881 }
882
883 bool isDisableWQM(uint32_t Opcode) const {
884 return SIInstrFlags::isDisableWQM(get(Opcode));
885 }
886
887 // SI_SPILL_S32_TO_VGPR and SI_RESTORE_S32_FROM_VGPR form a special case of
888 // SGPRs spilling to VGPRs which are SGPR spills but from VALU instructions
889 // therefore we need an explicit check for them since just checking if the
890 // Spill bit is set and what instruction type it came from misclassifies
891 // them.
892 static bool isVGPRSpill(const MachineInstr &MI) {
893 return MI.getOpcode() != AMDGPU::SI_SPILL_S32_TO_VGPR &&
894 MI.getOpcode() != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
895 (isSpill(MI) && isVALU(MI, /*AllowLDSDMA=*/false));
896 }
897
898 bool isVGPRSpill(uint32_t Opcode) const {
899 return Opcode != AMDGPU::SI_SPILL_S32_TO_VGPR &&
900 Opcode != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
901 (isSpill(Opcode) && isVALU(Opcode, /*AllowLDSDMA=*/false));
902 }
903
904 static bool isSGPRSpill(const MachineInstr &MI) {
905 return MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR ||
906 MI.getOpcode() == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
907 (isSpill(MI) && isSALU(MI));
908 }
909
910 bool isSGPRSpill(uint32_t Opcode) const {
911 return Opcode == AMDGPU::SI_SPILL_S32_TO_VGPR ||
912 Opcode == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
913 (isSpill(Opcode) && isSALU(Opcode));
914 }
915
916 bool isSpill(uint32_t Opcode) const {
917 return SIInstrFlags::isSpill(get(Opcode));
918 }
919
920 static bool isSpill(const MCInstrDesc &Desc) {
922 }
923
924 static bool isSpill(const MachineInstr &MI) { return isSpill(MI.getDesc()); }
925
926 static bool isWWMRegSpillOpcode(uint32_t Opcode) {
927 return Opcode == AMDGPU::SI_SPILL_WWM_V32_SAVE ||
928 Opcode == AMDGPU::SI_SPILL_WWM_AV32_SAVE ||
929 Opcode == AMDGPU::SI_SPILL_WWM_V32_RESTORE ||
930 Opcode == AMDGPU::SI_SPILL_WWM_AV32_RESTORE;
931 }
932
933 static bool isChainCallOpcode(uint64_t Opcode) {
934 return Opcode == AMDGPU::SI_CS_CHAIN_TC_W32 ||
935 Opcode == AMDGPU::SI_CS_CHAIN_TC_W64;
936 }
937
938 static bool isDPP(const MachineInstr &MI) { return SIInstrFlags::isDPP(MI); }
939
940 bool isDPP(uint32_t Opcode) const { return SIInstrFlags::isDPP(get(Opcode)); }
941
942 // Some opcodes use Src1 for DPP instead of Src0, because the sequencer
943 // transforms them and reverse the order of their operands at runtime.
944 //
945 // Documentation is incomplete on which instructions are effected, so
946 // the implementation is derived from experimentation.
947 //
948 // Listed as target-independent pseudos; the per-subtarget MC opcodes
949 // (V_SUBREV_NC_U32_e32_gfx11 and friends) are all reached through these.
950 // Defined out of line because GCNSubtarget is incomplete here.
951 static bool isSrc1DPPRevOpcode(const GCNSubtarget &ST, uint32_t Opcode);
952
953 static bool isTRANS(const MachineInstr &MI) {
955 }
956
957 bool isTRANS(uint32_t Opcode) const {
958 return SIInstrFlags::isTRANS(get(Opcode));
959 }
960
961 static bool isVOP3P(const MachineInstr &MI) {
963 }
964
965 bool isVOP3P(uint32_t Opcode) const {
966 return SIInstrFlags::isVOP3P(get(Opcode));
967 }
968
969 bool isVOP3PMix(const MachineInstr &MI) const {
970 return isVOP3PMix(MI.getOpcode());
971 }
972
973 bool isVOP3PMix(uint16_t Opcode) const {
974 switch (Opcode) {
975 case AMDGPU::V_FMA_MIXHI_F16:
976 case AMDGPU::V_FMA_MIXLO_F16:
977 case AMDGPU::V_FMA_MIX_F32:
978 case AMDGPU::V_MAD_MIXHI_F16:
979 case AMDGPU::V_MAD_MIXLO_F16:
980 case AMDGPU::V_MAD_MIX_F32:
981 return true;
982 default:
983 return false;
984 }
985 }
986
987 static bool isVINTRP(const MachineInstr &MI) {
989 }
990
991 bool isVINTRP(uint32_t Opcode) const {
992 return SIInstrFlags::isVINTRP(get(Opcode));
993 }
994
995 static bool isMAI(const MCInstrDesc &Desc) {
997 }
998
999 static bool isMAI(const MachineInstr &MI) { return isMAI(MI.getDesc()); }
1000
1001 bool isMAI(uint32_t Opcode) const { return isMAI(get(Opcode)); }
1002
1003 static bool isMFMA(const MachineInstr &MI) {
1004 return isMAI(MI) && MI.getOpcode() != AMDGPU::V_ACCVGPR_WRITE_B32_e64 &&
1005 MI.getOpcode() != AMDGPU::V_ACCVGPR_READ_B32_e64;
1006 }
1007
1008 bool isMFMA(uint32_t Opcode) const {
1009 return isMAI(Opcode) && Opcode != AMDGPU::V_ACCVGPR_WRITE_B32_e64 &&
1010 Opcode != AMDGPU::V_ACCVGPR_READ_B32_e64;
1011 }
1012
1013 static bool isDOT(const MachineInstr &MI) { return SIInstrFlags::isDOT(MI); }
1014
1015 static bool isWMMA(const MachineInstr &MI) {
1016 return SIInstrFlags::isWMMA(MI);
1017 }
1018
1019 bool isWMMA(uint32_t Opcode) const {
1020 return SIInstrFlags::isWMMA(get(Opcode));
1021 }
1022
1023 static bool isMFMAorWMMA(const MachineInstr &MI) {
1024 return isMFMA(MI) || isWMMA(MI) || isSWMMAC(MI);
1025 }
1026
1027 bool isMFMAorWMMA(uint32_t Opcode) const {
1028 return isMFMA(Opcode) || isWMMA(Opcode) || isSWMMAC(Opcode);
1029 }
1030
1031 static bool isSWMMAC(const MachineInstr &MI) {
1032 return SIInstrFlags::isSWMMAC(MI);
1033 }
1034
1035 bool isSWMMAC(uint32_t Opcode) const {
1036 return SIInstrFlags::isSWMMAC(get(Opcode));
1037 }
1038
1039 bool isDOT(uint32_t Opcode) const { return SIInstrFlags::isDOT(get(Opcode)); }
1040
1041 bool isXDLWMMA(const MachineInstr &MI) const;
1042
1043 bool isXDL(const MachineInstr &MI) const;
1044
1045 static bool isDGEMM(unsigned Opcode) { return AMDGPU::getMAIIsDGEMM(Opcode); }
1046
1047 static bool isLDSDIR(const MachineInstr &MI) {
1048 return SIInstrFlags::isLDSDIR(MI);
1049 }
1050
1051 bool isLDSDIR(uint32_t Opcode) const {
1052 return SIInstrFlags::isLDSDIR(get(Opcode));
1053 }
1054
1055 static bool isVINTERP(const MachineInstr &MI) {
1057 }
1058
1059 bool isVINTERP(uint32_t Opcode) const {
1060 return SIInstrFlags::isVINTERP(get(Opcode));
1061 }
1062
1063 static bool isScalarUnit(const MachineInstr &MI) {
1065 }
1066
1067 static bool usesVM_CNT(const MachineInstr &MI) {
1069 }
1070
1071 static bool usesLGKM_CNT(const MachineInstr &MI) {
1073 }
1074
1075 static bool usesASYNC_CNT(const MachineInstr &MI) {
1077 }
1078
1079 bool usesASYNC_CNT(uint32_t Opcode) const {
1080 return SIInstrFlags::usesASYNC_CNT(get(Opcode));
1081 }
1082
1083 static bool usesTENSOR_CNT(const MachineInstr &MI) {
1085 }
1086
1087 bool usesTENSOR_CNT(uint32_t Opcode) const {
1088 return SIInstrFlags::usesTENSOR_CNT(get(Opcode));
1089 }
1090
1091 // Most sopk treat the immediate as a signed 16-bit, however some
1092 // use it as unsigned.
1093 static bool sopkIsZext(unsigned Opcode) {
1094 return Opcode == AMDGPU::S_CMPK_EQ_U32 || Opcode == AMDGPU::S_CMPK_LG_U32 ||
1095 Opcode == AMDGPU::S_CMPK_GT_U32 || Opcode == AMDGPU::S_CMPK_GE_U32 ||
1096 Opcode == AMDGPU::S_CMPK_LT_U32 || Opcode == AMDGPU::S_CMPK_LE_U32 ||
1097 Opcode == AMDGPU::S_GETREG_B32 ||
1098 Opcode == AMDGPU::S_GETREG_B32_const;
1099 }
1100
1101 /// \returns true if this is an s_store_dword* instruction. This is more
1102 /// specific than isSMEM && mayStore.
1103 static bool isScalarStore(const MachineInstr &MI) {
1105 }
1106
1107 bool isScalarStore(uint32_t Opcode) const {
1108 return SIInstrFlags::isScalarStore(get(Opcode));
1109 }
1110
1111 static bool isFixedSize(const MachineInstr &MI) {
1113 }
1114
1115 bool isFixedSize(uint32_t Opcode) const {
1116 return SIInstrFlags::isFixedSize(get(Opcode));
1117 }
1118
1119 static bool hasFPClamp(const MachineInstr &MI) {
1121 }
1122
1123 bool hasFPClamp(uint32_t Opcode) const {
1124 return SIInstrFlags::hasFPClamp(get(Opcode));
1125 }
1126
1127 static bool hasIntClamp(const MachineInstr &MI) {
1129 }
1130
1131 static bool hasSameClamp(const MachineInstr &A, const MachineInstr &B) {
1132 const MCInstrDesc &DA = A.getDesc(), &DB = B.getDesc();
1137 }
1138
1139 static bool usesFPDPRounding(const MachineInstr &MI) {
1141 }
1142
1143 bool usesFPDPRounding(uint32_t Opcode) const {
1144 return SIInstrFlags::usesFPDPRounding(get(Opcode));
1145 }
1146
1147 static bool isFPAtomic(const MachineInstr &MI) {
1149 }
1150
1151 bool isFPAtomic(uint32_t Opcode) const {
1152 return SIInstrFlags::isFPAtomic(get(Opcode));
1153 }
1154
1155 static bool isNeverUniform(const MachineInstr &MI) {
1157 }
1158
1159 // Check to see if opcode is for a barrier start. Pre gfx12 this is just the
1160 // S_BARRIER, but after support for S_BARRIER_SIGNAL* / S_BARRIER_WAIT we want
1161 // to check for the barrier start (S_BARRIER_SIGNAL*)
1162 bool isBarrierStart(unsigned Opcode) const {
1163 return Opcode == AMDGPU::S_BARRIER ||
1164 Opcode == AMDGPU::S_BARRIER_SIGNAL_M0 ||
1165 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_M0 ||
1166 Opcode == AMDGPU::S_BARRIER_SIGNAL_IMM ||
1167 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM;
1168 }
1169
1170 bool isBarrier(unsigned Opcode) const {
1171 return isBarrierStart(Opcode) || Opcode == AMDGPU::S_BARRIER_WAIT ||
1172 Opcode == AMDGPU::S_BARRIER_INIT_M0 ||
1173 Opcode == AMDGPU::S_BARRIER_INIT_IMM ||
1174 Opcode == AMDGPU::S_BARRIER_JOIN_IMM ||
1175 Opcode == AMDGPU::S_BARRIER_LEAVE || Opcode == AMDGPU::DS_GWS_INIT ||
1176 Opcode == AMDGPU::DS_GWS_BARRIER;
1177 }
1178
1179 static bool isLoadMonitor(unsigned Opc) {
1180 switch (Opc) {
1181 case AMDGPU::GLOBAL_LOAD_MONITOR_B32:
1182 case AMDGPU::GLOBAL_LOAD_MONITOR_B32_SADDR:
1183 case AMDGPU::GLOBAL_LOAD_MONITOR_B64:
1184 case AMDGPU::GLOBAL_LOAD_MONITOR_B64_SADDR:
1185 case AMDGPU::GLOBAL_LOAD_MONITOR_B128:
1186 case AMDGPU::GLOBAL_LOAD_MONITOR_B128_SADDR:
1187 case AMDGPU::FLAT_LOAD_MONITOR_B32:
1188 case AMDGPU::FLAT_LOAD_MONITOR_B64:
1189 case AMDGPU::FLAT_LOAD_MONITOR_B128:
1190 return true;
1191 default:
1192 return false;
1193 }
1194 }
1195
1196 static bool isGFX12CacheInvOrWBInst(unsigned Opc) {
1197 return Opc == AMDGPU::GLOBAL_INV || Opc == AMDGPU::GLOBAL_WB ||
1198 Opc == AMDGPU::GLOBAL_WBINV;
1199 }
1200
1201 static bool isF16PseudoScalarTrans(unsigned Opcode) {
1202 return Opcode == AMDGPU::V_S_EXP_F16_e64 ||
1203 Opcode == AMDGPU::V_S_LOG_F16_e64 ||
1204 Opcode == AMDGPU::V_S_RCP_F16_e64 ||
1205 Opcode == AMDGPU::V_S_RSQ_F16_e64 ||
1206 Opcode == AMDGPU::V_S_SQRT_F16_e64;
1207 }
1208
1209 static bool isPseudoScalarTrans(unsigned Opcode) {
1210 return isF16PseudoScalarTrans(Opcode) ||
1211 Opcode == AMDGPU::V_S_EXP_F32_e64 ||
1212 Opcode == AMDGPU::V_S_LOG_F32_e64 ||
1213 Opcode == AMDGPU::V_S_RCP_F32_e64 ||
1214 Opcode == AMDGPU::V_S_RSQ_F32_e64 ||
1215 Opcode == AMDGPU::V_S_SQRT_F32_e64;
1216 }
1217
1218 static bool isVPermPk16(unsigned Opcode) {
1219 return Opcode == AMDGPU::V_PERM_PK16_B4_U4_e64 ||
1220 Opcode == AMDGPU::V_PERM_PK16_B6_U4_e64 ||
1221 Opcode == AMDGPU::V_PERM_PK16_B8_U4_e64;
1222 }
1223
1224 // \returns true if \p MI clears the V_PERM_PK16 hazard when it immediately
1225 // follows a V_PERM_PK16 (i.e. \p MI is a "safe" instruction).
1227 unsigned Opc = MI.getOpcode();
1228
1229 // Only VALU ops issue on the pipe that clears the V_PERM_PK16 hazard.
1230 if (!isVALU(MI, /*AllowLDSDMA=*/false))
1231 return false;
1232 // OP_XDL: matrix (WMMA/SWMMAC/DOT) ops clear the hazard.
1233 if (isXDL(MI))
1234 return true;
1235 // Pseudo-scalar transcendentals (OP32_SCL_T) do NOT clear the hazard.
1237 return false;
1238
1239 // Use the table lookup, not getBlockingCycles(): occupancy is gated off on
1240 // gfx1251 but the hazard applies to both gfx1250 and gfx1251. Gfx1250 table
1241 // is valid enough for gfx1251 w.r.t. v_perm_pk16 safety check here.
1242 // OP_32_T is in the table at 2 and is safe; other table entries (>= 2) are
1243 // not.
1244 unsigned Cycles = getGFX1250BlockingCyclesTable(MI);
1245 return Cycles < 2 || (Cycles == 2 && isTRANS(MI));
1246 }
1247
1251
1252 bool doesNotReadTiedSource(uint32_t Opcode) const {
1253 return SIInstrFlags::isTiedSourceNotRead(get(Opcode));
1254 }
1255
1256 bool isIGLP(unsigned Opcode) const {
1257 return Opcode == AMDGPU::SCHED_BARRIER ||
1258 Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
1259 }
1260
1261 bool isIGLP(const MachineInstr &MI) const { return isIGLP(MI.getOpcode()); }
1262
1263 // Return true if the instruction is mutually exclusive with all non-IGLP DAG
1264 // mutations, requiring all other mutations to be disabled.
1265 bool isIGLPMutationOnly(unsigned Opcode) const {
1266 return Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
1267 }
1268
1269 static unsigned getNonSoftWaitcntOpcode(unsigned Opcode) {
1270 switch (Opcode) {
1271 case AMDGPU::S_WAITCNT_soft:
1272 return AMDGPU::S_WAITCNT;
1273 case AMDGPU::S_WAITCNT_VSCNT_soft:
1274 return AMDGPU::S_WAITCNT_VSCNT;
1275 case AMDGPU::S_WAIT_LOADCNT_soft:
1276 return AMDGPU::S_WAIT_LOADCNT;
1277 case AMDGPU::S_WAIT_STORECNT_soft:
1278 return AMDGPU::S_WAIT_STORECNT;
1279 case AMDGPU::S_WAIT_SAMPLECNT_soft:
1280 return AMDGPU::S_WAIT_SAMPLECNT;
1281 case AMDGPU::S_WAIT_BVHCNT_soft:
1282 return AMDGPU::S_WAIT_BVHCNT;
1283 case AMDGPU::S_WAIT_DSCNT_soft:
1284 return AMDGPU::S_WAIT_DSCNT;
1285 case AMDGPU::S_WAIT_KMCNT_soft:
1286 return AMDGPU::S_WAIT_KMCNT;
1287 case AMDGPU::S_WAIT_XCNT_soft:
1288 return AMDGPU::S_WAIT_XCNT;
1289 default:
1290 return Opcode;
1291 }
1292 }
1293
1294 static bool isWaitcnt(unsigned Opcode) {
1295 switch (getNonSoftWaitcntOpcode(Opcode)) {
1296 case AMDGPU::S_WAITCNT:
1297 case AMDGPU::S_WAITCNT_VSCNT:
1298 case AMDGPU::S_WAITCNT_VMCNT:
1299 case AMDGPU::S_WAITCNT_EXPCNT:
1300 case AMDGPU::S_WAITCNT_LGKMCNT:
1301 case AMDGPU::S_WAIT_LOADCNT:
1302 case AMDGPU::S_WAIT_LOADCNT_DSCNT:
1303 case AMDGPU::S_WAIT_STORECNT:
1304 case AMDGPU::S_WAIT_STORECNT_DSCNT:
1305 case AMDGPU::S_WAIT_SAMPLECNT:
1306 case AMDGPU::S_WAIT_BVHCNT:
1307 case AMDGPU::S_WAIT_EXPCNT:
1308 case AMDGPU::S_WAIT_DSCNT:
1309 case AMDGPU::S_WAIT_KMCNT:
1310 case AMDGPU::S_WAIT_XCNT:
1311 case AMDGPU::S_WAIT_IDLE:
1312 return true;
1313 default:
1314 return false;
1315 }
1316 }
1317
1318 bool isVGPRCopy(const MachineInstr &MI) const {
1319 assert(isCopyInstr(MI));
1320 Register Dest = MI.getOperand(0).getReg();
1321 const MachineFunction &MF = *MI.getMF();
1322 const MachineRegisterInfo &MRI = MF.getRegInfo();
1323 return !RI.isSGPRReg(MRI, Dest);
1324 }
1325
1326 bool hasVGPRUses(const MachineInstr &MI) const {
1327 const MachineFunction &MF = *MI.getMF();
1328 const MachineRegisterInfo &MRI = MF.getRegInfo();
1329 return llvm::any_of(MI.explicit_uses(),
1330 [&MRI, this](const MachineOperand &MO) {
1331 return MO.isReg() && RI.isVGPR(MRI, MO.getReg());});
1332 }
1333
1334 /// Return true if the instruction modifies the mode register.q
1335 static bool modifiesModeRegister(const MachineInstr &MI);
1336
1337 /// This function is used to determine if an instruction can be safely
1338 /// executed under EXEC = 0 without hardware error, indeterminate results,
1339 /// and/or visible effects on future vector execution or outside the shader.
1340 /// Note: as of 2024 the only use of this is SIPreEmitPeephole where it is
1341 /// used in removing branches over short EXEC = 0 sequences.
1342 /// As such it embeds certain assumptions which may not apply to every case
1343 /// of EXEC = 0 execution.
1345
1346 /// Returns true if the instruction could potentially depend on the value of
1347 /// exec. If false, exec dependencies may safely be ignored.
1348 bool mayReadEXEC(const MachineRegisterInfo &MRI, const MachineInstr &MI) const;
1349
1350 bool isInlineConstant(const APInt &Imm) const;
1351
1352 bool isInlineConstant(const APFloat &Imm) const;
1353
1354 // Returns true if this non-register operand definitely does not need to be
1355 // encoded as a 32-bit literal. Note that this function handles all kinds of
1356 // operands, not just immediates.
1357 //
1358 // Some operands like FrameIndexes could resolve to an inline immediate value
1359 // that will not require an additional 4-bytes; this function assumes that it
1360 // will.
1361 bool isInlineConstant(const MachineOperand &MO, uint8_t OperandType) const {
1362 if (!MO.isImm())
1363 return false;
1364 return isInlineConstant(MO.getImm(), OperandType);
1365 }
1366 bool isInlineConstant(int64_t ImmVal, uint8_t OperandType) const;
1367
1369 const MCOperandInfo &OpInfo) const {
1370 return isInlineConstant(MO, OpInfo.OperandType);
1371 }
1372
1373 /// \p returns true if \p UseMO is substituted with \p DefMO in \p MI it would
1374 /// be an inline immediate.
1376 const MachineOperand &UseMO,
1377 const MachineOperand &DefMO) const {
1378 assert(UseMO.getParent() == &MI);
1379 int OpIdx = UseMO.getOperandNo();
1380 if (OpIdx >= MI.getDesc().NumOperands)
1381 return false;
1382
1383 return isInlineConstant(DefMO, MI.getDesc().operands()[OpIdx]);
1384 }
1385
1386 /// \p returns true if the operand \p OpIdx in \p MI is a valid inline
1387 /// immediate.
1388 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx) const {
1389 const MachineOperand &MO = MI.getOperand(OpIdx);
1390 return isInlineConstant(MO, MI.getDesc().operands()[OpIdx].OperandType);
1391 }
1392
1393 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx,
1394 int64_t ImmVal) const {
1395 if (OpIdx >= MI.getDesc().NumOperands)
1396 return false;
1397
1398 if (isCopyInstr(MI)) {
1399 unsigned Size = getOpSize(MI, OpIdx);
1400 assert(Size == 8 || Size == 4);
1401
1402 uint8_t OpType = (Size == 8) ?
1404 return isInlineConstant(ImmVal, OpType);
1405 }
1406
1407 return isInlineConstant(ImmVal, MI.getDesc().operands()[OpIdx].OperandType);
1408 }
1409
1410 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx,
1411 const MachineOperand &MO) const {
1412 return isInlineConstant(MI, OpIdx, MO.getImm());
1413 }
1414
1415 bool isInlineConstant(const MachineOperand &MO) const {
1416 return isInlineConstant(*MO.getParent(), MO.getOperandNo());
1417 }
1418
1419 bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
1420 const MachineOperand &MO) const;
1421
1422 bool isLiteralOperandLegal(const MCInstrDesc &InstDesc,
1423 const MCOperandInfo &OpInfo) const;
1424
1425 bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
1426 int64_t ImmVal) const;
1427
1428 bool isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
1429 const MachineOperand &MO) const {
1430 return isImmOperandLegal(MI.getDesc(), OpNo, MO);
1431 }
1432
1433 bool isNeverCoissue(MachineInstr &MI) const;
1434
1435 /// Check if this immediate value can be used for AV_MOV_B64_IMM_PSEUDO.
1436 bool isLegalAV64PseudoImm(uint64_t Imm) const;
1437
1438 /// Return true if this 64-bit VALU instruction has a 32-bit encoding.
1439 /// This function will return false if you pass it a 32-bit instruction.
1440 bool hasVALU32BitEncoding(unsigned Opcode) const;
1441
1442 /// Return true if \p Reg is a lane mask that already has 0 in every bit
1443 /// corresponding to a lane that is inactive in EXEC where \p Use executes,
1444 /// so that ANDing it with EXEC there would be a no-op. Requires SSA form.
1446 const MachineRegisterInfo &MRI, unsigned Depth = 0) const;
1447
1448 bool physRegUsesConstantBus(const MachineOperand &Reg) const;
1450 const MachineRegisterInfo &MRI) const;
1451
1452 /// Returns true if this operand uses the constant bus.
1453 bool usesConstantBus(const MachineRegisterInfo &MRI,
1454 const MachineOperand &MO,
1455 const MCOperandInfo &OpInfo) const;
1456
1458 int OpIdx) const {
1459 return usesConstantBus(MRI, MI.getOperand(OpIdx),
1460 MI.getDesc().operands()[OpIdx]);
1461 }
1462
1463 /// Return true if this instruction has any modifiers.
1464 /// e.g. src[012]_mod, omod, clamp.
1465 bool hasModifiers(unsigned Opcode) const;
1466
1467 bool hasModifiersSet(const MachineInstr &MI, AMDGPU::OpName OpName) const;
1468 bool hasAnyModifiersSet(const MachineInstr &MI) const;
1469
1470 bool canShrink(const MachineInstr &MI,
1471 const MachineRegisterInfo &MRI) const;
1472
1474 unsigned NewOpcode) const;
1475
1476 bool verifyInstruction(const MachineInstr &MI,
1477 StringRef &ErrInfo) const override;
1478
1479 unsigned getVALUOp(const MachineInstr &MI) const;
1480 unsigned getVALUOp(unsigned Opc) const;
1481
1484 const DebugLoc &DL, Register Reg, bool IsSCCLive,
1485 SlotIndexes *Indexes = nullptr) const;
1486
1489 Register Reg, SlotIndexes *Indexes = nullptr) const;
1490
1492
1493 /// Return the correct register class for \p OpNo. For target-specific
1494 /// instructions, this will return the register class that has been defined
1495 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
1496 /// the register class of its machine operand.
1497 /// to infer the correct register class base on the other operands.
1499 unsigned OpNo) const;
1500
1501 /// Return the size in bytes of the operand OpNo on the given
1502 // instruction opcode.
1503 unsigned getOpSize(uint32_t Opcode, unsigned OpNo) const {
1504 const MCOperandInfo &OpInfo = get(Opcode).operands()[OpNo];
1505
1506 if (OpInfo.RegClass == -1) {
1507 // If this is an immediate operand, this must be a 32-bit literal.
1508 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
1509 return 4;
1510 }
1511
1512 return RI.getRegSizeInBits(*RI.getRegClass(getOpRegClassID(OpInfo))) / 8;
1513 }
1514
1515 /// This form should usually be preferred since it handles operands
1516 /// with unknown register classes.
1517 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
1518 const MachineOperand &MO = MI.getOperand(OpNo);
1519 if (MO.isReg()) {
1520 if (unsigned SubReg = MO.getSubReg()) {
1521 return RI.getSubRegIdxSize(SubReg) / 8;
1522 }
1523 }
1524 return RI.getRegSizeInBits(*getOpRegClass(MI, OpNo)) / 8;
1525 }
1526
1527 /// Legalize the \p OpIndex operand of this instruction by inserting
1528 /// a MOV. For example:
1529 /// ADD_I32_e32 VGPR0, 15
1530 /// to
1531 /// MOV VGPR1, 15
1532 /// ADD_I32_e32 VGPR0, VGPR1
1533 ///
1534 /// If the operand being legalized is a register, then a COPY will be used
1535 /// instead of MOV.
1536 void legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const;
1537
1538 /// Check if \p MO is a legal operand if it was the \p OpIdx Operand
1539 /// for \p MI.
1540 bool isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
1541 const MachineOperand *MO = nullptr) const;
1542
1543 /// Check if \p MO would be a valid operand for the given operand
1544 /// definition \p OpInfo. Note this does not attempt to validate constant bus
1545 /// restrictions (e.g. literal constant usage).
1547 const MCOperandInfo &OpInfo,
1548 const MachineOperand &MO) const;
1549
1550 /// Check if \p MO (a register operand) is a legal register for the
1551 /// given operand description or operand index.
1552 /// The operand index version provide more legality checks
1553 bool isLegalRegOperand(const MachineRegisterInfo &MRI,
1554 const MCOperandInfo &OpInfo,
1555 const MachineOperand &MO) const;
1556 bool isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
1557 const MachineOperand &MO) const;
1558
1559 /// Check if \p MO would be a legal operand for a single-SGPR-read
1560 /// instruction.
1561 ///
1562 /// Single-SGPR-read instructions typically accept VGPRs, SGPRs, or immediates
1563 /// as source operands. On gfx12+, if a source operand uses SGPRs, the HW can
1564 /// only read the first SGPR and replicate the value across all lanes. \p SrcN
1565 /// can be 0, 1, or 2, representing src0, src1, and src2, respectively. If \p
1566 /// MO is nullptr, the operand corresponding to \p SrcN will be used. Non-SGPR
1567 /// operands are always considered legal.
1568 bool
1570 const MachineInstr &MI, unsigned SrcN,
1571 const MachineOperand *MO = nullptr) const;
1572
1573 /// Legalize operands in \p MI by either commuting it or inserting a
1574 /// copy of src1.
1576
1577 /// Fix operands in \p MI to satisfy constant bus requirements.
1579
1580 /// Copy a value from a VGPR (\p SrcReg) to SGPR. The desired register class
1581 /// for the dst register (\p DstRC) can be optionally supplied. This function
1582 /// can only be used when it is know that the value in SrcReg is same across
1583 /// all threads in the wave.
1584 /// \returns The SGPR register that \p SrcReg was copied to.
1587 const TargetRegisterClass *DstRC = nullptr) const;
1588
1591
1594 const TargetRegisterClass *DstRC,
1596 const DebugLoc &DL) const;
1597
1598 /// Legalize all operands in this instruction. This function may create new
1599 /// instructions and control-flow around \p MI. If present, \p MDT is
1600 /// updated.
1601 /// \returns A new basic block that contains \p MI if new blocks were created.
1603 legalizeOperands(MachineInstr &MI, MachineDominatorTree *MDT = nullptr) const;
1604
1605 /// Change SADDR form of a FLAT \p Inst to its VADDR form if saddr operand
1606 /// was moved to VGPR. \returns true if succeeded.
1607 bool moveFlatAddrToVGPR(MachineInstr &Inst) const;
1608
1609 /// Fix operands in Inst to fix 16bit SALU to VALU lowering.
1611 MachineRegisterInfo &MRI) const;
1612 void legalizeOperandsVALUt16(MachineInstr &Inst, unsigned OpIdx,
1613 MachineRegisterInfo &MRI) const;
1614
1615 /// Replace the instructions opcode with the equivalent VALU
1616 /// opcode. This function will also move the users of MachineInstruntions
1617 /// in the \p WorkList to the VALU if necessary. If present, \p MDT is
1618 /// updated.
1619 void moveToVALU(SIInstrWorklist &Worklist, MachineDominatorTree *MDT) const;
1620
1621 void
1623 MachineInstr &Inst,
1625 DenseMap<MachineInstr *, bool> &V2SPhyCopiesToErase) const;
1626 /// Wrapper function for generating waterfall for instruction \p MI
1627 /// This function take into consideration of related pre & succ instructions
1628 /// (e.g. calling process) into consideratioin
1631 ArrayRef<Register> PhySGPRs = {}) const;
1632
1633 void insertNoop(MachineBasicBlock &MBB,
1634 MachineBasicBlock::iterator MI) const override;
1635
1636 void insertNoops(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
1637 unsigned Quantity) const override;
1638
1639 /// Build instructions that simulate the behavior of a `s_trap 2` instructions
1640 /// for hardware (namely, gfx11) that runs in PRIV=1 mode. There, s_trap is
1641 /// interpreted as a nop.
1642 MachineBasicBlock *insertSimulatedTrap(MachineRegisterInfo &MRI,
1643 MachineBasicBlock &MBB,
1644 MachineInstr &MI,
1645 const DebugLoc &DL) const;
1646
1647 /// Return the number of wait states that result from executing this
1648 /// instruction.
1649 static unsigned getNumWaitStates(const MachineInstr &MI);
1650
1651 /// Returns the operand named \p Op. If \p MI does not have an
1652 /// operand named \c Op, this function returns nullptr.
1654 MachineOperand *getNamedOperand(MachineInstr &MI,
1655 AMDGPU::OpName OperandName) const;
1656
1659 AMDGPU::OpName OperandName) const {
1660 return getNamedOperand(const_cast<MachineInstr &>(MI), OperandName);
1661 }
1662
1663 /// Get required immediate operand
1665 AMDGPU::OpName OperandName) const {
1666 int Idx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), OperandName);
1667 return MI.getOperand(Idx).getImm();
1668 }
1669
1672
1673 bool isLowLatencyInstruction(const MachineInstr &MI) const;
1674 bool isHighLatencyDef(int Opc) const override;
1675
1676 /// Return the descriptor of the target-specific machine instruction
1677 /// that corresponds to the specified pseudo or native opcode.
1678 const MCInstrDesc &getMCOpcodeFromPseudo(unsigned Opcode) const {
1679 return get(pseudoToMCOpcode(Opcode));
1680 }
1681
1682 Register isStackAccess(const MachineInstr &MI, int &FrameIndex,
1683 TypeSize &MemBytes) const;
1684 Register isSGPRStackAccess(const MachineInstr &MI, int &FrameIndex,
1685 TypeSize &MemBytes) const;
1686
1688 int &FrameIndex) const override {
1689 TypeSize MemBytes = TypeSize::getZero();
1690 return isLoadFromStackSlot(MI, FrameIndex, MemBytes);
1691 }
1692
1693 Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex,
1694 TypeSize &MemBytes) const override;
1695
1697 int &FrameIndex) const override {
1698 TypeSize MemBytes = TypeSize::getZero();
1699 return isStoreToStackSlot(MI, FrameIndex, MemBytes);
1700 }
1701
1702 Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex,
1703 TypeSize &MemBytes) const override;
1704
1705 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
1706
1707 InstSizeVerifyMode
1708 getInstSizeVerifyMode(const MachineInstr &MI) const override;
1709
1710 bool mayAccessFlatAddressSpace(const MachineInstr &MI) const;
1711
1712 std::pair<unsigned, unsigned>
1713 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
1714
1716 getSerializableTargetIndices() const override;
1717
1720
1723
1726 const ScheduleDAG *DAG) const override;
1727
1730 MachineLoopInfo *MLI) const override;
1731
1734 const ScheduleDAGMI *DAG) const override;
1735
1737 const MachineFunction &MF) const override;
1738
1740 Register Reg = Register()) const override;
1741
1742 bool canAddToBBProlog(const MachineInstr &MI) const;
1743
1746 const DebugLoc &DL, Register Src,
1747 Register Dst) const override;
1748
1751 const DebugLoc &DL, Register Src,
1752 unsigned SrcSubReg,
1753 Register Dst) const override;
1754
1755 bool isWave32() const;
1756
1757 bool isVOPDAntidependencyAllowed(const MachineInstr &MI) const;
1758
1759 bool hasRAWDependency(const MachineInstr &FirstMI,
1760 const MachineInstr &SecondMI) const;
1761
1762 /// Return a partially built integer add instruction without carry.
1763 /// Caller must add source operands.
1764 /// For pre-GFX9 it will generate unused carry destination operand.
1765 /// TODO: After GFX9 it should return a no-carry operation.
1768 const DebugLoc &DL,
1769 Register DestReg) const;
1770
1773 const DebugLoc &DL,
1774 Register DestReg,
1775 RegScavenger &RS) const;
1776
1777 static bool isKillTerminator(unsigned Opcode);
1778 const MCInstrDesc &getKillTerminatorFromPseudo(unsigned Opcode) const;
1779
1780 bool isLegalMUBUFImmOffset(unsigned Imm) const;
1781
1782 static unsigned getMaxMUBUFImmOffset(const GCNSubtarget &ST);
1783
1784 bool splitMUBUFOffset(uint32_t Imm, uint32_t &SOffset, uint32_t &ImmOffset,
1785 Align Alignment = Align(4)) const;
1786
1787 /// Returns if \p Offset is legal for the subtarget as the offset to a FLAT
1788 /// encoded instruction with the given \p FlatVariant.
1789 bool isLegalFLATOffset(int64_t Offset, unsigned AddrSpace,
1790 AMDGPU::FlatAddrSpace FlatVariant) const;
1791
1792 /// Split \p COffsetVal into {immediate offset field, remainder offset}
1793 /// values.
1794 std::pair<int64_t, int64_t>
1795 splitFlatOffset(int64_t COffsetVal, unsigned AddrSpace,
1796 AMDGPU::FlatAddrSpace FlatVariant) const;
1797
1798 /// Returns true if negative offsets are allowed for the given \p FlatVariant.
1799 bool allowNegativeFlatOffset(AMDGPU::FlatAddrSpace FlatVariant) const;
1800
1801 /// \brief Return a target-specific opcode if Opcode is a pseudo instruction.
1802 /// Return -1 if the target-specific opcode for the pseudo instruction does
1803 /// not exist. If Opcode is not a pseudo instruction, this is identity.
1804 int pseudoToMCOpcode(int Opcode) const;
1805
1806 /// \brief Check if this instruction should only be used by assembler.
1807 /// Return true if this opcode should not be used by codegen.
1808 bool isAsmOnlyOpcode(int MCOp) const;
1809
1810 void fixImplicitOperands(MachineInstr &MI) const;
1811
1813 ArrayRef<unsigned> Ops, int FrameIndex,
1814 MachineInstr *&CopyMI,
1815 LiveIntervals *LIS = nullptr,
1816 VirtRegMap *VRM = nullptr) const override;
1817
1818 unsigned getInstrLatency(const InstrItineraryData *ItinData,
1819 const MachineInstr &MI,
1820 unsigned *PredCost = nullptr) const override;
1821
1822 unsigned getBlockingCycles(const MachineInstr &MI) const;
1823
1824 /// GFX1250 blocking-cycles table lookup with no occupancy subtarget gate.
1825 /// Returns 0 if \p MI is not in the table. Used as a multi-pass VALU denylist
1826 /// (e.g. V_PERM_PK16 hazard) on both gfx1250 and gfx1251.
1827 unsigned getGFX1250BlockingCyclesTable(const MachineInstr &MI) const;
1828
1829 const MachineOperand &getCalleeOperand(const MachineInstr &MI) const override;
1830
1832
1834
1835 const MIRFormatter *getMIRFormatter() const override;
1836
1837 static unsigned getDSShaderTypeValue(const MachineFunction &MF);
1838
1839 const TargetSchedModel &getSchedModel() const { return SchedModel; }
1840
1842 Register DstReg,
1843 MachineInstr &Inst) const;
1844
1846 SIInstrWorklist &Worklist, Register DstReg, MachineInstr &Inst,
1849 DenseMap<MachineInstr *, bool> &V2SPhyCopiesToErase) const;
1850
1851 // FIXME: This should be removed
1852 // Enforce operand's \p OpName even alignment if required by target.
1853 // This is used if an operand is a 32 bit register but needs to be aligned
1854 // regardless.
1855 void enforceOperandRCAlignment(MachineInstr &MI, AMDGPU::OpName OpName) const;
1856
1857 /// Get the repeat rate for a VALU instruction from the scheduling model.
1858 /// Returns 1 for regular VALU, >1 for long-latency VALU (packed, F64, etc.)
1859 unsigned getRepeatRate(const MachineInstr &MI) const;
1860};
1861
1862/// \brief Returns true if a reg:subreg pair P has a TRC class
1864 const TargetRegisterClass &TRC,
1865 MachineRegisterInfo &MRI) {
1866 auto *RC = MRI.getRegClass(P.Reg);
1867 if (!P.SubReg)
1868 return RC == &TRC;
1869 auto *TRI = MRI.getTargetRegisterInfo();
1870 return RC == TRI->getMatchingSuperRegClass(RC, &TRC, P.SubReg);
1871}
1872
1873/// \brief Create RegSubRegPair from a register MachineOperand
1874inline
1876 assert(O.isReg());
1877 return TargetInstrInfo::RegSubRegPair(O.getReg(), O.getSubReg());
1878}
1879
1880/// \brief Return the SubReg component from REG_SEQUENCE
1881TargetInstrInfo::RegSubRegPair getRegSequenceSubReg(MachineInstr &MI,
1882 unsigned SubReg);
1883
1884/// \brief Return the defining instruction for a given reg:subreg pair
1885/// skipping copy like instructions and subreg-manipulation pseudos.
1886/// Following another subreg of a reg:subreg isn't supported.
1887MachineInstr *getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P,
1888 const MachineRegisterInfo &MRI);
1889
1890/// \brief Return false if EXEC is not changed between the def of \p VReg at \p
1891/// DefMI and the use at \p UseMI. Should be run on SSA. Currently does not
1892/// attempt to track between blocks.
1893bool execMayBeModifiedBeforeUse(const MachineRegisterInfo &MRI,
1894 Register VReg,
1895 const MachineInstr &DefMI,
1896 const MachineInstr &UseMI);
1897
1898/// \brief Return false if EXEC is not changed between the def of \p VReg at \p
1899/// DefMI and all its uses. Should be run on SSA. Currently does not attempt to
1900/// track between blocks.
1901bool execMayBeModifiedBeforeAnyUse(const MachineRegisterInfo &MRI,
1902 Register VReg,
1903 const MachineInstr &DefMI);
1904
1905namespace AMDGPU {
1906
1908 int32_t getVOPe64(uint32_t Opcode);
1909
1911 int32_t getVOPe32(uint32_t Opcode);
1912
1914 int32_t getSDWAOp(uint32_t Opcode);
1915
1917 int32_t getDPPOp32(uint32_t Opcode);
1918
1920 int32_t getDPPOp64(uint32_t Opcode);
1921
1924
1926 int32_t getCommuteRev(uint32_t Opcode);
1927
1929 int32_t getCommuteOrig(uint32_t Opcode);
1930
1932 int32_t getAddr64Inst(uint32_t Opcode);
1933
1934 /// Check if \p Opcode is an Addr64 opcode.
1935 ///
1936 /// \returns \p Opcode if it is an Addr64 opcode, otherwise -1.
1938 int32_t getIfAddr64Inst(uint32_t Opcode);
1939
1941 int32_t getSOPKOp(uint32_t Opcode);
1942
1943 /// \returns SADDR form of a FLAT Global instruction given an \p Opcode
1944 /// of a VADDR form.
1947
1948 /// \returns VADDR form of a FLAT Global instruction given an \p Opcode
1949 /// of a SADDR form.
1952
1953 /// \returns ST form with only immediate offset of a FLAT Scratch instruction
1954 /// given an \p Opcode of an SS (SADDR) form.
1957
1958 /// \returns SV (VADDR) form of a FLAT Scratch instruction given an \p Opcode
1959 /// of an SVS (SADDR + VADDR) form.
1962
1963 /// \returns SS (SADDR) form of a FLAT Scratch instruction given an \p Opcode
1964 /// of an SV (VADDR) form.
1967
1968 /// \returns SV (VADDR) form of a FLAT Scratch instruction given an \p Opcode
1969 /// of an SS (SADDR) form.
1972
1973 /// \returns earlyclobber version of a MAC MFMA is exists.
1976
1977 /// \returns Version of an instruction which uses AGPRs for coupled operands
1978 /// given an \p Opcode which uses VGPRs for coupled operands.
1980 int32_t getAGPRFormOp(uint32_t Opcode);
1981
1982 /// \returns v_cmpx version of a v_cmp instruction.
1985
1986 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
1989 const uint64_t RSRC_TID_ENABLE = UINT64_C(1) << (32 + 23);
1990
1991} // end namespace AMDGPU
1992
1993namespace AMDGPU {
1995 // For sgpr to vgpr spill instructions
1997};
1998} // namespace AMDGPU
1999
2000namespace SI {
2002
2003/// Offsets in bytes from the start of the input buffer
2015
2016} // end namespace KernelInputOffsets
2017} // end namespace SI
2018
2019} // end namespace llvm
2020
2021#endif // LLVM_LIB_TARGET_AMDGPU_SIINSTRINFO_H
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
unsigned uint64_t
Provides AMDGPU specific target descriptions.
AMDGPU specific overrides of MIRFormatter.
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_READONLY
Definition Compiler.h:338
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
Interface definition for SIRegisterInfo.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
static unsigned getBranchOpcode(ISD::CondCode Cond)
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
Itinerary data supplied by a subtarget to be used by a target.
Describe properties that are true of each instruction in the target description file.
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition MCInstrDesc.h:88
MIRFormater - Interface to format MIR operand based on target.
MachineInstrBundleIterator< MachineInstr > iterator
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
LLVM_ABI unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const TargetRegisterInfo * getTargetRegisterInfo() const
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Represents one node in the SelectionDAG.
bool usesFPDPRounding(uint32_t Opcode) const
static bool isCBranchVCCZRead(const MachineInstr &MI)
bool isLegalMUBUFImmOffset(unsigned Imm) const
bool isInlineConstant(const APInt &Imm) const
static bool isMAI(const MachineInstr &MI)
void legalizeOperandsVOP3(MachineRegisterInfo &MRI, MachineInstr &MI) const
Fix operands in MI to satisfy constant bus requirements.
bool canAddToBBProlog(const MachineInstr &MI) const
static bool isDS(const MachineInstr &MI)
static bool isVMEM(const MachineInstr &MI)
MachineBasicBlock * legalizeOperands(MachineInstr &MI, MachineDominatorTree *MDT=nullptr) const
Legalize all operands in this instruction.
bool areLoadsFromSameBasePtr(SDNode *Load0, SDNode *Load1, int64_t &Offset0, int64_t &Offset1) const override
bool isWQM(uint32_t Opcode) const
static bool isVOP3(const MachineInstr &MI)
bool isMTBUF(uint32_t Opcode) const
unsigned getLiveRangeSplitOpcode(Register Reg, const MachineFunction &MF) const override
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width, const TargetRegisterInfo *TRI) const final
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
static bool isNeverUniform(const MachineInstr &MI)
bool isXDLWMMA(const MachineInstr &MI) const
bool isBasicBlockPrologue(const MachineInstr &MI, Register Reg=Register()) const override
bool isSpill(uint32_t Opcode) const
bool isMUBUF(uint32_t Opcode) const
uint64_t getDefaultRsrcDataFormat() const
static bool isSOPP(const MachineInstr &MI)
bool hasVGPRUses(const MachineInstr &MI) const
bool mayAccessScratch(const MachineInstr &MI) const
bool isIGLP(unsigned Opcode) const
static bool isFLATScratch(const MachineInstr &MI)
bool isLegalFLATOffset(int64_t Offset, unsigned AddrSpace, AMDGPU::FlatAddrSpace FlatVariant) const
Returns if Offset is legal for the subtarget as the offset to a FLAT encoded instruction with the giv...
const MCInstrDesc & getIndirectRegWriteMovRelPseudo(unsigned VecSize, unsigned EltSize, bool IsSGPR) const
static bool isSpill(const MachineInstr &MI)
MachineInstrBuilder getAddNoCarry(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg) const
Return a partially built integer add instruction without carry.
bool isVOP3PMix(uint16_t Opcode) const
bool mayAccessFlatAddressSpace(const MachineInstr &MI) const
bool shouldScheduleLoadsNear(SDNode *Load0, SDNode *Load1, int64_t Offset0, int64_t Offset1, unsigned NumLoads) const override
bool splitMUBUFOffset(uint32_t Imm, uint32_t &SOffset, uint32_t &ImmOffset, Align Alignment=Align(4)) const
bool isIgnorableUse(const MachineInstr &MI, unsigned OpIdx) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
void moveToVALU(SIInstrWorklist &Worklist, MachineDominatorTree *MDT) const
Replace the instructions opcode with the equivalent VALU opcode.
bool isDisableWQM(uint32_t Opcode) const
static bool isSMRD(const MachineInstr &MI)
unsigned getGFX1250BlockingCyclesTable(const MachineInstr &MI) const
GFX1250 blocking-cycles table lookup with no occupancy subtarget gate.
void restoreExec(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register Reg, SlotIndexes *Indexes=nullptr) const
void storeRegToStackSlotCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC) const
bool usesConstantBus(const MachineRegisterInfo &MRI, const MachineOperand &MO, const MCOperandInfo &OpInfo) const
Returns true if this operand uses the constant bus.
static unsigned getMaxMUBUFImmOffset(const GCNSubtarget &ST)
bool doesNotReadTiedSource(uint32_t Opcode) const
bool isSOPK(uint32_t Opcode) const
static unsigned getFoldableCopySrcIdx(const MachineInstr &MI)
unsigned getOpSize(uint32_t Opcode, unsigned OpNo) const
Return the size in bytes of the operand OpNo on the given.
bool isLDSDMA(uint32_t Opcode) const
static bool hasSameClamp(const MachineInstr &A, const MachineInstr &B)
void legalizeOperandsFLAT(MachineRegisterInfo &MRI, MachineInstr &MI) const
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask, int64_t CmpValue, const MachineRegisterInfo *MRI) const override
bool usesConstantBus(const MachineRegisterInfo &MRI, const MachineInstr &MI, int OpIdx) const
const TargetRegisterClass * getInlineAsmMemoryOperandRegClass(InlineAsm::ConstraintCode C) const override
bool isAtomicRet(uint32_t Opcode) const
static std::optional< int64_t > extractSubregFromImm(int64_t ImmVal, unsigned SubRegIndex)
Return the extracted immediate value in a subregister use from a constant materialized in a super reg...
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool isVINTRP(uint32_t Opcode) const
bool isSOP1(uint32_t Opcode) const
static bool isMTBUF(const MachineInstr &MI)
const MCInstrDesc & getIndirectGPRIDXPseudo(unsigned VecSize, bool IsIndirectSrc) const
static bool isDGEMM(unsigned Opcode)
static bool isEXP(const MachineInstr &MI)
static bool isSALU(const MachineInstr &MI)
static bool setsSCCIfResultIsNonZero(const MachineInstr &MI)
const MIRFormatter * getMIRFormatter() const override
bool isSGPRSpill(uint32_t Opcode) const
static bool isXcntDrain(const MachineInstr &MI)
True if MI implicitly drains XCNT.
void legalizeGenericOperand(MachineBasicBlock &InsertMBB, MachineBasicBlock::iterator I, const TargetRegisterClass *DstRC, MachineOperand &Op, MachineRegisterInfo &MRI, const DebugLoc &DL) const
MachineInstr * buildShrunkInst(MachineInstr &MI, unsigned NewOpcode) const
static bool isVOP2(const MachineInstr &MI)
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const override
static bool isSDWA(const MachineInstr &MI)
const MCInstrDesc & getKillTerminatorFromPseudo(unsigned Opcode) const
static bool mayWriteLDSThroughDMA(const MachineInstr &MI)
void insertNoops(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned Quantity) const override
bool isDOT(uint32_t Opcode) const
static bool isVINTRP(const MachineInstr &MI)
bool isIGLPMutationOnly(unsigned Opcode) const
static bool isGather4(const MachineInstr &MI)
bool isDS(uint32_t Opcode) const
MachineInstr * getWholeWaveFunctionSetup(MachineFunction &MF) const
static bool isMFMAorWMMA(const MachineInstr &MI)
static bool isWQM(const MachineInstr &MI)
static bool doesNotReadTiedSource(const MachineInstr &MI)
bool isLegalVSrcOperand(const MachineRegisterInfo &MRI, const MCOperandInfo &OpInfo, const MachineOperand &MO) const
Check if MO would be a valid operand for the given operand definition OpInfo.
static bool isDOT(const MachineInstr &MI)
std::unique_ptr< PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
InstSizeVerifyMode getInstSizeVerifyMode(const MachineInstr &MI) const override
bool isGather4(uint32_t Opcode) const
static bool usesFPDPRounding(const MachineInstr &MI)
bool isVIMAGE(uint32_t Opcode) const
MachineInstr * createPHISourceCopy(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt, const DebugLoc &DL, Register Src, unsigned SrcSubReg, Register Dst) const override
bool isImage(uint32_t Opcode) const
static bool usesTENSOR_CNT(const MachineInstr &MI)
bool isInlineConstant(const MachineOperand &MO) const
bool hasModifiers(unsigned Opcode) const
Return true if this instruction has any modifiers.
bool shouldClusterMemOps(ArrayRef< const MachineOperand * > BaseOps1, int64_t Offset1, bool OffsetIsScalable1, ArrayRef< const MachineOperand * > BaseOps2, int64_t Offset2, bool OffsetIsScalable2, unsigned ClusterSize, unsigned NumBytes) const override
static bool isSWMMAC(const MachineInstr &MI)
ScheduleHazardRecognizer * CreateTargetMIHazardRecognizer(const InstrItineraryData *II, const ScheduleDAGMI *DAG) const override
bool isDPP(uint32_t Opcode) const
bool isWave32() const
bool isHighLatencyDef(int Opc) const override
void legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const
Legalize the OpIndex operand of this instruction by inserting a MOV.
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
static bool isVOPC(const MachineInstr &MI)
void removeModOperands(MachineInstr &MI) const
bool hasFPClamp(uint32_t Opcode) const
bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx, int64_t ImmVal) const
bool isGWS(uint32_t Opcode) const
unsigned getRepeatRate(const MachineInstr &MI) const
Get the repeat rate for a VALU instruction from the scheduling model.
unsigned getVectorRegSpillRestoreOpcode(Register Reg, const TargetRegisterClass *RC, unsigned Size, const SIMachineFunctionInfo &MFI) const
bool isLegalSingleSGPRReadInstOperand(const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN, const MachineOperand *MO=nullptr) const
Check if MO would be a legal operand for a single-SGPR-read instruction.
bool isXDL(const MachineInstr &MI) const
Register isStackAccess(const MachineInstr &MI, int &FrameIndex, TypeSize &MemBytes) const
static bool isVIMAGE(const MachineInstr &MI)
static bool isLDSDIR(const MachineInstr &MI)
void enforceOperandRCAlignment(MachineInstr &MI, AMDGPU::OpName OpName) const
static bool isSOP2(const MachineInstr &MI)
LLVM_READONLY const MachineOperand * getNamedOperand(const MachineInstr &MI, AMDGPU::OpName OperandName) const
static bool isGWS(const MachineInstr &MI)
bool hasRAWDependency(const MachineInstr &FirstMI, const MachineInstr &SecondMI) const
bool isLegalAV64PseudoImm(uint64_t Imm) const
Check if this immediate value can be used for AV_MOV_B64_IMM_PSEUDO.
bool isNeverCoissue(MachineInstr &MI) const
const TargetSchedModel & getSchedModel() const
static bool isBUF(const MachineInstr &MI)
bool isInlineConstant(const MachineInstr &MI, const MachineOperand &UseMO, const MachineOperand &DefMO) const
returns true if UseMO is substituted with DefMO in MI it would be an inline immediate.
bool isSOPC(uint32_t Opcode) const
bool isMAI(uint32_t Opcode) const
bool isNonCommutableDPP(const MachineInstr &MI) const
void handleCopyToPhysHelper(SIInstrWorklist &Worklist, Register DstReg, MachineInstr &Inst, MachineRegisterInfo &MRI, DenseMap< MachineInstr *, V2PhysSCopyInfo > &WaterFalls, DenseMap< MachineInstr *, bool > &V2SPhyCopiesToErase) const
bool hasModifiersSet(const MachineInstr &MI, AMDGPU::OpName OpName) const
bool isLegalToSwap(const MachineInstr &MI, unsigned fromIdx, unsigned toIdx) const
bool isFixedSize(uint32_t Opcode) const
static bool isFLATGlobal(const MachineInstr &MI)
unsigned getMachineCSELookAheadLimit() const override
MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, int FrameIndex, MachineInstr *&CopyMI, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const override
bool isGlobalMemoryObject(const MachineInstr *MI) const override
static bool isVSAMPLE(const MachineInstr &MI)
static bool isAtomicRet(const MachineInstr &MI)
bool isBufferSMRD(const MachineInstr &MI) const
static bool isKillTerminator(unsigned Opcode)
bool isVOPDAntidependencyAllowed(const MachineInstr &MI) const
If OpX is multicycle, anti-dependencies are not allowed.
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx0, unsigned &SrcOpIdx1) const override
const GCNSubtarget & getSubtarget() const
void insertScratchExecCopy(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register Reg, bool IsSCCLive, SlotIndexes *Indexes=nullptr) const
bool hasVALU32BitEncoding(unsigned Opcode) const
Return true if this 64-bit VALU instruction has a 32-bit encoding.
static bool isDisableWQM(const MachineInstr &MI)
unsigned getBlockingCycles(const MachineInstr &MI) const
bool isVOP3PMix(const MachineInstr &MI) const
unsigned getMovOpcode(const TargetRegisterClass *DstRC) const
Register isSGPRStackAccess(const MachineInstr &MI, int &FrameIndex, TypeSize &MemBytes) const
bool isMFMAorWMMA(uint32_t Opcode) const
unsigned buildExtractSubReg(MachineBasicBlock::iterator MI, MachineRegisterInfo &MRI, const MachineOperand &SuperReg, const TargetRegisterClass *SuperRC, unsigned SubIdx, const TargetRegisterClass *SubRC) const
void legalizeOperandsVOP2(MachineRegisterInfo &MRI, MachineInstr &MI) const
Legalize operands in MI by either commuting it or inserting a copy of src1.
static bool isVPermPk16(unsigned Opcode)
bool isFLATGlobal(uint32_t Opcode) const
static bool isVALU(const MachineInstr &MI, bool AllowLDSDMA)
bool foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg, MachineRegisterInfo *MRI) const final
static bool isTRANS(const MachineInstr &MI)
static bool isImage(const MachineInstr &MI)
static bool isSOPK(const MachineInstr &MI)
const TargetRegisterClass * getOpRegClass(const MachineInstr &MI, unsigned OpNo) const
Return the correct register class for OpNo.
MachineBasicBlock * insertSimulatedTrap(MachineRegisterInfo &MRI, MachineBasicBlock &MBB, MachineInstr &MI, const DebugLoc &DL) const
Build instructions that simulate the behavior of a s_trap 2 instructions for hardware (namely,...
bool isMIMG(uint32_t Opcode) const
static unsigned getNonSoftWaitcntOpcode(unsigned Opcode)
bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx) const
returns true if the operand OpIdx in MI is a valid inline immediate.
bool isVGPRSpill(uint32_t Opcode) const
static unsigned getDSShaderTypeValue(const MachineFunction &MF)
static bool isFoldableCopy(const MachineInstr &MI)
bool isAtomic(uint32_t Opcode) const
static bool isVINTERP(const MachineInstr &MI)
static bool isMUBUF(const MachineInstr &MI)
bool expandPostRAPseudo(MachineInstr &MI) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &CmpMask, int64_t &CmpValue) const override
void createWaterFallForSiCall(MachineInstr *MI, MachineDominatorTree *MDT, ArrayRef< MachineOperand * > ScalarOps, ArrayRef< Register > PhySGPRs={}) const
Wrapper function for generating waterfall for instruction MI This function take into consideration of...
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
static bool hasFPClamp(const MachineInstr &MI)
bool isVOP2(uint32_t Opcode) const
static bool isGFX12CacheInvOrWBInst(unsigned Opc)
static bool isSegmentSpecificFLAT(const MachineInstr &MI)
static bool isWaitcnt(unsigned Opcode)
bool isReMaterializableImpl(const MachineInstr &MI) const override
bool isFLATScratch(uint32_t Opcode) const
static bool isVOP3(const MCInstrDesc &Desc)
unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const
This form should usually be preferred since it handles operands with unknown register classes.
bool isSegmentSpecificFLAT(uint32_t Opcode) const
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool physRegUsesConstantBus(const MachineOperand &Reg) const
bool isInlineConstant(const MachineOperand &MO, const MCOperandInfo &OpInfo) const
static bool isF16PseudoScalarTrans(unsigned Opcode)
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
bool mayAccessVMEMThroughFlat(const MachineInstr &MI) const
static bool isChainCallOpcode(uint64_t Opcode)
bool isVOPC(uint32_t Opcode) const
static bool isDPP(const MachineInstr &MI)
bool analyzeBranchImpl(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const
bool isPacked(uint32_t Opcode) const
static bool isMFMA(const MachineInstr &MI)
bool isLowLatencyInstruction(const MachineInstr &MI) const
bool isIGLP(const MachineInstr &MI) const
static bool isScalarStore(const MachineInstr &MI)
bool isFLAT(uint32_t Opcode) const
std::optional< DestSourcePair > isCopyInstrImpl(const MachineInstr &MI) const override
If the specific machine instruction is a instruction that moves/copies value from one register to ano...
bool isVALU(uint32_t Opcode, bool AllowLDSDMA) const
LDSDMA instructions act as both VALU and memory instructions, thus we also tag them as VALU.
void mutateAndCleanupImplicit(MachineInstr &MI, const MCInstrDesc &NewDesc) const
ValueUniformity getGenericValueUniformity(const MachineInstr &MI) const
static bool isMAI(const MCInstrDesc &Desc)
static bool isSrc1DPPRevOpcode(const GCNSubtarget &ST, uint32_t Opcode)
void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, unsigned SubIdx, const MachineInstr &Orig, LaneBitmask UsedLanes=LaneBitmask::getAll()) const override
static bool isFPAtomic(const MachineInstr &MI)
static bool usesLGKM_CNT(const MachineInstr &MI)
bool isFPAtomic(uint32_t Opcode) const
void legalizeOperandsVALUt16(MachineInstr &Inst, MachineRegisterInfo &MRI) const
Fix operands in Inst to fix 16bit SALU to VALU lowering.
bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo, const MachineOperand &MO) const
static bool isPacked(const MachineInstr &MI)
bool canShrink(const MachineInstr &MI, const MachineRegisterInfo &MRI) const
const MachineOperand & getCalleeOperand(const MachineInstr &MI) const override
bool isVPermPk16SafeInstr(const MachineInstr &MI) const
bool isAsmOnlyOpcode(int MCOp) const
Check if this instruction should only be used by assembler.
bool isAlwaysGDS(uint32_t Opcode) const
static bool isVGPRSpill(const MachineInstr &MI)
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
This is used by the post-RA scheduler (SchedulePostRAList.cpp).
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
static bool isSBarrierSCCWrite(unsigned Opcode)
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
unsigned getVectorRegSpillSaveOpcode(Register Reg, const TargetRegisterClass *RC, unsigned Size, const SIMachineFunctionInfo &MFI, bool NeedsCFI) const
int64_t getNamedImmOperand(const MachineInstr &MI, AMDGPU::OpName OperandName) const
Get required immediate operand.
bool isSOP2(uint32_t Opcode) const
ArrayRef< std::pair< int, const char * > > getSerializableTargetIndices() const override
bool isVGPRCopy(const MachineInstr &MI) const
bool isVOP1(uint32_t Opcode) const
bool isVINTERP(uint32_t Opcode) const
bool regUsesConstantBus(const MachineOperand &Reg, const MachineRegisterInfo &MRI) const
static bool isMIMG(const MachineInstr &MI)
MachineOperand buildExtractSubRegOrImm(MachineBasicBlock::iterator MI, MachineRegisterInfo &MRI, const MachineOperand &SuperReg, const TargetRegisterClass *SuperRC, unsigned SubIdx, const TargetRegisterClass *SubRC) const
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool isLegalRegOperand(const MachineRegisterInfo &MRI, const MCOperandInfo &OpInfo, const MachineOperand &MO) const
Check if MO (a register operand) is a legal register for the given operand description or operand ind...
LLVM_READONLY int commuteOpcode(const MachineInstr &MI) const
static unsigned getNumWaitStates(const MachineInstr &MI)
Return the number of wait states that result from executing this instruction.
static bool isVOP3P(const MachineInstr &MI)
unsigned getVALUOp(const MachineInstr &MI) const
static bool modifiesModeRegister(const MachineInstr &MI)
Return true if the instruction modifies the mode register.q.
Register readlaneVGPRToSGPR(Register SrcReg, MachineInstr &UseMI, MachineRegisterInfo &MRI, const TargetRegisterClass *DstRC=nullptr) const
Copy a value from a VGPR (SrcReg) to SGPR.
bool hasDivergentBranch(const MachineBasicBlock *MBB) const
Return whether the block terminate with divergent branch.
bool isInlineConstant(const MachineOperand &MO, uint8_t OperandType) const
std::pair< int64_t, int64_t > splitFlatOffset(int64_t COffsetVal, unsigned AddrSpace, AMDGPU::FlatAddrSpace FlatVariant) const
Split COffsetVal into {immediate offset field, remainder offset} values.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
bool isVOP3P(uint32_t Opcode) const
void fixImplicitOperands(MachineInstr &MI) const
bool moveFlatAddrToVGPR(MachineInstr &Inst) const
Change SADDR form of a FLAT Inst to its VADDR form if saddr operand was moved to VGPR.
bool isSWMMAC(uint32_t Opcode) const
static bool usesASYNC_CNT(const MachineInstr &MI)
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
bool isMaskedByExec(Register Reg, const MachineInstr &Use, const MachineRegisterInfo &MRI, unsigned Depth=0) const
Return true if Reg is a lane mask that already has 0 in every bit corresponding to a lane that is ina...
void createReadFirstLaneFromCopyToPhysReg(MachineRegisterInfo &MRI, Register DstReg, MachineInstr &Inst) const
bool swapSourceModifiers(MachineInstr &MI, MachineOperand &Src0, AMDGPU::OpName Src0OpName, MachineOperand &Src1, AMDGPU::OpName Src1OpName) const
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
static bool isDualSourceBlendEXP(const MachineInstr &MI)
bool hasUnwantedEffectsWhenEXECEmpty(const MachineInstr &MI) const
This function is used to determine if an instruction can be safely executed under EXEC = 0 without ha...
bool getConstValDefinedInReg(const MachineInstr &MI, const Register Reg, int64_t &ImmVal) const override
static bool isAtomic(const MachineInstr &MI)
bool canInsertSelect(const MachineBasicBlock &MBB, ArrayRef< MachineOperand > Cond, Register DstReg, Register TrueReg, Register FalseReg, int &CondCycles, int &TrueCycles, int &FalseCycles) const override
bool isLiteralOperandLegal(const MCInstrDesc &InstDesc, const MCOperandInfo &OpInfo) const
static bool isWWMRegSpillOpcode(uint32_t Opcode)
static bool sopkIsZext(unsigned Opcode)
static bool isSGPRSpill(const MachineInstr &MI)
static bool isWMMA(const MachineInstr &MI)
bool isMFMA(uint32_t Opcode) const
ArrayRef< std::pair< MachineMemOperand::Flags, const char * > > getSerializableMachineMemOperandTargetFlags() const override
bool mayReadEXEC(const MachineRegisterInfo &MRI, const MachineInstr &MI) const
Returns true if the instruction could potentially depend on the value of exec.
bool isSALU(uint32_t Opcode) const
bool isSMRD(uint32_t Opcode) const
bool isWMMA(uint32_t Opcode) const
void legalizeOperandsSMRD(MachineRegisterInfo &MRI, MachineInstr &MI) const
bool isVSAMPLE(uint32_t Opcode) const
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
std::pair< MachineInstr *, MachineInstr * > expandMovDPP64(MachineInstr &MI) const
static bool isLoadMonitor(unsigned Opc)
static bool isSOP1(const MachineInstr &MI)
static bool isSOPC(const MachineInstr &MI)
bool isSOPP(uint32_t Opcode) const
static bool isFLAT(const MachineInstr &MI)
const SIRegisterInfo & getRegisterInfo() const
bool isLDSDIR(uint32_t Opcode) const
bool isBarrier(unsigned Opcode) const
bool isAtomicNoRet(uint32_t Opcode) const
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx0, unsigned OpIdx1) const override
bool isVOP3(uint32_t Opcode) const
bool mayAccessLDSThroughFlat(const MachineInstr &MI, bool TgSplit) const
static bool hasIntClamp(const MachineInstr &MI)
static bool isSpill(const MCInstrDesc &Desc)
int pseudoToMCOpcode(int Opcode) const
Return a target-specific opcode if Opcode is a pseudo instruction.
const MCInstrDesc & getMCOpcodeFromPseudo(unsigned Opcode) const
Return the descriptor of the target-specific machine instruction that corresponds to the specified ps...
bool isImmOperandLegal(const MachineInstr &MI, unsigned OpNo, const MachineOperand &MO) const
bool isEXP(uint32_t Opcode) const
bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx, const MachineOperand &MO) const
static bool isScalarUnit(const MachineInstr &MI)
static bool usesVM_CNT(const MachineInstr &MI)
MachineInstr * createPHIDestinationCopy(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt, const DebugLoc &DL, Register Src, Register Dst) const override
static bool isFixedSize(const MachineInstr &MI)
bool isSafeToSink(MachineInstr &MI, MachineBasicBlock *SuccToSinkTo, MachineCycleInfo *CI) const override
static bool isPseudoScalarTrans(unsigned Opcode)
bool usesTENSOR_CNT(uint32_t Opcode) const
LLVM_READONLY int commuteOpcode(unsigned Opc) const
bool isScalarStore(uint32_t Opcode) const
static bool isBlockLoadStore(uint32_t Opcode)
ValueUniformity getValueUniformity(const MachineInstr &MI) const final
uint64_t getScratchRsrcWords23() const
bool usesASYNC_CNT(uint32_t Opcode) const
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, AMDGPU::OpName OperandName) const
Returns the operand named Op.
MachineInstr * convertToThreeAddress(MachineInstr &MI, LiveIntervals *LIS) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool isVMEM(uint32_t Opcode) const
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
bool isOperandLegal(const MachineInstr &MI, unsigned OpIdx, const MachineOperand *MO=nullptr) const
Check if MO is a legal operand if it was the OpIdx Operand for MI.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool allowNegativeFlatOffset(AMDGPU::FlatAddrSpace FlatVariant) const
Returns true if negative offsets are allowed for the given FlatVariant.
bool isBarrierStart(unsigned Opcode) const
void moveToVALUImpl(SIInstrWorklist &Worklist, MachineDominatorTree *MDT, MachineInstr &Inst, DenseMap< MachineInstr *, V2PhysSCopyInfo > &WaterFalls, DenseMap< MachineInstr *, bool > &V2SPhyCopiesToErase) const
static bool isLDSDMA(const MachineInstr &MI)
static bool isAtomicNoRet(const MachineInstr &MI)
static bool isVOP1(const MachineInstr &MI)
SIInstrInfo(const GCNSubtarget &ST)
std::optional< int64_t > getImmOrMaterializedImm(const MachineRegisterInfo &MRI, const MachineOperand &Op, MachineInstr **DefMI=nullptr) const
void insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, MachineBasicBlock &RestoreBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS) const override
bool isTRANS(uint32_t Opcode) const
bool isSDWA(uint32_t Opcode) const
bool hasAnyModifiersSet(const MachineInstr &MI) const
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
A vector that has set insertion semantics.
Definition SetVector.h:57
SlotIndexes pass.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
Target - Wrapper for Target specific information.
static constexpr TypeSize getZero()
Definition TypeSize.h:345
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
const uint64_t RSRC_DATA_FORMAT
LLVM_READONLY int32_t getSOPKOp(uint32_t Opcode)
LLVM_READONLY int32_t getCommuteRev(uint32_t Opcode)
LLVM_READONLY int32_t getCommuteOrig(uint32_t Opcode)
LLVM_READONLY int32_t getDPPOp32(uint32_t Opcode)
LLVM_READONLY int32_t getGlobalVaddrOp(uint32_t Opcode)
LLVM_READONLY int32_t getMFMAEarlyClobberOp(uint32_t Opcode)
const uint64_t RSRC_ELEMENT_SIZE_SHIFT
LLVM_READONLY int32_t getIfAddr64Inst(uint32_t Opcode)
Check if Opcode is an Addr64 opcode.
const uint64_t RSRC_TID_ENABLE
LLVM_READONLY int32_t getVOPe32(uint32_t Opcode)
LLVM_READONLY int32_t getSDWAOp(uint32_t Opcode)
LLVM_READONLY int32_t getVCMPXOpFromVCMP(uint32_t Opcode)
LLVM_READONLY int32_t getAGPRFormOp(uint32_t Opcode)
LLVM_READONLY int32_t getGlobalSaddrOp(uint32_t Opcode)
LLVM_READONLY int32_t getAddr64Inst(uint32_t Opcode)
LLVM_READONLY int32_t getVOPe64(uint32_t Opcode)
LLVM_READONLY int32_t getDPPOp64(uint32_t Opcode)
@ OPERAND_REG_IMM_INT64
Definition SIDefines.h:426
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:425
LLVM_READONLY int32_t getBasicFromSDWAOp(uint32_t Opcode)
LLVM_READONLY int32_t getFlatScratchInstSSfromSV(uint32_t Opcode)
const uint64_t RSRC_INDEX_STRIDE_SHIFT
bool getMAIIsDGEMM(unsigned Opc)
Returns true if MAI operation is a double precision GEMM.
LLVM_READONLY int32_t getFlatScratchInstSVfromSVS(uint32_t Opcode)
LLVM_READONLY int32_t getFlatScratchInstSVfromSS(uint32_t Opcode)
LLVM_READONLY int32_t getFlatScratchInstSTfromSS(uint32_t Opcode)
@ OPERAND_IMMEDIATE
Definition MCInstrDesc.h:61
constexpr bool isAtomicRet(const T &...O)
Definition SIDefines.h:361
constexpr bool isVOPC(const T &...O)
Definition SIDefines.h:233
constexpr bool isVOP3(const T &...O)
Definition SIDefines.h:236
constexpr bool isScalarStore(const T &...O)
Definition SIDefines.h:310
constexpr bool isVOP1(const T &...O)
Definition SIDefines.h:227
constexpr bool isFPAtomic(const T &...O)
Definition SIDefines.h:346
constexpr bool usesVM_CNT(const T &...O)
Definition SIDefines.h:382
constexpr bool usesTENSOR_CNT(const T &...O)
Definition SIDefines.h:307
constexpr bool isMAI(const T &...O)
Definition SIDefines.h:349
constexpr bool isVOP2(const T &...O)
Definition SIDefines.h:230
constexpr bool isSWMMAC(const T &...O)
Definition SIDefines.h:376
constexpr bool isTRANS(const T &...O)
Definition SIDefines.h:255
constexpr bool isSOP2(const T &...O)
Definition SIDefines.h:215
constexpr bool isFLAT(const T &...O)
Definition SIDefines.h:283
constexpr bool isVOP3P(const T &...O)
Definition SIDefines.h:239
constexpr bool usesFPDPRounding(const T &...O)
Definition SIDefines.h:343
constexpr bool isDisableWQM(const T &...O)
Definition SIDefines.h:301
constexpr bool hasIntClamp(const T &...O)
Definition SIDefines.h:328
constexpr bool isAtomicNoRet(const T &...O)
Definition SIDefines.h:358
constexpr bool isMTBUF(const T &...O)
Definition SIDefines.h:261
constexpr bool isVIMAGE(const T &...O)
Definition SIDefines.h:274
constexpr bool isSMRD(const T &...O)
Definition SIDefines.h:268
constexpr bool isFlatScratch(const T &...O)
Definition SIDefines.h:355
constexpr bool isSpill(const T &...O)
Definition SIDefines.h:289
constexpr bool isMIMG(const T &...O)
Definition SIDefines.h:271
constexpr bool isVMEM(const T &...O)
Definition SIDefines.h:401
constexpr bool hasFPClamp(const T &...O)
Definition SIDefines.h:325
constexpr bool isNeverUniform(const T &...O)
Definition SIDefines.h:370
constexpr bool isImage(const T &...O)
Definition SIDefines.h:397
constexpr bool isWMMA(const T &...O)
Definition SIDefines.h:364
constexpr bool isVALU(const T &...O)
Definition SIDefines.h:209
constexpr bool isWQM(const T &...O)
Definition SIDefines.h:298
constexpr bool hasClampLo(const T &...O)
Definition SIDefines.h:331
constexpr bool isGWS(const T &...O)
Definition SIDefines.h:373
constexpr bool isFlatGlobal(const T &...O)
Definition SIDefines.h:340
constexpr bool usesASYNC_CNT(const T &...O)
Definition SIDefines.h:316
constexpr bool isMUBUF(const T &...O)
Definition SIDefines.h:258
constexpr bool isSDWA(const T &...O)
Definition SIDefines.h:249
constexpr bool isTiedSourceNotRead(const T &...O)
Definition SIDefines.h:367
constexpr bool isEXP(const T &...O)
Definition SIDefines.h:280
constexpr bool usesLGKM_CNT(const T &...O)
Definition SIDefines.h:385
constexpr bool isSOPK(const T &...O)
Definition SIDefines.h:221
constexpr bool isSOPC(const T &...O)
Definition SIDefines.h:218
constexpr bool isSOPP(const T &...O)
Definition SIDefines.h:224
constexpr bool isDOT(const T &...O)
Definition SIDefines.h:352
constexpr bool isVINTRP(const T &...O)
Definition SIDefines.h:246
constexpr bool isVINTERP(const T &...O)
Definition SIDefines.h:295
constexpr bool isVSAMPLE(const T &...O)
Definition SIDefines.h:277
constexpr bool isDS(const T &...O)
Definition SIDefines.h:286
constexpr bool isAtomic(const T &...O)
Definition SIDefines.h:390
constexpr bool isLDSDIR(const T &...O)
Definition SIDefines.h:292
constexpr bool isSALU(const T &...O)
Definition SIDefines.h:206
constexpr bool isGather4(const T &...O)
Definition SIDefines.h:304
constexpr bool isPacked(const T &...O)
Definition SIDefines.h:337
constexpr bool hasClampHi(const T &...O)
Definition SIDefines.h:334
constexpr bool isDPP(const T &...O)
Definition SIDefines.h:252
constexpr bool isSOP1(const T &...O)
Definition SIDefines.h:212
constexpr bool isSegmentSpecificFLAT(const T &...O)
Definition SIDefines.h:393
constexpr bool isFixedSize(const T &...O)
Definition SIDefines.h:313
Offsets
Offsets in bytes from the start of the input buffer.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
TargetInstrInfo::RegSubRegPair getRegSubRegPair(const MachineOperand &O)
Create RegSubRegPair from a register MachineOperand.
bool execMayBeModifiedBeforeUse(const MachineRegisterInfo &MRI, Register VReg, const MachineInstr &DefMI, const MachineInstr &UseMI)
Return false if EXEC is not changed between the def of VReg at DefMI and the use at UseMI.
uint64_t getTSFlags(const MachineInstr &MI)
Op::Description Desc
TargetInstrInfo::RegSubRegPair getRegSequenceSubReg(MachineInstr &MI, unsigned SubReg)
Return the SubReg component from REG_SEQUENCE.
static const MachineMemOperand::Flags MONoClobber
Mark the MMO of a uniform load if there are no potentially clobbering stores on any path from the sta...
Definition SIInstrInfo.h:45
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
MachineInstr * getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P, const MachineRegisterInfo &MRI)
Return the defining instruction for a given reg:subreg pair skipping copy like instructions and subre...
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
static const MachineMemOperand::Flags MOCooperative
Mark the MMO of cooperative load/store atomics.
Definition SIInstrInfo.h:53
DWARFExpression::Operation Op
constexpr unsigned DefaultMemoryClusterDWordsLimit
Definition SIInstrInfo.h:41
static const MachineMemOperand::Flags MOLastUse
Mark the MMO of a load as the last use.
Definition SIInstrInfo.h:49
bool isOfRegClass(const TargetInstrInfo::RegSubRegPair &P, const TargetRegisterClass &TRC, MachineRegisterInfo &MRI)
Returns true if a reg:subreg pair P has a TRC class.
ValueUniformity
Enum describing how values behave with respect to uniformity and divergence, to answer the question: ...
Definition Uniformity.h:18
static const MachineMemOperand::Flags MOThreadPrivate
Mark the MMO of accesses to memory locations that are never written to by other threads.
Definition SIInstrInfo.h:64
bool execMayBeModifiedBeforeAnyUse(const MachineRegisterInfo &MRI, Register VReg, const MachineInstr &DefMI)
Return false if EXEC is not changed between the def of VReg at DefMI and all its uses.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Helper struct for the implementation of 3-address conversion to communicate updates made to instructi...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
Utility to store machine instructions worklist.
Definition SIInstrInfo.h:68
MachineInstr * top() const
Definition SIInstrInfo.h:73
bool isDeferred(MachineInstr *MI)
SetVector< MachineInstr * > & getDeferredList()
Definition SIInstrInfo.h:91
void insert(MachineInstr *MI)
A pair composed of a register and a sub-register index.
SmallVector< MachineOperand * > MOs
Definition SIInstrInfo.h:58
SmallVector< Register > SGPRs
Definition SIInstrInfo.h:60