Commit 8b1771bd authored by Lang Hames's avatar Lang Hames
Browse files

[ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.

ExecutorAddr was introduced in b8e5f918 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).
parent 41a964cf
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ specified before the JIT instance is constructed. For example:
  auto JIT = LLLazyJITBuilder()
               .setNumCompileThreads(4)
               .setLazyCompileFailureAddr(
                   toJITTargetAddress(&handleLazyCompileFailure))
                   ExecutorAddr::fromPtr(&handleLazyCompileFailure))
               .create();

  // ...
@@ -315,7 +315,7 @@ absolute symbols is allowing resolution of process symbols. E.g.

  JD.define(absoluteSymbols(SymbolMap({
      { Mangle("printf"),
        { pointerToJITTargetAddress(&printf),
        { ExecutorAddr::fromPtr(&printf),
          JITSymbolFlags::Callable } }
    });

@@ -364,7 +364,7 @@ absolute symbol definition when the JIT is started:

  JITStdLibJD.define(absoluteSymbols(SymbolMap({
      { Mangle("__MyJITInstance"),
        { pointerToJITTargetAddress(&J), JITSymbolFlags() } }
        { ExecutorAddr::fromPtr(&J), JITSymbolFlags() } }
    });

Aliases and Reexports
@@ -819,8 +819,8 @@ absoluteSymbols function:

    JD.define(
      absoluteSymbols({
        { Mangle("puts"), pointerToJITTargetAddress(&puts)},
        { Mangle("gets"), pointerToJITTargetAddress(&getS)}
        { Mangle("puts"), ExecutorAddr::fromPtr(&puts)},
        { Mangle("gets"), ExecutorAddr::fromPtr(&getS)}
      }));

Using absoluteSymbols is reasonable if the set of symbols to be reflected is
+2 −6
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ just two functions:

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

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:
  #define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H

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

  Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
  Expected<ExecutorSymbolDef> lookup(StringRef Name) {
    return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str()));
  }

@@ -295,9 +294,6 @@ Here is the code:
.. [2] +-----------------------------+-----------------------------------------------+
       |         File                |               Reason for inclusion            |
       +=============================+===============================================+
       |        JITSymbol.h          | Defines the lookup result type                |
       |                             | JITEvaluatedSymbol                            |
       +-----------------------------+-----------------------------------------------+
       |       CompileUtils.h        | Provides the SimpleCompiler class.            |
       +-----------------------------+-----------------------------------------------+
       |           Core.h            | Core utilities such as ExecutionSession and   |
+2 −2
Original line number Diff line number Diff line
@@ -119,8 +119,8 @@ to create the compile callback needed for each function.

Next we have to update our constructor to initialize the new members. To create
an appropriate compile callback manager we use the
createLocalCompileCallbackManager function, which takes a TargetMachine and a
JITTargetAddress to call if it receives a request to compile an unknown
createLocalCompileCallbackManager function, which takes a TargetMachine and an
ExecutorAddr to call if it receives a request to compile an unknown
function.  In our simple JIT this situation is unlikely to come up, so we'll
cheat and just pass '0' here. In a production quality JIT you could give the
address of a function that throws an exception in order to unwind the JIT'd
+1 −2
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H

#include "llvm/ADT/StringRef.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
@@ -89,7 +88,7 @@ public:
    return CompileLayer.add(RT, std::move(TSM));
  }

  Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
  Expected<ExecutorSymbolDef> lookup(StringRef Name) {
    return ES->lookup({&MainJD}, Mangle(Name.str()));
  }
};
+1 −1
Original line number Diff line number Diff line
@@ -1159,7 +1159,7 @@ static void HandleTopLevelExpression() {

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

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