Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 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 | |
Dan Gohman | e784616 | 2010-07-07 16:01:37 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 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" |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame^] | 23 | #include "llvm/CodeGen/WinEHFuncInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 24 | #include "llvm/IR/DataLayout.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 25 | #include "llvm/IR/DebugInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 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" |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
| 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include "llvm/Support/MathExtras.h" |
Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetFrameLowering.h" |
Chandler Carruth | 9205140 | 2014-03-05 10:30:38 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetLowering.h" |
| 39 | #include "llvm/Target/TargetOptions.h" |
| 40 | #include "llvm/Target/TargetRegisterInfo.h" |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetSubtargetInfo.h" |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 42 | #include <algorithm> |
| 43 | using namespace llvm; |
| 44 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 45 | #define DEBUG_TYPE "function-lowering-info" |
| 46 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 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. |
Dan Gohman | 913c998 | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 50 | static bool isUsedOutsideOfDefiningBlock(const Instruction *I) { |
Dan Gohman | 7c845e4 | 2010-04-20 14:50:13 +0000 | [diff] [blame] | 51 | if (I->use_empty()) return false; |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 52 | if (isa<PHINode>(I)) return true; |
Dan Gohman | 913c998 | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 53 | const BasicBlock *BB = I->getParent(); |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 54 | for (const User *U : I->users()) |
Gabor Greif | 52617fc | 2010-07-09 16:08:33 +0000 | [diff] [blame] | 55 | if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U)) |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 56 | return true; |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 57 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 58 | return false; |
| 59 | } |
| 60 | |
Jiangning Liu | ffbc690 | 2014-09-19 05:30:35 +0000 | [diff] [blame] | 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 | |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame^] | 83 | namespace { |
| 84 | struct WinEHNumbering { |
| 85 | WinEHNumbering(WinEHFuncInfo &FuncInfo) : FuncInfo(FuncInfo), NextState(0) {} |
| 86 | |
| 87 | WinEHFuncInfo &FuncInfo; |
| 88 | int NextState; |
| 89 | |
| 90 | SmallVector<ActionHandler *, 4> HandlerStack; |
| 91 | |
| 92 | int currentEHNumber() const { |
| 93 | return HandlerStack.empty() ? -1 : HandlerStack.back()->getEHState(); |
| 94 | } |
| 95 | |
| 96 | void parseEHActions(const IntrinsicInst *II, |
| 97 | SmallVectorImpl<ActionHandler *> &Actions); |
| 98 | void createUnwindMapEntry(int ToState, ActionHandler *AH); |
| 99 | void proccessCallSite(ArrayRef<ActionHandler *> Actions, ImmutableCallSite CS); |
| 100 | void calculateStateNumbers(const Function &F); |
| 101 | }; |
| 102 | } |
| 103 | |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 104 | void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, |
| 105 | SelectionDAG *DAG) { |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 106 | Fn = &fn; |
| 107 | MF = &mf; |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 108 | TLI = MF->getSubtarget().getTargetLowering(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 109 | RegInfo = &MF->getRegInfo(); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame^] | 110 | MachineModuleInfo &MMI = MF->getMMI(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 111 | |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 112 | // Check whether the function can return without sret-demotion. |
| 113 | SmallVector<ISD::OutputArg, 4> Outs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 114 | GetReturnInfo(Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI); |
| 115 | CanLowerReturn = TLI->CanLowerReturn(Fn->getCallingConv(), *MF, |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 116 | Fn->isVarArg(), Outs, Fn->getContext()); |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 117 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 118 | // Initialize the mapping of values to registers. This is only set up for |
| 119 | // instruction values that are used outside of the block that defines |
| 120 | // them. |
Dan Gohman | 913c998 | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 121 | Function::const_iterator BB = Fn->begin(), EB = Fn->end(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 122 | for (; BB != EB; ++BB) |
Eric Christopher | 219d51d | 2012-02-24 01:59:01 +0000 | [diff] [blame] | 123 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); |
| 124 | I != E; ++I) { |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 125 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) { |
Reid Kleckner | 0b2bccc | 2014-09-02 18:42:44 +0000 | [diff] [blame] | 126 | // Static allocas can be folded into the initial stack frame adjustment. |
| 127 | if (AI->isStaticAlloca()) { |
| 128 | const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize()); |
| 129 | Type *Ty = AI->getAllocatedType(); |
| 130 | uint64_t TySize = TLI->getDataLayout()->getTypeAllocSize(Ty); |
| 131 | unsigned Align = |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 132 | std::max((unsigned)TLI->getDataLayout()->getPrefTypeAlignment(Ty), |
| 133 | AI->getAlignment()); |
Reid Kleckner | 0b2bccc | 2014-09-02 18:42:44 +0000 | [diff] [blame] | 134 | |
| 135 | TySize *= CUI->getZExtValue(); // Get total allocated size. |
| 136 | if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects. |
| 137 | |
| 138 | StaticAllocaMap[AI] = |
| 139 | MF->getFrameInfo()->CreateStackObject(TySize, Align, false, AI); |
| 140 | |
| 141 | } else { |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 142 | unsigned Align = std::max( |
| 143 | (unsigned)TLI->getDataLayout()->getPrefTypeAlignment( |
| 144 | AI->getAllocatedType()), |
| 145 | AI->getAlignment()); |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 146 | unsigned StackAlign = |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 147 | MF->getSubtarget().getFrameLowering()->getStackAlignment(); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 148 | if (Align <= StackAlign) |
| 149 | Align = 0; |
| 150 | // Inform the Frame Information that we have variable-sized objects. |
| 151 | MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, AI); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Look for inline asm that clobbers the SP register. |
| 156 | if (isa<CallInst>(I) || isa<InvokeInst>(I)) { |
| 157 | ImmutableCallSite CS(I); |
Hans Wennborg | 0c72fd2 | 2014-03-05 03:21:23 +0000 | [diff] [blame] | 158 | if (isa<InlineAsm>(CS.getCalledValue())) { |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 159 | unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 160 | const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 161 | std::vector<TargetLowering::AsmOperandInfo> Ops = |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 162 | TLI->ParseConstraints(TRI, CS); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 163 | for (size_t I = 0, E = Ops.size(); I != E; ++I) { |
| 164 | TargetLowering::AsmOperandInfo &Op = Ops[I]; |
| 165 | if (Op.Type == InlineAsm::isClobber) { |
| 166 | // Clobbers don't have SDValue operands, hence SDValue(). |
| 167 | TLI->ComputeConstraintToUse(Op, SDValue(), DAG); |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 168 | std::pair<unsigned, const TargetRegisterClass *> PhysReg = |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 169 | TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode, |
| 170 | Op.ConstraintVT); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 171 | if (PhysReg.first == SP) |
| 172 | MF->getFrameInfo()->setHasInlineAsmWithSPAdjust(true); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 178 | // Look for calls to the @llvm.va_start intrinsic. We can omit some |
| 179 | // prologue boilerplate for variadic functions that don't examine their |
| 180 | // arguments. |
| 181 | if (const auto *II = dyn_cast<IntrinsicInst>(I)) { |
| 182 | if (II->getIntrinsicID() == Intrinsic::vastart) |
| 183 | MF->getFrameInfo()->setHasVAStart(true); |
| 184 | } |
| 185 | |
Reid Kleckner | 16e5541 | 2014-08-29 21:42:08 +0000 | [diff] [blame] | 186 | // If we have a musttail call in a variadic funciton, we need to ensure we |
| 187 | // forward implicit register parameters. |
Reid Kleckner | dccd0cb | 2014-08-29 21:42:21 +0000 | [diff] [blame] | 188 | if (const auto *CI = dyn_cast<CallInst>(I)) { |
Reid Kleckner | 16e5541 | 2014-08-29 21:42:08 +0000 | [diff] [blame] | 189 | if (CI->isMustTailCall() && Fn->isVarArg()) |
| 190 | MF->getFrameInfo()->setHasMustTailInVarArgFunc(true); |
| 191 | } |
| 192 | |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 193 | // Mark values used outside their block as exported, by allocating |
| 194 | // a virtual register for them. |
Cameron Zwarich | f8b22b3 | 2011-02-22 03:24:52 +0000 | [diff] [blame] | 195 | if (isUsedOutsideOfDefiningBlock(I)) |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 196 | if (!isa<AllocaInst>(I) || |
| 197 | !StaticAllocaMap.count(cast<AllocaInst>(I))) |
| 198 | InitializeRegForValue(I); |
| 199 | |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 200 | // Collect llvm.dbg.declare information. This is done now instead of |
| 201 | // during the initial isel pass through the IR so that it is done |
| 202 | // in a predictable order. |
| 203 | if (const DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(I)) { |
Manman Ren | 983a16c | 2013-06-28 05:43:10 +0000 | [diff] [blame] | 204 | DIVariable DIVar(DI->getVariable()); |
| 205 | assert((!DIVar || DIVar.isVariable()) && |
| 206 | "Variable in DbgDeclareInst should be either null or a DIVariable."); |
Duncan P. N. Exon Smith | 9dffcd0 | 2015-03-30 19:14:47 +0000 | [diff] [blame] | 207 | if (MMI.hasDebugInfo() && DIVar && DI->getDebugLoc()) { |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 208 | // Don't handle byval struct arguments or VLAs, for example. |
| 209 | // Non-byval arguments are handled here (they refer to the stack |
| 210 | // temporary alloca at this point). |
| 211 | const Value *Address = DI->getAddress(); |
| 212 | if (Address) { |
| 213 | if (const BitCastInst *BCI = dyn_cast<BitCastInst>(Address)) |
| 214 | Address = BCI->getOperand(0); |
| 215 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(Address)) { |
| 216 | DenseMap<const AllocaInst *, int>::iterator SI = |
| 217 | StaticAllocaMap.find(AI); |
| 218 | if (SI != StaticAllocaMap.end()) { // Check for VLAs. |
| 219 | int FI = SI->second; |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 220 | MMI.setVariableDbgInfo(DI->getVariable(), DI->getExpression(), |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 221 | FI, DI->getDebugLoc()); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
Jiangning Liu | ffbc690 | 2014-09-19 05:30:35 +0000 | [diff] [blame] | 227 | |
| 228 | // Decide the preferred extend type for a value. |
| 229 | PreferredExtendType[I] = getPreferredExtendForValue(I); |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 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. |
Dan Gohman | f57117d | 2010-04-14 16:30:40 +0000 | [diff] [blame] | 235 | for (BB = Fn->begin(); BB != EB; ++BB) { |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 236 | MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(BB); |
| 237 | MBBMap[BB] = MBB; |
| 238 | MF->push_back(MBB); |
| 239 | |
| 240 | // Transfer the address-taken flag. This is necessary because there could |
| 241 | // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only |
| 242 | // the first one should be marked. |
| 243 | if (BB->hasAddressTaken()) |
| 244 | MBB->setHasAddressTaken(); |
| 245 | |
| 246 | // Create Machine PHI nodes for LLVM PHI nodes, lowering them as |
| 247 | // appropriate. |
Dan Gohman | 0f055d3 | 2010-04-20 14:46:25 +0000 | [diff] [blame] | 248 | for (BasicBlock::const_iterator I = BB->begin(); |
| 249 | const PHINode *PN = dyn_cast<PHINode>(I); ++I) { |
| 250 | if (PN->use_empty()) continue; |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 251 | |
Rafael Espindola | e53b7d1 | 2011-05-13 15:18:06 +0000 | [diff] [blame] | 252 | // Skip empty types |
| 253 | if (PN->getType()->isEmptyTy()) |
| 254 | continue; |
| 255 | |
Dan Gohman | 7b7f088 | 2010-04-20 14:48:02 +0000 | [diff] [blame] | 256 | DebugLoc DL = PN->getDebugLoc(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 257 | unsigned PHIReg = ValueMap[PN]; |
| 258 | assert(PHIReg && "PHI node does not have an assigned virtual register!"); |
| 259 | |
| 260 | SmallVector<EVT, 4> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 261 | ComputeValueVTs(*TLI, PN->getType(), ValueVTs); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 262 | for (unsigned vti = 0, vte = ValueVTs.size(); vti != vte; ++vti) { |
| 263 | EVT VT = ValueVTs[vti]; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 264 | unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 265 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 266 | for (unsigned i = 0; i != NumRegisters; ++i) |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 267 | BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 268 | PHIReg += NumRegisters; |
| 269 | } |
| 270 | } |
| 271 | } |
Dan Gohman | 69e8e32 | 2010-04-14 16:32:56 +0000 | [diff] [blame] | 272 | |
| 273 | // Mark landing pad blocks. |
| 274 | for (BB = Fn->begin(); BB != EB; ++BB) |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame^] | 275 | if (const auto *Invoke = dyn_cast<InvokeInst>(BB->getTerminator())) |
Dan Gohman | 69e8e32 | 2010-04-14 16:32:56 +0000 | [diff] [blame] | 276 | MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad(); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame^] | 277 | |
| 278 | // Calculate EH numbers for WinEH. |
| 279 | if (fn.getFnAttribute("wineh-parent").getValueAsString() == fn.getName()) |
| 280 | WinEHNumbering(MMI.getWinEHFuncInfo(&fn)).calculateStateNumbers(fn); |
| 281 | } |
| 282 | |
| 283 | void WinEHNumbering::parseEHActions(const IntrinsicInst *II, |
| 284 | SmallVectorImpl<ActionHandler *> &Actions) { |
| 285 | for (unsigned I = 0, E = II->getNumArgOperands(); I != E;) { |
| 286 | uint64_t ActionKind = |
| 287 | cast<ConstantInt>(II->getArgOperand(I))->getZExtValue(); |
| 288 | if (ActionKind == /*catch=*/1) { |
| 289 | auto *Selector = cast<Constant>(II->getArgOperand(I + 1)); |
| 290 | Value *CatchObject = II->getArgOperand(I + 2); |
| 291 | Constant *Handler = cast<Constant>(II->getArgOperand(I + 3)); |
| 292 | I += 4; |
| 293 | auto *CH = new CatchHandler(/*BB=*/nullptr, Selector, /*NextBB=*/nullptr); |
| 294 | CH->setExceptionVar(CatchObject); |
| 295 | CH->setHandlerBlockOrFunc(Handler); |
| 296 | Actions.push_back(CH); |
| 297 | } else { |
| 298 | assert(ActionKind == 0 && "expected a cleanup or a catch action!"); |
| 299 | Constant *Handler = cast<Constant>(II->getArgOperand(I + 1)); |
| 300 | I += 2; |
| 301 | auto *CH = new CleanupHandler(/*BB=*/nullptr); |
| 302 | CH->setHandlerBlockOrFunc(Handler); |
| 303 | Actions.push_back(CH); |
| 304 | } |
| 305 | } |
| 306 | std::reverse(Actions.begin(), Actions.end()); |
| 307 | } |
| 308 | |
| 309 | void WinEHNumbering::createUnwindMapEntry(int ToState, ActionHandler *AH) { |
| 310 | WinEHUnwindMapEntry UME; |
| 311 | UME.ToState = ToState; |
| 312 | if (auto *CH = dyn_cast<CleanupHandler>(AH)) |
| 313 | UME.Cleanup = cast<Function>(CH->getHandlerBlockOrFunc()); |
| 314 | else |
| 315 | UME.Cleanup = nullptr; |
| 316 | FuncInfo.UnwindMap.push_back(UME); |
| 317 | } |
| 318 | |
| 319 | static void print_name(const Value *V) { |
| 320 | if (!V) { |
| 321 | DEBUG(dbgs() << "null"); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | if (const auto *F = dyn_cast<Function>(V)) |
| 326 | DEBUG(dbgs() << F->getName()); |
| 327 | else |
| 328 | DEBUG(V->dump()); |
| 329 | } |
| 330 | |
| 331 | void WinEHNumbering::proccessCallSite(ArrayRef<ActionHandler *> Actions, |
| 332 | ImmutableCallSite CS) { |
| 333 | // float, int |
| 334 | // float, double, int |
| 335 | int FirstMismatch = 0; |
| 336 | for (int E = std::min(HandlerStack.size(), Actions.size()); FirstMismatch < E; |
| 337 | ++FirstMismatch) { |
| 338 | if (HandlerStack[FirstMismatch]->getHandlerBlockOrFunc() != |
| 339 | Actions[FirstMismatch]->getHandlerBlockOrFunc()) |
| 340 | break; |
| 341 | delete Actions[FirstMismatch]; |
| 342 | } |
| 343 | |
| 344 | // Don't recurse while we are looping over the handler stack. Instead, defer |
| 345 | // the numbering of the catch handlers until we are done popping. |
| 346 | SmallVector<const Function *, 4> UnnumberedHandlers; |
| 347 | for (int I = HandlerStack.size() - 1; I >= FirstMismatch; --I) { |
| 348 | if (auto *CH = dyn_cast<CatchHandler>(HandlerStack.back())) |
| 349 | if (const auto *F = dyn_cast<Function>(CH->getHandlerBlockOrFunc())) |
| 350 | UnnumberedHandlers.push_back(F); |
| 351 | // Pop the handlers off of the stack. |
| 352 | delete HandlerStack.back(); |
| 353 | HandlerStack.pop_back(); |
| 354 | } |
| 355 | |
| 356 | for (const Function *F : UnnumberedHandlers) |
| 357 | calculateStateNumbers(*F); |
| 358 | |
| 359 | for (size_t I = FirstMismatch; I != Actions.size(); ++I) { |
| 360 | createUnwindMapEntry(currentEHNumber(), Actions[I]); |
| 361 | Actions[I]->setEHState(NextState++); |
| 362 | DEBUG(dbgs() << "Creating unwind map entry for: ("); |
| 363 | print_name(Actions[I]->getHandlerBlockOrFunc()); |
| 364 | DEBUG(dbgs() << ", " << currentEHNumber() << ")\n"); |
| 365 | HandlerStack.push_back(Actions[I]); |
| 366 | } |
| 367 | |
| 368 | DEBUG(dbgs() << "In EHState " << currentEHNumber() << " for CallSite: "); |
| 369 | print_name(CS ? CS.getCalledValue() : nullptr); |
| 370 | DEBUG(dbgs() << '\n'); |
| 371 | } |
| 372 | |
| 373 | void WinEHNumbering::calculateStateNumbers(const Function &F) { |
| 374 | DEBUG(dbgs() << "Calculating state numbers for: " << F.getName() << '\n'); |
| 375 | SmallVector<ActionHandler *, 4> ActionList; |
| 376 | for (const BasicBlock &BB : F) { |
| 377 | for (const Instruction &I : BB) { |
| 378 | const auto *CI = dyn_cast<CallInst>(&I); |
| 379 | if (!CI || CI->doesNotThrow()) |
| 380 | continue; |
| 381 | proccessCallSite(None, CI); |
| 382 | } |
| 383 | const auto *II = dyn_cast<InvokeInst>(BB.getTerminator()); |
| 384 | if (!II) |
| 385 | continue; |
| 386 | const LandingPadInst *LPI = II->getLandingPadInst(); |
| 387 | if (auto *ActionsCall = dyn_cast<IntrinsicInst>(LPI->getNextNode())) { |
| 388 | assert(ActionsCall->getIntrinsicID() == Intrinsic::eh_actions); |
| 389 | parseEHActions(ActionsCall, ActionList); |
| 390 | proccessCallSite(ActionList, II); |
| 391 | ActionList.clear(); |
| 392 | FuncInfo.LandingPadStateMap[LPI] = currentEHNumber(); |
| 393 | } |
| 394 | } |
| 395 | proccessCallSite(None, ImmutableCallSite()); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /// clear - Clear out all the function-specific state. This returns this |
| 399 | /// FunctionLoweringInfo to an empty state, ready to be used for a |
| 400 | /// different function. |
| 401 | void FunctionLoweringInfo::clear() { |
Dan Gohman | ad0b3ea | 2010-04-14 17:11:23 +0000 | [diff] [blame] | 402 | assert(CatchInfoFound.size() == CatchInfoLost.size() && |
| 403 | "Not all catch info was assigned to a landing pad!"); |
| 404 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 405 | MBBMap.clear(); |
| 406 | ValueMap.clear(); |
| 407 | StaticAllocaMap.clear(); |
| 408 | #ifndef NDEBUG |
| 409 | CatchInfoLost.clear(); |
| 410 | CatchInfoFound.clear(); |
| 411 | #endif |
| 412 | LiveOutRegInfo.clear(); |
Cameron Zwarich | 988faf9 | 2011-02-24 10:00:13 +0000 | [diff] [blame] | 413 | VisitedBBs.clear(); |
Evan Cheng | 6e82245 | 2010-04-28 23:08:54 +0000 | [diff] [blame] | 414 | ArgDbgValues.clear(); |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 415 | ByValArgFrameIndexMap.clear(); |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 416 | RegFixups.clear(); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 417 | StatepointStackSlots.clear(); |
Jiangning Liu | 3b09617 | 2014-09-24 03:22:56 +0000 | [diff] [blame] | 418 | PreferredExtendType.clear(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 421 | /// CreateReg - Allocate a single virtual register for the given type. |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 422 | unsigned FunctionLoweringInfo::CreateReg(MVT VT) { |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 423 | return RegInfo->createVirtualRegister( |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 424 | MF->getSubtarget().getTargetLowering()->getRegClassFor(VT)); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 427 | /// CreateRegs - Allocate the appropriate number of virtual registers of |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 428 | /// the correctly promoted or expanded types. Assign these registers |
| 429 | /// consecutive vreg numbers and return the first assigned number. |
| 430 | /// |
| 431 | /// In the case that the given value has struct or array type, this function |
| 432 | /// will assign registers for each member or element. |
| 433 | /// |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 434 | unsigned FunctionLoweringInfo::CreateRegs(Type *Ty) { |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 435 | const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); |
Bill Wendling | 0ccf310 | 2013-06-19 20:32:16 +0000 | [diff] [blame] | 436 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 437 | SmallVector<EVT, 4> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 438 | ComputeValueVTs(*TLI, Ty, ValueVTs); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 439 | |
| 440 | unsigned FirstReg = 0; |
| 441 | for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) { |
| 442 | EVT ValueVT = ValueVTs[Value]; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 443 | MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 444 | |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 445 | unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 446 | for (unsigned i = 0; i != NumRegs; ++i) { |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 447 | unsigned R = CreateReg(RegisterVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 448 | if (!FirstReg) FirstReg = R; |
| 449 | } |
| 450 | } |
| 451 | return FirstReg; |
| 452 | } |
Dan Gohman | ad97b3d | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 453 | |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 454 | /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the |
| 455 | /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If |
| 456 | /// the register's LiveOutInfo is for a smaller bit width, it is extended to |
| 457 | /// the larger bit width by zero extension. The bit width must be no smaller |
| 458 | /// than the LiveOutInfo's existing bit width. |
| 459 | const FunctionLoweringInfo::LiveOutInfo * |
| 460 | FunctionLoweringInfo::GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth) { |
| 461 | if (!LiveOutRegInfo.inBounds(Reg)) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 462 | return nullptr; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 463 | |
| 464 | LiveOutInfo *LOI = &LiveOutRegInfo[Reg]; |
| 465 | if (!LOI->IsValid) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 466 | return nullptr; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 467 | |
Cameron Zwarich | d2f3041 | 2011-02-25 01:10:55 +0000 | [diff] [blame] | 468 | if (BitWidth > LOI->KnownZero.getBitWidth()) { |
Cameron Zwarich | 4c82cd2 | 2011-02-25 01:11:01 +0000 | [diff] [blame] | 469 | LOI->NumSignBits = 1; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 470 | LOI->KnownZero = LOI->KnownZero.zextOrTrunc(BitWidth); |
| 471 | LOI->KnownOne = LOI->KnownOne.zextOrTrunc(BitWidth); |
| 472 | } |
| 473 | |
| 474 | return LOI; |
| 475 | } |
| 476 | |
| 477 | /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination |
| 478 | /// register based on the LiveOutInfo of its operands. |
| 479 | void FunctionLoweringInfo::ComputePHILiveOutRegInfo(const PHINode *PN) { |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 480 | Type *Ty = PN->getType(); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 481 | if (!Ty->isIntegerTy() || Ty->isVectorTy()) |
| 482 | return; |
| 483 | |
| 484 | SmallVector<EVT, 1> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 485 | ComputeValueVTs(*TLI, Ty, ValueVTs); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 486 | assert(ValueVTs.size() == 1 && |
| 487 | "PHIs with non-vector integer types should have a single VT."); |
| 488 | EVT IntVT = ValueVTs[0]; |
| 489 | |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 490 | if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1) |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 491 | return; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 492 | IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 493 | unsigned BitWidth = IntVT.getSizeInBits(); |
| 494 | |
| 495 | unsigned DestReg = ValueMap[PN]; |
| 496 | if (!TargetRegisterInfo::isVirtualRegister(DestReg)) |
| 497 | return; |
| 498 | LiveOutRegInfo.grow(DestReg); |
| 499 | LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg]; |
| 500 | |
| 501 | Value *V = PN->getIncomingValue(0); |
| 502 | if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { |
| 503 | DestLOI.NumSignBits = 1; |
| 504 | APInt Zero(BitWidth, 0); |
| 505 | DestLOI.KnownZero = Zero; |
| 506 | DestLOI.KnownOne = Zero; |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 511 | APInt Val = CI->getValue().zextOrTrunc(BitWidth); |
| 512 | DestLOI.NumSignBits = Val.getNumSignBits(); |
| 513 | DestLOI.KnownZero = ~Val; |
| 514 | DestLOI.KnownOne = Val; |
| 515 | } else { |
| 516 | assert(ValueMap.count(V) && "V should have been placed in ValueMap when its" |
| 517 | "CopyToReg node was created."); |
| 518 | unsigned SrcReg = ValueMap[V]; |
| 519 | if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { |
| 520 | DestLOI.IsValid = false; |
| 521 | return; |
| 522 | } |
| 523 | const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); |
| 524 | if (!SrcLOI) { |
| 525 | DestLOI.IsValid = false; |
| 526 | return; |
| 527 | } |
| 528 | DestLOI = *SrcLOI; |
| 529 | } |
| 530 | |
| 531 | assert(DestLOI.KnownZero.getBitWidth() == BitWidth && |
| 532 | DestLOI.KnownOne.getBitWidth() == BitWidth && |
| 533 | "Masks should have the same bit width as the type."); |
| 534 | |
| 535 | for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 536 | Value *V = PN->getIncomingValue(i); |
| 537 | if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { |
| 538 | DestLOI.NumSignBits = 1; |
| 539 | APInt Zero(BitWidth, 0); |
| 540 | DestLOI.KnownZero = Zero; |
| 541 | DestLOI.KnownOne = Zero; |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 542 | return; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 546 | APInt Val = CI->getValue().zextOrTrunc(BitWidth); |
| 547 | DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits()); |
| 548 | DestLOI.KnownZero &= ~Val; |
| 549 | DestLOI.KnownOne &= Val; |
| 550 | continue; |
| 551 | } |
| 552 | |
| 553 | assert(ValueMap.count(V) && "V should have been placed in ValueMap when " |
| 554 | "its CopyToReg node was created."); |
| 555 | unsigned SrcReg = ValueMap[V]; |
| 556 | if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { |
| 557 | DestLOI.IsValid = false; |
| 558 | return; |
| 559 | } |
| 560 | const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); |
| 561 | if (!SrcLOI) { |
| 562 | DestLOI.IsValid = false; |
| 563 | return; |
| 564 | } |
| 565 | DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits); |
| 566 | DestLOI.KnownZero &= SrcLOI->KnownZero; |
| 567 | DestLOI.KnownOne &= SrcLOI->KnownOne; |
| 568 | } |
| 569 | } |
| 570 | |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 571 | /// setArgumentFrameIndex - Record frame index for the byval |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 572 | /// argument. This overrides previous frame index entry for this argument, |
| 573 | /// if any. |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 574 | void FunctionLoweringInfo::setArgumentFrameIndex(const Argument *A, |
Eric Christopher | 219d51d | 2012-02-24 01:59:01 +0000 | [diff] [blame] | 575 | int FI) { |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 576 | ByValArgFrameIndexMap[A] = FI; |
| 577 | } |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 578 | |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 579 | /// getArgumentFrameIndex - Get frame index for the byval argument. |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 580 | /// If the argument does not have any assigned frame index then 0 is |
| 581 | /// returned. |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 582 | int FunctionLoweringInfo::getArgumentFrameIndex(const Argument *A) { |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 583 | DenseMap<const Argument *, int>::iterator I = |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 584 | ByValArgFrameIndexMap.find(A); |
| 585 | if (I != ByValArgFrameIndexMap.end()) |
| 586 | return I->second; |
Eric Christopher | 18c6be7 | 2012-02-23 03:39:43 +0000 | [diff] [blame] | 587 | DEBUG(dbgs() << "Argument does not have assigned frame index!\n"); |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Michael J. Spencer | 8b98bf2 | 2012-02-22 19:06:13 +0000 | [diff] [blame] | 591 | /// ComputeUsesVAFloatArgument - Determine if any floating-point values are |
| 592 | /// being passed to this variadic function, and set the MachineModuleInfo's |
| 593 | /// usesVAFloatArgument flag if so. This flag is used to emit an undefined |
| 594 | /// reference to _fltused on Windows, which will link in MSVCRT's |
| 595 | /// floating-point support. |
| 596 | void llvm::ComputeUsesVAFloatArgument(const CallInst &I, |
| 597 | MachineModuleInfo *MMI) |
| 598 | { |
| 599 | FunctionType *FT = cast<FunctionType>( |
| 600 | I.getCalledValue()->getType()->getContainedType(0)); |
| 601 | if (FT->isVarArg() && !MMI->usesVAFloatArgument()) { |
| 602 | for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) { |
| 603 | Type* T = I.getArgOperand(i)->getType(); |
| 604 | for (po_iterator<Type*> i = po_begin(T), e = po_end(T); |
| 605 | i != e; ++i) { |
| 606 | if (i->isFloatingPointTy()) { |
| 607 | MMI->setUsesVAFloatArgument(true); |
| 608 | return; |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 615 | /// AddLandingPadInfo - Extract the exception handling information from the |
| 616 | /// landingpad instruction and add them to the specified machine module info. |
| 617 | void llvm::AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI, |
| 618 | MachineBasicBlock *MBB) { |
| 619 | MMI.addPersonality(MBB, |
| 620 | cast<Function>(I.getPersonalityFn()->stripPointerCasts())); |
| 621 | |
| 622 | if (I.isCleanup()) |
| 623 | MMI.addCleanup(MBB); |
| 624 | |
| 625 | // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct, |
| 626 | // but we need to do it this way because of how the DWARF EH emitter |
| 627 | // processes the clauses. |
| 628 | for (unsigned i = I.getNumClauses(); i != 0; --i) { |
| 629 | Value *Val = I.getClause(i - 1); |
| 630 | if (I.isCatch(i - 1)) { |
| 631 | MMI.addCatchTypeInfo(MBB, |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 632 | dyn_cast<GlobalValue>(Val->stripPointerCasts())); |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 633 | } else { |
| 634 | // Add filters in a list. |
| 635 | Constant *CVal = cast<Constant>(Val); |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 636 | SmallVector<const GlobalValue*, 4> FilterList; |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 637 | for (User::op_iterator |
| 638 | II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 639 | FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts())); |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 640 | |
| 641 | MMI.addFilterTypeInfo(MBB, FilterList); |
| 642 | } |
| 643 | } |
| 644 | } |