aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-11-20 03:46:14 +0000
committerChris Lattner <sabre@nondot.org>2004-11-20 03:46:14 +0000
commit5be478f360b4c632d1adfccc64df87840e1ccfc1 (patch)
tree893798c02dba6b9afba72d5a77521080e8257a8a /lib/ExecutionEngine
parent47012c0c711fd10901fb30643def557af7bbb4a9 (diff)
downloadexternal_llvm-5be478f360b4c632d1adfccc64df87840e1ccfc1.zip
external_llvm-5be478f360b4c632d1adfccc64df87840e1ccfc1.tar.gz
external_llvm-5be478f360b4c632d1adfccc64df87840e1ccfc1.tar.bz2
Add getCurrentPCOffset() and addRelocation() methods.
Add stub support for relocations to finishFunction git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 8c1de88..695e044 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines a MachineCodeEmitter object that is used by Jello to write
-// machine code to memory and remember where relocatable values lie.
+// This file defines a MachineCodeEmitter object that is used by the JIT to
+// write machine code to memory and remember where relocatable values are.
//
//===----------------------------------------------------------------------===//
@@ -19,7 +19,9 @@
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineRelocation.h"
#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetJITInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/System/Memory.h"
@@ -72,9 +74,9 @@ unsigned char *JITMemoryManager::allocateStub(unsigned StubSize) {
}
unsigned char *JITMemoryManager::startFunctionBody() {
- // Round up to an even multiple of 4 bytes, this should eventually be target
+ // Round up to an even multiple of 8 bytes, this should eventually be target
// specific.
- return (unsigned char*)(((intptr_t)CurFunctionPtr + 3) & ~3);
+ return (unsigned char*)(((intptr_t)CurFunctionPtr + 7) & ~7);
}
void JITMemoryManager::endFunctionBody(unsigned char *FunctionEnd) {
@@ -101,6 +103,10 @@ namespace {
// ConstantPoolAddresses - Contains the location for each entry in the
// constant pool.
std::vector<void*> ConstantPoolAddresses;
+
+ /// Relocations - These are the relocations that the function needs, as
+ /// emitted.
+ std::vector<MachineRelocation> Relocations;
public:
Emitter(JIT &jit) { TheJIT = &jit; }
@@ -113,10 +119,15 @@ namespace {
virtual void emitWord(unsigned W);
virtual void emitWordAt(unsigned W, unsigned *Ptr);
+ virtual void addRelocation(const MachineRelocation &MR) {
+ Relocations.push_back(MR);
+ }
+
+ virtual uint64_t getCurrentPCValue();
+ virtual uint64_t getCurrentPCOffset();
virtual uint64_t getGlobalValueAddress(GlobalValue *V);
virtual uint64_t getGlobalValueAddress(const char *Name);
virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
- virtual uint64_t getCurrentPCValue();
// forceCompilationOf - Force the compilation of the specified function, and
// return its address, because we REALLY need the address now.
@@ -141,9 +152,28 @@ void Emitter::finishFunction(MachineFunction &F) {
ConstantPoolAddresses.clear();
NumBytes += CurByte-CurBlock;
+ if (!Relocations.empty()) {
+ // Resolve the relocations to concrete pointers.
+ for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
+ MachineRelocation &MR = Relocations[i];
+ void *ResultPtr;
+ if (MR.isGlobalValue()) {
+ assert(0 && "Unimplemented!\n");
+ } else {
+ ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
+ }
+ MR.setResultPointer(ResultPtr);
+ }
+
+ TheJIT->getJITInfo().relocate(CurBlock, &Relocations[0],
+ Relocations.size());
+ }
+
DEBUG(std::cerr << "Finished CodeGen of [" << (void*)CurBlock
<< "] Function: " << F.getFunction()->getName()
- << ": " << CurByte-CurBlock << " bytes of text\n");
+ << ": " << CurByte-CurBlock << " bytes of text, "
+ << Relocations.size() << " relocations\n");
+ Relocations.clear();
}
void Emitter::emitConstantPool(MachineConstantPool *MCP) {
@@ -245,6 +275,10 @@ uint64_t Emitter::getCurrentPCValue() {
return (intptr_t)CurByte;
}
+uint64_t Emitter::getCurrentPCOffset() {
+ return (intptr_t)CurByte-(intptr_t)CurBlock;
+}
+
uint64_t Emitter::forceCompilationOf(Function *F) {
return (intptr_t)TheJIT->getPointerToFunction(F);
}