2
0

FunctionLoweringInfo.cpp 22 KB

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