diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 56213f88b9e30..f8663e3193a18 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -116,6 +116,9 @@ class Interpreter { /// Compiler instance performing the incremental compilation. std::unique_ptr CI; + /// An optional compiler instance for CUDA offloading + std::unique_ptr DeviceCI; + protected: // Derived classes can use an extended interface of the Interpreter. Interpreter(std::unique_ptr Instance, llvm::Error &Err, diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp index 7d0125403ea52..05625ddedb72f 100644 --- a/clang/lib/Interpreter/DeviceOffload.cpp +++ b/clang/lib/Interpreter/DeviceOffload.cpp @@ -25,13 +25,12 @@ namespace clang { IncrementalCUDADeviceParser::IncrementalCUDADeviceParser( - std::unique_ptr DeviceInstance, - CompilerInstance &HostInstance, + CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, llvm::IntrusiveRefCntPtr FS, llvm::Error &Err, const std::list &PTUs) - : IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS), + : IncrementalParser(DeviceInstance, Err), PTUs(PTUs), VFS(FS), CodeGenOpts(HostInstance.getCodeGenOpts()), - TargetOpts(DeviceInstance->getTargetOpts()) { + TargetOpts(DeviceInstance.getTargetOpts()) { if (Err) return; StringRef Arch = TargetOpts.CPU; @@ -41,7 +40,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser( llvm::inconvertibleErrorCode())); return; } - DeviceCI = std::move(DeviceInstance); } llvm::Expected IncrementalCUDADeviceParser::GeneratePTX() { diff --git a/clang/lib/Interpreter/DeviceOffload.h b/clang/lib/Interpreter/DeviceOffload.h index 43645033c4840..0b903e31c6799 100644 --- a/clang/lib/Interpreter/DeviceOffload.h +++ b/clang/lib/Interpreter/DeviceOffload.h @@ -28,8 +28,7 @@ class IncrementalCUDADeviceParser : public IncrementalParser { public: IncrementalCUDADeviceParser( - std::unique_ptr DeviceInstance, - CompilerInstance &HostInstance, + CompilerInstance &DeviceInstance, CompilerInstance &HostInstance, llvm::IntrusiveRefCntPtr VFS, llvm::Error &Err, const std::list &PTUs); @@ -42,7 +41,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser { ~IncrementalCUDADeviceParser(); protected: - std::unique_ptr DeviceCI; int SMVersion; llvm::SmallString<1024> PTXCode; llvm::SmallVector FatbinContent; diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index f91563dd0378c..3b81f9d701b42 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -416,6 +416,10 @@ Interpreter::Interpreter(std::unique_ptr Instance, Interpreter::~Interpreter() { IncrParser.reset(); Act->FinalizeAction(); + if (DeviceParser) + DeviceParser.reset(); + if (DeviceAct) + DeviceAct->FinalizeAction(); if (IncrExecutor) { if (llvm::Error Err = IncrExecutor->cleanUp()) llvm::report_fatal_error( @@ -501,8 +505,11 @@ Interpreter::createWithCUDA(std::unique_ptr CI, DCI->ExecuteAction(*Interp->DeviceAct); + Interp->DeviceCI = std::move(DCI); + auto DeviceParser = std::make_unique( - std::move(DCI), *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs); + *Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err, + Interp->PTUs); if (Err) return std::move(Err);