Repository: llvm/llvm-project
Pull request #137070: [Clang][NFC] Move OffloadArch enum to a generic location
Author: login: jzc
Labels: name: clang
description: Clang issues not falling into any other category
name: clang:frontend
description: Language frontend issues, e.g. anything involving "Sema"
name: clang:codegen
description: IR generation bugs: mangling, exceptions, etc.
name: clang:openmp
description: OpenMP related changes to Clang
name: SYCL
description: https://registry.khronos.org/SYCL
Created: 2025-04-23T22:07:26Z | Merged: 2025-04-25T16:37:56Z

Currently, the OffloadArch enum is defined Cuda.h. This PR moves the definition to a more generic location in OffloadArch.h/cpp. 


Diff:
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index c4eb7b7cac1d6..d6a22a7af559b 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_BASIC_CUDA_H
 #define LLVM_CLANG_BASIC_CUDA_H
 
+#include "clang/Basic/OffloadArch.h"
+
 namespace llvm {
 class StringRef;
 class Twine;
@@ -54,98 +56,6 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
-enum class OffloadArch {
-  UNUSED,
-  UNKNOWN,
-  // TODO: Deprecate and remove GPU architectures older than sm_52.
-  SM_20,
-  SM_21,
-  SM_30,
-  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
-  SM_32_,
-  SM_35,
-  SM_37,
-  SM_50,
-  SM_52,
-  SM_53,
-  SM_60,
-  SM_61,
-  SM_62,
-  SM_70,
-  SM_72,
-  SM_75,
-  SM_80,
-  SM_86,
-  SM_87,
-  SM_89,
-  SM_90,
-  SM_90a,
-  SM_100,
-  SM_100a,
-  SM_101,
-  SM_101a,
-  SM_120,
-  SM_120a,
-  GFX600,
-  GFX601,
-  GFX602,
-  GFX700,
-  GFX701,
-  GFX702,
-  GFX703,
-  GFX704,
-  GFX705,
-  GFX801,
-  GFX802,
-  GFX803,
-  GFX805,
-  GFX810,
-  GFX9_GENERIC,
-  GFX900,
-  GFX902,
-  GFX904,
-  GFX906,
-  GFX908,
-  GFX909,
-  GFX90a,
-  GFX90c,
-  GFX9_4_GENERIC,
-  GFX942,
-  GFX950,
-  GFX10_1_GENERIC,
-  GFX1010,
-  GFX1011,
-  GFX1012,
-  GFX1013,
-  GFX10_3_GENERIC,
-  GFX1030,
-  GFX1031,
-  GFX1032,
-  GFX1033,
-  GFX1034,
-  GFX1035,
-  GFX1036,
-  GFX11_GENERIC,
-  GFX1100,
-  GFX1101,
-  GFX1102,
-  GFX1103,
-  GFX1150,
-  GFX1151,
-  GFX1152,
-  GFX1153,
-  GFX12_GENERIC,
-  GFX1200,
-  GFX1201,
-  AMDGCNSPIRV,
-  Generic, // A processor model named 'generic' if the target backend defines a
-           // public one.
-  LAST,
-
-  CudaDefault = OffloadArch::SM_52,
-  HIPDefault = OffloadArch::GFX906,
-};
-
 enum class CUDAFunctionTarget {
   Device,
   Global,
@@ -154,21 +64,6 @@ enum class CUDAFunctionTarget {
   InvalidTarget
 };
 
-static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
-  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
-}
-
-static inline bool IsAMDOffloadArch(OffloadArch A) {
-  // Generic processor model is for testing only.
-  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
-}
-
-const char *OffloadArchToString(OffloadArch A);
-const char *OffloadArchToVirtualArchString(OffloadArch A);
-
-// The input should have the form "sm_20".
-OffloadArch StringToOffloadArch(llvm::StringRef S);
-
 /// Get the earliest CudaVersion that supports the given OffloadArch.
 CudaVersion MinVersionForOffloadArch(OffloadArch A);
 
diff --git a/clang/include/clang/Basic/OffloadArch.h b/clang/include/clang/Basic/OffloadArch.h
new file mode 100644
index 0000000000000..c5ccd17e7a8be
--- /dev/null
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -0,0 +1,128 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  LAST,
+
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
+};
+
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
+}
+
+static inline bool IsAMDOffloadArch(OffloadArch A) {
+  // Generic processor model is for testing only.
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
+}
+
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
+
+// Convert a string to an OffloadArch enum value. Returns
+// OffloadArch::UNKNOWN if the string is not recognized.
+OffloadArch StringToOffloadArch(llvm::StringRef S);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_OFFLOADARCH_H
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 331dfbb3f4b67..419fd9bc136cf 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -76,6 +76,7 @@ add_clang_library(clangBasic
   MakeSupport.cpp
   Module.cpp
   ObjCRuntime.cpp
+  OffloadArch.cpp
   OpenCLOptions.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index 68d042eca2492..8ea242911a2ba 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -73,123 +73,6 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
   return CudaVersion::UNKNOWN;
 }
 
