summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2008-08-12 23:20:24 +0000
committerDale Johannesen <dalej@apple.com>2008-08-12 23:20:24 +0000
commit40f83ac6497f61f24baf49afb66d67d5181e9dfe (patch)
tree55e82126fb38e22d4b74593ad260babc550ae3c7 /llvm
parentf21a38700f8d6541411bd4da465bcafc6b0849b7 (diff)
downloadbcm5719-llvm-40f83ac6497f61f24baf49afb66d67d5181e9dfe.tar.gz
bcm5719-llvm-40f83ac6497f61f24baf49afb66d67d5181e9dfe.zip
When resolving a stub in x86-64 JIT, use a PC-relative branch
rather than the absolute address if the target is within range. llvm-svn: 54708
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/X86/X86JITInfo.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/X86JITInfo.cpp b/llvm/lib/Target/X86/X86JITInfo.cpp
index f7d1118d700..7b3a0703277 100644
--- a/llvm/lib/Target/X86/X86JITInfo.cpp
+++ b/llvm/lib/Target/X86/X86JITInfo.cpp
@@ -352,7 +352,8 @@ X86CompilationCallback2(intptr_t *StackPtr, intptr_t RetAddr) {
// 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 @@ X86CompilationCallback2(intptr_t *StackPtr, intptr_t RetAddr) {
// 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
OpenPOWER on IntegriCloud