Files
clang-p2996/llvm/tools/lli/ExecutionUtils.h
Lang Hames 8b1771bd9f [ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.
ExecutorAddr was introduced in b8e5f91816 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).
2023-03-27 17:37:58 -07:00

61 lines
1.9 KiB
C++

//===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Contains utilities for executing code in lli.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
#define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/Core.h"
#include "llvm/ExecutionEngine/Orc/Mangling.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ToolOutputFile.h"
#include <memory>
#include <utility>
namespace llvm {
enum class BuiltinFunctionKind {
DumpDebugDescriptor,
DumpDebugObjects,
};
// Utility class to expose symbols for special-purpose functions to the JIT.
class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
public:
LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
orc::MangleAndInterner &Mangle);
Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
const orc::SymbolLookupSet &Symbols) override;
void appendDebugObject(const char *Addr, size_t Size) {
TestOut->os().write(Addr, Size);
}
private:
orc::SymbolMap BuiltinFunctions;
std::unique_ptr<ToolOutputFile> TestOut;
template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler),
JITSymbolFlags::Exported};
}
static std::unique_ptr<ToolOutputFile> createToolOutput();
};
} // end namespace llvm
#endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H