Move methods out of line so that MutexGuard.h isn't required in the header.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28178 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-05-08 22:00:26 +00:00
parent 9fd868ae0a
commit 683d1bb712

View File

@ -19,7 +19,7 @@
#include <map> #include <map>
#include <cassert> #include <cassert>
#include <string> #include <string>
#include "llvm/Support/MutexGuard.h" #include "llvm/System/Mutex.h"
namespace llvm { namespace llvm {
@ -32,6 +32,7 @@ class Module;
class ModuleProvider; class ModuleProvider;
class TargetData; class TargetData;
class Type; class Type;
class MutexGuard;
class ExecutionEngineState { class ExecutionEngineState {
private: private:
@ -114,58 +115,27 @@ public:
const char * const * envp); const char * const * envp);
void addGlobalMapping(const GlobalValue *GV, void *Addr) { /// addGlobalMapping - Tell the execution engine that the specified global is
MutexGuard locked(lock); /// at the specified location. This is used internally as functions are JIT'd
/// and as global variables are laid out in memory. It can and should also be
void *&CurVal = state.getGlobalAddressMap(locked)[GV]; /// used by clients of the EE that want to have an LLVM global overlay
assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!"); /// existing data in memory.
CurVal = Addr; void addGlobalMapping(const GlobalValue *GV, void *Addr);
// If we are using the reverse mapping, add it too
if (!state.getGlobalAddressReverseMap(locked).empty()) {
const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
assert((V == 0 || GV == 0) && "GlobalMapping already established!");
V = GV;
}
}
/// clearAllGlobalMappings - Clear all global mappings and start over again /// clearAllGlobalMappings - Clear all global mappings and start over again
/// use in dynamic compilation scenarios when you want to move globals /// use in dynamic compilation scenarios when you want to move globals
void clearAllGlobalMappings() { void clearAllGlobalMappings();
MutexGuard locked(lock);
state.getGlobalAddressMap(locked).clear();
state.getGlobalAddressReverseMap(locked).clear();
}
/// updateGlobalMapping - Replace an existing mapping for GV with a new /// updateGlobalMapping - Replace an existing mapping for GV with a new
/// address. This updates both maps as required. /// address. This updates both maps as required. If "Addr" is null, the
void updateGlobalMapping(const GlobalValue *GV, void *Addr) { /// entry for the global is removed from the mappings.
MutexGuard locked(lock); void updateGlobalMapping(const GlobalValue *GV, void *Addr);
void *&CurVal = state.getGlobalAddressMap(locked)[GV];
if (CurVal && !state.getGlobalAddressReverseMap(locked).empty())
state.getGlobalAddressReverseMap(locked).erase(CurVal);
CurVal = Addr;
// If we are using the reverse mapping, add it too
if (!state.getGlobalAddressReverseMap(locked).empty()) {
const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
assert((V == 0 || GV == 0) && "GlobalMapping already established!");
V = GV;
}
}
/// getPointerToGlobalIfAvailable - This returns the address of the specified /// getPointerToGlobalIfAvailable - This returns the address of the specified
/// global value if it is available, otherwise it returns null. /// global value if it is has already been codegen'd, otherwise it returns
/// null.
/// ///
void *getPointerToGlobalIfAvailable(const GlobalValue *GV) { void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
MutexGuard locked(lock);
std::map<const GlobalValue*, void*>::iterator I =
state.getGlobalAddressMap(locked).find(GV);
return I != state.getGlobalAddressMap(locked).end() ? I->second : 0;
}
/// getPointerToGlobal - This returns the address of the specified global /// getPointerToGlobal - This returns the address of the specified global
/// value. This may involve code generation if it's a function. /// value. This may involve code generation if it's a function.