https://github.com/AdityaSinha149 updated https://github.com/llvm/llvm-project/pull/231391
>From 3899de0742ad12f9f883718a90cdc351ef7594db Mon Sep 17 00:00:00 2001 From: AdityaSinha149 <[email protected]> Date: Tue, 13 Oct 2026 11:57:25 +0530 Subject: [PATCH 1/2] [NFC][clang-repl] Introduce OffloadType for CUDA/HIP device selection --- clang/include/clang/Interpreter/Interpreter.h | 8 ++++++++ clang/lib/Interpreter/Interpreter.cpp | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index a598574b417c0..64f02b797c204 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -46,6 +46,10 @@ class Decl; class IncrementalParser; class IncrementalDeviceParser; +/// The device language to offload to. \c Detect selects the vendor of the +/// device available on the machine. +enum class OffloadType { Detect, CUDA, HIP }; + /// Create a pre-configured \c CompilerInstance for incremental processing. class IncrementalCompilerBuilder { using DriverCompilationFn = llvm::Error(const driver::Compilation &); @@ -147,6 +151,10 @@ class Interpreter { create(std::unique_ptr<CompilerInstance> CI, std::unique_ptr<IncrementalExecutorBuilder> IEB = nullptr); static llvm::Expected<std::unique_ptr<Interpreter>> + createWithDevice(std::unique_ptr<CompilerInstance> CI, + std::unique_ptr<CompilerInstance> DCI, + OffloadType Type = OffloadType::Detect); + static llvm::Expected<std::unique_ptr<Interpreter>> createWithCUDA(std::unique_ptr<CompilerInstance> CI, std::unique_ptr<CompilerInstance> DCI); diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index a8e54d62864b5..124ed44835593 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -479,6 +479,13 @@ llvm::Expected<std::unique_ptr<Interpreter>> Interpreter::create( llvm::Expected<std::unique_ptr<Interpreter>> Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI, std::unique_ptr<CompilerInstance> DCI) { + return createWithDevice(std::move(CI), std::move(DCI), OffloadType::CUDA); +} + +llvm::Expected<std::unique_ptr<Interpreter>> +Interpreter::createWithDevice(std::unique_ptr<CompilerInstance> CI, + std::unique_ptr<CompilerInstance> DCI, + OffloadType Type) { // avoid writing fat binary to disk using an in-memory virtual file system llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> IMVFS = std::make_unique<llvm::vfs::InMemoryFileSystem>(); >From 48f549c4926bbc2633a469270f5d370e8d5caf04 Mon Sep 17 00:00:00 2001 From: AdityaSinha149 <[email protected]> Date: Tue, 13 Oct 2026 12:11:18 +0530 Subject: [PATCH 2/2] [clang-repl] Add IncrementalHIPDeviceParser [1/4]: Add class skeleton --- clang/lib/Interpreter/DeviceOffload.cpp | 25 +++++++++++++++++++++++++ clang/lib/Interpreter/DeviceOffload.h | 16 +++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp index e5887bc9c8841..165f5877e9493 100644 --- a/clang/lib/Interpreter/DeviceOffload.cpp +++ b/clang/lib/Interpreter/DeviceOffload.cpp @@ -36,6 +36,31 @@ IncrementalDeviceParser::IncrementalDeviceParser( IncrementalDeviceParser::~IncrementalDeviceParser() {} +IncrementalHIPDeviceParser::IncrementalHIPDeviceParser( + CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, + IncrementalAction *DeviceAct, + llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS, + llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs) + : IncrementalDeviceParser(DeviceInstance, HostInstance, DeviceAct, FS, Err, + PTUs) { + if (Err) + return; + StringRef Arch = TargetOpts.CPU; + if (!Arch.starts_with("gfx")) { + Err = llvm::joinErrors(std::move(Err), llvm::make_error<llvm::StringError>( + "Invalid HIP architecture", + llvm::inconvertibleErrorCode())); + return; + } +} + +llvm::Error IncrementalHIPDeviceParser::GenerateOffloadBinary() { + // FIXME: Generate the HSACO and bundle it for the host compilation. + return llvm::Error::success(); +} + +IncrementalHIPDeviceParser::~IncrementalHIPDeviceParser() {} + IncrementalCUDADeviceParser::IncrementalCUDADeviceParser( CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, IncrementalAction *DeviceAct, diff --git a/clang/lib/Interpreter/DeviceOffload.h b/clang/lib/Interpreter/DeviceOffload.h index fc780ef64add8..0275c0e10cda8 100644 --- a/clang/lib/Interpreter/DeviceOffload.h +++ b/clang/lib/Interpreter/DeviceOffload.h @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// This file defines a base class required for offloading to devices. +// This file defines the classes required for offloading to devices. // //===----------------------------------------------------------------------===// @@ -44,6 +44,20 @@ class IncrementalDeviceParser : public IncrementalParser { const TargetOptions &TargetOpts; }; +class IncrementalHIPDeviceParser : public IncrementalDeviceParser { + +public: + IncrementalHIPDeviceParser( + CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, + IncrementalAction *DeviceAct, + llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS, + llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs); + + llvm::Error GenerateOffloadBinary() override; + + ~IncrementalHIPDeviceParser() override; +}; + class IncrementalCUDADeviceParser : public IncrementalDeviceParser { public: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
