https://github.com/AdityaSinha149 updated 
https://github.com/llvm/llvm-project/pull/231391

>From 57c64f6555a25bb6eb7528c0f3fcb3d2a3bd0638 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 |  6 +++++
 clang/lib/Interpreter/Interpreter.cpp         | 25 ++++++++++++++-----
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index a598574b417c0..9e2699c9ee054 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,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);
+  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

Reply via email to