diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-07-11 23:07:28 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-07-11 23:07:28 +0000 |
| commit | b6df00c29a9b4f456487280390f29640c2ef5974 (patch) | |
| tree | 6991de27d87be3bdba0a5b747daef7f3c0fdbeb8 /llvm/lib/ExecutionEngine/JIT/JIT.cpp | |
| parent | ef74e2b2a8f34c731c287df3c47a21a6ca2d5796 (diff) | |
| download | bcm5719-llvm-b6df00c29a9b4f456487280390f29640c2ef5974.tar.gz bcm5719-llvm-b6df00c29a9b4f456487280390f29640c2ef5974.zip | |
first part of JIT support for address of labels, part of PR7264,
patch by Yuri!
llvm-svn: 108107
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JIT.cpp')
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index 546d2b21be9..67bd3ed10ad 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -626,10 +626,7 @@ void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) { void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) { assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!"); - // JIT the function - isAlreadyCodeGenerating = true; - jitstate->getPM(locked).run(*F); - isAlreadyCodeGenerating = false; + jitTheFunction(F, locked); // If the function referred to another function that had not yet been // read from bitcode, and we are jitting non-lazily, emit it now. @@ -640,10 +637,7 @@ void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) { assert(!PF->hasAvailableExternallyLinkage() && "Externally-defined function should not be in pending list."); - // JIT the function - isAlreadyCodeGenerating = true; - jitstate->getPM(locked).run(*PF); - isAlreadyCodeGenerating = false; + jitTheFunction(PF, locked); // Now that the function has been jitted, ask the JITEmitter to rewrite // the stub with real address of the function. @@ -651,6 +645,15 @@ void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) { } } +void JIT::jitTheFunction(Function *F, const MutexGuard &locked) { + isAlreadyCodeGenerating = true; + jitstate->getPM(locked).run(*F); + isAlreadyCodeGenerating = false; + + // clear basic block addresses after this function is done + getBasicBlockAddressMap(locked).clear(); +} + /// getPointerToFunction - This method is used to get the address of the /// specified function, compiling it if neccesary. /// @@ -687,6 +690,41 @@ void *JIT::getPointerToFunction(Function *F) { return Addr; } +void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) { + MutexGuard locked(lock); + + BasicBlockAddressMapTy::iterator I = + getBasicBlockAddressMap(locked).find(BB); + if (I == getBasicBlockAddressMap(locked).end()) { + getBasicBlockAddressMap(locked)[BB] = Addr; + } else { + // ignore repeats: some BBs can be split into few MBBs? + } +} + +void JIT::clearPointerToBasicBlock(const BasicBlock *BB) { + MutexGuard locked(lock); + getBasicBlockAddressMap(locked).erase(BB); +} + +void *JIT::getPointerToBasicBlock(BasicBlock *BB) { + // make sure it's function is compiled by JIT + (void)getPointerToFunction(BB->getParent()); + + // resolve basic block address + MutexGuard locked(lock); + + BasicBlockAddressMapTy::iterator I = + getBasicBlockAddressMap(locked).find(BB); + if (I != getBasicBlockAddressMap(locked).end()) { + return I->second; + } else { + assert(0 && "JIT does not have BB address for address-of-label, was" + " it eliminated by optimizer?"); + return 0; + } +} + /// getOrEmitGlobalVariable - Return the address of the specified global /// variable, possibly emitting it to memory if needed. This is used by the /// Emitter. |

