[llvm-commits] CVS: reopt/lib/TraceJIT/TraceJITEmitter.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Sun Nov 28 23:36:10 PST 2004
Changes in directory reopt/lib/TraceJIT:
TraceJITEmitter.cpp updated: 1.5 -> 1.6
---
Log message:
Add relocation support.
---
Diffs of the changes: (+50 -38)
Index: reopt/lib/TraceJIT/TraceJITEmitter.cpp
diff -u reopt/lib/TraceJIT/TraceJITEmitter.cpp:1.5 reopt/lib/TraceJIT/TraceJITEmitter.cpp:1.6
--- reopt/lib/TraceJIT/TraceJITEmitter.cpp:1.5 Sun Nov 21 17:01:06 2004
+++ reopt/lib/TraceJIT/TraceJITEmitter.cpp Mon Nov 29 01:35:58 2004
@@ -27,7 +27,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/Support/DynamicLinker.h"
using namespace llvm;
@@ -47,6 +49,10 @@
// 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:
TraceJITEmitter (TraceJIT *JIT_) : TheJIT (JIT_) {
// Re-use the existing DummyFunction area for code emission in the
@@ -65,26 +71,19 @@
virtual void* finishFunctionStub(const Function *F) {
abort ();
}
- virtual void addRelocation(const MachineRelocation &) {
- assert(0 && "Relocations not supported!");
+ virtual void addRelocation(const MachineRelocation &MR) {
+ Relocations.push_back(MR);
}
virtual void emitByte(unsigned char B);
virtual void emitWord(unsigned W);
virtual void emitWordAt(unsigned W, unsigned *Ptr);
- virtual uint64_t getGlobalValueAddress(GlobalValue *V);
- virtual uint64_t getGlobalValueAddress(const char *Name);
- virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
virtual uint64_t getCurrentPCValue();
virtual uint64_t getCurrentPCOffset();
-
- // forceCompilationOf - Force the compilation of the specified function, and
- // return its address, because we REALLY need the address now.
- //
- // FIXME: This is JIT specific!
- //
- virtual uint64_t forceCompilationOf(Function *F);
+ virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
+ private:
+ void *getPointerToGlobal(GlobalValue *GV, uint64_t Reference, bool NoNeedStub);
};
} // end anonymous namespace
@@ -96,6 +95,22 @@
} // end namespace llvm
+void *TraceJITEmitter::getPointerToGlobal(GlobalValue *V, uint64_t Reference,
+ bool DoesntNeedStub) {
+ // Try looking up the function to see if it is already compiled, if not
+ // return 0.
+ if (isa<Function>(V)) {
+ if (V->hasExternalLinkage () && V->hasName ()) {
+ void *where = GetAddressOfSymbol (V->getName ());
+ if (where)
+ return where;
+ }
+ return TheJIT->getPointerToGlobalIfAvailable(V);
+ } else {
+ return TheJIT->getOrEmitGlobalVariable(cast<GlobalVariable>(V));
+ }
+}
+
void TraceJITEmitter::startFunction(MachineFunction &F) {
// Round up to a 64-bit word boundary.
CurBlock = (CurFunctionPtr + 7) & ~7;
@@ -108,12 +123,32 @@
void TraceJITEmitter::finishFunction(MachineFunction &F) {
assert(CurByte > CurFunctionPtr);
CurFunctionPtr = CurByte;
-
ConstantPoolAddresses.clear();
- DEBUG(std::cerr << "Finished CodeGen of [" << (void*)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.isString())
+ ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
+ else
+ ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
+ CurBlock+MR.getMachineCodeOffset(),
+ MR.doesntNeedFunctionStub());
+ MR.setResultPointer(ResultPtr);
+ }
+
+ TheJIT->getJITInfo().relocate((void*)CurBlock, &Relocations[0],
+ Relocations.size());
+ }
+
+ DEBUG(std::cerr << "JIT: 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 TraceJITEmitter::emitConstantPool(MachineConstantPool *MCP) {
@@ -176,25 +211,6 @@
(uint64_t) Ptr + sizeof (unsigned));
}
-uint64_t TraceJITEmitter::getGlobalValueAddress(GlobalValue *V) {
- // Try looking up the function to see if it is already compiled, if not return
- // 0.
- if (isa<Function>(V)) {
- if (V->hasExternalLinkage () && V->hasName ()) {
- uint64_t where = (uint64_t) GetAddressOfSymbol (V->getName ());
- if (where)
- return where;
- }
- return (uint64_t)TheJIT->getPointerToGlobalIfAvailable(V);
- } else {
- return (uint64_t)TheJIT->getOrEmitGlobalVariable(cast<GlobalVariable>(V));
- }
-}
-
-uint64_t TraceJITEmitter::getGlobalValueAddress(const char *Name) {
- return (uint64_t)TheJIT->getPointerToNamedFunction(Name);
-}
-
// getConstantPoolEntryAddress - Return the address of the 'ConstantNum' entry
// in the constant pool that was last emitted with the 'emitConstantPool'
// method.
@@ -215,7 +231,3 @@
uint64_t TraceJITEmitter::getCurrentPCOffset() {
return CurByte-CurFunctionPtr;
}
-
-uint64_t TraceJITEmitter::forceCompilationOf(Function *F) {
- return (uint64_t)TheJIT->getPointerToFunction(F);
-}
More information about the llvm-commits
mailing list