-namespace {
-struct OffloadArchToStringMap {
-  OffloadArch arch;
-  const char *arch_name;
-  const char *virtual_arch_name;
-};
-} // namespace
-
-#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
-#define SM(sm) SM2(sm, "compute_" #sm)
-#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
-static const OffloadArchToStringMap arch_names[] = {
-    // clang-format off
-    {OffloadArch::UNUSED, "", ""},
-    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
-    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
-    SM(50), SM(52), SM(53),          // Maxwell
-    SM(60), SM(61), SM(62),          // Pascal
-    SM(70), SM(72),                  // Volta
-    SM(75),                          // Turing
-    SM(80), SM(86),                  // Ampere
-    SM(87),                          // Jetson/Drive AGX Orin
-    SM(89),                          // Ada Lovelace
-    SM(90),                          // Hopper
-    SM(90a),                         // Hopper
-    SM(100),                         // Blackwell
-    SM(100a),                        // Blackwell
-    SM(101),                         // Blackwell
-    SM(101a),                        // Blackwell
-    SM(120),                         // Blackwell
-    SM(120a),                        // Blackwell
-    GFX(600),  // gfx600
-    GFX(601),  // gfx601
-    GFX(602),  // gfx602
-    GFX(700),  // gfx700
-    GFX(701),  // gfx701
-    GFX(702),  // gfx702
-    GFX(703),  // gfx703
-    GFX(704),  // gfx704
-    GFX(705),  // gfx705
-    GFX(801),  // gfx801
-    GFX(802),  // gfx802
-    GFX(803),  // gfx803
-    GFX(805),  // gfx805
-    GFX(810),  // gfx810
-    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
-    GFX(900),  // gfx900
-    GFX(902),  // gfx902
-    GFX(904),  // gfx903
-    GFX(906),  // gfx906
-    GFX(908),  // gfx908
-    GFX(909),  // gfx909
-    GFX(90a),  // gfx90a
-    GFX(90c),  // gfx90c
-    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
-    GFX(942),  // gfx942
-    GFX(950),  // gfx950
-    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
-    GFX(1010), // gfx1010
-    GFX(1011), // gfx1011
-    GFX(1012), // gfx1012
-    GFX(1013), // gfx1013
-    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
-    GFX(1030), // gfx1030
-    GFX(1031), // gfx1031
-    GFX(1032), // gfx1032
-    GFX(1033), // gfx1033
-    GFX(1034), // gfx1034
-    GFX(1035), // gfx1035
-    GFX(1036), // gfx1036
-    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
-    GFX(1100), // gfx1100
-    GFX(1101), // gfx1101
-    GFX(1102), // gfx1102
-    GFX(1103), // gfx1103
-    GFX(1150), // gfx1150
-    GFX(1151), // gfx1151
-    GFX(1152), // gfx1152
-    GFX(1153), // gfx1153
-    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
-    GFX(1200), // gfx1200
-    GFX(1201), // gfx1201
-    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
-    {OffloadArch::Generic, "generic", ""},
-    // clang-format on
-};
-#undef SM
-#undef SM2
-#undef GFX
-
-const char *OffloadArchToString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->arch_name;
-}
-
-const char *OffloadArchToVirtualArchString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->virtual_arch_name;
-}
-
-OffloadArch StringToOffloadArch(llvm::StringRef S) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
-  if (result == std::end(arch_names))
-    return OffloadArch::UNKNOWN;
-  return result->arch;
-}
-
 CudaVersion MinVersionForOffloadArch(OffloadArch A) {
   if (A == OffloadArch::UNKNOWN)
     return CudaVersion::UNKNOWN;
diff --git a/clang/lib/Basic/OffloadArch.cpp b/clang/lib/Basic/OffloadArch.cpp
new file mode 100644
index 0000000000000..5e29742478b99
--- /dev/null
+++ b/clang/lib/Basic/OffloadArch.cpp
@@ -0,0 +1,126 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch Arch;
+  const char *ArchName;
+  const char *VirtualArchName;
+};
+} // namespace
+
+#define SM(sm) {OffloadArch::SM_##sm, "sm_" #sm, "compute_" #sm}
+#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
+static const OffloadArchToStringMap ArchNames[] = {
+    // clang-format off
+    {OffloadArch::UNUSED, "", ""},
+    SM(20), {OffloadArch::SM_21, "sm_21", "compute_20"}, // Fermi
+    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
+    SM(50), SM(52), SM(53),          // Maxwell
+    SM(60), SM(61), SM(62),          // Pascal
+    SM(70), SM(72),                  // Volta
+    SM(75),                          // Turing
+    SM(80), SM(86),                  // Ampere
+    SM(87),                          // Jetson/Drive AGX Orin
+    SM(89),                          // Ada Lovelace
+    SM(90),                          // Hopper
+    SM(90a),                         // Hopper
+    SM(100),                         // Blackwell
+    SM(100a),                        // Blackwell
+    SM(101),                         // Blackwell
+    SM(101a),                        // Blackwell
+    SM(120),                         // Blackwell
+    SM(120a),                        // Blackwell
+    GFX(600),  // gfx600
+    GFX(601),  // gfx601
+    GFX(602),  // gfx602
+    GFX(700),  // gfx700
+    GFX(701),  // gfx701
+    GFX(702),  // gfx702
+    GFX(703),  // gfx703
+    GFX(704),  // gfx704
+    GFX(705),  // gfx705
+    GFX(801),  // gfx801
+    GFX(802),  // gfx802
+    GFX(803),  // gfx803
+    GFX(805),  // gfx805
+    GFX(810),  // gfx810
+    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
+    GFX(900),  // gfx900
+    GFX(902),  // gfx902
+    GFX(904),  // gfx903
+    GFX(906),  // gfx906
+    GFX(908),  // gfx908
+    GFX(909),  // gfx909
+    GFX(90a),  // gfx90a
+    GFX(90c),  // gfx90c
+    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
+    GFX(942),  // gfx942
+    GFX(950),  // gfx950
+    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
+    GFX(1010), // gfx1010
+    GFX(1011), // gfx1011
+    GFX(1012), // gfx1012
+    GFX(1013), // gfx1013
+    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
+    GFX(1030), // gfx1030
+    GFX(1031), // gfx1031
+    GFX(1032), // gfx1032
+    GFX(1033), // gfx1033
+    GFX(1034), // gfx1034
+    GFX(1035), // gfx1035
+    GFX(1036), // gfx1036
+    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
+    GFX(1100), // gfx1100
+    GFX(1101), // gfx1101
+    GFX(1102), // gfx1102
+    GFX(1103), // gfx1103
+    GFX(1150), // gfx1150
+    GFX(1151), // gfx1151
+    GFX(1152), // gfx1152
+    GFX(1153), // gfx1153
+    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
+    GFX(1200), // gfx1200
+    GFX(1201), // gfx1201
+    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
+    {OffloadArch::Generic, "generic", ""},
+    // clang-format on
+};
+#undef SM
+#undef GFX
+
+const char *OffloadArchToString(OffloadArch A) {
+  auto Result =
+      llvm::find_if(ArchNames, [A](const OffloadArchToStringMap &Map) {
+        return A == Map.Arch;
+      });
+  if (Result == std::end(ArchNames))
+    return "unknown";
+  return Result->ArchName;
+}
+
+const char *OffloadArchToVirtualArchString(OffloadArch A) {
+  auto Result =
+      llvm::find_if(ArchNames, [A](const OffloadArchToStringMap &Map) {
+        return A == Map.Arch;
+      });
+  if (Result == std::end(ArchNames))
+    return "unknown";
+  return Result->VirtualArchName;
+}
+
+OffloadArch StringToOffloadArch(llvm::StringRef S) {
+  auto Result =
+      llvm::find_if(ArchNames, [S](const OffloadArchToStringMap &Map) {
+        return S == Map.ArchName;
+      });
+  if (Result == std::end(ArchNames))
+    return OffloadArch::UNKNOWN;
+  return Result->Arch;
+}
+
+} // namespace clang


Reviews:
user: login: asudarsa
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T22:57:03Z
user: login: jhuber6
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T22:58:37Z
user: login: jhuber6
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:03:06Z
user: login: jhuber6
body: Thanks
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:13:11Z
user: login: sarnex
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-24T16:15:21Z
user: login: jhuber6
body: LG, I'll merge it once CI's green. Thanks.
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:19:14Z
user: login: jzc
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:19:16Z
user: login: jzc
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:19:44Z
user: login: jzc
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:20:45Z
user: login: jzc
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:21:12Z
user: login: shiltian
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:21:32Z
user: login: jzc
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T16:32:13Z
user: login: asudarsa
body: LGTM. Thanks
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-25T16:36:55Z

