xref: /llvm-project/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h (revision 209c242845e56eb8dbbde5e380b165d261769266)
17f99337fSLang Hames //===- EPCGenericMemoryAccess.h - Generic EPC MemoryAccess impl -*- C++ -*-===//
27f99337fSLang Hames //
37f99337fSLang Hames // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47f99337fSLang Hames // See https://llvm.org/LICENSE.txt for license information.
57f99337fSLang Hames // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67f99337fSLang Hames //
77f99337fSLang Hames //===----------------------------------------------------------------------===//
87f99337fSLang Hames //
97f99337fSLang Hames // Implements ExecutorProcessControl::MemoryAccess by making calls to
107f99337fSLang Hames // ExecutorProcessControl::callWrapperAsync.
117f99337fSLang Hames //
127f99337fSLang Hames // This simplifies the implementaton of new ExecutorProcessControl instances,
137f99337fSLang Hames // as this implementation will always work (at the cost of some performance
147f99337fSLang Hames // overhead for the calls).
157f99337fSLang Hames //
167f99337fSLang Hames //===----------------------------------------------------------------------===//
177f99337fSLang Hames 
187f99337fSLang Hames #ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H
197f99337fSLang Hames #define LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H
207f99337fSLang Hames 
217f99337fSLang Hames #include "llvm/ExecutionEngine/Orc/Core.h"
227f99337fSLang Hames 
237f99337fSLang Hames namespace llvm {
247f99337fSLang Hames namespace orc {
257f99337fSLang Hames 
267f99337fSLang Hames class EPCGenericMemoryAccess : public ExecutorProcessControl::MemoryAccess {
277f99337fSLang Hames public:
287f99337fSLang Hames   /// Function addresses for memory access.
297f99337fSLang Hames   struct FuncAddrs {
30ef391df2SLang Hames     ExecutorAddr WriteUInt8s;
31ef391df2SLang Hames     ExecutorAddr WriteUInt16s;
32ef391df2SLang Hames     ExecutorAddr WriteUInt32s;
33ef391df2SLang Hames     ExecutorAddr WriteUInt64s;
34ef391df2SLang Hames     ExecutorAddr WriteBuffers;
35*209c2428SSunho Kim     ExecutorAddr WritePointers;
367f99337fSLang Hames   };
377f99337fSLang Hames 
387f99337fSLang Hames   /// Create an EPCGenericMemoryAccess instance from a given set of
397f99337fSLang Hames   /// function addrs.
EPCGenericMemoryAccess(ExecutorProcessControl & EPC,FuncAddrs FAs)407f99337fSLang Hames   EPCGenericMemoryAccess(ExecutorProcessControl &EPC, FuncAddrs FAs)
417f99337fSLang Hames       : EPC(EPC), FAs(FAs) {}
427f99337fSLang Hames 
writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,WriteResultFn OnWriteComplete)437f99337fSLang Hames   void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
447f99337fSLang Hames                         WriteResultFn OnWriteComplete) override {
457f99337fSLang Hames     using namespace shared;
467f99337fSLang Hames     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt8Write>)>(
47da7f993aSLang Hames         FAs.WriteUInt8s, std::move(OnWriteComplete), Ws);
487f99337fSLang Hames   }
497f99337fSLang Hames 
writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,WriteResultFn OnWriteComplete)507f99337fSLang Hames   void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws,
517f99337fSLang Hames                          WriteResultFn OnWriteComplete) override {
527f99337fSLang Hames     using namespace shared;
537f99337fSLang Hames     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt16Write>)>(
54da7f993aSLang Hames         FAs.WriteUInt16s, std::move(OnWriteComplete), Ws);
557f99337fSLang Hames   }
567f99337fSLang Hames 
writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,WriteResultFn OnWriteComplete)577f99337fSLang Hames   void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws,
587f99337fSLang Hames                          WriteResultFn OnWriteComplete) override {
597f99337fSLang Hames     using namespace shared;
607f99337fSLang Hames     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt32Write>)>(
61da7f993aSLang Hames         FAs.WriteUInt32s, std::move(OnWriteComplete), Ws);
627f99337fSLang Hames   }
637f99337fSLang Hames 
writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,WriteResultFn OnWriteComplete)647f99337fSLang Hames   void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws,
657f99337fSLang Hames                          WriteResultFn OnWriteComplete) override {
667f99337fSLang Hames     using namespace shared;
677f99337fSLang Hames     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt64Write>)>(
68da7f993aSLang Hames         FAs.WriteUInt64s, std::move(OnWriteComplete), Ws);
697f99337fSLang Hames   }
707f99337fSLang Hames 
writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,WriteResultFn OnWriteComplete)717f99337fSLang Hames   void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
727f99337fSLang Hames                          WriteResultFn OnWriteComplete) override {
737f99337fSLang Hames     using namespace shared;
747f99337fSLang Hames     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessBufferWrite>)>(
75da7f993aSLang Hames         FAs.WriteBuffers, std::move(OnWriteComplete), Ws);
767f99337fSLang Hames   }
777f99337fSLang Hames 
writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,WriteResultFn OnWriteComplete)78*209c2428SSunho Kim   void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws,
79*209c2428SSunho Kim                           WriteResultFn OnWriteComplete) override {
80*209c2428SSunho Kim     using namespace shared;
81*209c2428SSunho Kim     EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessPointerWrite>)>(
82*209c2428SSunho Kim         FAs.WritePointers, std::move(OnWriteComplete), Ws);
83*209c2428SSunho Kim   }
84*209c2428SSunho Kim 
857f99337fSLang Hames private:
867f99337fSLang Hames   ExecutorProcessControl &EPC;
877f99337fSLang Hames   FuncAddrs FAs;
887f99337fSLang Hames };
897f99337fSLang Hames 
907f99337fSLang Hames } // end namespace orc
917f99337fSLang Hames } // end namespace llvm
927f99337fSLang Hames 
937f99337fSLang Hames #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H
94