https://github.com/AdityaSinha149 updated https://github.com/llvm/llvm-project/pull/231391
>From 2c6afd4b9dbbfe194eeaaf3af6e246d69f3e0f6a Mon Sep 17 00:00:00 2001 From: AdityaSinha149 <[email protected]> Date: Tue, 13 Oct 2026 11:57:25 +0530 Subject: [PATCH] [NFC][clang-repl] Introduce OffloadType for CUDA/HIP device selection --- clang/include/clang/Interpreter/Interpreter.h | 5 ++++ clang/lib/Interpreter/Interpreter.cpp | 25 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index a598574b417c0..1f3624d0c0331 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -46,6 +46,8 @@ class Decl; class IncrementalParser; class IncrementalDeviceParser; +enum class OffloadType { CUDA, HIP }; + /// Create a pre-configured \c CompilerInstance for incremental processing. class IncrementalCompilerBuilder { using DriverCompilationFn = llvm::Error(const driver::Compilation &); @@ -147,6 +149,9 @@ 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); + 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..5e89b50839760 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>(); @@ -515,14 +522,20 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI, Interp->DeviceCI = std::move(DCI); - auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>( - *Interp->DeviceCI, *Interp->getCompilerInstance(), - Interp->DeviceAct.get(), IMVFS, Err, Interp->PTUs); + if (Type == OffloadType::HIP) { + // FIXME: HIP device parsing is not supported yet; it should use an + // IncrementalHIPDeviceParser once one exists. + } else { + auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>( + *Interp->DeviceCI, *Interp->getCompilerInstance(), + Interp->DeviceAct.get(), IMVFS, Err, Interp->PTUs); - if (Err) - return std::move(Err); + if (Err) + return std::move(Err); + + Interp->DeviceParser = std::move(DeviceParser); + } - Interp->DeviceParser = std::move(DeviceParser); return std::move(Interp); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
