1 //===-- FunctionLoweringInfo.cpp ------------------------------------------===// 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 implements routines for translating functions from LLVM IR into 11 // Machine IR. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/CodeGen/FunctionLoweringInfo.h" 16 #include "llvm/CodeGen/Analysis.h" 17 #include "llvm/CodeGen/MachineFrameInfo.h" 18 #include "llvm/CodeGen/MachineFunction.h" 19 #include "llvm/CodeGen/MachineInstrBuilder.h" 20 #include "llvm/CodeGen/MachineRegisterInfo.h" 21 #include "llvm/CodeGen/TargetFrameLowering.h" 22 #include "llvm/CodeGen/TargetInstrInfo.h" 23 #include "llvm/CodeGen/TargetLowering.h" 24 #include "llvm/CodeGen/TargetRegisterInfo.h" 25 #include "llvm/CodeGen/TargetSubtargetInfo.h" 26 #include "llvm/CodeGen/WinEHFuncInfo.h" 27 #include "llvm/IR/DataLayout.h" 28 #include "llvm/IR/DerivedTypes.h" 29 #include "llvm/IR/Function.h" 30 #include "llvm/IR/Instructions.h" 31 #include "llvm/IR/IntrinsicInst.h" 32 #include "llvm/IR/LLVMContext.h" 33 #include "llvm/IR/Module.h" 34 #include "llvm/Support/Debug.h" 35 #include "llvm/Support/ErrorHandling.h" 36 #include "llvm/Support/MathExtras.h" 37 #include "llvm/Support/raw_ostream.h" 38 #include "llvm/Target/TargetOptions.h" 39 #include <algorithm> 40 using namespace llvm; 41 42 #define DEBUG_TYPE "function-lowering-info" 43 44 /// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by 45 /// PHI nodes or outside of the basic block that defines it, or used by a 46 /// switch or atomic instruction, which may expand to multiple basic blocks. 47 static bool isUsedOutsideOfDefiningBlock(const Instruction *I) { 48 if (I->use_empty()) return false; 49 if (isa<PHINode>(I)) return true; 50 const BasicBlock *BB = I->getParent(); 51 for (const User *U : I->users()) 52 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U)) 53 return true; 54 55 return false; 56 } 57 58 static ISD::NodeType getPreferredExtendForValue(const Value *V) { 59 // For the users of the source value being used for compare instruction, if 60 // the number of signed predicate is greater than unsigned predicate, we 61 // prefer to use SIGN_EXTEND. 62 // 63 // With this optimization, we would be able to reduce some redundant sign or 64 // zero extension instruction, and eventually more machine CSE opportunities 65 // can be exposed. 66 ISD::NodeType ExtendKind = ISD::ANY_EXTEND; 67 unsigned NumOfSigned = 0, NumOfUnsigned = 0; 68 for (const User *U : V->users()) { 69 if (const auto *CI = dyn_cast<CmpInst>(U)) { 70 NumOfSigned += CI->isSigned(); 71 NumOfUnsigned += CI->isUnsigned(); 72 } 73 } 74 if (NumOfSigned > NumOfUnsigned) 75 ExtendKind = ISD::SIGN_EXTEND; 76 77 return ExtendKind; 78 } 79 80 void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, 81 SelectionDAG *DAG) { 82 Fn = &fn; 83 MF = &mf; 84 TLI = MF->getSubtarget().getTargetLowering(); 85 RegInfo = &MF->getRegInfo(); 86 const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering(); 87 unsigned StackAlign = TFI->getStackAlignment(); 88 89 // Check whether the function can return without sret-demotion. 90 SmallVector<ISD::OutputArg, 4> Outs; 91 GetReturnInfo(Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI, 92 mf.getDataLayout()); 93 CanLowerReturn = TLI->CanLowerReturn(Fn->getCallingConv(), *MF, 94 Fn->isVarArg(), Outs, Fn->getContext()); 95 96 // If this personality uses funclets, we need to do a bit more work. 97 DenseMap<const AllocaInst *, TinyPtrVector<int *>> CatchObjects; 98 EHPersonality Personality = classifyEHPersonality( 99 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr); 100 if (isFuncletEHPersonality(Personality)) { 101 // Calculate state numbers if we haven't already. 102 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo(); 103 if (Personality == EHPersonality::MSVC_CXX) 104 calculateWinCXXEHStateNumbers(&fn, EHInfo); 105 else if (isAsynchronousEHPersonality(Personality)) 106 calculateSEHStateNumbers(&fn, EHInfo); 107 else if (Personality == EHPersonality::CoreCLR) 108 calculateClrEHStateNumbers(&fn, EHInfo); 109 110 // Map all BB references in the WinEH data to MBBs. 111 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { 112 for (WinEHHandlerType &H : TBME.HandlerArray) { 113 if (const AllocaInst *AI = H.CatchObj.Alloca) 114 CatchObjects.insert({AI, {}}).first->second.push_back( 115 &H.CatchObj.FrameIndex); 116 else 117 H.CatchObj.FrameIndex = INT_MAX; 118 } 119 } 120 } 121 122 // Initialize the mapping of values to registers. This is only set up for 123 // instruction values that are used outside of the block that defines 124 // them. 125 for (const BasicBlock &BB : *Fn) { 126 for (const Instruction &I : BB) { 127 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { 128 Type *Ty = AI->getAllocatedType(); 129 unsigned Align = 130 std::max((unsigned)MF->getDataLayout().getPrefTypeAlignment(Ty), 131 AI->getAlignment()); 132 133 // Static allocas can be folded into the initial stack frame 134 // adjustment. For targets that don't realign the stack, don't 135 // do this if there is an extra alignment requirement. 136 if (AI->isStaticAlloca() && 137 (TFI->isStackRealignable() || (Align <= StackAlign))) { 138 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize()); 139 uint64_t TySize = MF->getDataLayout().getTypeAllocSize(Ty); 140 141 TySize *= CUI->getZExtValue(); // Get total allocated size. 142 if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects. 143 int FrameIndex = INT_MAX; 144 auto Iter = CatchObjects.find(AI); 145 if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) { 146 FrameIndex = MF->getFrameInfo().CreateFixedObject( 147 TySize, 0, /*Immutable=*/false, /*isAliased=*/true); 148 MF->getFrameInfo().setObjectAlignment(FrameIndex, Align); 149 } else { 150 FrameIndex = 151 MF->getFrameInfo().CreateStackObject(TySize, Align, false, AI); 152 } 153 154 StaticAllocaMap[AI] = FrameIndex; 155 // Update the catch handler information. 156 if (Iter != CatchObjects.end()) { 157 for (int *CatchObjPtr : Iter->second) 158 *CatchObjPtr = FrameIndex; 159 } 160 } else { 161 // FIXME: Overaligned static allocas should be grouped into 162 // a single dynamic allocation instead of using a separate 163 // stack allocation for each one. 164 if (Align <= StackAlign) 165 Align = 0; 166 // Inform the Frame Information that we have variable-sized objects. 167 MF->getFrameInfo().CreateVariableSizedObject(Align ? Align : 1, AI); 168 } 169 } 170 171 // Look for inline asm that clobbers the SP register. 172 if (isa<CallInst>(I) || isa<InvokeInst>(I)) { 173 ImmutableCallSite CS(&I); 174 if (isa<InlineAsm>(CS.getCalledValue())) { 175 unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); 176 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); 177 std::vector<TargetLowering::AsmOperandInfo> Ops = 178 TLI->ParseConstraints(Fn->getParent()->getDataLayout(), TRI, CS); 179 for (TargetLowering::AsmOperandInfo &Op : Ops) { 180 if (Op.Type == InlineAsm::isClobber) { 181 // Clobbers don't have SDValue operands, hence SDValue(). 182 TLI->ComputeConstraintToUse(Op, SDValue(), DAG); 183 std::pair<unsigned, const TargetRegisterClass *> PhysReg = 184 TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode, 185 Op.ConstraintVT); 186 if (PhysReg.first == SP) 187 MF->getFrameInfo().setHasOpaqueSPAdjustment(true); 188 } 189 } 190 } 191 } 192 193 // Look for calls to the @llvm.va_start intrinsic. We can omit some 194 // prologue boilerplate for variadic functions that don't examine their 195 // arguments. 196 if (const auto *II = dyn_cast<IntrinsicInst>(&I)) { 197 if (II->getIntrinsicID() == Intrinsic::vastart) 198 MF->getFrameInfo().setHasVAStart(true); 199 } 200 201 // If we have a musttail call in a variadic function, we need to ensure we 202 // forward implicit register parameters. 203 if (const auto *CI = dyn_cast<CallInst>(&I)) { 204 if (CI->isMustTailCall() && Fn->isVarArg()) 205 MF->getFrameInfo().setHasMustTailInVarArgFunc(true); 206 } 207 208 // Mark values used outside their block as exported, by allocating 209 // a virtual register for them. 210 if (isUsedOutsideOfDefiningBlock(&I)) 211 if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I))) 212 InitializeRegForValue(&I); 213 214 // Decide the preferred extend type for a value. 215 PreferredExtendType[&I] = getPreferredExtendForValue(&I); 216 } 217 } 218 219 // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This 220 // also creates the initial PHI MachineInstrs, though none of the input 221 // operands are populated. 222 for (const BasicBlock &BB : *Fn) { 223 // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks 224 // are really data, and no instructions can live here. 225 if (BB.isEHPad()) { 226 const Instruction *PadInst = BB.getFirstNonPHI(); 227 // If this is a non-landingpad EH pad, mark this function as using 228 // funclets. 229 // FIXME: SEH catchpads do not create funclets, so we could avoid setting 230 // this in such cases in order to improve frame layout. 231 if (!isa<LandingPadInst>(PadInst)) { 232 MF->setHasEHFunclets(true); 233 MF->getFrameInfo().setHasOpaqueSPAdjustment(true); 234 } 235 if (isa<CatchSwitchInst>(PadInst)) { 236 assert(&*BB.begin() == PadInst && 237 "WinEHPrepare failed to remove PHIs from imaginary BBs"); 238 continue; 239 } 240 if (isa<FuncletPadInst>(PadInst)) 241 assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs"); 242 } 243 244 MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(&BB); 245 MBBMap[&BB] = MBB; 246 MF->push_back(MBB); 247 248 // Transfer the address-taken flag. This is necessary because there could 249 // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only 250 // the first one should be marked. 251 if (BB.hasAddressTaken()) 252 MBB->setHasAddressTaken(); 253 254 // Mark landing pad blocks. 255 if (BB.isEHPad()) 256 MBB->setIsEHPad(); 257 258 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as 259 // appropriate. 260 for (const PHINode &PN : BB.phis()) { 261 if (PN.use_empty()) 262 continue; 263 264 // Skip empty types 265 if (PN.getType()->isEmptyTy()) 266 continue; 267 268 DebugLoc DL = PN.getDebugLoc(); 269 unsigned PHIReg = ValueMap[&PN]; 270 assert(PHIReg && "PHI node does not have an assigned virtual register!"); 271 272 SmallVector<EVT, 4> ValueVTs; 273 ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs); 274 for (EVT VT : ValueVTs) { 275 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT); 276 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); 277 for (unsigned i = 0; i != NumRegisters; ++i) 278 BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i); 279 PHIReg += NumRegisters; 280 } 281 } 282 } 283 284 if (!isFuncletEHPersonality(Personality)) 285 return; 286 287 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo(); 288 289 // Map all BB references in the WinEH data to MBBs. 290 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { 291 for (WinEHHandlerType &H : TBME.HandlerArray) { 292 if (H.Handler) 293 H.Handler = MBBMap[H.Handler.get<const BasicBlock *>()]; 294 } 295 } 296 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap) 297 if (UME.Cleanup) 298 UME.Cleanup = MBBMap[UME.Cleanup.get<const BasicBlock *>()]; 299 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) { 300 const BasicBlock *BB = UME.Handler.get<const BasicBlock *>(); 301 UME.Handler = MBBMap[BB]; 302 } 303 for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap) { 304 const BasicBlock *BB = CME.Handler.get<const BasicBlock *>(); 305 CME.Handler = MBBMap[BB]; 306 } 307 } 308 309 /// clear - Clear out all the function-specific state. This returns this 310 /// FunctionLoweringInfo to an empty state, ready to be used for a 311 /// different function. 312 void FunctionLoweringInfo::clear() { 313 MBBMap.clear(); 314 ValueMap.clear(); 315 StaticAllocaMap.clear(); 316 LiveOutRegInfo.clear(); 317 VisitedBBs.clear(); 318 ArgDbgValues.clear(); 319 ByValArgFrameIndexMap.clear(); 320 RegFixups.clear(); 321 RegsWithFixups.clear(); 322 StatepointStackSlots.clear(); 323 StatepointSpillMaps.clear(); 324 PreferredExtendType.clear(); 325 } 326 327 /// CreateReg - Allocate a single virtual register for the given type. 328 unsigned FunctionLoweringInfo::CreateReg(MVT VT) { 329 return RegInfo->createVirtualRegister( 330 MF->getSubtarget().getTargetLowering()->getRegClassFor(VT)); 331 } 332 333 /// CreateRegs - Allocate the appropriate number of virtual registers of 334 /// the correctly promoted or expanded types. Assign these registers 335 /// consecutive vreg numbers and return the first assigned number. 336 /// 337 /// In the case that the given value has struct or array type, this function 338 /// will assign registers for each member or element. 339 /// 340 unsigned FunctionLoweringInfo::CreateRegs(Type *Ty) { 341 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); 342 343 SmallVector<EVT, 4> ValueVTs; 344 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs); 345 346 unsigned FirstReg = 0; 347 for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) { 348 EVT ValueVT = ValueVTs[Value]; 349 MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT); 350 351 unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT); 352 for (unsigned i = 0; i != NumRegs; ++i) { 353 unsigned R = CreateReg(RegisterVT); 354 if (!FirstReg) FirstReg = R; 355 } 356 } 357 return FirstReg; 358 } 359 360 /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the 361 /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If 362 /// the register's LiveOutInfo is for a smaller bit width, it is extended to 363 /// the larger bit width by zero extension. The bit width must be no smaller 364 /// than the LiveOutInfo's existing bit width. 365 const FunctionLoweringInfo::LiveOutInfo * 366 FunctionLoweringInfo::GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth) { 367 if (!LiveOutRegInfo.inBounds(Reg)) 368 return nullptr; 369 370 LiveOutInfo *LOI = &LiveOutRegInfo[Reg]; 371 if (!LOI->IsValid) 372 return nullptr; 373 374 if (BitWidth > LOI->Known.getBitWidth()) { 375 LOI->NumSignBits = 1; 376 LOI->Known = LOI->Known.zextOrTrunc(BitWidth); 377 } 378 379 return LOI; 380 } 381 382 /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination 383 /// register based on the LiveOutInfo of its operands. 384 void FunctionLoweringInfo::ComputePHILiveOutRegInfo(const PHINode *PN) { 385 Type *Ty = PN->getType(); 386 if (!Ty->isIntegerTy() || Ty->isVectorTy()) 387 return; 388 389 SmallVector<EVT, 1> ValueVTs; 390 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs); 391 assert(ValueVTs.size() == 1 && 392 "PHIs with non-vector integer types should have a single VT."); 393 EVT IntVT = ValueVTs[0]; 394 395 if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1) 396 return; 397 IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT); 398 unsigned BitWidth = IntVT.getSizeInBits(); 399 400 unsigned DestReg = ValueMap[PN]; 401 if (!TargetRegisterInfo::isVirtualRegister(DestReg)) 402 return; 403 LiveOutRegInfo.grow(DestReg); 404 LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg]; 405 406 Value *V = PN->getIncomingValue(0); 407 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { 408 DestLOI.NumSignBits = 1; 409 DestLOI.Known = KnownBits(BitWidth); 410 return; 411 } 412 413 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { 414 APInt Val = CI->getValue().zextOrTrunc(BitWidth); 415 DestLOI.NumSignBits = Val.getNumSignBits(); 416 DestLOI.Known.Zero = ~Val; 417 DestLOI.Known.One = Val; 418 } else { 419 assert(ValueMap.count(V) && "V should have been placed in ValueMap when its" 420 "CopyToReg node was created."); 421 unsigned SrcReg = ValueMap[V]; 422 if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { 423 DestLOI.IsValid = false; 424 return; 425 } 426 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); 427 if (!SrcLOI) { 428 DestLOI.IsValid = false; 429 return; 430 } 431 DestLOI = *SrcLOI; 432 } 433 434 assert(DestLOI.Known.Zero.getBitWidth() == BitWidth && 435 DestLOI.Known.One.getBitWidth() == BitWidth && 436 "Masks should have the same bit width as the type."); 437 438 for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) { 439 Value *V = PN->getIncomingValue(i); 440 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { 441 DestLOI.NumSignBits = 1; 442 DestLOI.Known = KnownBits(BitWidth); 443 return; 444 } 445 446 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { 447 APInt Val = CI->getValue().zextOrTrunc(BitWidth); 448 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits()); 449 DestLOI.Known.Zero &= ~Val; 450 DestLOI.Known.One &= Val; 451 continue; 452 } 453 454 assert(ValueMap.count(V) && "V should have been placed in ValueMap when " 455 "its CopyToReg node was created."); 456 unsigned SrcReg = ValueMap[V]; 457 if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { 458 DestLOI.IsValid = false; 459 return; 460 } 461 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); 462 if (!SrcLOI) { 463 DestLOI.IsValid = false; 464 return; 465 } 466 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits); 467 DestLOI.Known.Zero &= SrcLOI->Known.Zero; 468 DestLOI.Known.One &= SrcLOI->Known.One; 469 } 470 } 471 472 /// setArgumentFrameIndex - Record frame index for the byval 473 /// argument. This overrides previous frame index entry for this argument, 474 /// if any. 475 void FunctionLoweringInfo::setArgumentFrameIndex(const Argument *A, 476 int FI) { 477 ByValArgFrameIndexMap[A] = FI; 478 } 479 480 /// getArgumentFrameIndex - Get frame index for the byval argument. 481 /// If the argument does not have any assigned frame index then 0 is 482 /// returned. 483 int FunctionLoweringInfo::getArgumentFrameIndex(const Argument *A) { 484 auto I = ByValArgFrameIndexMap.find(A); 485 if (I != ByValArgFrameIndexMap.end()) 486 return I->second; 487 DEBUG(dbgs() << "Argument does not have assigned frame index!\n"); 488 return INT_MAX; 489 } 490 491 unsigned FunctionLoweringInfo::getCatchPadExceptionPointerVReg( 492 const Value *CPI, const TargetRegisterClass *RC) { 493 MachineRegisterInfo &MRI = MF->getRegInfo(); 494 auto I = CatchPadExceptionPointers.insert({CPI, 0}); 495 unsigned &VReg = I.first->second; 496 if (I.second) 497 VReg = MRI.createVirtualRegister(RC); 498 assert(VReg && "null vreg in exception pointer table!"); 499 return VReg; 500 } 501 502 unsigned 503 FunctionLoweringInfo::getOrCreateSwiftErrorVReg(const MachineBasicBlock *MBB, 504 const Value *Val) { 505 auto Key = std::make_pair(MBB, Val); 506 auto It = SwiftErrorVRegDefMap.find(Key); 507 // If this is the first use of this swifterror value in this basic block, 508 // create a new virtual register. 509 // After we processed all basic blocks we will satisfy this "upwards exposed 510 // use" by inserting a copy or phi at the beginning of this block. 511 if (It == SwiftErrorVRegDefMap.end()) { 512 auto &DL = MF->getDataLayout(); 513 const TargetRegisterClass *RC = TLI->getRegClassFor(TLI->getPointerTy(DL)); 514 auto VReg = MF->getRegInfo().createVirtualRegister(RC); 515 SwiftErrorVRegDefMap[Key] = VReg; 516 SwiftErrorVRegUpwardsUse[Key] = VReg; 517 return VReg; 518 } else return It->second; 519 } 520 521 void FunctionLoweringInfo::setCurrentSwiftErrorVReg( 522 const MachineBasicBlock *MBB, const Value *Val, unsigned VReg) { 523 SwiftErrorVRegDefMap[std::make_pair(MBB, Val)] = VReg; 524 } 525 526 std::pair<unsigned, bool> 527 FunctionLoweringInfo::getOrCreateSwiftErrorVRegDefAt(const Instruction *I) { 528 auto Key = PointerIntPair<const Instruction *, 1, bool>(I, true); 529 auto It = SwiftErrorVRegDefUses.find(Key); 530 if (It == SwiftErrorVRegDefUses.end()) { 531 auto &DL = MF->getDataLayout(); 532 const TargetRegisterClass *RC = TLI->getRegClassFor(TLI->getPointerTy(DL)); 533 unsigned VReg = MF->getRegInfo().createVirtualRegister(RC); 534 SwiftErrorVRegDefUses[Key] = VReg; 535 return std::make_pair(VReg, true); 536 } 537 return std::make_pair(It->second, false); 538 } 539 540 std::pair<unsigned, bool> 541 FunctionLoweringInfo::getOrCreateSwiftErrorVRegUseAt(const Instruction *I, const MachineBasicBlock *MBB, const Value *Val) { 542 auto Key = PointerIntPair<const Instruction *, 1, bool>(I, false); 543 auto It = SwiftErrorVRegDefUses.find(Key); 544 if (It == SwiftErrorVRegDefUses.end()) { 545 unsigned VReg = getOrCreateSwiftErrorVReg(MBB, Val); 546 SwiftErrorVRegDefUses[Key] = VReg; 547 return std::make_pair(VReg, true); 548 } 549 return std::make_pair(It->second, false); 550 } 551 552 const Value * 553 FunctionLoweringInfo::getValueFromVirtualReg(unsigned Vreg) { 554 if (VirtReg2Value.empty()) { 555 for (auto &P : ValueMap) { 556 VirtReg2Value[P.second] = P.first; 557 } 558 } 559 return VirtReg2Value[Vreg]; 560 } 561