[clang] [llvm] [Clang][SYCL] Compile device code once per IGCA target (PR #239010)

Srividya Sundaram via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 15:50:55 PST 2026


https://github.com/srividya-sundaram updated https://github.com/llvm/llvm-project/pull/239010

>From b001bba68a1b086bbe8ff091bbfec5476e3a2c48 Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Nov 2026 11:01:28 -0800
Subject: [PATCH 1/4] [TargetParser] Map an Intel GPU to its IGCA target

Add getIGCATarget, which returns the IGCA target of an Intel GPU from the IGCA columns of IntelGPUTargetParser.def, e.g. igca_30r for both xe-mtl-u and xe-mtl-h. The driver will use it to compile once per IGCA target.
---
 .../llvm/TargetParser/IntelGPUTargetParser.h      |  4 ++++
 llvm/lib/TargetParser/IntelGPUTargetParser.cpp    | 15 +++++++++++++++
 .../TargetParser/IntelGPUTargetParserTest.cpp     | 15 +++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/llvm/include/llvm/TargetParser/IntelGPUTargetParser.h b/llvm/include/llvm/TargetParser/IntelGPUTargetParser.h
index 3e9f7ef82b41d4..4225ec24455ba2 100644
--- a/llvm/include/llvm/TargetParser/IntelGPUTargetParser.h
+++ b/llvm/include/llvm/TargetParser/IntelGPUTargetParser.h
@@ -176,6 +176,10 @@ LLVM_ABI IGCATarget parseIGCATarget(StringRef MaybeTarget);
 /// \p Target is invalid.
 LLVM_ABI StringRef getIGCATargetName(IGCATarget Target);
 
+/// \return the IGCA target of \p Kind, e.g. igca_20ca for xe-pvc, or an
+/// invalid IGCATarget for GK_NONE.
+LLVM_ABI IGCATarget getIGCATarget(GPUKind Kind);
+
 } // namespace IntelGPU
 } // namespace llvm
 
diff --git a/llvm/lib/TargetParser/IntelGPUTargetParser.cpp b/llvm/lib/TargetParser/IntelGPUTargetParser.cpp
index efc171de4d8db3..8d2206fb4fed10 100644
--- a/llvm/lib/TargetParser/IntelGPUTargetParser.cpp
+++ b/llvm/lib/TargetParser/IntelGPUTargetParser.cpp
@@ -197,3 +197,18 @@ StringRef llvm::IntelGPU::getIGCATargetName(IGCATarget T) {
       return E.Name;
   return "";
 }
+
+IGCATarget llvm::IntelGPU::getIGCATarget(GPUKind Kind) {
+  switch (Kind) {
+  case GK_NONE:
+    return IGCATarget::invalid();
+#define INTEL_GPU(NAME, KIND, MAJOR, MINOR, IGCA_TARGET, IGCA_FEATURE_SETS)    \
+  case GK_##KIND:                                                              \
+    return IGCATarget(IGCA_TARGET, IGCAFeatureSet::IGCA_FEATURE_SETS);
+#define INTEL_GPU_COMPAT(NAME, KIND, IGCA_TARGET, IGCA_FEATURE_SETS)           \
+  case GK_##KIND:                                                              \
+    return IGCATarget(IGCA_TARGET, IGCAFeatureSet::IGCA_FEATURE_SETS);
+#include "llvm/TargetParser/IntelGPUTargetParser.def"
+  }
+  llvm_unreachable("invalid Intel GPU kind");
+}
diff --git a/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp b/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
index 40fef95203c74f..9eba07b1fb6e11 100644
--- a/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
@@ -265,4 +265,19 @@ TEST(IntelGPUTargetParserTest, IGCATargetName) {
       IntelGPU::getIGCATargetName(IGCATarget(10, IGCAFeatureSet::Compute)), "");
 }
 
+TEST(IntelGPUTargetParserTest, KindIGCATargets) {
+  auto TargetName = [](IntelGPU::GPUKind Kind) {
+    return IntelGPU::getIGCATargetName(IntelGPU::getIGCATarget(Kind));
+  };
+  // Devices can share an IGCA target.
+  EXPECT_EQ(TargetName(IntelGPU::GK_XE_MTL_U), "igca_30r");
+  EXPECT_EQ(TargetName(IntelGPU::GK_XE_MTL_H), "igca_30r");
+  EXPECT_EQ(TargetName(IntelGPU::GK_XE_PVC), "igca_20ca");
+  EXPECT_EQ(TargetName(IntelGPU::GK_XE_CRI), "igca_60");
+  // A compatibility name and an alias have IGCA targets too.
+  EXPECT_EQ(TargetName(IntelGPU::GK_XE_DG2), "igca_15ra");
+  EXPECT_EQ(TargetName(IntelGPU::parseArch("xe-arl-u")), "igca_30r");
+  EXPECT_FALSE(IntelGPU::getIGCATarget(IntelGPU::GK_NONE).isValid());
+}
+
 } // namespace

>From ce7d28434a72fae00e4e9642f1845b263d3fd75f Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Nov 2026 12:22:05 -0800
Subject: [PATCH 2/4] [TargetParser] Clarify a test comment

---
 llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp b/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
