[llvm-commits] [llvm] r49206 - in /llvm/trunk: include/llvm/ExecutionEngine/ExecutionEngine.h lib/ExecutionEngine/ExecutionEngine.cpp

Chris Lattner sabre at nondot.org
Thu Apr 3 21:47:41 PDT 2008


Author: lattner
Date: Thu Apr  3 23:47:41 2008
New Revision: 49206

URL: http://llvm.org/viewvc/llvm-project?rev=49206&view=rev
Log:
Make ExecutionEngine::updateGlobalMapping return the old mapping.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
    llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=49206&r1=49205&r2=49206&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Thu Apr  3 23:47:41 2008
@@ -96,9 +96,9 @@
   /// any of those classes.
   sys::Mutex lock; // Used to make this class and subclasses thread-safe
 
-  //===----------------------------------------------------------------------===//
+  //===--------------------------------------------------------------------===//
   //  ExecutionEngine Startup
-  //===----------------------------------------------------------------------===//
+  //===--------------------------------------------------------------------===//
 
   virtual ~ExecutionEngine();
 
@@ -176,8 +176,9 @@
   
   /// 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 updateGlobalMapping(const GlobalValue *GV, void *Addr);
+  /// entry for the global is removed from the mappings.  This returns the old
+  /// value of the pointer, or null if it was not in the map.
+  void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
   
   /// getPointerToGlobalIfAvailable - This returns the address of the specified
   /// global value if it is has already been codegen'd, otherwise it returns
@@ -211,7 +212,8 @@
   const GlobalValue *getGlobalValueAtAddress(void *Addr);
 
 
-  void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, const Type *Ty);
+  void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
+                          const Type *Ty);
   void InitializeMemory(const Constant *Init, void *Addr);
 
   /// recompileAndRelinkFunction - This method is used to force a function

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=49206&r1=49205&r2=49206&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Thu Apr  3 23:47:41 2008
@@ -109,18 +109,30 @@
 /// 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 @@
     assert((V == 0 || GV == 0) && "GlobalMapping already established!");
     V = GV;
   }
+  return OldVal;
 }
 
 /// getPointerToGlobalIfAvailable - This returns the address of the specified





More information about the llvm-commits mailing list