Skip to content

Commit 0faa181

Browse files
authored
[ORC] Extract MemoryAccess from ExecutorProcessControl, break up header. (#145671)
This moves the MemoryAccess interface out of the ExecutorProcessControl class and splits implementation classes InProcessMemoryManager and SelfExecutorProcessControl out of ExecutorProcessControl.h and into their own headers.
1 parent b413bea commit 0faa181

25 files changed

+486
-372
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
2222
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2323
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
24+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
2425
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2526
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2627
#include "llvm/IR/DataLayout.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
2323
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2424
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
25+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
2526
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2627
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2728
#include "llvm/IR/DataLayout.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
2626
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2727
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
28+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
2829
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2930
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
3031
#include "llvm/IR/DataLayout.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
2525
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2626
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
27+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
2728
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2829
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2930
#include "llvm/IR/DataLayout.h"

llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
2323
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
2424
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
25+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
2526
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
2627
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2728
#include "llvm/IR/DataLayout.h"

llvm/examples/OrcV2Examples/LLJITWithExecutorProcessControl/LLJITWithExecutorProcessControl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
2828
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
2929
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
30+
#include "llvm/ExecutionEngine/Orc/SelfExecutorProcessControl.h"
3031
#include "llvm/Support/InitLLVM.h"
3132
#include "llvm/Support/TargetSelect.h"
3233
#include "llvm/Support/raw_ostream.h"

llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace llvm {
2424
namespace orc {
2525

26-
class EPCGenericMemoryAccess : public ExecutorProcessControl::MemoryAccess {
26+
class EPCGenericMemoryAccess : public MemoryAccess {
2727
public:
2828
/// Function addresses for memory access.
2929
struct FuncAddrs {

llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h

Lines changed: 3 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
1818
#include "llvm/ExecutionEngine/Orc/DylibManager.h"
19+
#include "llvm/ExecutionEngine/Orc/MemoryAccess.h"
1920
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
2021
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
2122
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
2223
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
2324
#include "llvm/ExecutionEngine/Orc/TargetProcess/UnwindInfoManager.h"
2425
#include "llvm/ExecutionEngine/Orc/TaskDispatch.h"
2526
#include "llvm/Support/Compiler.h"
26-
#include "llvm/Support/MSVCErrorWorkarounds.h"
2727
#include "llvm/TargetParser/Triple.h"
2828

2929
#include <future>
3030
#include <mutex>
3131
#include <vector>
3232

33-
namespace llvm {
34-
namespace orc {
33+
namespace llvm::orc {
3534

3635
class ExecutionSession;
3736

@@ -98,81 +97,6 @@ class LLVM_ABI ExecutorProcessControl {
9897
TaskDispatcher &D;
9998
};
10099

101-
/// APIs for manipulating memory in the target process.
102-
class LLVM_ABI MemoryAccess {
103-
public:
104-
/// Callback function for asynchronous writes.
105-
using WriteResultFn = unique_function<void(Error)>;
106-
107-
virtual ~MemoryAccess();
108-
109-
virtual void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
110-
WriteResultFn OnWriteComplete) = 0;
111-
112-
virtual void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
113-
WriteResultFn OnWriteComplete) = 0;
114-
115-
virtual void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
116-
WriteResultFn OnWriteComplete) = 0;
117-
118-
virtual void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
119-
WriteResultFn OnWriteComplete) = 0;
120-
121-
virtual void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
122-
WriteResultFn OnWriteComplete) = 0;
123-
124-
virtual void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
125-
WriteResultFn OnWriteComplete) = 0;
126-
127-
Error writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws) {
128-
std::promise<MSVCPError> ResultP;
129-
auto ResultF = ResultP.get_future();
130-
writeUInt8sAsync(Ws,
131-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
132-
return ResultF.get();
133-
}
134-
135-
Error writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws) {
136-
std::promise<MSVCPError> ResultP;
137-
auto ResultF = ResultP.get_future();
138-
writeUInt16sAsync(Ws,
139-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
140-
return ResultF.get();
141-
}
142-
143-
Error writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws) {
144-
std::promise<MSVCPError> ResultP;
145-
auto ResultF = ResultP.get_future();
146-
writeUInt32sAsync(Ws,
147-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
148-
return ResultF.get();
149-
}
150-
151-
Error writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws) {
152-
std::promise<MSVCPError> ResultP;
153-
auto ResultF = ResultP.get_future();
154-
writeUInt64sAsync(Ws,
155-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
156-
return ResultF.get();
157-
}
158-
159-
Error writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws) {
160-
std::promise<MSVCPError> ResultP;
161-
auto ResultF = ResultP.get_future();
162-
writeBuffersAsync(Ws,
163-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
164-
return ResultF.get();
165-
}
166-
167-
Error writePointers(ArrayRef<tpctypes::PointerWrite> Ws) {
168-
std::promise<MSVCPError> ResultP;
169-
auto ResultF = ResultP.get_future();
170-
writePointersAsync(Ws,
171-
[&](Error Err) { ResultP.set_value(std::move(Err)); });
172-
return ResultF.get();
173-
}
174-
};
175-
176100
/// Contains the address of the dispatch function and context that the ORC
177101
/// runtime can use to call functions in the JIT.
178102
struct JITDispatchInfo {
@@ -398,83 +322,6 @@ class LLVM_ABI ExecutorProcessControl {
398322
StringMap<ExecutorAddr> BootstrapSymbols;
399323
};
400324

401-
class LLVM_ABI InProcessMemoryAccess
402-
: public ExecutorProcessControl::MemoryAccess {
403-
public:
404-
InProcessMemoryAccess(bool IsArch64Bit) : IsArch64Bit(IsArch64Bit) {}
405-
void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
406-
WriteResultFn OnWriteComplete) override;
407-
408-
void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
409-
WriteResultFn OnWriteComplete) override;
410-
411-
void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
412-
WriteResultFn OnWriteComplete) override;
413-
414-
void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
415-
WriteResultFn OnWriteComplete) override;
416-
417-
void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
418-
WriteResultFn OnWriteComplete) override;
419-
420-
void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
421-
WriteResultFn OnWriteComplete) override;
422-
423-
private:
424-
bool IsArch64Bit;
425-
};
426-
427-
/// A ExecutorProcessControl implementation targeting the current process.
428-
class LLVM_ABI SelfExecutorProcessControl : public ExecutorProcessControl,
429-
private InProcessMemoryAccess,
430-
private DylibManager {
431-
public:
432-
SelfExecutorProcessControl(
433-
std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D,
434-
Triple TargetTriple, unsigned PageSize,
435-
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
436-
437-
/// Create a SelfExecutorProcessControl with the given symbol string pool and
438-
/// memory manager.
439-
/// If no symbol string pool is given then one will be created.
440-
/// If no memory manager is given a jitlink::InProcessMemoryManager will
441-
/// be created and used by default.
442-
static Expected<std::unique_ptr<SelfExecutorProcessControl>>
443-
Create(std::shared_ptr<SymbolStringPool> SSP = nullptr,
444-
std::unique_ptr<TaskDispatcher> D = nullptr,
445-
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr);
446-
447-
Expected<int32_t> runAsMain(ExecutorAddr MainFnAddr,
448-
ArrayRef<std::string> Args) override;
449-
450-
Expected<int32_t> runAsVoidFunction(ExecutorAddr VoidFnAddr) override;
451-
452-
Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
453-
454-
void callWrapperAsync(ExecutorAddr WrapperFnAddr,
455-
IncomingWFRHandler OnComplete,
456-
ArrayRef<char> ArgBuffer) override;
457-
458-
Error disconnect() override;
459-
460-
private:
461-
static shared::CWrapperFunctionResult
462-
jitDispatchViaWrapperFunctionManager(void *Ctx, const void *FnTag,
463-
const char *Data, size_t Size);
464-
465-
Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
466-
467-
void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
468-
SymbolLookupCompleteFn F) override;
469-
470-
std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
471-
#ifdef __APPLE__
472-
std::unique_ptr<UnwindInfoManager> UnwindInfoMgr;
473-
#endif // __APPLE__
474-
char GlobalManglingPrefix = 0;
475-
};
476-
477-
} // end namespace orc
478-
} // end namespace llvm
325+
} // namespace llvm::orc
479326