Review comments:
diff_hunk: @@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
+  LAST,
+
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
+};
+
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
+}
+
+static inline bool IsAMDOffloadArch(OffloadArch A) {
+  // Generic processor model is for testing only.
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
+}
+
+static inline bool IsIntelCPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::GRANITERAPIDS && Arch < OffloadArch::BMG_G21;
+}
+
+static inline bool IsIntelGPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::BMG_G21 && Arch < OffloadArch::LAST;
+}
+
+static inline bool IsIntelOffloadArch(OffloadArch Arch) {
+  return IsIntelCPUArch(Arch) || IsIntelGPUArch(Arch);
+}
+
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
+
+// The input should have the form "sm_20".
path: clang/include/clang/Basic/OffloadArch.h
user: login: asudarsa
body: Does this comment need to be updated?

Thanks
created_at: 2025-04-23T22:57:03Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
path: clang/include/clang/Basic/OffloadArch.h
user: login: jhuber6
body: Are these new? If so that should be in a follow-up after an NFC move.
created_at: 2025-04-23T22:58:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,126 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <algorithm>
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch arch;
+  const char *arch_name;
+  const char *virtual_arch_name;
path: clang/lib/Basic/OffloadArch.cpp
user: login: jhuber6
body: While we're here, can we update these to the LLVM style?
```suggestion
  OffloadArch Arch
  const char *ArchName;
  const char *VirtualArchName;
```
created_at: 2025-04-24T16:03:05Z
author_association: CONTRIBUTOR
diff_hunk: @@ -97,30 +97,30 @@ static const OffloadArchToStringMap arch_names[] = {
 #undef GFX
 
 const char *OffloadArchToString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
+  auto Result = std::find_if(
+      std::begin(ArchNames), std::end(ArchNames),
path: clang/lib/Basic/OffloadArch.cpp
user: login: jhuber6
body: Extremely small nit. Should be able to use `llvm::find_if` to make this shorter.
created_at: 2025-04-24T16:13:09Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
path: clang/include/clang/Basic/OffloadArch.h
user: login: jzc
body: That's reasonable. I'll introduce these later.
created_at: 2025-04-24T16:19:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,126 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <algorithm>
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch arch;
+  const char *arch_name;
+  const char *virtual_arch_name;
path: clang/lib/Basic/OffloadArch.cpp
user: login: jzc
body: Good catch. [d43ae13](https://github.com/llvm/llvm-project/pull/137070/commits/d43ae1368c8ac5375fa63498697083fe02fe1941)
created_at: 2025-04-24T16:19:44Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
+  LAST,
+
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
+};
+
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
+}
+
+static inline bool IsAMDOffloadArch(OffloadArch A) {
+  // Generic processor model is for testing only.
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
+}
+
+static inline bool IsIntelCPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::GRANITERAPIDS && Arch < OffloadArch::BMG_G21;
+}
+
+static inline bool IsIntelGPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::BMG_G21 && Arch < OffloadArch::LAST;
+}
+
+static inline bool IsIntelOffloadArch(OffloadArch Arch) {
+  return IsIntelCPUArch(Arch) || IsIntelGPUArch(Arch);
+}
+
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
+
+// The input should have the form "sm_20".
path: clang/include/clang/Basic/OffloadArch.h
user: login: jzc
body: Updated in [91b7c9d](https://github.com/llvm/llvm-project/pull/137070/commits/91b7c9de8cfb2df2075fcde974ba6221a44a4a20)
created_at: 2025-04-24T16:20:45Z
author_association: CONTRIBUTOR
diff_hunk: @@ -97,30 +97,30 @@ static const OffloadArchToStringMap arch_names[] = {
 #undef GFX
 
 const char *OffloadArchToString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
+  auto Result = std::find_if(
+      std::begin(ArchNames), std::end(ArchNames),
path: clang/lib/Basic/OffloadArch.cpp
user: login: jzc
body: [9c36e30](https://github.com/llvm/llvm-project/pull/137070/commits/9c36e3020b811b635b9a0d0322ec0518849b21f7)
created_at: 2025-04-24T16:21:12Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,128 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch Arch;
+  const char *ArchName;
+  const char *VirtualArchName;
+};
+} // namespace
+
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
path: clang/lib/Basic/OffloadArch.cpp
user: login: shiltian
body: I'd just define the special `sm_20` w/o using this macro
created_at: 2025-04-24T16:21:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,128 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch Arch;
+  const char *ArchName;
+  const char *VirtualArchName;
+};
+} // namespace
+
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
path: clang/lib/Basic/OffloadArch.cpp
user: login: jzc
body: Good point, that is simpler - [bd5e7a2](https://github.com/llvm/llvm-project/pull/137070/commits/bd5e7a26f48a1afcdfdb4e14415572a0d2a72875)
created_at: 2025-04-24T16:32:13Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-04-23T22:07:44Z
body: <!--LLVM NEW CONTRIBUTOR COMMENT-->

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/).
author_association: NONE
user: login: llvmbot
created_at: 2025-04-23T22:08:17Z
body: 
<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Justin Cai (jzc)

<details>
<summary>Changes</summary>

Currently, the OffloadArch enum is defined Cuda.h. This PR moves the definition to a more generic location in OffloadArch.h/cpp and also adds an initial set of Intel OffloadArch values that will be used in SYCL compilation.

---
Full diff: https://github.com/llvm/llvm-project/pull/137070.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/Cuda.h (+2-107) 
- (added) clang/include/clang/Basic/OffloadArch.h (+143) 
- (modified) clang/lib/Basic/CMakeLists.txt (+1) 
- (modified) clang/lib/Basic/Cuda.cpp (-117) 
- (added) clang/lib/Basic/OffloadArch.cpp (+133) 
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+2) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2) 
- (modified) clang/unittests/Basic/CMakeLists.txt (+1) 
- (added) clang/unittests/Basic/OffloadArchTest.cpp (+36) 


``````````diff
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index c4eb7b7cac1d6..d6a22a7af559b 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_BASIC_CUDA_H
 #define LLVM_CLANG_BASIC_CUDA_H
 
