File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed
include/clang/Interpreter Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,6 @@ class Interpreter {
96
96
// An optional parser for CUDA offloading
97
97
std::unique_ptr<IncrementalParser> DeviceParser;
98
98
99
- llvm::Error CreateExecutor ();
100
99
unsigned InitPTUSize = 0 ;
101
100
102
101
// This member holds the last result of the value printing. It's a class
@@ -114,6 +113,14 @@ class Interpreter {
114
113
// That's useful for testing and out-of-tree clients.
115
114
Interpreter (std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
116
115
116
+ // Create the internal IncrementalExecutor, or re-create it after calling
117
+ // ResetExecutor().
118
+ llvm::Error CreateExecutor ();
119
+
120
+ // Delete the internal IncrementalExecutor. This causes a hard shutdown of the
121
+ // JIT engine. In particular, it doesn't run cleanup or destructors.
122
+ void ResetExecutor ();
123
+
117
124
// Lazily construct the RuntimeInterfaceBuilder. The provided instance will be
118
125
// used for the entire lifetime of the interpreter. The default implementation
119
126
// targets the in-process __clang_Interpreter runtime. Override this to use a
Original file line number Diff line number Diff line change @@ -375,6 +375,10 @@ Interpreter::Parse(llvm::StringRef Code) {
375
375
llvm::Error Interpreter::CreateExecutor () {
376
376
const clang::TargetInfo &TI =
377
377
getCompilerInstance ()->getASTContext ().getTargetInfo ();
378
+ if (IncrExecutor)
379
+ return llvm::make_error<llvm::StringError>(" Operation failed. "
380
+ " Execution engine exists" ,
381
+ std::error_code ());
378
382
llvm::Error Err = llvm::Error::success ();
379
383
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, TI);
380
384
if (!Err)
@@ -383,6 +387,8 @@ llvm::Error Interpreter::CreateExecutor() {
383
387
return Err;
384
388
}
385
389
390
+ void Interpreter::ResetExecutor () { IncrExecutor.reset (); }
391
+
386
392
llvm::Error Interpreter::Execute (PartialTranslationUnit &T) {
387
393
assert (T.TheModule );
388
394
if (!IncrExecutor) {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
4
4
OrcJIT
5
5
Support
6
6
TargetParser
7
+ TestingSupport
7
8
)
8
9
9
10
add_clang_unittest(ClangReplInterpreterTests
Original file line number Diff line number Diff line change 27
27
using namespace clang ;
28
28
namespace {
29
29
30
+ class TestCreateResetExecutor : public Interpreter {
31
+ public:
32
+ TestCreateResetExecutor (std::unique_ptr<CompilerInstance> CI,
33
+ llvm::Error &Err)
34
+ : Interpreter(std::move(CI), Err) {}
35
+
36
+ llvm::Error testCreateExecutor () { return Interpreter::CreateExecutor (); }
37
+
38
+ void resetExecutor () { Interpreter::ResetExecutor (); }
39
+ };
40
+
41
+ TEST (InterpreterExtensionsTest, ExecutorCreateReset) {
42
+ clang::IncrementalCompilerBuilder CB;
43
+ llvm::Error ErrOut = llvm::Error::success ();
44
+ TestCreateResetExecutor Interp (cantFail (CB.CreateCpp ()), ErrOut);
45
+ cantFail (std::move (ErrOut));
46
+ cantFail (Interp.testCreateExecutor ());
47
+ Interp.resetExecutor ();
48
+ cantFail (Interp.testCreateExecutor ());
49
+ EXPECT_THAT_ERROR (Interp.testCreateExecutor (),
50
+ llvm::FailedWithMessage (" Operation failed. "
51
+ " Execution engine exists" ));
52
+ }
53
+
30
54
class RecordRuntimeIBMetrics : public Interpreter {
31
55
struct NoopRuntimeInterfaceBuilder : public RuntimeInterfaceBuilder {
32
56
NoopRuntimeInterfaceBuilder (Sema &S) : S(S) {}
You can’t perform that action at this time.
0 commit comments