MipsISelDAGToDAG.cpp revision 69a0aa87f8d64895af082cb52c7ecee0f6021d20
1//===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the MIPS target.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "mips-isel"
15#include "Mips.h"
16#include "MipsAnalyzeImmediate.h"
17#include "MipsMachineFunction.h"
18#include "MipsRegisterInfo.h"
19#include "MipsSubtarget.h"
20#include "MipsTargetMachine.h"
21#include "MCTargetDesc/MipsBaseInfo.h"
22#include "llvm/GlobalValue.h"
23#include "llvm/Instructions.h"
24#include "llvm/Intrinsics.h"
25#include "llvm/Support/CFG.h"
26#include "llvm/Type.h"
27#include "llvm/CodeGen/MachineConstantPool.h"
28#include "llvm/CodeGen/MachineFunction.h"
29#include "llvm/CodeGen/MachineFrameInfo.h"
30#include "llvm/CodeGen/MachineInstrBuilder.h"
31#include "llvm/CodeGen/MachineRegisterInfo.h"
32#include "llvm/CodeGen/SelectionDAGISel.h"
33#include "llvm/CodeGen/SelectionDAGNodes.h"
34#include "llvm/Target/TargetMachine.h"
35#include "llvm/Support/Debug.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38using namespace llvm;
39
40//===----------------------------------------------------------------------===//
41// Instruction Selector Implementation
42//===----------------------------------------------------------------------===//
43
44//===----------------------------------------------------------------------===//
45// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
46// instructions for SelectionDAG operations.
47//===----------------------------------------------------------------------===//
48namespace {
49
50class MipsDAGToDAGISel : public SelectionDAGISel {
51
52  /// TM - Keep a reference to MipsTargetMachine.
53  MipsTargetMachine &TM;
54
55  /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
56  /// make the right decision when generating code for different targets.
57  const MipsSubtarget &Subtarget;
58
59public:
60  explicit MipsDAGToDAGISel(MipsTargetMachine &tm) :
61  SelectionDAGISel(tm),
62  TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {}
63
64  // Pass Name
65  virtual const char *getPassName() const {
66    return "MIPS DAG->DAG Pattern Instruction Selection";
67  }
68
69  virtual bool runOnMachineFunction(MachineFunction &MF);
70
71private:
72  // Include the pieces autogenerated from the target description.
73  #include "MipsGenDAGISel.inc"
74
75  /// getTargetMachine - Return a reference to the TargetMachine, casted
76  /// to the target-specific type.
77  const MipsTargetMachine &getTargetMachine() {
78    return static_cast<const MipsTargetMachine &>(TM);
79  }
80
81  /// getInstrInfo - Return a reference to the TargetInstrInfo, casted
82  /// to the target-specific type.
83  const MipsInstrInfo *getInstrInfo() {
84    return getTargetMachine().getInstrInfo();
85  }
86
87  SDNode *getGlobalBaseReg();
88
89  std::pair<SDNode*, SDNode*> SelectMULT(SDNode *N, unsigned Opc, DebugLoc dl,
90                                         EVT Ty, bool HasLo, bool HasHi);
91
92  SDNode *Select(SDNode *N);
93
94  // Complex Pattern.
95  bool SelectAddr(SDNode *Parent, SDValue N, SDValue &Base, SDValue &Offset);
96
97  // getImm - Return a target constant with the specified value.
98  inline SDValue getImm(const SDNode *Node, unsigned Imm) {
99    return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
100  }
101
102  void ProcessFunctionAfterISel(MachineFunction &MF);
103  bool ReplaceUsesWithZeroReg(MachineRegisterInfo *MRI, const MachineInstr&);
104  void InitGlobalBaseReg(MachineFunction &MF);
105
106  virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
107                                            char ConstraintCode,
108                                            std::vector<SDValue> &OutOps);
109};
110
111}
112
113// Insert instructions to initialize the global base register in the
114// first MBB of the function. When the ABI is O32 and the relocation model is
115// PIC, the necessary instructions are emitted later to prevent optimization
116// passes from moving them.
117void MipsDAGToDAGISel::InitGlobalBaseReg(MachineFunction &MF) {
118  MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
119
120  if (!MipsFI->globalBaseRegSet())
121    return;
122
123  MachineBasicBlock &MBB = MF.front();
124  MachineBasicBlock::iterator I = MBB.begin();
125  MachineRegisterInfo &RegInfo = MF.getRegInfo();
126  const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
127  DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
128  unsigned V0, V1, V2, GlobalBaseReg = MipsFI->getGlobalBaseReg();
129  const TargetRegisterClass *RC;
130
131  if (Subtarget.isABI_N64())
132    RC = (const TargetRegisterClass*)&Mips::CPU64RegsRegClass;
133  else if (Subtarget.inMips16Mode())
134    RC = (const TargetRegisterClass*)&Mips::CPU16RegsRegClass;
135  else
136    RC = (const TargetRegisterClass*)&Mips::CPURegsRegClass;
137
138  V0 = RegInfo.createVirtualRegister(RC);
139  V1 = RegInfo.createVirtualRegister(RC);
140  V2 = RegInfo.createVirtualRegister(RC);
141
142  if (Subtarget.isABI_N64()) {
143    MF.getRegInfo().addLiveIn(Mips::T9_64);
144    MBB.addLiveIn(Mips::T9_64);
145
146    // lui $v0, %hi(%neg(%gp_rel(fname)))
147    // daddu $v1, $v0, $t9
148    // daddiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
149    const GlobalValue *FName = MF.getFunction();
150    BuildMI(MBB, I, DL, TII.get(Mips::LUi64), V0)
151      .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI);
152    BuildMI(MBB, I, DL, TII.get(Mips::DADDu), V1).addReg(V0)
153      .addReg(Mips::T9_64);
154    BuildMI(MBB, I, DL, TII.get(Mips::DADDiu), GlobalBaseReg).addReg(V1)
155      .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO);
156    return;
157  }
158
159  if (Subtarget.inMips16Mode()) {
160    BuildMI(MBB, I, DL, TII.get(Mips::LiRxImmX16), V0)
161      .addExternalSymbol("_gp_disp", MipsII::MO_ABS_HI);
162    BuildMI(MBB, I, DL, TII.get(Mips::AddiuRxPcImmX16), V1)
163      .addExternalSymbol("_gp_disp", MipsII::MO_ABS_LO);
164    BuildMI(MBB, I, DL, TII.get(Mips::SllX16), V2).addReg(V0).addImm(16);
165    BuildMI(MBB, I, DL, TII.get(Mips::AdduRxRyRz16), GlobalBaseReg)
166      .addReg(V1).addReg(V2);
167    return;
168  }
169
170  if (MF.getTarget().getRelocationModel() == Reloc::Static) {
171    // Set global register to __gnu_local_gp.
172    //
173    // lui   $v0, %hi(__gnu_local_gp)
174    // addiu $globalbasereg, $v0, %lo(__gnu_local_gp)
175    BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
176      .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_HI);
177    BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V0)
178      .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_LO);
179    return;
180  }
181
182  MF.getRegInfo().addLiveIn(Mips::T9);
183  MBB.addLiveIn(Mips::T9);
184
185  if (Subtarget.isABI_N32()) {
186    // lui $v0, %hi(%neg(%gp_rel(fname)))
187    // addu $v1, $v0, $t9
188    // addiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
189    const GlobalValue *FName = MF.getFunction();
190    BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
191      .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI);
192    BuildMI(MBB, I, DL, TII.get(Mips::ADDu), V1).addReg(V0).addReg(Mips::T9);
193    BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V1)
194      .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO);
195    return;
196  }
197
198  assert(Subtarget.isABI_O32());
199
200  // For O32 ABI, the following instruction sequence is emitted to initialize
201  // the global base register:
202  //
203  //  0. lui   $2, %hi(_gp_disp)
204  //  1. addiu $2, $2, %lo(_gp_disp)
205  //  2. addu  $globalbasereg, $2, $t9
206  //
207  // We emit only the last instruction here.
208  //
209  // GNU linker requires that the first two instructions appear at the beginning
210  // of a function and no instructions be inserted before or between them.
211  // The two instructions are emitted during lowering to MC layer in order to
212  // avoid any reordering.
213  //
214  // Register $2 (Mips::V0) is added to the list of live-in registers to ensure
215  // the value instruction 1 (addiu) defines is valid when instruction 2 (addu)
216  // reads it.
217  MF.getRegInfo().addLiveIn(Mips::V0);
218  MBB.addLiveIn(Mips::V0);
219  BuildMI(MBB, I, DL, TII.get(Mips::ADDu), GlobalBaseReg)
220    .addReg(Mips::V0).addReg(Mips::T9);
221}
222
223bool MipsDAGToDAGISel::ReplaceUsesWithZeroReg(MachineRegisterInfo *MRI,
224                                              const MachineInstr& MI) {
225  unsigned DstReg = 0, ZeroReg = 0;
226
227  // Check if MI is "addiu $dst, $zero, 0" or "daddiu $dst, $zero, 0".
228  if ((MI.getOpcode() == Mips::ADDiu) &&
229      (MI.getOperand(1).getReg() == Mips::ZERO) &&
230      (MI.getOperand(2).getImm() == 0)) {
231    DstReg = MI.getOperand(0).getReg();
232    ZeroReg = Mips::ZERO;
233  } else if ((MI.getOpcode() == Mips::DADDiu) &&
234             (MI.getOperand(1).getReg() == Mips::ZERO_64) &&
235             (MI.getOperand(2).getImm() == 0)) {
236    DstReg = MI.getOperand(0).getReg();
237    ZeroReg = Mips::ZERO_64;
238  }
239
240  if (!DstReg)
241    return false;
242
243  // Replace uses with ZeroReg.
244  for (MachineRegisterInfo::use_iterator U = MRI->use_begin(DstReg),
245       E = MRI->use_end(); U != E;) {
246    MachineOperand &MO = U.getOperand();
247    unsigned OpNo = U.getOperandNo();
248    MachineInstr *MI = MO.getParent();
249    ++U;
250
251    // Do not replace if it is a phi's operand or is tied to def operand.
252    if (MI->isPHI() || MI->isRegTiedToDefOperand(OpNo) || MI->isPseudo())
253      continue;
254
255    MO.setReg(ZeroReg);
256  }
257
258  return true;
259}
260
261void MipsDAGToDAGISel::ProcessFunctionAfterISel(MachineFunction &MF) {
262  InitGlobalBaseReg(MF);
263
264  MachineRegisterInfo *MRI = &MF.getRegInfo();
265
266  for (MachineFunction::iterator MFI = MF.begin(), MFE = MF.end(); MFI != MFE;
267       ++MFI)
268    for (MachineBasicBlock::iterator I = MFI->begin(); I != MFI->end(); ++I)
269      ReplaceUsesWithZeroReg(MRI, *I);
270}
271
272bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
273  bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
274
275  ProcessFunctionAfterISel(MF);
276
277  return Ret;
278}
279
280/// getGlobalBaseReg - Output the instructions required to put the
281/// GOT address into a register.
282SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
283  unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
284  return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
285}
286
287/// ComplexPattern used on MipsInstrInfo
288/// Used on Mips Load/Store instructions
289bool MipsDAGToDAGISel::
290SelectAddr(SDNode *Parent, SDValue Addr, SDValue &Base, SDValue &Offset) {
291  EVT ValTy = Addr.getValueType();
292
293  // if Address is FI, get the TargetFrameIndex.
294  if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
295    Base   = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
296    Offset = CurDAG->getTargetConstant(0, ValTy);
297    return true;
298  }
299
300  // on PIC code Load GA
301  if (Addr.getOpcode() == MipsISD::Wrapper) {
302    Base   = Addr.getOperand(0);
303    Offset = Addr.getOperand(1);
304    return true;
305  }
306
307  if (TM.getRelocationModel() != Reloc::PIC_) {
308    if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
309        Addr.getOpcode() == ISD::TargetGlobalAddress))
310      return false;
311  }
312
313  // Addresses of the form FI+const or FI|const
314  if (CurDAG->isBaseWithConstantOffset(Addr)) {
315    ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
316    if (isInt<16>(CN->getSExtValue())) {
317
318      // If the first operand is a FI, get the TargetFI Node
319      if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
320                                  (Addr.getOperand(0)))
321        Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
322      else
323        Base = Addr.getOperand(0);
324
325      Offset = CurDAG->getTargetConstant(CN->getZExtValue(), ValTy);
326      return true;
327    }
328  }
329
330  // Operand is a result from an ADD.
331  if (Addr.getOpcode() == ISD::ADD) {
332    // When loading from constant pools, load the lower address part in
333    // the instruction itself. Example, instead of:
334    //  lui $2, %hi($CPI1_0)
335    //  addiu $2, $2, %lo($CPI1_0)
336    //  lwc1 $f0, 0($2)
337    // Generate:
338    //  lui $2, %hi($CPI1_0)
339    //  lwc1 $f0, %lo($CPI1_0)($2)
340    if (Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
341      SDValue LoVal = Addr.getOperand(1), Opnd0 = LoVal.getOperand(0);
342      if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) ||
343          isa<JumpTableSDNode>(Opnd0)) {
344        Base = Addr.getOperand(0);
345        Offset = Opnd0;
346        return true;
347      }
348    }
349
350    // If an indexed floating point load/store can be emitted, return false.
351    const LSBaseSDNode *LS = dyn_cast<LSBaseSDNode>(Parent);
352
353    if (LS &&
354        (LS->getMemoryVT() == MVT::f32 || LS->getMemoryVT() == MVT::f64) &&
355        Subtarget.hasMips32r2Or64())
356      return false;
357  }
358
359  Base   = Addr;
360  Offset = CurDAG->getTargetConstant(0, ValTy);
361  return true;
362}
363
364/// Select multiply instructions.
365std::pair<SDNode*, SDNode*>
366MipsDAGToDAGISel::SelectMULT(SDNode *N, unsigned Opc, DebugLoc dl, EVT Ty,
367                             bool HasLo, bool HasHi) {
368  SDNode *Lo = 0, *Hi = 0;
369  SDNode *Mul = CurDAG->getMachineNode(Opc, dl, MVT::Glue, N->getOperand(0),
370                                       N->getOperand(1));
371  SDValue InFlag = SDValue(Mul, 0);
372
373  if (HasLo) {
374    Lo = CurDAG->getMachineNode(Ty == MVT::i32 ? Mips::MFLO : Mips::MFLO64, dl,
375                                Ty, MVT::Glue, InFlag);
376    InFlag = SDValue(Lo, 1);
377  }
378  if (HasHi)
379    Hi = CurDAG->getMachineNode(Ty == MVT::i32 ? Mips::MFHI : Mips::MFHI64, dl,
380                                Ty, InFlag);
381
382  return std::make_pair(Lo, Hi);
383}
384
385
386/// Select instructions not customized! Used for
387/// expanded, promoted and normal instructions
388SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
389  unsigned Opcode = Node->getOpcode();
390  DebugLoc dl = Node->getDebugLoc();
391
392  // Dump information about the Node being selected
393  DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
394
395  // If we have a custom node, we already have selected!
396  if (Node->isMachineOpcode()) {
397    DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
398    return NULL;
399  }
400
401  ///
402  // Instruction Selection not handled by the auto-generated
403  // tablegen selection should be handled here.
404  ///
405  EVT NodeTy = Node->getValueType(0);
406  unsigned MultOpc;
407
408  switch(Opcode) {
409  default: break;
410
411  case ISD::SUBE:
412  case ISD::ADDE: {
413    SDValue InFlag = Node->getOperand(2), CmpLHS;
414    unsigned Opc = InFlag.getOpcode(); (void)Opc;
415    assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
416            (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
417           "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
418
419    unsigned MOp;
420    if (Opcode == ISD::ADDE) {
421      CmpLHS = InFlag.getValue(0);
422      MOp = Mips::ADDu;
423    } else {
424      CmpLHS = InFlag.getOperand(0);
425      MOp = Mips::SUBu;
426    }
427
428    SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
429
430    SDValue LHS = Node->getOperand(0);
431    SDValue RHS = Node->getOperand(1);
432
433    EVT VT = LHS.getValueType();
434    SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
435    SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
436                                              SDValue(Carry,0), RHS);
437
438    return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue,
439                                LHS, SDValue(AddCarry,0));
440  }
441
442  /// Mul with two results
443  case ISD::SMUL_LOHI:
444  case ISD::UMUL_LOHI: {
445    if (NodeTy == MVT::i32)
446      MultOpc = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
447    else
448      MultOpc = (Opcode == ISD::UMUL_LOHI ? Mips::DMULTu : Mips::DMULT);
449
450    std::pair<SDNode*, SDNode*> LoHi = SelectMULT(Node, MultOpc, dl, NodeTy,
451                                                  true, true);
452
453    if (!SDValue(Node, 0).use_empty())
454      ReplaceUses(SDValue(Node, 0), SDValue(LoHi.first, 0));
455
456    if (!SDValue(Node, 1).use_empty())
457      ReplaceUses(SDValue(Node, 1), SDValue(LoHi.second, 0));
458
459    return NULL;
460  }
461
462  /// Special Muls
463  case ISD::MUL: {
464    // Mips32 has a 32-bit three operand mul instruction.
465    if (Subtarget.hasMips32() && NodeTy == MVT::i32)
466      break;
467    return SelectMULT(Node, NodeTy == MVT::i32 ? Mips::MULT : Mips::DMULT,
468                      dl, NodeTy, true, false).first;
469  }
470  case ISD::MULHS:
471  case ISD::MULHU: {
472    if (NodeTy == MVT::i32)
473      MultOpc = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT);
474    else
475      MultOpc = (Opcode == ISD::MULHU ? Mips::DMULTu : Mips::DMULT);
476
477    return SelectMULT(Node, MultOpc, dl, NodeTy, false, true).second;
478  }
479
480  // Get target GOT address.
481  case ISD::GLOBAL_OFFSET_TABLE:
482    return getGlobalBaseReg();
483
484  case ISD::ConstantFP: {
485    ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
486    if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
487      if (Subtarget.hasMips64()) {
488        SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
489                                              Mips::ZERO_64, MVT::i64);
490        return CurDAG->getMachineNode(Mips::DMTC1, dl, MVT::f64, Zero);
491      }
492
493      SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
494                                            Mips::ZERO, MVT::i32);
495      return CurDAG->getMachineNode(Mips::BuildPairF64, dl, MVT::f64, Zero,
496                                    Zero);
497    }
498    break;
499  }
500
501  case ISD::Constant: {
502    const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Node);
503    unsigned Size = CN->getValueSizeInBits(0);
504
505    if (Size == 32)
506      break;
507
508    MipsAnalyzeImmediate AnalyzeImm;
509    int64_t Imm = CN->getSExtValue();
510
511    const MipsAnalyzeImmediate::InstSeq &Seq =
512      AnalyzeImm.Analyze(Imm, Size, false);
513
514    MipsAnalyzeImmediate::InstSeq::const_iterator Inst = Seq.begin();
515    DebugLoc DL = CN->getDebugLoc();
516    SDNode *RegOpnd;
517    SDValue ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd),
518                                                MVT::i64);
519
520    // The first instruction can be a LUi which is different from other
521    // instructions (ADDiu, ORI and SLL) in that it does not have a register
522    // operand.
523    if (Inst->Opc == Mips::LUi64)
524      RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64, ImmOpnd);
525    else
526      RegOpnd =
527        CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64,
528                               CurDAG->getRegister(Mips::ZERO_64, MVT::i64),
529                               ImmOpnd);
530
531    // The remaining instructions in the sequence are handled here.
532    for (++Inst; Inst != Seq.end(); ++Inst) {
533      ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd),
534                                          MVT::i64);
535      RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64,
536                                       SDValue(RegOpnd, 0), ImmOpnd);
537    }
538
539    return RegOpnd;
540  }
541
542  case MipsISD::ThreadPointer: {
543    EVT PtrVT = TLI.getPointerTy();
544    unsigned RdhwrOpc, SrcReg, DestReg;
545
546    if (PtrVT == MVT::i32) {
547      RdhwrOpc = Mips::RDHWR;
548      SrcReg = Mips::HWR29;
549      DestReg = Mips::V1;
550    } else {
551      RdhwrOpc = Mips::RDHWR64;
552      SrcReg = Mips::HWR29_64;
553      DestReg = Mips::V1_64;
554    }
555
556    SDNode *Rdhwr =
557      CurDAG->getMachineNode(RdhwrOpc, Node->getDebugLoc(),
558                             Node->getValueType(0),
559                             CurDAG->getRegister(SrcReg, PtrVT));
560    SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, DestReg,
561                                         SDValue(Rdhwr, 0));
562    SDValue ResNode = CurDAG->getCopyFromReg(Chain, dl, DestReg, PtrVT);
563    ReplaceUses(SDValue(Node, 0), ResNode);
564    return ResNode.getNode();
565  }
566  }
567
568  // Select the default instruction
569  SDNode *ResNode = SelectCode(Node);
570
571  DEBUG(errs() << "=> ");
572  if (ResNode == NULL || ResNode == Node)
573    DEBUG(Node->dump(CurDAG));
574  else
575    DEBUG(ResNode->dump(CurDAG));
576  DEBUG(errs() << "\n");
577  return ResNode;
578}
579
580bool MipsDAGToDAGISel::
581SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
582                             std::vector<SDValue> &OutOps) {
583  assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
584  OutOps.push_back(Op);
585  return false;
586}
587
588/// createMipsISelDag - This pass converts a legalized DAG into a
589/// MIPS-specific DAG, ready for instruction scheduling.
590FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
591  return new MipsDAGToDAGISel(TM);
592}
593