+#include "clang/Basic/OffloadArch.h"
+
 namespace llvm {
 class StringRef;
 class Twine;
@@ -54,98 +56,6 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
-enum class OffloadArch {
-  UNUSED,
-  UNKNOWN,
-  // TODO: Deprecate and remove GPU architectures older than sm_52.
-  SM_20,
-  SM_21,
-  SM_30,
-  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
-  SM_32_,
-  SM_35,
-  SM_37,
-  SM_50,
-  SM_52,
-  SM_53,
-  SM_60,
-  SM_61,
-  SM_62,
-  SM_70,
-  SM_72,
-  SM_75,
-  SM_80,
-  SM_86,
-  SM_87,
-  SM_89,
-  SM_90,
-  SM_90a,
-  SM_100,
-  SM_100a,
-  SM_101,
-  SM_101a,
-  SM_120,
-  SM_120a,
-  GFX600,
-  GFX601,
-  GFX602,
-  GFX700,
-  GFX701,
-  GFX702,
-  GFX703,
-  GFX704,
-  GFX705,
-  GFX801,
-  GFX802,
-  GFX803,
-  GFX805,
-  GFX810,
-  GFX9_GENERIC,
-  GFX900,
-  GFX902,
-  GFX904,
-  GFX906,
-  GFX908,
-  GFX909,
-  GFX90a,
-  GFX90c,
-  GFX9_4_GENERIC,
-  GFX942,
-  GFX950,
-  GFX10_1_GENERIC,
-  GFX1010,
-  GFX1011,
-  GFX1012,
-  GFX1013,
-  GFX10_3_GENERIC,
-  GFX1030,
-  GFX1031,
-  GFX1032,
-  GFX1033,
-  GFX1034,
-  GFX1035,
-  GFX1036,
-  GFX11_GENERIC,
-  GFX1100,
-  GFX1101,
-  GFX1102,
-  GFX1103,
-  GFX1150,
-  GFX1151,
-  GFX1152,
-  GFX1153,
-  GFX12_GENERIC,
-  GFX1200,
-  GFX1201,
-  AMDGCNSPIRV,
-  Generic, // A processor model named 'generic' if the target backend defines a
-           // public one.
-  LAST,
-
-  CudaDefault = OffloadArch::SM_52,
-  HIPDefault = OffloadArch::GFX906,
-};
-
 enum class CUDAFunctionTarget {
   Device,
   Global,
@@ -154,21 +64,6 @@ enum class CUDAFunctionTarget {
   InvalidTarget
 };
 
-static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
-  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
-}
-
-static inline bool IsAMDOffloadArch(OffloadArch A) {
-  // Generic processor model is for testing only.
-  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
-}
-
-const char *OffloadArchToString(OffloadArch A);
-const char *OffloadArchToVirtualArchString(OffloadArch A);
-
-// The input should have the form "sm_20".
-OffloadArch StringToOffloadArch(llvm::StringRef S);
-
 /// Get the earliest CudaVersion that supports the given OffloadArch.
 CudaVersion MinVersionForOffloadArch(OffloadArch A);
 
diff --git a/clang/include/clang/Basic/OffloadArch.h b/clang/include/clang/Basic/OffloadArch.h
new file mode 100644
index 0000000000000..6fee1e2bc8c06
--- /dev/null
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
+  LAST,
+
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
+};
+
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
+}
+
+static inline bool IsAMDOffloadArch(OffloadArch A) {
+  // Generic processor model is for testing only.
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
+}
+
+static inline bool IsIntelCPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::GRANITERAPIDS && Arch < OffloadArch::BMG_G21;
+}
+
+static inline bool IsIntelGPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::BMG_G21 && Arch < OffloadArch::LAST;
+}
+
+static inline bool IsIntelOffloadArch(OffloadArch Arch) {
+  return IsIntelCPUArch(Arch) || IsIntelGPUArch(Arch);
+}
+
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
+
+// The input should have the form "sm_20".
+OffloadArch StringToOffloadArch(llvm::StringRef S);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_OFFLOADARCH_H
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 331dfbb3f4b67..419fd9bc136cf 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -76,6 +76,7 @@ add_clang_library(clangBasic
   MakeSupport.cpp
   Module.cpp
   ObjCRuntime.cpp
+  OffloadArch.cpp
   OpenCLOptions.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index 68d042eca2492..8ea242911a2ba 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -73,123 +73,6 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
   return CudaVersion::UNKNOWN;
 }
 
