@@ -481,20 +481,34 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
481
481
OverlayVFS->pushOverlay (IMVFS);
482
482
CI->createFileManager (OverlayVFS);
483
483
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);
487
490
488
491
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
+
492
497
if (Err)
493
498
return std::move (Err);
494
499
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);
496
509
497
- return Interp;
510
+ Interp->DeviceParser = std::move (DeviceParser);
511
+ return std::move (Interp);
498
512
}
499
513
500
514
const CompilerInstance *Interpreter::getCompilerInstance () const {
@@ -532,15 +546,17 @@ size_t Interpreter::getEffectivePTUSize() const {
532
546
533
547
PartialTranslationUnit &
534
548
Interpreter::RegisterPTU (TranslationUnitDecl *TU,
535
- std::unique_ptr<llvm::Module> M /* ={}*/ ) {
549
+ std::unique_ptr<llvm::Module> M /* ={}*/ ,
550
+ IncrementalAction *Action) {
536
551
PTUs.emplace_back (PartialTranslationUnit ());
537
552
PartialTranslationUnit &LastPTU = PTUs.back ();
538
553
LastPTU.TUPart = TU;
539
554
540
555
if (!M)
541
- M = GenModule ();
556
+ M = GenModule (Action );
542
557
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" );
544
560
545
561
LastPTU.TheModule = std::move (M);
546
562
LLVM_DEBUG (llvm::dbgs () << " compile-ptu " << PTUs.size () - 1
@@ -558,8 +574,22 @@ Interpreter::Parse(llvm::StringRef Code) {
558
574
// included in the host compilation
559
575
if (DeviceParser) {
560
576
llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse (Code);
561
- if (auto E = DeviceTU.takeError ())
577
+ if (auto E = DeviceTU.takeError ()) {
562
578
return std::move (E);
579
+ }
580
+
581
+ auto *CudaParser =
582
+ llvm::cast<IncrementalCUDADeviceParser>(DeviceParser.get ());
583
+
584
+ RegisterPTU (*DeviceTU, nullptr , DeviceAct.get ());
585
+
586
+ llvm::Expected<llvm::StringRef> PTX = CudaParser->GeneratePTX ();
587
+ if (!PTX)
588
+ return PTX.takeError ();
589
+
590
+ llvm::Error Err = CudaParser->GenerateFatbinary ();
591
+ if (Err)
592
+ return std::move (Err);
563
593
}
564
594
565
595
// Tell the interpreter sliently ignore unused expressions since value
@@ -736,9 +766,10 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
736
766
return llvm::Error::success ();
737
767
}
738
768
739
- std::unique_ptr<llvm::Module> Interpreter::GenModule () {
769
+ std::unique_ptr<llvm::Module>
770
+ Interpreter::GenModule (IncrementalAction *Action) {
740
771
static unsigned ID = 0 ;
741
- if (CodeGenerator *CG = getCodeGen ()) {
772
+ if (CodeGenerator *CG = getCodeGen (Action )) {
742
773
// Clang's CodeGen is designed to work with a single llvm::Module. In many
743
774
// cases for convenience various CodeGen parts have a reference to the
744
775
// llvm::Module (TheModule or Module) which does not change when a new
@@ -760,8 +791,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
760
791
return nullptr ;
761
792
}
762
793
763
- CodeGenerator *Interpreter::getCodeGen () const {
764
- FrontendAction *WrappedAct = Act->getWrapped ();
794
+ CodeGenerator *Interpreter::getCodeGen (IncrementalAction *Action) const {
795
+ if (!Action)
796
+ Action = Act.get ();
797
+ FrontendAction *WrappedAct = Action->getWrapped ();
765
798
if (!WrappedAct->hasIRSupport ())
766
799
return nullptr ;
767
800
return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
0 commit comments