@@ -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
@@ -560,6 +576,16 @@ Interpreter::Parse(llvm::StringRef Code) {
560
576
llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse (Code);
561
577
if (auto E = DeviceTU.takeError ())
562
578
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);
563
589
}
564
590
565
591
// Tell the interpreter sliently ignore unused expressions since value
@@ -736,9 +762,10 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
736
762
return llvm::Error::success ();
737
763
}
738
764
739
- std::unique_ptr<llvm::Module> Interpreter::GenModule () {
765
+ std::unique_ptr<llvm::Module>
766
+ Interpreter::GenModule (IncrementalAction *Action) {
740
767
static unsigned ID = 0 ;
741
- if (CodeGenerator *CG = getCodeGen ()) {
768
+ if (CodeGenerator *CG = getCodeGen (Action )) {
742
769
// Clang's CodeGen is designed to work with a single llvm::Module. In many
743
770
// cases for convenience various CodeGen parts have a reference to the
744
771
// llvm::Module (TheModule or Module) which does not change when a new
@@ -760,8 +787,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
760
787
return nullptr ;
761
788
}
762
789
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 ();
765
794
if (!WrappedAct->hasIRSupport ())
766
795
return nullptr ;
767
796
return static_cast <CodeGenAction *>(WrappedAct)->getCodeGenerator ();
0 commit comments