LLVM API Documentation

SparcGenDAGISel.inc

Go to the documentation of this file.
00001 //===- TableGen'erated file -------------------------------------*- C++ -*-===//
00002 //
00003 // DAG Instruction Selector for the Sparc target
00004 //
00005 // Automatically generated file, do not edit!
00006 //
00007 //===----------------------------------------------------------------------===//
00008 
00009 // *** NOTE: This file is #included into the middle of the target
00010 // *** instruction selector class.  These functions are really methods.
00011 
00012 #if defined(__GNUC__) && \
00013     ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)))
00014 #define NOINLINE __attribute__((noinline))
00015 #else
00016 
00017 #define NOINLINE
00018 
00019 #endif
00020 
00021 // Instance var to keep track of multiply used nodes that have 
00022 // already been selected.
00023 std::map<SDOperand, SDOperand> CodeGenMap;
00024 // Instance var to keep track of mapping of chain generating nodes
00025 // and their place handle nodes.
00026 std::map<SDOperand, SDOperand> HandleMap;
00027 // Instance var to keep track of mapping of place handle nodes
00028 // and their replacement nodes.
00029 std::map<SDOperand, SDOperand> ReplaceMap;
00030 // Keep track of nodes that are currently being selecte and therefore
00031 // should not be folded.
00032 std::set<SDNode*> InFlightSet;
00033 
00034 static void findNonImmUse(SDNode* Use, SDNode* Def, bool &found, std::set<SDNode *> &Visited) {
00035   if (found || !Visited.insert(Use).second) return;
00036   for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
00037     SDNode *N = Use->getOperand(i).Val;
00038     if (N != Def) {
00039       findNonImmUse(N, Def, found, Visited);
00040     } else {
00041       found = true;
00042       break;
00043     }
00044   }
00045 }
00046 
00047 static bool isNonImmUse(SDNode* Use, SDNode* Def) {
00048   std::set<SDNode *> Visited;
00049   bool found = false;
00050   for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
00051     SDNode *N = Use->getOperand(i).Val;
00052     if (N != Def) {
00053       findNonImmUse(N, Def, found, Visited);
00054       if (found) break;
00055     }
00056   }
00057   return found;
00058 }
00059 
00060 // AddHandleReplacement - Note the pending replacement node for a
00061 // handle node in ReplaceMap.
00062 void AddHandleReplacement(SDNode *H, unsigned HNum, SDNode *R, unsigned RNum) {
00063   SDOperand N(H, HNum);
00064   std::map<SDOperand, SDOperand>::iterator HMI = HandleMap.find(N);
00065   if (HMI != HandleMap.end()) {
00066     ReplaceMap[HMI->second] = SDOperand(R, RNum);
00067     HandleMap.erase(N);
00068   }
00069 }
00070 
00071 // SelectDanglingHandles - Select replacements for all `dangling`
00072 // handles.Some handles do not yet have replacements because the
00073 // nodes they replacements have only dead readers.
00074 void SelectDanglingHandles() {
00075   for (std::map<SDOperand, SDOperand>::iterator I = HandleMap.begin(),
00076          E = HandleMap.end(); I != E; ++I) {
00077     SDOperand N = I->first;
00078     SDOperand R;
00079     Select(R, N.getValue(0));
00080     AddHandleReplacement(N.Val, N.ResNo, R.Val, R.ResNo);
00081   }
00082 }
00083 
00084 // ReplaceHandles - Replace all the handles with the real target
00085 // specific nodes.
00086 void ReplaceHandles() {
00087   for (std::map<SDOperand, SDOperand>::iterator I = ReplaceMap.begin(),
00088         E = ReplaceMap.end(); I != E; ++I) {
00089     SDOperand From = I->first;
00090     SDOperand To   = I->second;
00091     for (SDNode::use_iterator UI = From.Val->use_begin(), E = From.Val->use_end(); UI != E; ++UI) {
00092       SDNode *Use = *UI;
00093       std::vector<SDOperand> Ops;
00094       for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i){
00095         SDOperand O = Use->getOperand(i);
00096         if (O.Val == From.Val)
00097           Ops.push_back(To);
00098         else
00099           Ops.push_back(O);
00100       }
00101       SDOperand U = SDOperand(Use, 0);
00102       CurDAG->UpdateNodeOperands(U, Ops);
00103     }
00104   }
00105 }
00106 
00107 // SelectRoot - Top level entry to DAG isel.
00108 SDOperand SelectRoot(SDOperand N) {
00109   SDOperand ResNode;
00110   Select(ResNode, N);
00111   SelectDanglingHandles();
00112   ReplaceHandles();
00113   ReplaceMap.clear();
00114   return ResNode;
00115 }
00116 
00117 // Node transformations.
00118 inline SDOperand Transform_LO10(SDNode *inN) {
00119   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00120 
00121   return CurDAG->getTargetConstant((unsigned)N->getValue() & 1023, MVT::i32);
00122 
00123 }
00124 inline SDOperand Transform_HI22(SDNode *inN) {
00125   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00126 
00127   // Transformation function: shift the immediate value down into the low bits.
00128   return CurDAG->getTargetConstant((unsigned)N->getValue() >> 10, MVT::i32);
00129 
00130 }
00131 
00132 // Predicate functions.
00133 inline bool Predicate_SETHIimm(SDNode *inN) {
00134   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00135 
00136   return (((unsigned)N->getValue() >> 10) << 10) == (unsigned)N->getValue();
00137 
00138 }
00139 inline bool Predicate_immAllOnes(SDNode *inN) {
00140   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00141  return N->isAllOnesValue(); 
00142 }
00143 inline bool Predicate_immAllOnesV(SDNode *N) {
00144 
00145   return ISD::isBuildVectorAllOnes(N);
00146 
00147 }
00148 inline bool Predicate_immAllOnesV_bc(SDNode *N) {
00149 
00150   return ISD::isBuildVectorAllOnes(N);
00151 
00152 }
00153 inline bool Predicate_immAllZerosV(SDNode *N) {
00154 
00155   return ISD::isBuildVectorAllZeros(N);
00156 
00157 }
00158 inline bool Predicate_simm11(SDNode *inN) {
00159   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00160 
00161   // simm11 predicate - True if the imm fits in a 11-bit sign extended field.
00162   return (((int)N->getValue() << (32-11)) >> (32-11)) == (int)N->getValue();
00163 
00164 }
00165 inline bool Predicate_simm13(SDNode *inN) {
00166   ConstantSDNode *N = cast<ConstantSDNode>(inN);
00167 
00168   // simm13 predicate - True if the imm fits in a 13-bit sign extended field.
00169   return (((int)N->getValue() << (32-13)) >> (32-13)) == (int)N->getValue();
00170 
00171 }
00172 inline bool Predicate_vtFP(SDNode *inN) {
00173   VTSDNode *N = cast<VTSDNode>(inN);
00174  return MVT::isFloatingPoint(N->getVT()); 
00175 }
00176 inline bool Predicate_vtInt(SDNode *inN) {
00177   VTSDNode *N = cast<VTSDNode>(inN);
00178  return MVT::isInteger(N->getVT()); 
00179 }
00180 
00181 
00182 void Emit_0(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain, SDOperand &N1, SDOperand &N2) NOINLINE {
00183   SDOperand InFlag(0, 0);
00184   SDOperand Tmp0(0, 0);
00185   SDOperand Tmp1(0, 0);
00186   SDNode *ResNode = NULL;
00187   Select(Tmp0, N1);
00188   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N2)->getValue()), MVT::i32);
00189   Select(Chain, Chain);
00190   Select(InFlag, N.getOperand(3));
00191   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Tmp0, Tmp1, Chain, InFlag);
00192   Chain = SDOperand(ResNode, 0);
00193   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
00194   Result = SDOperand(ResNode, N.ResNo);
00195   return;
00196 }
00197 void Select_SPbrfcc(SDOperand &Result, SDOperand N) {
00198   SDOperand Chain(0, 0);
00199   SDOperand InFlag(0, 0);
00200   SDOperand N1(0, 0);
00201   SDOperand N2(0, 0);
00202   SDOperand Tmp0(0, 0);
00203   SDOperand Tmp1(0, 0);
00204   SDNode *ResNode = NULL;
00205   Chain = N.getOperand(0);
00206   N1 = N.getOperand(1);
00207   if (N1.getOpcode() == ISD::BasicBlock) {
00208     N2 = N.getOperand(2);
00209     if (N2.getOpcode() == ISD::Constant) {
00210       Emit_0(Result, N, SP::FBCOND, Chain, N1, N2);
00211       return;
00212     }
00213   }
00214   std::cerr << "Cannot yet select: ";
00215   N.Val->dump(CurDAG);
00216   std::cerr << '\n';
00217   abort();
00218 }
00219 
00220 void Select_SPbricc(SDOperand &Result, SDOperand N) {
00221   SDOperand Chain(0, 0);
00222   SDOperand InFlag(0, 0);
00223   SDOperand N1(0, 0);
00224   SDOperand N2(0, 0);
00225   SDOperand Tmp0(0, 0);
00226   SDOperand Tmp1(0, 0);
00227   SDNode *ResNode = NULL;
00228   Chain = N.getOperand(0);
00229   N1 = N.getOperand(1);
00230   if (N1.getOpcode() == ISD::BasicBlock) {
00231     N2 = N.getOperand(2);
00232     if (N2.getOpcode() == ISD::Constant) {
00233       Emit_0(Result, N, SP::BCOND, Chain, N1, N2);
00234       return;
00235     }
00236   }
00237   std::cerr << "Cannot yet select: ";
00238   N.Val->dump(CurDAG);
00239   std::cerr << '\n';
00240   abort();
00241 }
00242 
00243 void Emit_1(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &N0, SDOperand &N1) NOINLINE {
00244   SDOperand InFlag(0, 0);
00245   SDOperand Tmp0(0, 0);
00246   SDOperand Tmp1(0, 0);
00247   SDNode *ResNode = NULL;
00248   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00249   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00250   Select(Tmp0, N0);
00251   Select(Tmp1, N1);
00252   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00253   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00254   ResNode = CurDAG->getTargetNode(Opc0, MVT::Flag, Tmp0, Tmp1);
00255   InFlag = SDOperand(ResNode, 0);
00256   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, InFlag.Val, InFlag.ResNo);
00257   Result = SDOperand(ResNode, N.ResNo);
00258   return;
00259 }
00260 void Select_SPcmpfcc(SDOperand &Result, SDOperand N) {
00261   SDOperand InFlag(0, 0);
00262   SDOperand N0(0, 0);
00263   SDOperand N1(0, 0);
00264   SDOperand Tmp0(0, 0);
00265   SDOperand Tmp1(0, 0);
00266   SDNode *ResNode = NULL;
00267   N0 = N.getOperand(0);
00268   N1 = N.getOperand(1);
00269 
00270   // Pattern: (SPcmpfcc:void FPRegs:f32:$src1, FPRegs:f32:$src2)
00271   // Emits: (FCMPS:void FPRegs:f32:$src1, FPRegs:f32:$src2)
00272   // Pattern complexity = 2  cost = 1  size = 0
00273   if (N0.Val->getValueType(0) == MVT::f32) {
00274     Emit_1(Result, N, SP::FCMPS, N0, N1);
00275     return;
00276   }
00277 
00278   // Pattern: (SPcmpfcc:void DFPRegs:f64:$src1, DFPRegs:f64:$src2)
00279   // Emits: (FCMPD:void DFPRegs:f64:$src1, DFPRegs:f64:$src2)
00280   // Pattern complexity = 2  cost = 1
00281   if (N0.Val->getValueType(0) == MVT::f64) {
00282     Emit_1(Result, N, SP::FCMPD, N0, N1);
00283     return;
00284   }
00285   std::cerr << "Cannot yet select: ";
00286   N.Val->dump(CurDAG);
00287   std::cerr << '\n';
00288   abort();
00289 }
00290 
00291 void Emit_2(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00292   SDOperand InFlag(0, 0);
00293   SDOperand Tmp0(0, 0);
00294   SDOperand Tmp1(0, 0);
00295   SDNode *ResNode = NULL;
00296   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00297   Select(Tmp0, N0);
00298   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N1)->getValue()), MVT::i32);
00299   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00300   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Flag, Tmp0, Tmp1);
00301   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
00302   InFlag = SDOperand(ResNode, 1);
00303   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
00304   Result = SDOperand(ResNode, N.ResNo);
00305   return;
00306 }
00307 void Emit_3(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00308   SDOperand InFlag(0, 0);
00309   SDOperand Tmp0(0, 0);
00310   SDOperand Tmp1(0, 0);
00311   SDNode *ResNode = NULL;
00312   N0 = N.getOperand(0);
00313   N1 = N.getOperand(1);
00314   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00315   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00316   Select(Tmp0, N0);
00317   Select(Tmp1, N1);
00318   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00319   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00320   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Flag, Tmp0, Tmp1);
00321   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
00322   InFlag = SDOperand(ResNode, 1);
00323   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
00324   Result = SDOperand(ResNode, N.ResNo);
00325   return;
00326 }
00327 void Select_SPcmpicc(SDOperand &Result, SDOperand N) {
00328   SDOperand InFlag(0, 0);
00329   SDOperand N0(0, 0);
00330   SDOperand N1(0, 0);
00331   SDOperand Tmp0(0, 0);
00332   SDOperand Tmp1(0, 0);
00333   SDNode *ResNode = NULL;
00334 
00335   // Pattern: (SPcmpicc:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
00336   // Emits: (SUBCCri:i32 IntRegs:i32:$b, (imm:i32):$c)
00337   // Pattern complexity = 5  cost = 1  size = 0
00338   {
00339     N0 = N.getOperand(0);
00340     N1 = N.getOperand(1);
00341     if (N1.getOpcode() == ISD::Constant &&
00342         Predicate_simm13(N1.Val)) {
00343       Emit_2(Result, N, SP::SUBCCri, MVT::i32, N0, N1);
00344       return;
00345     }
00346   }
00347 
00348   // Pattern: (SPcmpicc:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00349   // Emits: (SUBCCrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00350   // Pattern complexity = 2  cost = 1
00351   Emit_3(Result, N, SP::SUBCCrr, MVT::i32, N0, N1);
00352   return;
00353 }
00354 
00355 void Emit_4(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0) NOINLINE {
00356   SDOperand Tmp0(0, 0);
00357   SDNode *ResNode = NULL;
00358   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00359   Select(Tmp0, N0);
00360   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00361   if (N.Val->hasOneUse()) {
00362     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0);
00363   } else {
00364     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0);
00365     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00366     Result = SDOperand(ResNode, 0);
00367   }
00368   return;
00369 }
00370 void Select_SPftoi(SDOperand &Result, SDOperand N) {
00371   SDOperand N0(0, 0);
00372   SDOperand Tmp0(0, 0);
00373   SDNode *ResNode = NULL;
00374   N0 = N.getOperand(0);
00375 
00376   // Pattern: (SPftoi:f32 FPRegs:f32:$src)
00377   // Emits: (FSTOI:f32 FPRegs:f32:$src)
00378   // Pattern complexity = 2  cost = 1  size = 0
00379   if (N0.Val->getValueType(0) == MVT::f32) {
00380     Emit_4(Result, N, SP::FSTOI, MVT::f32, N0);
00381     return;
00382   }
00383 
00384   // Pattern: (SPftoi:f32 DFPRegs:f64:$src)
00385   // Emits: (FDTOI:f32 DFPRegs:f64:$src)
00386   // Pattern complexity = 2  cost = 1
00387   if (N0.Val->getValueType(0) == MVT::f64) {
00388     Emit_4(Result, N, SP::FDTOI, MVT::f32, N0);
00389     return;
00390   }
00391   std::cerr << "Cannot yet select: ";
00392   N.Val->dump(CurDAG);
00393   std::cerr << '\n';
00394   abort();
00395 }
00396 
00397 void Emit_5(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0) NOINLINE {
00398   SDOperand Tmp0(0, 0);
00399   SDNode *ResNode = NULL;
00400   Tmp0 = N0;
00401   if (N.Val->hasOneUse()) {
00402     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0);
00403   } else {
00404     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0);
00405     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00406     Result = SDOperand(ResNode, 0);
00407   }
00408   return;
00409 }
00410 void Select_SPhi(SDOperand &Result, SDOperand N) {
00411   SDOperand N0(0, 0);
00412   SDOperand Tmp0(0, 0);
00413   SDNode *ResNode = NULL;
00414   N0 = N.getOperand(0);
00415 
00416   // Pattern: (SPhi:i32 (tglobaladdr:i32):$in)
00417   // Emits: (SETHIi:i32 (tglobaladdr:i32):$in)
00418   // Pattern complexity = 4  cost = 1  size = 0
00419   if (N0.getOpcode() == ISD::TargetGlobalAddress) {
00420     Emit_5(Result, N, SP::SETHIi, MVT::i32, N0);
00421     return;
00422   }
00423 
00424   // Pattern: (SPhi:i32 (tconstpool:i32):$in)
00425   // Emits: (SETHIi:i32 (tconstpool:i32):$in)
00426   // Pattern complexity = 4  cost = 1
00427   if (N0.getOpcode() == ISD::TargetConstantPool) {
00428     Emit_5(Result, N, SP::SETHIi, MVT::i32, N0);
00429     return;
00430   }
00431   std::cerr << "Cannot yet select: ";
00432   N.Val->dump(CurDAG);
00433   std::cerr << '\n';
00434   abort();
00435 }
00436 
00437 void Select_SPitof(SDOperand &Result, SDOperand N) {
00438   SDOperand N0(0, 0);
00439   SDOperand Tmp0(0, 0);
00440   SDNode *ResNode = NULL;
00441   N0 = N.getOperand(0);
00442 
00443   // Pattern: (SPitof:f32 FPRegs:f32:$src)
00444   // Emits: (FITOS:f32 FPRegs:f32:$src)
00445   // Pattern complexity = 2  cost = 1  size = 0
00446   if (N.Val->getValueType(0) == MVT::f32) {
00447     Emit_4(Result, N, SP::FITOS, MVT::f32, N0);
00448     return;
00449   }
00450 
00451   // Pattern: (SPitof:f64 FPRegs:f32:$src)
00452   // Emits: (FITOD:f64 FPRegs:f32:$src)
00453   // Pattern complexity = 2  cost = 1
00454   if (N.Val->getValueType(0) == MVT::f64) {
00455     Emit_4(Result, N, SP::FITOD, MVT::f64, N0);
00456     return;
00457   }
00458   std::cerr << "Cannot yet select: ";
00459   N.Val->dump(CurDAG);
00460   std::cerr << '\n';
00461   abort();
00462 }
00463 
00464 void Emit_6(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0) NOINLINE {
00465   SDOperand Tmp0(0, 0);
00466   SDOperand Tmp1(0, 0);
00467   SDNode *ResNode = NULL;
00468   Tmp0 = CurDAG->getRegister(SP::G0, MVT::i32);
00469   Tmp1 = N0;
00470   if (N.Val->hasOneUse()) {
00471     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00472   } else {
00473     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
00474     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00475     Result = SDOperand(ResNode, 0);
00476   }
00477   return;
00478 }
00479 void Select_SPlo(SDOperand &Result, SDOperand N) {
00480   SDOperand N0(0, 0);
00481   SDOperand Tmp0(0, 0);
00482   SDOperand Tmp1(0, 0);
00483   SDNode *ResNode = NULL;
00484   N0 = N.getOperand(0);
00485 
00486   // Pattern: (SPlo:i32 (tglobaladdr:i32):$in)
00487   // Emits: (ORri:i32 G0:i32, (tglobaladdr:i32):$in)
00488   // Pattern complexity = 4  cost = 1  size = 0
00489   if (N0.getOpcode() == ISD::TargetGlobalAddress) {
00490     Emit_6(Result, N, SP::ORri, MVT::i32, N0);
00491     return;
00492   }
00493 
00494   // Pattern: (SPlo:i32 (tconstpool:i32):$in)
00495   // Emits: (ORri:i32 G0:i32, (tconstpool:i32):$in)
00496   // Pattern complexity = 4  cost = 1
00497   if (N0.getOpcode() == ISD::TargetConstantPool) {
00498     Emit_6(Result, N, SP::ORri, MVT::i32, N0);
00499     return;
00500   }
00501   std::cerr << "Cannot yet select: ";
00502   N.Val->dump(CurDAG);
00503   std::cerr << '\n';
00504   abort();
00505 }
00506 
00507 void Emit_7(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N2) NOINLINE {
00508   SDOperand InFlag(0, 0);
00509   SDOperand Tmp0(0, 0);
00510   SDOperand Tmp1(0, 0);
00511   SDOperand Tmp2(0, 0);
00512   SDNode *ResNode = NULL;
00513   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00514   Select(Tmp0, N1);
00515   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N0)->getValue()), MVT::i32);
00516   Tmp2 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N2)->getValue()), MVT::i32);
00517   Select(InFlag, N.getOperand(3));
00518   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00519   if (N.Val->hasOneUse()) {
00520     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00521   } else {
00522     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00523     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00524     Result = SDOperand(ResNode, 0);
00525   }
00526   return;
00527 }
00528 void Emit_8(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N2) NOINLINE {
00529   SDOperand InFlag(0, 0);
00530   SDOperand Tmp0(0, 0);
00531   SDOperand Tmp1(0, 0);
00532   SDOperand Tmp2(0, 0);
00533   SDNode *ResNode = NULL;
00534   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00535   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00536   Select(Tmp0, N1);
00537   Select(Tmp1, N0);
00538   Tmp2 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N2)->getValue()), MVT::i32);
00539   Select(InFlag, N.getOperand(3));
00540   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00541   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00542   if (N.Val->hasOneUse()) {
00543     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00544   } else {
00545     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00546     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00547     Result = SDOperand(ResNode, 0);
00548   }
00549   return;
00550 }
00551 void Emit_9(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N2) NOINLINE {
00552   SDOperand InFlag(0, 0);
00553   SDOperand Tmp0(0, 0);
00554   SDOperand Tmp1(0, 0);
00555   SDOperand Tmp2(0, 0);
00556   SDNode *ResNode = NULL;
00557   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00558   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00559   Select(Tmp0, N0);
00560   Select(Tmp1, N1);
00561   Tmp2 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N2)->getValue()), MVT::i32);
00562   Select(InFlag, N.getOperand(3));
00563   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00564   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00565   if (N.Val->hasOneUse()) {
00566     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00567   } else {
00568     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1, Tmp2, InFlag);
00569     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00570     Result = SDOperand(ResNode, 0);
00571   }
00572   return;
00573 }
00574 void Select_SPselectfcc(SDOperand &Result, SDOperand N) {
00575   SDOperand InFlag(0, 0);
00576   SDOperand N0(0, 0);
00577   SDOperand N1(0, 0);
00578   SDOperand N2(0, 0);
00579   SDOperand Tmp0(0, 0);
00580   SDOperand Tmp1(0, 0);
00581   SDOperand Tmp2(0, 0);
00582   SDNode *ResNode = NULL;
00583   if ((Subtarget.isV9())) {
00584     N0 = N.getOperand(0);
00585 
00586     // Pattern: (SPselectfcc:i32 (imm:i32)<<P:Predicate_simm11>>:$F, IntRegs:i32:$T, (imm:i32):$cc)
00587     // Emits: (MOVFCCri:i32 IntRegs:i32:$T, (imm:i32):$F, (imm:i32):$cc)
00588     // Pattern complexity = 7  cost = 1  size = 0
00589     if (N0.getOpcode() == ISD::Constant &&
00590         Predicate_simm11(N0.Val)) {
00591       N1 = N.getOperand(1);
00592       N2 = N.getOperand(2);
00593       if (N2.getOpcode() == ISD::Constant) {
00594         Emit_7(Result, N, SP::MOVFCCri, MVT::i32, N0, N1, N2);
00595         return;
00596       }
00597     }
00598     N1 = N.getOperand(1);
00599     N2 = N.getOperand(2);
00600     if (N2.getOpcode() == ISD::Constant) {
00601 
00602       // Pattern: (SPselectfcc:i32 IntRegs:i32:$F, IntRegs:i32:$T, (imm:i32):$cc)
00603       // Emits: (MOVFCCrr:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$cc)
00604       // Pattern complexity = 4  cost = 1  size = 0
00605       if (N.Val->getValueType(0) == MVT::i32) {
00606         Emit_8(Result, N, SP::MOVFCCrr, MVT::i32, N0, N1, N2);
00607         return;
00608       }
00609 
00610       // Pattern: (SPselectfcc:f32 FPRegs:f32:$F, FPRegs:f32:$T, (imm:i32):$cc)
00611       // Emits: (FMOVS_FCC:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$cc)
00612       // Pattern complexity = 4  cost = 1  size = 0
00613       if (N.Val->getValueType(0) == MVT::f32) {
00614         Emit_8(Result, N, SP::FMOVS_FCC, MVT::f32, N0, N1, N2);
00615         return;
00616       }
00617 
00618       // Pattern: (SPselectfcc:f64 DFPRegs:f64:$F, DFPRegs:f64:$T, (imm:i32):$cc)
00619       // Emits: (FMOVD_FCC:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$cc)
00620       // Pattern complexity = 4  cost = 1
00621       if (N.Val->getValueType(0) == MVT::f64) {
00622         Emit_8(Result, N, SP::FMOVD_FCC, MVT::f64, N0, N1, N2);
00623         return;
00624       }
00625     }
00626   }
00627   N0 = N.getOperand(0);
00628   N1 = N.getOperand(1);
00629   N2 = N.getOperand(2);
00630   if (N2.getOpcode() == ISD::Constant) {
00631 
00632     // Pattern: (SPselectfcc:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$Cond)
00633     // Emits: (SELECT_CC_Int_FCC:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$Cond)
00634     // Pattern complexity = 4  cost = 11  size = 0
00635     if (N.Val->getValueType(0) == MVT::i32) {
00636       Emit_9(Result, N, SP::SELECT_CC_Int_FCC, MVT::i32, N0, N1, N2);
00637       return;
00638     }
00639 
00640     // Pattern: (SPselectfcc:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$Cond)
00641     // Emits: (SELECT_CC_FP_FCC:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$Cond)
00642     // Pattern complexity = 4  cost = 11  size = 0
00643     if (N.Val->getValueType(0) == MVT::f32) {
00644       Emit_9(Result, N, SP::SELECT_CC_FP_FCC, MVT::f32, N0, N1, N2);
00645       return;
00646     }
00647 
00648     // Pattern: (SPselectfcc:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$Cond)
00649     // Emits: (SELECT_CC_DFP_FCC:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$Cond)
00650     // Pattern complexity = 4  cost = 11
00651     if (N.Val->getValueType(0) == MVT::f64) {
00652       Emit_9(Result, N, SP::SELECT_CC_DFP_FCC, MVT::f64, N0, N1, N2);
00653       return;
00654     }
00655   }
00656   std::cerr << "Cannot yet select: ";
00657   N.Val->dump(CurDAG);
00658   std::cerr << '\n';
00659   abort();
00660 }
00661 
00662 void Select_SPselecticc(SDOperand &Result, SDOperand N) {
00663   SDOperand InFlag(0, 0);
00664   SDOperand N0(0, 0);
00665   SDOperand N1(0, 0);
00666   SDOperand N2(0, 0);
00667   SDOperand Tmp0(0, 0);
00668   SDOperand Tmp1(0, 0);
00669   SDOperand Tmp2(0, 0);
00670   SDNode *ResNode = NULL;
00671   if ((Subtarget.isV9())) {
00672     N0 = N.getOperand(0);
00673 
00674     // Pattern: (SPselecticc:i32 (imm:i32)<<P:Predicate_simm11>>:$F, IntRegs:i32:$T, (imm:i32):$cc)
00675     // Emits: (MOVICCri:i32 IntRegs:i32:$T, (imm:i32):$F, (imm:i32):$cc)
00676     // Pattern complexity = 7  cost = 1  size = 0
00677     if (N0.getOpcode() == ISD::Constant &&
00678         Predicate_simm11(N0.Val)) {
00679       N1 = N.getOperand(1);
00680       N2 = N.getOperand(2);
00681       if (N2.getOpcode() == ISD::Constant) {
00682         Emit_7(Result, N, SP::MOVICCri, MVT::i32, N0, N1, N2);
00683         return;
00684       }
00685     }
00686     N1 = N.getOperand(1);
00687     N2 = N.getOperand(2);
00688     if (N2.getOpcode() == ISD::Constant) {
00689 
00690       // Pattern: (SPselecticc:i32 IntRegs:i32:$F, IntRegs:i32:$T, (imm:i32):$cc)
00691       // Emits: (MOVICCrr:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$cc)
00692       // Pattern complexity = 4  cost = 1  size = 0
00693       if (N.Val->getValueType(0) == MVT::i32) {
00694         Emit_8(Result, N, SP::MOVICCrr, MVT::i32, N0, N1, N2);
00695         return;
00696       }
00697 
00698       // Pattern: (SPselecticc:f32 FPRegs:f32:$F, FPRegs:f32:$T, (imm:i32):$cc)
00699       // Emits: (FMOVS_ICC:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$cc)
00700       // Pattern complexity = 4  cost = 1  size = 0
00701       if (N.Val->getValueType(0) == MVT::f32) {
00702         Emit_8(Result, N, SP::FMOVS_ICC, MVT::f32, N0, N1, N2);
00703         return;
00704       }
00705 
00706       // Pattern: (SPselecticc:f64 DFPRegs:f64:$F, DFPRegs:f64:$T, (imm:i32):$cc)
00707       // Emits: (FMOVD_ICC:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$cc)
00708       // Pattern complexity = 4  cost = 1
00709       if (N.Val->getValueType(0) == MVT::f64) {
00710         Emit_8(Result, N, SP::FMOVD_ICC, MVT::f64, N0, N1, N2);
00711         return;
00712       }
00713     }
00714   }
00715   N0 = N.getOperand(0);
00716   N1 = N.getOperand(1);
00717   N2 = N.getOperand(2);
00718   if (N2.getOpcode() == ISD::Constant) {
00719 
00720     // Pattern: (SPselecticc:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$Cond)
00721     // Emits: (SELECT_CC_Int_ICC:i32 IntRegs:i32:$T, IntRegs:i32:$F, (imm:i32):$Cond)
00722     // Pattern complexity = 4  cost = 11  size = 0
00723     if (N.Val->getValueType(0) == MVT::i32) {
00724       Emit_9(Result, N, SP::SELECT_CC_Int_ICC, MVT::i32, N0, N1, N2);
00725       return;
00726     }
00727 
00728     // Pattern: (SPselecticc:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$Cond)
00729     // Emits: (SELECT_CC_FP_ICC:f32 FPRegs:f32:$T, FPRegs:f32:$F, (imm:i32):$Cond)
00730     // Pattern complexity = 4  cost = 11  size = 0
00731     if (N.Val->getValueType(0) == MVT::f32) {
00732       Emit_9(Result, N, SP::SELECT_CC_FP_ICC, MVT::f32, N0, N1, N2);
00733       return;
00734     }
00735 
00736     // Pattern: (SPselecticc:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$Cond)
00737     // Emits: (SELECT_CC_DFP_ICC:f64 DFPRegs:f64:$T, DFPRegs:f64:$F, (imm:i32):$Cond)
00738     // Pattern complexity = 4  cost = 11
00739     if (N.Val->getValueType(0) == MVT::f64) {
00740       Emit_9(Result, N, SP::SELECT_CC_DFP_ICC, MVT::f64, N0, N1, N2);
00741       return;
00742     }
00743   }
00744   std::cerr << "Cannot yet select: ";
00745   N.Val->dump(CurDAG);
00746   std::cerr << '\n';
00747   abort();
00748 }
00749 
00750 void Emit_10(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N10) NOINLINE {
00751   SDOperand Tmp0(0, 0);
00752   SDOperand Tmp1(0, 0);
00753   SDNode *ResNode = NULL;
00754   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00755   Select(Tmp0, N0);
00756   Tmp1 = N10;
00757   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00758   if (N.Val->hasOneUse()) {
00759     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00760   } else {
00761     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
00762     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00763     Result = SDOperand(ResNode, 0);
00764   }
00765   return;
00766 }
00767 void Emit_11(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N00, SDOperand &N1) NOINLINE {
00768   SDOperand Tmp0(0, 0);
00769   SDOperand Tmp1(0, 0);
00770   SDNode *ResNode = NULL;
00771   N1 = N.getOperand(1);
00772   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00773   Select(Tmp0, N1);
00774   Tmp1 = N00;
00775   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00776   if (N.Val->hasOneUse()) {
00777     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00778   } else {
00779     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
00780     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00781     Result = SDOperand(ResNode, 0);
00782   }
00783   return;
00784 }
00785 void Emit_12(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00786   SDOperand Tmp0(0, 0);
00787   SDOperand Tmp1(0, 0);
00788   SDNode *ResNode = NULL;
00789   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00790   Select(Tmp0, N0);
00791   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N1)->getValue()), MVT::i32);
00792   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00793   if (N.Val->hasOneUse()) {
00794     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00795   } else {
00796     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
00797     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00798     Result = SDOperand(ResNode, 0);
00799   }
00800   return;
00801 }
00802 void Emit_13(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00803   SDOperand Tmp0(0, 0);
00804   SDOperand Tmp1(0, 0);
00805   SDNode *ResNode = NULL;
00806   N0 = N.getOperand(0);
00807   N1 = N.getOperand(1);
00808   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00809   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00810   Select(Tmp0, N0);
00811   Select(Tmp1, N1);
00812   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00813   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00814   if (N.Val->hasOneUse()) {
00815     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00816   } else {
00817     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
00818     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
00819     Result = SDOperand(ResNode, 0);
00820   }
00821   return;
00822 }
00823 void Select_add(SDOperand &Result, SDOperand N) {
00824   SDOperand N0(0, 0);
00825   SDOperand N00(0, 0);
00826   SDOperand N1(0, 0);
00827   SDOperand N10(0, 0);
00828   SDOperand Tmp0(0, 0);
00829   SDOperand Tmp1(0, 0);
00830   SDNode *ResNode = NULL;
00831   {
00832     N0 = N.getOperand(0);
00833     {
00834       N1 = N.getOperand(1);
00835       if (N1.getOpcode() == SPISD::Lo) {
00836         N10 = N1.getOperand(0);
00837 
00838         // Pattern: (add:i32 IntRegs:i32:$r, (SPlo:i32 (tconstpool:i32):$in))
00839         // Emits: (ADDri:i32 IntRegs:i32:$r, (tconstpool:i32):$in)
00840         // Pattern complexity = 6  cost = 1  size = 0
00841         if (N10.getOpcode() == ISD::TargetConstantPool) {
00842           Emit_10(Result, N, SP::ADDri, MVT::i32, N0, N1, N10);
00843           return;
00844         }
00845 
00846         // Pattern: (add:i32 IntRegs:i32:$r, (SPlo:i32 (tglobaladdr:i32):$in))
00847         // Emits: (ADDri:i32 IntRegs:i32:$r, (tglobaladdr:i32):$in)
00848         // Pattern complexity = 6  cost = 1
00849         if (N10.getOpcode() == ISD::TargetGlobalAddress) {
00850           Emit_10(Result, N, SP::ADDri, MVT::i32, N0, N1, N10);
00851           return;
00852         }
00853       }
00854     }
00855     if (N0.getOpcode() == SPISD::Lo) {
00856       N00 = N0.getOperand(0);
00857 
00858       // Pattern: (add:i32 (SPlo:i32 (tconstpool:i32):$in), IntRegs:i32:$r)
00859       // Emits: (ADDri:i32 IntRegs:i32:$r, (tconstpool:i32):$in)
00860       // Pattern complexity = 6  cost = 1  size = 0
00861       if (N00.getOpcode() == ISD::TargetConstantPool) {
00862         Emit_11(Result, N, SP::ADDri, MVT::i32, N0, N00, N1);
00863         return;
00864       }
00865 
00866       // Pattern: (add:i32 (SPlo:i32 (tglobaladdr:i32):$in), IntRegs:i32:$r)
00867       // Emits: (ADDri:i32 IntRegs:i32:$r, (tglobaladdr:i32):$in)
00868       // Pattern complexity = 6  cost = 1
00869       if (N00.getOpcode() == ISD::TargetGlobalAddress) {
00870         Emit_11(Result, N, SP::ADDri, MVT::i32, N0, N00, N1);
00871         return;
00872       }
00873     }
00874 
00875     // Pattern: (add:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
00876     // Emits: (ADDri:i32 IntRegs:i32:$b, (imm:i32):$c)
00877     // Pattern complexity = 5  cost = 1
00878     N1 = N.getOperand(1);
00879     if (N1.getOpcode() == ISD::Constant &&
00880         Predicate_simm13(N1.Val)) {
00881       Emit_12(Result, N, SP::ADDri, MVT::i32, N0, N1);
00882       return;
00883     }
00884   }
00885 
00886   // Pattern: (add:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00887   // Emits: (ADDrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00888   // Pattern complexity = 2  cost = 1
00889   Emit_13(Result, N, SP::ADDrr, MVT::i32, N0, N1);
00890   return;
00891 }
00892 
00893 void Select_addc(SDOperand &Result, SDOperand N) {
00894   SDOperand InFlag(0, 0);
00895   SDOperand N0(0, 0);
00896   SDOperand N1(0, 0);
00897   SDOperand Tmp0(0, 0);
00898   SDOperand Tmp1(0, 0);
00899   SDNode *ResNode = NULL;
00900 
00901   // Pattern: (addc:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
00902   // Emits: (ADDCCri:i32 IntRegs:i32:$b, (imm:i32):$c)
00903   // Pattern complexity = 5  cost = 1  size = 0
00904   {
00905     N0 = N.getOperand(0);
00906     N1 = N.getOperand(1);
00907     if (N1.getOpcode() == ISD::Constant &&
00908         Predicate_simm13(N1.Val)) {
00909       Emit_2(Result, N, SP::ADDCCri, MVT::i32, N0, N1);
00910       return;
00911     }
00912   }
00913 
00914   // Pattern: (addc:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00915   // Emits: (ADDCCrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00916   // Pattern complexity = 2  cost = 1
00917   Emit_3(Result, N, SP::ADDCCrr, MVT::i32, N0, N1);
00918   return;
00919 }
00920 
00921 void Emit_14(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00922   SDOperand InFlag(0, 0);
00923   SDOperand Tmp0(0, 0);
00924   SDOperand Tmp1(0, 0);
00925   SDNode *ResNode = NULL;
00926   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00927   Select(Tmp0, N0);
00928   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N1)->getValue()), MVT::i32);
00929   Select(InFlag, N.getOperand(2));
00930   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00931   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Flag, Tmp0, Tmp1, InFlag);
00932   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
00933   InFlag = SDOperand(ResNode, 1);
00934   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
00935   Result = SDOperand(ResNode, N.ResNo);
00936   return;
00937 }
00938 void Emit_15(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
00939   SDOperand InFlag(0, 0);
00940   SDOperand Tmp0(0, 0);
00941   SDOperand Tmp1(0, 0);
00942   SDNode *ResNode = NULL;
00943   N0 = N.getOperand(0);
00944   N1 = N.getOperand(1);
00945   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00946   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
00947   Select(Tmp0, N0);
00948   Select(Tmp1, N1);
00949   Select(InFlag, N.getOperand(2));
00950   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00951   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
00952   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Flag, Tmp0, Tmp1, InFlag);
00953   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
00954   InFlag = SDOperand(ResNode, 1);
00955   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
00956   Result = SDOperand(ResNode, N.ResNo);
00957   return;
00958 }
00959 void Select_adde(SDOperand &Result, SDOperand N) {
00960   SDOperand InFlag(0, 0);
00961   SDOperand N0(0, 0);
00962   SDOperand N1(0, 0);
00963   SDOperand Tmp0(0, 0);
00964   SDOperand Tmp1(0, 0);
00965   SDNode *ResNode = NULL;
00966 
00967   // Pattern: (adde:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
00968   // Emits: (ADDXri:i32 IntRegs:i32:$b, (imm:i32):$c)
00969   // Pattern complexity = 5  cost = 1  size = 0
00970   {
00971     N0 = N.getOperand(0);
00972     N1 = N.getOperand(1);
00973     if (N1.getOpcode() == ISD::Constant &&
00974         Predicate_simm13(N1.Val)) {
00975       Emit_14(Result, N, SP::ADDXri, MVT::i32, N0, N1);
00976       return;
00977     }
00978   }
00979 
00980   // Pattern: (adde:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00981   // Emits: (ADDXrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
00982   // Pattern complexity = 2  cost = 1
00983   Emit_15(Result, N, SP::ADDXrr, MVT::i32, N0, N1);
00984   return;
00985 }
00986 
00987 void Emit_16(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N10, SDOperand &N11) NOINLINE {
00988   SDOperand Tmp0(0, 0);
00989   SDOperand Tmp1(0, 0);
00990   SDNode *ResNode = NULL;
00991   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
00992   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N10.Val);
00993   Select(Tmp0, N0);
00994   Select(Tmp1, N10);
00995   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
00996   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N10.Val);
00997   if (N.Val->hasOneUse()) {
00998     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
00999   } else {
01000     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01001     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01002     Result = SDOperand(ResNode, 0);
01003   }
01004   return;
01005 }
01006 void Emit_17(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N00, SDOperand &N01, SDOperand &N1) NOINLINE {
01007   SDOperand Tmp0(0, 0);
01008   SDOperand Tmp1(0, 0);
01009   SDNode *ResNode = NULL;
01010   N1 = N.getOperand(1);
01011   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
01012   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N00.Val);
01013   Select(Tmp0, N1);
01014   Select(Tmp1, N00);
01015   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
01016   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N00.Val);
01017   if (N.Val->hasOneUse()) {
01018     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
01019   } else {
01020     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01021     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01022     Result = SDOperand(ResNode, 0);
01023   }
01024   return;
01025 }
01026 void Select_and(SDOperand &Result, SDOperand N) {
01027   SDOperand N0(0, 0);
01028   SDOperand N00(0, 0);
01029   SDOperand N01(0, 0);
01030   SDOperand N1(0, 0);
01031   SDOperand N10(0, 0);
01032   SDOperand N11(0, 0);
01033   SDOperand Tmp0(0, 0);
01034   SDOperand Tmp1(0, 0);
01035   SDNode *ResNode = NULL;
01036   {
01037     N0 = N.getOperand(0);
01038 
01039     // Pattern: (and:i32 IntRegs:i32:$b, (xor:i32 IntRegs:i32:$c, (imm:i32)<<P:Predicate_immAllOnes>>))
01040     // Emits: (ANDNrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01041     // Pattern complexity = 7  cost = 1  size = 0
01042     {
01043       N1 = N.getOperand(1);
01044       if (N1.getOpcode() == ISD::XOR) {
01045         N10 = N1.getOperand(0);
01046         N11 = N1.getOperand(1);
01047         if (N11.getOpcode() == ISD::Constant &&
01048             Predicate_immAllOnes(N11.Val)) {
01049           Emit_16(Result, N, SP::ANDNrr, MVT::i32, N0, N1, N10, N11);
01050           return;
01051         }
01052       }
01053     }
01054 
01055     // Pattern: (and:i32 (xor:i32 IntRegs:i32:$c, (imm:i32)<<P:Predicate_immAllOnes>>), IntRegs:i32:$b)
01056     // Emits: (ANDNrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01057     // Pattern complexity = 7  cost = 1  size = 0
01058     if (N0.getOpcode() == ISD::XOR) {
01059       N00 = N0.getOperand(0);
01060       N01 = N0.getOperand(1);
01061       if (N01.getOpcode() == ISD::Constant &&
01062           Predicate_immAllOnes(N01.Val)) {
01063         Emit_17(Result, N, SP::ANDNrr, MVT::i32, N0, N00, N01, N1);
01064         return;
01065       }
01066     }
01067 
01068     // Pattern: (and:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
01069     // Emits: (ANDri:i32 IntRegs:i32:$b, (imm:i32):$c)
01070     // Pattern complexity = 5  cost = 1
01071     N1 = N.getOperand(1);
01072     if (N1.getOpcode() == ISD::Constant &&
01073         Predicate_simm13(N1.Val)) {
01074       Emit_12(Result, N, SP::ANDri, MVT::i32, N0, N1);
01075       return;
01076     }
01077   }
01078 
01079   // Pattern: (and:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01080   // Emits: (ANDrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01081   // Pattern complexity = 2  cost = 1
01082   Emit_13(Result, N, SP::ANDrr, MVT::i32, N0, N1);
01083   return;
01084 }
01085 
01086 void Emit_18(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain, SDOperand &N1) NOINLINE {
01087   SDOperand Tmp0(0, 0);
01088   SDNode *ResNode = NULL;
01089   Select(Tmp0, N1);
01090   Select(Chain, Chain);
01091   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Tmp0, Chain);
01092   Chain = SDOperand(ResNode, 0);
01093   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
01094   Result = SDOperand(ResNode, N.ResNo);
01095   return;
01096 }
01097 void Select_br(SDOperand &Result, SDOperand N) {
01098   SDOperand Chain(0, 0);
01099   SDOperand N1(0, 0);
01100   SDOperand Tmp0(0, 0);
01101   SDNode *ResNode = NULL;
01102   Chain = N.getOperand(0);
01103   N1 = N.getOperand(1);
01104   if (N1.getOpcode() == ISD::BasicBlock) {
01105     Emit_18(Result, N, SP::BA, Chain, N1);
01106     return;
01107   }
01108   std::cerr << "Cannot yet select: ";
01109   N.Val->dump(CurDAG);
01110   std::cerr << '\n';
01111   abort();
01112 }
01113 
01114 void Emit_19(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &CPTmp0, SDOperand &CPTmp1, SDOperand &Chain, SDOperand &N1, bool HasInFlag) NOINLINE {
01115   SDOperand InFlag(0, 0);
01116   SDOperand Tmp0(0, 0);
01117   SDOperand Tmp1(0, 0);
01118   SDNode *ResNode = NULL;
01119   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
01120   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
01121   Select(Tmp0, CPTmp0);
01122   Select(Tmp1, CPTmp1);
01123   Select(Chain, Chain);
01124   if (HasInFlag)
01125     Select(InFlag, N.getOperand(N.getNumOperands()-1));
01126   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
01127   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
01128   ResNode = HasInFlag ? CurDAG->getTargetNode(Opc0, MVT::Other, MVT::Flag, Tmp0, Tmp1, Chain, InFlag) : CurDAG->getTargetNode(Opc0, MVT::Other, MVT::Flag, Tmp0, Tmp1, Chain);
01129   Chain = SDOperand(ResNode, 0);
01130   InFlag = SDOperand(ResNode, 1);
01131   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
01132   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
01133   Result = SDOperand(ResNode, N.ResNo);
01134   return;
01135 }
01136 void Emit_20(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain, SDOperand &N1, bool HasInFlag) NOINLINE {
01137   SDOperand InFlag(0, 0);
01138   SDOperand Tmp0(0, 0);
01139   SDNode *ResNode = NULL;
01140   HasInFlag = (N.getOperand(N.getNumOperands()-1).getValueType() == MVT::Flag);
01141   Tmp0 = N1;
01142   Select(Chain, Chain);
01143   if (HasInFlag)
01144     Select(InFlag, N.getOperand(N.getNumOperands()-1));
01145   ResNode = HasInFlag ? CurDAG->getTargetNode(Opc0, MVT::Other, MVT::Flag, Tmp0, Chain, InFlag) : CurDAG->getTargetNode(Opc0, MVT::Other, MVT::Flag, Tmp0, Chain);
01146   Chain = SDOperand(ResNode, 0);
01147   InFlag = SDOperand(ResNode, 1);
01148   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
01149   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, InFlag.Val, InFlag.ResNo);
01150   Result = SDOperand(ResNode, N.ResNo);
01151   return;
01152 }
01153 void Select_call(SDOperand &Result, SDOperand N) {
01154   SDOperand CPTmp0(0, 0);
01155   SDOperand CPTmp1(0, 0);
01156   SDOperand Chain(0, 0);
01157   SDOperand InFlag(0, 0);
01158   SDOperand N1(0, 0);
01159   SDOperand Tmp0(0, 0);
01160   SDOperand Tmp1(0, 0);
01161   SDNode *ResNode = NULL;
01162   bool HasInFlag = false;
01163   Chain = N.getOperand(0);
01164   N1 = N.getOperand(1);
01165   {
01166     HasInFlag = (N.getOperand(N.getNumOperands()-1).getValueType() == MVT::Flag);
01167 
01168     // Pattern: (call:void ADDRrr:i32:$ptr)
01169     // Emits: (JMPLrr:void ADDRrr:i32:$ptr)
01170     // Pattern complexity = 8  cost = 1  size = 0
01171     {
01172       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01173       if (Match) {
01174         Emit_19(Result, N, SP::JMPLrr, CPTmp0, CPTmp1, Chain, N1, HasInFlag);
01175         return;
01176       }
01177     }
01178 
01179     // Pattern: (call:void ADDRri:i32:$ptr)
01180     // Emits: (JMPLri:void ADDRri:i32:$ptr)
01181     // Pattern complexity = 8  cost = 1
01182     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01183     if (Match) {
01184       Emit_19(Result, N, SP::JMPLri, CPTmp0, CPTmp1, Chain, N1, HasInFlag);
01185       return;
01186     }
01187   }
01188 
01189   // Pattern: (call:void (tglobaladdr:i32):$dst)
01190   // Emits: (CALL:void (tglobaladdr:i32):$dst)
01191   // Pattern complexity = 4  cost = 1  size = 0
01192   if (N1.getOpcode() == ISD::TargetGlobalAddress) {
01193     Emit_20(Result, N, SP::CALL, Chain, N1, HasInFlag);
01194     return;
01195   }
01196 
01197   // Pattern: (call:void (texternalsym:i32):$dst)
01198   // Emits: (CALL:void (texternalsym:i32):$dst)
01199   // Pattern complexity = 4  cost = 1
01200   if (N1.getOpcode() == ISD::TargetExternalSymbol) {
01201     Emit_20(Result, N, SP::CALL, Chain, N1, HasInFlag);
01202     return;
01203   }
01204   std::cerr << "Cannot yet select: ";
01205   N.Val->dump(CurDAG);
01206   std::cerr << '\n';
01207   abort();
01208 }
01209 
01210 void Emit_21(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain, SDOperand &N1) NOINLINE {
01211   SDOperand Tmp0(0, 0);
01212   SDNode *ResNode = NULL;
01213   Tmp0 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N1)->getValue()), MVT::i32);
01214   Select(Chain, Chain);
01215   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Tmp0, Chain);
01216   Chain = SDOperand(ResNode, 0);
01217   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
01218   Result = SDOperand(ResNode, N.ResNo);
01219   return;
01220 }
01221 void Select_callseq_end(SDOperand &Result, SDOperand N) {
01222   SDOperand Chain(0, 0);
01223   SDOperand N1(0, 0);
01224   SDOperand Tmp0(0, 0);
01225   SDNode *ResNode = NULL;
01226   Chain = N.getOperand(0);
01227   N1 = N.getOperand(1);
01228   if (N1.getOpcode() == ISD::Constant) {
01229     Emit_21(Result, N, SP::ADJCALLSTACKUP, Chain, N1);
01230     return;
01231   }
01232   std::cerr << "Cannot yet select: ";
01233   N.Val->dump(CurDAG);
01234   std::cerr << '\n';
01235   abort();
01236 }
01237 
01238 void Select_callseq_start(SDOperand &Result, SDOperand N) {
01239   SDOperand Chain(0, 0);
01240   SDOperand N1(0, 0);
01241   SDOperand Tmp0(0, 0);
01242   SDNode *ResNode = NULL;
01243   Chain = N.getOperand(0);
01244   N1 = N.getOperand(1);
01245   if (N1.getOpcode() == ISD::Constant) {
01246     Emit_21(Result, N, SP::ADJCALLSTACKDOWN, Chain, N1);
01247     return;
01248   }
01249   std::cerr << "Cannot yet select: ";
01250   N.Val->dump(CurDAG);
01251   std::cerr << '\n';
01252   abort();
01253 }
01254 
01255 void Emit_22(SDOperand &Result, SDOperand &N, unsigned Opc0, unsigned Opc1, MVT::ValueType VT0, MVT::ValueType VT1, SDOperand &N0) NOINLINE {
01256   SDOperand Tmp0(0, 0);
01257   SDOperand Tmp1(0, 0);
01258   SDOperand Tmp2(0, 0);
01259   SDNode *ResNode = NULL;
01260   N0 = N.getOperand(0);
01261   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
01262   Select(Tmp0, N0);
01263   Tmp1 = CurDAG->getTargetConstant(0, MVT::i32);
01264   Tmp2 = SDOperand(CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1), 0);
01265   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
01266   if (N.Val->hasOneUse()) {
01267     Result = CurDAG->SelectNodeTo(N.Val, Opc1, VT1, Tmp2);
01268   } else {
01269     ResNode = CurDAG->getTargetNode(Opc1, VT1, Tmp2);
01270     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01271     Result = SDOperand(ResNode, 0);
01272   }
01273   return;
01274 }
01275 void Select_ctpop(SDOperand &Result, SDOperand N) {
01276   SDOperand N0(0, 0);
01277   SDOperand Tmp0(0, 0);
01278   SDOperand Tmp1(0, 0);
01279   SDOperand Tmp2(0, 0);
01280   SDNode *ResNode = NULL;
01281   Emit_22(Result, N, SP::SLLri, SP::POPCrr, MVT::i32, MVT::i32, N0);
01282   return;
01283 }
01284 
01285 void Emit_23(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &CPTmp0, SDOperand &CPTmp1, SDOperand &Chain, SDOperand &N1, SDOperand &N2, SDOperand &N3) NOINLINE {
01286   SDOperand Tmp0(0, 0);
01287   SDOperand Tmp1(0, 0);
01288   SDNode *ResNode = NULL;
01289   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
01290   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
01291   Select(Tmp0, CPTmp0);
01292   Select(Tmp1, CPTmp1);
01293   Select(Chain, Chain);
01294   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
01295   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
01296   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Other, Tmp0, Tmp1, Chain);
01297   Chain = SDOperand(ResNode, 1);
01298   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
01299   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Chain.Val, Chain.ResNo);
01300   if (N.ResNo == 0) AddHandleReplacement(N.Val, 1, Chain.Val, Chain.ResNo);
01301   Result = SDOperand(ResNode, N.ResNo);
01302   return;
01303 }
01304 void Select_extld(SDOperand &Result, SDOperand N) {
01305   if (N.ResNo == 1 && N.getValue(0).hasOneUse()) {
01306     SDOperand Dummy = CurDAG->getNode(ISD::HANDLENODE, MVT::Other, N);
01307     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Dummy.Val, 0);
01308     SelectionDAG::InsertISelMapEntry(HandleMap, N.Val, 1, Dummy.Val, 0);
01309     Result = Dummy;
01310     return;
01311   }
01312   SDOperand CPTmp0(0, 0);
01313   SDOperand CPTmp1(0, 0);
01314   SDOperand Chain(0, 0);
01315   SDOperand N1(0, 0);
01316   SDOperand N2(0, 0);
01317   SDOperand N3(0, 0);
01318   SDOperand Tmp0(0, 0);
01319   SDOperand Tmp1(0, 0);
01320   SDNode *ResNode = NULL;
01321   Chain = N.getOperand(0);
01322   N1 = N.getOperand(1);
01323   N2 = N.getOperand(2);
01324   N3 = N.getOperand(3);
01325   if (cast<VTSDNode>(N3)->getVT() == MVT::i1 &&
01326       N.Val->getValueType(0) == MVT::i32 &&
01327       N1.Val->getValueType(0) == MVT::i32) {
01328 
01329     // Pattern: (extld:i32 ADDRrr:i32:$src, srcvalue:Other:$dummy, i1:Other)
01330     // Emits: (LDUBrr:i32 ADDRrr:i32:$src)
01331     // Pattern complexity = 8  cost = 1  size = 0
01332     {
01333       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01334       if (Match) {
01335         Emit_23(Result, N, SP::LDUBrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01336         return;
01337       }
01338     }
01339 
01340     // Pattern: (extld:i32 ADDRri:i32:$src, srcvalue:Other:$dummy, i1:Other)
01341     // Emits: (LDUBri:i32 ADDRri:i32:$src)
01342     // Pattern complexity = 8  cost = 1
01343     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01344     if (Match) {
01345       Emit_23(Result, N, SP::LDUBri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01346       return;
01347     }
01348   }
01349   if (cast<VTSDNode>(N3)->getVT() == MVT::i8 &&
01350       N.Val->getValueType(0) == MVT::i32 &&
01351       N1.Val->getValueType(0) == MVT::i32) {
01352 
01353     // Pattern: (extld:i32 ADDRrr:i32:$src, srcvalue:Other:$dummy, i8:Other)
01354     // Emits: (LDUBrr:i32 ADDRrr:i32:$src)
01355     // Pattern complexity = 8  cost = 1  size = 0
01356     {
01357       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01358       if (Match) {
01359         Emit_23(Result, N, SP::LDUBrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01360         return;
01361       }
01362     }
01363 
01364     // Pattern: (extld:i32 ADDRri:i32:$src, srcvalue:Other:$dummy, i8:Other)
01365     // Emits: (LDUBri:i32 ADDRri:i32:$src)
01366     // Pattern complexity = 8  cost = 1
01367     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01368     if (Match) {
01369       Emit_23(Result, N, SP::LDUBri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01370       return;
01371     }
01372   }
01373   if (cast<VTSDNode>(N3)->getVT() == MVT::i16 &&
01374       N.Val->getValueType(0) == MVT::i32 &&
01375       N1.Val->getValueType(0) == MVT::i32) {
01376 
01377     // Pattern: (extld:i32 ADDRrr:i32:$src, srcvalue:Other:$dummy, i16:Other)
01378     // Emits: (LDUHrr:i32 ADDRrr:i32:$src)
01379     // Pattern complexity = 8  cost = 1  size = 0
01380     {
01381       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01382       if (Match) {
01383         Emit_23(Result, N, SP::LDUHrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01384         return;
01385       }
01386     }
01387 
01388     // Pattern: (extld:i32 ADDRri:i32:$src, srcvalue:Other:$dummy, i16:Other)
01389     // Emits: (LDUHri:i32 ADDRri:i32:$src)
01390     // Pattern complexity = 8  cost = 1
01391     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01392     if (Match) {
01393       Emit_23(Result, N, SP::LDUHri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
01394       return;
01395     }
01396   }
01397   std::cerr << "Cannot yet select: ";
01398   N.Val->dump(CurDAG);
01399   std::cerr << '\n';
01400   abort();
01401 }
01402 
01403 void Select_fabs(SDOperand &Result, SDOperand N) {
01404   SDOperand N0(0, 0);
01405   SDOperand Tmp0(0, 0);
01406   SDNode *ResNode = NULL;
01407 
01408   // Pattern: (fabs:f64 DFPRegs:f64:$src)
01409   // Emits: (FpABSD:f64 DFPRegs:f64:$src)
01410   // Pattern complexity = 2  cost = 1  size = 0
01411   if ((!Subtarget.isV9())) {
01412     N0 = N.getOperand(0);
01413     if (N.Val->getValueType(0) == MVT::f64) {
01414       Emit_4(Result, N, SP::FpABSD, MVT::f64, N0);
01415       return;
01416     }
01417   }
01418 
01419   // Pattern: (fabs:f32 FPRegs:f32:$src)
01420   // Emits: (FABSS:f32 FPRegs:f32:$src)
01421   // Pattern complexity = 2  cost = 1  size = 0
01422   {
01423     N0 = N.getOperand(0);
01424     if (N.Val->getValueType(0) == MVT::f32) {
01425       Emit_4(Result, N, SP::FABSS, MVT::f32, N0);
01426       return;
01427     }
01428   }
01429 
01430   // Pattern: (fabs:f64 DFPRegs:f64:$src)
01431   // Emits: (FABSD:f64 DFPRegs:f64:$src)
01432   // Pattern complexity = 2  cost = 1
01433   if ((Subtarget.isV9())) {
01434     N0 = N.getOperand(0);
01435     if (N.Val->getValueType(0) == MVT::f64) {
01436       Emit_4(Result, N, SP::FABSD, MVT::f64, N0);
01437       return;
01438     }
01439   }
01440   std::cerr << "Cannot yet select: ";
01441   N.Val->dump(CurDAG);
01442   std::cerr << '\n';
01443   abort();
01444 }
01445 
01446 void Emit_24(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1) NOINLINE {
01447   SDOperand Tmp0(0, 0);
01448   SDOperand Tmp1(0, 0);
01449   SDNode *ResNode = NULL;
01450   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
01451   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
01452   Select(Tmp0, N0);
01453   Select(Tmp1, N1);
01454   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
01455   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
01456   if (N.Val->hasOneUse()) {
01457     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
01458   } else {
01459     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01460     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01461     Result = SDOperand(ResNode, 0);
01462   }
01463   return;
01464 }
01465 void Select_fadd(SDOperand &Result, SDOperand N) {
01466   SDOperand N0(0, 0);
01467   SDOperand N1(0, 0);
01468   SDOperand Tmp0(0, 0);
01469   SDOperand Tmp1(0, 0);
01470   SDNode *ResNode = NULL;
01471   N0 = N.getOperand(0);
01472   N1 = N.getOperand(1);
01473 
01474   // Pattern: (fadd:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01475   // Emits: (FADDS:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01476   // Pattern complexity = 2  cost = 1  size = 0
01477   if (N.Val->getValueType(0) == MVT::f32) {
01478     Emit_24(Result, N, SP::FADDS, MVT::f32, N0, N1);
01479     return;
01480   }
01481 
01482   // Pattern: (fadd:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01483   // Emits: (FADDD:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01484   // Pattern complexity = 2  cost = 1
01485   if (N.Val->getValueType(0) == MVT::f64) {
01486     Emit_24(Result, N, SP::FADDD, MVT::f64, N0, N1);
01487     return;
01488   }
01489   std::cerr << "Cannot yet select: ";
01490   N.Val->dump(CurDAG);
01491   std::cerr << '\n';
01492   abort();
01493 }
01494 
01495 void Select_fdiv(SDOperand &Result, SDOperand N) {
01496   SDOperand N0(0, 0);
01497   SDOperand N1(0, 0);
01498   SDOperand Tmp0(0, 0);
01499   SDOperand Tmp1(0, 0);
01500   SDNode *ResNode = NULL;
01501   N0 = N.getOperand(0);
01502   N1 = N.getOperand(1);
01503 
01504   // Pattern: (fdiv:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01505   // Emits: (FDIVS:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01506   // Pattern complexity = 2  cost = 1  size = 0
01507   if (N.Val->getValueType(0) == MVT::f32) {
01508     Emit_24(Result, N, SP::FDIVS, MVT::f32, N0, N1);
01509     return;
01510   }
01511 
01512   // Pattern: (fdiv:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01513   // Emits: (FDIVD:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01514   // Pattern complexity = 2  cost = 1
01515   if (N.Val->getValueType(0) == MVT::f64) {
01516     Emit_24(Result, N, SP::FDIVD, MVT::f64, N0, N1);
01517     return;
01518   }
01519   std::cerr << "Cannot yet select: ";
01520   N.Val->dump(CurDAG);
01521   std::cerr << '\n';
01522   abort();
01523 }
01524 
01525 void Emit_25(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0) NOINLINE {
01526   SDOperand Tmp0(0, 0);
01527   SDNode *ResNode = NULL;
01528   N0 = N.getOperand(0);
01529   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
01530   Select(Tmp0, N0);
01531   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
01532   if (N.Val->hasOneUse()) {
01533     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0);
01534   } else {
01535     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0);
01536     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01537     Result = SDOperand(ResNode, 0);
01538   }
01539   return;
01540 }
01541 void Select_fextend(SDOperand &Result, SDOperand N) {
01542   SDOperand N0(0, 0);
01543   SDOperand Tmp0(0, 0);
01544   SDNode *ResNode = NULL;
01545   Emit_25(Result, N, SP::FSTOD, MVT::f64, N0);
01546   return;
01547 }
01548 
01549 void Emit_26(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N00, SDOperand &N1, SDOperand &N10) NOINLINE {
01550   SDOperand Tmp0(0, 0);
01551   SDOperand Tmp1(0, 0);
01552   SDNode *ResNode = NULL;
01553   N10 = N1.getOperand(0);
01554   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N00.Val);
01555   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N10.Val);
01556   Select(Tmp0, N00);
01557   Select(Tmp1, N10);
01558   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N00.Val);
01559   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N10.Val);
01560   if (N.Val->hasOneUse()) {
01561     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
01562   } else {
01563     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01564     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01565     Result = SDOperand(ResNode, 0);
01566   }
01567   return;
01568 }
01569 void Select_fmul(SDOperand &Result, SDOperand N) {
01570   SDOperand N0(0, 0);
01571   SDOperand N00(0, 0);
01572   SDOperand N1(0, 0);
01573   SDOperand N10(0, 0);
01574   SDOperand Tmp0(0, 0);
01575   SDOperand Tmp1(0, 0);
01576   SDNode *ResNode = NULL;
01577   N0 = N.getOperand(0);
01578 
01579   // Pattern: (fmul:f64 (fextend:f64 FPRegs:f32:$src1), (fextend:f64 FPRegs:f32:$src2))
01580   // Emits: (FSMULD:f64 FPRegs:f32:$src1, FPRegs:f32:$src2)
01581   // Pattern complexity = 6  cost = 1  size = 0
01582   if (N0.getOpcode() == ISD::FP_EXTEND) {
01583     N00 = N0.getOperand(0);
01584     N1 = N.getOperand(1);
01585     if (N1.getOpcode() == ISD::FP_EXTEND) {
01586       Emit_26(Result, N, SP::FSMULD, MVT::f64, N0, N00, N1, N10);
01587       return;
01588     }
01589   }
01590   N1 = N.getOperand(1);
01591 
01592   // Pattern: (fmul:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01593   // Emits: (FMULS:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01594   // Pattern complexity = 2  cost = 1  size = 0
01595   if (N.Val->getValueType(0) == MVT::f32) {
01596     Emit_24(Result, N, SP::FMULS, MVT::f32, N0, N1);
01597     return;
01598   }
01599 
01600   // Pattern: (fmul:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01601   // Emits: (FMULD:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01602   // Pattern complexity = 2  cost = 1
01603   if (N.Val->getValueType(0) == MVT::f64) {
01604     Emit_24(Result, N, SP::FMULD, MVT::f64, N0, N1);
01605     return;
01606   }
01607   std::cerr << "Cannot yet select: ";
01608   N.Val->dump(CurDAG);
01609   std::cerr << '\n';
01610   abort();
01611 }
01612 
01613 void Select_fneg(SDOperand &Result, SDOperand N) {
01614   SDOperand N0(0, 0);
01615   SDOperand Tmp0(0, 0);
01616   SDNode *ResNode = NULL;
01617 
01618   // Pattern: (fneg:f64 DFPRegs:f64:$src)
01619   // Emits: (FpNEGD:f64 DFPRegs:f64:$src)
01620   // Pattern complexity = 2  cost = 1  size = 0
01621   if ((!Subtarget.isV9())) {
01622     N0 = N.getOperand(0);
01623     if (N.Val->getValueType(0) == MVT::f64) {
01624       Emit_4(Result, N, SP::FpNEGD, MVT::f64, N0);
01625       return;
01626     }
01627   }
01628 
01629   // Pattern: (fneg:f32 FPRegs:f32:$src)
01630   // Emits: (FNEGS:f32 FPRegs:f32:$src)
01631   // Pattern complexity = 2  cost = 1  size = 0
01632   {
01633     N0 = N.getOperand(0);
01634     if (N.Val->getValueType(0) == MVT::f32) {
01635       Emit_4(Result, N, SP::FNEGS, MVT::f32, N0);
01636       return;
01637     }
01638   }
01639 
01640   // Pattern: (fneg:f64 DFPRegs:f64:$src)
01641   // Emits: (FNEGD:f64 DFPRegs:f64:$src)
01642   // Pattern complexity = 2  cost = 1
01643   if ((Subtarget.isV9())) {
01644     N0 = N.getOperand(0);
01645     if (N.Val->getValueType(0) == MVT::f64) {
01646       Emit_4(Result, N, SP::FNEGD, MVT::f64, N0);
01647       return;
01648     }
01649   }
01650   std::cerr << "Cannot yet select: ";
01651   N.Val->dump(CurDAG);
01652   std::cerr << '\n';
01653   abort();
01654 }
01655 
01656 void Emit_27(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &CPTmp0, SDOperand &CPTmp1) NOINLINE {
01657   SDOperand Tmp0(0, 0);
01658   SDOperand Tmp1(0, 0);
01659   SDNode *ResNode = NULL;
01660   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
01661   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
01662   Select(Tmp0, CPTmp0);
01663   Select(Tmp1, CPTmp1);
01664   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
01665   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
01666   if (N.Val->hasOneUse()) {
01667     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
01668   } else {
01669     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01670     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01671     Result = SDOperand(ResNode, 0);
01672   }
01673   return;
01674 }
01675 void Select_frameindex(SDOperand &Result, SDOperand N) {
01676   SDOperand CPTmp0(0, 0);
01677   SDOperand CPTmp1(0, 0);
01678   SDOperand Tmp0(0, 0);
01679   SDOperand Tmp1(0, 0);
01680   SDNode *ResNode = NULL;
01681   if (N.Val->getValueType(0) == MVT::i32) {
01682     bool Match = SelectADDRri(N, CPTmp0, CPTmp1);
01683     if (Match) {
01684       Emit_27(Result, N, SP::LEA_ADDri, MVT::i32, CPTmp0, CPTmp1);
01685       return;
01686     }
01687   }
01688   std::cerr << "Cannot yet select: ";
01689   N.Val->dump(CurDAG);
01690   std::cerr << '\n';
01691   abort();
01692 }
01693 
01694 void Select_fround(SDOperand &Result, SDOperand N) {
01695   SDOperand N0(0, 0);
01696   SDOperand Tmp0(0, 0);
01697   SDNode *ResNode = NULL;
01698   Emit_25(Result, N, SP::FDTOS, MVT::f32, N0);
01699   return;
01700 }
01701 
01702 void Select_fsqrt(SDOperand &Result, SDOperand N) {
01703   SDOperand N0(0, 0);
01704   SDOperand Tmp0(0, 0);
01705   SDNode *ResNode = NULL;
01706   N0 = N.getOperand(0);
01707 
01708   // Pattern: (fsqrt:f32 FPRegs:f32:$src)
01709   // Emits: (FSQRTS:f32 FPRegs:f32:$src)
01710   // Pattern complexity = 2  cost = 1  size = 0
01711   if (N.Val->getValueType(0) == MVT::f32) {
01712     Emit_4(Result, N, SP::FSQRTS, MVT::f32, N0);
01713     return;
01714   }
01715 
01716   // Pattern: (fsqrt:f64 DFPRegs:f64:$src)
01717   // Emits: (FSQRTD:f64 DFPRegs:f64:$src)
01718   // Pattern complexity = 2  cost = 1
01719   if (N.Val->getValueType(0) == MVT::f64) {
01720     Emit_4(Result, N, SP::FSQRTD, MVT::f64, N0);
01721     return;
01722   }
01723   std::cerr << "Cannot yet select: ";
01724   N.Val->dump(CurDAG);
01725   std::cerr << '\n';
01726   abort();
01727 }
01728 
01729 void Select_fsub(SDOperand &Result, SDOperand N) {
01730   SDOperand N0(0, 0);
01731   SDOperand N1(0, 0);
01732   SDOperand Tmp0(0, 0);
01733   SDOperand Tmp1(0, 0);
01734   SDNode *ResNode = NULL;
01735   N0 = N.getOperand(0);
01736   N1 = N.getOperand(1);
01737 
01738   // Pattern: (fsub:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01739   // Emits: (FSUBS:f32 FPRegs:f32:$src1, FPRegs:f32:$src2)
01740   // Pattern complexity = 2  cost = 1  size = 0
01741   if (N.Val->getValueType(0) == MVT::f32) {
01742     Emit_24(Result, N, SP::FSUBS, MVT::f32, N0, N1);
01743     return;
01744   }
01745 
01746   // Pattern: (fsub:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01747   // Emits: (FSUBD:f64 DFPRegs:f64:$src1, DFPRegs:f64:$src2)
01748   // Pattern complexity = 2  cost = 1
01749   if (N.Val->getValueType(0) == MVT::f64) {
01750     Emit_24(Result, N, SP::FSUBD, MVT::f64, N0, N1);
01751     return;
01752   }
01753   std::cerr << "Cannot yet select: ";
01754   N.Val->dump(CurDAG);
01755   std::cerr << '\n';
01756   abort();
01757 }
01758 
01759 void Emit_28(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0) NOINLINE {
01760   SDOperand Tmp0(0, 0);
01761   SDOperand Tmp1(0, 0);
01762   SDNode *ResNode = NULL;
01763   Tmp0 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N)->getValue()), MVT::i32);
01764   Tmp1 = Transform_HI22(Tmp0.Val);
01765   if (N.Val->hasOneUse()) {
01766     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp1);
01767   } else {
01768     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp1);
01769     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01770     Result = SDOperand(ResNode, 0);
01771   }
01772   return;
01773 }
01774 void Emit_29(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0) NOINLINE {
01775   SDOperand Tmp0(0, 0);
01776   SDOperand Tmp1(0, 0);
01777   SDNode *ResNode = NULL;
01778   Tmp0 = CurDAG->getRegister(SP::G0, MVT::i32);
01779   Tmp1 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N)->getValue()), MVT::i32);
01780   if (N.Val->hasOneUse()) {
01781     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
01782   } else {
01783     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
01784     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01785     Result = SDOperand(ResNode, 0);
01786   }
01787   return;
01788 }
01789 void Emit_30(SDOperand &Result, SDOperand &N, unsigned Opc0, unsigned Opc1, MVT::ValueType VT0, MVT::ValueType VT1) NOINLINE {
01790   SDOperand Tmp0(0, 0);
01791   SDOperand Tmp1(0, 0);
01792   SDOperand Tmp2(0, 0);
01793   SDOperand Tmp3(0, 0);
01794   SDNode *ResNode = NULL;
01795   Tmp0 = CurDAG->getTargetConstant(((unsigned) cast<ConstantSDNode>(N)->getValue()), MVT::i32);
01796   Tmp1 = Transform_HI22(Tmp0.Val);
01797   Tmp2 = SDOperand(CurDAG->getTargetNode(Opc0, VT0, Tmp1), 0);
01798   Tmp3 = Transform_LO10(Tmp0.Val);
01799   if (N.Val->hasOneUse()) {
01800     Result = CurDAG->SelectNodeTo(N.Val, Opc1, VT1, Tmp2, Tmp3);
01801   } else {
01802     ResNode = CurDAG->getTargetNode(Opc1, VT1, Tmp2, Tmp3);
01803     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
01804     Result = SDOperand(ResNode, 0);
01805   }
01806   return;
01807 }
01808 void Select_imm(SDOperand &Result, SDOperand N) {
01809   SDOperand Tmp0(0, 0);
01810   SDOperand Tmp1(0, 0);
01811   SDOperand Tmp2(0, 0);
01812   SDOperand Tmp3(0, 0);
01813   SDNode *ResNode = NULL;
01814 
01815   // Pattern: (imm:i32)<<P:Predicate_SETHIimm>><<X:HI22>>:$src
01816   // Emits: (SETHIi:i32 (HI22:i32 (imm:i32):$src))
01817   // Pattern complexity = 3  cost = 1  size = 0
01818   if (Predicate_SETHIimm(N.Val)) {
01819     Emit_28(Result, N, SP::SETHIi, MVT::i32);
01820     return;
01821   }
01822 
01823   // Pattern: (imm:i32)<<P:Predicate_simm13>>:$val
01824   // Emits: (ORri:i32 G0:i32, (imm:i32):$val)
01825   // Pattern complexity = 3  cost = 1  size = 0
01826   if (Predicate_simm13(N.Val)) {
01827     Emit_29(Result, N, SP::ORri, MVT::i32);
01828     return;
01829   }
01830 
01831   // Pattern: (imm:i32):$val
01832   // Emits: (ORri:i32 (SETHIi:i32 (HI22:i32 (imm:i32):$val)), (LO10:i32 (imm:i32):$val))
01833   // Pattern complexity = 2  cost = 2
01834   Emit_30(Result, N, SP::SETHIi, SP::ORri, MVT::i32, MVT::i32);
01835   return;
01836 }
01837 
01838 void Emit_31(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &CPTmp0, SDOperand &CPTmp1, SDOperand &Chain, SDOperand &N1) NOINLINE {
01839   SDOperand Tmp0(0, 0);
01840   SDOperand Tmp1(0, 0);
01841   SDNode *ResNode = NULL;
01842   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
01843   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
01844   Select(Tmp0, CPTmp0);
01845   Select(Tmp1, CPTmp1);
01846   Select(Chain, Chain);
01847   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
01848   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
01849   ResNode = CurDAG->getTargetNode(Opc0, VT0, MVT::Other, Tmp0, Tmp1, Chain);
01850   Chain = SDOperand(ResNode, 1);
01851   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, ResNode, 0);
01852   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Chain.Val, Chain.ResNo);
01853   if (N.ResNo == 0) AddHandleReplacement(N.Val, 1, Chain.Val, Chain.ResNo);
01854   Result = SDOperand(ResNode, N.ResNo);
01855   return;
01856 }
01857 void Select_load(SDOperand &Result, SDOperand N) {
01858   if (N.ResNo == 1 && N.getValue(0).hasOneUse()) {
01859     SDOperand Dummy = CurDAG->getNode(ISD::HANDLENODE, MVT::Other, N);
01860     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Dummy.Val, 0);
01861     SelectionDAG::InsertISelMapEntry(HandleMap, N.Val, 1, Dummy.Val, 0);
01862     Result = Dummy;
01863     return;
01864   }
01865   SDOperand CPTmp0(0, 0);
01866   SDOperand CPTmp1(0, 0);
01867   SDOperand Chain(0, 0);
01868   SDOperand N1(0, 0);
01869   SDOperand Tmp0(0, 0);
01870   SDOperand Tmp1(0, 0);
01871   SDNode *ResNode = NULL;
01872   Chain = N.getOperand(0);
01873   N1 = N.getOperand(1);
01874   if (N.Val->getValueType(0) == MVT::i32 &&
01875       N1.Val->getValueType(0) == MVT::i32) {
01876 
01877     // Pattern: (load:i32 ADDRrr:i32:$addr)
01878     // Emits: (LDrr:i32 ADDRrr:i32:$addr)
01879     // Pattern complexity = 8  cost = 1  size = 0
01880     {
01881       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01882       if (Match) {
01883         Emit_31(Result, N, SP::LDrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1);
01884         return;
01885       }
01886     }
01887 
01888     // Pattern: (load:i32 ADDRri:i32:$addr)
01889     // Emits: (LDri:i32 ADDRri:i32:$addr)
01890     // Pattern complexity = 8  cost = 1
01891     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01892     if (Match) {
01893       Emit_31(Result, N, SP::LDri, MVT::i32, CPTmp0, CPTmp1, Chain, N1);
01894       return;
01895     }
01896   }
01897   if (N.Val->getValueType(0) == MVT::f32 &&
01898       N1.Val->getValueType(0) == MVT::i32) {
01899 
01900     // Pattern: (load:f32 ADDRrr:i32:$addr)
01901     // Emits: (LDFrr:f32 ADDRrr:i32:$addr)
01902     // Pattern complexity = 8  cost = 1  size = 0
01903     {
01904       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01905       if (Match) {
01906         Emit_31(Result, N, SP::LDFrr, MVT::f32, CPTmp0, CPTmp1, Chain, N1);
01907         return;
01908       }
01909     }
01910 
01911     // Pattern: (load:f32 ADDRri:i32:$addr)
01912     // Emits: (LDFri:f32 ADDRri:i32:$addr)
01913     // Pattern complexity = 8  cost = 1
01914     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01915     if (Match) {
01916       Emit_31(Result, N, SP::LDFri, MVT::f32, CPTmp0, CPTmp1, Chain, N1);
01917       return;
01918     }
01919   }
01920   if (N.Val->getValueType(0) == MVT::f64 &&
01921       N1.Val->getValueType(0) == MVT::i32) {
01922 
01923     // Pattern: (load:f64 ADDRrr:i32:$addr)
01924     // Emits: (LDDFrr:f64 ADDRrr:i32:$addr)
01925     // Pattern complexity = 8  cost = 1  size = 0
01926     {
01927       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
01928       if (Match) {
01929         Emit_31(Result, N, SP::LDDFrr, MVT::f64, CPTmp0, CPTmp1, Chain, N1);
01930         return;
01931       }
01932     }
01933 
01934     // Pattern: (load:f64 ADDRri:i32:$addr)
01935     // Emits: (LDDFri:f64 ADDRri:i32:$addr)
01936     // Pattern complexity = 8  cost = 1
01937     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
01938     if (Match) {
01939       Emit_31(Result, N, SP::LDDFri, MVT::f64, CPTmp0, CPTmp1, Chain, N1);
01940       return;
01941     }
01942   }
01943   std::cerr << "Cannot yet select: ";
01944   N.Val->dump(CurDAG);
01945   std::cerr << '\n';
01946   abort();
01947 }
01948 
01949 void Select_mul(SDOperand &Result, SDOperand N) {
01950   SDOperand N0(0, 0);
01951   SDOperand N1(0, 0);
01952   SDOperand Tmp0(0, 0);
01953   SDOperand Tmp1(0, 0);
01954   SDNode *ResNode = NULL;
01955 
01956   // Pattern: (mul:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
01957   // Emits: (SMULri:i32 IntRegs:i32:$b, (imm:i32):$c)
01958   // Pattern complexity = 5  cost = 1  size = 0
01959   {
01960     N0 = N.getOperand(0);
01961     N1 = N.getOperand(1);
01962     if (N1.getOpcode() == ISD::Constant &&
01963         Predicate_simm13(N1.Val)) {
01964       Emit_12(Result, N, SP::SMULri, MVT::i32, N0, N1);
01965       return;
01966     }
01967   }
01968 
01969   // Pattern: (mul:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01970   // Emits: (SMULrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01971   // Pattern complexity = 2  cost = 1
01972   Emit_13(Result, N, SP::SMULrr, MVT::i32, N0, N1);
01973   return;
01974 }
01975 
01976 void Select_or(SDOperand &Result, SDOperand N) {
01977   SDOperand N0(0, 0);
01978   SDOperand N00(0, 0);
01979   SDOperand N01(0, 0);
01980   SDOperand N1(0, 0);
01981   SDOperand N10(0, 0);
01982   SDOperand N11(0, 0);
01983   SDOperand Tmp0(0, 0);
01984   SDOperand Tmp1(0, 0);
01985   SDNode *ResNode = NULL;
01986   {
01987     N0 = N.getOperand(0);
01988 
01989     // Pattern: (or:i32 IntRegs:i32:$b, (xor:i32 IntRegs:i32:$c, (imm:i32)<<P:Predicate_immAllOnes>>))
01990     // Emits: (ORNrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
01991     // Pattern complexity = 7  cost = 1  size = 0
01992     {
01993       N1 = N.getOperand(1);
01994       if (N1.getOpcode() == ISD::XOR) {
01995         N10 = N1.getOperand(0);
01996         N11 = N1.getOperand(1);
01997         if (N11.getOpcode() == ISD::Constant &&
01998             Predicate_immAllOnes(N11.Val)) {
01999           Emit_16(Result, N, SP::ORNrr, MVT::i32, N0, N1, N10, N11);
02000           return;
02001         }
02002       }
02003     }
02004 
02005     // Pattern: (or:i32 (xor:i32 IntRegs:i32:$c, (imm:i32)<<P:Predicate_immAllOnes>>), IntRegs:i32:$b)
02006     // Emits: (ORNrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02007     // Pattern complexity = 7  cost = 1  size = 0
02008     if (N0.getOpcode() == ISD::XOR) {
02009       N00 = N0.getOperand(0);
02010       N01 = N0.getOperand(1);
02011       if (N01.getOpcode() == ISD::Constant &&
02012           Predicate_immAllOnes(N01.Val)) {
02013         Emit_17(Result, N, SP::ORNrr, MVT::i32, N0, N00, N01, N1);
02014         return;
02015       }
02016     }
02017 
02018     // Pattern: (or:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02019     // Emits: (ORri:i32 IntRegs:i32:$b, (imm:i32):$c)
02020     // Pattern complexity = 5  cost = 1
02021     N1 = N.getOperand(1);
02022     if (N1.getOpcode() == ISD::Constant &&
02023         Predicate_simm13(N1.Val)) {
02024       Emit_12(Result, N, SP::ORri, MVT::i32, N0, N1);
02025       return;
02026     }
02027   }
02028 
02029   // Pattern: (or:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02030   // Emits: (ORrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02031   // Pattern complexity = 2  cost = 1
02032   Emit_13(Result, N, SP::ORrr, MVT::i32, N0, N1);
02033   return;
02034 }
02035 
02036 void Emit_32(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain) NOINLINE {
02037   SDNode *ResNode = NULL;
02038   Chain = N.getOperand(0);
02039   Select(Chain, Chain);
02040   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Chain);
02041   Chain = SDOperand(ResNode, 0);
02042   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
02043   Result = SDOperand(ResNode, N.ResNo);
02044   return;
02045 }
02046 void Select_ret(SDOperand &Result, SDOperand N) {
02047   SDOperand Chain(0, 0);
02048   SDNode *ResNode = NULL;
02049   Emit_32(Result, N, SP::RETL, Chain);
02050   return;
02051 }
02052 
02053 void Emit_33(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &Chain, bool HasInFlag) NOINLINE {
02054   SDOperand InFlag(0, 0);
02055   SDNode *ResNode = NULL;
02056   Chain = N.getOperand(0);
02057   HasInFlag = (N.getOperand(N.getNumOperands()-1).getValueType() == MVT::Flag);
02058   Select(Chain, Chain);
02059   if (HasInFlag)
02060     Select(InFlag, N.getOperand(N.getNumOperands()-1));
02061   ResNode = HasInFlag ? CurDAG->getTargetNode(Opc0, MVT::Other, Chain, InFlag) : CurDAG->getTargetNode(Opc0, MVT::Other, Chain);
02062   Chain = SDOperand(ResNode, 0);
02063   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
02064   Result = SDOperand(ResNode, N.ResNo);
02065   return;
02066 }
02067 void Select_retflag(SDOperand &Result, SDOperand N) {
02068   SDOperand Chain(0, 0);
02069   SDOperand InFlag(0, 0);
02070   SDNode *ResNode = NULL;
02071   bool HasInFlag = false;
02072   Emit_33(Result, N, SP::RETL, Chain, HasInFlag);
02073   return;
02074 }
02075 
02076 void Select_sextld(SDOperand &Result, SDOperand N) {
02077   if (N.ResNo == 1 && N.getValue(0).hasOneUse()) {
02078     SDOperand Dummy = CurDAG->getNode(ISD::HANDLENODE, MVT::Other, N);
02079     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Dummy.Val, 0);
02080     SelectionDAG::InsertISelMapEntry(HandleMap, N.Val, 1, Dummy.Val, 0);
02081     Result = Dummy;
02082     return;
02083   }
02084   SDOperand CPTmp0(0, 0);
02085   SDOperand CPTmp1(0, 0);
02086   SDOperand Chain(0, 0);
02087   SDOperand N1(0, 0);
02088   SDOperand N2(0, 0);
02089   SDOperand N3(0, 0);
02090   SDOperand Tmp0(0, 0);
02091   SDOperand Tmp1(0, 0);
02092   SDNode *ResNode = NULL;
02093   Chain = N.getOperand(0);
02094   N1 = N.getOperand(1);
02095   N2 = N.getOperand(2);
02096   N3 = N.getOperand(3);
02097   if (cast<VTSDNode>(N3)->getVT() == MVT::i8 &&
02098       N1.Val->getValueType(0) == MVT::i32) {
02099 
02100     // Pattern: (sextld:i32 ADDRrr:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02101     // Emits: (LDSBrr:i32 ADDRrr:i32:$addr)
02102     // Pattern complexity = 8  cost = 1  size = 0
02103     {
02104       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
02105       if (Match) {
02106         Emit_23(Result, N, SP::LDSBrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02107         return;
02108       }
02109     }
02110 
02111     // Pattern: (sextld:i32 ADDRri:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02112     // Emits: (LDSBri:i32 ADDRri:i32:$addr)
02113     // Pattern complexity = 8  cost = 1
02114     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
02115     if (Match) {
02116       Emit_23(Result, N, SP::LDSBri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02117       return;
02118     }
02119   }
02120   if (cast<VTSDNode>(N3)->getVT() == MVT::i16 &&
02121       N1.Val->getValueType(0) == MVT::i32) {
02122 
02123     // Pattern: (sextld:i32 ADDRrr:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02124     // Emits: (LDSHrr:i32 ADDRrr:i32:$addr)
02125     // Pattern complexity = 8  cost = 1  size = 0
02126     {
02127       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
02128       if (Match) {
02129         Emit_23(Result, N, SP::LDSHrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02130         return;
02131       }
02132     }
02133 
02134     // Pattern: (sextld:i32 ADDRri:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02135     // Emits: (LDSHri:i32 ADDRri:i32:$addr)
02136     // Pattern complexity = 8  cost = 1
02137     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
02138     if (Match) {
02139       Emit_23(Result, N, SP::LDSHri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02140       return;
02141     }
02142   }
02143   std::cerr << "Cannot yet select: ";
02144   N.Val->dump(CurDAG);
02145   std::cerr << '\n';
02146   abort();
02147 }
02148 
02149 void Select_shl(SDOperand &Result, SDOperand N) {
02150   SDOperand N0(0, 0);
02151   SDOperand N1(0, 0);
02152   SDOperand Tmp0(0, 0);
02153   SDOperand Tmp1(0, 0);
02154   SDNode *ResNode = NULL;
02155 
02156   // Pattern: (shl:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02157   // Emits: (SLLri:i32 IntRegs:i32:$b, (imm:i32):$c)
02158   // Pattern complexity = 5  cost = 1  size = 0
02159   {
02160     N0 = N.getOperand(0);
02161     N1 = N.getOperand(1);
02162     if (N1.getOpcode() == ISD::Constant &&
02163         Predicate_simm13(N1.Val)) {
02164       Emit_12(Result, N, SP::SLLri, MVT::i32, N0, N1);
02165       return;
02166     }
02167   }
02168 
02169   // Pattern: (shl:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02170   // Emits: (SLLrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02171   // Pattern complexity = 2  cost = 1
02172   Emit_13(Result, N, SP::SLLrr, MVT::i32, N0, N1);
02173   return;
02174 }
02175 
02176 void Select_sra(SDOperand &Result, SDOperand N) {
02177   SDOperand N0(0, 0);
02178   SDOperand N1(0, 0);
02179   SDOperand Tmp0(0, 0);
02180   SDOperand Tmp1(0, 0);
02181   SDNode *ResNode = NULL;
02182 
02183   // Pattern: (sra:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02184   // Emits: (SRAri:i32 IntRegs:i32:$b, (imm:i32):$c)
02185   // Pattern complexity = 5  cost = 1  size = 0
02186   {
02187     N0 = N.getOperand(0);
02188     N1 = N.getOperand(1);
02189     if (N1.getOpcode() == ISD::Constant &&
02190         Predicate_simm13(N1.Val)) {
02191       Emit_12(Result, N, SP::SRAri, MVT::i32, N0, N1);
02192       return;
02193     }
02194   }
02195 
02196   // Pattern: (sra:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02197   // Emits: (SRArr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02198   // Pattern complexity = 2  cost = 1
02199   Emit_13(Result, N, SP::SRArr, MVT::i32, N0, N1);
02200   return;
02201 }
02202 
02203 void Select_srl(SDOperand &Result, SDOperand N) {
02204   SDOperand N0(0, 0);
02205   SDOperand N1(0, 0);
02206   SDOperand Tmp0(0, 0);
02207   SDOperand Tmp1(0, 0);
02208   SDNode *ResNode = NULL;
02209 
02210   // Pattern: (srl:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02211   // Emits: (SRLri:i32 IntRegs:i32:$b, (imm:i32):$c)
02212   // Pattern complexity = 5  cost = 1  size = 0
02213   {
02214     N0 = N.getOperand(0);
02215     N1 = N.getOperand(1);
02216     if (N1.getOpcode() == ISD::Constant &&
02217         Predicate_simm13(N1.Val)) {
02218       Emit_12(Result, N, SP::SRLri, MVT::i32, N0, N1);
02219       return;
02220     }
02221   }
02222 
02223   // Pattern: (srl:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02224   // Emits: (SRLrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02225   // Pattern complexity = 2  cost = 1
02226   Emit_13(Result, N, SP::SRLrr, MVT::i32, N0, N1);
02227   return;
02228 }
02229 
02230 void Emit_34(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &CPTmp0, SDOperand &CPTmp1, SDOperand &Chain, SDOperand &N1, SDOperand &N2) NOINLINE {
02231   SDOperand Tmp0(0, 0);
02232   SDOperand Tmp1(0, 0);
02233   SDOperand Tmp2(0, 0);
02234   SDNode *ResNode = NULL;
02235   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
02236   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
02237   Select(Tmp0, CPTmp0);
02238   Select(Tmp1, CPTmp1);
02239   Select(Tmp2, N1);
02240   Select(Chain, Chain);
02241   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02242   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
02243   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
02244   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Tmp0, Tmp1, Tmp2, Chain);
02245   Chain = SDOperand(ResNode, 0);
02246   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
02247   Result = SDOperand(ResNode, N.ResNo);
02248   return;
02249 }
02250 void Select_store(SDOperand &Result, SDOperand N) {
02251   SDOperand CPTmp0(0, 0);
02252   SDOperand CPTmp1(0, 0);
02253   SDOperand Chain(0, 0);
02254   SDOperand N1(0, 0);
02255   SDOperand N2(0, 0);
02256   SDOperand Tmp0(0, 0);
02257   SDOperand Tmp1(0, 0);
02258   SDOperand Tmp2(0, 0);
02259   SDNode *ResNode = NULL;
02260   Chain = N.getOperand(0);
02261   N1 = N.getOperand(1);
02262   N2 = N.getOperand(2);
02263   if (N1.Val->getValueType(0) == MVT::i32 &&
02264       N2.Val->getValueType(0) == MVT::i32) {
02265     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02266 
02267     // Pattern: (store:void IntRegs:i32:$src, ADDRrr:i32:$addr)
02268     // Emits: (STrr:void ADDRrr:i32:$addr, IntRegs:i32:$src)
02269     // Pattern complexity = 8  cost = 1  size = 0
02270     {
02271       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02272       if (!Match) {
02273         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02274       }
02275       if (Match) {
02276         Emit_34(Result, N, SP::STrr, CPTmp0, CPTmp1, Chain, N1, N2);
02277         return;
02278       }
02279     }
02280 
02281     // Pattern: (store:void IntRegs:i32:$src, ADDRri:i32:$addr)
02282     // Emits: (STri:void ADDRri:i32:$addr, IntRegs:i32:$src)
02283     // Pattern complexity = 8  cost = 1
02284     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02285     if (!Match) {
02286       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02287     }
02288     if (Match) {
02289       Emit_34(Result, N, SP::STri, CPTmp0, CPTmp1, Chain, N1, N2);
02290       return;
02291     }
02292   }
02293   if (N1.Val->getValueType(0) == MVT::f32 &&
02294       N2.Val->getValueType(0) == MVT::i32) {
02295     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02296 
02297     // Pattern: (store:void FPRegs:f32:$src, ADDRrr:i32:$addr)
02298     // Emits: (STFrr:void ADDRrr:i32:$addr, FPRegs:f32:$src)
02299     // Pattern complexity = 8  cost = 1  size = 0
02300     {
02301       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02302       if (!Match) {
02303         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02304       }
02305       if (Match) {
02306         Emit_34(Result, N, SP::STFrr, CPTmp0, CPTmp1, Chain, N1, N2);
02307         return;
02308       }
02309     }
02310 
02311     // Pattern: (store:void FPRegs:f32:$src, ADDRri:i32:$addr)
02312     // Emits: (STFri:void ADDRri:i32:$addr, FPRegs:f32:$src)
02313     // Pattern complexity = 8  cost = 1
02314     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02315     if (!Match) {
02316       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02317     }
02318     if (Match) {
02319       Emit_34(Result, N, SP::STFri, CPTmp0, CPTmp1, Chain, N1, N2);
02320       return;
02321     }
02322   }
02323   if (N1.Val->getValueType(0) == MVT::f64 &&
02324       N2.Val->getValueType(0) == MVT::i32) {
02325     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02326 
02327     // Pattern: (store:void DFPRegs:f64:$src, ADDRrr:i32:$addr)
02328     // Emits: (STDFrr:void ADDRrr:i32:$addr, DFPRegs:f64:$src)
02329     // Pattern complexity = 8  cost = 1  size = 0
02330     {
02331       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02332       if (!Match) {
02333         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02334       }
02335       if (Match) {
02336         Emit_34(Result, N, SP::STDFrr, CPTmp0, CPTmp1, Chain, N1, N2);
02337         return;
02338       }
02339     }
02340 
02341     // Pattern: (store:void DFPRegs:f64:$src, ADDRri:i32:$addr)
02342     // Emits: (STDFri:void ADDRri:i32:$addr, DFPRegs:f64:$src)
02343     // Pattern complexity = 8  cost = 1
02344     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02345     if (!Match) {
02346       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02347     }
02348     if (Match) {
02349       Emit_34(Result, N, SP::STDFri, CPTmp0, CPTmp1, Chain, N1, N2);
02350       return;
02351     }
02352   }
02353   std::cerr << "Cannot yet select: ";
02354   N.Val->dump(CurDAG);
02355   std::cerr << '\n';
02356   abort();
02357 }
02358 
02359 void Select_sub(SDOperand &Result, SDOperand N) {
02360   SDOperand N0(0, 0);
02361   SDOperand N1(0, 0);
02362   SDOperand Tmp0(0, 0);
02363   SDOperand Tmp1(0, 0);
02364   SDNode *ResNode = NULL;
02365 
02366   // Pattern: (sub:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02367   // Emits: (SUBri:i32 IntRegs:i32:$b, (imm:i32):$c)
02368   // Pattern complexity = 5  cost = 1  size = 0
02369   {
02370     N0 = N.getOperand(0);
02371     N1 = N.getOperand(1);
02372     if (N1.getOpcode() == ISD::Constant &&
02373         Predicate_simm13(N1.Val)) {
02374       Emit_12(Result, N, SP::SUBri, MVT::i32, N0, N1);
02375       return;
02376     }
02377   }
02378 
02379   // Pattern: (sub:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02380   // Emits: (SUBrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02381   // Pattern complexity = 2  cost = 1
02382   Emit_13(Result, N, SP::SUBrr, MVT::i32, N0, N1);
02383   return;
02384 }
02385 
02386 void Select_subc(SDOperand &Result, SDOperand N) {
02387   SDOperand InFlag(0, 0);
02388   SDOperand N0(0, 0);
02389   SDOperand N1(0, 0);
02390   SDOperand Tmp0(0, 0);
02391   SDOperand Tmp1(0, 0);
02392   SDNode *ResNode = NULL;
02393 
02394   // Pattern: (subc:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$val)
02395   // Emits: (SUBCCri:i32 IntRegs:i32:$b, (imm:i32):$val)
02396   // Pattern complexity = 5  cost = 1  size = 0
02397   {
02398     N0 = N.getOperand(0);
02399     N1 = N.getOperand(1);
02400     if (N1.getOpcode() == ISD::Constant &&
02401         Predicate_simm13(N1.Val)) {
02402       Emit_2(Result, N, SP::SUBCCri, MVT::i32, N0, N1);
02403       return;
02404     }
02405   }
02406 
02407   // Pattern: (subc:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02408   // Emits: (SUBCCrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02409   // Pattern complexity = 2  cost = 1
02410   Emit_3(Result, N, SP::SUBCCrr, MVT::i32, N0, N1);
02411   return;
02412 }
02413 
02414 void Select_sube(SDOperand &Result, SDOperand N) {
02415   SDOperand InFlag(0, 0);
02416   SDOperand N0(0, 0);
02417   SDOperand N1(0, 0);
02418   SDOperand Tmp0(0, 0);
02419   SDOperand Tmp1(0, 0);
02420   SDNode *ResNode = NULL;
02421 
02422   // Pattern: (sube:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02423   // Emits: (SUBXri:i32 IntRegs:i32:$b, (imm:i32):$c)
02424   // Pattern complexity = 5  cost = 1  size = 0
02425   {
02426     N0 = N.getOperand(0);
02427     N1 = N.getOperand(1);
02428     if (N1.getOpcode() == ISD::Constant &&
02429         Predicate_simm13(N1.Val)) {
02430       Emit_14(Result, N, SP::SUBXri, MVT::i32, N0, N1);
02431       return;
02432     }
02433   }
02434 
02435   // Pattern: (sube:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02436   // Emits: (SUBXrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02437   // Pattern complexity = 2  cost = 1
02438   Emit_15(Result, N, SP::SUBXrr, MVT::i32, N0, N1);
02439   return;
02440 }
02441 
02442 void Emit_35(SDOperand &Result, SDOperand &N, unsigned Opc0, SDOperand &CPTmp0, SDOperand &CPTmp1, SDOperand &Chain, SDOperand &N1, SDOperand &N2, SDOperand &N3, SDOperand &N4) NOINLINE {
02443   SDOperand Tmp0(0, 0);
02444   SDOperand Tmp1(0, 0);
02445   SDOperand Tmp2(0, 0);
02446   SDNode *ResNode = NULL;
02447   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp0.Val);
02448   SelectionDAG::InsertInFlightSetEntry(InFlightSet, CPTmp1.Val);
02449   Select(Tmp0, CPTmp0);
02450   Select(Tmp1, CPTmp1);
02451   Select(Tmp2, N1);
02452   Select(Chain, Chain);
02453   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02454   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp0.Val);
02455   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, CPTmp1.Val);
02456   ResNode = CurDAG->getTargetNode(Opc0, MVT::Other, Tmp0, Tmp1, Tmp2, Chain);
02457   Chain = SDOperand(ResNode, 0);
02458   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Chain.Val, Chain.ResNo);
02459   Result = SDOperand(ResNode, N.ResNo);
02460   return;
02461 }
02462 void Select_truncst(SDOperand &Result, SDOperand N) {
02463   SDOperand CPTmp0(0, 0);
02464   SDOperand CPTmp1(0, 0);
02465   SDOperand Chain(0, 0);
02466   SDOperand N1(0, 0);
02467   SDOperand N2(0, 0);
02468   SDOperand N3(0, 0);
02469   SDOperand N4(0, 0);
02470   SDOperand Tmp0(0, 0);
02471   SDOperand Tmp1(0, 0);
02472   SDOperand Tmp2(0, 0);
02473   SDNode *ResNode = NULL;
02474   Chain = N.getOperand(0);
02475   N1 = N.getOperand(1);
02476   N2 = N.getOperand(2);
02477   N3 = N.getOperand(3);
02478   N4 = N.getOperand(4);
02479   if (cast<VTSDNode>(N4)->getVT() == MVT::i8 &&
02480       N1.Val->getValueType(0) == MVT::i32 &&
02481       N2.Val->getValueType(0) == MVT::i32) {
02482     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02483 
02484     // Pattern: (truncst:void IntRegs:i32:$src, ADDRrr:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02485     // Emits: (STBrr:void ADDRrr:i32:$addr, IntRegs:i32:$src)
02486     // Pattern complexity = 8  cost = 1  size = 0
02487     {
02488       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02489       if (!Match) {
02490         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02491       }
02492       if (Match) {
02493         Emit_35(Result, N, SP::STBrr, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02494         return;
02495       }
02496     }
02497 
02498     // Pattern: (truncst:void IntRegs:i32:$src, ADDRri:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02499     // Emits: (STBri:void ADDRri:i32:$addr, IntRegs:i32:$src)
02500     // Pattern complexity = 8  cost = 1
02501     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02502     if (!Match) {
02503       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02504     }
02505     if (Match) {
02506       Emit_35(Result, N, SP::STBri, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02507       return;
02508     }
02509   }
02510   if (cast<VTSDNode>(N4)->getVT() == MVT::i16 &&
02511       N1.Val->getValueType(0) == MVT::i32 &&
02512       N2.Val->getValueType(0) == MVT::i32) {
02513     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02514 
02515     // Pattern: (truncst:void IntRegs:i32:$src, ADDRrr:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02516     // Emits: (STHrr:void ADDRrr:i32:$addr, IntRegs:i32:$src)
02517     // Pattern complexity = 8  cost = 1  size = 0
02518     {
02519       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02520       if (!Match) {
02521         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02522       }
02523       if (Match) {
02524         Emit_35(Result, N, SP::STHrr, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02525         return;
02526       }
02527     }
02528 
02529     // Pattern: (truncst:void IntRegs:i32:$src, ADDRri:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02530     // Emits: (STHri:void ADDRri:i32:$addr, IntRegs:i32:$src)
02531     // Pattern complexity = 8  cost = 1
02532     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02533     if (!Match) {
02534       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02535     }
02536     if (Match) {
02537       Emit_35(Result, N, SP::STHri, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02538       return;
02539     }
02540   }
02541   if (cast<VTSDNode>(N4)->getVT() == MVT::i1 &&
02542       N1.Val->getValueType(0) == MVT::i32 &&
02543       N2.Val->getValueType(0) == MVT::i32) {
02544     SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02545 
02546     // Pattern: (truncst:void IntRegs:i32:$src, ADDRrr:i32:$addr, srcvalue:Other:$dummy, i1:Other)
02547     // Emits: (STBrr:void ADDRrr:i32:$addr, IntRegs:i32:$src)
02548     // Pattern complexity = 8  cost = 1  size = 0
02549     {
02550       bool Match = SelectADDRrr(N2, CPTmp0, CPTmp1);
02551       if (!Match) {
02552         SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02553       }
02554       if (Match) {
02555         Emit_35(Result, N, SP::STBrr, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02556         return;
02557       }
02558     }
02559 
02560     // Pattern: (truncst:void IntRegs:i32:$src, ADDRri:i32:$addr, srcvalue:Other:$dummy, i1:Other)
02561     // Emits: (STBri:void ADDRri:i32:$addr, IntRegs:i32:$src)
02562     // Pattern complexity = 8  cost = 1
02563     bool Match = SelectADDRri(N2, CPTmp0, CPTmp1);
02564     if (!Match) {
02565       SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02566     }
02567     if (Match) {
02568       Emit_35(Result, N, SP::STBri, CPTmp0, CPTmp1, Chain, N1, N2, N3, N4);
02569       return;
02570     }
02571   }
02572   std::cerr << "Cannot yet select: ";
02573   N.Val->dump(CurDAG);
02574   std::cerr << '\n';
02575   abort();
02576 }
02577 
02578 void Emit_36(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0) NOINLINE {
02579   SDNode *ResNode = NULL;
02580   if (N.Val->hasOneUse()) {
02581     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0);
02582   } else {
02583     ResNode = CurDAG->getTargetNode(Opc0, VT0);
02584     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
02585     Result = SDOperand(ResNode, 0);
02586   }
02587   return;
02588 }
02589 void Select_undef(SDOperand &Result, SDOperand N) {
02590   SDNode *ResNode = NULL;
02591 
02592   // Pattern: (undef:i32)
02593   // Emits: (IMPLICIT_DEF_Int:i32)
02594   // Pattern complexity = 2  cost = 1  size = 0
02595   if (N.Val->getValueType(0) == MVT::i32) {
02596     Emit_36(Result, N, SP::IMPLICIT_DEF_Int, MVT::i32);
02597     return;
02598   }
02599 
02600   // Pattern: (undef:f32)
02601   // Emits: (IMPLICIT_DEF_FP:f32)
02602   // Pattern complexity = 2  cost = 1  size = 0
02603   if (N.Val->getValueType(0) == MVT::f32) {
02604     Emit_36(Result, N, SP::IMPLICIT_DEF_FP, MVT::f32);
02605     return;
02606   }
02607 
02608   // Pattern: (undef:f64)
02609   // Emits: (IMPLICIT_DEF_DFP:f64)
02610   // Pattern complexity = 2  cost = 1
02611   if (N.Val->getValueType(0) == MVT::f64) {
02612     Emit_36(Result, N, SP::IMPLICIT_DEF_DFP, MVT::f64);
02613     return;
02614   }
02615   std::cerr << "Cannot yet select: ";
02616   N.Val->dump(CurDAG);
02617   std::cerr << '\n';
02618   abort();
02619 }
02620 
02621 void Emit_37(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N00, SDOperand &N01, SDOperand &N1) NOINLINE {
02622   SDOperand Tmp0(0, 0);
02623   SDOperand Tmp1(0, 0);
02624   SDNode *ResNode = NULL;
02625   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N00.Val);
02626   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N01.Val);
02627   Select(Tmp0, N00);
02628   Select(Tmp1, N01);
02629   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N00.Val);
02630   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N01.Val);
02631   if (N.Val->hasOneUse()) {
02632     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
02633   } else {
02634     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
02635     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
02636     Result = SDOperand(ResNode, 0);
02637   }
02638   return;
02639 }
02640 void Emit_38(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N00, SDOperand &N01, SDOperand &N1) NOINLINE {
02641   SDOperand Tmp0(0, 0);
02642   SDOperand Tmp1(0, 0);
02643   SDNode *ResNode = NULL;
02644   N1 = N.getOperand(1);
02645   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N00.Val);
02646   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N1.Val);
02647   Select(Tmp0, N00);
02648   Select(Tmp1, N1);
02649   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N00.Val);
02650   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N1.Val);
02651   if (N.Val->hasOneUse()) {
02652     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
02653   } else {
02654     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
02655     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
02656     Result = SDOperand(ResNode, 0);
02657   }
02658   return;
02659 }
02660 void Emit_39(SDOperand &Result, SDOperand &N, unsigned Opc0, MVT::ValueType VT0, SDOperand &N0, SDOperand &N1, SDOperand &N10, SDOperand &N11) NOINLINE {
02661   SDOperand Tmp0(0, 0);
02662   SDOperand Tmp1(0, 0);
02663   SDNode *ResNode = NULL;
02664   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N10.Val);
02665   SelectionDAG::InsertInFlightSetEntry(InFlightSet, N0.Val);
02666   Select(Tmp0, N10);
02667   Select(Tmp1, N0);
02668   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N10.Val);
02669   SelectionDAG::RemoveInFlightSetEntry(InFlightSet, N0.Val);
02670   if (N.Val->hasOneUse()) {
02671     Result = CurDAG->SelectNodeTo(N.Val, Opc0, VT0, Tmp0, Tmp1);
02672   } else {
02673     ResNode = CurDAG->getTargetNode(Opc0, VT0, Tmp0, Tmp1);
02674     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, ResNode, 0);
02675     Result = SDOperand(ResNode, 0);
02676   }
02677   return;
02678 }
02679 void Select_xor(SDOperand &Result, SDOperand N) {
02680   SDOperand N0(0, 0);
02681   SDOperand N00(0, 0);
02682   SDOperand N01(0, 0);
02683   SDOperand N1(0, 0);
02684   SDOperand N10(0, 0);
02685   SDOperand N11(0, 0);
02686   SDOperand Tmp0(0, 0);
02687   SDOperand Tmp1(0, 0);
02688   SDNode *ResNode = NULL;
02689   {
02690     N0 = N.getOperand(0);
02691     if (N0.getOpcode() == ISD::XOR) {
02692       N00 = N0.getOperand(0);
02693       N01 = N0.getOperand(1);
02694 
02695       // Pattern: (xor:i32 (xor:i32 IntRegs:i32:$b, IntRegs:i32:$c), (imm:i32)<<P:Predicate_immAllOnes>>)
02696       // Emits: (XNORrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02697       // Pattern complexity = 7  cost = 1  size = 0
02698       {
02699         N1 = N.getOperand(1);
02700         if (N1.getOpcode() == ISD::Constant &&
02701             Predicate_immAllOnes(N1.Val)) {
02702           Emit_37(Result, N, SP::XNORrr, MVT::i32, N0, N00, N01, N1);
02703           return;
02704         }
02705       }
02706 
02707       // Pattern: (xor:i32 (xor:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_immAllOnes>>), IntRegs:i32:$c)
02708       // Emits: (XNORrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02709       // Pattern complexity = 7  cost = 1
02710       if (N01.getOpcode() == ISD::Constant &&
02711           Predicate_immAllOnes(N01.Val)) {
02712         Emit_38(Result, N, SP::XNORrr, MVT::i32, N0, N00, N01, N1);
02713         return;
02714       }
02715     }
02716     N1 = N.getOperand(1);
02717 
02718     // Pattern: (xor:i32 IntRegs:i32:$c, (xor:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_immAllOnes>>))
02719     // Emits: (XNORrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02720     // Pattern complexity = 7  cost = 1  size = 0
02721     if (N1.getOpcode() == ISD::XOR) {
02722       N10 = N1.getOperand(0);
02723       N11 = N1.getOperand(1);
02724       if (N11.getOpcode() == ISD::Constant &&
02725           Predicate_immAllOnes(N11.Val)) {
02726         Emit_39(Result, N, SP::XNORrr, MVT::i32, N0, N1, N10, N11);
02727         return;
02728       }
02729     }
02730 
02731     // Pattern: (xor:i32 IntRegs:i32:$b, (imm:i32)<<P:Predicate_simm13>>:$c)
02732     // Emits: (XORri:i32 IntRegs:i32:$b, (imm:i32):$c)
02733     // Pattern complexity = 5  cost = 1
02734     if (N1.getOpcode() == ISD::Constant &&
02735         Predicate_simm13(N1.Val)) {
02736       Emit_12(Result, N, SP::XORri, MVT::i32, N0, N1);
02737       return;
02738     }
02739   }
02740 
02741   // Pattern: (xor:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02742   // Emits: (XORrr:i32 IntRegs:i32:$b, IntRegs:i32:$c)
02743   // Pattern complexity = 2  cost = 1
02744   Emit_13(Result, N, SP::XORrr, MVT::i32, N0, N1);
02745   return;
02746 }
02747 
02748 void Select_zextld(SDOperand &Result, SDOperand N) {
02749   if (N.ResNo == 1 && N.getValue(0).hasOneUse()) {
02750     SDOperand Dummy = CurDAG->getNode(ISD::HANDLENODE, MVT::Other, N);
02751     SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Dummy.Val, 0);
02752     SelectionDAG::InsertISelMapEntry(HandleMap, N.Val, 1, Dummy.Val, 0);
02753     Result = Dummy;
02754     return;
02755   }
02756   SDOperand CPTmp0(0, 0);
02757   SDOperand CPTmp1(0, 0);
02758   SDOperand Chain(0, 0);
02759   SDOperand N1(0, 0);
02760   SDOperand N2(0, 0);
02761   SDOperand N3(0, 0);
02762   SDOperand Tmp0(0, 0);
02763   SDOperand Tmp1(0, 0);
02764   SDNode *ResNode = NULL;
02765   Chain = N.getOperand(0);
02766   N1 = N.getOperand(1);
02767   N2 = N.getOperand(2);
02768   N3 = N.getOperand(3);
02769   if (cast<VTSDNode>(N3)->getVT() == MVT::i8 &&
02770       N1.Val->getValueType(0) == MVT::i32) {
02771 
02772     // Pattern: (zextld:i32 ADDRrr:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02773     // Emits: (LDUBrr:i32 ADDRrr:i32:$addr)
02774     // Pattern complexity = 8  cost = 1  size = 0
02775     {
02776       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
02777       if (Match) {
02778         Emit_23(Result, N, SP::LDUBrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02779         return;
02780       }
02781     }
02782 
02783     // Pattern: (zextld:i32 ADDRri:i32:$addr, srcvalue:Other:$dummy, i8:Other)
02784     // Emits: (LDUBri:i32 ADDRri:i32:$addr)
02785     // Pattern complexity = 8  cost = 1
02786     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
02787     if (Match) {
02788       Emit_23(Result, N, SP::LDUBri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02789       return;
02790     }
02791   }
02792   if (cast<VTSDNode>(N3)->getVT() == MVT::i16 &&
02793       N1.Val->getValueType(0) == MVT::i32) {
02794 
02795     // Pattern: (zextld:i32 ADDRrr:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02796     // Emits: (LDUHrr:i32 ADDRrr:i32:$addr)
02797     // Pattern complexity = 8  cost = 1  size = 0
02798     {
02799       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
02800       if (Match) {
02801         Emit_23(Result, N, SP::LDUHrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02802         return;
02803       }
02804     }
02805 
02806     // Pattern: (zextld:i32 ADDRri:i32:$addr, srcvalue:Other:$dummy, i16:Other)
02807     // Emits: (LDUHri:i32 ADDRri:i32:$addr)
02808     // Pattern complexity = 8  cost = 1
02809     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
02810     if (Match) {
02811       Emit_23(Result, N, SP::LDUHri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02812       return;
02813     }
02814   }
02815   if (cast<VTSDNode>(N3)->getVT() == MVT::i1 &&
02816       N1.Val->getValueType(0) == MVT::i32) {
02817 
02818     // Pattern: (zextld:i32 ADDRrr:i32:$src, srcvalue:Other:$dummy, i1:Other)
02819     // Emits: (LDUBrr:i32 ADDRrr:i32:$src)
02820     // Pattern complexity = 8  cost = 1  size = 0
02821     {
02822       bool Match = SelectADDRrr(N1, CPTmp0, CPTmp1);
02823       if (Match) {
02824         Emit_23(Result, N, SP::LDUBrr, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02825         return;
02826       }
02827     }
02828 
02829     // Pattern: (zextld:i32 ADDRri:i32:$src, srcvalue:Other:$dummy, i1:Other)
02830     // Emits: (LDUBri:i32 ADDRri:i32:$src)
02831     // Pattern complexity = 8  cost = 1
02832     bool Match = SelectADDRri(N1, CPTmp0, CPTmp1);
02833     if (Match) {
02834       Emit_23(Result, N, SP::LDUBri, MVT::i32, CPTmp0, CPTmp1, Chain, N1, N2, N3);
02835       return;
02836     }
02837   }
02838   std::cerr << "Cannot yet select: ";
02839   N.Val->dump(CurDAG);
02840   std::cerr << '\n';
02841   abort();
02842 }
02843 
02844 void Select_INLINEASM(SDOperand& Result, SDOperand N) {
02845   std::vector<SDOperand> Ops(N.Val->op_begin(), N.Val->op_end());
02846   Select(Ops[0], N.getOperand(0)); // Select the chain.
02847 
02848   // Select the flag operand.
02849   if (Ops.back().getValueType() == MVT::Flag)
02850     Select(Ops.back(), Ops.back());
02851   SelectInlineAsmMemoryOperands(Ops, *CurDAG);
02852   std::vector<MVT::ValueType> VTs;
02853   VTs.push_back(MVT::Other);
02854   VTs.push_back(MVT::Flag);
02855   SDOperand New = CurDAG->getNode(ISD::INLINEASM, VTs, Ops);
02856   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, New.Val, 0);
02857   SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, New.Val, 1);
02858   Result = New.getValue(N.ResNo);
02859   return;
02860 }
02861 
02862 // The main instruction selector code.
02863 void SelectCode(SDOperand &Result, SDOperand N) {
02864   if (N.getOpcode() >= ISD::BUILTIN_OP_END &&
02865       N.getOpcode() < (ISD::BUILTIN_OP_END+SP::INSTRUCTION_LIST_END)) {
02866     Result = N;
02867     return;   // Already selected.
02868   }
02869 
02870   std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(N);
02871   if (CGMI != CodeGenMap.end()) {
02872     Result = CGMI->second;
02873     return;
02874   }
02875 
02876   switch (N.getOpcode()) {
02877   default: break;
02878   case ISD::EntryToken:       // These leaves remain the same.
02879   case ISD::BasicBlock:
02880   case ISD::Register:
02881   case ISD::HANDLENODE:
02882   case ISD::TargetConstant:
02883   case ISD::TargetConstantPool:
02884   case ISD::TargetFrameIndex:
02885   case ISD::TargetJumpTable:
02886   case ISD::TargetGlobalAddress: {
02887     Result = N;
02888     return;
02889   }
02890   case ISD::AssertSext:
02891   case ISD::AssertZext: {
02892     SDOperand Tmp0;
02893     Select(Tmp0, N.getOperand(0));
02894     if (!N.Val->hasOneUse())
02895       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, Tmp0.Val, Tmp0.ResNo);
02896     Result = Tmp0;
02897     return;
02898   }
02899   case ISD::TokenFactor:
02900     if (N.getNumOperands() == 2) {
02901       SDOperand Op0, Op1;
02902       Select(Op0, N.getOperand(0));
02903       Select(Op1, N.getOperand(1));
02904       Result = 
02905           CurDAG->getNode(ISD::TokenFactor, MVT::Other, Op0, Op1);
02906       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, Result.Val, Result.ResNo);
02907     } else {
02908       std::vector<SDOperand> Ops;
02909       for (unsigned i = 0, e = N.getNumOperands(); i != e; ++i) {
02910         SDOperand Val;
02911         Select(Val, N.getOperand(i));
02912         Ops.push_back(Val);
02913       }
02914       Result = 
02915           CurDAG->getNode(ISD::TokenFactor, MVT::Other, Ops);
02916       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, N.ResNo, Result.Val, Result.ResNo);
02917     }
02918     return;
02919   case ISD::CopyFromReg: {
02920     SDOperand Chain;
02921     Select(Chain, N.getOperand(0));
02922     unsigned Reg = cast<RegisterSDNode>(N.getOperand(1))->getReg();
02923     MVT::ValueType VT = N.Val->getValueType(0);
02924     if (N.Val->getNumValues() == 2) {
02925       if (Chain == N.getOperand(0)) {
02926         Result = N; // No change
02927         return;
02928       }
02929       SDOperand New = CurDAG->getCopyFromReg(Chain, Reg, VT);
02930       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, New.Val, 0);
02931       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, New.Val, 1);
02932       Result = New.getValue(N.ResNo);
02933       return;
02934     } else {
02935       SDOperand Flag;
02936       if (N.getNumOperands() == 3) Select(Flag, N.getOperand(2));
02937       if (Chain == N.getOperand(0) &&
02938           (N.getNumOperands() == 2 || Flag == N.getOperand(2))) {
02939         Result = N; // No change
02940         return;
02941       }
02942       SDOperand New = CurDAG->getCopyFromReg(Chain, Reg, VT, Flag);
02943       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, New.Val, 0);
02944       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, New.Val, 1);
02945       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 2, New.Val, 2);
02946       Result = New.getValue(N.ResNo);
02947       return;
02948     }
02949   }
02950   case ISD::CopyToReg: {
02951     SDOperand Chain;
02952     Select(Chain, N.getOperand(0));
02953     unsigned Reg = cast<RegisterSDNode>(N.getOperand(1))->getReg();
02954     SDOperand Val;
02955     Select(Val, N.getOperand(2));
02956     Result = N;
02957     if (N.Val->getNumValues() == 1) {
02958       if (Chain != N.getOperand(0) || Val != N.getOperand(2))
02959         Result = CurDAG->getCopyToReg(Chain, Reg, Val);
02960       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Result.Val, 0);
02961     } else {
02962       SDOperand Flag(0, 0);
02963       if (N.getNumOperands() == 4) Select(Flag, N.getOperand(3));
02964       if (Chain != N.getOperand(0) || Val != N.getOperand(2) ||
02965           (N.getNumOperands() == 4 && Flag != N.getOperand(3)))
02966         Result = CurDAG->getCopyToReg(Chain, Reg, Val, Flag);
02967       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 0, Result.Val, 0);
02968       SelectionDAG::InsertISelMapEntry(CodeGenMap, N.Val, 1, Result.Val, 1);
02969       Result = Result.getValue(N.ResNo);
02970     }
02971     return;
02972   }
02973   case ISD::INLINEASM:  Select_INLINEASM(Result, N); return;
02974   case SPISD::BRFCC:             Select_SPbrfcc(Result, N); return;
02975   case SPISD::BRICC:             Select_SPbricc(Result, N); return;
02976   case SPISD::CMPFCC:            Select_SPcmpfcc(Result, N); return;
02977   case SPISD::CMPICC:            Select_SPcmpicc(Result, N); return;
02978   case SPISD::FTOI:              Select_SPftoi(Result, N); return;
02979   case SPISD::Hi:                Select_SPhi(Result, N); return;
02980   case SPISD::ITOF:              Select_SPitof(Result, N); return;
02981   case SPISD::Lo:                Select_SPlo(Result, N); return;
02982   case SPISD::SELECT_FCC:        Select_SPselectfcc(Result, N); return;
02983   case SPISD::SELECT_ICC:        Select_SPselecticc(Result, N); return;
02984   case ISD::ADD:                 Select_add(Result, N); return;
02985   case ISD::ADDC:                Select_addc(Result, N); return;
02986   case ISD::ADDE:                Select_adde(Result, N); return;
02987   case ISD::AND:                 Select_and(Result, N); return;
02988   case ISD::BR:                  Select_br(Result, N); return;
02989   case SPISD::CALL:              Select_call(Result, N); return;
02990   case ISD::CALLSEQ_END:         Select_callseq_end(Result, N); return;
02991   case ISD::CALLSEQ_START:       Select_callseq_start(Result, N); return;
02992   case ISD::CTPOP:               Select_ctpop(Result, N); return;
02993   case ISD::EXTLOAD:             Select_extld(Result, N); return;
02994   case ISD::FABS:                Select_fabs(Result, N); return;
02995   case ISD::FADD:                Select_fadd(Result, N); return;
02996   case ISD::FDIV:                Select_fdiv(Result, N); return;
02997   case ISD::FP_EXTEND:           Select_fextend(Result, N); return;
02998   case ISD::FMUL:                Select_fmul(Result, N); return;
02999   case ISD::FNEG:                Select_fneg(Result, N); return;
03000   case ISD::FrameIndex:          Select_frameindex(Result, N); return;
03001   case ISD::FP_ROUND:            Select_fround(Result, N); return;
03002   case ISD::FSQRT:               Select_fsqrt(Result, N); return;
03003   case ISD::FSUB:                Select_fsub(Result, N); return;
03004   case ISD::Constant:            Select_imm(Result, N); return;
03005   case ISD::LOAD:                Select_load(Result, N); return;
03006   case ISD::MUL:                 Select_mul(Result, N); return;
03007   case ISD::OR:                  Select_or(Result, N); return;
03008   case ISD::RET:                 Select_ret(Result, N); return;
03009   case SPISD::RET_FLAG:          Select_retflag(Result, N); return;
03010   case ISD::SEXTLOAD:            Select_sextld(Result, N); return;
03011   case ISD::SHL:                 Select_shl(Result, N); return;
03012   case ISD::SRA:                 Select_sra(Result, N); return;
03013   case ISD::SRL:                 Select_srl(Result, N); return;
03014   case ISD::STORE:               Select_store(Result, N); return;
03015   case ISD::SUB:                 Select_sub(Result, N); return;
03016   case ISD::SUBC:                Select_subc(Result, N); return;
03017   case ISD::SUBE:                Select_sube(Result, N); return;
03018   case ISD::TRUNCSTORE:          Select_truncst(Result, N); return;
03019   case ISD::UNDEF:               Select_undef(Result, N); return;
03020   case ISD::XOR:                 Select_xor(Result, N); return;
03021   case ISD::ZEXTLOAD:            Select_zextld(Result, N); return;
03022   } // end of big switch.
03023 
03024   std::cerr << "Cannot yet select: ";
03025   if (N.getOpcode() != ISD::INTRINSIC_W_CHAIN &&
03026       N.getOpcode() != ISD::INTRINSIC_WO_CHAIN &&
03027       N.getOpcode() != ISD::INTRINSIC_VOID) {
03028     N.Val->dump(CurDAG);
03029   } else {
03030     unsigned iid = cast<ConstantSDNode>(N.getOperand(N.getOperand(0).getValueType() == MVT::Other))->getValue();
03031     std::cerr << "intrinsic %"<< Intrinsic::getName((Intrinsic::ID)iid);
03032   }
03033   std::cerr << '\n';
03034   abort();
03035 }