-namespace {
-struct OffloadArchToStringMap {
-  OffloadArch arch;
-  const char *arch_name;
-  const char *virtual_arch_name;
-};
-} // namespace
-
-#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
-#define SM(sm) SM2(sm, "compute_" #sm)
-#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
-static const OffloadArchToStringMap arch_names[] = {
-    // clang-format off
-    {OffloadArch::UNUSED, "", ""},
-    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
-    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
-    SM(50), SM(52), SM(53),          // Maxwell
-    SM(60), SM(61), SM(62),          // Pascal
-    SM(70), SM(72),                  // Volta
-    SM(75),                          // Turing
-    SM(80), SM(86),                  // Ampere
-    SM(87),                          // Jetson/Drive AGX Orin
-    SM(89),                          // Ada Lovelace
-    SM(90),                          // Hopper
-    SM(90a),                         // Hopper
-    SM(100),                         // Blackwell
-    SM(100a),                        // Blackwell
-    SM(101),                         // Blackwell
-    SM(101a),                        // Blackwell
-    SM(120),                         // Blackwell
-    SM(120a),                        // Blackwell
-    GFX(600),  // gfx600
-    GFX(601),  // gfx601
-    GFX(602),  // gfx602
-    GFX(700),  // gfx700
-    GFX(701),  // gfx701
-    GFX(702),  // gfx702
-    GFX(703),  // gfx703
-    GFX(704),  // gfx704
-    GFX(705),  // gfx705
-    GFX(801),  // gfx801
-    GFX(802),  // gfx802
-    GFX(803),  // gfx803
-    GFX(805),  // gfx805
-    GFX(810),  // gfx810
-    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
-    GFX(900),  // gfx900
-    GFX(902),  // gfx902
-    GFX(904),  // gfx903
-    GFX(906),  // gfx906
-    GFX(908),  // gfx908
-    GFX(909),  // gfx909
-    GFX(90a),  // gfx90a
-    GFX(90c),  // gfx90c
-    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
-    GFX(942),  // gfx942
-    GFX(950),  // gfx950
-    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
-    GFX(1010), // gfx1010
-    GFX(1011), // gfx1011
-    GFX(1012), // gfx1012
-    GFX(1013), // gfx1013
-    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
-    GFX(1030), // gfx1030
-    GFX(1031), // gfx1031
-    GFX(1032), // gfx1032
-    GFX(1033), // gfx1033
-    GFX(1034), // gfx1034
-    GFX(1035), // gfx1035
-    GFX(1036), // gfx1036
-    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
-    GFX(1100), // gfx1100
-    GFX(1101), // gfx1101
-    GFX(1102), // gfx1102
-    GFX(1103), // gfx1103
-    GFX(1150), // gfx1150
-    GFX(1151), // gfx1151
-    GFX(1152), // gfx1152
-    GFX(1153), // gfx1153
-    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
-    GFX(1200), // gfx1200
-    GFX(1201), // gfx1201
-    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
-    {OffloadArch::Generic, "generic", ""},
-    // clang-format on
-};
-#undef SM
-#undef SM2
-#undef GFX
-
-const char *OffloadArchToString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->arch_name;
-}
-
-const char *OffloadArchToVirtualArchString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->virtual_arch_name;
-}
-
-OffloadArch StringToOffloadArch(llvm::StringRef S) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
-  if (result == std::end(arch_names))
-    return OffloadArch::UNKNOWN;
-  return result->arch;
-}
-
 CudaVersion MinVersionForOffloadArch(OffloadArch A) {
   if (A == OffloadArch::UNKNOWN)
     return CudaVersion::UNKNOWN;
diff --git a/clang/lib/Basic/OffloadArch.cpp b/clang/lib/Basic/OffloadArch.cpp
new file mode 100644
index 0000000000000..828c1ebf866fa
--- /dev/null
+++ b/clang/lib/Basic/OffloadArch.cpp
@@ -0,0 +1,133 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <algorithm>
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch arch;
+  const char *arch_name;
+  const char *virtual_arch_name;
+};
+} // namespace
+
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
+#define SM(sm) SM2(sm, "compute_" #sm)
+#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
+static const OffloadArchToStringMap arch_names[] = {
+    // clang-format off
+    {OffloadArch::UNUSED, "", ""},
+    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
+    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
+    SM(50), SM(52), SM(53),          // Maxwell
+    SM(60), SM(61), SM(62),          // Pascal
+    SM(70), SM(72),                  // Volta
+    SM(75),                          // Turing
+    SM(80), SM(86),                  // Ampere
+    SM(87),                          // Jetson/Drive AGX Orin
+    SM(89),                          // Ada Lovelace
+    SM(90),                          // Hopper
+    SM(90a),                         // Hopper
+    SM(100),                         // Blackwell
+    SM(100a),                        // Blackwell
+    SM(101),                         // Blackwell
+    SM(101a),                        // Blackwell
+    SM(120),                         // Blackwell
+    SM(120a),                        // Blackwell
+    GFX(600),  // gfx600
+    GFX(601),  // gfx601
+    GFX(602),  // gfx602
+    GFX(700),  // gfx700
+    GFX(701),  // gfx701
+    GFX(702),  // gfx702
+    GFX(703),  // gfx703
+    GFX(704),  // gfx704
+    GFX(705),  // gfx705
+    GFX(801),  // gfx801
+    GFX(802),  // gfx802
+    GFX(803),  // gfx803
+    GFX(805),  // gfx805
+    GFX(810),  // gfx810
+    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
+    GFX(900),  // gfx900
+    GFX(902),  // gfx902
+    GFX(904),  // gfx903
+    GFX(906),  // gfx906
+    GFX(908),  // gfx908
+    GFX(909),  // gfx909
+    GFX(90a),  // gfx90a
+    GFX(90c),  // gfx90c
+    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
+    GFX(942),  // gfx942
+    GFX(950),  // gfx950
+    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
+    GFX(1010), // gfx1010
+    GFX(1011), // gfx1011
+    GFX(1012), // gfx1012
+    GFX(1013), // gfx1013
+    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
+    GFX(1030), // gfx1030
+    GFX(1031), // gfx1031
+    GFX(1032), // gfx1032
+    GFX(1033), // gfx1033
+    GFX(1034), // gfx1034
+    GFX(1035), // gfx1035
+    GFX(1036), // gfx1036
+    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
+    GFX(1100), // gfx1100
+    GFX(1101), // gfx1101
+    GFX(1102), // gfx1102
+    GFX(1103), // gfx1103
+    GFX(1150), // gfx1150
+    GFX(1151), // gfx1151
+    GFX(1152), // gfx1152
+    GFX(1153), // gfx1153
+    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
+    GFX(1200), // gfx1200
+    GFX(1201), // gfx1201
+    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
+    // Note: this is an initial list of Intel GPU and GPU offloading architectures.
+    // The list will be expanded later as support for more architectures is added.
+    // Intel CPUs
+    {OffloadArch::GRANITERAPIDS, "graniterapids", ""},
+    // Intel GPUS
+    {OffloadArch::BMG_G21, "bmg_g21", ""},
+    {OffloadArch::Generic, "generic", ""},
+    // clang-format on
+};
+#undef SM
+#undef SM2
+#undef GFX
+#undef INTEL
+
+const char *OffloadArchToString(OffloadArch A) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
+  if (result == std::end(arch_names))
+    return "unknown";
+  return result->arch_name;
+}
+
+const char *OffloadArchToVirtualArchString(OffloadArch A) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
+  if (result == std::end(arch_names))
+    return "unknown";
+  return result->virtual_arch_name;
+}
+
+OffloadArch StringToOffloadArch(llvm::StringRef S) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
+  if (result == std::end(arch_names))
+    return OffloadArch::UNKNOWN;
+  return result->arch;
+}
+
+} // namespace clang
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp
index 08c8460045c6a..42b66d3559f6a 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -241,6 +241,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
       case OffloadArch::GFX1201:
       case OffloadArch::AMDGCNSPIRV:
       case OffloadArch::Generic:
+      case OffloadArch::GRANITERAPIDS:
+      case OffloadArch::BMG_G21:
       case OffloadArch::LAST:
         break;
       case OffloadArch::UNKNOWN:
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index f697c13f4c522..eed4471c38e4e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -2335,6 +2335,8 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(const OMPRequiresDecl *D) {
       case OffloadArch::GFX1201:
       case OffloadArch::AMDGCNSPIRV:
       case OffloadArch::Generic:
+      case OffloadArch::GRANITERAPIDS:
+      case OffloadArch::BMG_G21:
       case OffloadArch::UNUSED:
       case OffloadArch::UNKNOWN:
         break;
diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt
index e818bd3e2c372..37b01cc9f66a8 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -5,6 +5,7 @@ add_clang_unittest(BasicTests
   FileEntryTest.cpp
   FileManagerTest.cpp
   LineOffsetMappingTest.cpp
+  OffloadArchTest.cpp
   SanitizersTest.cpp
   SarifTest.cpp
   SourceManagerTest.cpp
diff --git a/clang/unittests/Basic/OffloadArchTest.cpp b/clang/unittests/Basic/OffloadArchTest.cpp
new file mode 100644
index 0000000000000..964f5f2ad2603
--- /dev/null
+++ b/clang/unittests/Basic/OffloadArchTest.cpp
@@ -0,0 +1,36 @@
+//===- unittests/Basic/OffloadArchTest.cpp - Test OffloadArch -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/OffloadArch.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+TEST(OffloadArchTest, basic) {
+  EXPECT_TRUE(IsNVIDIAOffloadArch(OffloadArch::SM_20));
+  EXPECT_TRUE(IsNVIDIAOffloadArch(OffloadArch::SM_120a));
+  EXPECT_FALSE(IsNVIDIAOffloadArch(OffloadArch::GFX600));
+
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::SM_120a));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX600));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX1201));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX12_GENERIC));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::AMDGCNSPIRV));
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::GRANITERAPIDS));
+
+  EXPECT_TRUE(IsIntelOffloadArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_TRUE(IsIntelCPUArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_FALSE(IsIntelGPUArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_TRUE(IsIntelOffloadArch(OffloadArch::BMG_G21));
+  EXPECT_FALSE(IsIntelCPUArch(OffloadArch::BMG_G21));
+  EXPECT_TRUE(IsIntelGPUArch(OffloadArch::BMG_G21));
+
+  EXPECT_FALSE(IsNVIDIAOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsIntelOffloadArch(OffloadArch::Generic));
+}

``````````

</details>

author_association: MEMBER
user: login: llvmbot
created_at: 2025-04-23T22:08:17Z
body: 
<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Justin Cai (jzc)

<details>
<summary>Changes</summary>

Currently, the OffloadArch enum is defined Cuda.h. This PR moves the definition to a more generic location in OffloadArch.h/cpp and also adds an initial set of Intel OffloadArch values that will be used in SYCL compilation.

---
Full diff: https://github.com/llvm/llvm-project/pull/137070.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/Cuda.h (+2-107) 
- (added) clang/include/clang/Basic/OffloadArch.h (+143) 
- (modified) clang/lib/Basic/CMakeLists.txt (+1) 
- (modified) clang/lib/Basic/Cuda.cpp (-117) 
- (added) clang/lib/Basic/OffloadArch.cpp (+133) 
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+2) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2) 
- (modified) clang/unittests/Basic/CMakeLists.txt (+1) 
- (added) clang/unittests/Basic/OffloadArchTest.cpp (+36) 


