1 //===-- OrcTargetSupport.h - Code to support specific targets --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Target specific code for Orc, e.g. callback assembly.
12 // Target classes should be part of the JIT *target* process, not the host
13 // process (except where you're doing hosted JITing and the two are one and the
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H
19 #define LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H
21 #include "IndirectionUtils.h"
22 #include "llvm/Support/Memory.h"
29 static const char *ResolverBlockName;
31 /// @brief Insert module-level inline callback asm into module M for the
32 /// symbols managed by JITResolveCallbackHandler J.
33 static void insertResolverBlock(Module &M,
34 JITCompileCallbackManagerBase &JCBM);
36 /// @brief Get a label name from the given index.
37 typedef std::function<std::string(unsigned)> LabelNameFtor;
39 /// @brief Insert the requested number of trampolines into the given module.
40 /// @param M Module to insert the call block into.
41 /// @param NumCalls Number of calls to create in the call block.
42 /// @param StartIndex Optional argument specifying the index suffix to start
44 /// @return A functor that provides the symbol name for each entry in the call
47 static LabelNameFtor insertCompileCallbackTrampolines(
49 TargetAddress TrampolineAddr,
51 unsigned StartIndex = 0);
53 /// @brief Provide information about stub blocks generated by the
54 /// makeIndirectStubsBlock function.
55 class IndirectStubsInfo {
56 friend class OrcX86_64;
58 const static unsigned StubSize = 8;
59 const static unsigned PtrSize = 8;
61 IndirectStubsInfo() : NumStubs(0) {}
62 IndirectStubsInfo(IndirectStubsInfo&&);
63 IndirectStubsInfo& operator=(IndirectStubsInfo&&);
66 /// @brief Number of stubs in this block.
67 unsigned getNumStubs() const { return NumStubs; }
69 /// @brief Get a pointer to the stub at the given index, which must be in
70 /// the range 0 .. getNumStubs() - 1.
71 void* getStub(unsigned Idx) const {
72 return static_cast<uint64_t*>(StubsBlock.base()) + Idx;
75 /// @brief Get a pointer to the implementation-pointer at the given index,
76 /// which must be in the range 0 .. getNumStubs() - 1.
77 void** getPtr(unsigned Idx) const {
78 return static_cast<void**>(PtrsBlock.base()) + Idx;
82 sys::MemoryBlock StubsBlock;
83 sys::MemoryBlock PtrsBlock;
86 /// @brief Emit at least MinStubs worth of indirect call stubs, rounded out to
87 /// the nearest page size.
89 /// E.g. Asking for 4 stubs on x86-64, where stubs are 8-bytes, with 4k
90 /// pages will return a block of 512 stubs (4096 / 8 = 512). Asking for 513
91 /// will return a block of 1024 (2-pages worth).
92 static std::error_code emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
97 } // End namespace orc.
98 } // End namespace llvm.
100 #endif // LLVM_EXECUTIONENGINE_ORC_ORCTARGETSUPPORT_H