@@ -481,20 +481,34 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
481481 OverlayVFS->pushOverlay (IMVFS);
482482 CI->createFileManager (OverlayVFS);
483483
484- auto Interp = Interpreter::create (std::move (CI));
485- if (auto E = Interp.takeError ())
486- return std::move (E);
484+ llvm::Expected<std::unique_ptr<Interpreter>> InterpOrErr =
485+ Interpreter::create (std::move (CI));
486+ if (!InterpOrErr)
487+ return InterpOrErr;
488+
489+ std::unique_ptr<Interpreter> Interp = std::move (*InterpOrErr);
487490
488491 llvm::Error Err = llvm::Error::success ();
489- auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
490- std::move (DCI), *(*Interp)->getCompilerInstance (), IMVFS, Err,
491- (*Interp)->PTUs );
492+ llvm::LLVMContext &LLVMCtx = *Interp->TSCtx ->getContext ();
493+
494+ auto DeviceAct =
495+ std::make_unique<IncrementalAction>(*DCI, LLVMCtx, Err, *Interp);
496+
492497 if (Err)
493498 return std::move (Err);
494499
495- (*Interp)->DeviceParser = std::move (DeviceParser);
500+ Interp->DeviceAct = std::move (DeviceAct);
501+
502+ DCI->ExecuteAction (*Interp->DeviceAct );
503+
504+ auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
505+ std::move (DCI), *Interp->getCompilerInstance (), IMVFS, Err, Interp->PTUs );
506+
507+ if (Err)
508+ return std::move (Err);
496509
497- return Interp;
510+ Interp->DeviceParser = std::move (DeviceParser);
511+ return std::move (Interp);
498512}
499513
500514const CompilerInstance *Interpreter::getCompilerInstance () const {
@@ -532,15 +546,17 @@ size_t Interpreter::getEffectivePTUSize() const {
532546
533547PartialTranslationUnit &
534548Interpreter::RegisterPTU (TranslationUnitDecl *TU,
535- std::unique_ptr<llvm::Module> M /* ={}*/ ) {
549+ std::unique_ptr<llvm::Module> M /* ={}*/ ,
550+ IncrementalAction *Action) {
536551 PTUs.emplace_back (PartialTranslationUnit ());
537552 PartialTranslationUnit &LastPTU = PTUs.back ();
538553 LastPTU.TUPart = TU;
539554
540555 if (!M)
541- M = GenModule ();
556+ M = GenModule (Action );
542557
543- assert ((!getCodeGen () || M) && " Must have a llvm::Module at this point" );
558+ assert ((!getCodeGen (Action) || M) &&
559+ " Must have a llvm::Module at this point" );
544560
545561 LastPTU.TheModule = std::move (M);
546562 LLVM_DEBUG (llvm::dbgs () << " compile-ptu " << PTUs.size () - 1
@@ -560,6 +576,16 @@ Interpreter::Parse(llvm::StringRef Code) {
560576 llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse (Code);
561577 if (auto E = DeviceTU.takeError ())
562578 return std::move (E);
579+
580+ RegisterPTU (*DeviceTU, nullptr , DeviceAct.get ());
581+
582+ llvm::Expected<llvm::StringRef> PTX = DeviceParser->GeneratePTX ();
583+ if (!PTX)
584+ return PTX.takeError ();
585+
586+ llvm::Error Err = DeviceParser->GenerateFatbinary ();
587+ if (Err)
588+ return std::move (Err);
563589 }
564590
565591 // Tell the interpreter sliently ignore unused expressions since value
@@ -736,9 +762,10 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
736762 return llvm::Error::success ();
737763}
738764
739- std::unique_ptr<llvm::Module> Interpreter::GenModule () {
765+ std::unique_ptr<llvm::Module>
766+ Interpreter::GenModule (IncrementalAction *Action) {
740767 static unsigned ID = 0 ;
741- if (CodeGenerator *CG = getCodeGen ()) {
768+ if (CodeGenerator *CG = getCodeGen (Action )) {
742769 // Clang's CodeGen is designed to work with a single llvm::Module. In many
743770 // cases for convenience various CodeGen parts have a reference to the
744771 // llvm::Module (TheModule or Module) which does not change when a new
@@ -760,8 +787,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
760787 return nullptr ;
761788}
762789
763- CodeGenerator *Interpreter::getCodeGen () const {
764- FrontendAction *WrappedAct = Act->getWrapped ();
790+ CodeGenerator *Interpreter::getCodeGen (IncrementalAction *Action) const {
791+ if (!Action)
792+ Action = Act.get ();
793+ FrontendAction *WrappedAct = Action->getWrapped ();
765794 if (!WrappedAct->hasIRSupport ())
766795 return nullptr ;
767796 return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
0 commit comments