https://github.com/jzc updated https://github.com/llvm/llvm-project/pull/138158

>From f1b0e2cbe8229ba00956e0eac58f97d71995b0dd Mon Sep 17 00:00:00 2001
From: "Cai, Justin" <justin....@intel.com>
Date: Mon, 14 Apr 2025 21:30:39 +0000
Subject: [PATCH 1/2] [Clang][SYCL] Add initial set of Intel OffloadArch values

---
 clang/include/clang/Basic/OffloadArch.h   | 19 ++++++++++++
 clang/lib/Basic/OffloadArch.cpp           |  4 +++
 clang/lib/Basic/Targets/NVPTX.cpp         |  2 ++
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp  |  2 ++
 clang/unittests/Basic/CMakeLists.txt      |  1 +
 clang/unittests/Basic/OffloadArchTest.cpp | 36 +++++++++++++++++++++++
 6 files changed, 64 insertions(+)
 create mode 100644 clang/unittests/Basic/OffloadArchTest.cpp

diff --git a/clang/include/clang/Basic/OffloadArch.h 
b/clang/include/clang/Basic/OffloadArch.h
index c5ccd17e7a8be..c681f99f2e146 100644
--- a/clang/include/clang/Basic/OffloadArch.h
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -101,6 +101,13 @@ enum class OffloadArch {
   AMDGCNSPIRV,
   Generic, // A processor model named 'generic' if the target backend defines a
            // public one.
+  // 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
+  GRANITERAPIDS,
+  // Intel GPUs
+  BMG_G21,
   LAST,
 
   CudaDefault = OffloadArch::SM_52,
@@ -116,6 +123,18 @@ static inline bool IsAMDOffloadArch(OffloadArch A) {
   return A >= OffloadArch::GFX600 && A < OffloadArch::Generic;
 }
 
+static inline bool IsIntelCPUOffloadArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::GRANITERAPIDS && Arch < OffloadArch::BMG_G21;
+}
+
+static inline bool IsIntelGPUOffloadArch(OffloadArch Arch) {
+  return Arch >= OffloadArch::BMG_G21 && Arch < OffloadArch::LAST;
+}
+
+static inline bool IsIntelOffloadArch(OffloadArch Arch) {
+  return IsIntelCPUOffloadArch(Arch) || IsIntelGPUOffloadArch(Arch);
+}
+
 const char *OffloadArchToString(OffloadArch A);
 const char *OffloadArchToVirtualArchString(OffloadArch A);
 
diff --git a/clang/lib/Basic/OffloadArch.cpp b/clang/lib/Basic/OffloadArch.cpp
index 5e29742478b99..a019f0ac18c84 100644
--- a/clang/lib/Basic/OffloadArch.cpp
+++ b/clang/lib/Basic/OffloadArch.cpp
@@ -87,6 +87,10 @@ static const OffloadArchToStringMap ArchNames[] = {
     GFX(1200), // gfx1200
     GFX(1201), // gfx1201
     {OffloadArch::AMDGCNSPIRV, "amdgcnspirv", "compute_amdgcn"},
+    // Intel CPUs
+    {OffloadArch::GRANITERAPIDS, "graniterapids", ""},
+    // Intel GPUS
+    {OffloadArch::BMG_G21, "bmg_g21", ""},
     {OffloadArch::Generic, "generic", ""},
     // clang-format on
 };
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 59a5f7b914ce5..aa97422d54ede 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -2334,6 +2334,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 b0e0a97168757..8c8baa57b64e7 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -7,6 +7,7 @@ add_distinct_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..c19ad0043d774
--- /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(IsIntelCPUOffloadArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_FALSE(IsIntelGPUOffloadArch(OffloadArch::GRANITERAPIDS));
+  EXPECT_TRUE(IsIntelOffloadArch(OffloadArch::BMG_G21));
+  EXPECT_FALSE(IsIntelCPUOffloadArch(OffloadArch::BMG_G21));
+  EXPECT_TRUE(IsIntelGPUOffloadArch(OffloadArch::BMG_G21));
+
+  EXPECT_FALSE(IsNVIDIAOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsAMDOffloadArch(OffloadArch::Generic));
+  EXPECT_FALSE(IsIntelOffloadArch(OffloadArch::Generic));
+}

>From 4d4c901ad78a104989b328e7532fd47a61a0cad6 Mon Sep 17 00:00:00 2001
From: "Cai, Justin" <justin....@intel.com>
Date: Thu, 1 May 2025 17:13:00 +0000
Subject: [PATCH 2/2] Remove comment

---
 clang/include/clang/Basic/OffloadArch.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/include/clang/Basic/OffloadArch.h 
b/clang/include/clang/Basic/OffloadArch.h
index c681f99f2e146..99b1024b9d0d4 100644
--- a/clang/include/clang/Basic/OffloadArch.h
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -101,9 +101,6 @@ enum class OffloadArch {
   AMDGCNSPIRV,
   Generic, // A processor model named 'generic' if the target backend defines a
            // public one.
-  // 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
   GRANITERAPIDS,
   // Intel GPUs

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to