Changes in directory llvm/lib/ExecutionEngine/JIT:
JITEmitter.cpp updated: 1.121 -> 1.122 --- Log message: 1. Tidy up jump table info. 2. Allow the jit to handle PIC relocable jump tables. --- Diffs of the changes: (+36 -17) JITEmitter.cpp | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 36 insertions(+), 17 deletions(-) Index: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp diff -u llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.121 llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.122 --- llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.121 Thu Dec 7 14:04:42 2006 +++ llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp Thu Dec 14 13:17:33 2006 @@ -25,6 +25,7 @@ #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetJITInfo.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MutexGuard.h" #include "llvm/ADT/Statistic.h" @@ -700,7 +701,7 @@ void emitConstantPool(MachineConstantPool *MCP); void initJumpTableInfo(MachineJumpTableInfo *MJTI); - void emitJumpTableInfo(MachineJumpTableInfo *MJTI); + void emitJumpTableInfo(MachineJumpTableInfo *MJTI, Reloc::Model RM); virtual void startFunctionStub(unsigned StubSize, unsigned Alignment = 1); virtual void* finishFunctionStub(const Function *F); @@ -791,7 +792,7 @@ abort(); } - emitJumpTableInfo(F.getJumpTableInfo()); + emitJumpTableInfo(F.getJumpTableInfo(), F.getTarget().getRelocationModel()); // FnStart is the start of the text, not the start of the constant pool and // other per-function data. @@ -821,7 +822,7 @@ MR.doesntNeedFunctionStub()); } else if (MR.isBasicBlock()) { ResultPtr = (void*)getMachineBasicBlockAddress(MR.getBasicBlock()); - } else if (MR.isConstantPoolIndex()){ + } else if (MR.isConstantPoolIndex()) { ResultPtr=(void*)getConstantPoolEntryAddress(MR.getConstantPoolIndex()); } else { assert(MR.isJumpTableIndex()); @@ -914,22 +915,38 @@ JumpTableBase = allocateSpace(NumEntries * EntrySize, MJTI->getAlignment()); } -void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI) { +void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI, Reloc::Model RM){ const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); if (JT.empty() || JumpTableBase == 0) return; - - assert(MJTI->getEntrySize() == sizeof(void*) && "Cross JIT'ing?"); - // For each jump table, map each target in the jump table to the address of - // an emitted MachineBasicBlock. - intptr_t *SlotPtr = (intptr_t*)JumpTableBase; - - for (unsigned i = 0, e = JT.size(); i != e; ++i) { - const std::vector<MachineBasicBlock*> &MBBs = JT[i].MBBs; - // Store the address of the basic block for this jump table slot in the - // memory we allocated for the jump table in 'initJumpTableInfo' - for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) - *SlotPtr++ = getMachineBasicBlockAddress(MBBs[mi]); + if (RM == Reloc::PIC_) { + assert(MJTI->getEntrySize() == 4 && "Cross JIT'ing?"); + // For each jump table, place the offset from the beginning of the table + // to the target address. + int *SlotPtr = (int*)JumpTableBase; + + for (unsigned i = 0, e = JT.size(); i != e; ++i) { + const std::vector<MachineBasicBlock*> &MBBs = JT[i].MBBs; + // Store the offset of the basic block for this jump table slot in the + // memory we allocated for the jump table in 'initJumpTableInfo' + intptr_t Base = (intptr_t)SlotPtr; + for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) + *SlotPtr++ = (intptr_t)getMachineBasicBlockAddress(MBBs[mi]) - Base; + } + } else { + assert(MJTI->getEntrySize() == sizeof(void*) && "Cross JIT'ing?"); + + // For each jump table, map each target in the jump table to the address of + // an emitted MachineBasicBlock. + intptr_t *SlotPtr = (intptr_t*)JumpTableBase; + + for (unsigned i = 0, e = JT.size(); i != e; ++i) { + const std::vector<MachineBasicBlock*> &MBBs = JT[i].MBBs; + // Store the address of the basic block for this jump table slot in the + // memory we allocated for the jump table in 'initJumpTableInfo' + for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) + *SlotPtr++ = getMachineBasicBlockAddress(MBBs[mi]); + } } } @@ -972,7 +989,9 @@ unsigned EntrySize = JumpTable->getEntrySize(); for (unsigned i = 0; i < Index; ++i) - Offset += JT[i].MBBs.size() * EntrySize; + Offset += JT[i].MBBs.size(); + + Offset *= EntrySize; return (intptr_t)((char *)JumpTableBase + Offset); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits