Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
DispatcherHost.hpp
Go to the documentation of this file.
1#ifndef PROTEUS_FRONTEND_DISPATCHER_HOST_HPP
2#define PROTEUS_FRONTEND_DISPATCHER_HOST_HPP
3
6
7namespace proteus {
8
9class DispatcherHost : public Dispatcher {
10public:
12 static DispatcherHost D;
13 return D;
14 }
15
16 std::unique_ptr<MemoryBuffer>
17 compile(std::unique_ptr<LLVMContext> Ctx, std::unique_ptr<Module> M,
18 [[maybe_unused]] HashT ModuleHash) override {
19 // ModuleHash is unused since we do not implement an object cache for host
20 // JIT.
21 Jit.compileOnly(std::move(Ctx), std::move(M));
22 // TODO: Host compilation is managed by ORC lazy JIT and does not support
23 // synchronous object creation.
24 return nullptr;
25 }
26
27 std::unique_ptr<MemoryBuffer> lookupObjectModule(HashT) override {
28 // Host JIT does not implement object caching.
29 return nullptr;
30 }
31
32 DispatchResult launch(StringRef, LaunchDims, LaunchDims, ArrayRef<void *>,
33 uint64_t, void *,
34 std::optional<MemoryBufferRef>) override {
35 PROTEUS_FATAL_ERROR("Host does not support launch");
36 }
37
38 DispatchResult launch(void *, LaunchDims, LaunchDims, ArrayRef<void *>,
39 uint64_t, void *) override {
40 PROTEUS_FATAL_ERROR("Host does not support launch");
41 }
42
43 StringRef getTargetArch() const override {
44 PROTEUS_FATAL_ERROR("Host dispatcher does not implement getTargetArch");
45 }
46
47 void *getFunctionAddress(StringRef FnName,
48 std::optional<MemoryBufferRef>) override {
49 // ObjectModule is unused, the ORC JIT singleton has a single global module.
50 void *FuncAddr = Jit.getFunctionAddress(FnName);
51 if (!FuncAddr)
52 PROTEUS_FATAL_ERROR("Failed to find address for function " + FnName);
53
54 return FuncAddr;
55 }
56
57private:
58 // TODO: The JitEngineHost is a singleton and consolidates all compiled IR in
59 // a single object layer. This creates name collision for same named functions
60 // (duplicate definitions) though they are in different Jit modules.
61 // Reconsider singletons for both the JitEngineHost and the Dispatcher.
62 JitEngineHost &Jit;
65 }
66};
67
68} // namespace proteus
69
70#endif // PROTEUS_FRONTEND_DISPATCHER_HOST_HPP
auto & Jit
Definition CompilerInterfaceDevice.cpp:54
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:7
Definition DispatcherHost.hpp:9
DispatchResult launch(void *, LaunchDims, LaunchDims, ArrayRef< void * >, uint64_t, void *) override
Definition DispatcherHost.hpp:38
static DispatcherHost & instance()
Definition DispatcherHost.hpp:11
StringRef getTargetArch() const override
Definition DispatcherHost.hpp:43
std::unique_ptr< MemoryBuffer > lookupObjectModule(HashT) override
Definition DispatcherHost.hpp:27
void * getFunctionAddress(StringRef FnName, std::optional< MemoryBufferRef >) override
Definition DispatcherHost.hpp:47
DispatchResult launch(StringRef, LaunchDims, LaunchDims, ArrayRef< void * >, uint64_t, void *, std::optional< MemoryBufferRef >) override
Definition DispatcherHost.hpp:32
std::unique_ptr< MemoryBuffer > compile(std::unique_ptr< LLVMContext > Ctx, std::unique_ptr< Module > M, HashT ModuleHash) override
Definition DispatcherHost.hpp:17
Definition Dispatcher.hpp:46
TargetModelType TargetModel
Definition Dispatcher.hpp:48
Definition Hashing.hpp:20
Definition JitEngineHost.hpp:28
void compileOnly(std::unique_ptr< LLVMContext > Ctx, std::unique_ptr< Module > M)
Definition JitEngineHost.cpp:369
void * getFunctionAddress(StringRef FnName)
Definition JitEngineHost.cpp:376
Definition CppJitModule.cpp:21
Definition Dispatcher.hpp:15
Definition Dispatcher.hpp:24