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/ObjectBuffer.h"
20 #include "llvm/ExecutionEngine/ObjectCache.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/DerivedTypes.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/IR/Operator.h"
26 #include "llvm/IR/ValueHandle.h"
27 #include "llvm/Object/Archive.h"
28 #include "llvm/Object/ObjectFile.h"
29 #include "llvm/Support/Debug.h"
30 #include "llvm/Support/DynamicLibrary.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/Host.h"
33 #include "llvm/Support/MutexGuard.h"
34 #include "llvm/Support/TargetRegistry.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/Target/TargetMachine.h"
41 #define DEBUG_TYPE "jit"
43 STATISTIC(NumInitBytes, "Number of bytes of global vars initialized");
44 STATISTIC(NumGlobals , "Number of global vars initialized");
46 // Pin the vtable to this file.
47 void ObjectCache::anchor() {}
48 void ObjectBuffer::anchor() {}
49 void ObjectBufferStream::anchor() {}
51 ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
52 std::unique_ptr<Module> M, std::string *ErrorStr,
53 RTDyldMemoryManager *MCJMM, std::unique_ptr<TargetMachine> TM) = nullptr;
54 ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
55 std::string *ErrorStr) =nullptr;
57 ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
59 LazyFunctionCreator(nullptr) {
60 CompilingLazily = false;
61 GVCompilationDisabled = false;
62 SymbolSearchingDisabled = false;
64 // IR module verification is enabled by default in debug builds, and disabled
65 // by default in release builds.
69 VerifyModules = false;
72 assert(M && "Module is null?");
73 Modules.push_back(std::move(M));
76 ExecutionEngine::~ExecutionEngine() {
77 clearAllGlobalMappings();
81 /// \brief Helper class which uses a value handler to automatically deletes the
82 /// memory block when the GlobalVariable is destroyed.
83 class GVMemoryBlock : public CallbackVH {
84 GVMemoryBlock(const GlobalVariable *GV)
85 : CallbackVH(const_cast<GlobalVariable*>(GV)) {}
88 /// \brief Returns the address the GlobalVariable should be written into. The
89 /// GVMemoryBlock object prefixes that.
90 static char *Create(const GlobalVariable *GV, const DataLayout& TD) {
91 Type *ElTy = GV->getType()->getElementType();
92 size_t GVSize = (size_t)TD.getTypeAllocSize(ElTy);
93 void *RawMemory = ::operator new(
94 RoundUpToAlignment(sizeof(GVMemoryBlock),
95 TD.getPreferredAlignment(GV))
97 new(RawMemory) GVMemoryBlock(GV);
98 return static_cast<char*>(RawMemory) + sizeof(GVMemoryBlock);
101 void deleted() override {
102 // We allocated with operator new and with some extra memory hanging off the
103 // end, so don't just delete this. I'm not sure if this is actually
105 this->~GVMemoryBlock();
106 ::operator delete(this);
109 } // anonymous namespace
111 char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) {
112 return GVMemoryBlock::Create(GV, *getDataLayout());
115 void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) {
116 llvm_unreachable("ExecutionEngine subclass doesn't implement addObjectFile.");
120 ExecutionEngine::addObjectFile(object::OwningBinary<object::ObjectFile> O) {
121 llvm_unreachable("ExecutionEngine subclass doesn't implement addObjectFile.");
124 void ExecutionEngine::addArchive(object::OwningBinary<object::Archive> A) {
125 llvm_unreachable("ExecutionEngine subclass doesn't implement addArchive.");
128 bool ExecutionEngine::removeModule(Module *M) {
129 for (auto I = Modules.begin(), E = Modules.end(); I != E; ++I) {
130 Module *Found = I->get();
134 clearGlobalMappingsFromModule(M);
141 Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
142 for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
143 if (Function *F = Modules[i]->getFunction(FnName))
150 void *ExecutionEngineState::RemoveMapping(const GlobalValue *ToUnmap) {
151 GlobalAddressMapTy::iterator I = GlobalAddressMap.find(ToUnmap);
154 // FIXME: This is silly, we shouldn't end up with a mapping -> 0 in the
156 if (I == GlobalAddressMap.end())
160 GlobalAddressMap.erase(I);
163 GlobalAddressReverseMap.erase(OldVal);
167 void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
168 MutexGuard locked(lock);
170 DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
171 << "\' to [" << Addr << "]\n";);
172 void *&CurVal = EEState.getGlobalAddressMap()[GV];
173 assert((!CurVal || !Addr) && "GlobalMapping already established!");
176 // If we are using the reverse mapping, add it too.
177 if (!EEState.getGlobalAddressReverseMap().empty()) {
178 AssertingVH<const GlobalValue> &V =
179 EEState.getGlobalAddressReverseMap()[Addr];
180 assert((!V || !GV) && "GlobalMapping already established!");
185 void ExecutionEngine::clearAllGlobalMappings() {
186 MutexGuard locked(lock);
188 EEState.getGlobalAddressMap().clear();
189 EEState.getGlobalAddressReverseMap().clear();
192 void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
193 MutexGuard locked(lock);
195 for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
196 EEState.RemoveMapping(FI);
197 for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
199 EEState.RemoveMapping(GI);
202 void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
203 MutexGuard locked(lock);
205 ExecutionEngineState::GlobalAddressMapTy &Map =
206 EEState.getGlobalAddressMap();
208 // Deleting from the mapping?
210 return EEState.RemoveMapping(GV);
212 void *&CurVal = Map[GV];
213 void *OldVal = CurVal;
215 if (CurVal && !EEState.getGlobalAddressReverseMap().empty())
216 EEState.getGlobalAddressReverseMap().erase(CurVal);
219 // If we are using the reverse mapping, add it too.
220 if (!EEState.getGlobalAddressReverseMap().empty()) {
221 AssertingVH<const GlobalValue> &V =
222 EEState.getGlobalAddressReverseMap()[Addr];
223 assert((!V || !GV) && "GlobalMapping already established!");
229 void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
230 MutexGuard locked(lock);
232 ExecutionEngineState::GlobalAddressMapTy::iterator I =
233 EEState.getGlobalAddressMap().find(GV);
234 return I != EEState.getGlobalAddressMap().end() ? I->second : nullptr;
237 const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
238 MutexGuard locked(lock);
240 // If we haven't computed the reverse mapping yet, do so first.
241 if (EEState.getGlobalAddressReverseMap().empty()) {
242 for (ExecutionEngineState::GlobalAddressMapTy::iterator
243 I = EEState.getGlobalAddressMap().begin(),
244 E = EEState.getGlobalAddressMap().end(); I != E; ++I)
245 EEState.getGlobalAddressReverseMap().insert(std::make_pair(
246 I->second, I->first));
249 std::map<void *, AssertingVH<const GlobalValue> >::iterator I =
250 EEState.getGlobalAddressReverseMap().find(Addr);
251 return I != EEState.getGlobalAddressReverseMap().end() ? I->second : nullptr;
256 std::unique_ptr<char[]> Array;
257 std::vector<std::unique_ptr<char[]>> Values;
259 /// Turn a vector of strings into a nice argv style array of pointers to null
260 /// terminated strings.
261 void *reset(LLVMContext &C, ExecutionEngine *EE,
262 const std::vector<std::string> &InputArgv);
264 } // anonymous namespace
265 void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
266 const std::vector<std::string> &InputArgv) {
267 Values.clear(); // Free the old contents.
268 Values.reserve(InputArgv.size());
269 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
270 Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
272 DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
273 Type *SBytePtr = Type::getInt8PtrTy(C);
275 for (unsigned i = 0; i != InputArgv.size(); ++i) {
276 unsigned Size = InputArgv[i].size()+1;
277 auto Dest = make_unique<char[]>(Size);
278 DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest.get() << "\n");
280 std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest.get());
283 // Endian safe: Array[i] = (PointerTy)Dest;
284 EE->StoreValueToMemory(PTOGV(Dest.get()),
285 (GenericValue*)(&Array[i*PtrSize]), SBytePtr);
286 Values.push_back(std::move(Dest));
290 EE->StoreValueToMemory(PTOGV(nullptr),
291 (GenericValue*)(&Array[InputArgv.size()*PtrSize]),
296 void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
298 const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
299 GlobalVariable *GV = module.getNamedGlobal(Name);
301 // If this global has internal linkage, or if it has a use, then it must be
302 // an old-style (llvmgcc3) static ctor with __main linked in and in use. If
303 // this is the case, don't execute any of the global ctors, __main will do
305 if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
307 // Should be an array of '{ i32, void ()* }' structs. The first value is
308 // the init priority, which we ignore.
309 ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
312 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
313 ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));
316 Constant *FP = CS->getOperand(1);
317 if (FP->isNullValue())
318 continue; // Found a sentinal value, ignore.
320 // Strip off constant expression casts.
321 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
323 FP = CE->getOperand(0);
325 // Execute the ctor/dtor function!
326 if (Function *F = dyn_cast<Function>(FP))
327 runFunction(F, std::vector<GenericValue>());
329 // FIXME: It is marginally lame that we just do nothing here if we see an
330 // entry we don't recognize. It might not be unreasonable for the verifier
331 // to not even allow this and just assert here.
335 void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
336 // Execute global ctors/dtors for each module in the program.
337 for (std::unique_ptr<Module> &M : Modules)
338 runStaticConstructorsDestructors(*M, isDtors);
342 /// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
343 static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
344 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
345 for (unsigned i = 0; i < PtrSize; ++i)
346 if (*(i + (uint8_t*)Loc))
352 int ExecutionEngine::runFunctionAsMain(Function *Fn,
353 const std::vector<std::string> &argv,
354 const char * const * envp) {
355 std::vector<GenericValue> GVArgs;
357 GVArgc.IntVal = APInt(32, argv.size());
360 unsigned NumArgs = Fn->getFunctionType()->getNumParams();
361 FunctionType *FTy = Fn->getFunctionType();
362 Type* PPInt8Ty = Type::getInt8PtrTy(Fn->getContext())->getPointerTo();
364 // Check the argument types.
366 report_fatal_error("Invalid number of arguments of main() supplied");
367 if (NumArgs >= 3 && FTy->getParamType(2) != PPInt8Ty)
368 report_fatal_error("Invalid type for third argument of main() supplied");
369 if (NumArgs >= 2 && FTy->getParamType(1) != PPInt8Ty)
370 report_fatal_error("Invalid type for second argument of main() supplied");
371 if (NumArgs >= 1 && !FTy->getParamType(0)->isIntegerTy(32))
372 report_fatal_error("Invalid type for first argument of main() supplied");
373 if (!FTy->getReturnType()->isIntegerTy() &&
374 !FTy->getReturnType()->isVoidTy())
375 report_fatal_error("Invalid return type of main() supplied");
380 GVArgs.push_back(GVArgc); // Arg #0 = argc.
383 GVArgs.push_back(PTOGV(CArgv.reset(Fn->getContext(), this, argv)));
384 assert(!isTargetNullPtr(this, GVTOP(GVArgs[1])) &&
385 "argv[0] was null after CreateArgv");
387 std::vector<std::string> EnvVars;
388 for (unsigned i = 0; envp[i]; ++i)
389 EnvVars.push_back(envp[i]);
391 GVArgs.push_back(PTOGV(CEnv.reset(Fn->getContext(), this, EnvVars)));
396 return runFunction(Fn, GVArgs).IntVal.getZExtValue();
399 void EngineBuilder::InitEngine() {
400 WhichEngine = EngineKind::Either;
402 OptLevel = CodeGenOpt::Default;
404 Options = TargetOptions();
405 RelocModel = Reloc::Default;
406 CMModel = CodeModel::JITDefault;
408 // IR module verification is enabled by default in debug builds, and disabled
409 // by default in release builds.
411 VerifyModules = true;
413 VerifyModules = false;
417 ExecutionEngine *EngineBuilder::create(TargetMachine *TM) {
418 std::unique_ptr<TargetMachine> TheTM(TM); // Take ownership.
420 // Make sure we can resolve symbols in the program as well. The zero arg
421 // to the function tells DynamicLibrary to load the program, not a library.
422 if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr, ErrorStr))
425 // If the user specified a memory manager but didn't specify which engine to
426 // create, we assume they only want the JIT, and we fail if they only want
429 if (WhichEngine & EngineKind::JIT)
430 WhichEngine = EngineKind::JIT;
433 *ErrorStr = "Cannot create an interpreter with a memory manager.";
438 // Unless the interpreter was explicitly selected or the JIT is not linked,
440 if ((WhichEngine & EngineKind::JIT) && TheTM) {
441 Triple TT(M->getTargetTriple());
442 if (!TM->getTarget().hasJIT()) {
443 errs() << "WARNING: This target JIT is not designed for the host"
444 << " you are running. If bad things happen, please choose"
445 << " a different -march switch.\n";
448 ExecutionEngine *EE = nullptr;
449 if (ExecutionEngine::MCJITCtor)
450 EE = ExecutionEngine::MCJITCtor(std::move(M), ErrorStr, MCJMM,
453 EE->setVerifyModules(VerifyModules);
458 // If we can't make a JIT and we didn't request one specifically, try making
459 // an interpreter instead.
460 if (WhichEngine & EngineKind::Interpreter) {
461 if (ExecutionEngine::InterpCtor)
462 return ExecutionEngine::InterpCtor(std::move(M), ErrorStr);
464 *ErrorStr = "Interpreter has not been linked in.";
468 if ((WhichEngine & EngineKind::JIT) && !ExecutionEngine::MCJITCtor) {
470 *ErrorStr = "JIT has not been linked in.";
476 void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
477 if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
478 return getPointerToFunction(F);
480 MutexGuard locked(lock);
481 if (void *P = EEState.getGlobalAddressMap()[GV])
484 // Global variable might have been added since interpreter started.
485 if (GlobalVariable *GVar =
486 const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
487 EmitGlobalVariable(GVar);
489 llvm_unreachable("Global hasn't had an address allocated yet!");
491 return EEState.getGlobalAddressMap()[GV];
494 /// \brief Converts a Constant* into a GenericValue, including handling of
495 /// ConstantExpr values.
496 GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
497 // If its undefined, return the garbage.
498 if (isa<UndefValue>(C)) {
500 switch (C->getType()->getTypeID()) {
503 case Type::IntegerTyID:
504 case Type::X86_FP80TyID:
505 case Type::FP128TyID:
506 case Type::PPC_FP128TyID:
507 // Although the value is undefined, we still have to construct an APInt
508 // with the correct bit width.
509 Result.IntVal = APInt(C->getType()->getPrimitiveSizeInBits(), 0);
511 case Type::StructTyID: {
512 // if the whole struct is 'undef' just reserve memory for the value.
513 if(StructType *STy = dyn_cast<StructType>(C->getType())) {
514 unsigned int elemNum = STy->getNumElements();
515 Result.AggregateVal.resize(elemNum);
516 for (unsigned int i = 0; i < elemNum; ++i) {
517 Type *ElemTy = STy->getElementType(i);
518 if (ElemTy->isIntegerTy())
519 Result.AggregateVal[i].IntVal =
520 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
521 else if (ElemTy->isAggregateType()) {
522 const Constant *ElemUndef = UndefValue::get(ElemTy);
523 Result.AggregateVal[i] = getConstantValue(ElemUndef);
529 case Type::VectorTyID:
530 // if the whole vector is 'undef' just reserve memory for the value.
531 const VectorType* VTy = dyn_cast<VectorType>(C->getType());
532 const Type *ElemTy = VTy->getElementType();
533 unsigned int elemNum = VTy->getNumElements();
534 Result.AggregateVal.resize(elemNum);
535 if (ElemTy->isIntegerTy())
536 for (unsigned int i = 0; i < elemNum; ++i)
537 Result.AggregateVal[i].IntVal =
538 APInt(ElemTy->getPrimitiveSizeInBits(), 0);
544 // Otherwise, if the value is a ConstantExpr...
545 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
546 Constant *Op0 = CE->getOperand(0);
547 switch (CE->getOpcode()) {
548 case Instruction::GetElementPtr: {
550 GenericValue Result = getConstantValue(Op0);
551 APInt Offset(DL->getPointerSizeInBits(), 0);
552 cast<GEPOperator>(CE)->accumulateConstantOffset(*DL, Offset);
554 char* tmp = (char*) Result.PointerVal;
555 Result = PTOGV(tmp + Offset.getSExtValue());
558 case Instruction::Trunc: {
559 GenericValue GV = getConstantValue(Op0);
560 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
561 GV.IntVal = GV.IntVal.trunc(BitWidth);
564 case Instruction::ZExt: {
565 GenericValue GV = getConstantValue(Op0);
566 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
567 GV.IntVal = GV.IntVal.zext(BitWidth);
570 case Instruction::SExt: {
571 GenericValue GV = getConstantValue(Op0);
572 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
573 GV.IntVal = GV.IntVal.sext(BitWidth);
576 case Instruction::FPTrunc: {
578 GenericValue GV = getConstantValue(Op0);
579 GV.FloatVal = float(GV.DoubleVal);
582 case Instruction::FPExt:{
584 GenericValue GV = getConstantValue(Op0);
585 GV.DoubleVal = double(GV.FloatVal);
588 case Instruction::UIToFP: {
589 GenericValue GV = getConstantValue(Op0);
590 if (CE->getType()->isFloatTy())
591 GV.FloatVal = float(GV.IntVal.roundToDouble());
592 else if (CE->getType()->isDoubleTy())
593 GV.DoubleVal = GV.IntVal.roundToDouble();
594 else if (CE->getType()->isX86_FP80Ty()) {
595 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
596 (void)apf.convertFromAPInt(GV.IntVal,
598 APFloat::rmNearestTiesToEven);
599 GV.IntVal = apf.bitcastToAPInt();
603 case Instruction::SIToFP: {
604 GenericValue GV = getConstantValue(Op0);
605 if (CE->getType()->isFloatTy())
606 GV.FloatVal = float(GV.IntVal.signedRoundToDouble());
607 else if (CE->getType()->isDoubleTy())
608 GV.DoubleVal = GV.IntVal.signedRoundToDouble();
609 else if (CE->getType()->isX86_FP80Ty()) {
610 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
611 (void)apf.convertFromAPInt(GV.IntVal,
613 APFloat::rmNearestTiesToEven);
614 GV.IntVal = apf.bitcastToAPInt();
618 case Instruction::FPToUI: // double->APInt conversion handles sign
619 case Instruction::FPToSI: {
620 GenericValue GV = getConstantValue(Op0);
621 uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
622 if (Op0->getType()->isFloatTy())
623 GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth);
624 else if (Op0->getType()->isDoubleTy())
625 GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
626 else if (Op0->getType()->isX86_FP80Ty()) {
627 APFloat apf = APFloat(APFloat::x87DoubleExtended, GV.IntVal);
630 (void)apf.convertToInteger(&v, BitWidth,
631 CE->getOpcode()==Instruction::FPToSI,
632 APFloat::rmTowardZero, &ignored);
633 GV.IntVal = v; // endian?
637 case Instruction::PtrToInt: {
638 GenericValue GV = getConstantValue(Op0);
639 uint32_t PtrWidth = DL->getTypeSizeInBits(Op0->getType());
640 assert(PtrWidth <= 64 && "Bad pointer width");
641 GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
642 uint32_t IntWidth = DL->getTypeSizeInBits(CE->getType());
643 GV.IntVal = GV.IntVal.zextOrTrunc(IntWidth);
646 case Instruction::IntToPtr: {
647 GenericValue GV = getConstantValue(Op0);
648 uint32_t PtrWidth = DL->getTypeSizeInBits(CE->getType());
649 GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
650 assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
651 GV.PointerVal = PointerTy(uintptr_t(GV.IntVal.getZExtValue()));
654 case Instruction::BitCast: {
655 GenericValue GV = getConstantValue(Op0);
656 Type* DestTy = CE->getType();
657 switch (Op0->getType()->getTypeID()) {
658 default: llvm_unreachable("Invalid bitcast operand");
659 case Type::IntegerTyID:
660 assert(DestTy->isFloatingPointTy() && "invalid bitcast");
661 if (DestTy->isFloatTy())
662 GV.FloatVal = GV.IntVal.bitsToFloat();
663 else if (DestTy->isDoubleTy())
664 GV.DoubleVal = GV.IntVal.bitsToDouble();
666 case Type::FloatTyID:
667 assert(DestTy->isIntegerTy(32) && "Invalid bitcast");
668 GV.IntVal = APInt::floatToBits(GV.FloatVal);
670 case Type::DoubleTyID:
671 assert(DestTy->isIntegerTy(64) && "Invalid bitcast");
672 GV.IntVal = APInt::doubleToBits(GV.DoubleVal);
674 case Type::PointerTyID:
675 assert(DestTy->isPointerTy() && "Invalid bitcast");
676 break; // getConstantValue(Op0) above already converted it
680 case Instruction::Add:
681 case Instruction::FAdd:
682 case Instruction::Sub:
683 case Instruction::FSub:
684 case Instruction::Mul:
685 case Instruction::FMul:
686 case Instruction::UDiv:
687 case Instruction::SDiv:
688 case Instruction::URem:
689 case Instruction::SRem:
690 case Instruction::And:
691 case Instruction::Or:
692 case Instruction::Xor: {
693 GenericValue LHS = getConstantValue(Op0);
694 GenericValue RHS = getConstantValue(CE->getOperand(1));
696 switch (CE->getOperand(0)->getType()->getTypeID()) {
697 default: llvm_unreachable("Bad add type!");
698 case Type::IntegerTyID:
699 switch (CE->getOpcode()) {
700 default: llvm_unreachable("Invalid integer opcode");
701 case Instruction::Add: GV.IntVal = LHS.IntVal + RHS.IntVal; break;
702 case Instruction::Sub: GV.IntVal = LHS.IntVal - RHS.IntVal; break;
703 case Instruction::Mul: GV.IntVal = LHS.IntVal * RHS.IntVal; break;
704 case Instruction::UDiv:GV.IntVal = LHS.IntVal.udiv(RHS.IntVal); break;
705 case Instruction::SDiv:GV.IntVal = LHS.IntVal.sdiv(RHS.IntVal); break;
706 case Instruction::URem:GV.IntVal = LHS.IntVal.urem(RHS.IntVal); break;
707 case Instruction::SRem:GV.IntVal = LHS.IntVal.srem(RHS.IntVal); break;
708 case Instruction::And: GV.IntVal = LHS.IntVal & RHS.IntVal; break;
709 case Instruction::Or: GV.IntVal = LHS.IntVal | RHS.IntVal; break;
710 case Instruction::Xor: GV.IntVal = LHS.IntVal ^ RHS.IntVal; break;
713 case Type::FloatTyID:
714 switch (CE->getOpcode()) {
715 default: llvm_unreachable("Invalid float opcode");
716 case Instruction::FAdd:
717 GV.FloatVal = LHS.FloatVal + RHS.FloatVal; break;
718 case Instruction::FSub:
719 GV.FloatVal = LHS.FloatVal - RHS.FloatVal; break;
720 case Instruction::FMul:
721 GV.FloatVal = LHS.FloatVal * RHS.FloatVal; break;
722 case Instruction::FDiv:
723 GV.FloatVal = LHS.FloatVal / RHS.FloatVal; break;
724 case Instruction::FRem:
725 GV.FloatVal = std::fmod(LHS.FloatVal,RHS.FloatVal); break;
728 case Type::DoubleTyID:
729 switch (CE->getOpcode()) {
730 default: llvm_unreachable("Invalid double opcode");
731 case Instruction::FAdd:
732 GV.DoubleVal = LHS.DoubleVal + RHS.DoubleVal; break;
733 case Instruction::FSub:
734 GV.DoubleVal = LHS.DoubleVal - RHS.DoubleVal; break;
735 case Instruction::FMul:
736 GV.DoubleVal = LHS.DoubleVal * RHS.DoubleVal; break;
737 case Instruction::FDiv:
738 GV.DoubleVal = LHS.DoubleVal / RHS.DoubleVal; break;
739 case Instruction::FRem:
740 GV.DoubleVal = std::fmod(LHS.DoubleVal,RHS.DoubleVal); break;
743 case Type::X86_FP80TyID:
744 case Type::PPC_FP128TyID:
745 case Type::FP128TyID: {
746 const fltSemantics &Sem = CE->getOperand(0)->getType()->getFltSemantics();
747 APFloat apfLHS = APFloat(Sem, LHS.IntVal);
748 switch (CE->getOpcode()) {
749 default: llvm_unreachable("Invalid long double opcode");
750 case Instruction::FAdd:
751 apfLHS.add(APFloat(Sem, RHS.IntVal), APFloat::rmNearestTiesToEven);
752 GV.IntVal = apfLHS.bitcastToAPInt();
754 case Instruction::FSub:
755 apfLHS.subtract(APFloat(Sem, RHS.IntVal),
756 APFloat::rmNearestTiesToEven);
757 GV.IntVal = apfLHS.bitcastToAPInt();
759 case Instruction::FMul:
760 apfLHS.multiply(APFloat(Sem, RHS.IntVal),
761 APFloat::rmNearestTiesToEven);
762 GV.IntVal = apfLHS.bitcastToAPInt();
764 case Instruction::FDiv:
765 apfLHS.divide(APFloat(Sem, RHS.IntVal),
766 APFloat::rmNearestTiesToEven);
767 GV.IntVal = apfLHS.bitcastToAPInt();
769 case Instruction::FRem:
770 apfLHS.mod(APFloat(Sem, RHS.IntVal),
771 APFloat::rmNearestTiesToEven);
772 GV.IntVal = apfLHS.bitcastToAPInt();
784 SmallString<256> Msg;
785 raw_svector_ostream OS(Msg);
786 OS << "ConstantExpr not handled: " << *CE;
787 report_fatal_error(OS.str());
790 // Otherwise, we have a simple constant.
792 switch (C->getType()->getTypeID()) {
793 case Type::FloatTyID:
794 Result.FloatVal = cast<ConstantFP>(C)->getValueAPF().convertToFloat();
796 case Type::DoubleTyID:
797 Result.DoubleVal = cast<ConstantFP>(C)->getValueAPF().convertToDouble();
799 case Type::X86_FP80TyID:
800 case Type::FP128TyID:
801 case Type::PPC_FP128TyID:
802 Result.IntVal = cast <ConstantFP>(C)->getValueAPF().bitcastToAPInt();
804 case Type::IntegerTyID:
805 Result.IntVal = cast<ConstantInt>(C)->getValue();
807 case Type::PointerTyID:
808 if (isa<ConstantPointerNull>(C))
809 Result.PointerVal = nullptr;
810 else if (const Function *F = dyn_cast<Function>(C))
811 Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
812 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
813 Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
815 llvm_unreachable("Unknown constant pointer type!");
817 case Type::VectorTyID: {
820 const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
821 const ConstantVector *CV = dyn_cast<ConstantVector>(C);
822 const ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(C);
825 elemNum = CDV->getNumElements();
826 ElemTy = CDV->getElementType();
827 } else if (CV || CAZ) {
828 VectorType* VTy = dyn_cast<VectorType>(C->getType());
829 elemNum = VTy->getNumElements();
830 ElemTy = VTy->getElementType();
832 llvm_unreachable("Unknown constant vector type!");
835 Result.AggregateVal.resize(elemNum);
836 // Check if vector holds floats.
837 if(ElemTy->isFloatTy()) {
839 GenericValue floatZero;
840 floatZero.FloatVal = 0.f;
841 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
846 for (unsigned i = 0; i < elemNum; ++i)
847 if (!isa<UndefValue>(CV->getOperand(i)))
848 Result.AggregateVal[i].FloatVal = cast<ConstantFP>(
849 CV->getOperand(i))->getValueAPF().convertToFloat();
853 for (unsigned i = 0; i < elemNum; ++i)
854 Result.AggregateVal[i].FloatVal = CDV->getElementAsFloat(i);
858 // Check if vector holds doubles.
859 if (ElemTy->isDoubleTy()) {
861 GenericValue doubleZero;
862 doubleZero.DoubleVal = 0.0;
863 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
868 for (unsigned i = 0; i < elemNum; ++i)
869 if (!isa<UndefValue>(CV->getOperand(i)))
870 Result.AggregateVal[i].DoubleVal = cast<ConstantFP>(
871 CV->getOperand(i))->getValueAPF().convertToDouble();
875 for (unsigned i = 0; i < elemNum; ++i)
876 Result.AggregateVal[i].DoubleVal = CDV->getElementAsDouble(i);
880 // Check if vector holds integers.
881 if (ElemTy->isIntegerTy()) {
883 GenericValue intZero;
884 intZero.IntVal = APInt(ElemTy->getScalarSizeInBits(), 0ull);
885 std::fill(Result.AggregateVal.begin(), Result.AggregateVal.end(),
890 for (unsigned i = 0; i < elemNum; ++i)
891 if (!isa<UndefValue>(CV->getOperand(i)))
892 Result.AggregateVal[i].IntVal = cast<ConstantInt>(
893 CV->getOperand(i))->getValue();
895 Result.AggregateVal[i].IntVal =
896 APInt(CV->getOperand(i)->getType()->getPrimitiveSizeInBits(), 0);
901 for (unsigned i = 0; i < elemNum; ++i)
902 Result.AggregateVal[i].IntVal = APInt(
903 CDV->getElementType()->getPrimitiveSizeInBits(),
904 CDV->getElementAsInteger(i));
908 llvm_unreachable("Unknown constant pointer type!");
913 SmallString<256> Msg;
914 raw_svector_ostream OS(Msg);
915 OS << "ERROR: Constant unimplemented for type: " << *C->getType();
916 report_fatal_error(OS.str());
922 /// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
923 /// with the integer held in IntVal.
924 static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst,
925 unsigned StoreBytes) {
926 assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!");
927 const uint8_t *Src = (const uint8_t *)IntVal.getRawData();
929 if (sys::IsLittleEndianHost) {
930 // Little-endian host - the source is ordered from LSB to MSB. Order the
931 // destination from LSB to MSB: Do a straight copy.
932 memcpy(Dst, Src, StoreBytes);
934 // Big-endian host - the source is an array of 64 bit words ordered from
935 // LSW to MSW. Each word is ordered from MSB to LSB. Order the destination
936 // from MSB to LSB: Reverse the word order, but not the bytes in a word.
937 while (StoreBytes > sizeof(uint64_t)) {
938 StoreBytes -= sizeof(uint64_t);
939 // May not be aligned so use memcpy.
940 memcpy(Dst + StoreBytes, Src, sizeof(uint64_t));
941 Src += sizeof(uint64_t);
944 memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes);
948 void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
949 GenericValue *Ptr, Type *Ty) {
950 const unsigned StoreBytes = getDataLayout()->getTypeStoreSize(Ty);
952 switch (Ty->getTypeID()) {
954 dbgs() << "Cannot store value of type " << *Ty << "!\n";
956 case Type::IntegerTyID:
957 StoreIntToMemory(Val.IntVal, (uint8_t*)Ptr, StoreBytes);
959 case Type::FloatTyID:
960 *((float*)Ptr) = Val.FloatVal;
962 case Type::DoubleTyID:
963 *((double*)Ptr) = Val.DoubleVal;
965 case Type::X86_FP80TyID:
966 memcpy(Ptr, Val.IntVal.getRawData(), 10);
968 case Type::PointerTyID:
969 // Ensure 64 bit target pointers are fully initialized on 32 bit hosts.
970 if (StoreBytes != sizeof(PointerTy))
971 memset(&(Ptr->PointerVal), 0, StoreBytes);
973 *((PointerTy*)Ptr) = Val.PointerVal;
975 case Type::VectorTyID:
976 for (unsigned i = 0; i < Val.AggregateVal.size(); ++i) {
977 if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
978 *(((double*)Ptr)+i) = Val.AggregateVal[i].DoubleVal;
979 if (cast<VectorType>(Ty)->getElementType()->isFloatTy())
980 *(((float*)Ptr)+i) = Val.AggregateVal[i].FloatVal;
981 if (cast<VectorType>(Ty)->getElementType()->isIntegerTy()) {
982 unsigned numOfBytes =(Val.AggregateVal[i].IntVal.getBitWidth()+7)/8;
983 StoreIntToMemory(Val.AggregateVal[i].IntVal,
984 (uint8_t*)Ptr + numOfBytes*i, numOfBytes);
990 if (sys::IsLittleEndianHost != getDataLayout()->isLittleEndian())
991 // Host and target are different endian - reverse the stored bytes.
992 std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr);
995 /// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
996 /// from Src into IntVal, which is assumed to be wide enough and to hold zero.
997 static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) {
998 assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
999 uint8_t *Dst = reinterpret_cast<uint8_t *>(
1000 const_cast<uint64_t *>(IntVal.getRawData()));
1002 if (sys::IsLittleEndianHost)
1003 // Little-endian host - the destination must be ordered from LSB to MSB.
1004 // The source is ordered from LSB to MSB: Do a straight copy.
1005 memcpy(Dst, Src, LoadBytes);
1007 // Big-endian - the destination is an array of 64 bit words ordered from
1008 // LSW to MSW. Each word must be ordered from MSB to LSB. The source is
1009 // ordered from MSB to LSB: Reverse the word order, but not the bytes in
1011 while (LoadBytes > sizeof(uint64_t)) {
1012 LoadBytes -= sizeof(uint64_t);
1013 // May not be aligned so use memcpy.
1014 memcpy(Dst, Src + LoadBytes, sizeof(uint64_t));
1015 Dst += sizeof(uint64_t);
1018 memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
1024 void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
1027 const unsigned LoadBytes = getDataLayout()->getTypeStoreSize(Ty);
1029 switch (Ty->getTypeID()) {
1030 case Type::IntegerTyID:
1031 // An APInt with all words initially zero.
1032 Result.IntVal = APInt(cast<IntegerType>(Ty)->getBitWidth(), 0);
1033 LoadIntFromMemory(Result.IntVal, (uint8_t*)Ptr, LoadBytes);
1035 case Type::FloatTyID:
1036 Result.FloatVal = *((float*)Ptr);
1038 case Type::DoubleTyID:
1039 Result.DoubleVal = *((double*)Ptr);
1041 case Type::PointerTyID:
1042 Result.PointerVal = *((PointerTy*)Ptr);
1044 case Type::X86_FP80TyID: {
1045 // This is endian dependent, but it will only work on x86 anyway.
1046 // FIXME: Will not trap if loading a signaling NaN.
1049 Result.IntVal = APInt(80, y);
1052 case Type::VectorTyID: {
1053 const VectorType *VT = cast<VectorType>(Ty);
1054 const Type *ElemT = VT->getElementType();
1055 const unsigned numElems = VT->getNumElements();
1056 if (ElemT->isFloatTy()) {
1057 Result.AggregateVal.resize(numElems);
1058 for (unsigned i = 0; i < numElems; ++i)
1059 Result.AggregateVal[i].FloatVal = *((float*)Ptr+i);
1061 if (ElemT->isDoubleTy()) {
1062 Result.AggregateVal.resize(numElems);
1063 for (unsigned i = 0; i < numElems; ++i)
1064 Result.AggregateVal[i].DoubleVal = *((double*)Ptr+i);
1066 if (ElemT->isIntegerTy()) {
1067 GenericValue intZero;
1068 const unsigned elemBitWidth = cast<IntegerType>(ElemT)->getBitWidth();
1069 intZero.IntVal = APInt(elemBitWidth, 0);
1070 Result.AggregateVal.resize(numElems, intZero);
1071 for (unsigned i = 0; i < numElems; ++i)
1072 LoadIntFromMemory(Result.AggregateVal[i].IntVal,
1073 (uint8_t*)Ptr+((elemBitWidth+7)/8)*i, (elemBitWidth+7)/8);
1078 SmallString<256> Msg;
1079 raw_svector_ostream OS(Msg);
1080 OS << "Cannot load value of type " << *Ty << "!";
1081 report_fatal_error(OS.str());
1085 void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
1086 DEBUG(dbgs() << "JIT: Initializing " << Addr << " ");
1087 DEBUG(Init->dump());
1088 if (isa<UndefValue>(Init))
1091 if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
1092 unsigned ElementSize =
1093 getDataLayout()->getTypeAllocSize(CP->getType()->getElementType());
1094 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
1095 InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
1099 if (isa<ConstantAggregateZero>(Init)) {
1100 memset(Addr, 0, (size_t)getDataLayout()->getTypeAllocSize(Init->getType()));
1104 if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
1105 unsigned ElementSize =
1106 getDataLayout()->getTypeAllocSize(CPA->getType()->getElementType());
1107 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
1108 InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
1112 if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
1113 const StructLayout *SL =
1114 getDataLayout()->getStructLayout(cast<StructType>(CPS->getType()));
1115 for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
1116 InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
1120 if (const ConstantDataSequential *CDS =
1121 dyn_cast<ConstantDataSequential>(Init)) {
1122 // CDS is already laid out in host memory order.
1123 StringRef Data = CDS->getRawDataValues();
1124 memcpy(Addr, Data.data(), Data.size());
1128 if (Init->getType()->isFirstClassType()) {
1129 GenericValue Val = getConstantValue(Init);
1130 StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
1134 DEBUG(dbgs() << "Bad Type: " << *Init->getType() << "\n");
1135 llvm_unreachable("Unknown constant type to initialize memory with!");
1138 /// EmitGlobals - Emit all of the global variables to memory, storing their
1139 /// addresses into GlobalAddress. This must make sure to copy the contents of
1140 /// their initializers into the memory.
1141 void ExecutionEngine::emitGlobals() {
1142 // Loop over all of the global variables in the program, allocating the memory
1143 // to hold them. If there is more than one module, do a prepass over globals
1144 // to figure out how the different modules should link together.
1145 std::map<std::pair<std::string, Type*>,
1146 const GlobalValue*> LinkedGlobalsMap;
1148 if (Modules.size() != 1) {
1149 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1150 Module &M = *Modules[m];
1151 for (const auto &GV : M.globals()) {
1152 if (GV.hasLocalLinkage() || GV.isDeclaration() ||
1153 GV.hasAppendingLinkage() || !GV.hasName())
1154 continue;// Ignore external globals and globals with internal linkage.
1156 const GlobalValue *&GVEntry =
1157 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())];
1159 // If this is the first time we've seen this global, it is the canonical
1166 // If the existing global is strong, never replace it.
1167 if (GVEntry->hasExternalLinkage())
1170 // Otherwise, we know it's linkonce/weak, replace it if this is a strong
1171 // symbol. FIXME is this right for common?
1172 if (GV.hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
1178 std::vector<const GlobalValue*> NonCanonicalGlobals;
1179 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
1180 Module &M = *Modules[m];
1181 for (const auto &GV : M.globals()) {
1182 // In the multi-module case, see what this global maps to.
1183 if (!LinkedGlobalsMap.empty()) {
1184 if (const GlobalValue *GVEntry =
1185 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())]) {
1186 // If something else is the canonical global, ignore this one.
1187 if (GVEntry != &GV) {
1188 NonCanonicalGlobals.push_back(&GV);
1194 if (!GV.isDeclaration()) {
1195 addGlobalMapping(&GV, getMemoryForGV(&GV));
1197 // External variable reference. Try to use the dynamic loader to
1198 // get a pointer to it.
1200 sys::DynamicLibrary::SearchForAddressOfSymbol(GV.getName()))
1201 addGlobalMapping(&GV, SymAddr);
1203 report_fatal_error("Could not resolve external global address: "
1209 // If there are multiple modules, map the non-canonical globals to their
1210 // canonical location.
1211 if (!NonCanonicalGlobals.empty()) {
1212 for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
1213 const GlobalValue *GV = NonCanonicalGlobals[i];
1214 const GlobalValue *CGV =
1215 LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
1216 void *Ptr = getPointerToGlobalIfAvailable(CGV);
1217 assert(Ptr && "Canonical global wasn't codegen'd!");
1218 addGlobalMapping(GV, Ptr);
1222 // Now that all of the globals are set up in memory, loop through them all
1223 // and initialize their contents.
1224 for (const auto &GV : M.globals()) {
1225 if (!GV.isDeclaration()) {
1226 if (!LinkedGlobalsMap.empty()) {
1227 if (const GlobalValue *GVEntry =
1228 LinkedGlobalsMap[std::make_pair(GV.getName(), GV.getType())])
1229 if (GVEntry != &GV) // Not the canonical variable.
1232 EmitGlobalVariable(&GV);
1238 // EmitGlobalVariable - This method emits the specified global variable to the
1239 // address specified in GlobalAddresses, or allocates new memory if it's not
1240 // already in the map.
1241 void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
1242 void *GA = getPointerToGlobalIfAvailable(GV);
1245 // If it's not already specified, allocate memory for the global.
1246 GA = getMemoryForGV(GV);
1248 // If we failed to allocate memory for this global, return.
1251 addGlobalMapping(GV, GA);
1254 // Don't initialize if it's thread local, let the client do it.
1255 if (!GV->isThreadLocal())
1256 InitializeMemory(GV->getInitializer(), GA);
1258 Type *ElTy = GV->getType()->getElementType();
1259 size_t GVSize = (size_t)getDataLayout()->getTypeAllocSize(ElTy);
1260 NumInitBytes += (unsigned)GVSize;
1264 ExecutionEngineState::ExecutionEngineState(ExecutionEngine &EE)
1265 : EE(EE), GlobalAddressMap(this) {
1269 ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
1270 return &EES->EE.lock;
1273 void ExecutionEngineState::AddressMapConfig::onDelete(ExecutionEngineState *EES,
1274 const GlobalValue *Old) {
1275 void *OldVal = EES->GlobalAddressMap.lookup(Old);
1276 EES->GlobalAddressReverseMap.erase(OldVal);
1279 void ExecutionEngineState::AddressMapConfig::onRAUW(ExecutionEngineState *,
1280 const GlobalValue *,
1281 const GlobalValue *) {
1282 llvm_unreachable("The ExecutionEngine doesn't know how to handle a"
1283 " RAUW on a value it has a global mapping for.");