[clang] [NFC][clang-repl] Introduce OffloadType for CUDA/HIP device selection (PR #231391)
Aditya Sinha via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 00:31:44 PDT 2026
https://github.com/AdityaSinha149 updated https://github.com/llvm/llvm-project/pull/231391
>From 33d046e9bff227d4375893e6b6e398adc146d2b1 Mon Sep 17 00:00:00 2001
From: AdityaSinha149 <adsinha at amd.com>
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 | 7 +++++++
clang/lib/Interpreter/Interpreter.cpp | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index a598574b417c0..9a729f7aeecec 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,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..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>();
More information about the cfe-commits
mailing list