1 //===-- ExecutionEngine.cpp - Common Implementation shared by EEs ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the common interface used by the various execution engine
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ExecutionEngine/ExecutionEngine.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/Statistic.h"
18 #include "llvm/ExecutionEngine/GenericValue.h"
19 #include "llvm/ExecutionEngine/JITEventListener.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/Operator.h"
25 #include "llvm/IR/ValueHandle.h"
26 #include "llvm/Object/Archive.h"
27 #include "llvm/Object/ObjectFile.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/DynamicLibrary.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/Host.h"
32 #include "llvm/Support/MutexGuard.h"
33 #include "llvm/Support/TargetRegistry.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetMachine.h"
40 #define DEBUG_TYPE "jit"
42 STATISTIC(NumInitBytes, "Number of bytes of global vars initialized");
43 STATISTIC(NumGlobals , "Number of global vars initialized");
45 ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
46 std::unique_ptr<Module> M, std::string *ErrorStr,
47 std::unique_ptr<RTDyldMemoryManager> MCJMM,
48 std::unique_ptr<TargetMachine> TM) = nullptr;
50 ExecutionEngine *(*ExecutionEngine::OrcMCJITReplacementCtor)(
51 std::string *ErrorStr, std::unique_ptr<RTDyldMemoryManager> OrcJMM,
52 std::unique_ptr<TargetMachine> TM) = nullptr;
54 ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
55 std::string *ErrorStr) =nullptr;
57 void JITEventListener::anchor() {}
59 ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
61 LazyFunctionCreator(nullptr) {
62 CompilingLazily = false;
63 GVCompilationDisabled = false;
64 SymbolSearchingDisabled = false;
66 // IR module verification is enabled by default in debug builds, and disabled
67 // by default in release builds.
71 VerifyModules = false;
74 assert(M && "Module is null?");
75 Modules.push_back(std::move(M));
78 ExecutionEngine::~ExecutionEngine() {
79 clearAllGlobalMappings();
83 /// \brief Helper class which uses a value handler to automatically deletes the
84 /// memory block when the GlobalVariable is destroyed.
85 class GVMemoryBlock : public CallbackVH {
86 GVMemoryBlock(const GlobalVariable *GV)
87 : CallbackVH(const_cast<GlobalVariable*>(GV)) {}
90 /// \brief Returns the address the GlobalVariable should be written into. The
91 /// GVMemoryBlock object prefixes that.
92 static char *Create(const GlobalVariable *GV, const DataLayout& TD) {
93 Type *ElTy = GV->getType()->getElementType();
94 size_t GVSize = (size_t)TD.getTypeAllocSize(ElTy);
95 void *RawMemory = ::operator new(
96 RoundUpToAlignment(sizeof(GVMemoryBlock),
97 TD.getPreferredAlignment(GV))
99 new(RawMemory) GVMemoryBlock(GV);
100 return static_cast<char*>(RawMemory) + sizeof(GVMemoryBlock);
103 void deleted() override {
104 // We allocated with operator new and with some extra memory hanging off the
105 // end, so don't just delete this. I'm not sure if this is actually
107 this->~GVMemoryBlock();
108 ::operator delete(this);
111 } // anonymous namespace
113 char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
114 return GVMemoryBlock::Create(GV, *getDataLayout());
117 void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) {
118 llvm_unreachable("ExecutionEngine subclass doesn't implement addObjectFile.");
122 ExecutionEngine::addObjectFile(object::OwningBinary<object::ObjectFile> O) {
123 llvm_unreachable("ExecutionEngine subclass doesn't implement addObjectFile.");
126 void ExecutionEngine::addArchive(object::OwningBinary<object::Archive> A) {
127 llvm_unreachable("ExecutionEngine subclass doesn't implement addArchive.");
130 bool ExecutionEngine::removeModule(Module *M) {
131 for (auto I = Modules.begin(), E = Modules.end(); I != E; ++I) {
132 Module *Found = I->get();
136 clearGlobalMappingsFromModule(M);
143 Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
144 for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
145 if (Function *F = Modules[i]->getFunction(FnName))
152 void *ExecutionEngineState::RemoveMapping(const GlobalValue *ToUnmap) {
153 GlobalAddressMapTy::iterator I = GlobalAddressMap.find(ToUnmap);
156 // FIXME: This is silly, we shouldn't end up with a mapping -> 0 in the
158 if (I == GlobalAddressMap.end())
162 GlobalAddressMap.erase(I);
165 GlobalAddressReverseMap.erase(OldVal);
169 void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
170 MutexGuard locked(lock);
172 DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
173 << "\' to [" << Addr << "]\n";);
174 void *&CurVal = EEState.getGlobalAddressMap()[GV];
175 assert((!CurVal || !Addr) && "GlobalMapping already established!");
178 // If we are using the reverse mapping, add it too.
179 if (!EEState.getGlobalAddressReverseMap().empty()) {
180 AssertingVH<const GlobalValue> &V =
181 EEState.getGlobalAddressReverseMap()[Addr];
182 assert((!V || !GV) && "GlobalMapping already established!");
187 void ExecutionEngine::clearAllGlobalMappings() {
188 MutexGuard locked(lock);
190 EEState.getGlobalAddressMap().clear();
191 EEState.getGlobalAddressReverseMap().clear();
194 void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
195 MutexGuard locked(lock);
197 for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
198 EEState.RemoveMapping(FI);
199 for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
201 EEState.RemoveMapping(GI);
204 void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
205 MutexGuard locked(lock);
207 ExecutionEngineState::GlobalAddressMapTy &Map =
208 EEState.getGlobalAddressMap();
210 // Deleting from the mapping?
212 return EEState.RemoveMapping(GV);
214 void *&CurVal = Map[GV];
215 void *OldVal = CurVal;
217 if (CurVal && !EEState.getGlobalAddressReverseMap().empty())
218 EEState.getGlobalAddressReverseMap().erase(CurVal);
221 // If we are using the reverse mapping, add it too.
222 if (!EEState.getGlobalAddressReverseMap().empty()) {
223 AssertingVH<const GlobalValue> &V =
224 EEState.getGlobalAddressReverseMap()[Addr];
225 assert((!V || !GV) && "GlobalMapping already established!");
231 void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
232 MutexGuard locked(lock);
234 ExecutionEngineState::GlobalAddressMapTy::iterator I =
235 EEState.getGlobalAddressMap().find(GV);
236 return I != EEState.getGlobalAddressMap().end() ? I->second : nullptr;
239 const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
240 MutexGuard locked(lock);
242 // If we haven't computed the reverse mapping yet, do so first.
243 if (EEState.getGlobalAddressReverseMap().empty()) {
244 for (ExecutionEngineState::GlobalAddressMapTy::iterator
245 I = EEState.getGlobalAddressMap().begin(),
246 E = EEState.getGlobalAddressMap().end(); I != E; ++I)
247 EEState.getGlobalAddressReverseMap().insert(std::make_pair(
248 I->second, I->first));
251 std::map<void *, AssertingVH<const GlobalValue> >::iterator I =
252 EEState.getGlobalAddressReverseMap().find(Addr);
253 return I != EEState.getGlobalAddressReverseMap().end() ? I->second : nullptr;
258 std::unique_ptr<char[]> Array;
259 std::vector<std::unique_ptr<char[]>> Values;
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);
266 } // anonymous namespace
267 void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
268 const std::vector<std::string> &InputArgv) {
269 Values.clear(); // Free the old contents.
270 Values.reserve(InputArgv.size());
271 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
272 Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
274 DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
275 Type *SBytePtr = Type::getInt8PtrTy(C);
277 for (unsigned i = 0; i != InputArgv.size(); ++i) {
278 unsigned Size = InputArgv[i].size()+1;
279 auto Dest = make_unique<char[]>(Size);
280 DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest.get() << "\n");
282 std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest.get());
285 // Endian safe: Array[i] = (PointerTy)Dest;
286 EE->StoreValueToMemory(PTOGV(Dest.get()),
287 (GenericValue*)(&Array[i*PtrSize]), SBytePtr);
288 Values.push_back(std::move(Dest));
292 EE->StoreValueToMemory(PTOGV(nullptr),
293 (GenericValue*)(&Array[InputArgv.size()*PtrSize]),
298 void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
300 const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
301 GlobalVariable *GV = module.getNamedGlobal(Name);
303 // If this global has internal linkage, or if it has a use, then it must be
304 // an old-style (llvmgcc3) static ctor with __main linked in and in use. If
305 // this is the case, don't execute any of the global ctors, __main will do
307 if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
309 // Should be an array of '{ i32, void ()* }' structs. The first value is
310 // the init priority, which we ignore.
311 ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
314 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
315 ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));
318 Constant *FP = CS->getOperand(1);
319 if (FP->isNullValue())
320 continue; // Found a sentinal value, ignore.
322 // Strip off constant expression casts.
323 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
325 FP = CE->getOperand(0);
327 // Execute the ctor/dtor function!
328 if (Function *F = dyn_cast<Function>(FP))
329 runFunction(F, std::vector<GenericValue>());
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.
337 void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
338 // Execute global ctors/dtors for each module in the program.
339 for (std::unique_ptr<Module> &M : Modules)
340 runStaticConstructorsDestructors(*M, isDtors);
344 /// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
345 static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
346 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
347 for (unsigned i = 0; i < PtrSize; ++i)
348 if (*(i + (uint8_t*)Loc))
354 int ExecutionEngine::runFunctionAsMain(Function *Fn,
355 const std::vector<std::string> &argv,
356 const char * const * envp) {
357 std::vector<GenericValue> GVArgs;
359 GVArgc.IntVal = APInt(32, argv.size());
362 unsigned NumArgs = Fn->getFunctionType()->getNumParams();
363 FunctionType *FTy = Fn->getFunctionType();
364 Type* PPInt8Ty = Type::getInt8PtrTy(Fn->getContext())->getPointerTo();
366 // Check the argument types.
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");
382 GVArgs.push_back(GVArgc); // Arg #0 = argc.
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");
389 std::vector<std::string> EnvVars;
390 for (unsigned i = 0; envp[i]; ++i)
391 EnvVars.push_back(envp[i]);
393 GVArgs.push_back(PTOGV(CEnv.reset(Fn->getContext(), this, EnvVars)));
398 return runFunction(Fn, GVArgs).IntVal.getZExtValue();
401 EngineBuilder::EngineBuilder() {
405 EngineBuilder::EngineBuilder(std::unique_ptr<Module> M)
406 : M(std::move(M)), MCJMM(nullptr) {
410 EngineBuilder::~EngineBuilder() {}
412 EngineBuilder &EngineBuilder::setMCJITMemoryManager(
413 std::unique_ptr<RTDyldMemoryManager> mcjmm) {
414 MCJMM = std::move(mcjmm);
418 void EngineBuilder::InitEngine() {
419 WhichEngine = EngineKind::Either;
421 OptLevel = CodeGenOpt::Default;
423 Options = TargetOptions();
424 RelocModel = Reloc::Default;
425 CMModel = CodeModel::JITDefault;
426 UseOrcMCJITReplacement = false;
428 // IR module verification is enabled by default in debug builds, and disabled
429 // by default in release builds.
431 VerifyModules = true;
433 VerifyModules = false;
437 ExecutionEngine *EngineBuilder::create(TargetMachine *TM) {
438 std::unique_ptr<TargetMachine> TheTM(TM); // Take ownership.
440 // Make sure we can resolve symbols in the program as well. The zero arg
441 // to the function tells DynamicLibrary to load the program, not a library.
442 if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, ErrorStr))
445 // If the user specified a memory manager but didn't specify which engine to
446 // create, we assume they only want the JIT, and we fail if they only want
449 if (WhichEngine & EngineKind::JIT)
450 WhichEngine = EngineKind::JIT;
453 *ErrorStr = "Cannot create an interpreter with a memory manager.";
458 // Unless the interpreter was explicitly selected or the JIT is not linked,
460 if ((WhichEngine & EngineKind::JIT) && TheTM) {
461 Triple TT(M->getTargetTriple());
462 if (!TM->getTarget().hasJIT()) {
463 errs() << "WARNING: This target JIT is not designed for the host"
464 << " you are running. If bad things happen, please choose"
465 << " a different -march switch.\n";
468 ExecutionEngine *EE = nullptr;
469 if (ExecutionEngine::OrcMCJITReplacementCtor && UseOrcMCJITReplacement) {
470 EE = ExecutionEngine::OrcMCJITReplacementCtor(ErrorStr, std::move(MCJMM),
472 EE->addModule(std::move(M));
473 } else if (ExecutionEngine::MCJITCtor)
474 EE = ExecutionEngine::MCJITCtor(std::move(M), ErrorStr, std::move(MCJMM),
478 EE->setVerifyModules(VerifyModules);
483 // If we can't make a JIT and we didn't request one specifically, try making
484 // an interpreter instead.
485 if (WhichEngine & EngineKind::Interpreter) {
486 if (ExecutionEngine::InterpCtor)
487 return ExecutionEngine::InterpCtor(std::move(M), ErrorStr);
489 *ErrorStr = "Interpreter has not been linked in.";
493 if ((WhichEngine & EngineKind::JIT) && !ExecutionEngine::MCJITCtor) {
495 *ErrorStr = "JIT has not been linked in.";
501 void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
502 if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
503 return getPointerToFunction(F);
505 MutexGuard locked(lock);
506 if (void *P = EEState.getGlobalAddressMap()[GV])
509 // Global variable might have been added since interpreter started.
510 if (GlobalVariable *GVar =
511 const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
512 EmitGlobalVariable(GVar);
514 llvm_unreachable("Global hasn't had an address allocated yet!");
516 return EEState.getGlobalAddressMap()[GV];
519 /// \brief Converts a Constant* into a GenericValue, including handling of
520 /// ConstantExpr values.
521 GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
522 // If its undefined, return the garbage.
523 if (isa<UndefValue>(C)) {
525 switch (C->getType()->getTypeID()) {
528 case Type::IntegerTyID:
529 case Type::X86_FP80TyID:
530 case Type::FP128TyID:
531 case Type::PPC_FP128TyID:
532 // Although the value is undefined, we still have to construct an APInt
533 // with the correct bit width.
534 Result.IntVal = APInt(C->getType()->getPrimitiveSizeInBits(), 0);
536 case Type::StructTyID: {
537 // if the whole struct is 'undef' just reserve memory for the value.
538 if(StructType *STy = dyn_cast<StructType>(C->getType())) {
539 unsigned int elemNum = STy->getNumElements();
540 Result.AggregateVal.resize(elemNum);
541 for (unsigned int i = 0; i < elemNum; ++i) {
542 Type *ElemTy = STy->getElementType(i);
543 if (ElemTy->isIntegerTy())
544 Result.AggregateVal[i].IntVal =
545 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
546 else if (ElemTy->isAggregateType()) {
547 const Constant *ElemUndef = UndefValue::get(ElemTy);
548 Result.AggregateVal[i] = getConstantValue(ElemUndef);
554 case Type::VectorTyID:
555 // if the whole vector is 'undef' just reserve memory for the value.
556 const VectorType* VTy = dyn_cast<VectorType>(C->getType());
557 const Type *ElemTy = VTy->getElementType();
558 unsigned int elemNum = VTy->getNumElements();
559 Result.AggregateVal.resize(elemNum);
560 if (ElemTy->isIntegerTy())
561 for (unsigned int i = 0; i < elemNum; ++i)
562 Result.AggregateVal[i].IntVal =
563 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
569 // Otherwise, if the value is a ConstantExpr...
570 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
571 Constant *Op0 = CE->getOperand(0);
572 switch (CE->getOpcode()) {
573 case Instruction::GetElementPtr: {
575 GenericValue Result = getConstantValue(Op0);
576 APInt Offset(DL->getPointerSizeInBits(), 0);
577 cast<GEPOperator>(CE)->accumulateConstantOffset(*DL, Offset);
579 char* tmp = (char*) Result.PointerVal;
580 Result = PTOGV(tmp + Offset.getSExtValue());
583 case Instruction::Trunc: {
584 GenericValue GV = getConstantValue(Op0);
585 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
586 GV.IntVal = GV.IntVal.trunc(BitWidth);
589 case Instruction::ZExt: {
590 GenericValue GV = getConstantValue(Op0);
591 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
592 GV.IntVal = GV.IntVal.zext(BitWidth);
595 case Instruction::SExt: {
596 GenericValue GV = getConstantValue(Op0);
597 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
598 GV.IntVal = GV.IntVal.sext(BitWidth);
601 case Instruction::FPTrunc: {
603 GenericValue GV = getConstantValue(Op0);
604 GV.FloatVal = float(GV.DoubleVal);
607 case Instruction::FPExt:{
609 GenericValue GV = getConstantValue(Op0);
610 GV.DoubleVal = double(GV.FloatVal);
613 case Instruction::UIToFP: {
614 GenericValue GV = getConstantValue(Op0);
615 if (CE->getType()->isFloatTy())
616 GV.FloatVal = float(GV.IntVal.roundToDouble());
617 else if (CE->getType()->isDoubleTy())
618 GV.DoubleVal = GV.IntVal.roundToDouble();
619 else if (CE->getType()->isX86_FP80Ty()) {
620 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
621 (void)apf.convertFromAPInt(GV.IntVal,
623 APFloat::rmNearestTiesToEven);
624 GV.IntVal = apf.bitcastToAPInt();
628 case Instruction::SIToFP: {
629 GenericValue GV = getConstantValue(Op0);
630 if (CE->getType()->isFloatTy())
631 GV.FloatVal = float(GV.IntVal.signedRoundToDouble());
632 else if (CE->getType()->isDoubleTy())
633 GV.DoubleVal = GV.IntVal.signedRoundToDouble();
634 else if (CE->getType()->isX86_FP80Ty()) {
635 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
636 (void)apf.convertFromAPInt(GV.IntVal,
638 APFloat::rmNearestTiesToEven);
639 GV.IntVal = apf.bitcastToAPInt();
643 case Instruction::FPToUI: // double->APInt conversion handles sign
644 case Instruction::FPToSI: {
645 GenericValue GV = getConstantValue(Op0);
646 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
647 if (Op0->getType()->isFloatTy())
648 GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth);
649 else if (Op0->getType()->isDoubleTy())
650 GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
651 else if (Op0->getType()->isX86_FP80Ty()) {
652 APFloat apf = APFloat(APFloat::x87DoubleExtended, GV.IntVal);
655 (void)apf.convertToInteger(&v, BitWidth,
656 CE->getOpcode()==Instruction::FPToSI,
657 APFloat::rmTowardZero, &ignored);
658 GV.IntVal = v; // endian?
662 case Instruction::PtrToInt: {
663 GenericValue GV = getConstantValue(Op0);
664 uint32_t PtrWidth = DL->getTypeSizeInBits(Op0->getType());
665 assert(PtrWidth <= 64 && "Bad pointer width");
666 GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
667 uint32_t IntWidth = DL->getTypeSizeInBits(CE->getType());
668 GV.IntVal = GV.IntVal.zextOrTrunc(IntWidth);
671 case Instruction::IntToPtr: {
672 GenericValue GV = getConstantValue(Op0);
673 uint32_t PtrWidth = DL->getTypeSizeInBits(CE->getType());
674 GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
675 assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
676 GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
679 case Instruction::BitCast: {
680 GenericValue GV = getConstantValue(Op0);
681 Type* DestTy = CE->getType();
682 switch (Op0->getType()->getTypeID()) {
683 default: llvm_unreachable("Invalid bitcast operand");
684 case Type::IntegerTyID:
685 assert(DestTy->isFloatingPointTy() && "invalid bitcast");
686 if (DestTy->isFloatTy())
687 GV.FloatVal = GV.IntVal.bitsToFloat();
688 else if (DestTy->isDoubleTy())
689 GV.DoubleVal = GV.IntVal.bitsToDouble();
691 case Type::FloatTyID:
692 assert(DestTy->isIntegerTy(32) && "Invalid bitcast");
693 GV.IntVal = APInt::floatToBits(GV.FloatVal);
695 case Type::DoubleTyID:
696 assert(DestTy->isIntegerTy(64) && "Invalid bitcast");
697 GV.IntVal = APInt::doubleToBits(GV.DoubleVal);
699 case Type::PointerTyID:
700 assert(DestTy->isPointerTy() && "Invalid bitcast");
701 break; // getConstantValue(Op0) above already converted it
705 case Instruction::Add:
706 case Instruction::FAdd:
707 case Instruction::Sub:
708 case Instruction::FSub:
709 case Instruction::Mul:
710 case Instruction::FMul:
711 case Instruction::UDiv:
712 case Instruction::SDiv:
713 case Instruction::URem:
714 case Instruction::SRem:
715 case Instruction::And:
716 case Instruction::Or:
717 case Instruction::Xor: {
718 GenericValue LHS = getConstantValue(Op0);
719 GenericValue RHS = getConstantValue(CE->getOperand(1));
721 switch (CE->getOperand(0)->getType()->getTypeID()) {
722 default: llvm_unreachable("Bad add type!");
723 case Type::IntegerTyID:
724 switch (CE->getOpcode()) {
725 default: llvm_unreachable("Invalid integer opcode");
726 case Instruction::Add: GV.IntVal = LHS.IntVal + RHS.IntVal; break;
727 case Instruction::Sub: GV.IntVal = LHS.IntVal - RHS.IntVal; break;
728 case Instruction::Mul: GV.IntVal = LHS.IntVal * RHS.IntVal; break;
729 case Instruction::UDiv:GV.IntVal = LHS.IntVal.udiv(RHS.IntVal); break;
730 case Instruction::SDiv:GV.IntVal = LHS.IntVal.sdiv(RHS.IntVal); break;
731 case Instruction::URem:GV.IntVal = LHS.IntVal.urem(RHS.IntVal); break;
732 case Instruction::SRem:GV.IntVal = LHS.IntVal.srem(RHS.IntVal); break;
733 case Instruction::And: GV.IntVal = LHS.IntVal & RHS.IntVal; break;
734 case Instruction::Or: GV.IntVal = LHS.IntVal | RHS.IntVal; break;
735 case Instruction::Xor: GV.IntVal = LHS.IntVal ^ RHS.IntVal; break;
738 case Type::FloatTyID:
739 switch (CE->getOpcode()) {
740 default: llvm_unreachable("Invalid float opcode");
741 case Instruction::FAdd:
742 GV.FloatVal = LHS.FloatVal + RHS.FloatVal; break;
743 case Instruction::FSub:
744 GV.FloatVal = LHS.FloatVal - RHS.FloatVal; break;
745 case Instruction::FMul:
746 GV.FloatVal = LHS.FloatVal * RHS.FloatVal; break;
747 case Instruction::FDiv:
748 GV.FloatVal = LHS.FloatVal / RHS.FloatVal; break;
749 case Instruction::FRem:
750 GV.FloatVal = std::fmod(LHS.FloatVal,RHS.FloatVal); break;
753 case Type::DoubleTyID:
754 switch (CE->getOpcode()) {
755 default: llvm_unreachable("Invalid double opcode");
756 case Instruction::FAdd:
757 GV.DoubleVal = LHS.DoubleVal + RHS.DoubleVal; break;
758 case Instruction::FSub:
759 GV.DoubleVal = LHS.DoubleVal - RHS.DoubleVal; break;
760 case Instruction::FMul:
761 GV.DoubleVal = LHS.DoubleVal * RHS.DoubleVal; break;
762 case Instruction::FDiv:
763 GV.DoubleVal = LHS.DoubleVal / RHS.DoubleVal; break;
764 case Instruction::FRem:
765 GV.DoubleVal = std::fmod(LHS.DoubleVal,RHS.DoubleVal); break;
768 case Type::X86_FP80TyID:
769 case Type::PPC_FP128TyID:
770 case Type::FP128TyID: {
771 const fltSemantics &Sem = CE->getOperand(0)->getType()->getFltSemantics();
772 APFloat apfLHS = APFloat(Sem, LHS.IntVal);
773 switch (CE->getOpcode()) {
774 default: llvm_unreachable("Invalid long double opcode");
775 case Instruction::FAdd:
776 apfLHS.add(APFloat(Sem, RHS.IntVal), APFloat::rmNearestTiesToEven);
777 GV.IntVal = apfLHS.bitcastToAPInt();
779 case Instruction::FSub:
780 apfLHS.subtract(APFloat(Sem, RHS.IntVal),
781 APFloat::rmNearestTiesToEven);
782 GV.IntVal = apfLHS.bitcastToAPInt();
784 case Instruction::FMul:
785 apfLHS.multiply(APFloat(Sem, RHS.IntVal),
786 APFloat::rmNearestTiesToEven);
787 GV.IntVal = apfLHS.bitcastToAPInt();
789 case Instruction::FDiv:
790 apfLHS.divide(APFloat(Sem, RHS.IntVal),
791 APFloat::rmNearestTiesToEven);
792 GV.IntVal = apfLHS.bitcastToAPInt();
794 case Instruction::FRem:
795 apfLHS.mod(APFloat(Sem, RHS.IntVal),
796 APFloat::rmNearestTiesToEven);
797 GV.IntVal = apfLHS.bitcastToAPInt();
809 SmallString<256> Msg;
810 raw_svector_ostream OS(Msg);
811 OS << "ConstantExpr not handled: " << *CE;
812 report_fatal_error(OS.str());
815 // Otherwise, we have a simple constant.
817 switch (C->getType()->getTypeID()) {
818 case Type::FloatTyID:
819 Result.FloatVal = cast<ConstantFP>(C)->getValueAPF().convertToFloat();
821 case Type::DoubleTyID:
822 Result.DoubleVal = cast<ConstantFP>(C)->getValueAPF().convertToDouble();
824 case Type::X86_FP80TyID:
825 case Type::FP128TyID:
826 case Type::PPC_FP128TyID:
827 Result.IntVal = cast <ConstantFP>(C)->getValueAPF().bitcastToAPInt();
829 case Type::IntegerTyID:
830 Result.IntVal = cast<ConstantInt>(C)->getValue();
832 case Type::PointerTyID:
833 if (isa<ConstantPointerNull>(C))
834 Result.PointerVal = nullptr;
835 else if (const Function *F = dyn_cast<Function>(C))
836 Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
837 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
838 Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
840 llvm_unreachable("Unknown constant pointer type!");
842 case Type::VectorTyID: {
845 const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
846 const ConstantVector *CV = dyn_cast<ConstantVector>(C);
847 const ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(C);
850 elemNum = CDV->getNumElements();
851 ElemTy = CDV->getElementType();
852 } else if (CV || CAZ) {
853 VectorType* VTy = dyn_cast<VectorType>(C->getType());
854 elemNum = VTy->getNumElements();
855 ElemTy = VTy->getElementType();
857 llvm_unreachable("Unknown constant vector type!");
860 Result.AggregateVal.resize(elemNum);
861 // Check if vector holds floats.
862 if(ElemTy->isFloatTy()) {
864 GenericValue floatZero;
865 floatZero.FloatVal = 0.f;
866 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
871 for (unsigned i = 0; i < elemNum; ++i)
872 if (!isa<UndefValue>(CV->getOperand(i)))
873 Result.AggregateVal[i].FloatVal = cast<ConstantFP>(
874 CV->getOperand(i))->getValueAPF().convertToFloat();
878 for (unsigned i = 0; i < elemNum; ++i)
879 Result.AggregateVal[i].FloatVal = CDV->getElementAsFloat(i);
883 // Check if vector holds doubles.
884 if (ElemTy->isDoubleTy()) {
886 GenericValue doubleZero;
887 doubleZero.DoubleVal = 0.0;
888 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
893 for (unsigned i = 0; i < elemNum; ++i)
894 if (!isa<UndefValue>(CV->getOperand(i)))
895 Result.AggregateVal[i].DoubleVal = cast<ConstantFP>(
896 CV->getOperand(i))->getValueAPF().convertToDouble();
900 for (unsigned i = 0; i < elemNum; ++i)
901 Result.AggregateVal[i].DoubleVal = CDV->getElementAsDouble(i);
905 // Check if vector holds integers.
906 if (ElemTy->isIntegerTy()) {
908 GenericValue intZero;
909 intZero.IntVal = APInt(ElemTy->getScalarSizeInBits(), 0ull);
910 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
915 for (unsigned i = 0; i < elemNum; ++i)
916 if (!isa<UndefValue>(CV->getOperand(i)))
917 Result.AggregateVal[i].IntVal = cast<ConstantInt>(
918 CV->getOperand(i))->getValue();
920 Result.AggregateVal[i].IntVal =
921 APInt(CV->getOperand(i)->getType()->getPrimitiveSizeInBits(), 0);
926 for (unsigned i = 0; i < elemNum; ++i)
927 Result.AggregateVal[i].IntVal = APInt(
928 CDV->getElementType()->getPrimitiveSizeInBits(),
929 CDV->getElementAsInteger(i));
933 llvm_unreachable("Unknown constant pointer type!");
938 SmallString<256> Msg;
939 raw_svector_ostream OS(Msg);
940 OS << "ERROR: Constant unimplemented for type: " << *C->getType();
941 report_fatal_error(OS.str());
947 /// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
948 /// with the integer held in IntVal.
949 static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
950 unsigned StoreBytes) {
951 assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!");
952 const uint8_t *Src = (const uint8_t *)IntVal.getRawData();
954 if (sys::IsLittleEndianHost) {
955 // Little-endian host - the source is ordered from LSB to MSB. Order the
956 // destination from LSB to MSB: Do a straight copy.
957 memcpy(Dst, Src, StoreBytes);
959 // Big-endian host - the source is an array of 64 bit words ordered from
960 // LSW to MSW. Each word is ordered from MSB to LSB. Order the destination
961 // from MSB to LSB: Reverse the word order, but not the bytes in a word.
962 while (StoreBytes > sizeof(uint64_t)) {
963 StoreBytes -= sizeof(uint64_t);
964 // May not be aligned so use memcpy.
965 memcpy(Dst + StoreBytes, Src, sizeof(uint64_t));
966 Src += sizeof(uint64_t);
969 memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes);
973 void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
974 GenericValue *Ptr, Type *Ty) {
975 const unsigned StoreBytes = getDataLayout()->getTypeStoreSize(Ty);
977 switch (Ty->getTypeID()) {
979 dbgs() << "Cannot store value of type " << *Ty << "!\n";
981 case Type::IntegerTyID:
982 StoreIntToMemory(Val.IntVal, (uint8_t*)Ptr, StoreBytes);
984 case Type::FloatTyID:
985 *((float*)Ptr) = Val.FloatVal;
987 case Type::DoubleTyID:
988 *((double*)Ptr) = Val.DoubleVal;
990 case Type::X86_FP80TyID:
991 memcpy(Ptr, Val.IntVal.getRawData(), 10);
993 case Type::PointerTyID:
994 // Ensure 64 bit target pointers are fully initialized on 32 bit hosts.
995 if (StoreBytes != sizeof(PointerTy))
996 memset(&(Ptr->PointerVal), 0, StoreBytes);
998 *((PointerTy*)Ptr) = Val.PointerVal;
1000 case Type::VectorTyID:
1001 for (unsigned i = 0; i < Val.AggregateVal.size(); ++i) {
1002 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
1003 *(((double*)Ptr)+i) = Val.AggregateVal[i].DoubleVal;
1004 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
1005 *(((float*)Ptr)+i) = Val.AggregateVal[i].FloatVal;
1006 if (cast<VectorType>(Ty)->getElementType()->isIntegerTy()) {
1007 unsigned numOfBytes =(Val.AggregateVal[i].IntVal.getBitWidth()+7)/8;
1008 StoreIntToMemory(Val.AggregateVal[i].IntVal,
1009 (uint8_t*)Ptr + numOfBytes*i, numOfBytes);
1015 if (sys::IsLittleEndianHost != getDataLayout()->isLittleEndian())
1016 // Host and target are different endian - reverse the stored bytes.
1017 std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
1020 /// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
1021 /// from Src into IntVal, which is assumed to be wide enough and to hold zero.
1022 static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
1023 assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
1024 uint8_t *Dst = reinterpret_cast<uint8_t *>(
1025 const_cast<uint64_t *>(IntVal.getRawData()));
1027 if (sys::IsLittleEndianHost)
1028 // Little-endian host - the destination must be ordered from LSB to MSB.
1029 // The source is ordered from LSB to MSB: Do a straight copy.
1030 memcpy(Dst, Src, LoadBytes);
1032 // Big-endian - the destination is an array of 64 bit words ordered from
1033 // LSW to MSW. Each word must be ordered from MSB to LSB. The source is
1034 // ordered from MSB to LSB: Reverse the word order, but not the bytes in
1036 while (LoadBytes > sizeof(uint64_t)) {
1037 LoadBytes -= sizeof(uint64_t);
1038 // May not be aligned so use memcpy.
1039 memcpy(Dst, Src + LoadBytes, sizeof(uint64_t));
1040 Dst += sizeof(uint64_t);
1043 memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
1049 void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
1052 const unsigned LoadBytes = getDataLayout()->getTypeStoreSize(Ty);
1054 switch (Ty->getTypeID()) {
1055 case Type::IntegerTyID:
1056 // An APInt with all words initially zero.
1057 Result.IntVal = APInt(cast<IntegerType>(Ty)->getBitWidth(), 0);
1058 LoadIntFromMemory(Result.IntVal, (uint8_t*)Ptr, LoadBytes);
1060 case Type::FloatTyID:
1061 Result.FloatVal = *((float*)Ptr);
1063 case Type::DoubleTyID:
1064 Result.DoubleVal = *((double*)Ptr);
1066 case Type::PointerTyID:
1067 Result.PointerVal = *((PointerTy*)Ptr);
1069 case Type::X86_FP80TyID: {
1070 // This is endian dependent, but it will only work on x86 anyway.
1071 // FIXME: Will not trap if loading a signaling NaN.
1074 Result.IntVal = APInt(80, y);
1077 case Type::VectorTyID: {
1078 const VectorType *VT = cast<VectorType>(Ty);
1079 const Type *ElemT = VT->getElementType();
1080 const unsigned numElems = VT->getNumElements();
1081 if (ElemT->isFloatTy()) {
1082 Result.AggregateVal.resize(numElems);
1083 for (unsigned i = 0; i < numElems; ++i)
1084 Result.AggregateVal[i].FloatVal = *((float*)Ptr+i);
1086 if (ElemT->isDoubleTy()) {
1087 Result.AggregateVal.resize(numElems);
1088 for (unsigned i = 0; i < numElems; ++i)
1089 Result.AggregateVal[i].DoubleVal = *((double*)Ptr+i);
1091 if (ElemT->isIntegerTy()) {
1092 GenericValue intZero;
1093 const unsigned elemBitWidth = cast<IntegerType>(ElemT)->getBitWidth();
1094 intZero.IntVal = APInt(elemBitWidth, 0);
1095 Result.AggregateVal.resize(numElems, intZero);
1096 for (unsigned i = 0; i < numElems; ++i)
1097 LoadIntFromMemory(Result.AggregateVal[i].IntVal,
1098 (uint8_t*)Ptr+((elemBitWidth+7)/8)*i, (elemBitWidth+7)/8);
1103 SmallString<256> Msg;
1104 raw_svector_ostream OS(Msg);
1105 OS << "Cannot load value of type " << *Ty << "!";
1106 report_fatal_error(OS.str());
1110 void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
1111 DEBUG(dbgs() << "JIT: Initializing " << Addr << " ");
1112 DEBUG(Init->dump());
1113 if (isa<UndefValue>(Init))
1116 if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
1117 unsigned ElementSize =
1118 getDataLayout()->getTypeAllocSize(CP->getType()->getElementType());
1119 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
1120 InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
1124 if (isa<ConstantAggregateZero>(Init)) {
1125 memset(Addr, 0, (size_t)getDataLayout()->getTypeAllocSize(Init->getType()));
1129 if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
1130 unsigned ElementSize =
1131 getDataLayout()->getTypeAllocSize(CPA->getType()->getElementType());
1132 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
1133 InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
1137 if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
1138 const StructLayout *SL =
1139 getDataLayout()->getStructLayout(cast<StructType>(CPS->getType()));
1140 for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
1141 InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
1145 if (const ConstantDataSequential *CDS =
1146 dyn_cast<ConstantDataSequential>(Init)) {
1147 // CDS is already laid out in host memory order.
1148 StringRef Data = CDS->getRawDataValues();
1149 memcpy(Addr, Data.data(), Data.size());
1153 if (Init->getType()->isFirstClassType()) {
1154 GenericValue Val = getConstantValue(Init);
1155 StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
1159 DEBUG(dbgs() << "Bad Type: " << *Init->getType() << "\n");
1160 llvm_unreachable("Unknown constant type to initialize memory with!");
1163 /// EmitGlobals - Emit all of the global variables to memory, storing their
1164 /// addresses into GlobalAddress. This must make sure to copy the contents of
1165 /// their initializers into the memory.
1166 void ExecutionEngine::emitGlobals() {
1167 // Loop over all of the global variables in the program, allocating the memory
1168 // to hold them. If there is more than one module, do a prepass over globals
1169 // to figure out how the different modules should link together.
1170 std::map<std::pair<std::string, Type*>,
1171 const GlobalValue*> LinkedGlobalsMap;
1173 if (Modules.size() != 1) {
1174 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1175 Module &M = *Modules[m];
1176 for (const auto &GV : M.globals()) {
1177 if (GV.hasLocalLinkage() || GV.isDeclaration() ||
1178 GV.hasAppendingLinkage() || !GV.hasName())
1179 continue;// Ignore external globals and globals with internal linkage.
1181 const GlobalValue *&GVEntry =
1182 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())];
1184 // If this is the first time we've seen this global, it is the canonical
1191 // If the existing global is strong, never replace it.
1192 if (GVEntry->hasExternalLinkage())
1195 // Otherwise, we know it's linkonce/weak, replace it if this is a strong
1196 // symbol. FIXME is this right for common?
1197 if (GV.hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
1203 std::vector<const GlobalValue*> NonCanonicalGlobals;
1204 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1205 Module &M = *Modules[m];
1206 for (const auto &GV : M.globals()) {
1207 // In the multi-module case, see what this global maps to.
1208 if (!LinkedGlobalsMap.empty()) {
1209 if (const GlobalValue *GVEntry =
1210 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())]) {
1211 // If something else is the canonical global, ignore this one.
1212 if (GVEntry != &GV) {
1213 NonCanonicalGlobals.push_back(&GV);
1219 if (!GV.isDeclaration()) {
1220 addGlobalMapping(&GV, getMemoryForGV(&GV));
1222 // External variable reference. Try to use the dynamic loader to
1223 // get a pointer to it.
1225 sys::DynamicLibrary::SearchForAddressOfSymbol(GV.getName()))
1226 addGlobalMapping(&GV, SymAddr);
1228 report_fatal_error("Could not resolve external global address: "
1234 // If there are multiple modules, map the non-canonical globals to their
1235 // canonical location.
1236 if (!NonCanonicalGlobals.empty()) {
1237 for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
1238 const GlobalValue *GV = NonCanonicalGlobals[i];
1239 const GlobalValue *CGV =
1240 LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
1241 void *Ptr = getPointerToGlobalIfAvailable(CGV);
1242 assert(Ptr && "Canonical global wasn't codegen'd!");
1243 addGlobalMapping(GV, Ptr);
1247 // Now that all of the globals are set up in memory, loop through them all
1248 // and initialize their contents.
1249 for (const auto &GV : M.globals()) {
1250 if (!GV.isDeclaration()) {
1251 if (!LinkedGlobalsMap.empty()) {
1252 if (const GlobalValue *GVEntry =
1253 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())])
1254 if (GVEntry != &GV) // Not the canonical variable.
1257 EmitGlobalVariable(&GV);
1263 // EmitGlobalVariable - This method emits the specified global variable to the
1264 // address specified in GlobalAddresses, or allocates new memory if it's not
1265 // already in the map.
1266 void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
1267 void *GA = getPointerToGlobalIfAvailable(GV);
1270 // If it's not already specified, allocate memory for the global.
1271 GA = getMemoryForGV(GV);
1273 // If we failed to allocate memory for this global, return.
1276 addGlobalMapping(GV, GA);
1279 // Don't initialize if it's thread local, let the client do it.
1280 if (!GV->isThreadLocal())
1281 InitializeMemory(GV->getInitializer(), GA);
1283 Type *ElTy = GV->getType()->getElementType();
1284 size_t GVSize = (size_t)getDataLayout()->getTypeAllocSize(ElTy);
1285 NumInitBytes += (unsigned)GVSize;
1289 ExecutionEngineState::ExecutionEngineState(ExecutionEngine &EE)
1290 : EE(EE), GlobalAddressMap(this) {
1294 ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
1295 return &EES->EE.lock;
1298 void ExecutionEngineState::AddressMapConfig::onDelete(ExecutionEngineState *EES,
1299 const GlobalValue *Old) {
1300 void *OldVal = EES->GlobalAddressMap.lookup(Old);
1301 EES->GlobalAddressReverseMap.erase(OldVal);
1304 void ExecutionEngineState::AddressMapConfig::onRAUW(ExecutionEngineState *,
1305 const GlobalValue *,
1306 const GlobalValue *) {
1307 llvm_unreachable("The ExecutionEngine doesn't know how to handle a"
1308 " RAUW on a value it has a global mapping for.");