[clang] [llvm] [TargetParser][Clang] Parse Intel GPU architecture names (PR #229247)

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 13:52:12 PDT 2026


================
@@ -63,3 +73,61 @@ std::string llvm::IntelGPU::getNumericArchName(uint32_t GPUIPVersion) {
   return ("xe_" + Twine(Major) + "." + Twine(Minor) + "." + Twine(Revision))
       .str();
 }
+
+StringRef llvm::IntelGPU::getArchName(GPUKind Kind) {
+  switch (Kind) {
+  case GK_NONE:
+    return "";
+#define INTEL_GPU(NAME, KIND, MAJOR, MINOR, IGCA_TARGET, IGCA_FEATURE_SETS)    \
+  case GK_##KIND:                                                              \
+    return NAME;
+#define INTEL_GPU_COMPAT(NAME, KIND, IGCA_TARGET, IGCA_FEATURE_SETS)           \
+  case GK_##KIND:                                                              \
+    return NAME;
+#include "llvm/TargetParser/IntelGPUTargetParser.def"
+  }
+  llvm_unreachable("invalid Intel GPU kind");
+}
+
+// Read a numeric name, e.g. "xe_12.60.7", into the GPU IP version it spells.
+// The revision may be omitted.
+static bool parseNumericArchName(StringRef Name, uint32_t &GPUIPVersion) {
+  if (!Name.consume_front("xe_"))
+    return false;
+
+  StringRef MajorStr, MinorStr, RevisionStr;
+  std::tie(MajorStr, Name) = Name.split('.');
+  // A separator with no revision after it is malformed.
+  const bool HasRevision = Name.contains('.');
+  std::tie(MinorStr, RevisionStr) = Name.split('.');
+  uint32_t Major, Minor, Revision = 0;
+  if (MajorStr.getAsInteger(10, Major) || MinorStr.getAsInteger(10, Minor))
+    return false;
+  if (HasRevision && RevisionStr.getAsInteger(10, Revision))
+    return false;
+
+  // Each field must fit its GPU IP version field.
+  if (Major > GPUIPMajorMask || Minor > GPUIPMinorMask ||
+      Revision > GPUIPRevisionMask)
+    return false;
+  GPUIPVersion = packDevice(Major, Minor) | Revision;
+  return true;
+}
+
+GPUKind llvm::IntelGPU::parseArch(StringRef Name) {
+  GPUKind Kind = StringSwitch<GPUKind>(Name)
+#define INTEL_GPU(NAME, KIND, MAJOR, MINOR, IGCA_TARGET, IGCA_FEATURE_SETS)    \
+  .Case(NAME, GK_##KIND)
----------------
bader wrote:

BTW, we can make the code simpler if arch values use unified prefix e.g. "xe-".
Current implementation defines "xe-" for "human-friendly" values and "xe_" for numeric values.
@gmlueck is it possible to use the same prefix for all values?

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


More information about the cfe-commits mailing list