LLVM 24.0.0git
OrcRTBootstrap.cpp
Go to the documentation of this file.
1//===------------------------ OrcRTBootstrap.cpp --------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
14
19
20#define DEBUG_TYPE "orc"
21
22using namespace llvm::orc::shared;
23
24namespace llvm {
25namespace orc {
26namespace rt_bootstrap {
27
28template <typename WriteT, typename SPSWriteT>
30writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
31 return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
32 ArgData, ArgSize,
33 [](std::vector<WriteT> Ws) {
34 for (auto &W : Ws)
35 *W.Addr.template toPtr<decltype(W.Value) *>() = W.Value;
36 })
37 .release();
38}
39
41writePointersWrapper(const char *ArgData, size_t ArgSize) {
43 handle(ArgData, ArgSize,
44 [](std::vector<tpctypes::PointerWrite> Ws) {
45 for (auto &W : Ws)
46 *W.Addr.template toPtr<void **>() =
47 W.Value.template toPtr<void *>();
48 })
49 .release();
50}
51
53writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
55 ArgData, ArgSize,
56 [](std::vector<tpctypes::BufferWrite> Ws) {
57 for (auto &W : Ws)
58 memcpy(W.Addr.template toPtr<char *>(), W.Buffer.data(),
59 W.Buffer.size());
60 })
61 .release();
62}
63
64template <typename ReadT>
66readUIntsWrapper(const char *ArgData, size_t ArgSize) {
68 return WrapperFunction<SPSSig>::handle(ArgData, ArgSize,
69 [](std::vector<ExecutorAddr> Rs) {
70 std::vector<ReadT> Result;
71 Result.reserve(Rs.size());
72 for (auto &R : Rs)
73 Result.push_back(
74 *R.toPtr<ReadT *>());
75 return Result;
76 })
77 .release();
78}
79
81readPointersWrapper(const char *ArgData, size_t ArgSize) {
84 ArgData, ArgSize,
85 [](std::vector<ExecutorAddr> Rs) {
86 std::vector<ExecutorAddr> Result;
87 Result.reserve(Rs.size());
88 for (auto &R : Rs)
89 Result.push_back(ExecutorAddr::fromPtr(*R.toPtr<void **>()));
90 return Result;
91 })
92 .release();
93}
94
96readBuffersWrapper(const char *ArgData, size_t ArgSize) {
97 using SPSSig =
100 ArgData, ArgSize,
101 [](std::vector<ExecutorAddrRange> Rs) {
102 std::vector<std::vector<uint8_t>> Result;
103 Result.reserve(Rs.size());
104 for (auto &R : Rs) {
105 Result.push_back({});
106 Result.back().resize(R.size());
107 memcpy(reinterpret_cast<char *>(Result.back().data()),
108 R.Start.toPtr<char *>(), R.size());
109 }
110 return Result;
111 })
112 .release();
113}
114
116readStringsWrapper(const char *ArgData, size_t ArgSize) {
118 return WrapperFunction<SPSSig>::handle(ArgData, ArgSize,
119 [](std::vector<ExecutorAddr> Rs) {
120 std::vector<std::string> Result;
121 Result.reserve(Rs.size());
122 for (auto &R : Rs)
123 Result.push_back(
124 R.toPtr<char *>());
125 return Result;
126 })
127 .release();
128}
129
131runAsMainWrapper(const char *ArgData, size_t ArgSize) {
133 ArgData, ArgSize,
134 [](ExecutorAddr MainAddr,
135 std::vector<std::string> Args) -> int64_t {
136 return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);
137 })
138 .release();
139}
140
142runAsInt32VoidFunctionWrapper(const char *ArgData, size_t ArgSize) {
144 ArgData, ArgSize,
145 [](ExecutorAddr MainAddr) -> int32_t {
146 return runAsVoidFunction(MainAddr.toPtr<int32_t (*)(void)>());
147 })
148 .release();
149}
150
152runAsInt32Int32FunctionWrapper(const char *ArgData, size_t ArgSize) {
154 ArgData, ArgSize,
155 [](ExecutorAddr MainAddr, int32_t Arg) -> int32_t {
156 return runAsIntFunction(MainAddr.toPtr<int32_t (*)(int32_t)>(),
157 Arg);
158 })
159 .release();
160}
161
169
172 M[Mangle.mangledCopy(rt::sps_ci::MemWriteUInt8s::Name)] =
176 M[Mangle.mangledCopy(rt::sps_ci::MemWriteUInt16s::Name)] =
180 M[Mangle.mangledCopy(rt::sps_ci::MemWriteUInt32s::Name)] =
184 M[Mangle.mangledCopy(rt::sps_ci::MemWriteUInt64s::Name)] =
188 M[Mangle.mangledCopy(rt::sps_ci::MemWritePointers::Name)] =
190 M[Mangle.mangledCopy(rt::sps_ci::MemWriteBuffers::Name)] =
192 M[Mangle.mangledCopy(rt::sps_ci::MemReadUInt8s::Name)] =
194 M[Mangle.mangledCopy(rt::sps_ci::MemReadUInt16s::Name)] =
196 M[Mangle.mangledCopy(rt::sps_ci::MemReadUInt32s::Name)] =
198 M[Mangle.mangledCopy(rt::sps_ci::MemReadUInt64s::Name)] =
200 M[Mangle.mangledCopy(rt::sps_ci::MemReadPointers::Name)] =
202 M[Mangle.mangledCopy(rt::sps_ci::MemReadBuffers::Name)] =
204 M[Mangle.mangledCopy(rt::sps_ci::MemReadStrings::Name)] =
206 M[Mangle.mangledCopy(rt::sps_ci::CallMain::Name)] =
209}
210
211} // end namespace rt_bootstrap
212} // end namespace orc
213} // end namespace llvm
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Represents an address in the executor process.
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given type.
Applies linker name-mangling for a target.
Definition Mangler.h:31
static llvm::orc::shared::CWrapperFunctionBuffer writePointersWrapper(const char *ArgData, size_t ArgSize)
LLVM_ABI void addRunAsFunctionWrappersTo(StringMap< ExecutorAddr > &M)
Adds executor-side wrappers for the run-as function proxies.
static llvm::orc::shared::CWrapperFunctionBuffer readPointersWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer readBuffersWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer runAsInt32Int32FunctionWrapper(const char *ArgData, size_t ArgSize)
LLVM_ABI void addTo(StringMap< ExecutorAddr > &M)
Adds all default target-process bootstrap wrappers.
static llvm::orc::shared::CWrapperFunctionBuffer runAsMainWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer runAsInt32VoidFunctionWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer writeUIntsWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer writeBuffersWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer readStringsWrapper(const char *ArgData, size_t ArgSize)
static llvm::orc::shared::CWrapperFunctionBuffer readUIntsWrapper(const char *ArgData, size_t ArgSize)
SPSMemoryAccessUIntWrite< uint8_t > SPSMemoryAccessUInt8Write
SPSMemoryAccessUIntWrite< uint16_t > SPSMemoryAccessUInt16Write
SPSMemoryAccessUIntWrite< uint64_t > SPSMemoryAccessUInt64Write
SPSMemoryAccessUIntWrite< uint32_t > SPSMemoryAccessUInt32Write
UIntWrite< uint64_t > UInt64Write
Describes a write to a uint64_t.
UIntWrite< uint8_t > UInt8Write
Describes a write to a uint8_t.
UIntWrite< uint32_t > UInt32Write
Describes a write to a uint32_t.
UIntWrite< uint16_t > UInt16Write
Describes a write to a uint16_t.
LLVM_ABI int runAsVoidFunction(int(*Func)(void))
LLVM_ABI int runAsIntFunction(int(*Func)(int), int Arg)
LLVM_ABI int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, std::optional< StringRef > ProgramName=std::nullopt)
Run a main function, returning the result.
LLVM_ABI std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
Definition Host.cpp:2653
This is an optimization pass for GlobalISel generic memory operations.
static constexpr SymbolNameSpec Name
Definition CallSPSCI.h:58
static constexpr SymbolNameSpec Name
Definition CallSPSCI.h:50
static constexpr SymbolNameSpec Name
Definition CallSPSCI.h:33
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name