Skip to content

Commit 31b0126

Browse files
committed
Tell the jit about -include files
1 parent d2096a6 commit 31b0126

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Interpreter {
175175

176176
CodeGenerator *getCodeGen() const;
177177
std::unique_ptr<llvm::Module> GenModule();
178+
PartialTranslationUnit &RegisterPTU(TranslationUnitDecl *TU);
178179

179180
// A cache for the compiled destructors used to for de-allocation of managed
180181
// clang::Values.

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -393,33 +393,29 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
393393
return;
394394
CI->ExecuteAction(*Act);
395395

396-
if (getCodeGen())
397-
CachedInCodeGenModule = GenModule();
396+
ASTContext &C = CI->getASTContext();
398397

399398
IncrParser = std::make_unique<IncrementalParser>(std::move(CI), ErrOut);
400399

401-
// An initial PTU is needed as CUDA includes some headers automatically.
402-
auto PTU = Parse("");
403-
if (auto E = PTU.takeError()) {
404-
ErrOut = joinErrors(std::move(ErrOut), std::move(E));
405-
return;
406-
}
407-
408-
if (getCodeGen()) {
409-
PTU->TheModule = GenModule();
410-
assert(PTU->TheModule && "Failed to create initial PTU");
411-
}
412-
413400
if (ErrOut)
414401
return;
415402

416-
// Not all frontends support code-generation, e.g. ast-dump actions don't
417403
if (getCodeGen()) {
404+
CachedInCodeGenModule = GenModule();
418405
if (llvm::Error Err = CreateExecutor()) {
419406
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
420407
return;
421408
}
409+
}
410+
411+
// The initial PTU is filled by `-include` or by CUDA includes automatically.
412+
RegisterPTU(C.getTranslationUnitDecl());
413+
414+
// Prepare the IncrParser for input.
415+
llvm::cantFail(Parse(""));
422416

417+
// Not all frontends support code-generation, e.g. ast-dump actions don't
418+
if (getCodeGen()) {
423419
// Process the PTUs that came from initialization. For example -include will
424420
// give us a header that's processed at initialization of the preprocessor.
425421
for (PartialTranslationUnit &PTU : PTUs)
@@ -549,6 +545,17 @@ size_t Interpreter::getEffectivePTUSize() const {
549545
return PTUs.size() - InitPTUSize;
550546
}
551547

548+
PartialTranslationUnit &Interpreter::RegisterPTU(TranslationUnitDecl *TU) {
549+
PTUs.emplace_back(PartialTranslationUnit());
550+
PartialTranslationUnit &LastPTU = PTUs.back();
551+
LastPTU.TUPart = TU;
552+
553+
if (std::unique_ptr<llvm::Module> M = GenModule())
554+
LastPTU.TheModule = std::move(M);
555+
556+
return LastPTU;
557+
}
558+
552559
llvm::Expected<PartialTranslationUnit &>
553560
Interpreter::Parse(llvm::StringRef Code) {
554561
// If we have a device parser, parse it first. The generated code will be
@@ -568,14 +575,7 @@ Interpreter::Parse(llvm::StringRef Code) {
568575
if (!TuOrErr)
569576
return TuOrErr.takeError();
570577

571-
PTUs.emplace_back(PartialTranslationUnit());
572-
PartialTranslationUnit &LastPTU = PTUs.back();
573-
LastPTU.TUPart = *TuOrErr;
574-
575-
if (std::unique_ptr<llvm::Module> M = GenModule())
576-
LastPTU.TheModule = std::move(M);
577-
578-
return LastPTU;
578+
return RegisterPTU(*TuOrErr);
579579
}
580580

581581
static llvm::Expected<llvm::orc::JITTargetMachineBuilder>

0 commit comments

Comments
 (0)