[Mlir-commits] [mlir] [MLIR][XeGPU] Enable `isa<>` check for uarch (PR #204577)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jun 18 05:31:27 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Artem Kroviakov (akroviakov)
<details>
<summary>Changes</summary>
This PR replaces the string-based uarch identification with `isa<>` checks of the type directly.
---
Full diff: https://github.com/llvm/llvm-project/pull/204577.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h (+13-13)
- (modified) mlir/include/mlir/Dialect/XeGPU/uArch/uArchBase.h (+40-7)
- (modified) mlir/lib/Dialect/XeGPU/Utils/XeGPUUtils.cpp (+1-3)
``````````diff
diff --git a/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h b/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
index eeb1100cc8eab..0b0e608db1970 100644
--- a/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
+++ b/mlir/include/mlir/Dialect/XeGPU/uArch/IntelGpuXe2.h
@@ -31,13 +31,17 @@ namespace xegpu {
namespace uArch {
struct Xe2Plus : public uArch {
- Xe2Plus(StringRef archName, StringRef archDescription,
- llvm::ArrayRef<const Instruction *> instructionRegistry,
+ Xe2Plus(Kind kind, llvm::ArrayRef<const Instruction *> instructionRegistry,
const XeCoreInfo &xeCore)
- : uArch(archName, archDescription, instructionRegistry), xeCore(xeCore) {}
+ : uArch(kind, instructionRegistry), xeCore(xeCore) {}
int getSubgroupSize() const override { return 16; }
unsigned getGeneralPackedFormatBitSize() const override { return 32; }
+ static bool classof(const uArch *u) {
+ return u->getKind() >= Kind::Xe2Plus_First &&
+ u->getKind() <= Kind::Xe2Plus_Last;
+ }
+
protected:
XeCoreInfo xeCore;
};
@@ -292,11 +296,10 @@ struct PVCuArch final : public Xe2Plus {
}
PVCuArch()
- : Xe2Plus("pvc", // archName
- "Ponte Vecchio Architecture", // archDescription
- getInstructionRegistryArr(),
+ : Xe2Plus(Kind::PVC, getInstructionRegistryArr(),
XeCoreInfo(8, SharedMemory(512 * 1024, 4), 8, 8) // xeCore
) {}
+ static bool classof(const uArch *u) { return u->getKind() == Kind::PVC; }
static const uArch *getInstance() {
static const PVCuArch instance;
return reinterpret_cast<const uArch *>(&instance);
@@ -318,11 +321,10 @@ struct BMGuArch : public Xe2Plus {
}
BMGuArch()
- : Xe2Plus("bmg", // archName
- "Battlemage Architecture", // archDescription
- getInstructionRegistryArr(),
+ : Xe2Plus(Kind::BMG, getInstructionRegistryArr(),
XeCoreInfo(8, SharedMemory(256 * 1024, 4), 8, 8) // xeCore
) {}
+ static bool classof(const uArch *u) { return u->getKind() == Kind::BMG; }
static const uArch *getInstance() {
static const BMGuArch instance;
return reinterpret_cast<const uArch *>(&instance);
@@ -345,13 +347,12 @@ struct CRIuArch : public Xe2Plus {
}
CRIuArch()
- : Xe2Plus("cri", // archName
- "Crescent Island Architecture", // archDescription
- getInstructionRegistryArr(),
+ : Xe2Plus(Kind::CRI, getInstructionRegistryArr(),
// Using bmg config as placeholder
// TODO: Update to actual XeCore and SharedMemory config
XeCoreInfo(8, SharedMemory(256 * 1024, 4), 8, 8) // xeCore
) {}
+ static bool classof(const uArch *u) { return u->getKind() == Kind::CRI; }
static const uArch *getInstance() {
static const CRIuArch instance;
return reinterpret_cast<const uArch *>(&instance);
@@ -367,7 +368,6 @@ inline const uArch *getUArch(llvm::StringRef archName) {
return CRIuArch::getInstance();
return nullptr;
}
-
} // namespace uArch
} // namespace xegpu
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/XeGPU/uArch/uArchBase.h b/mlir/include/mlir/Dialect/XeGPU/uArch/uArchBase.h
index 147a56a52c188..7e3576637ed12 100644
--- a/mlir/include/mlir/Dialect/XeGPU/uArch/uArchBase.h
+++ b/mlir/include/mlir/Dialect/XeGPU/uArch/uArchBase.h
@@ -24,6 +24,7 @@
#include "mlir/IR/Types.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Casting.h"
namespace mlir {
namespace xegpu {
@@ -152,16 +153,49 @@ struct CacheInfo {
};
struct uArch {
+ enum class Kind {
+ // Xe2 family
+ Xe2Plus_First,
+ PVC = Xe2Plus_First,
+ BMG,
+ CRI,
+ Xe2Plus_Last = CRI,
+ };
+
// Constructor
- uArch(StringRef name, StringRef description,
- llvm::ArrayRef<const Instruction *> instructionRegistry)
- : name(name), description(description) {
+ uArch(Kind kind, llvm::ArrayRef<const Instruction *> instructionRegistry)
+ : kind(kind) {
for (const Instruction *instr : instructionRegistry)
this->instructionRegistry[instr->getInstructionKind()] = instr;
}
virtual ~uArch() = default;
- StringRef getName() const { return name; }
- StringRef getDescription() const { return description; }
+ Kind getKind() const { return kind; }
+ StringRef getName() const { return getUArchName(kind); }
+ StringRef getDescription() const { return getUArchDescription(kind); }
+
+ static StringRef getUArchName(Kind k) {
+ switch (k) {
+ case Kind::PVC:
+ return "pvc";
+ case Kind::BMG:
+ return "bmg";
+ case Kind::CRI:
+ return "cri";
+ }
+ llvm_unreachable("Unknown uArch::Kind");
+ }
+
+ static StringRef getUArchDescription(Kind k) {
+ switch (k) {
+ case Kind::PVC:
+ return "Ponte Vecchio Architecture";
+ case Kind::BMG:
+ return "Battlemage Architecture";
+ case Kind::CRI:
+ return "Crescent Island Architecture";
+ }
+ llvm_unreachable("Unknown uArch::Kind");
+ }
virtual int getSubgroupSize() const = 0;
virtual unsigned getGeneralPackedFormatBitSize() const = 0;
@@ -177,8 +211,7 @@ struct uArch {
}
protected:
- StringRef name;
- StringRef description;
+ Kind kind;
llvm::SmallDenseMap<InstructionKind, const Instruction *, 32>
instructionRegistry;
};
diff --git a/mlir/lib/Dialect/XeGPU/Utils/XeGPUUtils.cpp b/mlir/lib/Dialect/XeGPU/Utils/XeGPUUtils.cpp
index 735dd93e2ac14..24999f85c1268 100644
--- a/mlir/lib/Dialect/XeGPU/Utils/XeGPUUtils.cpp
+++ b/mlir/lib/Dialect/XeGPU/Utils/XeGPUUtils.cpp
@@ -786,9 +786,7 @@ bool xegpu::requireTranspose(const xegpu::DistributeLayoutAttr layout,
const xegpu::uArch::uArch *uArch) {
// Return false for unsupported targets.
// TODO: Add more support or move to target info.
- if (uArch->getName().equals_insensitive("pvc") &&
- uArch->getName().equals_insensitive("bmg") &&
- uArch->getName().equals_insensitive("cri"))
+ if (!isa<xegpu::uArch::Xe2Plus>(uArch))
return false;
if (!layout)
return false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/204577
More information about the Mlir-commits
mailing list