index 9eba07b1fb6e11..07523e3849c879 100644
--- a/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/IntelGPUTargetParserTest.cpp
@@ -274,7 +274,8 @@ TEST(IntelGPUTargetParserTest, KindIGCATargets) {
   EXPECT_EQ(TargetName(IntelGPU::GK_XE_MTL_H), "igca_30r");
   EXPECT_EQ(TargetName(IntelGPU::GK_XE_PVC), "igca_20ca");
   EXPECT_EQ(TargetName(IntelGPU::GK_XE_CRI), "igca_60");
-  // A compatibility name and an alias have IGCA targets too.
+  // A compatibility name has an IGCA target too, and an alias has its
+  // device's.
   EXPECT_EQ(TargetName(IntelGPU::GK_XE_DG2), "igca_15ra");
   EXPECT_EQ(TargetName(IntelGPU::parseArch("xe-arl-u")), "igca_30r");
   EXPECT_FALSE(IntelGPU::getIGCATarget(IntelGPU::GK_NONE).isValid());

>From c153df6f4fcb73b3dc3ffbdd427c6686d70b592d Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Nov 2026 15:06:25 -0800
Subject: [PATCH 3/4] [Clang][SYCL] Compile device code once per IGCA target

For SYCL, an Intel GPU in --offload-arch is now compiled for its IGCA target, once for all GPUs that share it, e.g. once for igca_30r for xe-mtl-u and xe-mtl-h. The device image records the GPUs as code=xe-mtl-h,xe-mtl-u. At link time, clang-linker-wrapper links images with the same IGCA target and GPUs together, and clang-sycl-linker compiles them ahead of time with a single ocloc -device xe-mtl-h,xe-mtl-u. An IGCA target named directly lists no GPUs and is compiled just in time.
---
 clang/include/clang/Basic/OffloadArch.h       |  3 +
 clang/include/clang/Driver/Compilation.h      | 19 ++++++
 clang/lib/Basic/OffloadArch.cpp               |  6 ++
 clang/lib/Driver/Compilation.cpp              | 16 +++++
 clang/lib/Driver/Driver.cpp                   | 18 ++++++
 clang/lib/Driver/ToolChains/Clang.cpp         | 16 ++++-
 clang/test/Driver/sycl-igca-link.cpp          | 30 +++++++++
 clang/test/Driver/sycl-intel-gpu-arch.cpp     | 62 +++++++++++++------
 clang/test/Driver/sycl-offload-jit.cpp        |  2 +-
 clang/test/Driver/sycl-system-arch.cpp        |  2 +-
 .../clang-linker-wrapper/linker-wrapper.c     | 31 ++++++++++
 .../OffloadTools/clang-sycl-linker/basic.ll   | 18 ++++++
 .../ClangLinkerWrapper.cpp                    | 44 ++++++++++---
 .../clang-linker-wrapper/LinkerWrapperOpts.td |  3 +
 .../clang-sycl-linker/ClangSYCLLinker.cpp     | 23 ++++---
 clang/tools/clang-sycl-linker/SYCLLinkOpts.td |  5 ++
 clang/unittests/Basic/OffloadArchTest.cpp     |  8 +++
 17 files changed, 264 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/Driver/sycl-igca-link.cpp

diff --git a/clang/include/clang/Basic/OffloadArch.h b/clang/include/clang/Basic/OffloadArch.h
index fbf51ffab67922..84a25e5caf31ad 100644
--- a/clang/include/clang/Basic/OffloadArch.h
+++ b/clang/include/clang/Basic/OffloadArch.h
@@ -110,6 +110,9 @@ class OffloadArch {
   }
   /// Which IGCA target this is; only valid when isIntelIGCA().
   llvm::IntelGPU::IGCATarget igcaTarget() const;
+  /// The IGCA target of this Intel GPU, e.g. igca_30r for xe-mtl-u; only valid
+  /// when isIntelGPU().
+  OffloadArch intelGPUIGCATarget() const;
 
   bool operator==(const OffloadArch &Other) const {
     return V == Other.V && Kind == Other.Kind;
diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h
index 825806b6cfe332..59df1af0fc70b3 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -16,6 +16,7 @@
 #include "clang/Driver/Util.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Option/Option.h"
 #include <cassert>
@@ -97,6 +98,13 @@ class Compilation {
   };
   std::map<TCArgsKey, llvm::opt::DerivedArgList *> TCArgs;
 
+  /// The Intel GPUs that each SYCL device compile for an IGCA target is
+  /// compiled ahead of time for, sorted, e.g. xe-mtl-h and xe-mtl-u for the
+  /// igca_30r compile.
+  std::map<std::pair<const ToolChain *, StringRef>,
+           llvm::SmallVector<StringRef, 2>>
+      SYCLIGCADevices;
+
   /// Temporary files which should be removed on exit.
   llvm::opt::ArgStringList TempFiles;
 
@@ -256,6 +264,17 @@ class Compilation {
   getArgsForToolChain(const ToolChain *TC, BoundArch BA,
                       Action::OffloadKind DeviceOffloadKind);
 
+  /// Record that the SYCL device compile for the IGCA target \p Target on
+  /// \p TC is compiled ahead of time for the Intel GPU \p Device.
+  void addSYCLIGCADevice(const ToolChain *TC, StringRef Target,
+                         StringRef Device);
+
+  /// \return the Intel GPUs that the SYCL device compile for the IGCA target
+  /// \p Target on \p TC is compiled ahead of time for, sorted, or an empty
+  /// list.
+  ArrayRef<StringRef> getSYCLIGCADevices(const ToolChain *TC,
+                                         StringRef Target) const;
+
   /// addTempFile - Add a file to remove on exit, and returns its
   /// argument.
   const char *addTempFile(const char *Name) {
diff --git a/clang/lib/Basic/OffloadArch.cpp b/clang/lib/Basic/OffloadArch.cpp
index cc33b6d67c09ca..96e1ff6887d344 100644
--- a/clang/lib/Basic/OffloadArch.cpp
+++ b/clang/lib/Basic/OffloadArch.cpp
@@ -35,6 +35,12 @@ llvm::IntelGPU::IGCATarget OffloadArch::igcaTarget() const {
   return llvm::IntelGPU::IGCATarget::unpack(Kind);
 }
 
+OffloadArch OffloadArch::intelGPUIGCATarget() const {
+  assert(isIntelGPU() &&
+         "cannot get IGCA target of a non-Intel-GPU OffloadArch");
+  return getIntelIGCA(llvm::IntelGPU::getIGCATarget(intelGPUKind()));
+}
+
 const char *OffloadArchToString(OffloadArch A) {
   switch (A.targetArch()) {
   case OffloadArch::TargetArch::Unused:
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index 9b46b38811cb0b..40aa5a91cfca10 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -121,6 +121,22 @@ Compilation::getArgsForToolChain(const ToolChain *TC, BoundArch BA,
   return *Entry;
 }
 
+void Compilation::addSYCLIGCADevice(const ToolChain *TC, StringRef Target,
+                                    StringRef Device) {
+  SmallVector<StringRef, 2> &Devices = SYCLIGCADevices[{TC, Target}];
+  auto It = llvm::lower_bound(Devices, Device);
+  if (It == Devices.end() || *It != Device)
+    Devices.insert(It, Device);
+}
+
+ArrayRef<StringRef> Compilation::getSYCLIGCADevices(const ToolChain *TC,
+                                                    StringRef Target) const {
+  auto It = SYCLIGCADevices.find({TC, Target});
+  if (It == SYCLIGCADevices.end())
+    return {};
+  return It->second;
+}
+
 bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
   // FIXME: Why are we trying to remove files that we have not created? For
   // example we should only try to remove a temporary assembly file if
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9d95f69f1bbfe1..fdd2dcec9a03f1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4151,6 +4151,24 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
   Args.ClaimAllArgs(options::OPT_offload_arch_EQ);
   Args.ClaimAllArgs(options::OPT_no_offload_arch_EQ);
 
+  // For SYCL, compile once per IGCA target rather than once per Intel GPU,
+  // e.g. once for igca_30r for xe-mtl-u and xe-mtl-h, and record the GPUs so
+  // that the compile is also done ahead of time for them.
+  if (Kind == Action::OFK_SYCL) {
+    llvm::DenseSet<StringRef> Targets;
+    for (StringRef Arch : Archs) {
+      OffloadArch ID = StringToOffloadArch(Arch);
+      if (!ID.isIntelGPU()) {
+        Targets.insert(Arch);
+        continue;
+      }
+      StringRef Target = OffloadArchToString(ID.intelGPUIGCATarget());
+      Targets.insert(Target);
+      C.addSYCLIGCADevice(&TC, Target, Arch);
+    }
+    Archs = std::move(Targets);
+  }
+
   SmallVector<StringRef> Sorted(Archs.begin(), Archs.end());
   llvm::sort(Sorted);
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index d8819c952e5add..5ea1ca5888219b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9759,6 +9759,13 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
         "kind=" + Kind.str(),
     };
 
+    // List the Intel GPUs that a SYCL device compile for an IGCA target is
+    // compiled ahead of time for, one "code=" each. llvm-offload-binary joins
+    // repeated keys, so the image gets "code=xe-mtl-h,xe-mtl-u".
+    if (OffloadAction->getOffloadingDeviceKind() == Action::OFK_SYCL)
+      for (StringRef Device : C.getSYCLIGCADevices(TC, Arch.ArchName))
+        Parts.emplace_back("code=" + Device.str());
+
     if (TC->isUsingLTO(TCArgs, OffloadAction->getOffloadingDeviceKind()))
       for (StringRef Feature : FeatureArgs)
         Parts.emplace_back("feature=" + Feature.str());
@@ -9953,8 +9960,13 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
       for (StringRef Arg : ToolChainArgs.getAllArgValues(OPT_offload_arch_EQ)) {
         std::optional<std::string> TargetID =
             getCanonicalTargetID(TC->getTriple(), Arg);
-        CmdArgs.emplace_back(Args.MakeArgString(
-            "--should-extract=" + (TargetID ? StringRef(*TargetID) : Arg)));
+        StringRef Name = TargetID ? StringRef(*TargetID) : Arg;
+        // A SYCL device image for an Intel GPU is labeled with the GPU's IGCA
+        // target.
+        if (Kind == Action::OFK_SYCL)
+          if (OffloadArch ID = StringToOffloadArch(Arg); ID.isIntelGPU())
+            Name = OffloadArchToString(ID.intelGPUIGCATarget());
+        CmdArgs.emplace_back(Args.MakeArgString("--should-extract=" + Name));
       }
 
       // If this is OpenMP the device linker will need `-lompdevice`.
diff --git a/clang/test/Driver/sycl-igca-link.cpp b/clang/test/Driver/sycl-igca-link.cpp
new file mode 100644
index 00000000000000..d46739f5ae4bf2
--- /dev/null
+++ b/clang/test/Driver/sycl-igca-link.cpp
@@ -0,0 +1,30 @@
+/// Device code for Intel GPUs is compiled once per IGCA target. At link time,
+/// device code for the same IGCA target and devices is linked together, and
+/// compiled ahead of time for those devices.
+
+// REQUIRES: x86-registered-target
+// UNSUPPORTED: system-windows
+
+// RUN: %clang -fsycl --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=xe-mtl-u,xe-mtl-h -c %s -o %t-uh-a.o
+// RUN: %clang -fsycl --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=xe-mtl-h,xe-mtl-u -c %s -o %t-uh-b.o
+// RUN: %clang -fsycl --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=xe-mtl-u -c %s -o %t-u.o
+
+/// xe-mtl-u and xe-mtl-h share igca_30r, so both objects have one device image
+/// for igca_30r with the same devices, and their device code is linked together
+/// for both devices.
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --linker-path=/usr/bin/ld %t-uh-a.o %t-uh-b.o -o a.out 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=SAME-DEVICES
+// SAME-DEVICES:     clang{{.*}} -march=igca_30r {{.*}}.o {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-h -Xlinker --device=xe-mtl-u{{$}}
+// SAME-DEVICES-NOT: --sycl-link
+
+/// An object compiled for xe-mtl-u only has a different list of devices, so its
+/// device code is linked separately.
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --linker-path=/usr/bin/ld %t-u.o %t-uh-a.o -o a.out 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DIFFERENT-DEVICES
+// DIFFERENT-DEVICES-DAG: clang{{.*}} -march=igca_30r {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-u{{$}}
+// DIFFERENT-DEVICES-DAG: clang{{.*}} -march=igca_30r {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-h -Xlinker --device=xe-mtl-u{{$}}
diff --git a/clang/test/Driver/sycl-intel-gpu-arch.cpp b/clang/test/Driver/sycl-intel-gpu-arch.cpp
index 686570c91e0ea8..0aa5b0b7bd87a8 100644
--- a/clang/test/Driver/sycl-intel-gpu-arch.cpp
+++ b/clang/test/Driver/sycl-intel-gpu-arch.cpp
@@ -1,21 +1,46 @@
 /// Tests for Intel GPU names in --offload-arch.
 
-/// An Intel GPU name names a device job.
+/// An Intel GPU is compiled for its IGCA target, e.g. xe-bmg-g21 for igca_40r.
 // RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
 // RUN:   --offload-targets=spirv64-unknown-unknown --offload-arch=xe-bmg-g21 \
 // RUN:   --offload-arch=xe-dg2 -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-SYCL %s
-// CHK-SYCL-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-bmg-g21)"
-// CHK-SYCL-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-dg2)"
+// CHK-SYCL-DAG: offload, "device-sycl (spirv64-unknown-unknown:igca_40r)"
+// CHK-SYCL-DAG: offload, "device-sycl (spirv64-unknown-unknown:igca_15ra)"
 
-/// A device name, an alias and a numeric name are kept as given.
-// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
+/// A device name, an alias and a numeric name of one device give one device
+/// image for its IGCA target, which lists each name as given, to compile ahead
+/// of time for.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
 // RUN:   --offload-targets=spirv64-unknown-unknown --offload-arch=xe-mtl-u \
 // RUN:   --offload-arch=xe-arl-u --offload-arch=xe_12.70.0 -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-AS-GIVEN %s
-// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-mtl-u)"
-// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-arl-u)"
-// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe_12.70.0)"
+// CHK-AS-GIVEN: llvm-offload-binary{{.*}} "--image=file={{.*}},triple=spirv64-unknown-unknown,arch=igca_30r,kind=sycl,code=xe-arl-u,code=xe-mtl-u,code=xe_12.70.0"
+// CHK-AS-GIVEN-NOT: --image=
+
+/// The devices are sorted, so that objects compiled for the same devices in any
+/// order have the same list and are linked together.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN:   --offload-arch=xe-mtl-h,xe-mtl-u -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-SORTED %s
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN:   --offload-arch=xe-mtl-u,xe-mtl-h -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-SORTED %s
+// CHK-SORTED: "--image=file={{.*}},arch=igca_30r,kind=sycl,code=xe-mtl-h,code=xe-mtl-u"
+
+/// An IGCA target given directly lists no devices, so it is compiled just in
+/// time.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN:   --offload-arch=igca_30r -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-IGCA-ONLY %s
+// CHK-IGCA-ONLY: "--image=file={{.*}},arch=igca_30r,kind=sycl"
+
+/// Static libraries are searched for the IGCA target of an Intel GPU.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN:   --offload-arch=xe-mtl-u,xe-mtl-h %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-EXTRACT %s
+// CHK-EXTRACT: clang-linker-wrapper{{.*}} "--should-extract=igca_30r"
+// CHK-EXTRACT-NOT: --should-extract=xe-
 
 /// Without --offload-targets, an Intel device (by name or numeric name), an IGCA
 /// target or "generic" picks SPIR-V of the host's width.
@@ -26,24 +51,21 @@
 // CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:generic)"
 // CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:graniterapids)"
 // CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:igca_20ca)"
-// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-bmg-g21)"
-// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-pvc)"
-// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe_12.60.7)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:igca_40r)"
 // RUN: %clang -ccc-print-phases --target=i386-unknown-linux-gnu -fsycl \
 // RUN:   --offload-arch=xe-pvc --offload-arch=igca_20ca -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-NO-TARGETS-32 %s
-// CHK-NO-TARGETS-32-DAG: offload, "device-sycl (spirv32-unknown-unknown:xe-pvc)"
-// CHK-NO-TARGETS-32-DAG: offload, "device-sycl (spirv32-unknown-unknown:igca_20ca)"
-/// Names are kept as given, so two aliases of one device make two device jobs,
-/// and --no-offload-arch removes a name.
-// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
+// CHK-NO-TARGETS-32: offload, "device-sycl (spirv32-unknown-unknown:igca_20ca)"
+// CHK-NO-TARGETS-32-NOT: device-sycl (spirv
+
+/// Two names of one device give one device image that lists both, and
+/// --no-offload-arch removes a name.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
 // RUN:   --offload-arch=xe-mtl-u --offload-arch=xe-arl-u --offload-arch=xe-pvc \
 // RUN:   --no-offload-arch=xe-pvc -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-NO-TARGETS-AS-GIVEN %s
-// CHK-NO-TARGETS-AS-GIVEN-NOT: xe-pvc
-// CHK-NO-TARGETS-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-mtl-u)"
-// CHK-NO-TARGETS-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-arl-u)"
-// CHK-NO-TARGETS-AS-GIVEN-NOT: xe-pvc
+// CHK-NO-TARGETS-AS-GIVEN: "--image=file={{.*}},arch=igca_30r,kind=sycl,code=xe-arl-u,code=xe-mtl-u"
+// CHK-NO-TARGETS-AS-GIVEN-NOT: {{igca_20ca|xe-pvc}}
 
 /// As for CUDA and HIP, -foffload-via-llvm gives the inferred target the LLVM
 /// environment.
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index 40b6a9ede9ed85..a3908c5df884b9 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -91,7 +91,7 @@
 // RUN:   --offload-targets=spirv64-unknown-unknown --offload-arch=generic --offload-arch=xe-bmg-g21 \
 // RUN:   -c %s 2>&1 | FileCheck -check-prefixes=CHK-PHASES-NORDC-ARCHS %s
 // CHK-PHASES-NORDC-ARCHS: 7: offload, "device-sycl (spirv64-unknown-unknown:generic)" {6}, ir
-// CHK-PHASES-NORDC-ARCHS: 12: offload, "device-sycl (spirv64-unknown-unknown:xe-bmg-g21)" {11}, ir
+// CHK-PHASES-NORDC-ARCHS: 12: offload, "device-sycl (spirv64-unknown-unknown:igca_40r)" {11}, ir
 // CHK-PHASES-NORDC-ARCHS-NEXT: 13: llvm-offload-binary, {7, 12}, image, (device-sycl)
 // CHK-PHASES-NORDC-ARCHS-NEXT: 14: clang-linker-wrapper, {13}, sycl-fatbin, (device-sycl)
 
diff --git a/clang/test/Driver/sycl-system-arch.cpp b/clang/test/Driver/sycl-system-arch.cpp
index b5c86ab760f04f..0323182e486f8b 100644
--- a/clang/test/Driver/sycl-system-arch.cpp
+++ b/clang/test/Driver/sycl-system-arch.cpp
@@ -14,7 +14,7 @@
 // RUN:   --offload-arch=native --offload-arch-tool=%t/offload_arch_sm_70_gfx906_gfx90a_xe_pvc \
 // RUN:   -c %s 2>&1 | FileCheck %s
 // CHECK-NOT: "device-sycl ({{amdgpu|nvptx}}
-// CHECK: offload, "device-sycl (spirv64-unknown-unknown:xe-pvc)"
+// CHECK: offload, "device-sycl (spirv64-unknown-unknown:igca_20ca)"
 // CHECK-NOT: "device-sycl ({{amdgpu|nvptx}}
 
 /// Without an Intel GPU, SYCL reports that no GPU was found, as HIP and CUDA
diff --git a/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper.c b/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper.c
index b092052cabb9e0..4db98ef3fe0beb 100644
--- a/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper.c
+++ b/clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper.c
@@ -65,6 +65,37 @@ __attribute__((visibility("protected"), used)) int x;
 
 // SPIRV-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.spirv64.foo.img. --target=spirv64-unknown-unknown -march=foo {{.*}}.o --sycl-link{{$}}
 
+// SYCL images with the same IGCA target and the same "code" list are linked
+// together and compiled ahead of time for the devices in the list. Images with
+// a different "code" list are linked separately.
+// RUN: llvm-offload-binary -o %t.sycl-u.out \
+// RUN:   --image=file=%t.spirv.bc,kind=sycl,triple=spirv64-unknown-unknown,arch=igca_30r,code=xe-mtl-u
+// RUN: llvm-offload-binary -o %t.sycl-uh.out \
+// RUN:   --image=file=%t.spirv.bc,kind=sycl,triple=spirv64-unknown-unknown,arch=igca_30r,code=xe-mtl-u,code=xe-mtl-h
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.sycl-u.o -fembed-offload-object=%t.sycl-u.out
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.sycl-uh-a.o -fembed-offload-object=%t.sycl-uh.out
+// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.sycl-uh-b.o -fembed-offload-object=%t.sycl-uh.out
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --linker-path=/usr/bin/ld %t.sycl-uh-a.o %t.sycl-uh-b.o -o a.out 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=SYCL-SAME-CODE
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --linker-path=/usr/bin/ld %t.sycl-u.o %t.sycl-uh-a.o -o a.out 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=SYCL-DIFFERENT-CODE
+// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
+// RUN:   --save-temps --linker-path=/usr/bin/ld %t.sycl-u.o %t.sycl-uh-a.o \
+// RUN:   -o a.out 2>&1 | FileCheck %s --check-prefix=SYCL-SAVE-TEMPS
+
+// SYCL-SAME-CODE:     clang{{.*}} -march=igca_30r {{.*}}.o {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-u -Xlinker --device=xe-mtl-h{{$}}
+// SYCL-SAME-CODE-NOT: --sycl-link
+
+// SYCL-DIFFERENT-CODE-DAG: clang{{.*}} -march=igca_30r {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-u{{$}}
+// SYCL-DIFFERENT-CODE-DAG: clang{{.*}} -march=igca_30r {{.*}}.o --sycl-link -Xlinker --device=xe-mtl-u -Xlinker --device=xe-mtl-h{{$}}
+
+// The devices are part of the output name, so the two images do not overwrite
+// each other with --save-temps.
+// SYCL-SAVE-TEMPS-DAG: clang{{.*}} -o a.out.spirv64.igca_30r.xe-mtl-u.img {{.*}}--device=xe-mtl-u{{$}}
+// SYCL-SAVE-TEMPS-DAG: clang{{.*}} -o a.out.spirv64.igca_30r.xe-mtl-u.xe-mtl-h.img {{.*}}--device=xe-mtl-h{{$}}
+
 // RUN: llvm-offload-binary -o %t.out \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu
diff --git a/clang/test/OffloadTools/clang-sycl-linker/basic.ll b/clang/test/OffloadTools/clang-sycl-linker/basic.ll
index 8e0523c1ea2665..1095cd227f05b1 100644
--- a/clang/test/OffloadTools/clang-sycl-linker/basic.ll
+++ b/clang/test/OffloadTools/clang-sycl-linker/basic.ll
@@ -124,6 +124,24 @@
 ; RUN:   | FileCheck %s --check-prefix=AOT-INTEL-OCLOC-OPTIONS
 ; AOT-INTEL-OCLOC-OPTIONS: "{{.*}}ocloc{{.*}}" {{.*}}-device xe-bmg-g21 -a -b -c d "-e -f"
 ;
+; Test that an IGCA target is compiled ahead of time with one ocloc call for its
+; --device list.
+; RUN: clang-sycl-linker --dry-run -v --module-split-mode=link_unit -arch=igca_30r --device=xe-mtl-u --device=xe-mtl-h %t/input1.bc %t/input2.bc -o %t/aot-igca.out 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=AOT-IGCA
+; AOT-IGCA:      link: inputs: {{.*}}.bc, {{.*}}.bc output: [[LLVMLINKOUT:.*]].bc
+; AOT-IGCA-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: [[SPVSTEM:.*]].spv
+; AOT-IGCA-NEXT: "{{.*}}ocloc{{.*}}" {{.*}}-device xe-mtl-u,xe-mtl-h {{.*}}-output [[SPVSTEM]].out -file [[SPVSTEM]].spv
+; AOT-IGCA-NEXT: sycl-bundle: image kind: o, triple: spirv64-unknown-unknown, arch: igca_30r
+; AOT-IGCA-NOT:  {{.+}}
+;
+; Test that an IGCA target without --device is compiled just in time.
+; RUN: clang-sycl-linker --dry-run -v --module-split-mode=link_unit -arch=igca_30r %t/input1.bc %t/input2.bc -o %t/jit-igca.out 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=JIT-IGCA
+; JIT-IGCA:      link: inputs: {{.*}}.bc, {{.*}}.bc output: [[LLVMLINKOUT:.*]].bc
+; JIT-IGCA-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: {{.*}}.spv
+; JIT-IGCA-NEXT: sycl-bundle: image kind: spv, triple: spirv64-unknown-unknown, arch: igca_30r
+; JIT-IGCA-NOT:  {{.+}}
+;
 ; Test AOT compilation for an Intel CPU.
 ; Test that IMG_Object image kind is set for AOT compilation (Intel CPU).
 ; RUN: clang-sycl-linker --dry-run -v --module-split-mode=link_unit -arch=graniterapids %t/input1.bc %t/input2.bc -o %t/aot-cpu.out 2>&1 \
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9f3976949d3f6b..8b8a4fcf7df793 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -504,6 +504,11 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
   // input filename already has the device and architecture.
   std::string OutputFileBase =
       "." + Triple.getArchName().str() + "." + Arch.str();
+  // Images with the same architecture but different devices are linked
+  // separately, so the devices are part of the name.
+  std::vector<std::string> Devices = Args.getAllArgValues(OPT_device_EQ);
+  for (const std::string &Device : Devices)
+    OutputFileBase += "." + Device;
   auto TempFileOrErr = createOutputFile(ExecutableName + OutputFileBase, "img");
   if (!TempFileOrErr)
     return TempFileOrErr.takeError();
@@ -592,6 +597,10 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
   if (ActiveOffloadKindMask & OFK_SYCL)
     CmdArgs.push_back("--sycl-link");
 
+  // Pass the devices to compile ahead of time for on to clang-sycl-linker.
+  for (const std::string &Device : Devices)
+    CmdArgs.append({"-Xlinker", Args.MakeArgString("--device=" + Device)});
+
   for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
     CmdArgs.append({"-Xlinker", Args.MakeArgString(Arg)});
   for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))
@@ -1012,6 +1021,15 @@ DerivedArgList getLinkerArgs(ArrayRef<OffloadFile> Input,
   DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_triple_EQ),
                    Args.MakeArgString(Input.front().getBinary()->getTriple()));
 
+  // Record the Intel GPUs that a SYCL image lists in "code", which
+  // clang-sycl-linker compiles the image ahead of time for.
+  const OffloadBinary &Binary = *Input.front().getBinary();
+  if (Binary.getOffloadKind() == OFK_SYCL)
+    for (StringRef Device : llvm::split(Binary.getString("code"), ','))
+      if (!Device.empty())
+        DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_device_EQ),
+                         Args.MakeArgString(Device));
+
   // If every input file is bitcode we have whole program visibility as we
   // do only support static linking with bitcode.
   auto ContainsBitcode = [](const OffloadFile &F) {
@@ -1444,16 +1462,25 @@ getDeviceInput(const ArgList &Args) {
                              B.getBinary()->getArch().count(':');
                     });
 
