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