Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 1 | //===-- SelectionDAGBuilder.h - Selection-DAG building --------------------===// |
Dan Gohman | f0cbcd4 | 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 | |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 14 | #ifndef SELECTIONDAGBUILDER_H |
| 15 | #define SELECTIONDAGBUILDER_H |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 16 | |
| 17 | #include "llvm/Constants.h" |
Owen Anderson | 0a5372e | 2009-07-13 04:09:18 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/SelectionDAG.h" |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APInt.h" |
| 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #ifndef NDEBUG |
| 22 | #include "llvm/ADT/SmallSet.h" |
| 23 | #endif |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Bill Wendling | 0eb96fd | 2009-02-03 01:32:22 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/ValueTypes.h" |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CallSite.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 28 | #include <vector> |
| 29 | #include <set> |
| 30 | |
| 31 | namespace llvm { |
| 32 | |
| 33 | class AliasAnalysis; |
| 34 | class AllocaInst; |
| 35 | class BasicBlock; |
| 36 | class BitCastInst; |
| 37 | class BranchInst; |
| 38 | class CallInst; |
| 39 | class ExtractElementInst; |
| 40 | class ExtractValueInst; |
| 41 | class FCmpInst; |
| 42 | class FPExtInst; |
| 43 | class FPToSIInst; |
| 44 | class FPToUIInst; |
| 45 | class FPTruncInst; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 46 | class Function; |
Dan Gohman | 6277eb2 | 2009-11-23 17:16:22 +0000 | [diff] [blame] | 47 | class FunctionLoweringInfo; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 48 | class GetElementPtrInst; |
| 49 | class GCFunctionInfo; |
| 50 | class ICmpInst; |
| 51 | class IntToPtrInst; |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 52 | class IndirectBrInst; |
Dan Gohman | f0cbcd4 | 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; |
| 59 | class MachineFunction; |
| 60 | class MachineInstr; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 61 | class MachineRegisterInfo; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 62 | class PHINode; |
| 63 | class PtrToIntInst; |
| 64 | class ReturnInst; |
| 65 | class SDISelAsmOperandInfo; |
| 66 | class SExtInst; |
| 67 | class SelectInst; |
| 68 | class ShuffleVectorInst; |
| 69 | class SIToFPInst; |
| 70 | class StoreInst; |
| 71 | class SwitchInst; |
| 72 | class TargetData; |
| 73 | class TargetLowering; |
| 74 | class TruncInst; |
| 75 | class UIToFPInst; |
| 76 | class UnreachableInst; |
| 77 | class UnwindInst; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 78 | class VAArgInst; |
| 79 | class ZExtInst; |
| 80 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 81 | //===----------------------------------------------------------------------===// |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 82 | /// SelectionDAGBuilder - This is the common target-independent lowering |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 83 | /// implementation that is parameterized by a TargetLowering object. |
| 84 | /// Also, targets can overload any lowering method. |
| 85 | /// |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 86 | class SelectionDAGBuilder { |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 87 | MachineBasicBlock *CurMBB; |
| 88 | |
Dale Johannesen | 66978ee | 2009-01-31 02:22:37 +0000 | [diff] [blame] | 89 | /// CurDebugLoc - current file + line number. Changes as we build the DAG. |
| 90 | DebugLoc CurDebugLoc; |
| 91 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 92 | DenseMap<const Value*, SDValue> NodeMap; |
| 93 | |
Chris Lattner | 8047d9a | 2009-12-24 00:37:38 +0000 | [diff] [blame] | 94 | public: |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 95 | /// PendingLoads - Loads are not emitted to the program immediately. We bunch |
| 96 | /// them up and then emit token factor nodes when possible. This allows us to |
| 97 | /// get simple disambiguation between loads without worrying about alias |
| 98 | /// analysis. |
| 99 | SmallVector<SDValue, 8> PendingLoads; |
Chris Lattner | 8047d9a | 2009-12-24 00:37:38 +0000 | [diff] [blame] | 100 | private: |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 101 | |
| 102 | /// PendingExports - CopyToReg nodes that copy values to virtual registers |
| 103 | /// for export to other blocks need to be emitted before any terminator |
| 104 | /// instruction, but they have no other ordering requirements. We bunch them |
| 105 | /// up and the emit a single tokenfactor for them just before terminator |
| 106 | /// instructions. |
| 107 | SmallVector<SDValue, 8> PendingExports; |
| 108 | |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 109 | /// SDNodeOrder - A unique monotonically increasing number used to order the |
| 110 | /// SDNodes we create. |
| 111 | unsigned SDNodeOrder; |
| 112 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 113 | /// Case - A struct to record the Value for a switch case, and the |
| 114 | /// case's target basic block. |
| 115 | struct Case { |
| 116 | Constant* Low; |
| 117 | Constant* High; |
| 118 | MachineBasicBlock* BB; |
| 119 | |
| 120 | Case() : Low(0), High(0), BB(0) { } |
| 121 | Case(Constant* low, Constant* high, MachineBasicBlock* bb) : |
| 122 | Low(low), High(high), BB(bb) { } |
Chris Lattner | e880efe | 2009-11-07 07:50:34 +0000 | [diff] [blame] | 123 | APInt size() const { |
| 124 | const APInt &rHigh = cast<ConstantInt>(High)->getValue(); |
| 125 | const APInt &rLow = cast<ConstantInt>(Low)->getValue(); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 126 | return (rHigh - rLow + 1ULL); |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | struct CaseBits { |
| 131 | uint64_t Mask; |
| 132 | MachineBasicBlock* BB; |
| 133 | unsigned Bits; |
| 134 | |
| 135 | CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits): |
| 136 | Mask(mask), BB(bb), Bits(bits) { } |
| 137 | }; |
| 138 | |
| 139 | typedef std::vector<Case> CaseVector; |
| 140 | typedef std::vector<CaseBits> CaseBitsVector; |
| 141 | typedef CaseVector::iterator CaseItr; |
| 142 | typedef std::pair<CaseItr, CaseItr> CaseRange; |
| 143 | |
| 144 | /// CaseRec - A struct with ctor used in lowering switches to a binary tree |
| 145 | /// of conditional branches. |
| 146 | struct CaseRec { |
| 147 | CaseRec(MachineBasicBlock *bb, Constant *lt, Constant *ge, CaseRange r) : |
| 148 | CaseBB(bb), LT(lt), GE(ge), Range(r) {} |
| 149 | |
| 150 | /// CaseBB - The MBB in which to emit the compare and branch |
| 151 | MachineBasicBlock *CaseBB; |
| 152 | /// LT, GE - If nonzero, we know the current case value must be less-than or |
| 153 | /// greater-than-or-equal-to these Constants. |
| 154 | Constant *LT; |
| 155 | Constant *GE; |
| 156 | /// Range - A pair of iterators representing the range of case values to be |
| 157 | /// processed at this point in the binary search tree. |
| 158 | CaseRange Range; |
| 159 | }; |
| 160 | |
| 161 | typedef std::vector<CaseRec> CaseRecVector; |
| 162 | |
| 163 | /// The comparison function for sorting the switch case values in the vector. |
| 164 | /// WARNING: Case ranges should be disjoint! |
| 165 | struct CaseCmp { |
Chris Lattner | 53334ca | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 166 | bool operator()(const Case &C1, const Case &C2) { |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 167 | assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High)); |
| 168 | const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low); |
| 169 | const ConstantInt* CI2 = cast<const ConstantInt>(C2.High); |
| 170 | return CI1->getValue().slt(CI2->getValue()); |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | struct CaseBitsCmp { |
Chris Lattner | 53334ca | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 175 | bool operator()(const CaseBits &C1, const CaseBits &C2) { |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 176 | return C1.Bits > C2.Bits; |
| 177 | } |
| 178 | }; |
| 179 | |
Chris Lattner | 53334ca | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 180 | size_t Clusterify(CaseVector &Cases, const SwitchInst &SI); |
Anton Korobeynikov | 2321858 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 181 | |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 182 | /// CaseBlock - This structure is used to communicate between |
| 183 | /// SelectionDAGBuilder and SDISel for the code generation of additional basic |
| 184 | /// blocks needed by multi-case switch statements. |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 185 | struct CaseBlock { |
| 186 | CaseBlock(ISD::CondCode cc, Value *cmplhs, Value *cmprhs, Value *cmpmiddle, |
| 187 | MachineBasicBlock *truebb, MachineBasicBlock *falsebb, |
| 188 | MachineBasicBlock *me) |
| 189 | : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs), |
| 190 | TrueBB(truebb), FalseBB(falsebb), ThisBB(me) {} |
| 191 | // CC - the condition code to use for the case block's setcc node |
| 192 | ISD::CondCode CC; |
| 193 | // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit. |
| 194 | // Emit by default LHS op RHS. MHS is used for range comparisons: |
| 195 | // If MHS is not null: (LHS <= MHS) and (MHS <= RHS). |
| 196 | Value *CmpLHS, *CmpMHS, *CmpRHS; |
| 197 | // TrueBB/FalseBB - the block to branch to if the setcc is true/false. |
| 198 | MachineBasicBlock *TrueBB, *FalseBB; |
| 199 | // ThisBB - the block into which to emit the code for the setcc and branches |
| 200 | MachineBasicBlock *ThisBB; |
| 201 | }; |
| 202 | struct JumpTable { |
| 203 | JumpTable(unsigned R, unsigned J, MachineBasicBlock *M, |
| 204 | MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {} |
| 205 | |
| 206 | /// Reg - the virtual register containing the index of the jump table entry |
| 207 | //. to jump to. |
| 208 | unsigned Reg; |
| 209 | /// JTI - the JumpTableIndex for this jump table in the function. |
| 210 | unsigned JTI; |
| 211 | /// MBB - the MBB into which to emit the code for the indirect jump. |
| 212 | MachineBasicBlock *MBB; |
| 213 | /// Default - the MBB of the default bb, which is a successor of the range |
| 214 | /// check MBB. This is when updating PHI nodes in successors. |
| 215 | MachineBasicBlock *Default; |
| 216 | }; |
| 217 | struct JumpTableHeader { |
Chris Lattner | 53334ca | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 218 | JumpTableHeader(APInt F, APInt L, Value *SV, MachineBasicBlock *H, |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 219 | bool E = false): |
| 220 | First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {} |
Anton Korobeynikov | 2321858 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 221 | APInt First; |
| 222 | APInt Last; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 223 | Value *SValue; |
| 224 | MachineBasicBlock *HeaderBB; |
| 225 | bool Emitted; |
| 226 | }; |
| 227 | typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock; |
| 228 | |
| 229 | struct BitTestCase { |
| 230 | BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr): |
| 231 | Mask(M), ThisBB(T), TargetBB(Tr) { } |
| 232 | uint64_t Mask; |
Chris Lattner | 53334ca | 2010-01-01 23:37:34 +0000 | [diff] [blame] | 233 | MachineBasicBlock *ThisBB; |
| 234 | MachineBasicBlock *TargetBB; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | typedef SmallVector<BitTestCase, 3> BitTestInfo; |
| 238 | |
| 239 | struct BitTestBlock { |
Anton Korobeynikov | 2321858 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 240 | BitTestBlock(APInt F, APInt R, Value* SV, |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 241 | unsigned Rg, bool E, |
| 242 | MachineBasicBlock* P, MachineBasicBlock* D, |
| 243 | const BitTestInfo& C): |
| 244 | First(F), Range(R), SValue(SV), Reg(Rg), Emitted(E), |
| 245 | Parent(P), Default(D), Cases(C) { } |
Anton Korobeynikov | 2321858 | 2008-12-23 22:25:27 +0000 | [diff] [blame] | 246 | APInt First; |
| 247 | APInt Range; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 248 | Value *SValue; |
| 249 | unsigned Reg; |
| 250 | bool Emitted; |
| 251 | MachineBasicBlock *Parent; |
| 252 | MachineBasicBlock *Default; |
| 253 | BitTestInfo Cases; |
| 254 | }; |
| 255 | |
| 256 | public: |
| 257 | // TLI - This is information that describes the available target features we |
| 258 | // need for lowering. This indicates when operations are unavailable, |
| 259 | // implemented with a libcall, etc. |
| 260 | TargetLowering &TLI; |
| 261 | SelectionDAG &DAG; |
| 262 | const TargetData *TD; |
| 263 | AliasAnalysis *AA; |
| 264 | |
| 265 | /// SwitchCases - Vector of CaseBlock structures used to communicate |
| 266 | /// SwitchInst code generation information. |
| 267 | std::vector<CaseBlock> SwitchCases; |
| 268 | /// JTCases - Vector of JumpTable structures used to communicate |
| 269 | /// SwitchInst code generation information. |
| 270 | std::vector<JumpTableBlock> JTCases; |
| 271 | /// BitTestCases - Vector of BitTestBlock structures used to communicate |
| 272 | /// SwitchInst code generation information. |
| 273 | std::vector<BitTestBlock> BitTestCases; |
Evan Cheng | fb2e752 | 2009-09-18 21:02:19 +0000 | [diff] [blame] | 274 | |
| 275 | /// PHINodesToUpdate - A list of phi instructions whose operand list will |
| 276 | /// be updated after processing the current basic block. |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 277 | std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate; |
| 278 | |
Evan Cheng | fb2e752 | 2009-09-18 21:02:19 +0000 | [diff] [blame] | 279 | /// EdgeMapping - If an edge from CurMBB to any MBB is changed (e.g. due to |
| 280 | /// scheduler custom lowering), track the change here. |
| 281 | DenseMap<MachineBasicBlock*, MachineBasicBlock*> EdgeMapping; |
| 282 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 283 | // Emit PHI-node-operand constants only once even if used by multiple |
| 284 | // PHI nodes. |
| 285 | DenseMap<Constant*, unsigned> ConstantsOut; |
| 286 | |
| 287 | /// FuncInfo - Information about the function as a whole. |
| 288 | /// |
| 289 | FunctionLoweringInfo &FuncInfo; |
Bill Wendling | dfdacee | 2009-02-19 21:12:54 +0000 | [diff] [blame] | 290 | |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 291 | /// OptLevel - What optimization level we're generating code for. |
Bill Wendling | dfdacee | 2009-02-19 21:12:54 +0000 | [diff] [blame] | 292 | /// |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 293 | CodeGenOpt::Level OptLevel; |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 294 | |
| 295 | /// GFI - Garbage collection metadata for the function. |
| 296 | GCFunctionInfo *GFI; |
| 297 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 298 | /// HasTailCall - This is set to true if a call in the current |
| 299 | /// block has been translated as a tail call. In this case, |
| 300 | /// no subsequent DAG nodes should be created. |
| 301 | /// |
| 302 | bool HasTailCall; |
| 303 | |
Owen Anderson | 0a5372e | 2009-07-13 04:09:18 +0000 | [diff] [blame] | 304 | LLVMContext *Context; |
| 305 | |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 306 | SelectionDAGBuilder(SelectionDAG &dag, TargetLowering &tli, |
| 307 | FunctionLoweringInfo &funcinfo, |
| 308 | CodeGenOpt::Level ol) |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 309 | : CurDebugLoc(DebugLoc::getUnknownLoc()), SDNodeOrder(0), |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 310 | TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol), |
| 311 | HasTailCall(false), |
Owen Anderson | 0a5372e | 2009-07-13 04:09:18 +0000 | [diff] [blame] | 312 | Context(dag.getContext()) { |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void init(GCFunctionInfo *gfi, AliasAnalysis &aa); |
| 316 | |
| 317 | /// clear - Clear out the curret SelectionDAG and the associated |
Dan Gohman | 2048b85 | 2009-11-23 18:04:58 +0000 | [diff] [blame] | 318 | /// state and prepare this SelectionDAGBuilder object to be used |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 319 | /// for a new block. This doesn't clear out information about |
| 320 | /// additional blocks that are needed to complete switch lowering |
| 321 | /// or PHI node updating; that information is cleared out as it is |
| 322 | /// consumed. |
| 323 | void clear(); |
| 324 | |
| 325 | /// getRoot - Return the current virtual root of the Selection DAG, |
| 326 | /// flushing any PendingLoad items. This must be done before emitting |
| 327 | /// a store or any other node that may need to be ordered after any |
| 328 | /// prior load instructions. |
| 329 | /// |
| 330 | SDValue getRoot(); |
| 331 | |
| 332 | /// getControlRoot - Similar to getRoot, but instead of flushing all the |
| 333 | /// PendingLoad items, flush all the PendingExports items. It is necessary |
| 334 | /// to do this before emitting a terminator instruction. |
| 335 | /// |
| 336 | SDValue getControlRoot(); |
| 337 | |
Dale Johannesen | 66978ee | 2009-01-31 02:22:37 +0000 | [diff] [blame] | 338 | DebugLoc getCurDebugLoc() const { return CurDebugLoc; } |
Devang Patel | 390f3ac | 2009-04-16 01:33:10 +0000 | [diff] [blame] | 339 | void setCurDebugLoc(DebugLoc dl) { CurDebugLoc = dl; } |
Dale Johannesen | 66978ee | 2009-01-31 02:22:37 +0000 | [diff] [blame] | 340 | |
Bill Wendling | 3ea3c24 | 2009-12-22 02:10:19 +0000 | [diff] [blame] | 341 | unsigned getSDNodeOrder() const { return SDNodeOrder; } |
| 342 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 343 | void CopyValueToVirtualRegister(Value *V, unsigned Reg); |
| 344 | |
Bill Wendling | 4533cac | 2010-01-28 21:51:40 +0000 | [diff] [blame] | 345 | /// AssignOrderingToNode - Assign an ordering to the node. The order is gotten |
| 346 | /// from how the code appeared in the source. The ordering is used by the |
| 347 | /// scheduler to effectively turn off scheduling. |
| 348 | void AssignOrderingToNode(const SDNode *Node); |
| 349 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 350 | void visit(Instruction &I); |
| 351 | |
| 352 | void visit(unsigned Opcode, User &I); |
| 353 | |
| 354 | void setCurrentBasicBlock(MachineBasicBlock *MBB) { CurMBB = MBB; } |
| 355 | |
| 356 | SDValue getValue(const Value *V); |
| 357 | |
| 358 | void setValue(const Value *V, SDValue NewN) { |
| 359 | SDValue &N = NodeMap[V]; |
| 360 | assert(N.getNode() == 0 && "Already set a value for this node!"); |
| 361 | N = NewN; |
| 362 | } |
| 363 | |
Dale Johannesen | 8e3455b | 2008-09-24 23:13:09 +0000 | [diff] [blame] | 364 | void GetRegistersForValue(SDISelAsmOperandInfo &OpInfo, |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 365 | std::set<unsigned> &OutputRegs, |
| 366 | std::set<unsigned> &InputRegs); |
| 367 | |
| 368 | void FindMergedConditions(Value *Cond, MachineBasicBlock *TBB, |
| 369 | MachineBasicBlock *FBB, MachineBasicBlock *CurBB, |
| 370 | unsigned Opc); |
Dan Gohman | c227734 | 2008-10-17 21:16:08 +0000 | [diff] [blame] | 371 | void EmitBranchForMergedCondition(Value *Cond, MachineBasicBlock *TBB, |
| 372 | MachineBasicBlock *FBB, |
| 373 | MachineBasicBlock *CurBB); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 374 | bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases); |
| 375 | bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB); |
Dan Gohman | ad62f53 | 2009-04-23 23:13:24 +0000 | [diff] [blame] | 376 | void CopyToExportRegsIfNeeded(Value *V); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 377 | void ExportFromCurrentBlock(Value *V); |
| 378 | void LowerCallTo(CallSite CS, SDValue Callee, bool IsTailCall, |
| 379 | MachineBasicBlock *LandingPad = NULL); |
| 380 | |
| 381 | private: |
| 382 | // Terminator instructions. |
| 383 | void visitRet(ReturnInst &I); |
| 384 | void visitBr(BranchInst &I); |
| 385 | void visitSwitch(SwitchInst &I); |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 386 | void visitIndirectBr(IndirectBrInst &I); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 387 | void visitUnreachable(UnreachableInst &I) { /* noop */ } |
| 388 | |
| 389 | // Helpers for visitSwitch |
| 390 | bool handleSmallSwitchRange(CaseRec& CR, |
| 391 | CaseRecVector& WorkList, |
| 392 | Value* SV, |
| 393 | MachineBasicBlock* Default); |
| 394 | bool handleJTSwitchCase(CaseRec& CR, |
| 395 | CaseRecVector& WorkList, |
| 396 | Value* SV, |
| 397 | MachineBasicBlock* Default); |
| 398 | bool handleBTSplitSwitchCase(CaseRec& CR, |
| 399 | CaseRecVector& WorkList, |
| 400 | Value* SV, |
| 401 | MachineBasicBlock* Default); |
| 402 | bool handleBitTestsSwitchCase(CaseRec& CR, |
| 403 | CaseRecVector& WorkList, |
| 404 | Value* SV, |
| 405 | MachineBasicBlock* Default); |
| 406 | public: |
| 407 | void visitSwitchCase(CaseBlock &CB); |
| 408 | void visitBitTestHeader(BitTestBlock &B); |
| 409 | void visitBitTestCase(MachineBasicBlock* NextMBB, |
| 410 | unsigned Reg, |
| 411 | BitTestCase &B); |
| 412 | void visitJumpTable(JumpTable &JT); |
| 413 | void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH); |
| 414 | |
| 415 | private: |
| 416 | // These all get lowered before this pass. |
| 417 | void visitInvoke(InvokeInst &I); |
| 418 | void visitUnwind(UnwindInst &I); |
| 419 | |
| 420 | void visitBinary(User &I, unsigned OpCode); |
| 421 | void visitShift(User &I, unsigned Opcode); |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 422 | void visitAdd(User &I) { visitBinary(I, ISD::ADD); } |
| 423 | void visitFAdd(User &I) { visitBinary(I, ISD::FADD); } |
| 424 | void visitSub(User &I) { visitBinary(I, ISD::SUB); } |
| 425 | void visitFSub(User &I); |
| 426 | void visitMul(User &I) { visitBinary(I, ISD::MUL); } |
| 427 | void visitFMul(User &I) { visitBinary(I, ISD::FMUL); } |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 428 | void visitURem(User &I) { visitBinary(I, ISD::UREM); } |
| 429 | void visitSRem(User &I) { visitBinary(I, ISD::SREM); } |
| 430 | void visitFRem(User &I) { visitBinary(I, ISD::FREM); } |
| 431 | void visitUDiv(User &I) { visitBinary(I, ISD::UDIV); } |
| 432 | void visitSDiv(User &I) { visitBinary(I, ISD::SDIV); } |
| 433 | void visitFDiv(User &I) { visitBinary(I, ISD::FDIV); } |
| 434 | void visitAnd (User &I) { visitBinary(I, ISD::AND); } |
| 435 | void visitOr (User &I) { visitBinary(I, ISD::OR); } |
| 436 | void visitXor (User &I) { visitBinary(I, ISD::XOR); } |
| 437 | void visitShl (User &I) { visitShift(I, ISD::SHL); } |
| 438 | void visitLShr(User &I) { visitShift(I, ISD::SRL); } |
| 439 | void visitAShr(User &I) { visitShift(I, ISD::SRA); } |
| 440 | void visitICmp(User &I); |
| 441 | void visitFCmp(User &I); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 442 | // Visit the conversion instructions |
| 443 | void visitTrunc(User &I); |
| 444 | void visitZExt(User &I); |
| 445 | void visitSExt(User &I); |
| 446 | void visitFPTrunc(User &I); |
| 447 | void visitFPExt(User &I); |
| 448 | void visitFPToUI(User &I); |
| 449 | void visitFPToSI(User &I); |
| 450 | void visitUIToFP(User &I); |
| 451 | void visitSIToFP(User &I); |
| 452 | void visitPtrToInt(User &I); |
| 453 | void visitIntToPtr(User &I); |
| 454 | void visitBitCast(User &I); |
| 455 | |
| 456 | void visitExtractElement(User &I); |
| 457 | void visitInsertElement(User &I); |
| 458 | void visitShuffleVector(User &I); |
| 459 | |
| 460 | void visitExtractValue(ExtractValueInst &I); |
| 461 | void visitInsertValue(InsertValueInst &I); |
| 462 | |
| 463 | void visitGetElementPtr(User &I); |
| 464 | void visitSelect(User &I); |
| 465 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 466 | void visitAlloca(AllocaInst &I); |
| 467 | void visitLoad(LoadInst &I); |
| 468 | void visitStore(StoreInst &I); |
| 469 | void visitPHI(PHINode &I) { } // PHI nodes are handled specially. |
| 470 | void visitCall(CallInst &I); |
Chris Lattner | 8047d9a | 2009-12-24 00:37:38 +0000 | [diff] [blame] | 471 | bool visitMemCmpCall(CallInst &I); |
| 472 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 473 | void visitInlineAsm(CallSite CS); |
| 474 | const char *visitIntrinsicCall(CallInst &I, unsigned Intrinsic); |
| 475 | void visitTargetIntrinsic(CallInst &I, unsigned Intrinsic); |
| 476 | |
Bill Wendling | aeb5c7b | 2008-09-10 00:20:20 +0000 | [diff] [blame] | 477 | void visitPow(CallInst &I); |
Dale Johannesen | 601d3c0 | 2008-09-05 01:48:15 +0000 | [diff] [blame] | 478 | void visitExp2(CallInst &I); |
Dale Johannesen | 59e577f | 2008-09-05 18:38:42 +0000 | [diff] [blame] | 479 | void visitExp(CallInst &I); |
| 480 | void visitLog(CallInst &I); |
| 481 | void visitLog2(CallInst &I); |
| 482 | void visitLog10(CallInst &I); |
Dale Johannesen | 601d3c0 | 2008-09-05 01:48:15 +0000 | [diff] [blame] | 483 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 484 | void visitVAStart(CallInst &I); |
| 485 | void visitVAArg(VAArgInst &I); |
| 486 | void visitVAEnd(CallInst &I); |
| 487 | void visitVACopy(CallInst &I); |
| 488 | |
| 489 | void visitUserOp1(Instruction &I) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 490 | llvm_unreachable("UserOp1 should not exist at instruction selection time!"); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 491 | } |
| 492 | void visitUserOp2(Instruction &I) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 493 | llvm_unreachable("UserOp2 should not exist at instruction selection time!"); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | const char *implVisitBinaryAtomic(CallInst& I, ISD::NodeType Op); |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 497 | const char *implVisitAluOverflow(CallInst &I, ISD::NodeType Op); |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 498 | }; |
| 499 | |
Dan Gohman | f0cbcd4 | 2008-09-03 16:12:24 +0000 | [diff] [blame] | 500 | } // end namespace llvm |
| 501 | |
| 502 | #endif |