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