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