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