@@ -459,14 +459,28 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI,
459
459
if (Err)
460
460
return std::move (Err);
461
461
462
+ CompilerInstance &HostCI = *(Interp->getCompilerInstance ());
463
+
462
464
if (DeviceCI) {
463
- DeviceCI->ExecuteAction (*Interp->Act );
465
+ Interp->DeviceAct = std::make_unique<IncrementalAction>(
466
+ *DeviceCI, *Interp->TSCtx ->getContext (), Err, *Interp);
467
+
468
+ if (Err)
469
+ return std::move (Err);
470
+
471
+ DeviceCI->ExecuteAction (*Interp->DeviceAct );
464
472
473
+ // avoid writing fat binary to disk using an in-memory virtual file system
465
474
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> IMVFS =
466
475
std::make_unique<llvm::vfs::InMemoryFileSystem>();
476
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayVFS =
477
+ std::make_unique<llvm::vfs::OverlayFileSystem>(
478
+ llvm::vfs::getRealFileSystem ());
479
+ OverlayVFS->pushOverlay (IMVFS);
480
+ HostCI.createFileManager (OverlayVFS);
467
481
468
482
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
469
- std::move (DeviceCI), *Interp-> getCompilerInstance () , IMVFS, Err,
483
+ std::move (DeviceCI), HostCI , IMVFS, Err,
470
484
Interp->PTUs );
471
485
472
486
if (Err)
@@ -489,15 +503,6 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI,
489
503
llvm::Expected<std::unique_ptr<Interpreter>>
490
504
Interpreter::createWithCUDA (std::unique_ptr<CompilerInstance> CI,
491
505
std::unique_ptr<CompilerInstance> DCI) {
492
- // avoid writing fat binary to disk using an in-memory virtual file system
493
- llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> IMVFS =
494
- std::make_unique<llvm::vfs::InMemoryFileSystem>();
495
- llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayVFS =
496
- std::make_unique<llvm::vfs::OverlayFileSystem>(
497
- llvm::vfs::getRealFileSystem ());
498
- OverlayVFS->pushOverlay (IMVFS);
499
- CI->createFileManager (OverlayVFS);
500
-
501
506
return Interpreter::create (std::move (CI), std::move (DCI));
502
507
}
503
508
@@ -536,15 +541,16 @@ size_t Interpreter::getEffectivePTUSize() const {
536
541
537
542
PartialTranslationUnit &
538
543
Interpreter::RegisterPTU (TranslationUnitDecl *TU,
539
- std::unique_ptr<llvm::Module> M /* ={}*/ ) {
544
+ std::unique_ptr<llvm::Module> M /* ={}*/ ,
545
+ IncrementalAction *Action) {
540
546
PTUs.emplace_back (PartialTranslationUnit ());
541
547
PartialTranslationUnit &LastPTU = PTUs.back ();
542
548
LastPTU.TUPart = TU;
543
549
544
550
if (!M)
545
- M = GenModule ();
551
+ M = GenModule (Action );
546
552
547
- assert ((!getCodeGen () || M) && " Must have a llvm::Module at this point" );
553
+ assert ((!getCodeGen (Action ) || M) && " Must have a llvm::Module at this point" );
548
554
549
555
LastPTU.TheModule = std::move (M);
550
556
LLVM_DEBUG (llvm::dbgs () << " compile-ptu " << PTUs.size () - 1
@@ -561,18 +567,14 @@ Interpreter::Parse(llvm::StringRef Code) {
561
567
// If we have a device parser, parse it first. The generated code will be
562
568
// included in the host compilation
563
569
if (DeviceParser) {
564
- llvm::errs () << " [CUDA] Parsing device code...\n " ;
565
570
llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse (Code);
566
571
if (auto E = DeviceTU.takeError ()) {
567
- llvm::errs () << " [CUDA] Device Parse failed!\n " ;
568
572
return std::move (E);
569
573
}
570
- llvm::errs () << " [CUDA] Device parse successful.\n " ;
571
574
572
575
auto *CudaParser = llvm::cast<IncrementalCUDADeviceParser>(DeviceParser.get ());
573
- llvm::errs () << " [CUDA] Registering device PTU...\n " ;
574
576
575
- PartialTranslationUnit &DevicePTU = RegisterPTU (*DeviceTU);
577
+ PartialTranslationUnit &DevicePTU = RegisterPTU (*DeviceTU, nullptr , DeviceAct. get () );
576
578
577
579
llvm::Expected<llvm::StringRef> PTX = CudaParser->GeneratePTX ();
578
580
if (!PTX)
@@ -757,9 +759,9 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
757
759
return llvm::Error::success ();
758
760
}
759
761
760
- std::unique_ptr<llvm::Module> Interpreter::GenModule () {
762
+ std::unique_ptr<llvm::Module> Interpreter::GenModule (IncrementalAction *Action ) {
761
763
static unsigned ID = 0 ;
762
- if (CodeGenerator *CG = getCodeGen ()) {
764
+ if (CodeGenerator *CG = getCodeGen (Action )) {
763
765
// Clang's CodeGen is designed to work with a single llvm::Module. In many
764
766
// cases for convenience various CodeGen parts have a reference to the
765
767
// llvm::Module (TheModule or Module) which does not change when a new
@@ -781,8 +783,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
781
783
return nullptr ;
782
784
}
783
785
784
- CodeGenerator *Interpreter::getCodeGen () const {
785
- FrontendAction *WrappedAct = Act->getWrapped ();
786
+ CodeGenerator *Interpreter::getCodeGen (IncrementalAction *Action) const {
787
+ if (!Action)
788
+ Action = Act.get ();
789
+ FrontendAction *WrappedAct = Action->getWrapped ();
786
790
if (!WrappedAct->hasIRSupport ())
787
791
return nullptr ;
788
792
return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
0 commit comments