5 using namespace llvm::orc;
26 const unsigned X86_64_TrampolineLength = 6;
29 std::array<const char *, 14> GPRs = {{
30 "rax",
"rbx",
"rcx",
"rdx",
31 "rsi",
"rdi",
"r8",
"r9",
32 "r10",
"r11",
"r12",
"r13",
37 uint64_t CallbackAddr =
38 static_cast<uint64_t
>(
39 reinterpret_cast<uintptr_t
>(executeCompileCallback));
41 std::ostringstream AsmStream;
46 AsmStream <<
".section __TEXT,__text,regular,pure_instructions\n"
47 <<
".align 4, 0x90\n";
49 AsmStream <<
".text\n"
50 <<
".align 16, 0x90\n";
54 AsmStream <<
"jit_callback_manager_addr:\n"
55 <<
" .quad " << &JCBM <<
"\n";
58 AsmStream << ResolverBlockName <<
":\n"
60 <<
" movq %rsp, %rbp\n";
63 for (
const auto &GPR : GPRs)
64 AsmStream <<
" pushq %" << GPR <<
"\n";
70 unsigned Padding = (GPRs.size() + 1) % 2 ? 8 : 0;
71 unsigned FXSaveSize = 512 + Padding;
72 AsmStream <<
" subq $" << FXSaveSize <<
", %rsp\n"
73 <<
" fxsave64 (%rsp)\n"
76 <<
" lea jit_callback_manager_addr(%rip), %rdi\n"
77 <<
" movq (%rdi), %rdi\n"
78 <<
" movq 0x8(%rbp), %rsi\n"
79 <<
" subq $" << X86_64_TrampolineLength <<
", %rsi\n"
80 <<
" movabsq $" << CallbackAddr <<
", %rax\n"
85 <<
" movq %rax, 0x8(%rbp)\n"
88 <<
" fxrstor64 (%rsp)\n"
89 <<
" addq $" << FXSaveSize <<
", %rsp\n";
91 for (
const auto &GPR :
make_range(GPRs.rbegin(), GPRs.rend()))
92 AsmStream <<
" popq %" << GPR <<
"\n";
95 AsmStream <<
" popq %rbp\n"
105 unsigned StartIndex) {
106 const char *ResolverBlockPtrName =
"Lorc_resolve_block_addr";
108 std::ostringstream AsmStream;
112 AsmStream <<
".section __TEXT,__text,regular,pure_instructions\n"
113 <<
".align 4, 0x90\n";
115 AsmStream <<
".text\n"
116 <<
".align 16, 0x90\n";
118 AsmStream << ResolverBlockPtrName <<
":\n"
119 <<
" .quad " << ResolverBlockAddr <<
"\n";
123 std::ostringstream LabelStream;
124 LabelStream <<
"orc_jcc_" << (StartIndex +
I);
125 return LabelStream.
str();
128 for (
unsigned I = 0;
I < NumCalls; ++
I)
129 AsmStream << GetLabelName(
I) <<
":\n"
130 <<
" callq *" << ResolverBlockPtrName <<
"(%rip)\n";
A Module instance is used to store all the information related to an LLVM module. ...
const std::string & str() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static void insertResolverBlock(Module &M, JITCompileCallbackManagerBase &JCBM)
Insert module-level inline callback asm into module M for the symbols managed by JITResolveCallbackHa...
Base class for JITLayer independent aspects of JITCompileCallbackManager.
TargetAddress executeCompileCallback(TargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
Triple - Helper class for working with autoconf configuration names.
static const char * ResolverBlockName
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
uint64_t TargetAddress
Represents an address in the target process's address space.
std::function< std::string(unsigned)> LabelNameFtor
Get a label name from the given index.
static LabelNameFtor insertCompileCallbackTrampolines(Module &M, TargetAddress TrampolineAddr, unsigned NumCalls, unsigned StartIndex=0)
Insert the requested number of trampolines into the given module.
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.