diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-04 04:47:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-04 04:47:41 +0000 |
commit | f4cc3096fd893cdef5b5c2664ebff8c13a07ad51 (patch) | |
tree | 3376e99ece7c0a3e4e776d878416daeef6b07e29 /lib/ExecutionEngine | |
parent | fc5423d561bb7624bf328e3ed554efce6e296cbc (diff) | |
download | external_llvm-f4cc3096fd893cdef5b5c2664ebff8c13a07ad51.zip external_llvm-f4cc3096fd893cdef5b5c2664ebff8c13a07ad51.tar.gz external_llvm-f4cc3096fd893cdef5b5c2664ebff8c13a07ad51.tar.bz2 |
Make ExecutionEngine::updateGlobalMapping return the old mapping.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49206 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 6c04e86..a56951d 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -109,18 +109,30 @@ void ExecutionEngine::clearAllGlobalMappings() { /// updateGlobalMapping - Replace an existing mapping for GV with a new /// address. This updates both maps as required. If "Addr" is null, the /// entry for the global is removed from the mappings. -void ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { +void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { MutexGuard locked(lock); - + + std::map<const GlobalValue*, void *> &Map = state.getGlobalAddressMap(locked); + // Deleting from the mapping? if (Addr == 0) { - state.getGlobalAddressMap(locked).erase(GV); + std::map<const GlobalValue*, void *>::iterator I = Map.find(GV); + void *OldVal; + if (I == Map.end()) + OldVal = 0; + else { + OldVal = I->second; + Map.erase(I); + } + if (!state.getGlobalAddressReverseMap(locked).empty()) state.getGlobalAddressReverseMap(locked).erase(Addr); - return; + return OldVal; } - void *&CurVal = state.getGlobalAddressMap(locked)[GV]; + void *&CurVal = Map[GV]; + void *OldVal = CurVal; + if (CurVal && !state.getGlobalAddressReverseMap(locked).empty()) state.getGlobalAddressReverseMap(locked).erase(CurVal); CurVal = Addr; @@ -131,6 +143,7 @@ void ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { assert((V == 0 || GV == 0) && "GlobalMapping already established!"); V = GV; } + return OldVal; } /// getPointerToGlobalIfAvailable - This returns the address of the specified |