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 | |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 83 | void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, |
| 84 | SelectionDAG *DAG) { |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 85 | Fn = &fn; |
| 86 | MF = &mf; |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 87 | TLI = MF->getSubtarget().getTargetLowering(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 88 | RegInfo = &MF->getRegInfo(); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 89 | MachineModuleInfo &MMI = MF->getMMI(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 90 | |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 91 | // Check whether the function can return without sret-demotion. |
| 92 | SmallVector<ISD::OutputArg, 4> Outs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 93 | GetReturnInfo(Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI); |
| 94 | CanLowerReturn = TLI->CanLowerReturn(Fn->getCallingConv(), *MF, |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 95 | Fn->isVarArg(), Outs, Fn->getContext()); |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 96 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 97 | // Initialize the mapping of values to registers. This is only set up for |
| 98 | // instruction values that are used outside of the block that defines |
| 99 | // them. |
Dan Gohman | 913c998 | 2010-04-15 04:33:49 +0000 | [diff] [blame] | 100 | Function::const_iterator BB = Fn->begin(), EB = Fn->end(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 101 | for (; BB != EB; ++BB) |
Eric Christopher | 219d51d | 2012-02-24 01:59:01 +0000 | [diff] [blame] | 102 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); |
| 103 | I != E; ++I) { |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 104 | if (const AllocaInst *AI = dyn_cast<AllocaInst>(I)) { |
Reid Kleckner | 0b2bccc | 2014-09-02 18:42:44 +0000 | [diff] [blame] | 105 | // Static allocas can be folded into the initial stack frame adjustment. |
| 106 | if (AI->isStaticAlloca()) { |
| 107 | const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize()); |
| 108 | Type *Ty = AI->getAllocatedType(); |
Mehdi Amini | 8ac7a9d | 2015-07-07 19:07:19 +0000 | [diff] [blame^] | 109 | uint64_t TySize = MF->getDataLayout().getTypeAllocSize(Ty); |
Reid Kleckner | 0b2bccc | 2014-09-02 18:42:44 +0000 | [diff] [blame] | 110 | unsigned Align = |
Mehdi Amini | 8ac7a9d | 2015-07-07 19:07:19 +0000 | [diff] [blame^] | 111 | std::max((unsigned)MF->getDataLayout().getPrefTypeAlignment(Ty), |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 112 | AI->getAlignment()); |
Reid Kleckner | 0b2bccc | 2014-09-02 18:42:44 +0000 | [diff] [blame] | 113 | |
| 114 | TySize *= CUI->getZExtValue(); // Get total allocated size. |
| 115 | if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects. |
| 116 | |
| 117 | StaticAllocaMap[AI] = |
| 118 | MF->getFrameInfo()->CreateStackObject(TySize, Align, false, AI); |
| 119 | |
| 120 | } else { |
Mehdi Amini | 8ac7a9d | 2015-07-07 19:07:19 +0000 | [diff] [blame^] | 121 | unsigned Align = |
| 122 | std::max((unsigned)MF->getDataLayout().getPrefTypeAlignment( |
| 123 | AI->getAllocatedType()), |
| 124 | AI->getAlignment()); |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 125 | unsigned StackAlign = |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 126 | MF->getSubtarget().getFrameLowering()->getStackAlignment(); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 127 | if (Align <= StackAlign) |
| 128 | Align = 0; |
| 129 | // Inform the Frame Information that we have variable-sized objects. |
| 130 | MF->getFrameInfo()->CreateVariableSizedObject(Align ? Align : 1, AI); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Look for inline asm that clobbers the SP register. |
| 135 | if (isa<CallInst>(I) || isa<InvokeInst>(I)) { |
| 136 | ImmutableCallSite CS(I); |
Hans Wennborg | 0c72fd2 | 2014-03-05 03:21:23 +0000 | [diff] [blame] | 137 | if (isa<InlineAsm>(CS.getCalledValue())) { |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 138 | unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 139 | const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 140 | std::vector<TargetLowering::AsmOperandInfo> Ops = |
Mehdi Amini | 8ac7a9d | 2015-07-07 19:07:19 +0000 | [diff] [blame^] | 141 | TLI->ParseConstraints(Fn->getParent()->getDataLayout(), TRI, CS); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 142 | for (size_t I = 0, E = Ops.size(); I != E; ++I) { |
| 143 | TargetLowering::AsmOperandInfo &Op = Ops[I]; |
| 144 | if (Op.Type == InlineAsm::isClobber) { |
| 145 | // Clobbers don't have SDValue operands, hence SDValue(). |
| 146 | TLI->ComputeConstraintToUse(Op, SDValue(), DAG); |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 147 | std::pair<unsigned, const TargetRegisterClass *> PhysReg = |
Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 148 | TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode, |
| 149 | Op.ConstraintVT); |
Hans Wennborg | acb842d | 2014-03-05 02:43:26 +0000 | [diff] [blame] | 150 | if (PhysReg.first == SP) |
| 151 | MF->getFrameInfo()->setHasInlineAsmWithSPAdjust(true); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 157 | // Look for calls to the @llvm.va_start intrinsic. We can omit some |
| 158 | // prologue boilerplate for variadic functions that don't examine their |
| 159 | // arguments. |
| 160 | if (const auto *II = dyn_cast<IntrinsicInst>(I)) { |
| 161 | if (II->getIntrinsicID() == Intrinsic::vastart) |
| 162 | MF->getFrameInfo()->setHasVAStart(true); |
| 163 | } |
| 164 | |
Reid Kleckner | 16e5541 | 2014-08-29 21:42:08 +0000 | [diff] [blame] | 165 | // If we have a musttail call in a variadic funciton, we need to ensure we |
| 166 | // forward implicit register parameters. |
Reid Kleckner | dccd0cb | 2014-08-29 21:42:21 +0000 | [diff] [blame] | 167 | if (const auto *CI = dyn_cast<CallInst>(I)) { |
Reid Kleckner | 16e5541 | 2014-08-29 21:42:08 +0000 | [diff] [blame] | 168 | if (CI->isMustTailCall() && Fn->isVarArg()) |
| 169 | MF->getFrameInfo()->setHasMustTailInVarArgFunc(true); |
| 170 | } |
| 171 | |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 172 | // Mark values used outside their block as exported, by allocating |
| 173 | // a virtual register for them. |
Cameron Zwarich | f8b22b3 | 2011-02-22 03:24:52 +0000 | [diff] [blame] | 174 | if (isUsedOutsideOfDefiningBlock(I)) |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 175 | if (!isa<AllocaInst>(I) || |
| 176 | !StaticAllocaMap.count(cast<AllocaInst>(I))) |
| 177 | InitializeRegForValue(I); |
| 178 | |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 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)) { |
Duncan P. N. Exon Smith | d4a19a3 | 2015-04-21 18:24:23 +0000 | [diff] [blame] | 183 | assert(DI->getVariable() && "Missing variable"); |
| 184 | assert(DI->getDebugLoc() && "Missing location"); |
| 185 | if (MMI.hasDebugInfo()) { |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 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; |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 198 | MMI.setVariableDbgInfo(DI->getVariable(), DI->getExpression(), |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 199 | FI, DI->getDebugLoc()); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
Jiangning Liu | ffbc690 | 2014-09-19 05:30:35 +0000 | [diff] [blame] | 205 | |
| 206 | // Decide the preferred extend type for a value. |
| 207 | PreferredExtendType[I] = getPreferredExtendForValue(I); |
Dan Gohman | 1e936277 | 2010-07-16 17:54:27 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 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. |
Dan Gohman | f57117d | 2010-04-14 16:30:40 +0000 | [diff] [blame] | 213 | for (BB = Fn->begin(); BB != EB; ++BB) { |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 214 | MachineBasicBlock *MBB = mf.CreateMachineBasicBlock(BB); |
| 215 | MBBMap[BB] = MBB; |
| 216 | MF->push_back(MBB); |
| 217 | |
| 218 | // Transfer the address-taken flag. This is necessary because there could |
| 219 | // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only |
| 220 | // the first one should be marked. |
| 221 | if (BB->hasAddressTaken()) |
| 222 | MBB->setHasAddressTaken(); |
| 223 | |
| 224 | // Create Machine PHI nodes for LLVM PHI nodes, lowering them as |
| 225 | // appropriate. |
Dan Gohman | 0f055d3 | 2010-04-20 14:46:25 +0000 | [diff] [blame] | 226 | for (BasicBlock::const_iterator I = BB->begin(); |
| 227 | const PHINode *PN = dyn_cast<PHINode>(I); ++I) { |
| 228 | if (PN->use_empty()) continue; |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 229 | |
Rafael Espindola | e53b7d1 | 2011-05-13 15:18:06 +0000 | [diff] [blame] | 230 | // Skip empty types |
| 231 | if (PN->getType()->isEmptyTy()) |
| 232 | continue; |
| 233 | |
Dan Gohman | 7b7f088 | 2010-04-20 14:48:02 +0000 | [diff] [blame] | 234 | DebugLoc DL = PN->getDebugLoc(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 235 | unsigned PHIReg = ValueMap[PN]; |
| 236 | assert(PHIReg && "PHI node does not have an assigned virtual register!"); |
| 237 | |
| 238 | SmallVector<EVT, 4> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 239 | ComputeValueVTs(*TLI, PN->getType(), ValueVTs); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 240 | for (unsigned vti = 0, vte = ValueVTs.size(); vti != vte; ++vti) { |
| 241 | EVT VT = ValueVTs[vti]; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 242 | unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 243 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 244 | for (unsigned i = 0; i != NumRegisters; ++i) |
Chris Lattner | b06015a | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 245 | BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 246 | PHIReg += NumRegisters; |
| 247 | } |
| 248 | } |
| 249 | } |
Dan Gohman | 69e8e32 | 2010-04-14 16:32:56 +0000 | [diff] [blame] | 250 | |
| 251 | // Mark landing pad blocks. |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 252 | SmallVector<const LandingPadInst *, 4> LPads; |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 253 | for (BB = Fn->begin(); BB != EB; ++BB) { |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 254 | if (const auto *Invoke = dyn_cast<InvokeInst>(BB->getTerminator())) |
Dan Gohman | 69e8e32 | 2010-04-14 16:32:56 +0000 | [diff] [blame] | 255 | MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad(); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 256 | if (BB->isLandingPad()) |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 257 | LPads.push_back(BB->getLandingPadInst()); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 258 | } |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 259 | |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 260 | // If this is an MSVC EH personality, we need to do a bit more work. |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 261 | EHPersonality Personality = EHPersonality::Unknown; |
David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 262 | if (Fn->hasPersonalityFn()) |
| 263 | Personality = classifyEHPersonality(Fn->getPersonalityFn()); |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 264 | if (!isMSVCEHPersonality(Personality)) |
| 265 | return; |
| 266 | |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 267 | if (Personality == EHPersonality::MSVC_Win64SEH || |
| 268 | Personality == EHPersonality::MSVC_X86SEH) { |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 269 | addSEHHandlersForLPads(LPads); |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 270 | } |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 271 | |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 272 | WinEHFuncInfo &EHInfo = MMI.getWinEHFuncInfo(&fn); |
| 273 | if (Personality == EHPersonality::MSVC_CXX) { |
| 274 | const Function *WinEHParentFn = MMI.getWinEHParent(&fn); |
| 275 | calculateWinCXXEHStateNumbers(WinEHParentFn, EHInfo); |
| 276 | } |
| 277 | |
| 278 | // Copy the state numbers to LandingPadInfo for the current function, which |
| 279 | // could be a handler or the parent. This should happen for 32-bit SEH and |
| 280 | // C++ EH. |
| 281 | if (Personality == EHPersonality::MSVC_CXX || |
| 282 | Personality == EHPersonality::MSVC_X86SEH) { |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 283 | for (const LandingPadInst *LP : LPads) { |
| 284 | MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()]; |
Reid Kleckner | fe4d491 | 2015-05-28 22:00:24 +0000 | [diff] [blame] | 285 | MMI.addWinEHState(LPadMBB, EHInfo.LandingPadStateMap[LP]); |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 286 | } |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 287 | } |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 290 | void FunctionLoweringInfo::addSEHHandlersForLPads( |
| 291 | ArrayRef<const LandingPadInst *> LPads) { |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 292 | MachineModuleInfo &MMI = MF->getMMI(); |
| 293 | |
| 294 | // Iterate over all landing pads with llvm.eh.actions calls. |
Reid Kleckner | cfbfe6f | 2015-04-24 20:25:05 +0000 | [diff] [blame] | 295 | for (const LandingPadInst *LP : LPads) { |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 296 | const IntrinsicInst *ActionsCall = |
| 297 | dyn_cast<IntrinsicInst>(LP->getNextNode()); |
| 298 | if (!ActionsCall || |
| 299 | ActionsCall->getIntrinsicID() != Intrinsic::eh_actions) |
| 300 | continue; |
| 301 | |
| 302 | // Parse the llvm.eh.actions call we found. |
| 303 | MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()]; |
Benjamin Kramer | a48e065 | 2015-05-16 15:40:03 +0000 | [diff] [blame] | 304 | SmallVector<std::unique_ptr<ActionHandler>, 4> Actions; |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 305 | parseEHActions(ActionsCall, Actions); |
| 306 | |
| 307 | // Iterate EH actions from most to least precedence, which means |
| 308 | // iterating in reverse. |
| 309 | for (auto I = Actions.rbegin(), E = Actions.rend(); I != E; ++I) { |
Benjamin Kramer | a48e065 | 2015-05-16 15:40:03 +0000 | [diff] [blame] | 310 | ActionHandler *Action = I->get(); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 311 | if (auto *CH = dyn_cast<CatchHandler>(Action)) { |
| 312 | const auto *Filter = |
| 313 | dyn_cast<Function>(CH->getSelector()->stripPointerCasts()); |
| 314 | assert((Filter || CH->getSelector()->isNullValue()) && |
| 315 | "expected function or catch-all"); |
| 316 | const auto *RecoverBA = |
| 317 | cast<BlockAddress>(CH->getHandlerBlockOrFunc()); |
| 318 | MMI.addSEHCatchHandler(LPadMBB, Filter, RecoverBA); |
| 319 | } else { |
| 320 | assert(isa<CleanupHandler>(Action)); |
| 321 | const auto *Fini = cast<Function>(Action->getHandlerBlockOrFunc()); |
| 322 | MMI.addSEHCleanupHandler(LPadMBB, Fini); |
| 323 | } |
| 324 | } |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 328 | /// clear - Clear out all the function-specific state. This returns this |
| 329 | /// FunctionLoweringInfo to an empty state, ready to be used for a |
| 330 | /// different function. |
| 331 | void FunctionLoweringInfo::clear() { |
Dan Gohman | ad0b3ea | 2010-04-14 17:11:23 +0000 | [diff] [blame] | 332 | assert(CatchInfoFound.size() == CatchInfoLost.size() && |
| 333 | "Not all catch info was assigned to a landing pad!"); |
| 334 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 335 | MBBMap.clear(); |
| 336 | ValueMap.clear(); |
| 337 | StaticAllocaMap.clear(); |
| 338 | #ifndef NDEBUG |
| 339 | CatchInfoLost.clear(); |
| 340 | CatchInfoFound.clear(); |
| 341 | #endif |
| 342 | LiveOutRegInfo.clear(); |
Cameron Zwarich | 988faf9 | 2011-02-24 10:00:13 +0000 | [diff] [blame] | 343 | VisitedBBs.clear(); |
Evan Cheng | 6e82245 | 2010-04-28 23:08:54 +0000 | [diff] [blame] | 344 | ArgDbgValues.clear(); |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 345 | ByValArgFrameIndexMap.clear(); |
Dan Gohman | d7b5ce3 | 2010-07-10 09:00:22 +0000 | [diff] [blame] | 346 | RegFixups.clear(); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 347 | StatepointStackSlots.clear(); |
Igor Laevsky | 423bc9ec | 2015-05-20 11:37:25 +0000 | [diff] [blame] | 348 | StatepointRelocatedValues.clear(); |
Jiangning Liu | 3b09617 | 2014-09-24 03:22:56 +0000 | [diff] [blame] | 349 | PreferredExtendType.clear(); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 352 | /// CreateReg - Allocate a single virtual register for the given type. |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 353 | unsigned FunctionLoweringInfo::CreateReg(MVT VT) { |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 354 | return RegInfo->createVirtualRegister( |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 355 | MF->getSubtarget().getTargetLowering()->getRegClassFor(VT)); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 358 | /// CreateRegs - Allocate the appropriate number of virtual registers of |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 359 | /// the correctly promoted or expanded types. Assign these registers |
| 360 | /// consecutive vreg numbers and return the first assigned number. |
| 361 | /// |
| 362 | /// In the case that the given value has struct or array type, this function |
| 363 | /// will assign registers for each member or element. |
| 364 | /// |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 365 | unsigned FunctionLoweringInfo::CreateRegs(Type *Ty) { |
Eric Christopher | 2ae2de7 | 2014-10-09 00:57:31 +0000 | [diff] [blame] | 366 | const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); |
Bill Wendling | 0ccf310 | 2013-06-19 20:32:16 +0000 | [diff] [blame] | 367 | |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 368 | SmallVector<EVT, 4> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 369 | ComputeValueVTs(*TLI, Ty, ValueVTs); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 370 | |
| 371 | unsigned FirstReg = 0; |
| 372 | for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) { |
| 373 | EVT ValueVT = ValueVTs[Value]; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 374 | MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 375 | |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 376 | unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 377 | for (unsigned i = 0; i != NumRegs; ++i) { |
Dan Gohman | 93f5920 | 2010-07-02 00:10:16 +0000 | [diff] [blame] | 378 | unsigned R = CreateReg(RegisterVT); |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 379 | if (!FirstReg) FirstReg = R; |
| 380 | } |
| 381 | } |
| 382 | return FirstReg; |
| 383 | } |
Dan Gohman | ad97b3d | 2009-11-23 17:42:46 +0000 | [diff] [blame] | 384 | |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 385 | /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the |
| 386 | /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If |
| 387 | /// the register's LiveOutInfo is for a smaller bit width, it is extended to |
| 388 | /// the larger bit width by zero extension. The bit width must be no smaller |
| 389 | /// than the LiveOutInfo's existing bit width. |
| 390 | const FunctionLoweringInfo::LiveOutInfo * |
| 391 | FunctionLoweringInfo::GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth) { |
| 392 | if (!LiveOutRegInfo.inBounds(Reg)) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 393 | return nullptr; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 394 | |
| 395 | LiveOutInfo *LOI = &LiveOutRegInfo[Reg]; |
| 396 | if (!LOI->IsValid) |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 397 | return nullptr; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 398 | |
Cameron Zwarich | d2f3041 | 2011-02-25 01:10:55 +0000 | [diff] [blame] | 399 | if (BitWidth > LOI->KnownZero.getBitWidth()) { |
Cameron Zwarich | 4c82cd2 | 2011-02-25 01:11:01 +0000 | [diff] [blame] | 400 | LOI->NumSignBits = 1; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 401 | LOI->KnownZero = LOI->KnownZero.zextOrTrunc(BitWidth); |
| 402 | LOI->KnownOne = LOI->KnownOne.zextOrTrunc(BitWidth); |
| 403 | } |
| 404 | |
| 405 | return LOI; |
| 406 | } |
| 407 | |
| 408 | /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination |
| 409 | /// register based on the LiveOutInfo of its operands. |
| 410 | void FunctionLoweringInfo::ComputePHILiveOutRegInfo(const PHINode *PN) { |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 411 | Type *Ty = PN->getType(); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 412 | if (!Ty->isIntegerTy() || Ty->isVectorTy()) |
| 413 | return; |
| 414 | |
| 415 | SmallVector<EVT, 1> ValueVTs; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 416 | ComputeValueVTs(*TLI, Ty, ValueVTs); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 417 | assert(ValueVTs.size() == 1 && |
| 418 | "PHIs with non-vector integer types should have a single VT."); |
| 419 | EVT IntVT = ValueVTs[0]; |
| 420 | |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 421 | if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1) |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 422 | return; |
Bill Wendling | 8db01cb | 2013-06-06 00:11:39 +0000 | [diff] [blame] | 423 | IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT); |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 424 | unsigned BitWidth = IntVT.getSizeInBits(); |
| 425 | |
| 426 | unsigned DestReg = ValueMap[PN]; |
| 427 | if (!TargetRegisterInfo::isVirtualRegister(DestReg)) |
| 428 | return; |
| 429 | LiveOutRegInfo.grow(DestReg); |
| 430 | LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg]; |
| 431 | |
| 432 | Value *V = PN->getIncomingValue(0); |
| 433 | if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { |
| 434 | DestLOI.NumSignBits = 1; |
| 435 | APInt Zero(BitWidth, 0); |
| 436 | DestLOI.KnownZero = Zero; |
| 437 | DestLOI.KnownOne = Zero; |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 442 | APInt Val = CI->getValue().zextOrTrunc(BitWidth); |
| 443 | DestLOI.NumSignBits = Val.getNumSignBits(); |
| 444 | DestLOI.KnownZero = ~Val; |
| 445 | DestLOI.KnownOne = Val; |
| 446 | } else { |
| 447 | assert(ValueMap.count(V) && "V should have been placed in ValueMap when its" |
| 448 | "CopyToReg node was created."); |
| 449 | unsigned SrcReg = ValueMap[V]; |
| 450 | if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { |
| 451 | DestLOI.IsValid = false; |
| 452 | return; |
| 453 | } |
| 454 | const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); |
| 455 | if (!SrcLOI) { |
| 456 | DestLOI.IsValid = false; |
| 457 | return; |
| 458 | } |
| 459 | DestLOI = *SrcLOI; |
| 460 | } |
| 461 | |
| 462 | assert(DestLOI.KnownZero.getBitWidth() == BitWidth && |
| 463 | DestLOI.KnownOne.getBitWidth() == BitWidth && |
| 464 | "Masks should have the same bit width as the type."); |
| 465 | |
| 466 | for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 467 | Value *V = PN->getIncomingValue(i); |
| 468 | if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) { |
| 469 | DestLOI.NumSignBits = 1; |
| 470 | APInt Zero(BitWidth, 0); |
| 471 | DestLOI.KnownZero = Zero; |
| 472 | DestLOI.KnownOne = Zero; |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 473 | return; |
Cameron Zwarich | a62fc89 | 2011-02-24 10:00:25 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 477 | APInt Val = CI->getValue().zextOrTrunc(BitWidth); |
| 478 | DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits()); |
| 479 | DestLOI.KnownZero &= ~Val; |
| 480 | DestLOI.KnownOne &= Val; |
| 481 | continue; |
| 482 | } |
| 483 | |
| 484 | assert(ValueMap.count(V) && "V should have been placed in ValueMap when " |
| 485 | "its CopyToReg node was created."); |
| 486 | unsigned SrcReg = ValueMap[V]; |
| 487 | if (!TargetRegisterInfo::isVirtualRegister(SrcReg)) { |
| 488 | DestLOI.IsValid = false; |
| 489 | return; |
| 490 | } |
| 491 | const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth); |
| 492 | if (!SrcLOI) { |
| 493 | DestLOI.IsValid = false; |
| 494 | return; |
| 495 | } |
| 496 | DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits); |
| 497 | DestLOI.KnownZero &= SrcLOI->KnownZero; |
| 498 | DestLOI.KnownOne &= SrcLOI->KnownOne; |
| 499 | } |
| 500 | } |
| 501 | |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 502 | /// setArgumentFrameIndex - Record frame index for the byval |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 503 | /// argument. This overrides previous frame index entry for this argument, |
| 504 | /// if any. |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 505 | void FunctionLoweringInfo::setArgumentFrameIndex(const Argument *A, |
Eric Christopher | 219d51d | 2012-02-24 01:59:01 +0000 | [diff] [blame] | 506 | int FI) { |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 507 | ByValArgFrameIndexMap[A] = FI; |
| 508 | } |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 509 | |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 510 | /// getArgumentFrameIndex - Get frame index for the byval argument. |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 511 | /// If the argument does not have any assigned frame index then 0 is |
| 512 | /// returned. |
Devang Patel | 9d904e1 | 2011-09-08 22:59:09 +0000 | [diff] [blame] | 513 | int FunctionLoweringInfo::getArgumentFrameIndex(const Argument *A) { |
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 514 | DenseMap<const Argument *, int>::iterator I = |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 515 | ByValArgFrameIndexMap.find(A); |
| 516 | if (I != ByValArgFrameIndexMap.end()) |
| 517 | return I->second; |
Eric Christopher | 18c6be7 | 2012-02-23 03:39:43 +0000 | [diff] [blame] | 518 | DEBUG(dbgs() << "Argument does not have assigned frame index!\n"); |
Devang Patel | 86ec8b3 | 2010-08-31 22:22:42 +0000 | [diff] [blame] | 519 | return 0; |
| 520 | } |
| 521 | |
Michael J. Spencer | 8b98bf2 | 2012-02-22 19:06:13 +0000 | [diff] [blame] | 522 | /// ComputeUsesVAFloatArgument - Determine if any floating-point values are |
| 523 | /// being passed to this variadic function, and set the MachineModuleInfo's |
| 524 | /// usesVAFloatArgument flag if so. This flag is used to emit an undefined |
| 525 | /// reference to _fltused on Windows, which will link in MSVCRT's |
| 526 | /// floating-point support. |
| 527 | void llvm::ComputeUsesVAFloatArgument(const CallInst &I, |
| 528 | MachineModuleInfo *MMI) |
| 529 | { |
| 530 | FunctionType *FT = cast<FunctionType>( |
| 531 | I.getCalledValue()->getType()->getContainedType(0)); |
| 532 | if (FT->isVarArg() && !MMI->usesVAFloatArgument()) { |
| 533 | for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) { |
| 534 | Type* T = I.getArgOperand(i)->getType(); |
Daniel Berlin | 25db4f4 | 2015-04-15 17:41:42 +0000 | [diff] [blame] | 535 | for (auto i : post_order(T)) { |
Michael J. Spencer | 8b98bf2 | 2012-02-22 19:06:13 +0000 | [diff] [blame] | 536 | if (i->isFloatingPointTy()) { |
| 537 | MMI->setUsesVAFloatArgument(true); |
| 538 | return; |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 545 | /// AddLandingPadInfo - Extract the exception handling information from the |
| 546 | /// landingpad instruction and add them to the specified machine module info. |
| 547 | void llvm::AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI, |
| 548 | MachineBasicBlock *MBB) { |
David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 549 | MMI.addPersonality( |
| 550 | MBB, |
| 551 | cast<Function>( |
| 552 | I.getParent()->getParent()->getPersonalityFn()->stripPointerCasts())); |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 553 | |
| 554 | if (I.isCleanup()) |
| 555 | MMI.addCleanup(MBB); |
| 556 | |
| 557 | // FIXME: New EH - Add the clauses in reverse order. This isn't 100% correct, |
| 558 | // but we need to do it this way because of how the DWARF EH emitter |
| 559 | // processes the clauses. |
| 560 | for (unsigned i = I.getNumClauses(); i != 0; --i) { |
| 561 | Value *Val = I.getClause(i - 1); |
| 562 | if (I.isCatch(i - 1)) { |
| 563 | MMI.addCatchTypeInfo(MBB, |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 564 | dyn_cast<GlobalValue>(Val->stripPointerCasts())); |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 565 | } else { |
| 566 | // Add filters in a list. |
| 567 | Constant *CVal = cast<Constant>(Val); |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 568 | SmallVector<const GlobalValue*, 4> FilterList; |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 569 | for (User::op_iterator |
| 570 | II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) |
Reid Kleckner | 283bc2e | 2014-11-14 00:35:50 +0000 | [diff] [blame] | 571 | FilterList.push_back(cast<GlobalValue>((*II)->stripPointerCasts())); |
Bill Wendling | 247fd3b | 2011-08-17 21:56:44 +0000 | [diff] [blame] | 572 | |
| 573 | MMI.addFilterTypeInfo(MBB, FilterList); |
| 574 | } |
| 575 | } |
| 576 | } |