480327
#endif // LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===-- InProcessMemoryAccess.h - Direct, in-process mem access -*- C++ -*-===//
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+
//
9+
// Accesses memory in the current process.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
14+
#define LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
15+
16+
#include "llvm/ExecutionEngine/Orc/MemoryAccess.h"
17+
18+
namespace llvm::orc {
19+
20+
class LLVM_ABI InProcessMemoryAccess : public MemoryAccess {
21+
public:
22+
InProcessMemoryAccess(bool IsArch64Bit) : IsArch64Bit(IsArch64Bit) {}
23+
void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
24+
WriteResultFn OnWriteComplete) override;
25+
26+
void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
27+
WriteResultFn OnWriteComplete) override;
28+
29+
void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
30+
WriteResultFn OnWriteComplete) override;
31+
32+
void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
33+
WriteResultFn OnWriteComplete) override;
34+
35+
void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
36+
WriteResultFn OnWriteComplete) override;
37+
38+
void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
39+
WriteResultFn OnWriteComplete) override;
40+
41+
private:
42+
bool IsArch64Bit;
43+
};
44+
45+
} // namespace llvm::orc
46+
47+
#endif // LLVM_EXECUTIONENGINE_ORC_INPROCESSMEMORYACCESS_H
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//===------- MemoryAccess.h - Executor memory access APIs -------*- C++ -*-===//
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+
//
9+
// Utilities for accessing memory in the executor processes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H
14+
#define LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H
15+
16+
#include "llvm/ADT/ArrayRef.h"
17+
#include "llvm/ADT/FunctionExtras.h"
18+
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
19+
#include "llvm/Support/MSVCErrorWorkarounds.h"
20+
21+
#include <future>
22+
23+
namespace llvm::orc {
24+
25+
/// APIs for manipulating memory in the target process.
26+
class LLVM_ABI MemoryAccess {
27+
public:
28+
/// Callback function for asynchronous writes.
29+
using WriteResultFn = unique_function<void(Error)>;
30+
31+
virtual ~MemoryAccess();
32+
33+
virtual void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
34+
WriteResultFn OnWriteComplete) = 0;
35+
36+
virtual void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
37+
WriteResultFn OnWriteComplete) = 0;
38+
39+
virtual void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
40+
WriteResultFn OnWriteComplete) = 0;
41+
42+
virtual void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
43+
WriteResultFn OnWriteComplete) = 0;
44+
45+
virtual void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
46+
WriteResultFn OnWriteComplete) = 0;
47+
48+
virtual void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
49+
WriteResultFn OnWriteComplete) = 0;
50+
51+
Error writeUInt8s(ArrayRef<tpctypes::UInt8Write> Ws) {
52+
std::promise<MSVCPError> ResultP;
53+
auto ResultF = ResultP.get_future();
54+
writeUInt8sAsync(Ws, [&](Error Err) { ResultP.set_value(std::move(Err)); });
55+
return ResultF.get();
56+
}
57+
58+
Error writeUInt16s(ArrayRef<tpctypes::UInt16Write> Ws) {
59+
std::promise<MSVCPError> ResultP;
60+
auto ResultF = ResultP.get_future();
61+
writeUInt16sAsync(Ws,
62+
[&](Error Err) { ResultP.set_value(std::move(Err)); });
63+
return ResultF.get();
64+
}
65+
66+
Error writeUInt32s(ArrayRef<tpctypes::UInt32Write> Ws) {
67+
std::promise<MSVCPError> ResultP;
68+
auto ResultF = ResultP.get_future();
69+
writeUInt32sAsync(Ws,
70+
[&](Error Err) { ResultP.set_value(std::move(Err)); });
71+
return ResultF.get();
72+
}
73+
74+
Error writeUInt64s(ArrayRef<tpctypes::UInt64Write> Ws) {
75+
std::promise<MSVCPError> ResultP;
76+
auto ResultF = ResultP.get_future();
77+
writeUInt64sAsync(Ws,
78+
[&](Error Err) { ResultP.set_value(std::move(Err)); });
79+
return ResultF.get();
80+
}
81+
82+
Error writeBuffers(ArrayRef<tpctypes::BufferWrite> Ws) {
83+
std::promise<MSVCPError> ResultP;
84+
auto ResultF = ResultP.get_future();
85+
writeBuffersAsync(Ws,
86+
[&](Error Err) { ResultP.set_value(std::move(Err)); });
87+
return ResultF.get();
88+
}
89+
90+
Error writePointers(ArrayRef<tpctypes::PointerWrite> Ws) {
91+
std::promise<MSVCPError> ResultP;
92+
auto ResultF = ResultP.get_future();
93+
writePointersAsync(Ws,
94+
[&](Error Err) { ResultP.set_value(std::move(Err)); });
95+
return ResultF.get();
96+
}
97+
};
98+
99+
} // namespace llvm::orc
100+
101+
#endif // LLVM_EXECUTIONENGINE_ORC_MEMORYACCESS_H

0 commit comments

Comments
 (0)