llvm.org GIT mirror llvm / f4cc309
Make ExecutionEngine::updateGlobalMapping return the old mapping. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49206 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
2 changed file(s) with 25 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
9595 /// any of those classes.
9696 sys::Mutex lock; // Used to make this class and subclasses thread-safe
9797
98 //===----------------------------------------------------------------------===//
98 //===--------------------------------------------------------------------===//
9999 // ExecutionEngine Startup
100 //===----------------------------------------------------------------------===//
100 //===--------------------------------------------------------------------===//
101101
102102 virtual ~ExecutionEngine();
103103
175175
176176 /// updateGlobalMapping - Replace an existing mapping for GV with a new
177177 /// address. This updates both maps as required. If "Addr" is null, the
178 /// entry for the global is removed from the mappings.
179 void updateGlobalMapping(const GlobalValue *GV, void *Addr);
178 /// entry for the global is removed from the mappings. This returns the old
179 /// value of the pointer, or null if it was not in the map.
180 void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
180181
181182 /// getPointerToGlobalIfAvailable - This returns the address of the specified
182183 /// global value if it is has already been codegen'd, otherwise it returns
210211 const GlobalValue *getGlobalValueAtAddress(void *Addr);
211212
212213
213 void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, const Type *Ty);
214 void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
215 const Type *Ty);
214216 void InitializeMemory(const Constant *Init, void *Addr);
215217
216218 /// recompileAndRelinkFunction - This method is used to force a function
108108 /// updateGlobalMapping - Replace an existing mapping for GV with a new
109109 /// address. This updates both maps as required. If "Addr" is null, the
110110 /// entry for the global is removed from the mappings.
111 void ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
111 void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
112112 MutexGuard locked(lock);
113
113
114 std::map &Map = state.getGlobalAddressMap(locked);
115
114116 // Deleting from the mapping?
115117 if (Addr == 0) {
116 state.getGlobalAddressMap(locked).erase(GV);
118 std::map::iterator I = Map.find(GV);
119 void *OldVal;
120 if (I == Map.end())
121 OldVal = 0;
122 else {
123 OldVal = I->second;
124 Map.erase(I);
125 }
126
117127 if (!state.getGlobalAddressReverseMap(locked).empty())
118128 state.getGlobalAddressReverseMap(locked).erase(Addr);
119 return;
129 return OldVal;
120130 }
121131
122 void *&CurVal = state.getGlobalAddressMap(locked)[GV];
132 void *&CurVal = Map[GV];
133 void *OldVal = CurVal;
134
123135 if (CurVal && !state.getGlobalAddressReverseMap(locked).empty())
124136 state.getGlobalAddressReverseMap(locked).erase(CurVal);
125137 CurVal = Addr;
130142 assert((V == 0 || GV == 0) && "GlobalMapping already established!");
131143 V = GV;
132144 }
145 return OldVal;
133146 }
134147
135148 /// getPointerToGlobalIfAvailable - This returns the address of the specified