Skip to content

Commit 8b1771b

Browse files
committed
[ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.
ExecutorAddr was introduced in b8e5f91 as an eventual replacement for JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr, JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress, JITSymbolFlags) pair. A number of APIs had already migrated from JITTargetAddress to ExecutorAddr, but many of ORC's internals were still using the older type. This patch aims to address that. Some public APIs are affected as well. If you need to migrate your APIs you can use the following operations: * ExecutorAddr::toPtr replaces jitTargetAddressToPointer and jitTargetAddressToFunction. * ExecutorAddr::fromPtr replace pointerToJITTargetAddress. * ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a JITTargetAddress. * ExecutorAddr::getValue() creates a JITTargetAddress value from an ExecutorAddr. JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but the aim will be to eventually deprecate and remove these types (probably when MCJIT and RuntimeDyld are deprecated).
1 parent 41a964c commit 8b1771b

File tree

61 files changed

+552
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+552
-589
lines changed

llvm/docs/ORCv2.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ specified before the JIT instance is constructed. For example:
147147
auto JIT = LLLazyJITBuilder()
148148
.setNumCompileThreads(4)
149149
.setLazyCompileFailureAddr(
150-
toJITTargetAddress(&handleLazyCompileFailure))
150+
ExecutorAddr::fromPtr(&handleLazyCompileFailure))
151151
.create();
152152

153153
// ...
@@ -315,7 +315,7 @@ absolute symbols is allowing resolution of process symbols. E.g.
315315
316316
JD.define(absoluteSymbols(SymbolMap({
317317
{ Mangle("printf"),
318-
{ pointerToJITTargetAddress(&printf),
318+
{ ExecutorAddr::fromPtr(&printf),
319319
JITSymbolFlags::Callable } }
320320
});
321321
@@ -364,7 +364,7 @@ absolute symbol definition when the JIT is started:
364364
365365
JITStdLibJD.define(absoluteSymbols(SymbolMap({
366366
{ Mangle("__MyJITInstance"),
367-
{ pointerToJITTargetAddress(&J), JITSymbolFlags() } }
367+
{ ExecutorAddr::fromPtr(&J), JITSymbolFlags() } }
368368
});
369369
370370
Aliases and Reexports
@@ -819,8 +819,8 @@ absoluteSymbols function:
819819

820820
JD.define(
821821
absoluteSymbols({
822-
{ Mangle("puts"), pointerToJITTargetAddress(&puts)},
823-
{ Mangle("gets"), pointerToJITTargetAddress(&getS)}
822+
{ Mangle("puts"), ExecutorAddr::fromPtr(&puts)},
823+
{ Mangle("gets"), ExecutorAddr::fromPtr(&getS)}
824824
}));
825825

826826
Using absoluteSymbols is reasonable if the set of symbols to be reflected is

llvm/docs/tutorial/BuildingAJIT1.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ just two functions:
6767

6868
1. ``Error addModule(std::unique_ptr<Module> M)``: Make the given IR module
6969
available for execution.
70-
2. ``Expected<JITEvaluatedSymbol> lookup()``: Search for pointers to
70+
2. ``Expected<ExecutorSymbolDef> lookup()``: Search for pointers to
7171
symbols (functions or variables) that have been added to the JIT.
7272

7373
A basic use-case for this API, executing the 'main' function from a module,
@@ -110,7 +110,6 @@ usual include guards and #includes [2]_, we get to the definition of our class:
110110
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
111111

112112
#include "llvm/ADT/StringRef.h"
113-
#include "llvm/ExecutionEngine/JITSymbol.h"
114113
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
115114
#include "llvm/ExecutionEngine/Orc/Core.h"
116115
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -224,7 +223,7 @@ will build our IR modules.
224223
ThreadSafeModule(std::move(M), Ctx)));
225224
}
226225

227-
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
226+
Expected<ExecutorSymbolDef> lookup(StringRef Name) {
228227
return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str()));
229228
}
230229

@@ -295,9 +294,6 @@ Here is the code:
295294
.. [2] +-----------------------------+-----------------------------------------------+
296295
| File | Reason for inclusion |
297296
+=============================+===============================================+
298-
| JITSymbol.h | Defines the lookup result type |
299-
| | JITEvaluatedSymbol |
300-
+-----------------------------+-----------------------------------------------+
301297
| CompileUtils.h | Provides the SimpleCompiler class. |
302298
+-----------------------------+-----------------------------------------------+
303299
| Core.h | Core utilities such as ExecutionSession and |

llvm/docs/tutorial/BuildingAJIT3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ to create the compile callback needed for each function.
119119
120120
Next we have to update our constructor to initialize the new members. To create
121121
an appropriate compile callback manager we use the
122-
createLocalCompileCallbackManager function, which takes a TargetMachine and a
123-
JITTargetAddress to call if it receives a request to compile an unknown
122+
createLocalCompileCallbackManager function, which takes a TargetMachine and an
123+
ExecutorAddr to call if it receives a request to compile an unknown
124124
function. In our simple JIT this situation is unlikely to come up, so we'll
125125
cheat and just pass '0' here. In a production quality JIT you could give the
126126
address of a function that throws an exception in order to unwind the JIT'd

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
1515

