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