14 #define DEBUG_TYPE "jit"
27 #define BUILD_ADDIS(RD,RS,IMM16) \
28 ((15 << 26) | ((RD) << 21) | ((RS) << 16) | ((IMM16) & 65535))
29 #define BUILD_ORI(RD,RS,UIMM16) \
30 ((24 << 26) | ((RS) << 21) | ((RD) << 16) | ((UIMM16) & 65535))
31 #define BUILD_ORIS(RD,RS,UIMM16) \
32 ((25 << 26) | ((RS) << 21) | ((RD) << 16) | ((UIMM16) & 65535))
33 #define BUILD_RLDICR(RD,RS,SH,ME) \
34 ((30 << 26) | ((RS) << 21) | ((RD) << 16) | (((SH) & 31) << 11) | \
35 (((ME) & 63) << 6) | (1 << 2) | ((((SH) >> 5) & 1) << 1))
36 #define BUILD_MTSPR(RS,SPR) \
37 ((31 << 26) | ((RS) << 21) | ((SPR) << 16) | (467 << 1))
38 #define BUILD_BCCTRx(BO,BI,LINK) \
39 ((19 << 26) | ((BO) << 21) | ((BI) << 16) | (528 << 1) | ((LINK) & 1))
40 #define BUILD_B(TARGET, LINK) \
41 ((18 << 26) | (((TARGET) & 0x00FFFFFF) << 2) | ((LINK) & 1))
44 #define BUILD_LIS(RD,IMM16) BUILD_ADDIS(RD,0,IMM16)
45 #define BUILD_SLDI(RD,RS,IMM6) BUILD_RLDICR(RD,RS,IMM6,63-IMM6)
46 #define BUILD_MTCTR(RS) BUILD_MTSPR(RS,9)
47 #define BUILD_BCTR(LINK) BUILD_BCCTRx(20,0,LINK)
49 static void EmitBranchToAt(uint64_t At, uint64_t To,
bool isCall,
bool is64Bit){
51 unsigned *AtI = (
unsigned*)(
intptr_t)At;
53 if (Offset >= -(1 << 23) && Offset < (1 << 23)) {
54 AtI[0] =
BUILD_B(Offset, isCall);
55 }
else if (!is64Bit) {
76 #if (!defined(__ppc__) && !defined(__powerpc__)) || defined(__powerpc64__) || defined(__ppc64__)
80 #elif !defined(__ELF__)
88 ".globl _PPC32CompilationCallback\n"
89 "_PPC32CompilationCallback:\n"
101 "stwu r1, -208(r1)\n"
103 "stw r10, 204(r1)\n" "stw r9, 200(r1)\n"
104 "stw r8, 196(r1)\n" "stw r7, 192(r1)\n"
105 "stw r6, 188(r1)\n" "stw r5, 184(r1)\n"
106 "stw r4, 180(r1)\n" "stw r3, 176(r1)\n"
108 "stfd f13, 168(r1)\n" "stfd f12, 160(r1)\n"
109 "stfd f11, 152(r1)\n" "stfd f10, 144(r1)\n"
110 "stfd f9, 136(r1)\n" "stfd f8, 128(r1)\n"
111 "stfd f7, 120(r1)\n" "stfd f6, 112(r1)\n"
112 "stfd f5, 104(r1)\n" "stfd f4, 96(r1)\n"
113 "stfd f3, 88(r1)\n" "stfd f2, 80(r1)\n"
123 "bl _LLVMPPCCompilationCallback\n"
126 "lwz r10, 204(r1)\n" "lwz r9, 200(r1)\n"
127 "lwz r8, 196(r1)\n" "lwz r7, 192(r1)\n"
128 "lwz r6, 188(r1)\n" "lwz r5, 184(r1)\n"
129 "lwz r4, 180(r1)\n" "lwz r3, 176(r1)\n"
131 "lfd f13, 168(r1)\n" "lfd f12, 160(r1)\n"
132 "lfd f11, 152(r1)\n" "lfd f10, 144(r1)\n"
133 "lfd f9, 136(r1)\n" "lfd f8, 128(r1)\n"
134 "lfd f7, 120(r1)\n" "lfd f6, 112(r1)\n"
135 "lfd f5, 104(r1)\n" "lfd f4, 96(r1)\n"
136 "lfd f3, 88(r1)\n" "lfd f2, 80(r1)\n"
155 ".globl PPC32CompilationCallback\n"
156 "PPC32CompilationCallback:\n"
168 "stw 10, 100(1)\n" "stw 9, 96(1)\n"
169 "stw 8, 92(1)\n" "stw 7, 88(1)\n"
170 "stw 6, 84(1)\n" "stw 5, 80(1)\n"
171 "stw 4, 76(1)\n" "stw 3, 72(1)\n"
174 "stfd 7, 56(1)\n" "stfd 6, 48(1)\n"
175 "stfd 5, 40(1)\n" "stfd 4, 32(1)\n"
176 "stfd 3, 24(1)\n" "stfd 2, 16(1)\n"
186 "bl LLVMPPCCompilationCallback\n"
189 "lwz 10, 100(1)\n" "lwz 9, 96(1)\n"
190 "lwz 8, 92(1)\n" "lwz 7, 88(1)\n"
191 "lwz 6, 84(1)\n" "lwz 5, 80(1)\n"
192 "lwz 4, 76(1)\n" "lwz 3, 72(1)\n"
195 "lfd 7, 56(1)\n" "lfd 6, 48(1)\n"
196 "lfd 5, 40(1)\n" "lfd 4, 32(1)\n"
197 "lfd 3, 24(1)\n" "lfd 2, 16(1)\n"
207 #if !defined(__powerpc64__) && !defined(__ppc64__)
216 ".globl PPC64CompilationCallback\n"
217 ".section \".opd\",\"aw\",@progbits\n"
219 "PPC64CompilationCallback:\n"
220 ".quad .L.PPC64CompilationCallback,.TOC.@tocbase,0\n"
221 ".size PPC64CompilationCallback,24\n"
224 ".type PPC64CompilationCallback,@function\n"
225 ".L.PPC64CompilationCallback:\n"
230 ".globl _PPC64CompilationCallback\n"
231 "_PPC64CompilationCallback:\n"
245 "std 10, 272(1)\n" "std 9, 264(1)\n"
246 "std 8, 256(1)\n" "std 7, 248(1)\n"
247 "std 6, 240(1)\n" "std 5, 232(1)\n"
248 "std 4, 224(1)\n" "std 3, 216(1)\n"
250 "stfd 13, 208(1)\n" "stfd 12, 200(1)\n"
251 "stfd 11, 192(1)\n" "stfd 10, 184(1)\n"
252 "stfd 9, 176(1)\n" "stfd 8, 168(1)\n"
253 "stfd 7, 160(1)\n" "stfd 6, 152(1)\n"
254 "stfd 5, 144(1)\n" "stfd 4, 136(1)\n"
255 "stfd 3, 128(1)\n" "stfd 2, 120(1)\n"
266 "bl LLVMPPCCompilationCallback\n"
269 "bl _LLVMPPCCompilationCallback\n"
273 "ld 10, 272(1)\n" "ld 9, 264(1)\n"
274 "ld 8, 256(1)\n" "ld 7, 248(1)\n"
275 "ld 6, 240(1)\n" "ld 5, 232(1)\n"
276 "ld 4, 224(1)\n" "ld 3, 216(1)\n"
278 "lfd 13, 208(1)\n" "lfd 12, 200(1)\n"
279 "lfd 11, 192(1)\n" "lfd 10, 184(1)\n"
280 "lfd 9, 176(1)\n" "lfd 8, 168(1)\n"
281 "lfd 7, 160(1)\n" "lfd 6, 152(1)\n"
282 "lfd 5, 144(1)\n" "lfd 4, 136(1)\n"
283 "lfd 3, 128(1)\n" "lfd 2, 120(1)\n"
297 unsigned *OrigCallAddrPlus4,
301 unsigned *StubCallAddr = StubCallAddrPlus4 - 1;
302 unsigned *OrigCallAddr = OrigCallAddrPlus4 - 1;
309 unsigned OrigCallInst = *OrigCallAddr;
310 if ((OrigCallInst >> 26) == 18) {
313 if (Offset >= -(1 << 23) && Offset < (1 << 23)) {
315 OrigCallInst &= (63 << 26) | 3;
317 OrigCallInst |= (Offset & ((1 << 24)-1)) << 2;
319 *OrigCallAddr = OrigCallInst;
325 if ((*StubCallAddr >> 26) == 18)
328 assert((*StubCallAddr >> 26) == 19 &&
"Call in stub is not indirect!");
329 StubCallAddr -= is64Bit ? 9 : 6;
361 #if (defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)) && \
363 extern "C" void sys_icache_invalidate(
const void *Addr,
size_t len);
414 unsigned NumRelocs,
unsigned char* GOTBase) {
415 for (
unsigned i = 0; i != NumRelocs; ++i, ++MR) {
422 ResultPtr = (ResultPtr-(
intptr_t)RelocPos) >> 2;
423 assert(ResultPtr >= -(1 << 23) && ResultPtr < (1 << 23) &&
424 "Relocation out of range!");
425 *RelocPos |= (ResultPtr & ((1 << 24)-1)) << 2;
430 ResultPtr = (ResultPtr-(
intptr_t)RelocPos) >> 2;
431 assert(ResultPtr >= -(1 << 13) && ResultPtr < (1 << 13) &&
432 "Relocation out of range!");
433 *RelocPos |= (ResultPtr & ((1 << 14)-1)) << 2;
443 if (((
int)ResultPtr << 16) < 0)
444 ResultPtr += 1 << 16;
450 unsigned LowBits = (*RelocPos + ResultPtr) & 65535;
451 unsigned HighBits = *RelocPos & ~65535;
452 *RelocPos = LowBits | HighBits;
459 unsigned LowBits = (*RelocPos + ResultPtr) & 0xFFFC;
460 unsigned HighBits = *RelocPos & 0xFFFF0003;
461 *RelocPos = LowBits | HighBits;
#define BUILD_ORIS(RD, RS, UIMM16)
unsigned getRelocationType() const
virtual void * emitFunctionStub(const Function *F, void *Fn, JITCodeEmitter &JCE)
void *(* JITCompilerFn)(void *)
static void InvalidateInstructionCache(const void *Addr, size_t Len)
#define llvm_unreachable(msg)
intptr_t getConstantVal() const
virtual void replaceMachineCodeForFunction(void *Old, void *New)
void PPC64CompilationCallback()
void emitWordBE(uint32_t W)
intptr_t getMachineCodeOffset() const
virtual StubLayout getStubLayout()
Returns the maximum size and alignment for a call stub on this target.
#define LLVM_LIBRARY_VISIBILITY
virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn)
#define BUILD_SLDI(RD, RS, IMM6)
virtual const PPCSubtarget * getSubtargetImpl() const
void * getResultPointer() const
virtual uintptr_t getCurrentPCValue() const
LLVM_LIBRARY_VISIBILITY void * LLVMPPCCompilationCallback(unsigned *StubCallAddrPlus4, unsigned *OrigCallAddrPlus4, bool is64Bit)
static TargetJITInfo::JITCompilerFn JITCompilerFunction
#define BUILD_LIS(RD, IMM16)
#define BUILD_B(TARGET, LINK)
#define BUILD_ORI(RD, RS, UIMM16)
virtual void relocate(void *Function, MachineRelocation *MR, unsigned NumRelocs, unsigned char *GOTBase)
static void EmitBranchToAt(uint64_t At, uint64_t To, bool isCall, bool is64Bit)
void PPC32CompilationCallback()
Records the required size and alignment for a call stub in bytes.