[llvm] [NFC][AMDGPU] Introduce SIInstrFlags predicates for TSFlag access (PR #201512)

Valery Pykhtin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 01:51:07 PDT 2026


================
@@ -182,6 +182,210 @@ enum : uint64_t {
   IsSWMMAC = UINT64_C(1) << 63,
 };
 
+// Inline predicates for TSFlags — the single place where raw TSFlags bit
+// tests are written. All callers (SIInstrInfo methods, MC-level code) go
+// through these functions to make bit layout changes easier.
+//
+// getTSFlags extracts the TSFlags value from different argument types.
+// SIInstrInfo.h adds a MachineInstr overload in namespace llvm (found via ADL
+// when predicates are instantiated with MachineInstr). Later commits in this
+// series add (MCInstrInfo, unsigned Opcode) and (MCInstrInfo, MCInst) overloads
+// so that MC-layer callers can write e.g. isFLAT(MII, Inst) without extracting
+// a descriptor first.
+
+constexpr uint64_t getTSFlags(const MCInstrDesc &Desc) { return Desc.TSFlags; }
+
+template <typename... T> constexpr bool isSALU(const T &...O) {
+  return getTSFlags(O...) & SALU;
+}
+template <typename... T> constexpr bool isVALU(const T &...O) {
+  return getTSFlags(O...) & VALU;
+}
+template <typename... T> constexpr bool isSOP1(const T &...O) {
+  return getTSFlags(O...) & SOP1;
+}
+template <typename... T> constexpr bool isSOP2(const T &...O) {
+  return getTSFlags(O...) & SOP2;
+}
+template <typename... T> constexpr bool isSOPC(const T &...O) {
+  return getTSFlags(O...) & SOPC;
+}
+template <typename... T> constexpr bool isSOPK(const T &...O) {
+  return getTSFlags(O...) & SOPK;
+}
+template <typename... T> constexpr bool isSOPP(const T &...O) {
+  return getTSFlags(O...) & SOPP;
+}
+template <typename... T> constexpr bool isVOP1(const T &...O) {
+  return getTSFlags(O...) & VOP1;
+}
+template <typename... T> constexpr bool isVOP2(const T &...O) {
+  return getTSFlags(O...) & VOP2;
+}
+template <typename... T> constexpr bool isVOPC(const T &...O) {
+  return getTSFlags(O...) & VOPC;
+}
+template <typename... T> constexpr bool isVOP3(const T &...O) {
+  return getTSFlags(O...) & VOP3;
+}
+template <typename... T> constexpr bool isVOP3P(const T &...O) {
+  return getTSFlags(O...) & VOP3P;
+}
+template <typename... T> constexpr bool isVINTRP(const T &...O) {
+  return getTSFlags(O...) & VINTRP;
+}
+template <typename... T> constexpr bool isSDWA(const T &...O) {
+  return getTSFlags(O...) & SDWA;
+}
+template <typename... T> constexpr bool isDPP(const T &...O) {
+  return getTSFlags(O...) & DPP;
+}
+template <typename... T> constexpr bool isTRANS(const T &...O) {
+  return getTSFlags(O...) & TRANS;
+}
+template <typename... T> constexpr bool isMUBUF(const T &...O) {
+  return getTSFlags(O...) & MUBUF;
+}
+template <typename... T> constexpr bool isMTBUF(const T &...O) {
+  return getTSFlags(O...) & MTBUF;
+}
+template <typename... T> constexpr bool isSMRD(const T &...O) {
+  return getTSFlags(O...) & SMRD;
+}
+template <typename... T> constexpr bool isMIMG(const T &...O) {
+  return getTSFlags(O...) & MIMG;
+}
+template <typename... T> constexpr bool isVIMAGE(const T &...O) {
+  return getTSFlags(O...) & VIMAGE;
+}
+template <typename... T> constexpr bool isVSAMPLE(const T &...O) {
+  return getTSFlags(O...) & VSAMPLE;
+}
+template <typename... T> constexpr bool isEXP(const T &...O) {
+  return getTSFlags(O...) & EXP;
+}
+template <typename... T> constexpr bool isFLAT(const T &...O) {
+  return getTSFlags(O...) & FLAT;
+}
+template <typename... T> constexpr bool isDS(const T &...O) {
+  return getTSFlags(O...) & DS;
+}
+template <typename... T> constexpr bool isSpill(const T &...O) {
+  return getTSFlags(O...) & Spill;
+}
+template <typename... T> constexpr bool isLDSDIR(const T &...O) {
+  return getTSFlags(O...) & LDSDIR;
+}
+template <typename... T> constexpr bool isVINTERP(const T &...O) {
+  return getTSFlags(O...) & VINTERP;
+}
+template <typename... T> constexpr bool isWQM(const T &...O) {
+  return getTSFlags(O...) & WQM;
+}
+template <typename... T> constexpr bool isDisableWQM(const T &...O) {
+  return getTSFlags(O...) & DisableWQM;
+}
+template <typename... T> constexpr bool isGather4(const T &...O) {
+  return getTSFlags(O...) & Gather4;
+}
+template <typename... T> constexpr bool usesTENSOR_CNT(const T &...O) {
+  return getTSFlags(O...) & TENSOR_CNT;
+}
+template <typename... T> constexpr bool isScalarStore(const T &...O) {
+  return getTSFlags(O...) & SCALAR_STORE;
+}
+template <typename... T> constexpr bool isFixedSize(const T &...O) {
+  return getTSFlags(O...) & FIXED_SIZE;
+}
+template <typename... T> constexpr bool usesASYNC_CNT(const T &...O) {
+  return getTSFlags(O...) & ASYNC_CNT;
+}
+template <typename... T> constexpr bool hasVOP3OpSel(const T &...O) {
+  return getTSFlags(O...) & VOP3_OPSEL;
+}
+template <typename... T> constexpr bool isMaybeAtomic(const T &...O) {
+  return getTSFlags(O...) & maybeAtomic;
+}
+template <typename... T> constexpr bool hasFPClamp(const T &...O) {
+  return getTSFlags(O...) & FPClamp;
+}
+template <typename... T> constexpr bool hasIntClamp(const T &...O) {
+  return getTSFlags(O...) & IntClamp;
+}
+template <typename... T> constexpr bool hasClampLo(const T &...O) {
+  return getTSFlags(O...) & ClampLo;
+}
+template <typename... T> constexpr bool hasClampHi(const T &...O) {
+  return getTSFlags(O...) & ClampHi;
+}
+template <typename... T> constexpr bool isPacked(const T &...O) {
+  return getTSFlags(O...) & IsPacked;
+}
+template <typename... T> constexpr bool isD16Buf(const T &...O) {
+  return getTSFlags(O...) & D16Buf;
+}
+template <typename... T> constexpr bool isFlatGlobal(const T &...O) {
+  return getTSFlags(O...) & FlatGlobal;
+}
+template <typename... T> constexpr bool usesFPDPRounding(const T &...O) {
+  return getTSFlags(O...) & FPDPRounding;
+}
+template <typename... T> constexpr bool isFPAtomic(const T &...O) {
+  return getTSFlags(O...) & FPAtomic;
+}
+template <typename... T> constexpr bool isMAI(const T &...O) {
+  return getTSFlags(O...) & IsMAI;
+}
+template <typename... T> constexpr bool isDOT(const T &...O) {
+  return getTSFlags(O...) & IsDOT;
+}
+template <typename... T> constexpr bool isFlatScratch(const T &...O) {
+  return getTSFlags(O...) & FlatScratch;
+}
+template <typename... T> constexpr bool isAtomicNoRet(const T &...O) {
+  return getTSFlags(O...) & IsAtomicNoRet;
+}
+template <typename... T> constexpr bool isAtomicRet(const T &...O) {
+  return getTSFlags(O...) & IsAtomicRet;
+}
+template <typename... T> constexpr bool isWMMA(const T &...O) {
+  return getTSFlags(O...) & IsWMMA;
+}
+template <typename... T> constexpr bool isTiedSourceNotRead(const T &...O) {
+  return getTSFlags(O...) & TiedSourceNotRead;
+}
+template <typename... T> constexpr bool isNeverUniform(const T &...O) {
+  return getTSFlags(O...) & IsNeverUniform;
+}
+template <typename... T> constexpr bool isGWS(const T &...O) {
+  return getTSFlags(O...) & GWS;
+}
+template <typename... T> constexpr bool isSWMMAC(const T &...O) {
+  return getTSFlags(O...) & IsSWMMAC;
+}
+template <typename... T> constexpr bool usesVM_CNT(const T &...O) {
+  return getTSFlags(O...) & VM_CNT;
+}
+template <typename... T> constexpr bool usesLGKM_CNT(const T &...O) {
----------------
vpykhtin wrote:

This provides convenience by allowing the same predicate body to work with multiple argument types through the getTSFlags shim. For example:

```
usesVM_CNT(Desc)             // MCInstrDesc &
usesVM_CNT(MII, Instr)       // MCInstrInfo &, MCInst &
usesVM_CNT(MII, Opcode)      // MCInstrInfo &, unsigned
usesVM_CNT(MI)               // MachineInstr &
usesVM_CNT(TII, Opcode)      // TargetInstrInfo &, unsigned
```

This PR includes only the getTSFlags overloads needed for this change; additional overloads will follow.

This design also allows getTSFlags overloads to be defined close to the types they depend on. For instance, getTSFlags(MachineInstr&) can live where MachineInstr is available, avoiding the need to centralise all overloads or pull in all their dependencies.

https://github.com/llvm/llvm-project/pull/201512


More information about the llvm-commits mailing list