[llvm-commits] [llvm] r54713 - /llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp
Bill Wendling
isanbard at gmail.com
Tue Aug 12 19:50:50 PDT 2008
Author: void
Date: Tue Aug 12 21:50:50 2008
New Revision: 54713
URL: http://llvm.org/viewvc/llvm-project?rev=54713&view=rev
Log:
Pull r54708 into llvmCore-2064:
When resolving a stub in x86-64 JIT, use a PC-relative branch
rather than the absolute address if the target is within range.
Modified:
llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp
Modified: llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp?rev=54713&r1=54712&r2=54713&view=diff
==============================================================================
--- llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp (original)
+++ llvm/tags/Apple/llvmCore-2064/lib/Target/X86/X86JITInfo.cpp Tue Aug 12 21:50:50 2008
@@ -352,7 +352,8 @@
// Rewrite the call target... so that we don't end up here every time we
// execute the call.
#if defined (X86_64_JIT)
- *(intptr_t *)(RetAddr - 0xa) = NewVal;
+ if (!isStub)
+ *(intptr_t *)(RetAddr - 0xa) = NewVal;
#else
*(intptr_t *)RetAddr = (intptr_t)(NewVal-RetAddr-4);
#endif
@@ -363,7 +364,18 @@
// when the requested function finally gets called. This also makes the
// 0xCD byte (interrupt) dead, so the marker doesn't effect anything.
#if defined (X86_64_JIT)
- ((unsigned char*)RetAddr)[0] = (2 | (4 << 3) | (3 << 6));
+ // If the target address is within 32-bit range of the stub, use a
+ // PC-relative branch instead of loading the actual address. (This is
+ // considerably shorter than the 64-bit immediate load already there.)
+ // We assume here intptr_t is 64 bits.
+ intptr_t diff = NewVal-RetAddr+7;
+ if (diff >= -2147483648LL && diff <= 2147483647LL) {
+ *(unsigned char*)(RetAddr-0xc) = 0xE9;
+ *(intptr_t *)(RetAddr-0xb) = diff & 0xffffffff;
+ } else {
+ *(intptr_t *)(RetAddr - 0xa) = NewVal;
+ ((unsigned char*)RetAddr)[0] = (2 | (4 << 3) | (3 << 6));
+ }
#else
((unsigned char*)RetAddr)[-1] = 0xE9;
#endif
More information about the llvm-commits
mailing list