1616
#include "llvm/ADT/StringRef.h"
17-
#include "llvm/ExecutionEngine/JITSymbol.h"
1817
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
1918
#include "llvm/ExecutionEngine/Orc/Core.h"
2019
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -89,7 +88,7 @@ class KaleidoscopeJIT {
8988
return CompileLayer.add(RT, std::move(TSM));
9089
}
9190

92-
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
91+
Expected<ExecutorSymbolDef> lookup(StringRef Name) {
9392
return ES->lookup({&MainJD}, Mangle(Name.str()));
9493
}
9594
};

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ static void HandleTopLevelExpression() {
11591159

11601160
// Get the symbol's address and cast it to the right type (takes no
11611161
// arguments, returns a double) so we can call it as a native function.
1162-
auto *FP = (double (*)())(intptr_t)Sym.getAddress();
1162+
auto *FP = Sym.getAddress().toPtr<double (*)()>();
11631163
fprintf(stderr, "Evaluated to %f\n", FP());
11641164

11651165
// Delete the anonymous expression module from the JIT.

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
1515

1616
#include "llvm/ADT/StringRef.h"
17-
#include "llvm/ExecutionEngine/JITSymbol.h"
1817
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
1918
#include "llvm/ExecutionEngine/Orc/Core.h"
2019
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -97,7 +96,7 @@ class KaleidoscopeJIT {
9796
return OptimizeLayer.add(RT, std::move(TSM));
9897
}
9998

100-
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
99+
Expected<ExecutorSymbolDef> lookup(StringRef Name) {
101100
return ES->lookup({&MainJD}, Mangle(Name.str()));
102101
}
103102

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ static void HandleTopLevelExpression() {
11591159

11601160
// Get the symbol's address and cast it to the right type (takes no
11611161
// arguments, returns a double) so we can call it as a native function.
1162-
auto *FP = (double (*)())(intptr_t)Sym.getAddress();
1162+
auto *FP = Sym.getAddress().toPtr<double (*)()>();
11631163
fprintf(stderr, "Evaluated to %f\n", FP());
11641164

11651165
// Delete the anonymous expression module from the JIT.

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
1515

1616
#include "llvm/ADT/StringRef.h"
17-
#include "llvm/ExecutionEngine/JITSymbol.h"
1817
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
1918
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
2019
#include "llvm/ExecutionEngine/Orc/Core.h"
@@ -96,7 +95,7 @@ class KaleidoscopeJIT {
9695
return EPCIU.takeError();
9796

9897
(*EPCIU)->createLazyCallThroughManager(
99-
*ES, pointerToJITTargetAddress(&handleLazyCallThroughError));
98+
*ES, ExecutorAddr::fromPtr(&handleLazyCallThroughError));
10099

101100
if (auto Err = setUpInProcessLCTMReentryViaEPCIU(**EPCIU))
102101
return std::move(Err);
@@ -123,7 +122,7 @@ class KaleidoscopeJIT {
123122
return CODLayer.add(RT, std::move(TSM));
124123
}
125124

126-
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
125+
Expected<ExecutorSymbolDef> lookup(StringRef Name) {
127126
return ES->lookup({&MainJD}, Mangle(Name.str()));
128127
}
129128

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ static void HandleTopLevelExpression() {
11591159

11601160
// Get the symbol's address and cast it to the right type (takes no
11611161
// arguments, returns a double) so we can call it as a native function.
1162-
auto *FP = (double (*)())(intptr_t)Sym.getAddress();
1162+
auto *FP = Sym.getAddress().toPtr<double (*)()>();
11631163
fprintf(stderr, "Evaluated to %f\n", FP());
11641164

11651165
// Delete the anonymous expression module from the JIT.

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
1515

1616
#include "llvm/ADT/StringRef.h"
17-
#include "llvm/ExecutionEngine/JITSymbol.h"
1817
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
1918
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
2019
#include "llvm/ExecutionEngine/Orc/Core.h"
@@ -181,7 +180,7 @@ class KaleidoscopeJIT {
181180
return EPCIU.takeError();
182181

183182
(*EPCIU)->createLazyCallThroughManager(
184-
*ES, pointerToJITTargetAddress(&handleLazyCallThroughError));
183+
*ES, ExecutorAddr::fromPtr(&handleLazyCallThroughError));
185184

186185
if (auto Err = setUpInProcessLCTMReentryViaEPCIU(**EPCIU))
187186
return std::move(Err);
@@ -214,7 +213,7 @@ class KaleidoscopeJIT {
214213
return ASTLayer.add(RT, std::move(F));
215214
}
216215

217-
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
216+
Expected<ExecutorSymbolDef> lookup(StringRef Name) {
218217
return ES->lookup({&MainJD}, Mangle(Name.str()));
219218
}
220219

0 commit comments

Comments
 (0)