``````````diff
diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index c4eb7b7cac1d6..d6a22a7af559b 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_BASIC_CUDA_H
 #define LLVM_CLANG_BASIC_CUDA_H
 
+#include "clang/Basic/OffloadArch.h"
+
 namespace llvm {
 class StringRef;
 class Twine;
@@ -54,98 +56,6 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
-enum class OffloadArch {
-  UNUSED,
-  UNKNOWN,
-  // TODO: Deprecate and remove GPU architectures older than sm_52.
-  SM_20,
-  SM_21,
-  SM_30,
-  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
-  SM_32_,
-  SM_35,
-  SM_37,
-  SM_50,
-  SM_52,
-  SM_53,
-  SM_60,
-  SM_61,
-  SM_62,
-  SM_70,
-  SM_72,
-  SM_75,
-  SM_80,
-  SM_86,
-  SM_87,
-  SM_89,
-  SM_90,
-  SM_90a,
-  SM_100,
-  SM_100a,
-  SM_101,
-  SM_101a,
-  SM_120,
-  SM_120a,
-  GFX600,
-  GFX601,
-  GFX602,
-  GFX700,
-  GFX701,
-  GFX702,
-  GFX703,
-  GFX704,
-  GFX705,
-  GFX801,
-  GFX802,
-  GFX803,
-  GFX805,
-  GFX810,
-  GFX9_GENERIC,
-  GFX900,
-  GFX902,
-  GFX904,
-  GFX906,
-  GFX908,
-  GFX909,
-  GFX90a,
-  GFX90c,
-  GFX9_4_GENERIC,
-  GFX942,
-  GFX950,
-  GFX10_1_GENERIC,
-  GFX1010,
-  GFX1011,
-  GFX1012,
-  GFX1013,
-  GFX10_3_GENERIC,
-  GFX1030,
-  GFX1031,
-  GFX1032,
-  GFX1033,
-  GFX1034,
-  GFX1035,
-  GFX1036,
-  GFX11_GENERIC,
-  GFX1100,
-  GFX1101,
-  GFX1102,
-  GFX1103,
-  GFX1150,
-  GFX1151,
-  GFX1152,
-  GFX1153,
-  GFX12_GENERIC,
-  GFX1200,
-  GFX1201,
-  AMDGCNSPIRV,
-  Generic, // A processor model named 'generic' if the target backend defines a
-           // public one.
-  LAST,
-
-  CudaDefault = OffloadArch::SM_52,
-  HIPDefault = OffloadArch::GFX906,
-};
-
 enum class CUDAFunctionTarget {
   Device,
   Global,
@@ -154,21 +64,6 @@ enum class CUDAFunctionTarget {
   InvalidTarget
 };
 
-static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
-  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
-}
-
-static inline bool IsAMDOffloadArch(OffloadArch A) {
-  // Generic processor model is for testing only.
-  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
-}
-
-const char *OffloadArchToString(OffloadArch A);
-const char *OffloadArchToVirtualArchString(OffloadArch A);
-
-// The input should have the form "sm_20".
-OffloadArch StringToOffloadArch(llvm::StringRef S);
-
 /// Get the earliest CudaVersion that supports the given OffloadArch.
 CudaVersion MinVersionForOffloadArch(OffloadArch A);
 
diff --git a/clang/include/clang/Basic/OffloadArch.h b/clang/include/clang/Basic/OffloadArch.h
new file mode 100644
index 0000000000000..6fee1e2bc8c06
--- /dev/null
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -0,0 +1,143 @@
+//===--- OffloadArch.h - Definition of offloading architectures --- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_BASIC_OFFLOADARCH_H
+#define LLVM_CLANG_BASIC_OFFLOADARCH_H
+
+namespace llvm {
+class StringRef;
+} // namespace llvm
+
+namespace clang {
+
+enum class OffloadArch {
+  UNUSED,
+  UNKNOWN,
+  // TODO: Deprecate and remove GPU architectures older than sm_52.
+  SM_20,
+  SM_21,
+  SM_30,
+  // This has a name conflict with sys/mac.h on AIX, rename it as a workaround.
+  SM_32_,
+  SM_35,
+  SM_37,
+  SM_50,
+  SM_52,
+  SM_53,
+  SM_60,
+  SM_61,
+  SM_62,
+  SM_70,
+  SM_72,
+  SM_75,
+  SM_80,
+  SM_86,
+  SM_87,
+  SM_89,
+  SM_90,
+  SM_90a,
+  SM_100,
+  SM_100a,
+  SM_101,
+  SM_101a,
+  SM_120,
+  SM_120a,
+  GFX600,
+  GFX601,
+  GFX602,
+  GFX700,
+  GFX701,
+  GFX702,
+  GFX703,
+  GFX704,
+  GFX705,
+  GFX801,
+  GFX802,
+  GFX803,
+  GFX805,
+  GFX810,
+  GFX9_GENERIC,
+  GFX900,
+  GFX902,
+  GFX904,
+  GFX906,
+  GFX908,
+  GFX909,
+  GFX90a,
+  GFX90c,
+  GFX9_4_GENERIC,
+  GFX942,
+  GFX950,
+  GFX10_1_GENERIC,
+  GFX1010,
+  GFX1011,
+  GFX1012,
+  GFX1013,
+  GFX10_3_GENERIC,
+  GFX1030,
+  GFX1031,
+  GFX1032,
+  GFX1033,
+  GFX1034,
+  GFX1035,
+  GFX1036,
+  GFX11_GENERIC,
+  GFX1100,
+  GFX1101,
+  GFX1102,
+  GFX1103,
+  GFX1150,
+  GFX1151,
+  GFX1152,
+  GFX1153,
+  GFX12_GENERIC,
+  GFX1200,
+  GFX1201,
+  AMDGCNSPIRV,
+  Generic, // A processor model named 'generic' if the target backend defines a
+           // public one.
+  // Intel CPUs
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
+  LAST,
+
+  CudaDefault = OffloadArch::SM_52,
+  HIPDefault = OffloadArch::GFX906,
+};
+
+static inline bool IsNVIDIAOffloadArch(OffloadArch A) {
+  return A >= OffloadArch::SM_20 && A < OffloadArch::GFX600;
+}
+
+static inline bool IsAMDOffloadArch(OffloadArch A) {
+  // Generic processor model is for testing only.
+  return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
+}
+
+static inline bool IsIntelCPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::GRANITERAPIDS && Arch < OffloadArch::BMG_G21;
+}
+
+static inline bool IsIntelGPUArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::BMG_G21 && Arch < OffloadArch::LAST;
+}
+
+static inline bool IsIntelOffloadArch(OffloadArch Arch) {
+  return IsIntelCPUArch(Arch) || IsIntelGPUArch(Arch);
+}
+
+const char *OffloadArchToString(OffloadArch A);
+const char *OffloadArchToVirtualArchString(OffloadArch A);
+
+// The input should have the form "sm_20".
+OffloadArch StringToOffloadArch(llvm::StringRef S);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_OFFLOADARCH_H
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 331dfbb3f4b67..419fd9bc136cf 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -76,6 +76,7 @@ add_clang_library(clangBasic
   MakeSupport.cpp
   Module.cpp
   ObjCRuntime.cpp
+  OffloadArch.cpp
   OpenCLOptions.cpp
   OpenMPKinds.cpp
   OperatorPrecedence.cpp
diff --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index 68d042eca2492..8ea242911a2ba 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -73,123 +73,6 @@ CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
   return CudaVersion::UNKNOWN;
 }
 
