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 TyPrefAlign = MF->getDataLayout().getPrefTypeAlign(Ty); 138 // The "specified" alignment is the alignment written on the alloca, 139 // or the preferred alignment of the type if none is specified. 140 // 141 // (Unspecified alignment on allocas will be going away soon.) 142 Align SpecifiedAlign = AI->getAlign(); 143 144 // If the preferred alignment of the type is higher than the specified 145 // alignment of the alloca, promote the alignment, as long as it doesn't 146 // require realigning the stack. 147 // 148 // FIXME: Do we really want to second-guess the IR in isel? 149 Align Alignment = 150 std::max(std::min(TyPrefAlign, StackAlign), SpecifiedAlign); 151 152 // Static allocas can be folded into the initial stack frame 153 // adjustment. For targets that don't realign the stack, don't 154 // do this if there is an extra alignment requirement. 155 if (AI->isStaticAlloca() && 156 (TFI->isStackRealignable() || (Alignment <= StackAlign))) { 157 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize()); 158 uint64_t TySize = 159 MF->getDataLayout().getTypeAllocSize(Ty).getKnownMinSize(); 160 161 TySize *= CUI->getZExtValue(); // Get total allocated size. 162 if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects. 163 int FrameIndex = INT_MAX; 164 auto Iter = CatchObjects.find(AI); 165 if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) { 166 FrameIndex = MF->getFrameInfo().CreateFixedObject( 167 TySize, 0, /*IsImmutable=*/false, /*isAliased=*/true); 168 MF->getFrameInfo().setObjectAlignment(FrameIndex, Alignment); 169 } else { 170 FrameIndex = MF->getFrameInfo().CreateStackObject(TySize, Alignment, 171 false, AI); 172 } 173 174 // Scalable vectors may need a special StackID to distinguish 175 // them from other (fixed size) stack objects. 176 if (isa<ScalableVectorType>(Ty)) 177 MF->getFrameInfo().setStackID(FrameIndex, 178 TFI->getStackIDForScalableVectors()); 179 180 StaticAllocaMap[AI] = FrameIndex; 181 // Update the catch handler information. 182 if (Iter != CatchObjects.end()) { 183 for (int *CatchObjPtr : Iter->second) 184 *CatchObjPtr = FrameIndex; 185 } 186 } else { 187 // FIXME: Overaligned static allocas should be grouped into 188 // a single dynamic allocation instead of using a separate 189 // stack allocation for each one. 190 // Inform the Frame Information that we have variable-sized objects. 191 MF->getFrameInfo().CreateVariableSizedObject( 192 Alignment <= StackAlign ? 0 : Alignment.value(), AI); 193 } 194 } 195 196 // Look for inline asm that clobbers the SP register. 197 if (auto *Call = dyn_cast<CallBase>(&I)) { 198 if (Call->isInlineAsm()) { 199 unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); 200 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); 201 std::vector<TargetLowering::AsmOperandInfo> Ops = 202 TLI->ParseConstraints(Fn->getParent()->getDataLayout(), TRI, 203 *Call); 204 for (TargetLowering::AsmOperandInfo &Op : Ops) { 205 if (Op.Type == InlineAsm::isClobber) { 206 // Clobbers don't have SDValue operands, hence SDValue(). 207 TLI->ComputeConstraintToUse(Op, SDValue(), DAG); 208 std::pair<unsigned, const TargetRegisterClass *> PhysReg = 209 TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode, 210 Op.ConstraintVT); 211 if (PhysReg.first == SP) 212 MF->getFrameInfo().setHasOpaqueSPAdjustment(true); 213 } 214 } 215 } 216 } 217 218 // Look for calls to the @llvm.va_start intrinsic. We can omit some 219 // prologue boilerplate for variadic functions that don't examine their 220 // arguments. 221 if (const auto *II = dyn_cast<IntrinsicInst>(&I)) { 222 if (II->getIntrinsicID() == Intrinsic::vastart) 223 MF->getFrameInfo().setHasVAStart(true); 224 } 225 226 // If we have a musttail call in a variadic function, we need to ensure we 227 // forward implicit register parameters. 228 if (const auto *CI = dyn_cast<CallInst>(&I)) { 229 if (CI->isMustTailCall() && Fn->isVarArg()) 230 MF->getFrameInfo().setHasMustTailInVarArgFunc(true); 231 } 232 233 // Mark values used outside their block as exported, by allocating 234 // a virtual register for them. 235 if (isUsedOutsideOfDefiningBlock(&I)) 236 if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I))) 237 InitializeRegForValue(&I); 238 239 // Decide the preferred extend type for a value. 240 PreferredExtendType[&I] = getPreferredExtendForValue(&I); 241 } 242 } 243 244 // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This 245 // also creates the initial PHI MachineInstrs, though none of the input 246 // operands are populated. 247 for (const BasicBlock &BB : *Fn) { 248 // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks 249 // are really data, and no instructions can live here. 250 if (BB.isEHPad()) { 251 const Instruction *PadInst = BB.getFirstNonPHI(); 252 // If this is a non-landingpad EH pad, mark this function as using 253 // funclets. 254 // FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid 255 // setting this in such cases in order to improve frame layout. 256 if (!isa<LandingPadInst>(PadInst)) { 257 MF->setHasEHScopes(true); 258 MF->setHasEHFunclets(true); 259 MF->getFrameInfo().setHasOpaqueSPAdjustment(true); 260 } 261 if (isa<CatchSwitchInst>(PadInst)) { 262 assert(&*BB.begin() == PadInst && 263 "WinEHPrepare failed to remove PHIs from imaginary BBs"); 264 continue; 265 } 266 if (isa<FuncletPadInst>(PadInst)) 267 assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs"); 268 } 269 270 MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(&BB); 271 MBBMap[&BB] = MBB; 272 MF->push_back(MBB); 273 274 // Transfer the address-taken flag. This is necessary because there could 275 // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only 276 // the first one should be marked. 277 if (BB.hasAddressTaken()) 278 MBB->setHasAddressTaken(); 279 280 // Mark landing pad blocks. 281 if (BB.isEHPad()) 282 MBB->setIsEHPad(); 283 284 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as 285 // appropriate. 286 for (const PHINode &PN : BB.phis()) { 287 if (PN.use_empty()) 288 continue; 289 290 // Skip empty types 291 if (PN.getType()->isEmptyTy()) 292 continue; 293 294 DebugLoc DL = PN.getDebugLoc(); 295 unsigned PHIReg = ValueMap[&PN]; 296 assert(PHIReg && "PHI node does not have an assigned virtual register!"); 297 298 SmallVector<EVT, 4> ValueVTs; 299 ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs); 300 for (EVT VT : ValueVTs) { 301 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT); 302 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); 303 for (unsigned i = 0; i != NumRegisters; ++i) 304 BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i); 305 PHIReg += NumRegisters; 306 } 307 } 308 } 309 310 if (isFuncletEHPersonality(Personality)) { 311 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo(); 312 313 // Map all BB references in the WinEH data to MBBs. 314 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { 315 for (WinEHHandlerType &H : TBME.HandlerArray) { 316 if (H.Handler) 317 H.Handler = MBBMap[H.Handler.get<const BasicBlock *>()]; 318 } 319 } 320 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap) 321 if (UME.Cleanup) 322 UME.Cleanup = MBBMap[UME.Cleanup.get<const BasicBlock *>()]; 323 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) { 324 const auto *BB = UME.Handler.get<const BasicBlock *>(); 325 UME.Handler = MBBMap[BB]; 326 } 327 for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap) { 328 const auto *BB = CME.Handler.get<const BasicBlock *>(); 329 CME.Handler = MBBMap[BB]; 330 } 331 } 332 333 else if (Personality == EHPersonality::Wasm_CXX) { 334 WasmEHFuncInfo &EHInfo = *MF->getWasmEHFuncInfo(); 335 // Map all BB references in the WinEH data to MBBs. 336 DenseMap<BBOrMBB, BBOrMBB> NewMap; 337 for (auto &KV : EHInfo.EHPadUnwindMap) { 338 const auto *Src = KV.first.get<const BasicBlock *>(); 339 const auto *Dst = KV.second.get<const BasicBlock *>(); 340 NewMap[MBBMap[Src]] = MBBMap[Dst]; 341 } 342 EHInfo.EHPadUnwindMap = std::move(NewMap); 343 } 344 } 345 346 /// clear - Clear out all the function-specific state. This returns this 347 /// FunctionLoweringInfo to an empty state, ready to be used for a 348 /// different function. 349 void FunctionLoweringInfo::clear() { 350 MBBMap.clear(); 351 ValueMap.clear(); 352 VirtReg2Value.clear(); 353 StaticAllocaMap.clear(); 354 LiveOutRegInfo.clear(); 355 VisitedBBs.clear(); 356 ArgDbgValues.clear(); 357 DescribedArgs.clear(); 358 ByValArgFrameIndexMap.clear(); 359 RegFixups.clear(); 360 RegsWithFixups.clear(); 361 StatepointStackSlots.clear(); 362 StatepointSpillMaps.clear(); 363 PreferredExtendType.clear(); 364 } 365 366 /// CreateReg - Allocate a single virtual register for the given type. 367 Register FunctionLoweringInfo::CreateReg(MVT VT, bool isDivergent) { 368 return RegInfo->createVirtualRegister( 369 MF->getSubtarget().getTargetLowering()->getRegClassFor(VT, isDivergent)); 370 } 371 372 /// CreateRegs - Allocate the appropriate number of virtual registers of 373 /// the correctly promoted or expanded types. Assign these registers 374 /// consecutive vreg numbers and return the first assigned number. 375 /// 376 /// In the case that the given value has struct or array type, this function 377 /// will assign registers for each member or element. 378 /// 379 Register FunctionLoweringInfo::CreateRegs(Type *Ty, bool isDivergent) { 380 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); 381 382 SmallVector<EVT, 4> ValueVTs; 383 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs); 384 385 Register FirstReg; 386 for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) { 387 EVT ValueVT = ValueVTs[Value]; 388 MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT); 389 390 unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT); 391 for (unsigned i = 0; i != NumRegs; ++i) { 392 Register R = CreateReg(RegisterVT, isDivergent); 393 if (!FirstReg) FirstReg = R; 394 } 395 } 396 return FirstReg; 397 } 398 399 Register FunctionLoweringInfo::CreateRegs(const Value *V) { 400 return CreateRegs(V->getType(), DA && DA->isDivergent(V) && 401 !TLI->requiresUniformRegister(*MF, V)); 402 } 403 404 /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the 405 /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If 406 /// the register's LiveOutInfo is for a smaller bit width, it is extended to 407 /// the larger bit width by zero extension. The bit width must be no smaller 408 /// than the LiveOutInfo's existing bit width. 409 const FunctionLoweringInfo::LiveOutInfo * 410 FunctionLoweringInfo::GetLiveOutRegInfo(Register Reg, unsigned BitWidth) { 411 if (!LiveOutRegInfo.inBounds(Reg)) 412 return nullptr; 413 414 LiveOutInfo *LOI = &LiveOutRegInfo[Reg]; 415 if (!LOI->IsValid) 416 return nullptr; 417 418 if (BitWidth > LOI->Known.getBitWidth()) { 419 LOI->NumSignBits = 1; 420 LOI->Known = LOI->Known.anyext(BitWidth); 421 } 422 423 return LOI; 424 } 425 426 /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination 427 /// register based on the LiveOutInfo of its operands. 428 void FunctionLoweringInfo::ComputePHILiveOutRegInfo(const PHINode *PN) { 429 Type *Ty = PN->getType(); 430 if (!Ty->isIntegerTy() || Ty->isVectorTy()) 431 return; 432 433 SmallVector<EVT, 1> ValueVTs; 434 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs); 435 assert(ValueVTs.size() == 1 && 436 "PHIs with non-vector integer types should have a single VT."); 437 EVT IntVT = ValueVTs[0]; 438 439 if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1) 440 return; 441 IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT); 442 unsigned BitWidth = IntVT.getSizeInBits(); 443 444 Register DestReg = ValueMap[PN]; 445 if (!Register::isVirtualRegister(DestReg)) 446 return; 447 LiveOutRegInfo.grow(DestReg); 448 LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg]; 449 450 Value *V = PN->getIncomingValue(0); 451 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { 452 DestLOI.NumSignBits = 1; 453 DestLOI.Known = KnownBits(BitWidth); 454 return; 455 } 456 457 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { 458 APInt Val = CI->getValue().zextOrTrunc(BitWidth); 459 DestLOI.NumSignBits = Val.getNumSignBits(); 460 DestLOI.Known.Zero = ~Val; 461 DestLOI.Known.One = Val; 462 } else { 463 assert(ValueMap.count(V) && "V should have been placed in ValueMap when its" 464 "CopyToReg node was created."); 465 Register SrcReg = ValueMap[V]; 466 if (!Register::isVirtualRegister(SrcReg)) { 467 DestLOI.IsValid = false; 468 return; 469 } 470 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); 471 if (!SrcLOI) { 472 DestLOI.IsValid = false; 473 return; 474 } 475 DestLOI = *SrcLOI; 476 } 477 478 assert(DestLOI.Known.Zero.getBitWidth() == BitWidth && 479 DestLOI.Known.One.getBitWidth() == BitWidth && 480 "Masks should have the same bit width as the type."); 481 482 for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) { 483 Value *V = PN->getIncomingValue(i); 484 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { 485 DestLOI.NumSignBits = 1; 486 DestLOI.Known = KnownBits(BitWidth); 487 return; 488 } 489 490 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { 491 APInt Val = CI->getValue().zextOrTrunc(BitWidth); 492 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits()); 493 DestLOI.Known.Zero &= ~Val; 494 DestLOI.Known.One &= Val; 495 continue; 496 } 497 498 assert(ValueMap.count(V) && "V should have been placed in ValueMap when " 499 "its CopyToReg node was created."); 500 Register SrcReg = ValueMap[V]; 501 if (!SrcReg.isVirtual()) { 502 DestLOI.IsValid = false; 503 return; 504 } 505 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); 506 if (!SrcLOI) { 507 DestLOI.IsValid = false; 508 return; 509 } 510 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits); 511 DestLOI.Known.Zero &= SrcLOI->Known.Zero; 512 DestLOI.Known.One &= SrcLOI->Known.One; 513 } 514 } 515 516 /// setArgumentFrameIndex - Record frame index for the byval 517 /// argument. This overrides previous frame index entry for this argument, 518 /// if any. 519 void FunctionLoweringInfo::setArgumentFrameIndex(const Argument *A, 520 int FI) { 521 ByValArgFrameIndexMap[A] = FI; 522 } 523 524 /// getArgumentFrameIndex - Get frame index for the byval argument. 525 /// If the argument does not have any assigned frame index then 0 is 526 /// returned. 527 int FunctionLoweringInfo::getArgumentFrameIndex(const Argument *A) { 528 auto I = ByValArgFrameIndexMap.find(A); 529 if (I != ByValArgFrameIndexMap.end()) 530 return I->second; 531 LLVM_DEBUG(dbgs() << "Argument does not have assigned frame index!\n"); 532 return INT_MAX; 533 } 534 535 Register FunctionLoweringInfo::getCatchPadExceptionPointerVReg( 536 const Value *CPI, const TargetRegisterClass *RC) { 537 MachineRegisterInfo &MRI = MF->getRegInfo(); 538 auto I = CatchPadExceptionPointers.insert({CPI, 0}); 539 Register &VReg = I.first->second; 540 if (I.second) 541 VReg = MRI.createVirtualRegister(RC); 542 assert(VReg && "null vreg in exception pointer table!"); 543 return VReg; 544 } 545 546 const Value * 547 FunctionLoweringInfo::getValueFromVirtualReg(Register Vreg) { 548 if (VirtReg2Value.empty()) { 549 SmallVector<EVT, 4> ValueVTs; 550 for (auto &P : ValueMap) { 551 ValueVTs.clear(); 552 ComputeValueVTs(*TLI, Fn->getParent()->getDataLayout(), 553 P.first->getType(), ValueVTs); 554 unsigned Reg = P.second; 555 for (EVT VT : ValueVTs) { 556 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT); 557 for (unsigned i = 0, e = NumRegisters; i != e; ++i) 558 VirtReg2Value[Reg++] = P.first; 559 } 560 } 561 } 562 return VirtReg2Value.lookup(Vreg); 563 } 564