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