Michael Gottesman | 3923bec | 2013-08-12 21:02:02 +0000 | [diff] [blame] | 1 | //===-- SelectionDAGBuilder.h - Selection-DAG building --------*- C++ -*---===// |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 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 from LLVM IR into SelectionDAG IR. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H |
| 15 | #define LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 16 | |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 17 | #include "StatepointLowering.h" |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/APInt.h" |
| 19 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SelectionDAG.h" |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 22 | #include "llvm/IR/CallSite.h" |
Igor Laevsky | 7fc58a4 | 2015-02-20 15:28:35 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Statepoint.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Constants.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Juergen Ributzka | fd4633e | 2014-10-16 21:26:35 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetLowering.h" |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 27 | #include <vector> |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 31 | class AddrSpaceCastInst; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 32 | class AliasAnalysis; |
| 33 | class AllocaInst; |
| 34 | class BasicBlock; |
| 35 | class BitCastInst; |
| 36 | class BranchInst; |
| 37 | class CallInst; |
Devang Patel | b12ff59 | 2010-08-26 23:35:15 +0000 | [diff] [blame] | 38 | class DbgValueInst; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 39 | class ExtractElementInst; |
| 40 | class ExtractValueInst; |
| 41 | class FCmpInst; |
| 42 | class FPExtInst; |
| 43 | class FPToSIInst; |
| 44 | class FPToUIInst; |
| 45 | class FPTruncInst; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 46 | class Function; |
Dan Gohman | a3624b6 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 47 | class FunctionLoweringInfo; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 48 | class GetElementPtrInst; |
| 49 | class GCFunctionInfo; |
| 50 | class ICmpInst; |
| 51 | class IntToPtrInst; |
Chris Lattner | d04cb6d | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 52 | class IndirectBrInst; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 53 | class InvokeInst; |
| 54 | class InsertElementInst; |
| 55 | class InsertValueInst; |
| 56 | class Instruction; |
| 57 | class LoadInst; |
| 58 | class MachineBasicBlock; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 59 | class MachineInstr; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 60 | class MachineRegisterInfo; |
Evan Cheng | 6e82245 | 2010-04-28 23:08:54 +0000 | [diff] [blame] | 61 | class MDNode; |
Patrik Hagglund | 1da3512 | 2014-03-12 08:00:24 +0000 | [diff] [blame] | 62 | class MVT; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 63 | class PHINode; |
| 64 | class PtrToIntInst; |
| 65 | class ReturnInst; |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 66 | class SDDbgValue; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 67 | class SExtInst; |
| 68 | class SelectInst; |
| 69 | class ShuffleVectorInst; |
| 70 | class SIToFPInst; |
| 71 | class StoreInst; |
| 72 | class SwitchInst; |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 73 | class DataLayout; |
Owen Anderson | bb15fec | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 74 | class TargetLibraryInfo; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 75 | class TargetLowering; |
| 76 | class TruncInst; |
| 77 | class UIToFPInst; |
| 78 | class UnreachableInst; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 79 | class VAArgInst; |
| 80 | class ZExtInst; |
| 81 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 82 | //===----------------------------------------------------------------------===// |
Dan Gohman | 1a6c47f | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 83 | /// SelectionDAGBuilder - This is the common target-independent lowering |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 84 | /// implementation that is parameterized by a TargetLowering object. |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 85 | /// |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 86 | class SelectionDAGBuilder { |
Andrew Trick | 175143b | 2013-05-25 02:20:36 +0000 | [diff] [blame] | 87 | /// CurInst - The current instruction being visited |
| 88 | const Instruction *CurInst; |
Dale Johannesen | db7c5f6 | 2009-01-31 02:22:37 +0000 | [diff] [blame] | 89 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 90 | DenseMap<const Value*, SDValue> NodeMap; |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 91 | |
Devang Patel | b0c7639 | 2010-06-01 19:59:01 +0000 | [diff] [blame] | 92 | /// UnusedArgNodeMap - Maps argument value for unused arguments. This is used |
| 93 | /// to preserve debug information for incoming arguments. |
| 94 | DenseMap<const Value*, SDValue> UnusedArgNodeMap; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 95 | |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 96 | /// DanglingDebugInfo - Helper type for DanglingDebugInfoMap. |
| 97 | class DanglingDebugInfo { |
Devang Patel | b12ff59 | 2010-08-26 23:35:15 +0000 | [diff] [blame] | 98 | const DbgValueInst* DI; |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 99 | DebugLoc dl; |
| 100 | unsigned SDNodeOrder; |
| 101 | public: |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 102 | DanglingDebugInfo() : DI(nullptr), dl(DebugLoc()), SDNodeOrder(0) { } |
Devang Patel | b12ff59 | 2010-08-26 23:35:15 +0000 | [diff] [blame] | 103 | DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) : |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 104 | DI(di), dl(DL), SDNodeOrder(SDNO) { } |
Devang Patel | b12ff59 | 2010-08-26 23:35:15 +0000 | [diff] [blame] | 105 | const DbgValueInst* getDI() { return DI; } |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 106 | DebugLoc getdl() { return dl; } |
| 107 | unsigned getSDNodeOrder() { return SDNodeOrder; } |
| 108 | }; |
| 109 | |
| 110 | /// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not |
| 111 | /// yet seen the referent. We defer handling these until we do see it. |
| 112 | DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap; |
| 113 | |
Chris Lattner | 1a32ede | 2009-12-24 00:37:38 +0000 | [diff] [blame] | 114 | public: |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 115 | /// PendingLoads - Loads are not emitted to the program immediately. We bunch |
| 116 | /// them up and then emit token factor nodes when possible. This allows us to |
| 117 | /// get simple disambiguation between loads without worrying about alias |
| 118 | /// analysis. |
| 119 | SmallVector<SDValue, 8> PendingLoads; |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 120 | |
| 121 | /// State used while lowering a statepoint sequence (gc_statepoint, |
| 122 | /// gc_relocate, and gc_result). See StatepointLowering.hpp/cpp for details. |
| 123 | StatepointLoweringState StatepointLowering; |
Chris Lattner | 1a32ede | 2009-12-24 00:37:38 +0000 | [diff] [blame] | 124 | private: |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 125 | |
| 126 | /// PendingExports - CopyToReg nodes that copy values to virtual registers |
| 127 | /// for export to other blocks need to be emitted before any terminator |
| 128 | /// instruction, but they have no other ordering requirements. We bunch them |
| 129 | /// up and the emit a single tokenfactor for them just before terminator |
| 130 | /// instructions. |
| 131 | SmallVector<SDValue, 8> PendingExports; |
| 132 | |
Bill Wendling | 022d18f | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 133 | /// SDNodeOrder - A unique monotonically increasing number used to order the |
| 134 | /// SDNodes we create. |
| 135 | unsigned SDNodeOrder; |
| 136 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 137 | /// Case - A struct to record the Value for a switch case, and the |
| 138 | /// case's target basic block. |
| 139 | struct Case { |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 140 | const ConstantInt *Low; |
| 141 | const ConstantInt *High; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 142 | MachineBasicBlock* BB; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 143 | uint32_t ExtraWeight; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 144 | |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 145 | Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { } |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 146 | Case(const ConstantInt *low, const ConstantInt *high, MachineBasicBlock *bb, |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 147 | uint32_t extraweight) : Low(low), High(high), BB(bb), |
| 148 | ExtraWeight(extraweight) { } |
| 149 | |
Chris Lattner | 8e1d722 | 2009-11-07 07:50:34 +0000 | [diff] [blame] | 150 | APInt size() const { |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 151 | const APInt &rHigh = High->getValue(); |
| 152 | const APInt &rLow = Low->getValue(); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 153 | return (rHigh - rLow + 1ULL); |
| 154 | } |
| 155 | }; |
| 156 | |
| 157 | struct CaseBits { |
| 158 | uint64_t Mask; |
| 159 | MachineBasicBlock* BB; |
| 160 | unsigned Bits; |
Manman Ren | cf10446 | 2012-08-24 18:14:27 +0000 | [diff] [blame] | 161 | uint32_t ExtraWeight; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 162 | |
Manman Ren | cf10446 | 2012-08-24 18:14:27 +0000 | [diff] [blame] | 163 | CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits, |
| 164 | uint32_t Weight): |
| 165 | Mask(mask), BB(bb), Bits(bits), ExtraWeight(Weight) { } |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | typedef std::vector<Case> CaseVector; |
| 169 | typedef std::vector<CaseBits> CaseBitsVector; |
| 170 | typedef CaseVector::iterator CaseItr; |
| 171 | typedef std::pair<CaseItr, CaseItr> CaseRange; |
| 172 | |
| 173 | /// CaseRec - A struct with ctor used in lowering switches to a binary tree |
| 174 | /// of conditional branches. |
| 175 | struct CaseRec { |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 176 | CaseRec(MachineBasicBlock *bb, const ConstantInt *lt, const ConstantInt *ge, |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 177 | CaseRange r) : |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 178 | CaseBB(bb), LT(lt), GE(ge), Range(r) {} |
| 179 | |
| 180 | /// CaseBB - The MBB in which to emit the compare and branch |
| 181 | MachineBasicBlock *CaseBB; |
| 182 | /// LT, GE - If nonzero, we know the current case value must be less-than or |
| 183 | /// greater-than-or-equal-to these Constants. |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 184 | const ConstantInt *LT; |
| 185 | const ConstantInt *GE; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 186 | /// Range - A pair of iterators representing the range of case values to be |
| 187 | /// processed at this point in the binary search tree. |
| 188 | CaseRange Range; |
| 189 | }; |
| 190 | |
| 191 | typedef std::vector<CaseRec> CaseRecVector; |
| 192 | |
Bob Wilson | e407736 | 2013-09-09 19:14:35 +0000 | [diff] [blame] | 193 | /// The comparison function for sorting the switch case values in the vector. |
| 194 | /// WARNING: Case ranges should be disjoint! |
| 195 | struct CaseCmp { |
| 196 | bool operator()(const Case &C1, const Case &C2) { |
Hans Wennborg | 7832543 | 2015-03-19 16:42:21 +0000 | [diff] [blame^] | 197 | return C1.Low->getValue().slt(C2.High->getValue()); |
Bob Wilson | e407736 | 2013-09-09 19:14:35 +0000 | [diff] [blame] | 198 | } |
| 199 | }; |
| 200 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 201 | struct CaseBitsCmp { |
Chris Lattner | 24576a5 | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 202 | bool operator()(const CaseBits &C1, const CaseBits &C2) { |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 203 | return C1.Bits > C2.Bits; |
| 204 | } |
| 205 | }; |
| 206 | |
Chad Rosier | df82a33 | 2014-10-13 19:46:39 +0000 | [diff] [blame] | 207 | void Clusterify(CaseVector &Cases, const SwitchInst &SI); |
Anton Korobeynikov | 6f21913 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 208 | |
Dan Gohman | 1a6c47f | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 209 | /// CaseBlock - This structure is used to communicate between |
| 210 | /// SelectionDAGBuilder and SDISel for the code generation of additional basic |
| 211 | /// blocks needed by multi-case switch statements. |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 212 | struct CaseBlock { |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 213 | CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs, |
| 214 | const Value *cmpmiddle, |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 215 | MachineBasicBlock *truebb, MachineBasicBlock *falsebb, |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 216 | MachineBasicBlock *me, |
| 217 | uint32_t trueweight = 0, uint32_t falseweight = 0) |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 218 | : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs), |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 219 | TrueBB(truebb), FalseBB(falsebb), ThisBB(me), |
| 220 | TrueWeight(trueweight), FalseWeight(falseweight) { } |
| 221 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 222 | // CC - the condition code to use for the case block's setcc node |
| 223 | ISD::CondCode CC; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 224 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 225 | // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit. |
| 226 | // Emit by default LHS op RHS. MHS is used for range comparisons: |
| 227 | // If MHS is not null: (LHS <= MHS) and (MHS <= RHS). |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 228 | const Value *CmpLHS, *CmpMHS, *CmpRHS; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 229 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 230 | // TrueBB/FalseBB - the block to branch to if the setcc is true/false. |
| 231 | MachineBasicBlock *TrueBB, *FalseBB; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 232 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 233 | // ThisBB - the block into which to emit the code for the setcc and branches |
| 234 | MachineBasicBlock *ThisBB; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 235 | |
| 236 | // TrueWeight/FalseWeight - branch weights. |
| 237 | uint32_t TrueWeight, FalseWeight; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 238 | }; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 239 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 240 | struct JumpTable { |
| 241 | JumpTable(unsigned R, unsigned J, MachineBasicBlock *M, |
| 242 | MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {} |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 243 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 244 | /// Reg - the virtual register containing the index of the jump table entry |
| 245 | //. to jump to. |
| 246 | unsigned Reg; |
| 247 | /// JTI - the JumpTableIndex for this jump table in the function. |
| 248 | unsigned JTI; |
| 249 | /// MBB - the MBB into which to emit the code for the indirect jump. |
| 250 | MachineBasicBlock *MBB; |
| 251 | /// Default - the MBB of the default bb, which is a successor of the range |
| 252 | /// check MBB. This is when updating PHI nodes in successors. |
| 253 | MachineBasicBlock *Default; |
| 254 | }; |
| 255 | struct JumpTableHeader { |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 256 | JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H, |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 257 | bool E = false): |
| 258 | First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {} |
Anton Korobeynikov | 6f21913 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 259 | APInt First; |
| 260 | APInt Last; |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 261 | const Value *SValue; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 262 | MachineBasicBlock *HeaderBB; |
| 263 | bool Emitted; |
| 264 | }; |
| 265 | typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock; |
| 266 | |
| 267 | struct BitTestCase { |
Manman Ren | cf10446 | 2012-08-24 18:14:27 +0000 | [diff] [blame] | 268 | BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr, |
| 269 | uint32_t Weight): |
| 270 | Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { } |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 271 | uint64_t Mask; |
Chris Lattner | 24576a5 | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 272 | MachineBasicBlock *ThisBB; |
| 273 | MachineBasicBlock *TargetBB; |
Manman Ren | cf10446 | 2012-08-24 18:14:27 +0000 | [diff] [blame] | 274 | uint32_t ExtraWeight; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | typedef SmallVector<BitTestCase, 3> BitTestInfo; |
| 278 | |
| 279 | struct BitTestBlock { |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 280 | BitTestBlock(APInt F, APInt R, const Value* SV, |
Patrik Hagglund | 4e0f828 | 2012-12-19 12:23:01 +0000 | [diff] [blame] | 281 | unsigned Rg, MVT RgVT, bool E, |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 282 | MachineBasicBlock* P, MachineBasicBlock* D, |
Benjamin Kramer | c6cc58e | 2014-10-04 16:55:56 +0000 | [diff] [blame] | 283 | BitTestInfo C): |
Evan Cheng | ac730dd | 2011-01-06 01:02:44 +0000 | [diff] [blame] | 284 | First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E), |
Benjamin Kramer | c6cc58e | 2014-10-04 16:55:56 +0000 | [diff] [blame] | 285 | Parent(P), Default(D), Cases(std::move(C)) { } |
Anton Korobeynikov | 6f21913 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 286 | APInt First; |
| 287 | APInt Range; |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 288 | const Value *SValue; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 289 | unsigned Reg; |
Patrik Hagglund | 4e0f828 | 2012-12-19 12:23:01 +0000 | [diff] [blame] | 290 | MVT RegVT; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 291 | bool Emitted; |
| 292 | MachineBasicBlock *Parent; |
| 293 | MachineBasicBlock *Default; |
| 294 | BitTestInfo Cases; |
| 295 | }; |
| 296 | |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 297 | /// A class which encapsulates all of the information needed to generate a |
| 298 | /// stack protector check and signals to isel via its state being initialized |
| 299 | /// that a stack protector needs to be generated. |
| 300 | /// |
| 301 | /// *NOTE* The following is a high level documentation of SelectionDAG Stack |
| 302 | /// Protector Generation. The reason that it is placed here is for a lack of |
| 303 | /// other good places to stick it. |
| 304 | /// |
| 305 | /// High Level Overview of SelectionDAG Stack Protector Generation: |
| 306 | /// |
| 307 | /// Previously, generation of stack protectors was done exclusively in the |
| 308 | /// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated |
| 309 | /// splitting basic blocks at the IR level to create the success/failure basic |
| 310 | /// blocks in the tail of the basic block in question. As a result of this, |
| 311 | /// calls that would have qualified for the sibling call optimization were no |
| 312 | /// longer eligible for optimization since said calls were no longer right in |
| 313 | /// the "tail position" (i.e. the immediate predecessor of a ReturnInst |
| 314 | /// instruction). |
| 315 | /// |
| 316 | /// Then it was noticed that since the sibling call optimization causes the |
| 317 | /// callee to reuse the caller's stack, if we could delay the generation of |
| 318 | /// the stack protector check until later in CodeGen after the sibling call |
| 319 | /// decision was made, we get both the tail call optimization and the stack |
| 320 | /// protector check! |
| 321 | /// |
| 322 | /// A few goals in solving this problem were: |
| 323 | /// |
| 324 | /// 1. Preserve the architecture independence of stack protector generation. |
| 325 | /// |
| 326 | /// 2. Preserve the normal IR level stack protector check for platforms like |
Alp Toker | cf21875 | 2014-06-30 18:57:16 +0000 | [diff] [blame] | 327 | /// OpenBSD for which we support platform-specific stack protector |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 328 | /// generation. |
| 329 | /// |
| 330 | /// The main problem that guided the present solution is that one can not |
| 331 | /// solve this problem in an architecture independent manner at the IR level |
| 332 | /// only. This is because: |
| 333 | /// |
| 334 | /// 1. The decision on whether or not to perform a sibling call on certain |
| 335 | /// platforms (for instance i386) requires lower level information |
| 336 | /// related to available registers that can not be known at the IR level. |
| 337 | /// |
| 338 | /// 2. Even if the previous point were not true, the decision on whether to |
| 339 | /// perform a tail call is done in LowerCallTo in SelectionDAG which |
| 340 | /// occurs after the Stack Protector Pass. As a result, one would need to |
| 341 | /// put the relevant callinst into the stack protector check success |
| 342 | /// basic block (where the return inst is placed) and then move it back |
| 343 | /// later at SelectionDAG/MI time before the stack protector check if the |
| 344 | /// tail call optimization failed. The MI level option was nixed |
Alp Toker | cf21875 | 2014-06-30 18:57:16 +0000 | [diff] [blame] | 345 | /// immediately since it would require platform-specific pattern |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 346 | /// matching. The SelectionDAG level option was nixed because |
| 347 | /// SelectionDAG only processes one IR level basic block at a time |
| 348 | /// implying one could not create a DAG Combine to move the callinst. |
| 349 | /// |
| 350 | /// To get around this problem a few things were realized: |
| 351 | /// |
| 352 | /// 1. While one can not handle multiple IR level basic blocks at the |
| 353 | /// SelectionDAG Level, one can generate multiple machine basic blocks |
| 354 | /// for one IR level basic block. This is how we handle bit tests and |
| 355 | /// switches. |
| 356 | /// |
| 357 | /// 2. At the MI level, tail calls are represented via a special return |
| 358 | /// MIInst called "tcreturn". Thus if we know the basic block in which we |
| 359 | /// wish to insert the stack protector check, we get the correct behavior |
| 360 | /// by always inserting the stack protector check right before the return |
| 361 | /// statement. This is a "magical transformation" since no matter where |
| 362 | /// the stack protector check intrinsic is, we always insert the stack |
| 363 | /// protector check code at the end of the BB. |
| 364 | /// |
| 365 | /// Given the aforementioned constraints, the following solution was devised: |
| 366 | /// |
| 367 | /// 1. On platforms that do not support SelectionDAG stack protector check |
| 368 | /// generation, allow for the normal IR level stack protector check |
| 369 | /// generation to continue. |
| 370 | /// |
| 371 | /// 2. On platforms that do support SelectionDAG stack protector check |
| 372 | /// generation: |
| 373 | /// |
| 374 | /// a. Use the IR level stack protector pass to decide if a stack |
| 375 | /// protector is required/which BB we insert the stack protector check |
| 376 | /// in by reusing the logic already therein. If we wish to generate a |
| 377 | /// stack protector check in a basic block, we place a special IR |
| 378 | /// intrinsic called llvm.stackprotectorcheck right before the BB's |
| 379 | /// returninst or if there is a callinst that could potentially be |
| 380 | /// sibling call optimized, before the call inst. |
| 381 | /// |
| 382 | /// b. Then when a BB with said intrinsic is processed, we codegen the BB |
| 383 | /// normally via SelectBasicBlock. In said process, when we visit the |
| 384 | /// stack protector check, we do not actually emit anything into the |
| 385 | /// BB. Instead, we just initialize the stack protector descriptor |
| 386 | /// class (which involves stashing information/creating the success |
| 387 | /// mbbb and the failure mbb if we have not created one for this |
| 388 | /// function yet) and export the guard variable that we are going to |
| 389 | /// compare. |
| 390 | /// |
| 391 | /// c. After we finish selecting the basic block, in FinishBasicBlock if |
| 392 | /// the StackProtectorDescriptor attached to the SelectionDAGBuilder is |
| 393 | /// initialized, we first find a splice point in the parent basic block |
| 394 | /// before the terminator and then splice the terminator of said basic |
| 395 | /// block into the success basic block. Then we code-gen a new tail for |
| 396 | /// the parent basic block consisting of the two loads, the comparison, |
| 397 | /// and finally two branches to the success/failure basic blocks. We |
| 398 | /// conclude by code-gening the failure basic block if we have not |
| 399 | /// code-gened it already (all stack protector checks we generate in |
| 400 | /// the same function, use the same failure basic block). |
| 401 | class StackProtectorDescriptor { |
| 402 | public: |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 403 | StackProtectorDescriptor() : ParentMBB(nullptr), SuccessMBB(nullptr), |
Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 404 | FailureMBB(nullptr), Guard(nullptr), |
| 405 | GuardReg(0) { } |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 406 | ~StackProtectorDescriptor() { } |
| 407 | |
| 408 | /// Returns true if all fields of the stack protector descriptor are |
| 409 | /// initialized implying that we should/are ready to emit a stack protector. |
| 410 | bool shouldEmitStackProtector() const { |
| 411 | return ParentMBB && SuccessMBB && FailureMBB && Guard; |
| 412 | } |
| 413 | |
| 414 | /// Initialize the stack protector descriptor structure for a new basic |
| 415 | /// block. |
| 416 | void initialize(const BasicBlock *BB, |
| 417 | MachineBasicBlock *MBB, |
| 418 | const CallInst &StackProtCheckCall) { |
| 419 | // Make sure we are not initialized yet. |
| 420 | assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is " |
| 421 | "already initialized!"); |
| 422 | ParentMBB = MBB; |
Akira Hatanaka | b9991a2 | 2014-12-01 04:27:03 +0000 | [diff] [blame] | 423 | SuccessMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ true); |
| 424 | FailureMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ false, FailureMBB); |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 425 | if (!Guard) |
| 426 | Guard = StackProtCheckCall.getArgOperand(0); |
| 427 | } |
| 428 | |
| 429 | /// Reset state that changes when we handle different basic blocks. |
| 430 | /// |
| 431 | /// This currently includes: |
| 432 | /// |
| 433 | /// 1. The specific basic block we are generating a |
| 434 | /// stack protector for (ParentMBB). |
| 435 | /// |
| 436 | /// 2. The successor machine basic block that will contain the tail of |
| 437 | /// parent mbb after we create the stack protector check (SuccessMBB). This |
| 438 | /// BB is visited only on stack protector check success. |
| 439 | void resetPerBBState() { |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 440 | ParentMBB = nullptr; |
| 441 | SuccessMBB = nullptr; |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /// Reset state that only changes when we switch functions. |
| 445 | /// |
| 446 | /// This currently includes: |
| 447 | /// |
| 448 | /// 1. FailureMBB since we reuse the failure code path for all stack |
| 449 | /// protector checks created in an individual function. |
| 450 | /// |
| 451 | /// 2.The guard variable since the guard variable we are checking against is |
| 452 | /// always the same. |
| 453 | void resetPerFunctionState() { |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 454 | FailureMBB = nullptr; |
| 455 | Guard = nullptr; |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | MachineBasicBlock *getParentMBB() { return ParentMBB; } |
| 459 | MachineBasicBlock *getSuccessMBB() { return SuccessMBB; } |
| 460 | MachineBasicBlock *getFailureMBB() { return FailureMBB; } |
| 461 | const Value *getGuard() { return Guard; } |
| 462 | |
Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 463 | unsigned getGuardReg() const { return GuardReg; } |
| 464 | void setGuardReg(unsigned R) { GuardReg = R; } |
| 465 | |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 466 | private: |
| 467 | /// The basic block for which we are generating the stack protector. |
| 468 | /// |
| 469 | /// As a result of stack protector generation, we will splice the |
| 470 | /// terminators of this basic block into the successor mbb SuccessMBB and |
| 471 | /// replace it with a compare/branch to the successor mbbs |
| 472 | /// SuccessMBB/FailureMBB depending on whether or not the stack protector |
| 473 | /// was violated. |
| 474 | MachineBasicBlock *ParentMBB; |
| 475 | |
| 476 | /// A basic block visited on stack protector check success that contains the |
| 477 | /// terminators of ParentMBB. |
| 478 | MachineBasicBlock *SuccessMBB; |
| 479 | |
| 480 | /// This basic block visited on stack protector check failure that will |
| 481 | /// contain a call to __stack_chk_fail(). |
| 482 | MachineBasicBlock *FailureMBB; |
| 483 | |
| 484 | /// The guard variable which we will compare against the stored value in the |
| 485 | /// stack protector stack slot. |
| 486 | const Value *Guard; |
| 487 | |
Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 488 | /// The virtual register holding the stack guard value. |
| 489 | unsigned GuardReg; |
| 490 | |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 491 | /// Add a successor machine basic block to ParentMBB. If the successor mbb |
| 492 | /// has not been created yet (i.e. if SuccMBB = 0), then the machine basic |
Akira Hatanaka | b9991a2 | 2014-12-01 04:27:03 +0000 | [diff] [blame] | 493 | /// block will be created. Assign a large weight if IsLikely is true. |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 494 | MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB, |
| 495 | MachineBasicBlock *ParentMBB, |
Akira Hatanaka | b9991a2 | 2014-12-01 04:27:03 +0000 | [diff] [blame] | 496 | bool IsLikely, |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 497 | MachineBasicBlock *SuccMBB = nullptr); |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 498 | }; |
| 499 | |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 500 | private: |
Dan Gohman | c334960 | 2010-04-19 19:05:59 +0000 | [diff] [blame] | 501 | const TargetMachine &TM; |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 502 | public: |
Nico Rieck | b5262d6 | 2014-01-12 14:09:17 +0000 | [diff] [blame] | 503 | /// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling |
| 504 | /// nodes without a corresponding SDNode. |
| 505 | static const unsigned LowestSDNodeOrder = 1; |
| 506 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 507 | SelectionDAG &DAG; |
Rafael Espindola | 5f57f46 | 2014-02-21 18:34:28 +0000 | [diff] [blame] | 508 | const DataLayout *DL; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 509 | AliasAnalysis *AA; |
Owen Anderson | bb15fec | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 510 | const TargetLibraryInfo *LibInfo; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 511 | |
| 512 | /// SwitchCases - Vector of CaseBlock structures used to communicate |
| 513 | /// SwitchInst code generation information. |
| 514 | std::vector<CaseBlock> SwitchCases; |
| 515 | /// JTCases - Vector of JumpTable structures used to communicate |
| 516 | /// SwitchInst code generation information. |
| 517 | std::vector<JumpTableBlock> JTCases; |
| 518 | /// BitTestCases - Vector of BitTestBlock structures used to communicate |
| 519 | /// SwitchInst code generation information. |
| 520 | std::vector<BitTestBlock> BitTestCases; |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 521 | /// A StackProtectorDescriptor structure used to communicate stack protector |
| 522 | /// information in between SelectBasicBlock and FinishBasicBlock. |
| 523 | StackProtectorDescriptor SPDescriptor; |
Evan Cheng | 270d0f9 | 2009-09-18 21:02:19 +0000 | [diff] [blame] | 524 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 525 | // Emit PHI-node-operand constants only once even if used by multiple |
| 526 | // PHI nodes. |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 527 | DenseMap<const Constant *, unsigned> ConstantsOut; |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 528 | |
| 529 | /// FuncInfo - Information about the function as a whole. |
| 530 | /// |
| 531 | FunctionLoweringInfo &FuncInfo; |
Bill Wendling | 19e0a5b | 2009-02-19 21:12:54 +0000 | [diff] [blame] | 532 | |
Bill Wendling | 084669a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 533 | /// OptLevel - What optimization level we're generating code for. |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 534 | /// |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 535 | CodeGenOpt::Level OptLevel; |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 536 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 537 | /// GFI - Garbage collection metadata for the function. |
| 538 | GCFunctionInfo *GFI; |
| 539 | |
Bill Wendling | 267f323 | 2011-10-05 22:24:35 +0000 | [diff] [blame] | 540 | /// LPadToCallSiteMap - Map a landing pad to the call site indexes. |
| 541 | DenseMap<MachineBasicBlock*, SmallVector<unsigned, 4> > LPadToCallSiteMap; |
Bill Wendling | 3d11aa7 | 2011-10-04 22:00:35 +0000 | [diff] [blame] | 542 | |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 543 | /// HasTailCall - This is set to true if a call in the current |
| 544 | /// block has been translated as a tail call. In this case, |
| 545 | /// no subsequent DAG nodes should be created. |
| 546 | /// |
| 547 | bool HasTailCall; |
| 548 | |
Owen Anderson | 53a5221 | 2009-07-13 04:09:18 +0000 | [diff] [blame] | 549 | LLVMContext *Context; |
| 550 | |
Dan Gohman | c334960 | 2010-04-19 19:05:59 +0000 | [diff] [blame] | 551 | SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo, |
Dan Gohman | 1a6c47f | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 552 | CodeGenOpt::Level ol) |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 553 | : CurInst(nullptr), SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()), |
Dan Gohman | c334960 | 2010-04-19 19:05:59 +0000 | [diff] [blame] | 554 | DAG(dag), FuncInfo(funcinfo), OptLevel(ol), |
Richard Smith | 3fb2047 | 2012-08-22 00:42:39 +0000 | [diff] [blame] | 555 | HasTailCall(false) { |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Owen Anderson | bb15fec | 2011-12-08 22:15:21 +0000 | [diff] [blame] | 558 | void init(GCFunctionInfo *gfi, AliasAnalysis &aa, |
| 559 | const TargetLibraryInfo *li); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 560 | |
Dan Gohman | f5cca35 | 2010-04-14 18:24:06 +0000 | [diff] [blame] | 561 | /// clear - Clear out the current SelectionDAG and the associated |
Dan Gohman | 1a6c47f | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 562 | /// state and prepare this SelectionDAGBuilder object to be used |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 563 | /// for a new block. This doesn't clear out information about |
| 564 | /// additional blocks that are needed to complete switch lowering |
| 565 | /// or PHI node updating; that information is cleared out as it is |
| 566 | /// consumed. |
| 567 | void clear(); |
| 568 | |
Devang Patel | 79928838 | 2011-05-23 17:44:13 +0000 | [diff] [blame] | 569 | /// clearDanglingDebugInfo - Clear the dangling debug information |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 570 | /// map. This function is separated from the clear so that debug |
Devang Patel | 79928838 | 2011-05-23 17:44:13 +0000 | [diff] [blame] | 571 | /// information that is dangling in a basic block can be properly |
| 572 | /// resolved in a different basic block. This allows the |
| 573 | /// SelectionDAG to resolve dangling debug information attached |
| 574 | /// to PHI nodes. |
| 575 | void clearDanglingDebugInfo(); |
| 576 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 577 | /// getRoot - Return the current virtual root of the Selection DAG, |
| 578 | /// flushing any PendingLoad items. This must be done before emitting |
| 579 | /// a store or any other node that may need to be ordered after any |
| 580 | /// prior load instructions. |
| 581 | /// |
| 582 | SDValue getRoot(); |
| 583 | |
| 584 | /// getControlRoot - Similar to getRoot, but instead of flushing all the |
| 585 | /// PendingLoad items, flush all the PendingExports items. It is necessary |
| 586 | /// to do this before emitting a terminator instruction. |
| 587 | /// |
| 588 | SDValue getControlRoot(); |
| 589 | |
Andrew Trick | 175143b | 2013-05-25 02:20:36 +0000 | [diff] [blame] | 590 | SDLoc getCurSDLoc() const { |
Andrew Trick | 175143b | 2013-05-25 02:20:36 +0000 | [diff] [blame] | 591 | return SDLoc(CurInst, SDNodeOrder); |
| 592 | } |
| 593 | |
| 594 | DebugLoc getCurDebugLoc() const { |
| 595 | return CurInst ? CurInst->getDebugLoc() : DebugLoc(); |
| 596 | } |
Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 597 | |
Bill Wendling | 919b7aa | 2009-12-22 02:10:19 +0000 | [diff] [blame] | 598 | unsigned getSDNodeOrder() const { return SDNodeOrder; } |
| 599 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 600 | void CopyValueToVirtualRegister(const Value *V, unsigned Reg); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 601 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 602 | void visit(const Instruction &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 603 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 604 | void visit(unsigned Opcode, const User &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 605 | |
Igor Laevsky | 85f7f72 | 2015-03-10 16:26:48 +0000 | [diff] [blame] | 606 | /// getCopyFromRegs - If there was virtual register allocated for the value V |
| 607 | /// emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise. |
| 608 | SDValue getCopyFromRegs(const Value *V, Type *Ty); |
| 609 | |
Dale Johannesen | bfd4fd7 | 2010-07-16 00:02:08 +0000 | [diff] [blame] | 610 | // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V, |
| 611 | // generate the debug data structures now that we've seen its definition. |
| 612 | void resolveDanglingDebugInfo(const Value *V, SDValue Val); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 613 | SDValue getValue(const Value *V); |
Dan Gohman | d432223 | 2010-07-01 01:59:43 +0000 | [diff] [blame] | 614 | SDValue getNonRegisterValue(const Value *V); |
| 615 | SDValue getValueImpl(const Value *V); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 616 | |
| 617 | void setValue(const Value *V, SDValue NewN) { |
| 618 | SDValue &N = NodeMap[V]; |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 619 | assert(!N.getNode() && "Already set a value for this node!"); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 620 | N = NewN; |
| 621 | } |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 622 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 623 | void removeValue(const Value *V) { |
| 624 | // This is to support hack in lowerCallFromStatepoint |
| 625 | // Should be removed when hack is resolved |
Benjamin Kramer | 4e3b903 | 2015-02-27 21:43:14 +0000 | [diff] [blame] | 626 | NodeMap.erase(V); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Devang Patel | b0c7639 | 2010-06-01 19:59:01 +0000 | [diff] [blame] | 629 | void setUnusedArgValue(const Value *V, SDValue NewN) { |
| 630 | SDValue &N = UnusedArgNodeMap[V]; |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 631 | assert(!N.getNode() && "Already set a value for this node!"); |
Devang Patel | b0c7639 | 2010-06-01 19:59:01 +0000 | [diff] [blame] | 632 | N = NewN; |
| 633 | } |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 634 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 635 | void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB, |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 636 | MachineBasicBlock *FBB, MachineBasicBlock *CurBB, |
Manman Ren | 4ece745 | 2014-01-31 00:42:44 +0000 | [diff] [blame] | 637 | MachineBasicBlock *SwitchBB, unsigned Opc, |
| 638 | uint32_t TW, uint32_t FW); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 639 | void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB, |
Dan Gohman | d01ddb5 | 2008-10-17 21:16:08 +0000 | [diff] [blame] | 640 | MachineBasicBlock *FBB, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 641 | MachineBasicBlock *CurBB, |
Manman Ren | 4ece745 | 2014-01-31 00:42:44 +0000 | [diff] [blame] | 642 | MachineBasicBlock *SwitchBB, |
| 643 | uint32_t TW, uint32_t FW); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 644 | bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 645 | bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB); |
| 646 | void CopyToExportRegsIfNeeded(const Value *V); |
| 647 | void ExportFromCurrentBlock(const Value *V); |
| 648 | void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall, |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 649 | MachineBasicBlock *LandingPad = nullptr); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 650 | |
Juergen Ributzka | ad2363f | 2014-10-17 17:39:00 +0000 | [diff] [blame] | 651 | std::pair<SDValue, SDValue> lowerCallOperands( |
| 652 | ImmutableCallSite CS, |
| 653 | unsigned ArgIdx, |
| 654 | unsigned NumArgs, |
| 655 | SDValue Callee, |
| 656 | bool UseVoidTy = false, |
Hal Finkel | 0ad96c8 | 2015-01-13 17:48:04 +0000 | [diff] [blame] | 657 | MachineBasicBlock *LandingPad = nullptr, |
| 658 | bool IsPatchPoint = false); |
Andrew Trick | 74f4c74 | 2013-10-31 17:18:24 +0000 | [diff] [blame] | 659 | |
Jakob Stoklund Olesen | 665aa6e | 2010-09-30 19:44:31 +0000 | [diff] [blame] | 660 | /// UpdateSplitBlock - When an MBB was split during scheduling, update the |
Alp Toker | 798060e | 2014-01-11 14:01:43 +0000 | [diff] [blame] | 661 | /// references that need to refer to the last resulting block. |
Jakob Stoklund Olesen | 665aa6e | 2010-09-30 19:44:31 +0000 | [diff] [blame] | 662 | void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last); |
| 663 | |
Igor Laevsky | 7fc58a4 | 2015-02-20 15:28:35 +0000 | [diff] [blame] | 664 | // This function is responsible for the whole statepoint lowering process. |
Igor Laevsky | 85f7f72 | 2015-03-10 16:26:48 +0000 | [diff] [blame] | 665 | // It uniformly handles invoke and call statepoints. |
| 666 | void LowerStatepoint(ImmutableStatepoint Statepoint, |
| 667 | MachineBasicBlock *LandingPad = nullptr); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 668 | private: |
Juergen Ributzka | fd4633e | 2014-10-16 21:26:35 +0000 | [diff] [blame] | 669 | std::pair<SDValue, SDValue> lowerInvokable( |
| 670 | TargetLowering::CallLoweringInfo &CLI, |
| 671 | MachineBasicBlock *LandingPad); |
| 672 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 673 | // Terminator instructions. |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 674 | void visitRet(const ReturnInst &I); |
| 675 | void visitBr(const BranchInst &I); |
| 676 | void visitSwitch(const SwitchInst &I); |
| 677 | void visitIndirectBr(const IndirectBrInst &I); |
Yaron Keren | d7ba46b | 2014-04-19 13:47:43 +0000 | [diff] [blame] | 678 | void visitUnreachable(const UnreachableInst &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 679 | |
| 680 | // Helpers for visitSwitch |
| 681 | bool handleSmallSwitchRange(CaseRec& CR, |
| 682 | CaseRecVector& WorkList, |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 683 | const Value* SV, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 684 | MachineBasicBlock* Default, |
| 685 | MachineBasicBlock *SwitchBB); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 686 | bool handleJTSwitchCase(CaseRec& CR, |
| 687 | CaseRecVector& WorkList, |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 688 | const Value* SV, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 689 | MachineBasicBlock* Default, |
| 690 | MachineBasicBlock *SwitchBB); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 691 | bool handleBTSplitSwitchCase(CaseRec& CR, |
| 692 | CaseRecVector& WorkList, |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 693 | const Value* SV, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 694 | MachineBasicBlock *SwitchBB); |
Daniel Jasper | d106b73 | 2015-01-20 08:57:44 +0000 | [diff] [blame] | 695 | void splitSwitchCase(CaseRec &CR, CaseItr Pivot, CaseRecVector &WorkList, |
| 696 | const Value *SV, MachineBasicBlock *SwitchBB); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 697 | bool handleBitTestsSwitchCase(CaseRec& CR, |
| 698 | CaseRecVector& WorkList, |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 699 | const Value* SV, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 700 | MachineBasicBlock* Default, |
| 701 | MachineBasicBlock *SwitchBB); |
Jakub Staszak | 12a43bd | 2011-06-16 20:22:37 +0000 | [diff] [blame] | 702 | |
Jakub Staszak | 96f8c55 | 2011-12-20 20:03:10 +0000 | [diff] [blame] | 703 | uint32_t getEdgeWeight(const MachineBasicBlock *Src, |
| 704 | const MachineBasicBlock *Dst) const; |
Jakub Staszak | 0480a8f | 2011-07-29 22:25:21 +0000 | [diff] [blame] | 705 | void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst, |
| 706 | uint32_t Weight = 0); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 707 | public: |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 708 | void visitSwitchCase(CaseBlock &CB, |
| 709 | MachineBasicBlock *SwitchBB); |
Michael Gottesman | b27f0f1 | 2013-08-20 07:00:16 +0000 | [diff] [blame] | 710 | void visitSPDescriptorParent(StackProtectorDescriptor &SPD, |
| 711 | MachineBasicBlock *ParentBB); |
| 712 | void visitSPDescriptorFailure(StackProtectorDescriptor &SPD); |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 713 | void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB); |
Evan Cheng | ac730dd | 2011-01-06 01:02:44 +0000 | [diff] [blame] | 714 | void visitBitTestCase(BitTestBlock &BB, |
| 715 | MachineBasicBlock* NextMBB, |
Manman Ren | cf10446 | 2012-08-24 18:14:27 +0000 | [diff] [blame] | 716 | uint32_t BranchWeightToNext, |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 717 | unsigned Reg, |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 718 | BitTestCase &B, |
| 719 | MachineBasicBlock *SwitchBB); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 720 | void visitJumpTable(JumpTable &JT); |
Dan Gohman | 7c0303a | 2010-04-19 22:41:47 +0000 | [diff] [blame] | 721 | void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH, |
| 722 | MachineBasicBlock *SwitchBB); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 723 | unsigned visitLandingPadClauseBB(GlobalValue *ClauseGV, |
| 724 | MachineBasicBlock *LPadMBB); |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 725 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 726 | private: |
| 727 | // These all get lowered before this pass. |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 728 | void visitInvoke(const InvokeInst &I); |
Bill Wendling | f891bf8 | 2011-07-31 06:30:59 +0000 | [diff] [blame] | 729 | void visitResume(const ResumeInst &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 730 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 731 | void visitBinary(const User &I, unsigned OpCode); |
| 732 | void visitShift(const User &I, unsigned Opcode); |
| 733 | void visitAdd(const User &I) { visitBinary(I, ISD::ADD); } |
| 734 | void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); } |
| 735 | void visitSub(const User &I) { visitBinary(I, ISD::SUB); } |
| 736 | void visitFSub(const User &I); |
| 737 | void visitMul(const User &I) { visitBinary(I, ISD::MUL); } |
| 738 | void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); } |
| 739 | void visitURem(const User &I) { visitBinary(I, ISD::UREM); } |
| 740 | void visitSRem(const User &I) { visitBinary(I, ISD::SREM); } |
| 741 | void visitFRem(const User &I) { visitBinary(I, ISD::FREM); } |
| 742 | void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); } |
Benjamin Kramer | 9960a25 | 2011-07-08 10:31:30 +0000 | [diff] [blame] | 743 | void visitSDiv(const User &I); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 744 | void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); } |
| 745 | void visitAnd (const User &I) { visitBinary(I, ISD::AND); } |
| 746 | void visitOr (const User &I) { visitBinary(I, ISD::OR); } |
| 747 | void visitXor (const User &I) { visitBinary(I, ISD::XOR); } |
| 748 | void visitShl (const User &I) { visitShift(I, ISD::SHL); } |
| 749 | void visitLShr(const User &I) { visitShift(I, ISD::SRL); } |
| 750 | void visitAShr(const User &I) { visitShift(I, ISD::SRA); } |
| 751 | void visitICmp(const User &I); |
| 752 | void visitFCmp(const User &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 753 | // Visit the conversion instructions |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 754 | void visitTrunc(const User &I); |
| 755 | void visitZExt(const User &I); |
| 756 | void visitSExt(const User &I); |
| 757 | void visitFPTrunc(const User &I); |
| 758 | void visitFPExt(const User &I); |
| 759 | void visitFPToUI(const User &I); |
| 760 | void visitFPToSI(const User &I); |
| 761 | void visitUIToFP(const User &I); |
| 762 | void visitSIToFP(const User &I); |
| 763 | void visitPtrToInt(const User &I); |
| 764 | void visitIntToPtr(const User &I); |
| 765 | void visitBitCast(const User &I); |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 766 | void visitAddrSpaceCast(const User &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 767 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 768 | void visitExtractElement(const User &I); |
| 769 | void visitInsertElement(const User &I); |
| 770 | void visitShuffleVector(const User &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 771 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 772 | void visitExtractValue(const ExtractValueInst &I); |
| 773 | void visitInsertValue(const InsertValueInst &I); |
Bill Wendling | fae1475 | 2011-08-12 20:24:12 +0000 | [diff] [blame] | 774 | void visitLandingPad(const LandingPadInst &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 775 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 776 | void visitGetElementPtr(const User &I); |
| 777 | void visitSelect(const User &I); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 778 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 779 | void visitAlloca(const AllocaInst &I); |
| 780 | void visitLoad(const LoadInst &I); |
| 781 | void visitStore(const StoreInst &I); |
Elena Demikhovsky | f1de34b | 2014-12-04 09:40:44 +0000 | [diff] [blame] | 782 | void visitMaskedLoad(const CallInst &I); |
| 783 | void visitMaskedStore(const CallInst &I); |
Eli Friedman | c9a551e | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 784 | void visitAtomicCmpXchg(const AtomicCmpXchgInst &I); |
| 785 | void visitAtomicRMW(const AtomicRMWInst &I); |
Eli Friedman | fee02c6 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 786 | void visitFence(const FenceInst &I); |
Dan Gohman | f41ad47 | 2010-04-20 15:00:41 +0000 | [diff] [blame] | 787 | void visitPHI(const PHINode &I); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 788 | void visitCall(const CallInst &I); |
| 789 | bool visitMemCmpCall(const CallInst &I); |
Richard Sandiford | 6f6d551 | 2013-08-20 09:38:48 +0000 | [diff] [blame] | 790 | bool visitMemChrCall(const CallInst &I); |
Richard Sandiford | bb83a50 | 2013-08-16 11:29:37 +0000 | [diff] [blame] | 791 | bool visitStrCpyCall(const CallInst &I, bool isStpcpy); |
Richard Sandiford | ca23271 | 2013-08-16 11:21:54 +0000 | [diff] [blame] | 792 | bool visitStrCmpCall(const CallInst &I); |
Richard Sandiford | 0dec06a | 2013-08-16 11:41:43 +0000 | [diff] [blame] | 793 | bool visitStrLenCall(const CallInst &I); |
| 794 | bool visitStrNLenCall(const CallInst &I); |
Bob Wilson | 874886c | 2012-08-03 23:29:17 +0000 | [diff] [blame] | 795 | bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode); |
Matt Arsenault | 7c93690 | 2014-10-21 23:01:01 +0000 | [diff] [blame] | 796 | bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode); |
Eli Friedman | 342e8df | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 797 | void visitAtomicLoad(const LoadInst &I); |
| 798 | void visitAtomicStore(const StoreInst &I); |
| 799 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 800 | void visitInlineAsm(ImmutableCallSite CS); |
| 801 | const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic); |
| 802 | void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 803 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 804 | void visitVAStart(const CallInst &I); |
| 805 | void visitVAArg(const VAArgInst &I); |
| 806 | void visitVAEnd(const CallInst &I); |
| 807 | void visitVACopy(const CallInst &I); |
Andrew Trick | 74f4c74 | 2013-10-31 17:18:24 +0000 | [diff] [blame] | 808 | void visitStackmap(const CallInst &I); |
Juergen Ributzka | ad2363f | 2014-10-17 17:39:00 +0000 | [diff] [blame] | 809 | void visitPatchpoint(ImmutableCallSite CS, |
| 810 | MachineBasicBlock *LandingPad = nullptr); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 811 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 812 | // These three are implemented in StatepointLowering.cpp |
| 813 | void visitStatepoint(const CallInst &I); |
| 814 | void visitGCRelocate(const CallInst &I); |
| 815 | void visitGCResult(const CallInst &I); |
| 816 | |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 817 | void visitUserOp1(const Instruction &I) { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 818 | llvm_unreachable("UserOp1 should not exist at instruction selection time!"); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 819 | } |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 820 | void visitUserOp2(const Instruction &I) { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 821 | llvm_unreachable("UserOp2 should not exist at instruction selection time!"); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 822 | } |
Dan Gohman | 5b43aa0 | 2010-04-22 20:55:53 +0000 | [diff] [blame] | 823 | |
Richard Sandiford | e382775 | 2013-08-16 10:55:47 +0000 | [diff] [blame] | 824 | void processIntegerCallValue(const Instruction &I, |
| 825 | SDValue Value, bool IsSigned); |
| 826 | |
Dan Gohman | 5b43aa0 | 2010-04-22 20:55:53 +0000 | [diff] [blame] | 827 | void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB); |
Evan Cheng | 6e82245 | 2010-04-28 23:08:54 +0000 | [diff] [blame] | 828 | |
Devang Patel | 32a72ab | 2010-08-25 20:41:24 +0000 | [diff] [blame] | 829 | /// EmitFuncArgumentDbgValue - If V is an function argument then create |
Andrew Trick | d4d1d9c | 2013-10-31 17:18:07 +0000 | [diff] [blame] | 830 | /// corresponding DBG_VALUE machine instruction for it now. At the end of |
Devang Patel | 32a72ab | 2010-08-25 20:41:24 +0000 | [diff] [blame] | 831 | /// instruction selection, they will be inserted to the entry BB. |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 832 | bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable, MDNode *Expr, |
Adrian Prantl | 32da889 | 2014-04-25 20:49:25 +0000 | [diff] [blame] | 833 | int64_t Offset, bool IsIndirect, |
| 834 | const SDValue &N); |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 835 | }; |
| 836 | |
Dan Gohman | 575fad3 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 837 | } // end namespace llvm |
| 838 | |
| 839 | #endif |