[clang] [clang-repl] Add an interface for linking device code objects (PR #245574)
Aditya Sinha via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 03:16:33 PST 2026
https://github.com/AdityaSinha149 created https://github.com/llvm/llvm-project/pull/245574
This PR adds a `DeviceCodeObjectLinker` interface that turns a relocatable device object into a loadable code object.
`selectDeviceCodeObjectLinker` chooses the implementation. If the user passes `--ld-path`, an external linker is used. Otherwise, it falls back to an in-process (JITLink-based) linker.
The selector is a placeholder for now and always returns an error.
>From 24f1d895352b2dfb9a9e5f028c41c755e889966a Mon Sep 17 00:00:00 2001
From: AdityaSinha149 <adsinha at amd.com>
Date: Tue, 24 Nov 2026 16:36:58 +0530
Subject: [PATCH] [clang-repl] Add an interface for linking device code objects
---
clang/lib/Interpreter/CMakeLists.txt | 1 +
.../Interpreter/DeviceCodeObjectLinker.cpp | 39 +++++++++++++++++++
.../lib/Interpreter/DeviceCodeObjectLinker.h | 32 +++++++++++++++
3 files changed, 72 insertions(+)
create mode 100644 clang/lib/Interpreter/DeviceCodeObjectLinker.cpp
create mode 100644 clang/lib/Interpreter/DeviceCodeObjectLinker.h
diff --git a/clang/lib/Interpreter/CMakeLists.txt b/clang/lib/Interpreter/CMakeLists.txt
index 5e2937a2e7dcb9..82fcaadcce21d1 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -29,6 +29,7 @@ else()
endif()
add_clang_library(clangInterpreter
+ DeviceCodeObjectLinker.cpp
DeviceOffload.cpp
CodeCompletion.cpp
IncrementalAction.cpp
diff --git a/clang/lib/Interpreter/DeviceCodeObjectLinker.cpp b/clang/lib/Interpreter/DeviceCodeObjectLinker.cpp
new file mode 100644
index 00000000000000..9374d5e50552fc
--- /dev/null
+++ b/clang/lib/Interpreter/DeviceCodeObjectLinker.cpp
@@ -0,0 +1,39 @@
+//===--- DeviceCodeObjectLinker.cpp - Device Code Object Linker -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "DeviceCodeObjectLinker.h"
+
+#include "clang/Options/Options.h"
+
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/OptTable.h"
+
+#include <memory>
+
+namespace clang {
+
+llvm::Expected<std::unique_ptr<DeviceCodeObjectLinker>>
+selectDeviceCodeObjectLinker(llvm::ArrayRef<const char *> DriverArgs) {
+ unsigned MissingArgIndex, MissingArgCount;
+ llvm::opt::InputArgList Args = getDriverOptTable().ParseArgs(
+ DriverArgs, MissingArgIndex, MissingArgCount,
+ llvm::opt::Visibility(options::ClangOption));
+
+ // An explicit --ld-path means the user asked for an external linker.
+ // FIXME: Return the external linker asked.
+ if (Args.hasArg(options::OPT_ld_path_EQ))
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "No device code object linker is available.");
+
+ // FIXME: Return an in-process (JITLink-based) linker.
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "No device code object linker is available.");
+}
+
+} // namespace clang
diff --git a/clang/lib/Interpreter/DeviceCodeObjectLinker.h b/clang/lib/Interpreter/DeviceCodeObjectLinker.h
new file mode 100644
index 00000000000000..97bcd0196877e3
--- /dev/null
+++ b/clang/lib/Interpreter/DeviceCodeObjectLinker.h
@@ -0,0 +1,32 @@
+//===--- DeviceCodeObjectLinker.h - Device Code Object Linker ---*- 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_LIB_INTERPRETER_DEVICECODEOBJECTLINKER_H
+#define LLVM_CLANG_LIB_INTERPRETER_DEVICECODEOBJECTLINKER_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+#include <memory>
+
+namespace clang {
+
+// Turns one relocatable device object into a loadable code object.
+class DeviceCodeObjectLinker {
+public:
+ virtual ~DeviceCodeObjectLinker() = default;
+ virtual llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
+ link(llvm::MemoryBufferRef Object) = 0;
+};
+
+llvm::Expected<std::unique_ptr<DeviceCodeObjectLinker>>
+selectDeviceCodeObjectLinker(llvm::ArrayRef<const char *> DriverArgs);
+
+} // namespace clang
+
+#endif
More information about the cfe-commits
mailing list