ExecutionEngine: refactor interface
[oota-llvm.git] / lib / ExecutionEngine / ExecutionEngine.cpp
1 //===-- ExecutionEngine.cpp - Common Implementation shared by EEs ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the common interface used by the various execution engine
11 // subclasses.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "jit"
16 #include "llvm/ExecutionEngine/ExecutionEngine.h"
17
18 #include "llvm/Constants.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/Module.h"
21 #include "llvm/ExecutionEngine/GenericValue.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/Statistic.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/MutexGuard.h"
27 #include "llvm/Support/ValueHandle.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/Support/DynamicLibrary.h"
30 #include "llvm/Support/Host.h"
31 #include "llvm/Support/TargetRegistry.h"
32 #include "llvm/Target/TargetData.h"
33 #include "llvm/Target/TargetMachine.h"
34 #include <cmath>
35 #include <cstring>
36 using namespace llvm;
37
38 STATISTIC(NumInitBytes, "Number of bytes of global vars initialized");
39 STATISTIC(NumGlobals  , "Number of global vars initialized");
40
41 ExecutionEngine *(*ExecutionEngine::JITCtor)(
42   Module *M,
43   std::string *ErrorStr,
44   JITMemoryManager *JMM,
45   bool GVsWithCode,
46   TargetMachine *TM) = 0;
47 ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
48   Module *M,
49   std::string *ErrorStr,
50   JITMemoryManager *JMM,
51   bool GVsWithCode,
52   TargetMachine *TM) = 0;
53 ExecutionEngine *(*ExecutionEngine::InterpCtor)(Module *M,
54                                                 std::string *ErrorStr) = 0;
55
56 ExecutionEngine::ExecutionEngine(Module *M)
57   : EEState(*this),
58     LazyFunctionCreator(0),
59     ExceptionTableRegister(0),
60     ExceptionTableDeregister(0) {
61   CompilingLazily         = false;
62   GVCompilationDisabled   = false;
63   SymbolSearchingDisabled = false;
64   Modules.push_back(M);
65   assert(M && "Module is null?");
66 }
67
68 ExecutionEngine::~ExecutionEngine() {
69   clearAllGlobalMappings();
70   for (unsigned i = 0, e = Modules.size(); i != e; ++i)
71     delete Modules[i];
72 }
73
74 void ExecutionEngine::DeregisterAllTables() {
75   if (ExceptionTableDeregister) {
76     DenseMap<const Function*, void*>::iterator it = AllExceptionTables.begin();
77     DenseMap<const Function*, void*>::iterator ite = AllExceptionTables.end();
78     for (; it != ite; ++it)
79       ExceptionTableDeregister(it->second);
80     AllExceptionTables.clear();
81   }
82 }
83
84 namespace {
85 /// \brief Helper class which uses a value handler to automatically deletes the
86 /// memory block when the GlobalVariable is destroyed.
87 class GVMemoryBlock : public CallbackVH {
88   GVMemoryBlock(const GlobalVariable *GV)
89     : CallbackVH(const_cast<GlobalVariable*>(GV)) {}
90
91 public:
92   /// \brief Returns the address the GlobalVariable should be written into.  The
93   /// GVMemoryBlock object prefixes that.
94   static char *Create(const GlobalVariable *GV, const TargetData& TD) {
95     Type *ElTy = GV->getType()->getElementType();
96     size_t GVSize = (size_t)TD.getTypeAllocSize(ElTy);
97     void *RawMemory = ::operator new(
98       TargetData::RoundUpAlignment(sizeof(GVMemoryBlock),
99                                    TD.getPreferredAlignment(GV))
100       + GVSize);
101     new(RawMemory) GVMemoryBlock(GV);
102     return static_cast<char*>(RawMemory) + sizeof(GVMemoryBlock);
103   }
104
105   virtual void deleted() {
106     // We allocated with operator new and with some extra memory hanging off the
107     // end, so don't just delete this.  I'm not sure if this is actually
108     // required.
109     this->~GVMemoryBlock();
110     ::operator delete(this);
111   }
112 };
113 }  // anonymous namespace
114
115 char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
116   return GVMemoryBlock::Create(GV, *getTargetData());
117 }
118
119 bool ExecutionEngine::removeModule(Module *M) {
120   for(SmallVector<Module *, 1>::iterator I = Modules.begin(),
121         E = Modules.end(); I != E; ++I) {
122     Module *Found = *I;
123     if (Found == M) {
124       Modules.erase(I);
125       clearGlobalMappingsFromModule(M);
126       return true;
127     }
128   }
129   return false;
130 }
131
132 Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
133   for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
134     if (Function *F = Modules[i]->getFunction(FnName))
135       return F;
136   }
137   return 0;
138 }
139
140
141 void *ExecutionEngineState::RemoveMapping(const MutexGuard &,
142                                           const GlobalValue *ToUnmap) {
143   GlobalAddressMapTy::iterator I = GlobalAddressMap.find(ToUnmap);
144   void *OldVal;
145
146   // FIXME: This is silly, we shouldn't end up with a mapping -> 0 in the
147   // GlobalAddressMap.
148   if (I == GlobalAddressMap.end())
149     OldVal = 0;
150   else {
151     OldVal = I->second;
152     GlobalAddressMap.erase(I);
153   }
154
155   GlobalAddressReverseMap.erase(OldVal);
156   return OldVal;
157 }
158
159 void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
160   MutexGuard locked(lock);
161
162   DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
163         << "\' to [" << Addr << "]\n";);
164   void *&CurVal = EEState.getGlobalAddressMap(locked)[GV];
165   assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
166   CurVal = Addr;
167
168   // If we are using the reverse mapping, add it too.
169   if (!EEState.getGlobalAddressReverseMap(locked).empty()) {
170     AssertingVH<const GlobalValue> &V =
171       EEState.getGlobalAddressReverseMap(locked)[Addr];
172     assert((V == 0 || GV == 0) && "GlobalMapping already established!");
173     V = GV;
174   }
175 }
176
177 void ExecutionEngine::clearAllGlobalMappings() {
178   MutexGuard locked(lock);
179
180   EEState.getGlobalAddressMap(locked).clear();
181   EEState.getGlobalAddressReverseMap(locked).clear();
182 }
183
184 void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
185   MutexGuard locked(lock);
186
187   for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
188     EEState.RemoveMapping(locked, FI);
189   for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
190        GI != GE; ++GI)
191     EEState.RemoveMapping(locked, GI);
192 }
193
194 void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
195   MutexGuard locked(lock);
196
197   ExecutionEngineState::GlobalAddressMapTy &Map =
198     EEState.getGlobalAddressMap(locked);
199
200   // Deleting from the mapping?
201   if (Addr == 0)
202     return EEState.RemoveMapping(locked, GV);
203
204   void *&CurVal = Map[GV];
205   void *OldVal = CurVal;
206
207   if (CurVal && !EEState.getGlobalAddressReverseMap(locked).empty())
208     EEState.getGlobalAddressReverseMap(locked).erase(CurVal);
209   CurVal = Addr;
210
211   // If we are using the reverse mapping, add it too.
212   if (!EEState.getGlobalAddressReverseMap(locked).empty()) {
213     AssertingVH<const GlobalValue> &V =
214       EEState.getGlobalAddressReverseMap(locked)[Addr];
215     assert((V == 0 || GV == 0) && "GlobalMapping already established!");
216     V = GV;
217   }
218   return OldVal;
219 }
220
221 void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
222   MutexGuard locked(lock);
223
224   ExecutionEngineState::GlobalAddressMapTy::iterator I =
225     EEState.getGlobalAddressMap(locked).find(GV);
226   return I != EEState.getGlobalAddressMap(locked).end() ? I->second : 0;
227 }
228
229 const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
230   MutexGuard locked(lock);
231
232   // If we haven't computed the reverse mapping yet, do so first.
233   if (EEState.getGlobalAddressReverseMap(locked).empty()) {
234     for (ExecutionEngineState::GlobalAddressMapTy::iterator
235          I = EEState.getGlobalAddressMap(locked).begin(),
236          E = EEState.getGlobalAddressMap(locked).end(); I != E; ++I)
237       EEState.getGlobalAddressReverseMap(locked).insert(std::make_pair(
238                                                           I->second, I->first));
239   }
240
241   std::map<void *, AssertingVH<const GlobalValue> >::iterator I =
242     EEState.getGlobalAddressReverseMap(locked).find(Addr);
243   return I != EEState.getGlobalAddressReverseMap(locked).end() ? I->second : 0;
244 }
245
246 namespace {
247 class ArgvArray {
248   char *Array;
249   std::vector<char*> Values;
250 public:
251   ArgvArray() : Array(NULL) {}
252   ~ArgvArray() { clear(); }
253   void clear() {
254     delete[] Array;
255     Array = NULL;
256     for (size_t I = 0, E = Values.size(); I != E; ++I) {
257       delete[] Values[I];
258     }
259     Values.clear();
260   }
261   /// Turn a vector of strings into a nice argv style array of pointers to null
262   /// terminated strings.
263   void *reset(LLVMContext &C, ExecutionEngine *EE,
264               const std::vector<std::string> &InputArgv);
265 };
266 }  // anonymous namespace
267 void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
268                        const std::vector<std::string> &InputArgv) {
269   clear();  // Free the old contents.
270   unsigned PtrSize = EE->getTargetData()->getPointerSize();
271   Array = new char[(InputArgv.size()+1)*PtrSize];
272
273   DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array << "\n");
274   Type *SBytePtr = Type::getInt8PtrTy(C);
275
276   for (unsigned i = 0; i != InputArgv.size(); ++i) {
277     unsigned Size = InputArgv[i].size()+1;
278     char *Dest = new char[Size];
279     Values.push_back(Dest);
280     DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest << "\n");
281
282     std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
283     Dest[Size-1] = 0;
284
285     // Endian safe: Array[i] = (PointerTy)Dest;
286     EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Array+i*PtrSize),
287                            SBytePtr);
288   }
289
290   // Null terminate it
291   EE->StoreValueToMemory(PTOGV(0),
292                          (GenericValue*)(Array+InputArgv.size()*PtrSize),
293                          SBytePtr);
294   return Array;
295 }
296
297 void ExecutionEngine::runStaticConstructorsDestructors(Module *module,
298                                                        bool isDtors) {
299   const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
300   GlobalVariable *GV = module->getNamedGlobal(Name);
301
302   // If this global has internal linkage, or if it has a use, then it must be
303   // an old-style (llvmgcc3) static ctor with __main linked in and in use.  If
304   // this is the case, don't execute any of the global ctors, __main will do
305   // it.
306   if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
307
308   // Should be an array of '{ i32, void ()* }' structs.  The first value is
309   // the init priority, which we ignore.
310   if (isa<ConstantAggregateZero>(GV->getInitializer()))
311     return;
312   ConstantArray *InitList = cast<ConstantArray>(GV->getInitializer());
313   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
314     if (isa<ConstantAggregateZero>(InitList->getOperand(i)))
315       continue;
316     ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(i));
317
318     Constant *FP = CS->getOperand(1);
319     if (FP->isNullValue())
320       continue;  // Found a sentinal value, ignore.
321
322     // Strip off constant expression casts.
323     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
324       if (CE->isCast())
325         FP = CE->getOperand(0);
326
327     // Execute the ctor/dtor function!
328     if (Function *F = dyn_cast<Function>(FP))
329       runFunction(F, std::vector<GenericValue>());
330
331     // FIXME: It is marginally lame that we just do nothing here if we see an
332     // entry we don't recognize. It might not be unreasonable for the verifier
333     // to not even allow this and just assert here.
334   }
335 }
336
337 void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
338   // Execute global ctors/dtors for each module in the program.
339   for (unsigned i = 0, e = Modules.size(); i != e; ++i)
340     runStaticConstructorsDestructors(Modules[i], isDtors);
341 }
342
343 #ifndef NDEBUG
344 /// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
345 static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
346   unsigned PtrSize = EE->getTargetData()->getPointerSize();
347   for (unsigned i = 0; i < PtrSize; ++i)
348     if (*(i + (uint8_t*)Loc))
349       return false;
350   return true;
351 }
352 #endif
353
354 int ExecutionEngine::runFunctionAsMain(Function *Fn,
355                                        const std::vector<std::string> &argv,
356                                        const char * const * envp) {
357   std::vector<GenericValue> GVArgs;
358   GenericValue GVArgc;
359   GVArgc.IntVal = APInt(32, argv.size());
360
361   // Check main() type
362   unsigned NumArgs = Fn->getFunctionType()->getNumParams();
363   FunctionType *FTy = Fn->getFunctionType();
364   Type* PPInt8Ty = Type::getInt8PtrTy(Fn->getContext())->getPointerTo();
365
366   // Check the argument types.
367   if (NumArgs > 3)
368     report_fatal_error("Invalid number of arguments of main() supplied");
369   if (NumArgs >= 3 && FTy->getParamType(2) != PPInt8Ty)
370     report_fatal_error("Invalid type for third argument of main() supplied");
371   if (NumArgs >= 2 && FTy->getParamType(1) != PPInt8Ty)
372     report_fatal_error("Invalid type for second argument of main() supplied");
373   if (NumArgs >= 1 && !FTy->getParamType(0)->isIntegerTy(32))
374     report_fatal_error("Invalid type for first argument of main() supplied");
375   if (!FTy->getReturnType()->isIntegerTy() &&
376       !FTy->getReturnType()->isVoidTy())
377     report_fatal_error("Invalid return type of main() supplied");
378
379   ArgvArray CArgv;
380   ArgvArray CEnv;
381   if (NumArgs) {
382     GVArgs.push_back(GVArgc); // Arg #0 = argc.
383     if (NumArgs > 1) {
384       // Arg #1 = argv.
385       GVArgs.push_back(PTOGV(CArgv.reset(Fn->getContext(), this, argv)));
386       assert(!isTargetNullPtr(this, GVTOP(GVArgs[1])) &&
387              "argv[0] was null after CreateArgv");
388       if (NumArgs > 2) {
389         std::vector<std::string> EnvVars;
390         for (unsigned i = 0; envp[i]; ++i)
391           EnvVars.push_back(envp[i]);
392         // Arg #2 = envp.
393         GVArgs.push_back(PTOGV(CEnv.reset(Fn->getContext(), this, EnvVars)));
394       }
395     }
396   }
397
398   return runFunction(Fn, GVArgs).IntVal.getZExtValue();
399 }
400
401 ExecutionEngine *ExecutionEngine::create(Module *M,
402                                          bool ForceInterpreter,
403                                          std::string *ErrorStr,
404                                          CodeGenOpt::Level OptLevel,
405                                          bool GVsWithCode) {
406   return EngineBuilder(M)
407       .setEngineKind(ForceInterpreter
408                      ? EngineKind::Interpreter
409                      : EngineKind::JIT)
410       .setErrorStr(ErrorStr)
411       .setOptLevel(OptLevel)
412       .setAllocateGVsWithCode(GVsWithCode)
413       .create();
414 }
415
416 /// createJIT - This is the factory method for creating a JIT for the current
417 /// machine, it does not fall back to the interpreter.  This takes ownership
418 /// of the module.
419 ExecutionEngine *ExecutionEngine::createJIT(Module *M,
420                                             std::string *ErrorStr,
421                                             JITMemoryManager *JMM,
422                                             CodeGenOpt::Level OL,
423                                             bool GVsWithCode,
424                                             Reloc::Model RM,
425                                             CodeModel::Model CMM) {
426   if (ExecutionEngine::JITCtor == 0) {
427     if (ErrorStr)
428       *ErrorStr = "JIT has not been linked in.";
429     return 0;
430   }
431
432   // Use the defaults for extra parameters.  Users can use EngineBuilder to
433   // set them.
434   StringRef MArch = "";
435   StringRef MCPU = "";
436   SmallVector<std::string, 1> MAttrs;
437
438   Triple TT(M->getTargetTriple());
439   // TODO: permit custom TargetOptions here
440   TargetMachine *TM =
441     EngineBuilder::selectTarget(TT, MArch, MCPU, MAttrs, TargetOptions(), RM,
442                                 CMM, OL, ErrorStr);
443   if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
444
445   return ExecutionEngine::JITCtor(M, ErrorStr, JMM, GVsWithCode, TM);
446 }
447
448 ExecutionEngine *EngineBuilder::create() {
449   // Make sure we can resolve symbols in the program as well. The zero arg
450   // to the function tells DynamicLibrary to load the program, not a library.
451   if (sys::DynamicLibrary::LoadLibraryPermanently(0, ErrorStr))
452     return 0;
453
454   // If the user specified a memory manager but didn't specify which engine to
455   // create, we assume they only want the JIT, and we fail if they only want
456   // the interpreter.
457   if (JMM) {
458     if (WhichEngine & EngineKind::JIT)
459       WhichEngine = EngineKind::JIT;
460     else {
461       if (ErrorStr)
462         *ErrorStr = "Cannot create an interpreter with a memory manager.";
463       return 0;
464     }
465   }
466
467   // Unless the interpreter was explicitly selected or the JIT is not linked,
468   // try making a JIT.
469   if (WhichEngine & EngineKind::JIT) {
470     Triple TT(M->getTargetTriple());
471     if (TargetMachine *TM = EngineBuilder::selectTarget(TT, MArch, MCPU, MAttrs,
472                                                         Options,
473                                                         RelocModel, CMModel,
474                                                         OptLevel, ErrorStr)) {
475       if (!TM->getTarget().hasJIT()) {
476         errs() << "WARNING: This target JIT is not designed for the host"
477                << " you are running.  If bad things happen, please choose"
478                << " a different -march switch.\n";
479       }
480
481       if (UseMCJIT && ExecutionEngine::MCJITCtor) {
482         ExecutionEngine *EE =
483           ExecutionEngine::MCJITCtor(M, ErrorStr, JMM,
484                                      AllocateGVsWithCode, TM);
485         if (EE) return EE;
486       } else if (ExecutionEngine::JITCtor) {
487         ExecutionEngine *EE =
488           ExecutionEngine::JITCtor(M, ErrorStr, JMM,
489                                    AllocateGVsWithCode, TM);
490         if (EE) return EE;
491       }
492     }
493   }
494
495   // If we can't make a JIT and we didn't request one specifically, try making
496   // an interpreter instead.
497   if (WhichEngine & EngineKind::Interpreter) {
498     if (ExecutionEngine::InterpCtor)
499       return ExecutionEngine::InterpCtor(M, ErrorStr);
500     if (ErrorStr)
501       *ErrorStr = "Interpreter has not been linked in.";
502     return 0;
503   }
504
505   if ((WhichEngine & EngineKind::JIT) && ExecutionEngine::JITCtor == 0) {
506     if (ErrorStr)
507       *ErrorStr = "JIT has not been linked in.";
508   }
509
510   return 0;
511 }
512
513 void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
514   if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
515     return getPointerToFunction(F);
516
517   MutexGuard locked(lock);
518   if (void *P = EEState.getGlobalAddressMap(locked)[GV])
519     return P;
520
521   // Global variable might have been added since interpreter started.
522   if (GlobalVariable *GVar =
523           const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
524     EmitGlobalVariable(GVar);
525   else
526     llvm_unreachable("Global hasn't had an address allocated yet!");
527
528   return EEState.getGlobalAddressMap(locked)[GV];
529 }
530
531 /// \brief Converts a Constant* into a GenericValue, including handling of
532 /// ConstantExpr values.
533 GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
534   // If its undefined, return the garbage.
535   if (isa<UndefValue>(C)) {
536     GenericValue Result;
537     switch (C->getType()->getTypeID()) {
538     case Type::IntegerTyID:
539     case Type::X86_FP80TyID:
540     case Type::FP128TyID:
541     case Type::PPC_FP128TyID:
542       // Although the value is undefined, we still have to construct an APInt
543       // with the correct bit width.
544       Result.IntVal = APInt(C->getType()->getPrimitiveSizeInBits(), 0);
545       break;
546     default:
547       break;
548     }
549     return Result;
550   }
551
552   // Otherwise, if the value is a ConstantExpr...
553   if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
554     Constant *Op0 = CE->getOperand(0);
555     switch (CE->getOpcode()) {
556     case Instruction::GetElementPtr: {
557       // Compute the index
558       GenericValue Result = getConstantValue(Op0);
559       SmallVector<Value*, 8> Indices(CE->op_begin()+1, CE->op_end());
560       uint64_t Offset = TD->getIndexedOffset(Op0->getType(), Indices);
561
562       char* tmp = (char*) Result.PointerVal;
563       Result = PTOGV(tmp + Offset);
564       return Result;
565     }
566     case Instruction::Trunc: {
567       GenericValue GV = getConstantValue(Op0);
568       uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
569       GV.IntVal = GV.IntVal.trunc(BitWidth);
570       return GV;
571     }
572     case Instruction::ZExt: {
573       GenericValue GV = getConstantValue(Op0);
574       uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
575       GV.IntVal = GV.IntVal.zext(BitWidth);
576       return GV;
577     }
578     case Instruction::SExt: {
579       GenericValue GV = getConstantValue(Op0);
580       uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
581       GV.IntVal = GV.IntVal.sext(BitWidth);
582       return GV;
583     }
584     case Instruction::FPTrunc: {
585       // FIXME long double
586       GenericValue GV = getConstantValue(Op0);
587       GV.FloatVal = float(GV.DoubleVal);
588       return GV;
589     }
590     case Instruction::FPExt:{
591       // FIXME long double
592       GenericValue GV = getConstantValue(Op0);
593       GV.DoubleVal = double(GV.FloatVal);
594       return GV;
595     }
596     case Instruction::UIToFP: {
597       GenericValue GV = getConstantValue(Op0);
598       if (CE->getType()->isFloatTy())
599         GV.FloatVal = float(GV.IntVal.roundToDouble());
600       else if (CE->getType()->isDoubleTy())
601         GV.DoubleVal = GV.IntVal.roundToDouble();
602       else if (CE->getType()->isX86_FP80Ty()) {
603         APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
604         (void)apf.convertFromAPInt(GV.IntVal,
605                                    false,
606                                    APFloat::rmNearestTiesToEven);
607         GV.IntVal = apf.bitcastToAPInt();
608       }
609       return GV;
610     }
611     case Instruction::SIToFP: {
612       GenericValue GV = getConstantValue(Op0);
613       if (CE->getType()->isFloatTy())
614         GV.FloatVal = float(GV.IntVal.signedRoundToDouble());
615       else if (CE->getType()->isDoubleTy())
616         GV.DoubleVal = GV.IntVal.signedRoundToDouble();
617       else if (CE->getType()->isX86_FP80Ty()) {
618         APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
619         (void)apf.convertFromAPInt(GV.IntVal,
620                                    true,
621                                    APFloat::rmNearestTiesToEven);
622         GV.IntVal = apf.bitcastToAPInt();
623       }
624       return GV;
625     }
626     case Instruction::FPToUI: // double->APInt conversion handles sign
627     case Instruction::FPToSI: {
628       GenericValue GV = getConstantValue(Op0);
629       uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
630       if (Op0->getType()->isFloatTy())
631         GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth);
632       else if (Op0->getType()->isDoubleTy())
633         GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
634       else if (Op0->getType()->isX86_FP80Ty()) {
635         APFloat apf = APFloat(GV.IntVal);
636         uint64_t v;
637         bool ignored;
638         (void)apf.convertToInteger(&v, BitWidth,
639                                    CE->getOpcode()==Instruction::FPToSI,
640                                    APFloat::rmTowardZero, &ignored);
641         GV.IntVal = v; // endian?
642       }
643       return GV;
644     }
645     case Instruction::PtrToInt: {
646       GenericValue GV = getConstantValue(Op0);
647       uint32_t PtrWidth = TD->getPointerSizeInBits();
648       GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
649       return GV;
650     }
651     case Instruction::IntToPtr: {
652       GenericValue GV = getConstantValue(Op0);
653       uint32_t PtrWidth = TD->getPointerSizeInBits();
654       if (PtrWidth != GV.IntVal.getBitWidth())
655         GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
656       assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
657       GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
658       return GV;
659     }
660     case Instruction::BitCast: {
661       GenericValue GV = getConstantValue(Op0);
662       Type* DestTy = CE->getType();
663       switch (Op0->getType()->getTypeID()) {
664         default: llvm_unreachable("Invalid bitcast operand");
665         case Type::IntegerTyID:
666           assert(DestTy->isFloatingPointTy() && "invalid bitcast");
667           if (DestTy->isFloatTy())
668             GV.FloatVal = GV.IntVal.bitsToFloat();
669           else if (DestTy->isDoubleTy())
670             GV.DoubleVal = GV.IntVal.bitsToDouble();
671           break;
672         case Type::FloatTyID:
673           assert(DestTy->isIntegerTy(32) && "Invalid bitcast");
674           GV.IntVal = APInt::floatToBits(GV.FloatVal);
675           break;
676         case Type::DoubleTyID:
677           assert(DestTy->isIntegerTy(64) && "Invalid bitcast");
678           GV.IntVal = APInt::doubleToBits(GV.DoubleVal);
679           break;
680         case Type::PointerTyID:
681           assert(DestTy->isPointerTy() && "Invalid bitcast");
682           break; // getConstantValue(Op0)  above already converted it
683       }
684       return GV;
685     }
686     case Instruction::Add:
687     case Instruction::FAdd:
688     case Instruction::Sub:
689     case Instruction::FSub:
690     case Instruction::Mul:
691     case Instruction::FMul:
692     case Instruction::UDiv:
693     case Instruction::SDiv:
694     case Instruction::URem:
695     case Instruction::SRem:
696     case Instruction::And:
697     case Instruction::Or:
698     case Instruction::Xor: {
699       GenericValue LHS = getConstantValue(Op0);
700       GenericValue RHS = getConstantValue(CE->getOperand(1));
701       GenericValue GV;
702       switch (CE->getOperand(0)->getType()->getTypeID()) {
703       default: llvm_unreachable("Bad add type!");
704       case Type::IntegerTyID:
705         switch (CE->getOpcode()) {
706           default: llvm_unreachable("Invalid integer opcode");
707           case Instruction::Add: GV.IntVal = LHS.IntVal + RHS.IntVal; break;
708           case Instruction::Sub: GV.IntVal = LHS.IntVal - RHS.IntVal; break;
709           case Instruction::Mul: GV.IntVal = LHS.IntVal * RHS.IntVal; break;
710           case Instruction::UDiv:GV.IntVal = LHS.IntVal.udiv(RHS.IntVal); break;
711           case Instruction::SDiv:GV.IntVal = LHS.IntVal.sdiv(RHS.IntVal); break;
712           case Instruction::URem:GV.IntVal = LHS.IntVal.urem(RHS.IntVal); break;
713           case Instruction::SRem:GV.IntVal = LHS.IntVal.srem(RHS.IntVal); break;
714           case Instruction::And: GV.IntVal = LHS.IntVal & RHS.IntVal; break;
715           case Instruction::Or:  GV.IntVal = LHS.IntVal | RHS.IntVal; break;
716           case Instruction::Xor: GV.IntVal = LHS.IntVal ^ RHS.IntVal; break;
717         }
718         break;
719       case Type::FloatTyID:
720         switch (CE->getOpcode()) {
721           default: llvm_unreachable("Invalid float opcode");
722           case Instruction::FAdd:
723             GV.FloatVal = LHS.FloatVal + RHS.FloatVal; break;
724           case Instruction::FSub:
725             GV.FloatVal = LHS.FloatVal - RHS.FloatVal; break;
726           case Instruction::FMul:
727             GV.FloatVal = LHS.FloatVal * RHS.FloatVal; break;
728           case Instruction::FDiv:
729             GV.FloatVal = LHS.FloatVal / RHS.FloatVal; break;
730           case Instruction::FRem:
731             GV.FloatVal = std::fmod(LHS.FloatVal,RHS.FloatVal); break;
732         }
733         break;
734       case Type::DoubleTyID:
735         switch (CE->getOpcode()) {
736           default: llvm_unreachable("Invalid double opcode");
737           case Instruction::FAdd:
738             GV.DoubleVal = LHS.DoubleVal + RHS.DoubleVal; break;
739           case Instruction::FSub:
740             GV.DoubleVal = LHS.DoubleVal - RHS.DoubleVal; break;
741           case Instruction::FMul:
742             GV.DoubleVal = LHS.DoubleVal * RHS.DoubleVal; break;
743           case Instruction::FDiv:
744             GV.DoubleVal = LHS.DoubleVal / RHS.DoubleVal; break;
745           case Instruction::FRem:
746             GV.DoubleVal = std::fmod(LHS.DoubleVal,RHS.DoubleVal); break;
747         }
748         break;
749       case Type::X86_FP80TyID:
750       case Type::PPC_FP128TyID:
751       case Type::FP128TyID: {
752         APFloat apfLHS = APFloat(LHS.IntVal);
753         switch (CE->getOpcode()) {
754           default: llvm_unreachable("Invalid long double opcode");
755           case Instruction::FAdd:
756             apfLHS.add(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
757             GV.IntVal = apfLHS.bitcastToAPInt();
758             break;
759           case Instruction::FSub:
760             apfLHS.subtract(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
761             GV.IntVal = apfLHS.bitcastToAPInt();
762             break;
763           case Instruction::FMul:
764             apfLHS.multiply(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
765             GV.IntVal = apfLHS.bitcastToAPInt();
766             break;
767           case Instruction::FDiv:
768             apfLHS.divide(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
769             GV.IntVal = apfLHS.bitcastToAPInt();
770             break;
771           case Instruction::FRem:
772             apfLHS.mod(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven);
773             GV.IntVal = apfLHS.bitcastToAPInt();
774             break;
775           }
776         }
777         break;
778       }
779       return GV;
780     }
781     default:
782       break;
783     }
784
785     SmallString<256> Msg;
786     raw_svector_ostream OS(Msg);
787     OS << "ConstantExpr not handled: " << *CE;
788     report_fatal_error(OS.str());
789   }
790
791   // Otherwise, we have a simple constant.
792   GenericValue Result;
793   switch (C->getType()->getTypeID()) {
794   case Type::FloatTyID:
795     Result.FloatVal = cast<ConstantFP>(C)->getValueAPF().convertToFloat();
796     break;
797   case Type::DoubleTyID:
798     Result.DoubleVal = cast<ConstantFP>(C)->getValueAPF().convertToDouble();
799     break;
800   case Type::X86_FP80TyID:
801   case Type::FP128TyID:
802   case Type::PPC_FP128TyID:
803     Result.IntVal = cast <ConstantFP>(C)->getValueAPF().bitcastToAPInt();
804     break;
805   case Type::IntegerTyID:
806     Result.IntVal = cast<ConstantInt>(C)->getValue();
807     break;
808   case Type::PointerTyID:
809     if (isa<ConstantPointerNull>(C))
810       Result.PointerVal = 0;
811     else if (const Function *F = dyn_cast<Function>(C))
812       Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
813     else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
814       Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
815     else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C))
816       Result = PTOGV(getPointerToBasicBlock(const_cast<BasicBlock*>(
817                                                         BA->getBasicBlock())));
818     else
819       llvm_unreachable("Unknown constant pointer type!");
820     break;
821   default:
822     SmallString<256> Msg;
823     raw_svector_ostream OS(Msg);
824     OS << "ERROR: Constant unimplemented for type: " << *C->getType();
825     report_fatal_error(OS.str());
826   }
827
828   return Result;
829 }
830
831 /// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
832 /// with the integer held in IntVal.
833 static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
834                              unsigned StoreBytes) {
835   assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!");
836   uint8_t *Src = (uint8_t *)IntVal.getRawData();
837
838   if (sys::isLittleEndianHost()) {
839     // Little-endian host - the source is ordered from LSB to MSB.  Order the
840     // destination from LSB to MSB: Do a straight copy.
841     memcpy(Dst, Src, StoreBytes);
842   } else {
843     // Big-endian host - the source is an array of 64 bit words ordered from
844     // LSW to MSW.  Each word is ordered from MSB to LSB.  Order the destination
845     // from MSB to LSB: Reverse the word order, but not the bytes in a word.
846     while (StoreBytes > sizeof(uint64_t)) {
847       StoreBytes -= sizeof(uint64_t);
848       // May not be aligned so use memcpy.
849       memcpy(Dst + StoreBytes, Src, sizeof(uint64_t));
850       Src += sizeof(uint64_t);
851     }
852
853     memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes);
854   }
855 }
856
857 void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
858                                          GenericValue *Ptr, Type *Ty) {
859   const unsigned StoreBytes = getTargetData()->getTypeStoreSize(Ty);
860
861   switch (Ty->getTypeID()) {
862   case Type::IntegerTyID:
863     StoreIntToMemory(Val.IntVal, (uint8_t*)Ptr, StoreBytes);
864     break;
865   case Type::FloatTyID:
866     *((float*)Ptr) = Val.FloatVal;
867     break;
868   case Type::DoubleTyID:
869     *((double*)Ptr) = Val.DoubleVal;
870     break;
871   case Type::X86_FP80TyID:
872     memcpy(Ptr, Val.IntVal.getRawData(), 10);
873     break;
874   case Type::PointerTyID:
875     // Ensure 64 bit target pointers are fully initialized on 32 bit hosts.
876     if (StoreBytes != sizeof(PointerTy))
877       memset(&(Ptr->PointerVal), 0, StoreBytes);
878
879     *((PointerTy*)Ptr) = Val.PointerVal;
880     break;
881   default:
882     dbgs() << "Cannot store value of type " << *Ty << "!\n";
883   }
884
885   if (sys::isLittleEndianHost() != getTargetData()->isLittleEndian())
886     // Host and target are different endian - reverse the stored bytes.
887     std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
888 }
889
890 /// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
891 /// from Src into IntVal, which is assumed to be wide enough and to hold zero.
892 static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
893   assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
894   uint8_t *Dst = (uint8_t *)IntVal.getRawData();
895
896   if (sys::isLittleEndianHost())
897     // Little-endian host - the destination must be ordered from LSB to MSB.
898     // The source is ordered from LSB to MSB: Do a straight copy.
899     memcpy(Dst, Src, LoadBytes);
900   else {
901     // Big-endian - the destination is an array of 64 bit words ordered from
902     // LSW to MSW.  Each word must be ordered from MSB to LSB.  The source is
903     // ordered from MSB to LSB: Reverse the word order, but not the bytes in
904     // a word.
905     while (LoadBytes > sizeof(uint64_t)) {
906       LoadBytes -= sizeof(uint64_t);
907       // May not be aligned so use memcpy.
908       memcpy(Dst, Src + LoadBytes, sizeof(uint64_t));
909       Dst += sizeof(uint64_t);
910     }
911
912     memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
913   }
914 }
915
916 /// FIXME: document
917 ///
918 void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
919                                           GenericValue *Ptr,
920                                           Type *Ty) {
921   const unsigned LoadBytes = getTargetData()->getTypeStoreSize(Ty);
922
923   switch (Ty->getTypeID()) {
924   case Type::IntegerTyID:
925     // An APInt with all words initially zero.
926     Result.IntVal = APInt(cast<IntegerType>(Ty)->getBitWidth(), 0);
927     LoadIntFromMemory(Result.IntVal, (uint8_t*)Ptr, LoadBytes);
928     break;
929   case Type::FloatTyID:
930     Result.FloatVal = *((float*)Ptr);
931     break;
932   case Type::DoubleTyID:
933     Result.DoubleVal = *((double*)Ptr);
934     break;
935   case Type::PointerTyID:
936     Result.PointerVal = *((PointerTy*)Ptr);
937     break;
938   case Type::X86_FP80TyID: {
939     // This is endian dependent, but it will only work on x86 anyway.
940     // FIXME: Will not trap if loading a signaling NaN.
941     uint64_t y[2];
942     memcpy(y, Ptr, 10);
943     Result.IntVal = APInt(80, y);
944     break;
945   }
946   default:
947     SmallString<256> Msg;
948     raw_svector_ostream OS(Msg);
949     OS << "Cannot load value of type " << *Ty << "!";
950     report_fatal_error(OS.str());
951   }
952 }
953
954 void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
955   DEBUG(dbgs() << "JIT: Initializing " << Addr << " ");
956   DEBUG(Init->dump());
957   if (isa<UndefValue>(Init)) {
958     return;
959   } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
960     unsigned ElementSize =
961       getTargetData()->getTypeAllocSize(CP->getType()->getElementType());
962     for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
963       InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
964     return;
965   } else if (isa<ConstantAggregateZero>(Init)) {
966     memset(Addr, 0, (size_t)getTargetData()->getTypeAllocSize(Init->getType()));
967     return;
968   } else if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
969     unsigned ElementSize =
970       getTargetData()->getTypeAllocSize(CPA->getType()->getElementType());
971     for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
972       InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
973     return;
974   } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
975     const StructLayout *SL =
976       getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
977     for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
978       InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
979     return;
980   } else if (Init->getType()->isFirstClassType()) {
981     GenericValue Val = getConstantValue(Init);
982     StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
983     return;
984   }
985
986   DEBUG(dbgs() << "Bad Type: " << *Init->getType() << "\n");
987   llvm_unreachable("Unknown constant type to initialize memory with!");
988 }
989
990 /// EmitGlobals - Emit all of the global variables to memory, storing their
991 /// addresses into GlobalAddress.  This must make sure to copy the contents of
992 /// their initializers into the memory.
993 void ExecutionEngine::emitGlobals() {
994   // Loop over all of the global variables in the program, allocating the memory
995   // to hold them.  If there is more than one module, do a prepass over globals
996   // to figure out how the different modules should link together.
997   std::map<std::pair<std::string, Type*>,
998            const GlobalValue*> LinkedGlobalsMap;
999
1000   if (Modules.size() != 1) {
1001     for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1002       Module &M = *Modules[m];
1003       for (Module::const_global_iterator I = M.global_begin(),
1004            E = M.global_end(); I != E; ++I) {
1005         const GlobalValue *GV = I;
1006         if (GV->hasLocalLinkage() || GV->isDeclaration() ||
1007             GV->hasAppendingLinkage() || !GV->hasName())
1008           continue;// Ignore external globals and globals with internal linkage.
1009
1010         const GlobalValue *&GVEntry =
1011           LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
1012
1013         // If this is the first time we've seen this global, it is the canonical
1014         // version.
1015         if (!GVEntry) {
1016           GVEntry = GV;
1017           continue;
1018         }
1019
1020         // If the existing global is strong, never replace it.
1021         if (GVEntry->hasExternalLinkage() ||
1022             GVEntry->hasDLLImportLinkage() ||
1023             GVEntry->hasDLLExportLinkage())
1024           continue;
1025
1026         // Otherwise, we know it's linkonce/weak, replace it if this is a strong
1027         // symbol.  FIXME is this right for common?
1028         if (GV->hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
1029           GVEntry = GV;
1030       }
1031     }
1032   }
1033
1034   std::vector<const GlobalValue*> NonCanonicalGlobals;
1035   for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1036     Module &M = *Modules[m];
1037     for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
1038          I != E; ++I) {
1039       // In the multi-module case, see what this global maps to.
1040       if (!LinkedGlobalsMap.empty()) {
1041         if (const GlobalValue *GVEntry =
1042               LinkedGlobalsMap[std::make_pair(I->getName(), I->getType())]) {
1043           // If something else is the canonical global, ignore this one.
1044           if (GVEntry != &*I) {
1045             NonCanonicalGlobals.push_back(I);
1046             continue;
1047           }
1048         }
1049       }
1050
1051       if (!I->isDeclaration()) {
1052         addGlobalMapping(I, getMemoryForGV(I));
1053       } else {
1054         // External variable reference. Try to use the dynamic loader to
1055         // get a pointer to it.
1056         if (void *SymAddr =
1057             sys::DynamicLibrary::SearchForAddressOfSymbol(I->getName()))
1058           addGlobalMapping(I, SymAddr);
1059         else {
1060           report_fatal_error("Could not resolve external global address: "
1061                             +I->getName());
1062         }
1063       }
1064     }
1065
1066     // If there are multiple modules, map the non-canonical globals to their
1067     // canonical location.
1068     if (!NonCanonicalGlobals.empty()) {
1069       for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
1070         const GlobalValue *GV = NonCanonicalGlobals[i];
1071         const GlobalValue *CGV =
1072           LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
1073         void *Ptr = getPointerToGlobalIfAvailable(CGV);
1074         assert(Ptr && "Canonical global wasn't codegen'd!");
1075         addGlobalMapping(GV, Ptr);
1076       }
1077     }
1078
1079     // Now that all of the globals are set up in memory, loop through them all
1080     // and initialize their contents.
1081     for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
1082          I != E; ++I) {
1083       if (!I->isDeclaration()) {
1084         if (!LinkedGlobalsMap.empty()) {
1085           if (const GlobalValue *GVEntry =
1086                 LinkedGlobalsMap[std::make_pair(I->getName(), I->getType())])
1087             if (GVEntry != &*I)  // Not the canonical variable.
1088               continue;
1089         }
1090         EmitGlobalVariable(I);
1091       }
1092     }
1093   }
1094 }
1095
1096 // EmitGlobalVariable - This method emits the specified global variable to the
1097 // address specified in GlobalAddresses, or allocates new memory if it's not
1098 // already in the map.
1099 void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
1100   void *GA = getPointerToGlobalIfAvailable(GV);
1101
1102   if (GA == 0) {
1103     // If it's not already specified, allocate memory for the global.
1104     GA = getMemoryForGV(GV);
1105     addGlobalMapping(GV, GA);
1106   }
1107
1108   // Don't initialize if it's thread local, let the client do it.
1109   if (!GV->isThreadLocal())
1110     InitializeMemory(GV->getInitializer(), GA);
1111
1112   Type *ElTy = GV->getType()->getElementType();
1113   size_t GVSize = (size_t)getTargetData()->getTypeAllocSize(ElTy);
1114   NumInitBytes += (unsigned)GVSize;
1115   ++NumGlobals;
1116 }
1117
1118 ExecutionEngineState::ExecutionEngineState(ExecutionEngine &EE)
1119   : EE(EE), GlobalAddressMap(this) {
1120 }
1121
1122 sys::Mutex *
1123 ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
1124   return &EES->EE.lock;
1125 }
1126
1127 void ExecutionEngineState::AddressMapConfig::onDelete(ExecutionEngineState *EES,
1128                                                       const GlobalValue *Old) {
1129   void *OldVal = EES->GlobalAddressMap.lookup(Old);
1130   EES->GlobalAddressReverseMap.erase(OldVal);
1131 }
1132
1133 void ExecutionEngineState::AddressMapConfig::onRAUW(ExecutionEngineState *,
1134                                                     const GlobalValue *,
1135                                                     const GlobalValue *) {
1136   assert(false && "The ExecutionEngine doesn't know how to handle a"
1137          " RAUW on a value it has a global mapping for.");
1138 }