-namespace {
-struct OffloadArchToStringMap {
-  OffloadArch arch;
-  const char *arch_name;
-  const char *virtual_arch_name;
-};
-} // namespace
-
-#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
-#define SM(sm) SM2(sm, "compute_" #sm)
-#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
-static const OffloadArchToStringMap arch_names[] = {
-    // clang-format off
-    {OffloadArch::UNUSED, "", ""},
-    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
-    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
-    SM(50), SM(52), SM(53),          // Maxwell
-    SM(60), SM(61), SM(62),          // Pascal
-    SM(70), SM(72),                  // Volta
-    SM(75),                          // Turing
-    SM(80), SM(86),                  // Ampere
-    SM(87),                          // Jetson/Drive AGX Orin
-    SM(89),                          // Ada Lovelace
-    SM(90),                          // Hopper
-    SM(90a),                         // Hopper
-    SM(100),                         // Blackwell
-    SM(100a),                        // Blackwell
-    SM(101),                         // Blackwell
-    SM(101a),                        // Blackwell
-    SM(120),                         // Blackwell
-    SM(120a),                        // Blackwell
-    GFX(600),  // gfx600
-    GFX(601),  // gfx601
-    GFX(602),  // gfx602
-    GFX(700),  // gfx700
-    GFX(701),  // gfx701
-    GFX(702),  // gfx702
-    GFX(703),  // gfx703
-    GFX(704),  // gfx704
-    GFX(705),  // gfx705
-    GFX(801),  // gfx801
-    GFX(802),  // gfx802
-    GFX(803),  // gfx803
-    GFX(805),  // gfx805
-    GFX(810),  // gfx810
-    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
-    GFX(900),  // gfx900
-    GFX(902),  // gfx902
-    GFX(904),  // gfx903
-    GFX(906),  // gfx906
-    GFX(908),  // gfx908
-    GFX(909),  // gfx909
-    GFX(90a),  // gfx90a
-    GFX(90c),  // gfx90c
-    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
-    GFX(942),  // gfx942
-    GFX(950),  // gfx950
-    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
-    GFX(1010), // gfx1010
-    GFX(1011), // gfx1011
-    GFX(1012), // gfx1012
-    GFX(1013), // gfx1013
-    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
-    GFX(1030), // gfx1030
-    GFX(1031), // gfx1031
-    GFX(1032), // gfx1032
-    GFX(1033), // gfx1033
-    GFX(1034), // gfx1034
-    GFX(1035), // gfx1035
-    GFX(1036), // gfx1036
-    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
-    GFX(1100), // gfx1100
-    GFX(1101), // gfx1101
-    GFX(1102), // gfx1102
-    GFX(1103), // gfx1103
-    GFX(1150), // gfx1150
-    GFX(1151), // gfx1151
-    GFX(1152), // gfx1152
-    GFX(1153), // gfx1153
-    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
-    GFX(1200), // gfx1200
-    GFX(1201), // gfx1201
-    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
-    {OffloadArch::Generic, "generic", ""},
-    // clang-format on
-};
-#undef SM
-#undef SM2
-#undef GFX
-
-const char *OffloadArchToString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->arch_name;
-}
-
-const char *OffloadArchToVirtualArchString(OffloadArch A) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
-  if (result == std::end(arch_names))
-    return "unknown";
-  return result->virtual_arch_name;
-}
-
-OffloadArch StringToOffloadArch(llvm::StringRef S) {
-  auto result = std::find_if(
-      std::begin(arch_names), std::end(arch_names),
-      [S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
-  if (result == std::end(arch_names))
-    return OffloadArch::UNKNOWN;
-  return result->arch;
-}
-
 CudaVersion MinVersionForOffloadArch(OffloadArch A) {
   if (A == OffloadArch::UNKNOWN)
     return CudaVersion::UNKNOWN;
diff --git a/clang/lib/Basic/OffloadArch.cpp b/clang/lib/Basic/OffloadArch.cpp
new file mode 100644
index 0000000000000..828c1ebf866fa
--- /dev/null
+++ b/clang/lib/Basic/OffloadArch.cpp
@@ -0,0 +1,133 @@
+#include "clang/Basic/OffloadArch.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <algorithm>
+
+namespace clang {
+
+namespace {
+struct OffloadArchToStringMap {
+  OffloadArch arch;
+  const char *arch_name;
+  const char *virtual_arch_name;
+};
+} // namespace
+
+#define SM2(sm, ca) {OffloadArch::SM_##sm, "sm_" #sm, ca}
+#define SM(sm) SM2(sm, "compute_" #sm)
+#define GFX(gpu) {OffloadArch::GFX##gpu, "gfx" #gpu, "compute_amdgcn"}
+static const OffloadArchToStringMap arch_names[] = {
+    // clang-format off
+    {OffloadArch::UNUSED, "", ""},
+    SM2(20, "compute_20"), SM2(21, "compute_20"), // Fermi
+    SM(30), {OffloadArch::SM_32_, "sm_32", "compute_32"}, SM(35), SM(37),  // Kepler
+    SM(50), SM(52), SM(53),          // Maxwell
+    SM(60), SM(61), SM(62),          // Pascal
+    SM(70), SM(72),                  // Volta
+    SM(75),                          // Turing
+    SM(80), SM(86),                  // Ampere
+    SM(87),                          // Jetson/Drive AGX Orin
+    SM(89),                          // Ada Lovelace
+    SM(90),                          // Hopper
+    SM(90a),                         // Hopper
+    SM(100),                         // Blackwell
+    SM(100a),                        // Blackwell
+    SM(101),                         // Blackwell
+    SM(101a),                        // Blackwell
+    SM(120),                         // Blackwell
+    SM(120a),                        // Blackwell
+    GFX(600),  // gfx600
+    GFX(601),  // gfx601
+    GFX(602),  // gfx602
+    GFX(700),  // gfx700
+    GFX(701),  // gfx701
+    GFX(702),  // gfx702
+    GFX(703),  // gfx703
+    GFX(704),  // gfx704
+    GFX(705),  // gfx705
+    GFX(801),  // gfx801
+    GFX(802),  // gfx802
+    GFX(803),  // gfx803
+    GFX(805),  // gfx805
+    GFX(810),  // gfx810
+    {OffloadArch::GFX9_GENERIC, "gfx9-generic", "compute_amdgcn"},
+    GFX(900),  // gfx900
+    GFX(902),  // gfx902
+    GFX(904),  // gfx903
+    GFX(906),  // gfx906
+    GFX(908),  // gfx908
+    GFX(909),  // gfx909
+    GFX(90a),  // gfx90a
+    GFX(90c),  // gfx90c
+    {OffloadArch::GFX9_4_GENERIC, "gfx9-4-generic", "compute_amdgcn"},
+    GFX(942),  // gfx942
+    GFX(950),  // gfx950
+    {OffloadArch::GFX10_1_GENERIC, "gfx10-1-generic", "compute_amdgcn"},
+    GFX(1010), // gfx1010
+    GFX(1011), // gfx1011
+    GFX(1012), // gfx1012
+    GFX(1013), // gfx1013
+    {OffloadArch::GFX10_3_GENERIC, "gfx10-3-generic", "compute_amdgcn"},
+    GFX(1030), // gfx1030
+    GFX(1031), // gfx1031
+    GFX(1032), // gfx1032
+    GFX(1033), // gfx1033
+    GFX(1034), // gfx1034
+    GFX(1035), // gfx1035
+    GFX(1036), // gfx1036
+    {OffloadArch::GFX11_GENERIC, "gfx11-generic", "compute_amdgcn"},
+    GFX(1100), // gfx1100
+    GFX(1101), // gfx1101
+    GFX(1102), // gfx1102
+    GFX(1103), // gfx1103
+    GFX(1150), // gfx1150
+    GFX(1151), // gfx1151
+    GFX(1152), // gfx1152
+    GFX(1153), // gfx1153
+    {OffloadArch::GFX12_GENERIC, "gfx12-generic", "compute_amdgcn"},
+    GFX(1200), // gfx1200
+    GFX(1201), // gfx1201
+    {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
+    // Note: this is an initial list of Intel GPU and GPU offloading architectures.
+    // The list will be expanded later as support for more architectures is added.
+    // Intel CPUs
+    {OffloadArch::GRANITERAPIDS, "graniterapids", ""},
+    // Intel GPUS
+    {OffloadArch::BMG_G21, "bmg_g21", ""},
+    {OffloadArch::Generic, "generic", ""},
+    // clang-format on
+};
+#undef SM
+#undef SM2
+#undef GFX
+#undef INTEL
+
+const char *OffloadArchToString(OffloadArch A) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
+  if (result == std::end(arch_names))
+    return "unknown";
+  return result->arch_name;
+}
+
+const char *OffloadArchToVirtualArchString(OffloadArch A) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [A](const OffloadArchToStringMap &map) { return A == map.arch; });
+  if (result == std::end(arch_names))
+    return "unknown";
+  return result->virtual_arch_name;
+}
+
+OffloadArch StringToOffloadArch(llvm::StringRef S) {
+  auto result = std::find_if(
+      std::begin(arch_names), std::end(arch_names),
+      [S](const OffloadArchToStringMap &map) { return S == map.arch_name; });
+  if (result == std::end(arch_names))
+    return OffloadArch::UNKNOWN;
+  return result->arch;
+}
+
+} // namespace clang
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp
index 08c8460045c6a..42b66d3559f6a 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -241,6 +241,8 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions &Opts,
       case OffloadArch::GFX1201:
       case OffloadArch::AMDGCNSPIRV:
       case OffloadArch::Generic:
+      case OffloadArch::GRANITERAPIDS:
+      case OffloadArch::BMG_G21:
       case OffloadArch::LAST:
         break;
       case OffloadArch::UNKNOWN:
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index f697c13f4c522..eed4471c38e4e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -2335,6 +2335,8 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(const OMPRequiresDecl *D) {
       case OffloadArch::GFX1201:
       case OffloadArch::AMDGCNSPIRV:
       case OffloadArch::Generic:
+      case OffloadArch::GRANITERAPIDS:
+      case OffloadArch::BMG_G21:
       case OffloadArch::UNUSED:
       case OffloadArch::UNKNOWN:
         break;
diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt
index e818bd3e2c372..37b01cc9f66a8 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -5,6 +5,7 @@ add_clang_unittest(BasicTests
   FileEntryTest.cpp
   FileManagerTest.cpp
   LineOffsetMappingTest.cpp
+  OffloadArchTest.cpp
   SanitizersTest.cpp
   SarifTest.cpp
   SourceManagerTest.cpp
diff --git a/clang/unittests/Basic/OffloadArchTest.cpp b/clang/unittests/Basic/OffloadArchTest.cpp
new file mode 100644
index 0000000000000..964f5f2ad2603
--- /dev/null
+++ b/clang/unittests/Basic/OffloadArchTest.cpp
@@ -0,0 +1,36 @@
+//===- unittests/Basic/OffloadArchTest.cpp - Test OffloadArch -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/OffloadArch.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+TEST(OffloadArchTest, basic) {
+  EXPECT_TRUE(IsNVIDIAOffloadArch(OffloadArch::SM_20));
+  EXPECT_TRUE(IsNVIDIAOffloadArch(OffloadArch::SM_120a));
+  EXPECT_FALSE(IsNVIDIAOffloadArch(OffloadArch::GFX600));
+
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::SM_120a));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX600));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX1201));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::GFX12_GENERIC));
+  EXPECT_TRUE(IsAMDOffloadArch(OffloadArch::AMDGCNSPIRV));
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::GRANITERAPIDS));
+
+  EXPECT_TRUE(IsIntelOffloadArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_TRUE(IsIntelCPUArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_FALSE(IsIntelGPUArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_TRUE(IsIntelOffloadArch(OffloadArch::BMG_G21));
+  EXPECT_FALSE(IsIntelCPUArch(OffloadArch::BMG_G21));
+  EXPECT_TRUE(IsIntelGPUArch(OffloadArch::BMG_G21));
+
+  EXPECT_FALSE(IsNVIDIAOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsIntelOffloadArch(OffloadArch::Generic));
+}

``````````

</details>

author_association: MEMBER
user: login: github-actions[bot]
created_at: 2025-04-25T16:38:16Z
body: <!--LLVM BUILDBOT INFORMATION COMMENT-->

@jzc Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

author_association: NONE