LLVM 23.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"
24
25#define GET_INSTRINFO_HEADER
26#include "AMDGPUGenInstrInfo.inc"
27
28namespace llvm {
29
30class APInt;
31class GCNSubtarget;
32class LiveVariables;
33class MachineDominatorTree;
34class MachineRegisterInfo;
35class RegScavenger;
36class SIMachineFunctionInfo;
37class TargetRegisterClass;
38class ScheduleHazardRecognizer;
39
40constexpr unsigned DefaultMemoryClusterDWordsLimit = 8;
41
42/// Mark the MMO of a uniform load if there are no potentially clobbering stores
43/// on any path from the start of an entry function to this load.
46
47/// Mark the MMO of a load as the last use.
50
51/// Mark the MMO of cooperative load/store atomics.
54
56 // Operands that need to replaced by waterfall
58 // Target physical registers replacing the MOs
60};
61/// Mark the MMO of accesses to memory locations that are
62/// never written to by other threads.
65
66/// Utility to store machine instructions worklist.
68 SIInstrWorklist() = default;
69
70 void insert(MachineInstr *MI);
71
72 MachineInstr *top() const {
73 const auto *iter = InstrList.begin();
74 return *iter;
75 }
76
77 void erase_top() {
78 const auto *iter = InstrList.begin();
79 InstrList.erase(iter);
80 }
81
82 bool empty() const { return InstrList.empty(); }
83
84 void clear() {
85 InstrList.clear();
86 DeferredList.clear();
87 }
88
90
91 SetVector<MachineInstr *> &getDeferredList() { return DeferredList; }
92
93private:
94 /// InstrList contains the MachineInstrs.
96 /// Deferred instructions are specific MachineInstr
97 /// that will be added by insert method.
98 SetVector<MachineInstr *> DeferredList;
99};
100
101class SIInstrInfo final : public AMDGPUGenInstrInfo {
102 struct ThreeAddressUpdates;
103
104private:
105 const SIRegisterInfo RI;
106 const GCNSubtarget &ST;
107 TargetSchedModel SchedModel;
108 mutable std::unique_ptr<AMDGPUMIRFormatter> Formatter;
109
110 // The inverse predicate should have the negative value.
111 enum BranchPredicate {
112 INVALID_BR = 0,
113 SCC_TRUE = 1,
114 SCC_FALSE = -1,
115 VCCNZ = 2,
116 VCCZ = -2,
117 EXECNZ = -3,
118 EXECZ = 3
119 };
120
121 using SetVectorType = SmallSetVector<MachineInstr *, 32>;
122
123 static unsigned getBranchOpcode(BranchPredicate Cond);
124 static BranchPredicate getBranchPredicate(unsigned Opcode);
125
126public:
129 const MachineOperand &SuperReg,
130 const TargetRegisterClass *SuperRC,
131 unsigned SubIdx,
132 const TargetRegisterClass *SubRC) const;
135 const MachineOperand &SuperReg, const TargetRegisterClass *SuperRC,
136 unsigned SubIdx, const TargetRegisterClass *SubRC) const;
137
138private:
139 bool optimizeSCC(MachineInstr *SCCValid, MachineInstr *SCCRedefine,
140 bool NeedInversion) const;
141
142 bool invertSCCUse(MachineInstr *SCCDef) const;
143
144 void swapOperands(MachineInstr &Inst) const;
145
146 std::pair<bool, MachineBasicBlock *>
147 moveScalarAddSub(SIInstrWorklist &Worklist, MachineInstr &Inst,
148 MachineDominatorTree *MDT = nullptr) const;
149
150 void lowerSelect(SIInstrWorklist &Worklist, MachineInstr &Inst,
151 MachineDominatorTree *MDT = nullptr) const;
152
153 void lowerScalarAbs(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
154
155 void lowerScalarAbsDiff(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
156
157 void lowerScalarXnor(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
158
159 void splitScalarNotBinop(SIInstrWorklist &Worklist, MachineInstr &Inst,
160 unsigned Opcode) const;
161
162 void splitScalarBinOpN2(SIInstrWorklist &Worklist, MachineInstr &Inst,
163 unsigned Opcode) const;
164
165 void splitScalar64BitUnaryOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
166 unsigned Opcode, bool Swap = false) const;
167
168 void splitScalar64BitBinaryOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
169 unsigned Opcode,
170 MachineDominatorTree *MDT = nullptr) const;
171
172 void splitScalarSMulU64(SIInstrWorklist &Worklist, MachineInstr &Inst,
173 MachineDominatorTree *MDT) const;
174
175 void splitScalarSMulPseudo(SIInstrWorklist &Worklist, MachineInstr &Inst,
176 MachineDominatorTree *MDT) const;
177
178 void splitScalar64BitXnor(SIInstrWorklist &Worklist, MachineInstr &Inst,
179 MachineDominatorTree *MDT = nullptr) const;
180
181 void splitScalar64BitBCNT(SIInstrWorklist &Worklist,
182 MachineInstr &Inst) const;
183 void splitScalar64BitBFE(SIInstrWorklist &Worklist, MachineInstr &Inst) const;
184 void splitScalar64BitCountOp(SIInstrWorklist &Worklist, MachineInstr &Inst,
185 unsigned Opcode,
186 MachineDominatorTree *MDT = nullptr) const;
187 void movePackToVALU(SIInstrWorklist &Worklist, MachineRegisterInfo &MRI,
188 MachineInstr &Inst) const;
189
190 void addUsersToMoveToVALUWorklist(Register Reg, MachineRegisterInfo &MRI,
191 SIInstrWorklist &Worklist) const;
192
193 void addSCCDefUsersToVALUWorklist(const MachineOperand &Op,
194 MachineInstr &SCCDefInst,
195 SIInstrWorklist &Worklist,
196 Register NewCond = Register()) const;
197 void addSCCDefsToVALUWorklist(MachineInstr *SCCUseInst,
198 SIInstrWorklist &Worklist) const;
199
200 const TargetRegisterClass *
201 getDestEquivalentVGPRClass(const MachineInstr &Inst) const;
202
203 bool checkInstOffsetsDoNotOverlap(const MachineInstr &MIa,
204 const MachineInstr &MIb) const;
205
206 Register findUsedSGPR(const MachineInstr &MI, int OpIndices[3]) const;
207
208 bool verifyCopy(const MachineInstr &MI, const MachineRegisterInfo &MRI,
209 StringRef &ErrInfo) const;
210
211 bool resultDependsOnExec(const MachineInstr &MI) const;
212
213 MachineInstr *convertToThreeAddressImpl(MachineInstr &MI,
214 ThreeAddressUpdates &Updates) const;
215
216protected:
217 /// If the specific machine instruction is a instruction that moves/copies
218 /// value from one register to another register return destination and source
219 /// registers as machine operands.
220 std::optional<DestSourcePair>
221 isCopyInstrImpl(const MachineInstr &MI) const override;
222
224 AMDGPU::OpName Src0OpName, MachineOperand &Src1,
225 AMDGPU::OpName Src1OpName) const;
226 bool isLegalToSwap(const MachineInstr &MI, unsigned fromIdx,
227 unsigned toIdx) const;
229 unsigned OpIdx0,
230 unsigned OpIdx1) const override;
231
232public:
234 MO_MASK = 0xf,
235
237 // MO_GOTPCREL -> symbol@GOTPCREL -> R_AMDGPU_GOTPCREL.
239 // MO_GOTPCREL32_LO -> symbol@gotpcrel32@lo -> R_AMDGPU_GOTPCREL32_LO.
242 // MO_GOTPCREL32_HI -> symbol@gotpcrel32@hi -> R_AMDGPU_GOTPCREL32_HI.
244 // MO_GOTPCREL64 -> symbol@GOTPCREL -> R_AMDGPU_GOTPCREL.
246 // MO_REL32_LO -> symbol@rel32@lo -> R_AMDGPU_REL32_LO.
249 // MO_REL32_HI -> symbol@rel32@hi -> R_AMDGPU_REL32_HI.
252
254
258 };
259
260 explicit SIInstrInfo(const GCNSubtarget &ST);
261
263 return RI;
264 }
265
266 const GCNSubtarget &getSubtarget() const {
267 return ST;
268 }
269
270 bool isReMaterializableImpl(const MachineInstr &MI) const override;
271
272 bool isIgnorableUse(const MachineOperand &MO) const override;
273
274 bool isSafeToSink(MachineInstr &MI, MachineBasicBlock *SuccToSinkTo,
275 MachineCycleInfo *CI) const override;
276
277 bool areLoadsFromSameBasePtr(SDNode *Load0, SDNode *Load1, int64_t &Offset0,
278 int64_t &Offset1) const override;
279
280 bool isGlobalMemoryObject(const MachineInstr *MI) const override;
281
283 const MachineInstr &LdSt,
285 bool &OffsetIsScalable, LocationSize &Width,
286 const TargetRegisterInfo *TRI) const final;
287
289 int64_t Offset1, bool OffsetIsScalable1,
291 int64_t Offset2, bool OffsetIsScalable2,
292 unsigned ClusterSize,
293 unsigned NumBytes) const override;
294
295 bool shouldScheduleLoadsNear(SDNode *Load0, SDNode *Load1, int64_t Offset0,
296 int64_t Offset1, unsigned NumLoads) const override;
297
299 const DebugLoc &DL, Register DestReg, Register SrcReg,
300 bool KillSrc, bool RenamableDest = false,
301 bool RenamableSrc = false) const override;
302
304 unsigned Size) const;
305
308 Register SrcReg, int Value) const;
309
312 Register SrcReg, int Value) const;
313
315 int64_t &ImmVal) const override;
316
317 std::optional<int64_t> getImmOrMaterializedImm(MachineOperand &Op) const;
318
320 const TargetRegisterClass *RC,
321 unsigned Size,
322 const SIMachineFunctionInfo &MFI) const;
323 unsigned
325 unsigned Size,
326 const SIMachineFunctionInfo &MFI) const;
327
330 bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
331 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
332
335 int FrameIndex, const TargetRegisterClass *RC, Register VReg,
336 unsigned SubReg = 0,
337 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
338
339 bool expandPostRAPseudo(MachineInstr &MI) const override;
340
341 void
343 Register DestReg, unsigned SubIdx, const MachineInstr &Orig,
344 LaneBitmask UsedLanes = LaneBitmask::getAll()) const override;
345
346 // Splits a V_MOV_B64_DPP_PSEUDO opcode into a pair of v_mov_b32_dpp
347 // instructions. Returns a pair of generated instructions.
348 // Can split either post-RA with physical registers or pre-RA with
349 // virtual registers. In latter case IR needs to be in SSA form and
350 // and a REG_SEQUENCE is produced to define original register.
351 std::pair<MachineInstr*, MachineInstr*>
353
354 // Returns an opcode that can be used to move a value to a \p DstRC
355 // register. If there is no hardware instruction that can store to \p
356 // DstRC, then AMDGPU::COPY is returned.
357 unsigned getMovOpcode(const TargetRegisterClass *DstRC) const;
358
359 const MCInstrDesc &getIndirectRegWriteMovRelPseudo(unsigned VecSize,
360 unsigned EltSize,
361 bool IsSGPR) const;
362
363 const MCInstrDesc &getIndirectGPRIDXPseudo(unsigned VecSize,
364 bool IsIndirectSrc) const;
366 int commuteOpcode(unsigned Opc) const;
367
369 inline int commuteOpcode(const MachineInstr &MI) const {
370 return commuteOpcode(MI.getOpcode());
371 }
372
373 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx0,
374 unsigned &SrcOpIdx1) const override;
375
376 bool findCommutedOpIndices(const MCInstrDesc &Desc, unsigned &SrcOpIdx0,
377 unsigned &SrcOpIdx1) const;
378
379 bool isBranchOffsetInRange(unsigned BranchOpc,
380 int64_t BrOffset) const override;
381
382 MachineBasicBlock *getBranchDestBlock(const MachineInstr &MI) const override;
383
384 /// Return whether the block terminate with divergent branch.
385 /// Note this only work before lowering the pseudo control flow instructions.
386 bool hasDivergentBranch(const MachineBasicBlock *MBB) const;
387
389 MachineBasicBlock &NewDestBB,
390 MachineBasicBlock &RestoreBB, const DebugLoc &DL,
391 int64_t BrOffset, RegScavenger *RS) const override;
392
396 MachineBasicBlock *&FBB,
398 bool AllowModify) const;
399
401 MachineBasicBlock *&FBB,
403 bool AllowModify = false) const override;
404
406 int *BytesRemoved = nullptr) const override;
407
410 const DebugLoc &DL,
411 int *BytesAdded = nullptr) const override;
412
414 SmallVectorImpl<MachineOperand> &Cond) const override;
415
418 Register TrueReg, Register FalseReg, int &CondCycles,
419 int &TrueCycles, int &FalseCycles) const override;
420
424 Register TrueReg, Register FalseReg) const override;
425
429 Register TrueReg, Register FalseReg) const;
430
431 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
432 Register &SrcReg2, int64_t &CmpMask,
433 int64_t &CmpValue) const override;
434
435 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
436 Register SrcReg2, int64_t CmpMask, int64_t CmpValue,
437 const MachineRegisterInfo *MRI) const override;
438
439 bool
441 const MachineInstr &MIb) const override;
442
443 static bool isFoldableCopy(const MachineInstr &MI);
444 static unsigned getFoldableCopySrcIdx(const MachineInstr &MI);
445
446 void removeModOperands(MachineInstr &MI) const;
447
449 const MCInstrDesc &NewDesc) const;
450
451 /// Return the extracted immediate value in a subregister use from a constant
452 /// materialized in a super register.
453 ///
454 /// e.g. %imm = S_MOV_B64 K[0:63]
455 /// USE %imm.sub1
456 /// This will return K[32:63]
457 static std::optional<int64_t> extractSubregFromImm(int64_t ImmVal,
458 unsigned SubRegIndex);
459
461 MachineRegisterInfo *MRI) const final;
462
463 unsigned getMachineCSELookAheadLimit() const override { return 500; }
464
466 LiveIntervals *LIS) const override;
467
469 const MachineBasicBlock *MBB,
470 const MachineFunction &MF) const override;
471
472 static bool isSALU(const MachineInstr &MI) {
473 return MI.getDesc().TSFlags & SIInstrFlags::SALU;
474 }
475
476 bool isSALU(uint32_t Opcode) const {
477 return get(Opcode).TSFlags & SIInstrFlags::SALU;
478 }
479
480 static bool isVALU(const MachineInstr &MI) {
481 return MI.getDesc().TSFlags & SIInstrFlags::VALU;
482 }
483
484 bool isVALU(uint32_t Opcode) const {
485 return get(Opcode).TSFlags & SIInstrFlags::VALU;
486 }
487
488 static bool isImage(const MachineInstr &MI) {
489 return isMIMG(MI) || isVSAMPLE(MI) || isVIMAGE(MI);
490 }
491
492 bool isImage(uint32_t Opcode) const {
493 return isMIMG(Opcode) || isVSAMPLE(Opcode) || isVIMAGE(Opcode);
494 }
495
496 static bool isVMEM(const MachineInstr &MI) {
497 return isMUBUF(MI) || isMTBUF(MI) || isImage(MI) || isFLAT(MI);
498 }
499
500 bool isVMEM(uint32_t Opcode) const {
501 return isMUBUF(Opcode) || isMTBUF(Opcode) || isImage(Opcode) ||
502 isFLAT(Opcode);
503 }
504
505 static bool isSOP1(const MachineInstr &MI) {
506 return MI.getDesc().TSFlags & SIInstrFlags::SOP1;
507 }
508
509 bool isSOP1(uint32_t Opcode) const {
510 return get(Opcode).TSFlags & SIInstrFlags::SOP1;
511 }
512
513 static bool isSOP2(const MachineInstr &MI) {
514 return MI.getDesc().TSFlags & SIInstrFlags::SOP2;
515 }
516
517 bool isSOP2(uint32_t Opcode) const {
518 return get(Opcode).TSFlags & SIInstrFlags::SOP2;
519 }
520
521 static bool isSOPC(const MachineInstr &MI) {
522 return MI.getDesc().TSFlags & SIInstrFlags::SOPC;
523 }
524
525 bool isSOPC(uint32_t Opcode) const {
526 return get(Opcode).TSFlags & SIInstrFlags::SOPC;
527 }
528
529 static bool isSOPK(const MachineInstr &MI) {
530 return MI.getDesc().TSFlags & SIInstrFlags::SOPK;
531 }
532
533 bool isSOPK(uint32_t Opcode) const {
534 return get(Opcode).TSFlags & SIInstrFlags::SOPK;
535 }
536
537 static bool isSOPP(const MachineInstr &MI) {
538 return MI.getDesc().TSFlags & SIInstrFlags::SOPP;
539 }
540
541 bool isSOPP(uint32_t Opcode) const {
542 return get(Opcode).TSFlags & SIInstrFlags::SOPP;
543 }
544
545 static bool isPacked(const MachineInstr &MI) {
546 return MI.getDesc().TSFlags & SIInstrFlags::IsPacked;
547 }
548
549 bool isPacked(uint32_t Opcode) const {
550 return get(Opcode).TSFlags & SIInstrFlags::IsPacked;
551 }
552
553 static bool isVOP1(const MachineInstr &MI) {
554 return MI.getDesc().TSFlags & SIInstrFlags::VOP1;
555 }
556
557 bool isVOP1(uint32_t Opcode) const {
558 return get(Opcode).TSFlags & SIInstrFlags::VOP1;
559 }
560
561 static bool isVOP2(const MachineInstr &MI) {
562 return MI.getDesc().TSFlags & SIInstrFlags::VOP2;
563 }
564
565 bool isVOP2(uint32_t Opcode) const {
566 return get(Opcode).TSFlags & SIInstrFlags::VOP2;
567 }
568
569 static bool isVOP3(const MCInstrDesc &Desc) {
570 return Desc.TSFlags & SIInstrFlags::VOP3;
571 }
572
573 static bool isVOP3(const MachineInstr &MI) { return isVOP3(MI.getDesc()); }
574
575 bool isVOP3(uint32_t Opcode) const { return isVOP3(get(Opcode)); }
576
577 static bool isSDWA(const MachineInstr &MI) {
578 return MI.getDesc().TSFlags & SIInstrFlags::SDWA;
579 }
580
581 bool isSDWA(uint32_t Opcode) const {
582 return get(Opcode).TSFlags & SIInstrFlags::SDWA;
583 }
584
585 static bool isVOPC(const MachineInstr &MI) {
586 return MI.getDesc().TSFlags & SIInstrFlags::VOPC;
587 }
588
589 bool isVOPC(uint32_t Opcode) const {
590 return get(Opcode).TSFlags & SIInstrFlags::VOPC;
591 }
592
593 static bool isMUBUF(const MachineInstr &MI) {
594 return MI.getDesc().TSFlags & SIInstrFlags::MUBUF;
595 }
596
597 bool isMUBUF(uint32_t Opcode) const {
598 return get(Opcode).TSFlags & SIInstrFlags::MUBUF;
599 }
600
601 static bool isMTBUF(const MachineInstr &MI) {
602 return MI.getDesc().TSFlags & SIInstrFlags::MTBUF;
603 }
604
605 bool isMTBUF(uint32_t Opcode) const {
606 return get(Opcode).TSFlags & SIInstrFlags::MTBUF;
607 }
608
609 static bool isBUF(const MachineInstr &MI) {
610 return isMUBUF(MI) || isMTBUF(MI);
611 }
612
613 static bool isSMRD(const MachineInstr &MI) {
614 return MI.getDesc().TSFlags & SIInstrFlags::SMRD;
615 }
616
617 bool isSMRD(uint32_t Opcode) const {
618 return get(Opcode).TSFlags & SIInstrFlags::SMRD;
619 }
620
621 bool isBufferSMRD(const MachineInstr &MI) const;
622
623 static bool isDS(const MachineInstr &MI) {
624 return MI.getDesc().TSFlags & SIInstrFlags::DS;
625 }
626
627 bool isDS(uint32_t Opcode) const {
628 return get(Opcode).TSFlags & SIInstrFlags::DS;
629 }
630
631 static bool isLDSDMA(const MachineInstr &MI) {
632 return (isVALU(MI) && (isMUBUF(MI) || isFLAT(MI))) ||
633 (MI.getDesc().TSFlags & SIInstrFlags::TENSOR_CNT);
634 }
635
636 bool isLDSDMA(uint32_t Opcode) {
637 return (isVALU(Opcode) && (isMUBUF(Opcode) || isFLAT(Opcode))) ||
638 (get(Opcode).TSFlags & SIInstrFlags::TENSOR_CNT);
639 }
640
641 static bool isGWS(const MachineInstr &MI) {
642 return MI.getDesc().TSFlags & SIInstrFlags::GWS;
643 }
644
645 bool isGWS(uint32_t Opcode) const {
646 return get(Opcode).TSFlags & SIInstrFlags::GWS;
647 }
648
649 bool isAlwaysGDS(uint32_t Opcode) const;
650
651 static bool isMIMG(const MachineInstr &MI) {
652 return MI.getDesc().TSFlags & SIInstrFlags::MIMG;
653 }
654
655 bool isMIMG(uint32_t Opcode) const {
656 return get(Opcode).TSFlags & SIInstrFlags::MIMG;
657 }
658
659 static bool isVIMAGE(const MachineInstr &MI) {
660 return MI.getDesc().TSFlags & SIInstrFlags::VIMAGE;
661 }
662
663 bool isVIMAGE(uint32_t Opcode) const {
664 return get(Opcode).TSFlags & SIInstrFlags::VIMAGE;
665 }
666
667 static bool isVSAMPLE(const MachineInstr &MI) {
668 return MI.getDesc().TSFlags & SIInstrFlags::VSAMPLE;
669 }
670
671 bool isVSAMPLE(uint32_t Opcode) const {
672 return get(Opcode).TSFlags & SIInstrFlags::VSAMPLE;
673 }
674
675 static bool isGather4(const MachineInstr &MI) {
676 return MI.getDesc().TSFlags & SIInstrFlags::Gather4;
677 }
678
679 bool isGather4(uint32_t Opcode) const {
680 return get(Opcode).TSFlags & SIInstrFlags::Gather4;
681 }
682
683 static bool isFLAT(const MachineInstr &MI) {
684 return MI.getDesc().TSFlags & SIInstrFlags::FLAT;
685 }
686
687 // Is a FLAT encoded instruction which accesses a specific segment,
688 // i.e. global_* or scratch_*.
690 auto Flags = MI.getDesc().TSFlags;
692 }
693
694 bool isSegmentSpecificFLAT(uint32_t Opcode) const {
695 auto Flags = get(Opcode).TSFlags;
697 }
698
699 static bool isFLATGlobal(const MachineInstr &MI) {
700 return MI.getDesc().TSFlags & SIInstrFlags::FlatGlobal;
701 }
702
703 bool isFLATGlobal(uint32_t Opcode) const {
704 return get(Opcode).TSFlags & SIInstrFlags::FlatGlobal;
705 }
706
707 static bool isFLATScratch(const MachineInstr &MI) {
708 return MI.getDesc().TSFlags & SIInstrFlags::FlatScratch;
709 }
710
711 bool isFLATScratch(uint32_t Opcode) const {
712 return get(Opcode).TSFlags & SIInstrFlags::FlatScratch;
713 }
714
715 // Any FLAT encoded instruction, including global_* and scratch_*.
716 bool isFLAT(uint32_t Opcode) const {
717 return get(Opcode).TSFlags & SIInstrFlags::FLAT;
718 }
719
720 /// \returns true for SCRATCH_ instructions, or FLAT/BUF instructions unless
721 /// the MMOs do not include scratch.
722 /// Conservatively correct; will return true if \p MI cannot be proven
723 /// to not hit scratch.
724 bool mayAccessScratch(const MachineInstr &MI) const;
725
726 /// \returns true for FLAT instructions that can access VMEM.
727 bool mayAccessVMEMThroughFlat(const MachineInstr &MI) const;
728
729 /// \returns true for FLAT instructions that can access LDS.
730 bool mayAccessLDSThroughFlat(const MachineInstr &MI) const;
731
732 static bool isBlockLoadStore(uint32_t Opcode) {
733 switch (Opcode) {
734 case AMDGPU::SI_BLOCK_SPILL_V1024_SAVE:
735 case AMDGPU::SI_BLOCK_SPILL_V1024_RESTORE:
736 case AMDGPU::SCRATCH_STORE_BLOCK_SADDR:
737 case AMDGPU::SCRATCH_LOAD_BLOCK_SADDR:
738 case AMDGPU::SCRATCH_STORE_BLOCK_SVS:
739 case AMDGPU::SCRATCH_LOAD_BLOCK_SVS:
740 return true;
741 default:
742 return false;
743 }
744 }
745
747 switch (MI.getOpcode()) {
748 case AMDGPU::S_ABSDIFF_I32:
749 case AMDGPU::S_ABS_I32:
750 case AMDGPU::S_AND_B32:
751 case AMDGPU::S_AND_B64:
752 case AMDGPU::S_ANDN2_B32:
753 case AMDGPU::S_ANDN2_B64:
754 case AMDGPU::S_ASHR_I32:
755 case AMDGPU::S_ASHR_I64:
756 case AMDGPU::S_BCNT0_I32_B32:
757 case AMDGPU::S_BCNT0_I32_B64:
758 case AMDGPU::S_BCNT1_I32_B32:
759 case AMDGPU::S_BCNT1_I32_B64:
760 case AMDGPU::S_BFE_I32:
761 case AMDGPU::S_BFE_I64:
762 case AMDGPU::S_BFE_U32:
763 case AMDGPU::S_BFE_U64:
764 case AMDGPU::S_LSHL_B32:
765 case AMDGPU::S_LSHL_B64:
766 case AMDGPU::S_LSHR_B32:
767 case AMDGPU::S_LSHR_B64:
768 case AMDGPU::S_NAND_B32:
769 case AMDGPU::S_NAND_B64:
770 case AMDGPU::S_NOR_B32:
771 case AMDGPU::S_NOR_B64:
772 case AMDGPU::S_NOT_B32:
773 case AMDGPU::S_NOT_B64:
774 case AMDGPU::S_OR_B32:
775 case AMDGPU::S_OR_B64:
776 case AMDGPU::S_ORN2_B32:
777 case AMDGPU::S_ORN2_B64:
778 case AMDGPU::S_QUADMASK_B32:
779 case AMDGPU::S_QUADMASK_B64:
780 case AMDGPU::S_WQM_B32:
781 case AMDGPU::S_WQM_B64:
782 case AMDGPU::S_XNOR_B32:
783 case AMDGPU::S_XNOR_B64:
784 case AMDGPU::S_XOR_B32:
785 case AMDGPU::S_XOR_B64:
786 return true;
787 default:
788 return false;
789 }
790 }
791
792 static bool isEXP(const MachineInstr &MI) {
793 return MI.getDesc().TSFlags & SIInstrFlags::EXP;
794 }
795
797 if (!isEXP(MI))
798 return false;
799 unsigned Target = MI.getOperand(0).getImm();
802 }
803
804 bool isEXP(uint32_t Opcode) const {
805 return get(Opcode).TSFlags & SIInstrFlags::EXP;
806 }
807
808 static bool isAtomicNoRet(const MachineInstr &MI) {
809 return MI.getDesc().TSFlags & SIInstrFlags::IsAtomicNoRet;
810 }
811
812 bool isAtomicNoRet(uint32_t Opcode) const {
813 return get(Opcode).TSFlags & SIInstrFlags::IsAtomicNoRet;
814 }
815
816 static bool isAtomicRet(const MachineInstr &MI) {
817 return MI.getDesc().TSFlags & SIInstrFlags::IsAtomicRet;
818 }
819
820 bool isAtomicRet(uint32_t Opcode) const {
821 return get(Opcode).TSFlags & SIInstrFlags::IsAtomicRet;
822 }
823
824 static bool isAtomic(const MachineInstr &MI) {
825 return MI.getDesc().TSFlags & (SIInstrFlags::IsAtomicRet |
827 }
828
829 bool isAtomic(uint32_t Opcode) const {
830 return get(Opcode).TSFlags & (SIInstrFlags::IsAtomicRet |
832 }
833
835 unsigned Opc = MI.getOpcode();
836 // Exclude instructions that read FROM LDS (not write to it)
837 return isLDSDMA(MI) && Opc != AMDGPU::BUFFER_STORE_LDS_DWORD &&
838 Opc != AMDGPU::TENSOR_STORE_FROM_LDS_d2 &&
839 Opc != AMDGPU::TENSOR_STORE_FROM_LDS_d4;
840 }
841
842 static bool isSBarrierSCCWrite(unsigned Opcode) {
843 return Opcode == AMDGPU::S_BARRIER_LEAVE ||
844 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM ||
845 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_M0;
846 }
847
848 static bool isCBranchVCCZRead(const MachineInstr &MI) {
849 unsigned Opc = MI.getOpcode();
850 return (Opc == AMDGPU::S_CBRANCH_VCCNZ || Opc == AMDGPU::S_CBRANCH_VCCZ) &&
851 !MI.getOperand(1).isUndef();
852 }
853
854 static bool isWQM(const MachineInstr &MI) {
855 return MI.getDesc().TSFlags & SIInstrFlags::WQM;
856 }
857
858 bool isWQM(uint32_t Opcode) const {
859 return get(Opcode).TSFlags & SIInstrFlags::WQM;
860 }
861
862 static bool isDisableWQM(const MachineInstr &MI) {
863 return MI.getDesc().TSFlags & SIInstrFlags::DisableWQM;
864 }
865
866 bool isDisableWQM(uint32_t Opcode) const {
867 return get(Opcode).TSFlags & SIInstrFlags::DisableWQM;
868 }
869
870 // SI_SPILL_S32_TO_VGPR and SI_RESTORE_S32_FROM_VGPR form a special case of
871 // SGPRs spilling to VGPRs which are SGPR spills but from VALU instructions
872 // therefore we need an explicit check for them since just checking if the
873 // Spill bit is set and what instruction type it came from misclassifies
874 // them.
875 static bool isVGPRSpill(const MachineInstr &MI) {
876 return MI.getOpcode() != AMDGPU::SI_SPILL_S32_TO_VGPR &&
877 MI.getOpcode() != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
878 (isSpill(MI) && isVALU(MI));
879 }
880
881 bool isVGPRSpill(uint32_t Opcode) const {
882 return Opcode != AMDGPU::SI_SPILL_S32_TO_VGPR &&
883 Opcode != AMDGPU::SI_RESTORE_S32_FROM_VGPR &&
884 (isSpill(Opcode) && isVALU(Opcode));
885 }
886
887 static bool isSGPRSpill(const MachineInstr &MI) {
888 return MI.getOpcode() == AMDGPU::SI_SPILL_S32_TO_VGPR ||
889 MI.getOpcode() == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
890 (isSpill(MI) && isSALU(MI));
891 }
892
893 bool isSGPRSpill(uint32_t Opcode) const {
894 return Opcode == AMDGPU::SI_SPILL_S32_TO_VGPR ||
895 Opcode == AMDGPU::SI_RESTORE_S32_FROM_VGPR ||
896 (isSpill(Opcode) && isSALU(Opcode));
897 }
898
899 bool isSpill(uint32_t Opcode) const {
900 return get(Opcode).TSFlags & SIInstrFlags::Spill;
901 }
902
903 static bool isSpill(const MCInstrDesc &Desc) {
904 return Desc.TSFlags & SIInstrFlags::Spill;
905 }
906
907 static bool isSpill(const MachineInstr &MI) { return isSpill(MI.getDesc()); }
908
909 static bool isWWMRegSpillOpcode(uint32_t Opcode) {
910 return Opcode == AMDGPU::SI_SPILL_WWM_V32_SAVE ||
911 Opcode == AMDGPU::SI_SPILL_WWM_AV32_SAVE ||
912 Opcode == AMDGPU::SI_SPILL_WWM_V32_RESTORE ||
913 Opcode == AMDGPU::SI_SPILL_WWM_AV32_RESTORE;
914 }
915
916 static bool isChainCallOpcode(uint64_t Opcode) {
917 return Opcode == AMDGPU::SI_CS_CHAIN_TC_W32 ||
918 Opcode == AMDGPU::SI_CS_CHAIN_TC_W64;
919 }
920
921 static bool isDPP(const MachineInstr &MI) {
922 return MI.getDesc().TSFlags & SIInstrFlags::DPP;
923 }
924
925 bool isDPP(uint32_t Opcode) const {
926 return get(Opcode).TSFlags & SIInstrFlags::DPP;
927 }
928
929 static bool isTRANS(const MachineInstr &MI) {
930 return MI.getDesc().TSFlags & SIInstrFlags::TRANS;
931 }
932
933 bool isTRANS(uint32_t Opcode) const {
934 return get(Opcode).TSFlags & SIInstrFlags::TRANS;
935 }
936
937 static bool isVOP3P(const MachineInstr &MI) {
938 return MI.getDesc().TSFlags & SIInstrFlags::VOP3P;
939 }
940
941 bool isVOP3P(uint32_t Opcode) const {
942 return get(Opcode).TSFlags & SIInstrFlags::VOP3P;
943 }
944
945 bool isVOP3PMix(const MachineInstr &MI) const {
946 return isVOP3PMix(MI.getOpcode());
947 }
948
949 bool isVOP3PMix(uint16_t Opcode) const {
950 switch (Opcode) {
951 case AMDGPU::V_FMA_MIXHI_F16:
952 case AMDGPU::V_FMA_MIXLO_F16:
953 case AMDGPU::V_FMA_MIX_F32:
954 case AMDGPU::V_MAD_MIXHI_F16:
955 case AMDGPU::V_MAD_MIXLO_F16:
956 case AMDGPU::V_MAD_MIX_F32:
957 return true;
958 default:
959 return false;
960 }
961 }
962
963 static bool isVINTRP(const MachineInstr &MI) {
964 return MI.getDesc().TSFlags & SIInstrFlags::VINTRP;
965 }
966
967 bool isVINTRP(uint32_t Opcode) const {
968 return get(Opcode).TSFlags & SIInstrFlags::VINTRP;
969 }
970
971 static bool isMAI(const MCInstrDesc &Desc) {
972 return Desc.TSFlags & SIInstrFlags::IsMAI;
973 }
974
975 static bool isMAI(const MachineInstr &MI) { return isMAI(MI.getDesc()); }
976
977 bool isMAI(uint32_t Opcode) const { return isMAI(get(Opcode)); }
978
979 static bool isMFMA(const MachineInstr &MI) {
980 return isMAI(MI) && MI.getOpcode() != AMDGPU::V_ACCVGPR_WRITE_B32_e64 &&
981 MI.getOpcode() != AMDGPU::V_ACCVGPR_READ_B32_e64;
982 }
983
984 bool isMFMA(uint32_t Opcode) const {
985 return isMAI(Opcode) && Opcode != AMDGPU::V_ACCVGPR_WRITE_B32_e64 &&
986 Opcode != AMDGPU::V_ACCVGPR_READ_B32_e64;
987 }
988
989 static bool isDOT(const MachineInstr &MI) {
990 return MI.getDesc().TSFlags & SIInstrFlags::IsDOT;
991 }
992
993 static bool isWMMA(const MachineInstr &MI) {
994 return MI.getDesc().TSFlags & SIInstrFlags::IsWMMA;
995 }
996
997 bool isWMMA(uint32_t Opcode) const {
998 return get(Opcode).TSFlags & SIInstrFlags::IsWMMA;
999 }
1000
1001 static bool isMFMAorWMMA(const MachineInstr &MI) {
1002 return isMFMA(MI) || isWMMA(MI) || isSWMMAC(MI);
1003 }
1004
1005 bool isMFMAorWMMA(uint32_t Opcode) const {
1006 return isMFMA(Opcode) || isWMMA(Opcode) || isSWMMAC(Opcode);
1007 }
1008
1009 static bool isSWMMAC(const MachineInstr &MI) {
1010 return MI.getDesc().TSFlags & SIInstrFlags::IsSWMMAC;
1011 }
1012
1013 bool isSWMMAC(uint32_t Opcode) const {
1014 return get(Opcode).TSFlags & SIInstrFlags::IsSWMMAC;
1015 }
1016
1017 bool isDOT(uint32_t Opcode) const {
1018 return get(Opcode).TSFlags & SIInstrFlags::IsDOT;
1019 }
1020
1021 bool isXDLWMMA(const MachineInstr &MI) const;
1022
1023 bool isXDL(const MachineInstr &MI) const;
1024
1025 static bool isDGEMM(unsigned Opcode) { return AMDGPU::getMAIIsDGEMM(Opcode); }
1026
1027 static bool isLDSDIR(const MachineInstr &MI) {
1028 return MI.getDesc().TSFlags & SIInstrFlags::LDSDIR;
1029 }
1030
1031 bool isLDSDIR(uint32_t Opcode) const {
1032 return get(Opcode).TSFlags & SIInstrFlags::LDSDIR;
1033 }
1034
1035 static bool isVINTERP(const MachineInstr &MI) {
1036 return MI.getDesc().TSFlags & SIInstrFlags::VINTERP;
1037 }
1038
1039 bool isVINTERP(uint32_t Opcode) const {
1040 return get(Opcode).TSFlags & SIInstrFlags::VINTERP;
1041 }
1042
1043 static bool isScalarUnit(const MachineInstr &MI) {
1044 return MI.getDesc().TSFlags & (SIInstrFlags::SALU | SIInstrFlags::SMRD);
1045 }
1046
1047 static bool usesVM_CNT(const MachineInstr &MI) {
1048 return MI.getDesc().TSFlags & SIInstrFlags::VM_CNT;
1049 }
1050
1051 static bool usesLGKM_CNT(const MachineInstr &MI) {
1052 return MI.getDesc().TSFlags & SIInstrFlags::LGKM_CNT;
1053 }
1054
1055 static bool usesASYNC_CNT(const MachineInstr &MI) {
1056 return MI.getDesc().TSFlags & SIInstrFlags::ASYNC_CNT;
1057 }
1058
1059 bool usesASYNC_CNT(uint32_t Opcode) const {
1060 return get(Opcode).TSFlags & SIInstrFlags::ASYNC_CNT;
1061 }
1062
1063 // Most sopk treat the immediate as a signed 16-bit, however some
1064 // use it as unsigned.
1065 static bool sopkIsZext(unsigned Opcode) {
1066 return Opcode == AMDGPU::S_CMPK_EQ_U32 || Opcode == AMDGPU::S_CMPK_LG_U32 ||
1067 Opcode == AMDGPU::S_CMPK_GT_U32 || Opcode == AMDGPU::S_CMPK_GE_U32 ||
1068 Opcode == AMDGPU::S_CMPK_LT_U32 || Opcode == AMDGPU::S_CMPK_LE_U32 ||
1069 Opcode == AMDGPU::S_GETREG_B32 ||
1070 Opcode == AMDGPU::S_GETREG_B32_const;
1071 }
1072
1073 /// \returns true if this is an s_store_dword* instruction. This is more
1074 /// specific than isSMEM && mayStore.
1075 static bool isScalarStore(const MachineInstr &MI) {
1076 return MI.getDesc().TSFlags & SIInstrFlags::SCALAR_STORE;
1077 }
1078
1079 bool isScalarStore(uint32_t Opcode) const {
1080 return get(Opcode).TSFlags & SIInstrFlags::SCALAR_STORE;
1081 }
1082
1083 static bool isFixedSize(const MachineInstr &MI) {
1084 return MI.getDesc().TSFlags & SIInstrFlags::FIXED_SIZE;
1085 }
1086
1087 bool isFixedSize(uint32_t Opcode) const {
1088 return get(Opcode).TSFlags & SIInstrFlags::FIXED_SIZE;
1089 }
1090
1091 static bool hasFPClamp(const MachineInstr &MI) {
1092 return MI.getDesc().TSFlags & SIInstrFlags::FPClamp;
1093 }
1094
1095 bool hasFPClamp(uint32_t Opcode) const {
1096 return get(Opcode).TSFlags & SIInstrFlags::FPClamp;
1097 }
1098
1099 static bool hasIntClamp(const MachineInstr &MI) {
1100 return MI.getDesc().TSFlags & SIInstrFlags::IntClamp;
1101 }
1102
1104 const uint64_t ClampFlags = SIInstrFlags::FPClamp |
1108 return MI.getDesc().TSFlags & ClampFlags;
1109 }
1110
1111 static bool usesFPDPRounding(const MachineInstr &MI) {
1112 return MI.getDesc().TSFlags & SIInstrFlags::FPDPRounding;
1113 }
1114
1115 bool usesFPDPRounding(uint32_t Opcode) const {
1116 return get(Opcode).TSFlags & SIInstrFlags::FPDPRounding;
1117 }
1118
1119 static bool isFPAtomic(const MachineInstr &MI) {
1120 return MI.getDesc().TSFlags & SIInstrFlags::FPAtomic;
1121 }
1122
1123 bool isFPAtomic(uint32_t Opcode) const {
1124 return get(Opcode).TSFlags & SIInstrFlags::FPAtomic;
1125 }
1126
1127 static bool isNeverUniform(const MachineInstr &MI) {
1128 return MI.getDesc().TSFlags & SIInstrFlags::IsNeverUniform;
1129 }
1130
1131 // Check to see if opcode is for a barrier start. Pre gfx12 this is just the
1132 // S_BARRIER, but after support for S_BARRIER_SIGNAL* / S_BARRIER_WAIT we want
1133 // to check for the barrier start (S_BARRIER_SIGNAL*)
1134 bool isBarrierStart(unsigned Opcode) const {
1135 return Opcode == AMDGPU::S_BARRIER ||
1136 Opcode == AMDGPU::S_BARRIER_SIGNAL_M0 ||
1137 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_M0 ||
1138 Opcode == AMDGPU::S_BARRIER_SIGNAL_IMM ||
1139 Opcode == AMDGPU::S_BARRIER_SIGNAL_ISFIRST_IMM;
1140 }
1141
1142 bool isBarrier(unsigned Opcode) const {
1143 return isBarrierStart(Opcode) || Opcode == AMDGPU::S_BARRIER_WAIT ||
1144 Opcode == AMDGPU::S_BARRIER_INIT_M0 ||
1145 Opcode == AMDGPU::S_BARRIER_INIT_IMM ||
1146 Opcode == AMDGPU::S_BARRIER_JOIN_IMM ||
1147 Opcode == AMDGPU::S_BARRIER_LEAVE || Opcode == AMDGPU::DS_GWS_INIT ||
1148 Opcode == AMDGPU::DS_GWS_BARRIER;
1149 }
1150
1151 static bool isGFX12CacheInvOrWBInst(unsigned Opc) {
1152 return Opc == AMDGPU::GLOBAL_INV || Opc == AMDGPU::GLOBAL_WB ||
1153 Opc == AMDGPU::GLOBAL_WBINV;
1154 }
1155
1156 static bool isF16PseudoScalarTrans(unsigned Opcode) {
1157 return Opcode == AMDGPU::V_S_EXP_F16_e64 ||
1158 Opcode == AMDGPU::V_S_LOG_F16_e64 ||
1159 Opcode == AMDGPU::V_S_RCP_F16_e64 ||
1160 Opcode == AMDGPU::V_S_RSQ_F16_e64 ||
1161 Opcode == AMDGPU::V_S_SQRT_F16_e64;
1162 }
1163
1165 return MI.getDesc().TSFlags & SIInstrFlags::TiedSourceNotRead;
1166 }
1167
1168 bool doesNotReadTiedSource(uint32_t Opcode) const {
1169 return get(Opcode).TSFlags & SIInstrFlags::TiedSourceNotRead;
1170 }
1171
1172 bool isIGLP(unsigned Opcode) const {
1173 return Opcode == AMDGPU::SCHED_BARRIER ||
1174 Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
1175 }
1176
1177 bool isIGLP(const MachineInstr &MI) const { return isIGLP(MI.getOpcode()); }
1178
1179 // Return true if the instruction is mutually exclusive with all non-IGLP DAG
1180 // mutations, requiring all other mutations to be disabled.
1181 bool isIGLPMutationOnly(unsigned Opcode) const {
1182 return Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
1183 }
1184
1185 static unsigned getNonSoftWaitcntOpcode(unsigned Opcode) {
1186 switch (Opcode) {
1187 case AMDGPU::S_WAITCNT_soft:
1188 return AMDGPU::S_WAITCNT;
1189 case AMDGPU::S_WAITCNT_VSCNT_soft:
1190 return AMDGPU::S_WAITCNT_VSCNT;
1191 case AMDGPU::S_WAIT_LOADCNT_soft:
1192 return AMDGPU::S_WAIT_LOADCNT;
1193 case AMDGPU::S_WAIT_STORECNT_soft:
1194 return AMDGPU::S_WAIT_STORECNT;
1195 case AMDGPU::S_WAIT_SAMPLECNT_soft:
1196 return AMDGPU::S_WAIT_SAMPLECNT;
1197 case AMDGPU::S_WAIT_BVHCNT_soft:
1198 return AMDGPU::S_WAIT_BVHCNT;
1199 case AMDGPU::S_WAIT_DSCNT_soft:
1200 return AMDGPU::S_WAIT_DSCNT;
1201 case AMDGPU::S_WAIT_KMCNT_soft:
1202 return AMDGPU::S_WAIT_KMCNT;
1203 case AMDGPU::S_WAIT_XCNT_soft:
1204 return AMDGPU::S_WAIT_XCNT;
1205 default:
1206 return Opcode;
1207 }
1208 }
1209
1210 static bool isWaitcnt(unsigned Opcode) {
1211 switch (getNonSoftWaitcntOpcode(Opcode)) {
1212 case AMDGPU::S_WAITCNT:
1213 case AMDGPU::S_WAITCNT_VSCNT:
1214 case AMDGPU::S_WAITCNT_VMCNT:
1215 case AMDGPU::S_WAITCNT_EXPCNT:
1216 case AMDGPU::S_WAITCNT_LGKMCNT:
1217 case AMDGPU::S_WAIT_LOADCNT:
1218 case AMDGPU::S_WAIT_LOADCNT_DSCNT:
1219 case AMDGPU::S_WAIT_STORECNT:
1220 case AMDGPU::S_WAIT_STORECNT_DSCNT:
1221 case AMDGPU::S_WAIT_SAMPLECNT:
1222 case AMDGPU::S_WAIT_BVHCNT:
1223 case AMDGPU::S_WAIT_EXPCNT:
1224 case AMDGPU::S_WAIT_DSCNT:
1225 case AMDGPU::S_WAIT_KMCNT:
1226 case AMDGPU::S_WAIT_XCNT:
1227 case AMDGPU::S_WAIT_IDLE:
1228 return true;
1229 default:
1230 return false;
1231 }
1232 }
1233
1234 bool isVGPRCopy(const MachineInstr &MI) const {
1235 assert(isCopyInstr(MI));
1236 Register Dest = MI.getOperand(0).getReg();
1237 const MachineFunction &MF = *MI.getMF();
1238 const MachineRegisterInfo &MRI = MF.getRegInfo();
1239 return !RI.isSGPRReg(MRI, Dest);
1240 }
1241
1242 bool hasVGPRUses(const MachineInstr &MI) const {
1243 const MachineFunction &MF = *MI.getMF();
1244 const MachineRegisterInfo &MRI = MF.getRegInfo();
1245 return llvm::any_of(MI.explicit_uses(),
1246 [&MRI, this](const MachineOperand &MO) {
1247 return MO.isReg() && RI.isVGPR(MRI, MO.getReg());});
1248 }
1249
1250 /// Return true if the instruction modifies the mode register.q
1251 static bool modifiesModeRegister(const MachineInstr &MI);
1252
1253 /// This function is used to determine if an instruction can be safely
1254 /// executed under EXEC = 0 without hardware error, indeterminate results,
1255 /// and/or visible effects on future vector execution or outside the shader.
1256 /// Note: as of 2024 the only use of this is SIPreEmitPeephole where it is
1257 /// used in removing branches over short EXEC = 0 sequences.
1258 /// As such it embeds certain assumptions which may not apply to every case
1259 /// of EXEC = 0 execution.
1261
1262 /// Returns true if the instruction could potentially depend on the value of
1263 /// exec. If false, exec dependencies may safely be ignored.
1264 bool mayReadEXEC(const MachineRegisterInfo &MRI, const MachineInstr &MI) const;
1265
1266 bool isInlineConstant(const APInt &Imm) const;
1267
1268 bool isInlineConstant(const APFloat &Imm) const;
1269
1270 // Returns true if this non-register operand definitely does not need to be
1271 // encoded as a 32-bit literal. Note that this function handles all kinds of
1272 // operands, not just immediates.
1273 //
1274 // Some operands like FrameIndexes could resolve to an inline immediate value
1275 // that will not require an additional 4-bytes; this function assumes that it
1276 // will.
1277 bool isInlineConstant(const MachineOperand &MO, uint8_t OperandType) const {
1278 if (!MO.isImm())
1279 return false;
1280 return isInlineConstant(MO.getImm(), OperandType);
1281 }
1282 bool isInlineConstant(int64_t ImmVal, uint8_t OperandType) const;
1283
1285 const MCOperandInfo &OpInfo) const {
1286 return isInlineConstant(MO, OpInfo.OperandType);
1287 }
1288
1289 /// \p returns true if \p UseMO is substituted with \p DefMO in \p MI it would
1290 /// be an inline immediate.
1292 const MachineOperand &UseMO,
1293 const MachineOperand &DefMO) const {
1294 assert(UseMO.getParent() == &MI);
1295 int OpIdx = UseMO.getOperandNo();
1296 if (OpIdx >= MI.getDesc().NumOperands)
1297 return false;
1298
1299 return isInlineConstant(DefMO, MI.getDesc().operands()[OpIdx]);
1300 }
1301
1302 /// \p returns true if the operand \p OpIdx in \p MI is a valid inline
1303 /// immediate.
1304 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx) const {
1305 const MachineOperand &MO = MI.getOperand(OpIdx);
1306 return isInlineConstant(MO, MI.getDesc().operands()[OpIdx].OperandType);
1307 }
1308
1309 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx,
1310 int64_t ImmVal) const {
1311 if (OpIdx >= MI.getDesc().NumOperands)
1312 return false;
1313
1314 if (isCopyInstr(MI)) {
1315 unsigned Size = getOpSize(MI, OpIdx);
1316 assert(Size == 8 || Size == 4);
1317
1318 uint8_t OpType = (Size == 8) ?
1320 return isInlineConstant(ImmVal, OpType);
1321 }
1322
1323 return isInlineConstant(ImmVal, MI.getDesc().operands()[OpIdx].OperandType);
1324 }
1325
1326 bool isInlineConstant(const MachineInstr &MI, unsigned OpIdx,
1327 const MachineOperand &MO) const {
1328 return isInlineConstant(MI, OpIdx, MO.getImm());
1329 }
1330
1331 bool isInlineConstant(const MachineOperand &MO) const {
1332 return isInlineConstant(*MO.getParent(), MO.getOperandNo());
1333 }
1334
1335 bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
1336 const MachineOperand &MO) const;
1337
1338 bool isLiteralOperandLegal(const MCInstrDesc &InstDesc,
1339 const MCOperandInfo &OpInfo) const;
1340
1341 bool isImmOperandLegal(const MCInstrDesc &InstDesc, unsigned OpNo,
1342 int64_t ImmVal) const;
1343
1344 bool isImmOperandLegal(const MachineInstr &MI, unsigned OpNo,
1345 const MachineOperand &MO) const {
1346 return isImmOperandLegal(MI.getDesc(), OpNo, MO);
1347 }
1348
1349 bool isNeverCoissue(MachineInstr &MI) const;
1350
1351 /// Check if this immediate value can be used for AV_MOV_B64_IMM_PSEUDO.
1352 bool isLegalAV64PseudoImm(uint64_t Imm) const;
1353
1354 /// Return true if this 64-bit VALU instruction has a 32-bit encoding.
1355 /// This function will return false if you pass it a 32-bit instruction.
1356 bool hasVALU32BitEncoding(unsigned Opcode) const;
1357
1358 bool physRegUsesConstantBus(const MachineOperand &Reg) const;
1360 const MachineRegisterInfo &MRI) const;
1361
1362 /// Returns true if this operand uses the constant bus.
1363 bool usesConstantBus(const MachineRegisterInfo &MRI,
1364 const MachineOperand &MO,
1365 const MCOperandInfo &OpInfo) const;
1366
1368 int OpIdx) const {
1369 return usesConstantBus(MRI, MI.getOperand(OpIdx),
1370 MI.getDesc().operands()[OpIdx]);
1371 }
1372
1373 /// Return true if this instruction has any modifiers.
1374 /// e.g. src[012]_mod, omod, clamp.
1375 bool hasModifiers(unsigned Opcode) const;
1376
1377 bool hasModifiersSet(const MachineInstr &MI, AMDGPU::OpName OpName) const;
1378 bool hasAnyModifiersSet(const MachineInstr &MI) const;
1379
1380 bool canShrink(const MachineInstr &MI,
1381 const MachineRegisterInfo &MRI) const;
1382
1384 unsigned NewOpcode) const;
1385
1386 bool verifyInstruction(const MachineInstr &MI,
1387 StringRef &ErrInfo) const override;
1388
1389 unsigned getVALUOp(const MachineInstr &MI) const;
1390 unsigned getVALUOp(unsigned Opc) const;
1391
1394 const DebugLoc &DL, Register Reg, bool IsSCCLive,
1395 SlotIndexes *Indexes = nullptr) const;
1396
1399 Register Reg, SlotIndexes *Indexes = nullptr) const;
1400
1402
1403 /// Return the correct register class for \p OpNo. For target-specific
1404 /// instructions, this will return the register class that has been defined
1405 /// in tablegen. For generic instructions, like REG_SEQUENCE it will return
1406 /// the register class of its machine operand.
1407 /// to infer the correct register class base on the other operands.
1409 unsigned OpNo) const;
1410
1411 /// Return the size in bytes of the operand OpNo on the given
1412 // instruction opcode.
1413 unsigned getOpSize(uint32_t Opcode, unsigned OpNo) const {
1414 const MCOperandInfo &OpInfo = get(Opcode).operands()[OpNo];
1415
1416 if (OpInfo.RegClass == -1) {
1417 // If this is an immediate operand, this must be a 32-bit literal.
1418 assert(OpInfo.OperandType == MCOI::OPERAND_IMMEDIATE);
1419 return 4;
1420 }
1421
1422 return RI.getRegSizeInBits(*RI.getRegClass(getOpRegClassID(OpInfo))) / 8;
1423 }
1424
1425 /// This form should usually be preferred since it handles operands
1426 /// with unknown register classes.
1427 unsigned getOpSize(const MachineInstr &MI, unsigned OpNo) const {
1428 const MachineOperand &MO = MI.getOperand(OpNo);
1429 if (MO.isReg()) {
1430 if (unsigned SubReg = MO.getSubReg()) {
1431 return RI.getSubRegIdxSize(SubReg) / 8;
1432 }
1433 }
1434 return RI.getRegSizeInBits(*getOpRegClass(MI, OpNo)) / 8;
1435 }
1436
1437 /// Legalize the \p OpIndex operand of this instruction by inserting
1438 /// a MOV. For example:
1439 /// ADD_I32_e32 VGPR0, 15
1440 /// to
1441 /// MOV VGPR1, 15
1442 /// ADD_I32_e32 VGPR0, VGPR1
1443 ///
1444 /// If the operand being legalized is a register, then a COPY will be used
1445 /// instead of MOV.
1446 void legalizeOpWithMove(MachineInstr &MI, unsigned OpIdx) const;
1447
1448 /// Check if \p MO is a legal operand if it was the \p OpIdx Operand
1449 /// for \p MI.
1450 bool isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
1451 const MachineOperand *MO = nullptr) const;
1452
1453 /// Check if \p MO would be a valid operand for the given operand
1454 /// definition \p OpInfo. Note this does not attempt to validate constant bus
1455 /// restrictions (e.g. literal constant usage).
1457 const MCOperandInfo &OpInfo,
1458 const MachineOperand &MO) const;
1459
1460 /// Check if \p MO (a register operand) is a legal register for the
1461 /// given operand description or operand index.
1462 /// The operand index version provide more legality checks
1463 bool isLegalRegOperand(const MachineRegisterInfo &MRI,
1464 const MCOperandInfo &OpInfo,
1465 const MachineOperand &MO) const;
1466 bool isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
1467 const MachineOperand &MO) const;
1468
1469 /// Check if \p MO would be a legal operand for gfx12+ packed math FP32
1470 /// instructions. Packed math FP32 instructions typically accept SGPRs or
1471 /// VGPRs as source operands. On gfx12+, if a source operand uses SGPRs, the
1472 /// HW can only read the first SGPR and use it for both the low and high
1473 /// operations.
1474 /// \p SrcN can be 0, 1, or 2, representing src0, src1, and src2,
1475 /// respectively. If \p MO is nullptr, the operand corresponding to SrcN will
1476 /// be used.
1478 const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN,
1479 const MachineOperand *MO = nullptr) const;
1480
1481 /// Legalize operands in \p MI by either commuting it or inserting a
1482 /// copy of src1.
1484
1485 /// Fix operands in \p MI to satisfy constant bus requirements.
1487
1488 /// Copy a value from a VGPR (\p SrcReg) to SGPR. The desired register class
1489 /// for the dst register (\p DstRC) can be optionally supplied. This function
1490 /// can only be used when it is know that the value in SrcReg is same across
1491 /// all threads in the wave.
1492 /// \returns The SGPR register that \p SrcReg was copied to.
1495 const TargetRegisterClass *DstRC = nullptr) const;
1496
1499
1502 const TargetRegisterClass *DstRC,
1504 const DebugLoc &DL) const;
1505
1506 /// Legalize all operands in this instruction. This function may create new
1507 /// instructions and control-flow around \p MI. If present, \p MDT is
1508 /// updated.
1509 /// \returns A new basic block that contains \p MI if new blocks were created.
1511 legalizeOperands(MachineInstr &MI, MachineDominatorTree *MDT = nullptr) const;
1512
1513 /// Change SADDR form of a FLAT \p Inst to its VADDR form if saddr operand
1514 /// was moved to VGPR. \returns true if succeeded.
1515 bool moveFlatAddrToVGPR(MachineInstr &Inst) const;
1516
1517 /// Fix operands in Inst to fix 16bit SALU to VALU lowering.
1519 MachineRegisterInfo &MRI) const;
1520 void legalizeOperandsVALUt16(MachineInstr &Inst, unsigned OpIdx,
1521 MachineRegisterInfo &MRI) const;
1522
1523 /// Replace the instructions opcode with the equivalent VALU
1524 /// opcode. This function will also move the users of MachineInstruntions
1525 /// in the \p WorkList to the VALU if necessary. If present, \p MDT is
1526 /// updated.
1527 void moveToVALU(SIInstrWorklist &Worklist, MachineDominatorTree *MDT) const;
1528
1529 void
1531 MachineInstr &Inst,
1533 DenseMap<MachineInstr *, bool> &V2SPhyCopiesToErase) const;
1534 /// Wrapper function for generating waterfall for instruction \p MI
1535 /// This function take into consideration of related pre & succ instructions
1536 /// (e.g. calling process) into consideratioin
1539 ArrayRef<Register> PhySGPRs = {}) const;
1540
1541 void insertNoop(MachineBasicBlock &MBB,
1542 MachineBasicBlock::iterator MI) const override;
1543
1544 void insertNoops(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
1545 unsigned Quantity) const override;
1546
1547 void insertReturn(MachineBasicBlock &MBB) const;
1548
1549 /// Build instructions that simulate the behavior of a `s_trap 2` instructions
1550 /// for hardware (namely, gfx11) that runs in PRIV=1 mode. There, s_trap is
1551 /// interpreted as a nop.
1552 MachineBasicBlock *insertSimulatedTrap(MachineRegisterInfo &MRI,
1553 MachineBasicBlock &MBB,
1554 MachineInstr &MI,
1555 const DebugLoc &DL) const;
1556
1557 /// Return the number of wait states that result from executing this
1558 /// instruction.
1559 static unsigned getNumWaitStates(const MachineInstr &MI);
1560
1561 /// Returns the operand named \p Op. If \p MI does not have an
1562 /// operand named \c Op, this function returns nullptr.
1564 MachineOperand *getNamedOperand(MachineInstr &MI,
1565 AMDGPU::OpName OperandName) const;
1566
1569 AMDGPU::OpName OperandName) const {
1570 return getNamedOperand(const_cast<MachineInstr &>(MI), OperandName);
1571 }
1572
1573 /// Get required immediate operand
1575 AMDGPU::OpName OperandName) const {
1576 int Idx = AMDGPU::getNamedOperandIdx(MI.getOpcode(), OperandName);
1577 return MI.getOperand(Idx).getImm();
1578 }
1579
1582
1583 bool isLowLatencyInstruction(const MachineInstr &MI) const;
1584 bool isHighLatencyDef(int Opc) const override;
1585
1586 /// Return the descriptor of the target-specific machine instruction
1587 /// that corresponds to the specified pseudo or native opcode.
1588 const MCInstrDesc &getMCOpcodeFromPseudo(unsigned Opcode) const {
1589 return get(pseudoToMCOpcode(Opcode));
1590 }
1591
1592 Register isStackAccess(const MachineInstr &MI, int &FrameIndex,
1593 TypeSize &MemBytes) const;
1594 Register isSGPRStackAccess(const MachineInstr &MI, int &FrameIndex,
1595 TypeSize &MemBytes) const;
1596
1598 int &FrameIndex) const override {
1599 TypeSize MemBytes = TypeSize::getZero();
1600 return isLoadFromStackSlot(MI, FrameIndex, MemBytes);
1601 }
1602
1603 Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex,
1604 TypeSize &MemBytes) const override;
1605
1607 int &FrameIndex) const override {
1608 TypeSize MemBytes = TypeSize::getZero();
1609 return isStoreToStackSlot(MI, FrameIndex, MemBytes);
1610 }
1611
1612 Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex,
1613 TypeSize &MemBytes) const override;
1614
1615 unsigned getInstBundleSize(const MachineInstr &MI) const;
1616 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
1617
1618 bool mayAccessFlatAddressSpace(const MachineInstr &MI) const;
1619
1620 std::pair<unsigned, unsigned>
1621 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
1622
1624 getSerializableTargetIndices() const override;
1625
1628
1631
1634 const ScheduleDAG *DAG) const override;
1635
1638 MachineLoopInfo *MLI) const override;
1639
1642 const ScheduleDAGMI *DAG) const override;
1643
1645 const MachineFunction &MF) const override;
1646
1648 Register Reg = Register()) const override;
1649
1650 bool canAddToBBProlog(const MachineInstr &MI) const;
1651
1654 const DebugLoc &DL, Register Src,
1655 Register Dst) const override;
1656
1659 const DebugLoc &DL, Register Src,
1660 unsigned SrcSubReg,
1661 Register Dst) const override;
1662
1663 bool isWave32() const;
1664
1665 /// Return a partially built integer add instruction without carry.
1666 /// Caller must add source operands.
1667 /// For pre-GFX9 it will generate unused carry destination operand.
1668 /// TODO: After GFX9 it should return a no-carry operation.
1671 const DebugLoc &DL,
1672 Register DestReg) const;
1673
1676 const DebugLoc &DL,
1677 Register DestReg,
1678 RegScavenger &RS) const;
1679
1680 static bool isKillTerminator(unsigned Opcode);
1681 const MCInstrDesc &getKillTerminatorFromPseudo(unsigned Opcode) const;
1682
1683 bool isLegalMUBUFImmOffset(unsigned Imm) const;
1684
1685 static unsigned getMaxMUBUFImmOffset(const GCNSubtarget &ST);
1686
1687 bool splitMUBUFOffset(uint32_t Imm, uint32_t &SOffset, uint32_t &ImmOffset,
1688 Align Alignment = Align(4)) const;
1689
1690 /// Returns if \p Offset is legal for the subtarget as the offset to a FLAT
1691 /// encoded instruction with the given \p FlatVariant.
1692 bool isLegalFLATOffset(int64_t Offset, unsigned AddrSpace,
1693 uint64_t FlatVariant) const;
1694
1695 /// Split \p COffsetVal into {immediate offset field, remainder offset}
1696 /// values.
1697 std::pair<int64_t, int64_t> splitFlatOffset(int64_t COffsetVal,
1698 unsigned AddrSpace,
1699 uint64_t FlatVariant) const;
1700
1701 /// Returns true if negative offsets are allowed for the given \p FlatVariant.
1702 bool allowNegativeFlatOffset(uint64_t FlatVariant) const;
1703
1704 /// \brief Return a target-specific opcode if Opcode is a pseudo instruction.
1705 /// Return -1 if the target-specific opcode for the pseudo instruction does
1706 /// not exist. If Opcode is not a pseudo instruction, this is identity.
1707 int pseudoToMCOpcode(int Opcode) const;
1708
1709 /// \brief Check if this instruction should only be used by assembler.
1710 /// Return true if this opcode should not be used by codegen.
1711 bool isAsmOnlyOpcode(int MCOp) const;
1712
1713 void fixImplicitOperands(MachineInstr &MI) const;
1714
1716 ArrayRef<unsigned> Ops, int FrameIndex,
1717 MachineInstr *&CopyMI,
1718 LiveIntervals *LIS = nullptr,
1719 VirtRegMap *VRM = nullptr) const override;
1720
1721 unsigned getInstrLatency(const InstrItineraryData *ItinData,
1722 const MachineInstr &MI,
1723 unsigned *PredCost = nullptr) const override;
1724
1725 const MachineOperand &getCalleeOperand(const MachineInstr &MI) const override;
1726
1728
1730
1731 const MIRFormatter *getMIRFormatter() const override;
1732
1733 static unsigned getDSShaderTypeValue(const MachineFunction &MF);
1734
1735 const TargetSchedModel &getSchedModel() const { return SchedModel; }
1736
1738 Register DstReg,
1739 MachineInstr &Inst) const;
1740
1742 SIInstrWorklist &Worklist, Register DstReg, MachineInstr &Inst,
1745 DenseMap<MachineInstr *, bool> &V2SPhyCopiesToErase) const;
1746
1747 // FIXME: This should be removed
1748 // Enforce operand's \p OpName even alignment if required by target.
1749 // This is used if an operand is a 32 bit register but needs to be aligned
1750 // regardless.
1751 void enforceOperandRCAlignment(MachineInstr &MI, AMDGPU::OpName OpName) const;
1752};
1753
1754/// \brief Returns true if a reg:subreg pair P has a TRC class
1756 const TargetRegisterClass &TRC,
1757 MachineRegisterInfo &MRI) {
1758 auto *RC = MRI.getRegClass(P.Reg);
1759 if (!P.SubReg)
1760 return RC == &TRC;
1761 auto *TRI = MRI.getTargetRegisterInfo();
1762 return RC == TRI->getMatchingSuperRegClass(RC, &TRC, P.SubReg);
1763}
1764
1765/// \brief Create RegSubRegPair from a register MachineOperand
1766inline
1768 assert(O.isReg());
1769 return TargetInstrInfo::RegSubRegPair(O.getReg(), O.getSubReg());
1770}
1771
1772/// \brief Return the SubReg component from REG_SEQUENCE
1773TargetInstrInfo::RegSubRegPair getRegSequenceSubReg(MachineInstr &MI,
1774 unsigned SubReg);
1775
1776/// \brief Return the defining instruction for a given reg:subreg pair
1777/// skipping copy like instructions and subreg-manipulation pseudos.
1778/// Following another subreg of a reg:subreg isn't supported.
1779MachineInstr *getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P,
1780 const MachineRegisterInfo &MRI);
1781
1782/// \brief Return false if EXEC is not changed between the def of \p VReg at \p
1783/// DefMI and the use at \p UseMI. Should be run on SSA. Currently does not
1784/// attempt to track between blocks.
1785bool execMayBeModifiedBeforeUse(const MachineRegisterInfo &MRI,
1786 Register VReg,
1787 const MachineInstr &DefMI,
1788 const MachineInstr &UseMI);
1789
1790/// \brief Return false if EXEC is not changed between the def of \p VReg at \p
1791/// DefMI and all its uses. Should be run on SSA. Currently does not attempt to
1792/// track between blocks.
1793bool execMayBeModifiedBeforeAnyUse(const MachineRegisterInfo &MRI,
1794 Register VReg,
1795 const MachineInstr &DefMI);
1796
1797namespace AMDGPU {
1798
1800 int32_t getVOPe64(uint32_t Opcode);
1801
1803 int32_t getVOPe32(uint32_t Opcode);
1804
1806 int32_t getSDWAOp(uint32_t Opcode);
1807
1809 int32_t getDPPOp32(uint32_t Opcode);
1810
1812 int32_t getDPPOp64(uint32_t Opcode);
1813
1816
1818 int32_t getCommuteRev(uint32_t Opcode);
1819
1821 int32_t getCommuteOrig(uint32_t Opcode);
1822
1824 int32_t getAddr64Inst(uint32_t Opcode);
1825
1826 /// Check if \p Opcode is an Addr64 opcode.
1827 ///
1828 /// \returns \p Opcode if it is an Addr64 opcode, otherwise -1.
1830 int32_t getIfAddr64Inst(uint32_t Opcode);
1831
1833 int32_t getSOPKOp(uint32_t Opcode);
1834
1835 /// \returns SADDR form of a FLAT Global instruction given an \p Opcode
1836 /// of a VADDR form.
1839
1840 /// \returns VADDR form of a FLAT Global instruction given an \p Opcode
1841 /// of a SADDR form.
1844
1847
1848 /// \returns ST form with only immediate offset of a FLAT Scratch instruction
1849 /// given an \p Opcode of an SS (SADDR) form.
1852
1853 /// \returns SV (VADDR) form of a FLAT Scratch instruction given an \p Opcode
1854 /// of an SVS (SADDR + VADDR) form.
1857
1858 /// \returns SS (SADDR) form of a FLAT Scratch instruction given an \p Opcode
1859 /// of an SV (VADDR) form.
1862
1863 /// \returns SV (VADDR) form of a FLAT Scratch instruction given an \p Opcode
1864 /// of an SS (SADDR) form.
1867
1868 /// \returns earlyclobber version of a MAC MFMA is exists.
1871
1872 /// \returns Version of an MFMA instruction which uses AGPRs for srcC and
1873 /// vdst, given an \p Opcode of an MFMA which uses VGPRs for srcC/vdst.
1876
1877 /// \returns v_cmpx version of a v_cmp instruction.
1880
1881 const uint64_t RSRC_DATA_FORMAT = 0xf00000000000LL;
1884 const uint64_t RSRC_TID_ENABLE = UINT64_C(1) << (32 + 23);
1885
1886} // end namespace AMDGPU
1887
1888namespace AMDGPU {
1890 // For sgpr to vgpr spill instructions
1892};
1893} // namespace AMDGPU
1894
1895namespace SI {
1897
1898/// Offsets in bytes from the start of the input buffer
1910
1911} // end namespace KernelInputOffsets
1912} // end namespace SI
1913
1914} // end namespace llvm
1915
1916#endif // LLVM_LIB_TARGET_AMDGPU_SIINSTRINFO_H
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
AMDGPU specific overrides of MIRFormatter.
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define LLVM_READONLY
Definition Compiler.h:322
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
MachineInstr unsigned OpIdx
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.
static unsigned getBranchOpcode(ISD::CondCode Cond)
Class for arbitrary precision integers.
Definition APInt.h:78
ArrayRef - 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:123
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:86
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
uint64_t getClampMask(const MachineInstr &MI) const
bool mayAccessScratch(const MachineInstr &MI) const
bool isIGLP(unsigned Opcode) const
static bool isFLATScratch(const MachineInstr &MI)
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
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)
void restoreExec(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register Reg, SlotIndexes *Indexes=nullptr) 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.
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
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
void insertReturn(MachineBasicBlock &MBB) 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
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
unsigned getInstBundleSize(const MachineInstr &MI) 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)
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
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
std::pair< int64_t, int64_t > splitFlatOffset(int64_t COffsetVal, unsigned AddrSpace, uint64_t FlatVariant) const
Split COffsetVal into {immediate offset field, remainder offset} values.
bool isGWS(uint32_t Opcode) const
unsigned getVectorRegSpillRestoreOpcode(Register Reg, const TargetRegisterClass *RC, unsigned Size, const SIMachineFunctionInfo &MFI) const
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 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
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
const TargetRegisterClass * getPreferredSelectRegClass(unsigned Size) 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 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)
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.
bool isFLATGlobal(uint32_t Opcode) const
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 mayAccessLDSThroughFlat(const MachineInstr &MI) const
bool isAtomic(uint32_t Opcode) const
bool isIgnorableUse(const MachineOperand &MO) const override
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 isVALU(uint32_t Opcode) const
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...
void mutateAndCleanupImplicit(MachineInstr &MI, const MCInstrDesc &NewDesc) const
ValueUniformity getGenericValueUniformity(const MachineInstr &MI) const
static bool isMAI(const MCInstrDesc &Desc)
bool isLDSDMA(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 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)
bool isLegalFLATOffset(int64_t Offset, unsigned AddrSpace, uint64_t FlatVariant) const
Returns if Offset is legal for the subtarget as the offset to a FLAT encoded instruction with the giv...
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
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...
bool allowNegativeFlatOffset(uint64_t FlatVariant) const
Returns true if negative offsets are allowed for the given FlatVariant.
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 getVectorRegSpillSaveOpcode(Register Reg, const TargetRegisterClass *RC, unsigned Size, const SIMachineFunctionInfo &MFI) const
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
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
void createReadFirstLaneFromCopyToPhysReg(MachineRegisterInfo &MRI, Register DstReg, MachineInstr &Inst) const
bool swapSourceModifiers(MachineInstr &MI, MachineOperand &Src0, AMDGPU::OpName Src0OpName, MachineOperand &Src1, AMDGPU::OpName Src1OpName) const
Register insertNE(MachineBasicBlock *MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register SrcReg, int Value) 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
MachineInstr * convertToThreeAddress(MachineInstr &MI, LiveVariables *LV, LiveIntervals *LIS) 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 insertVectorSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
std::pair< MachineInstr *, MachineInstr * > expandMovDPP64(MachineInstr &MI) const
Register insertEQ(MachineBasicBlock *MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register SrcReg, int Value) const
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
static bool isVALU(const MachineInstr &MI)
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
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)
bool isLegalGFX12PlusPackedMathFP32Operand(const MachineRegisterInfo &MRI, const MachineInstr &MI, unsigned SrcN, const MachineOperand *MO=nullptr) const
Check if MO would be a legal operand for gfx12+ packed math FP32 instructions.
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
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.
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 isBarrierStart(unsigned Opcode) const
std::optional< int64_t > getImmOrMaterializedImm(MachineOperand &Op) 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)
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.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:339
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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:349
LLVM Value Representation.
Definition Value.h:75
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.
LLVM_READONLY int32_t getVCMPXNoSDstOp(uint32_t Opcode)
const uint64_t RSRC_TID_ENABLE
LLVM_READONLY int32_t getMFMASrcCVDstAGPROp(uint32_t Opcode)
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 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:204
@ OPERAND_REG_IMM_INT32
Operands with register, 32-bit, or 64-bit immediate.
Definition SIDefines.h:203
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
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:532
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.
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:44
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:1746
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:52
DWARFExpression::Operation Op
constexpr unsigned DefaultMemoryClusterDWordsLimit
Definition SIInstrInfo.h:40
static const MachineMemOperand::Flags MOLastUse
Mark the MMO of a load as the last use.
Definition SIInstrInfo.h:48
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:63
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.
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:67
MachineInstr * top() const
Definition SIInstrInfo.h:72
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:57
SmallVector< Register > SGPRs
Definition SIInstrInfo.h:59