+  // A SYCL image can also list the Intel GPUs to compile it ahead of time for,
+  // e.g. "code=xe-mtl-u,xe-mtl-h". Images with different lists are linked
+  // separately, so the key of an image is its target and its "code" value.
+  using ImageID = std::pair<OffloadFile::TargetID, StringRef>;
+  auto GetImageID = [](const OffloadFile &Binary) -> ImageID {
+    return {Binary, Binary.getBinary()->getString("code")};
+  };
+
   // Link all standard input files and update the list of symbols.
-  MapVector<OffloadFile::TargetID, SmallVector<OffloadFile, 0>> InputFiles;
+  MapVector<ImageID, SmallVector<OffloadFile, 0>> InputFiles;
   for (OffloadFile &Binary : ObjectFilesToExtract) {
     if (!Binary.getBinary())
       continue;
 
-    OffloadFile::TargetID Target = Binary;
-    SmallVector<OffloadFile::TargetID> CompatibleTargets;
+    ImageID Target = GetImageID(Binary);
+    SmallVector<ImageID> CompatibleTargets;
     for (const auto &[ID, Input] : InputFiles)
-      if (object::areTargetsEquivalent(Target, ID))
+      if (Target.second == ID.second &&
+          object::areTargetsEquivalent(Target.first, ID.first))
         CompatibleTargets.emplace_back(ID);
 
     // Seed a new image when no existing target can provide for this input.
@@ -1480,16 +1507,17 @@ getDeviceInput(const ArgList &Args) {
     if (!Binary.getBinary())
       continue;
 
-    SmallVector<OffloadFile::TargetID> CompatibleTargets = {Binary};
+    ImageID Target = GetImageID(Binary);
+    SmallVector<ImageID> CompatibleTargets = {Target};
     for (const auto &[ID, Input] : InputFiles)
-      if (OffloadFile::TargetID(Binary) != ID &&
-          object::areTargetsCompatible(Binary, ID))
+      if (Target != ID && Target.second == ID.second &&
+          object::areTargetsCompatible(Target.first, ID.first))
         CompatibleTargets.emplace_back(ID);
 
     for (const auto &[Index, ID] : llvm::enumerate(CompatibleTargets)) {
       // Only extract if we have an object matching this target or it
       // was specifically requested.
-      if (!InputFiles.count(ID) && !ShouldExtract.contains(ID.second))
+      if (!InputFiles.count(ID) && !ShouldExtract.contains(ID.first.second))
         continue;
 
       // If another target needs this binary it must be copied instead.
diff --git a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
index fc48eac2637eeb..d045b02428adfa 100644
--- a/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ b/clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -80,6 +80,9 @@ def arch_EQ : Joined<["--"], "arch=">,
 def triple_EQ : Joined<["--"], "triple=">,
   Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"<triple>">,
   HelpText<"The device target triple">;
+def device_EQ : Joined<["--"], "device=">,
+  Flags<[DeviceOnlyOption, HelpHidden]>, MetaVarName<"<device>">,
+  HelpText<"An Intel GPU to compile a SYCL image ahead of time for">;
 def whole_program : Flag<["--"], "whole-program">,
   Flags<[DeviceOnlyOption, HelpHidden]>,
   HelpText<"LTO has visibility of all input files">;
diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index 8b179f4c37e23b..314913a829e925 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -714,10 +714,14 @@ static Error runAOTCompileIntelGPU(StringRef InputFile, StringRef OutputFile,
   CmdArgs.push_back("-output_no_suffix");
   CmdArgs.push_back("-spirv_input");
 
-  StringRef Arch(Args.getLastArgValue(OPT_arch_EQ));
-  assert(!Arch.empty() && "Arch must be specified for AOT compilation");
+  // Compile for the --device list, e.g. "xe-mtl-u,xe-mtl-h" for an IGCA
+  // target, or else for the Intel GPU in --arch.
+  std::string Devices = llvm::join(Args.getAllArgValues(OPT_device_EQ), ",");
+  if (Devices.empty())
+    Devices = Args.getLastArgValue(OPT_arch_EQ);
+  assert(!Devices.empty() && "a device must be specified for AOT compilation");
   CmdArgs.push_back("-device");
-  CmdArgs.push_back(Arch);
+  CmdArgs.push_back(Devices);
 
   // getAllArgValues returns a temporary vector; retain it so the StringRefs
   // remain valid through the executeCommands call below.
@@ -742,15 +746,11 @@ static Error runAOTCompileIntelGPU(StringRef InputFile, StringRef OutputFile,
 /// into the AOT compilation step.
 static Error runAOTCompile(StringRef InputFile, StringRef OutputFile,
                            const ArgList &Args) {
-  StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);
-  OffloadArch OA = StringToOffloadArch(Arch);
-  if (OA.isIntelGPU())
+  OffloadArch OA = StringToOffloadArch(Args.getLastArgValue(OPT_arch_EQ));
+  if (OA.isIntelGPU() || OA.isIntelIGCA())
     return runAOTCompileIntelGPU(InputFile, OutputFile, Args);
   if (OA.isIntelCPU())
     return runAOTCompileIntelCPU(InputFile, OutputFile, Args);
-  if (OA.isIntelIGCA())
-    return createStringError("AOT compilation for IGCA target '" + Arch +
-                             "' is not yet implemented");
 
   llvm_unreachable("runAOTCompile dispatched on unsupported arch");
 }
@@ -1002,8 +1002,11 @@ static Error runSYCLLink(ArrayRef<std::unique_ptr<MemoryBuffer>> Inputs,
     SplitModules = std::move(*SplitModulesOrErr);
   }
 
+  // An IGCA target is compiled ahead of time only for its --device list, and
+  // otherwise just in time.
+  OffloadArch OA = StringToOffloadArch(Args.getLastArgValue(OPT_arch_EQ));
   bool IsAOTCompileNeeded =
-      StringToOffloadArch(Args.getLastArgValue(OPT_arch_EQ)).isIntel();
+      OA.isIntelIGCA() ? Args.hasArg(OPT_device_EQ) : OA.isIntel();
 
   StringRef OutputFileNameExt = ".spv";
 
diff --git a/clang/tools/clang-sycl-linker/SYCLLinkOpts.td b/clang/tools/clang-sycl-linker/SYCLLinkOpts.td
index 965ab6b5e4e65d..db81c494be0527 100644
--- a/clang/tools/clang-sycl-linker/SYCLLinkOpts.td
+++ b/clang/tools/clang-sycl-linker/SYCLLinkOpts.td
@@ -46,6 +46,11 @@ def arch_EQ : Joined<["--", "-"], "arch=">,
               Flags<[LinkerOnlyOption]>,
               MetaVarName<"<arch>">,
               HelpText<"The device architecture">;
+def device_EQ : Joined<["--", "-"], "device=">,
+                Flags<[LinkerOnlyOption]>,
+                MetaVarName<"<device>">,
+                HelpText<"An Intel GPU to compile ahead of time for. Can be "
+                         "repeated. Defaults to --arch for an Intel GPU">;
 def triple_EQ : Joined<["--", "-"], "triple=">,
                 Flags<[LinkerOnlyOption]>,
                 MetaVarName<"<triple>">,
diff --git a/clang/unittests/Basic/OffloadArchTest.cpp b/clang/unittests/Basic/OffloadArchTest.cpp
index 4ebee22fb2294d..2ed374e1d4a318 100644
--- a/clang/unittests/Basic/OffloadArchTest.cpp
+++ b/clang/unittests/Basic/OffloadArchTest.cpp
@@ -87,6 +87,14 @@ TEST(OffloadArchTest, IntelGPUOtherSpellings) {
   EXPECT_TRUE(parse("bmg_g21").isUnknown());
 }
 
+TEST(OffloadArchTest, IntelGPUIGCATarget) {
+  // Intel GPUs can share an IGCA target.
+  EXPECT_EQ(parse("xe-mtl-u").intelGPUIGCATarget(), parse("igca_30r"));
+  EXPECT_EQ(parse("xe-mtl-h").intelGPUIGCATarget(), parse("igca_30r"));
+  EXPECT_EQ(parse("xe-pvc").intelGPUIGCATarget(), parse("igca_20ca"));
+  EXPECT_TRUE(parse("xe-pvc").intelGPUIGCATarget().isIntelIGCA());
+}
+
 TEST(OffloadArchTest, Defaults) {
   EXPECT_STREQ(OffloadArchToString(OffloadArch::CudaDefault()), "sm_52");
   EXPECT_STREQ(OffloadArchToString(OffloadArch::HIPDefault()), "gfx906");

>From dc3a0fc233372a625f6dda73b4e0f4dfb22891ae Mon Sep 17 00:00:00 2001
From: srividya sundaram <srividya.sundaram at intel.com>
Date: Wed, 4 Nov 2026 15:50:42 -0800
Subject: [PATCH 4/4] [Clang][SYCL] Address review: use DenseMap, document
 --device and code

---
 clang/docs/ClangLinkerWrapper.md         | 5 +++++
 clang/docs/ClangSYCLLinker.md            | 9 +++++++++
 clang/include/clang/Driver/Compilation.h | 4 ++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangLinkerWrapper.md b/clang/docs/ClangLinkerWrapper.md
index 7245d3cead6ad9..df2a946080e0c3 100644
--- a/clang/docs/ClangLinkerWrapper.md
+++ b/clang/docs/ClangLinkerWrapper.md
@@ -82,6 +82,11 @@ other. Generally, this requires that the target triple and architecture match.
 An exception is made when the architecture is listed as `generic`, which will
 cause it be linked with any other device code with the same target triple.
 
+SYCL device code for an IGCA target can also list the Intel GPUs to compile it
+ahead of time for, as `code=xe-mtl-h,xe-mtl-u`. It is only linked with device
+code that lists the same GPUs, and the GPUs are passed on to
+`clang-sycl-linker`.
+
 ## Debugging
 
 The linker wrapper performs a lot of steps internally, such as input matching,
diff --git a/clang/docs/ClangSYCLLinker.md b/clang/docs/ClangSYCLLinker.md
index c527afa8b41f6d..6c156ca2540178 100644
--- a/clang/docs/ClangSYCLLinker.md
+++ b/clang/docs/ClangSYCLLinker.md
@@ -37,6 +37,7 @@ USAGE: clang-sycl-linker [options] <input bitcode files>
 
 OPTIONS:
   --arch <value>                Specify the name of the target architecture.
+  --device=<value>              An Intel GPU to compile ahead of time for. Can be repeated.
   --dry-run                     Print generated commands without running.
   -help-hidden                  Display all available options
   -help                         Display available options (--help-hidden for more)
@@ -108,6 +109,14 @@ generate the final executable.
 clang-sycl-linker --triple spirv64 --arch xe-bmg-g21 input.bc
 ```
 
+For an IGCA target, such as `igca_30r`, the device image is compiled ahead of
+time for the Intel GPUs given with `--device`, with a single ocloc call, or just
+in time if no `--device` is given:
+
+```console
+clang-sycl-linker --triple spirv64 --arch igca_30r --device=xe-mtl-u --device=xe-mtl-h input.bc
+```
+
 ### Linking with Device Libraries
 
 To link device bitcode libraries, first package them into archive files:
diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h
index 59df1af0fc70b3..d7e7deade6f7c0 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -101,8 +101,8 @@ class Compilation {
   /// The Intel GPUs that each SYCL device compile for an IGCA target is
   /// compiled ahead of time for, sorted, e.g. xe-mtl-h and xe-mtl-u for the
   /// igca_30r compile.
-  std::map<std::pair<const ToolChain *, StringRef>,
-           llvm::SmallVector<StringRef, 2>>
+  llvm::DenseMap<std::pair<const ToolChain *, StringRef>,
+                 llvm::SmallVector<StringRef, 2>>
       SYCLIGCADevices;
 
   /// Temporary files which should be removed on exit.



More information about the cfe-commits mailing list