llvm.org GIT mirror llvm / 683d1bb
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 Chris Lattner 14 years ago
1 changed file(s) with 19 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
1818 #include
1919 #include
2020 #include
21 #include "llvm/Support/MutexGuard.h"
21 #include "llvm/System/Mutex.h"
2222
2323 namespace llvm {
2424
3131 class ModuleProvider;
3232 class TargetData;
3333 class Type;
34 class MutexGuard;
3435
3536 class ExecutionEngineState {
3637 private:
113114 const char * const * envp);
114115
115116
116 void addGlobalMapping(const GlobalValue *GV, void *Addr) {
117 MutexGuard locked(lock);
118
119 void *&CurVal = state.getGlobalAddressMap(locked)[GV];
120 assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
121 CurVal = Addr;
122
123 // If we are using the reverse mapping, add it too
124 if (!state.getGlobalAddressReverseMap(locked).empty()) {
125 const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
126 assert((V == 0 || GV == 0) && "GlobalMapping already established!");
127 V = GV;
128 }
129 }
130
117 /// addGlobalMapping - Tell the execution engine that the specified global is
118 /// at the specified location. This is used internally as functions are JIT'd
119 /// and as global variables are laid out in memory. It can and should also be
120 /// used by clients of the EE that want to have an LLVM global overlay
121 /// existing data in memory.
122 void addGlobalMapping(const GlobalValue *GV, void *Addr);
123
131124 /// clearAllGlobalMappings - Clear all global mappings and start over again
132125 /// use in dynamic compilation scenarios when you want to move globals
133 void clearAllGlobalMappings() {
134 MutexGuard locked(lock);
135
136 state.getGlobalAddressMap(locked).clear();
137 state.getGlobalAddressReverseMap(locked).clear();
138 }
139
126 void clearAllGlobalMappings();
127
140128 /// updateGlobalMapping - Replace an existing mapping for GV with a new
141 /// address. This updates both maps as required.
142 void updateGlobalMapping(const GlobalValue *GV, void *Addr) {
143 MutexGuard locked(lock);
144
145 void *&CurVal = state.getGlobalAddressMap(locked)[GV];
146 if (CurVal && !state.getGlobalAddressReverseMap(locked).empty())
147 state.getGlobalAddressReverseMap(locked).erase(CurVal);
148 CurVal = Addr;
149
150 // If we are using the reverse mapping, add it too
151 if (!state.getGlobalAddressReverseMap(locked).empty()) {
152 const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
153 assert((V == 0 || GV == 0) && "GlobalMapping already established!");
154 V = GV;
155 }
156 }
157
129 /// address. This updates both maps as required. If "Addr" is null, the
130 /// entry for the global is removed from the mappings.
131 void updateGlobalMapping(const GlobalValue *GV, void *Addr);
132
158133 /// getPointerToGlobalIfAvailable - This returns the address of the specified
159 /// global value if it is available, otherwise it returns null.
160 ///
161 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
162 MutexGuard locked(lock);
163
164 std::map::iterator I =
165 state.getGlobalAddressMap(locked).find(GV);
166 return I != state.getGlobalAddressMap(locked).end() ? I->second : 0;
167 }
134 /// global value if it is has already been codegen'd, otherwise it returns
135 /// null.
136 ///
137 void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
168138
169139 /// getPointerToGlobal - This returns the address of the specified global
170140 /// value. This may involve code generation if it's a function.