blob: 0194ed589121a495466e8318a7c435e200f6318d [file] [log] [blame]
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001//===-- MipsISelDAGToDAG.cpp - A dag to dag inst selector for Mips --------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009//
10// This file defines an instruction selector for the MIPS target.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
14#define DEBUG_TYPE "mips-isel"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015#include "Mips.h"
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000016#include "MipsMachineFunction.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000017#include "MipsRegisterInfo.h"
18#include "MipsSubtarget.h"
19#include "MipsTargetMachine.h"
20#include "llvm/GlobalValue.h"
21#include "llvm/Instructions.h"
22#include "llvm/Intrinsics.h"
23#include "llvm/Support/CFG.h"
24#include "llvm/Type.h"
25#include "llvm/CodeGen/MachineConstantPool.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineFrameInfo.h"
28#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000029#include "llvm/CodeGen/MachineRegisterInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000030#include "llvm/CodeGen/SelectionDAGISel.h"
31#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035using namespace llvm;
36
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000037//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000038// Instruction Selector Implementation
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000039//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000040
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000041//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000042// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
43// instructions for SelectionDAG operations.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000044//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000045namespace {
46
Nick Lewycky6726b6d2009-10-25 06:33:48 +000047class MipsDAGToDAGISel : public SelectionDAGISel {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000048
49 /// TM - Keep a reference to MipsTargetMachine.
50 MipsTargetMachine &TM;
51
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052 /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
53 /// make the right decision when generating code for different targets.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000054 const MipsSubtarget &Subtarget;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000055
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000056public:
Dan Gohman1002c022008-07-07 18:00:37 +000057 explicit MipsDAGToDAGISel(MipsTargetMachine &tm) :
Dan Gohman79ce2762009-01-15 19:20:50 +000058 SelectionDAGISel(tm),
Dan Gohmanda8ac5f2008-10-03 16:55:19 +000059 TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {}
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000060
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000061 // Pass Name
62 virtual const char *getPassName() const {
63 return "MIPS DAG->DAG Pattern Instruction Selection";
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000064 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000065
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000066
67private:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000068 // Include the pieces autogenerated from the target description.
69 #include "MipsGenDAGISel.inc"
70
Dan Gohman99114052009-06-03 20:30:14 +000071 /// getTargetMachine - Return a reference to the TargetMachine, casted
72 /// to the target-specific type.
73 const MipsTargetMachine &getTargetMachine() {
74 return static_cast<const MipsTargetMachine &>(TM);
75 }
76
77 /// getInstrInfo - Return a reference to the TargetInstrInfo, casted
78 /// to the target-specific type.
79 const MipsInstrInfo *getInstrInfo() {
80 return getTargetMachine().getInstrInfo();
81 }
82
83 SDNode *getGlobalBaseReg();
Akira Hatanaka2fd04752011-12-20 23:10:57 +000084
85 std::pair<SDNode*, SDNode*> SelectMULT(SDNode *N, unsigned Opc, DebugLoc dl,
86 EVT Ty, bool HasLo, bool HasHi);
87
Dan Gohmaneeb3a002010-01-05 01:24:18 +000088 SDNode *Select(SDNode *N);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089
90 // Complex Pattern.
Chris Lattner52a261b2010-09-21 20:31:19 +000091 bool SelectAddr(SDValue N, SDValue &Base, SDValue &Offset);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092
Akira Hatanakabd150902011-12-07 20:15:01 +000093 // getImm - Return a target constant with the specified value.
Akira Hatanaka4d0eb632011-12-07 20:10:24 +000094 inline SDValue getImm(const SDNode *Node, unsigned Imm) {
95 return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000096 }
Akira Hatanaka21afc632011-06-21 00:40:49 +000097
98 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
99 char ConstraintCode,
100 std::vector<SDValue> &OutOps);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000101};
102
103}
104
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000105
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000106/// getGlobalBaseReg - Output the instructions required to put the
107/// GOT address into a register.
Dan Gohman99114052009-06-03 20:30:14 +0000108SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Dan Gohman99114052009-06-03 20:30:14 +0000109 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
110 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000111}
112
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000113/// ComplexPattern used on MipsInstrInfo
114/// Used on Mips Load/Store instructions
115bool MipsDAGToDAGISel::
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000116SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000117 EVT ValTy = Addr.getValueType();
118 unsigned GPReg = ValTy == MVT::i32 ? Mips::GP : Mips::GP_64;
119
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000120 // if Address is FI, get the TargetFrameIndex.
121 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000122 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
123 Offset = CurDAG->getTargetConstant(0, ValTy);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124 return true;
125 }
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000126
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000127 // on PIC code Load GA
Akira Hatanaka6df7e232011-12-09 01:53:17 +0000128 if (Addr.getOpcode() == MipsISD::Wrapper) {
Akira Hatanakaca074792011-12-08 20:34:32 +0000129 Base = CurDAG->getRegister(GPReg, ValTy);
130 Offset = Addr.getOperand(0);
131 return true;
132 }
133
134 if (TM.getRelocationModel() != Reloc::PIC_) {
Bill Wendling056292f2008-09-16 21:48:12 +0000135 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000136 Addr.getOpcode() == ISD::TargetGlobalAddress))
137 return false;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000138 }
139
Akira Hatanaka5e069032011-06-02 01:03:14 +0000140 // Addresses of the form FI+const or FI|const
141 if (CurDAG->isBaseWithConstantOffset(Addr)) {
142 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
143 if (isInt<16>(CN->getSExtValue())) {
144
145 // If the first operand is a FI, get the TargetFI Node
146 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
147 (Addr.getOperand(0)))
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000148 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
Akira Hatanaka5e069032011-06-02 01:03:14 +0000149 else
150 Base = Addr.getOperand(0);
151
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000152 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), ValTy);
Akira Hatanaka5e069032011-06-02 01:03:14 +0000153 return true;
154 }
155 }
156
Bruno Cardoso Lopes7ff6fa22007-08-18 02:16:30 +0000157 // Operand is a result from an ADD.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000158 if (Addr.getOpcode() == ISD::ADD) {
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000159 // When loading from constant pools, load the lower address part in
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000160 // the instruction itself. Example, instead of:
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000161 // lui $2, %hi($CPI1_0)
162 // addiu $2, $2, %lo($CPI1_0)
163 // lwc1 $f0, 0($2)
164 // Generate:
165 // lui $2, %hi($CPI1_0)
166 // lwc1 $f0, %lo($CPI1_0)($2)
Akira Hatanaka89dc8d72011-12-19 19:28:37 +0000167 if (Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000168 SDValue LoVal = Addr.getOperand(1);
Akira Hatanaka8b2b7132011-06-24 17:55:19 +0000169 if (isa<ConstantPoolSDNode>(LoVal.getOperand(0)) ||
170 isa<GlobalAddressSDNode>(LoVal.getOperand(0))) {
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000171 Base = Addr.getOperand(0);
172 Offset = LoVal.getOperand(0);
173 return true;
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000174 }
175 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176 }
177
Bruno Cardoso Lopesa4e82002007-07-11 23:24:41 +0000178 Base = Addr;
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000179 Offset = CurDAG->getTargetConstant(0, ValTy);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000180 return true;
181}
182
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000183/// Select multiply instructions.
184std::pair<SDNode*, SDNode*>
185MipsDAGToDAGISel::SelectMULT(SDNode *N, unsigned Opc, DebugLoc dl, EVT Ty,
186 bool HasLo, bool HasHi) {
Chad Rosiera32a08c2012-01-06 20:02:49 +0000187 SDNode *Lo = 0, *Hi = 0;
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000188 SDNode *Mul = CurDAG->getMachineNode(Opc, dl, MVT::Glue, N->getOperand(0),
189 N->getOperand(1));
190 SDValue InFlag = SDValue(Mul, 0);
191
192 if (HasLo) {
193 Lo = CurDAG->getMachineNode(Ty == MVT::i32 ? Mips::MFLO : Mips::MFLO64, dl,
194 Ty, MVT::Glue, InFlag);
195 InFlag = SDValue(Lo, 1);
196 }
197 if (HasHi)
198 Hi = CurDAG->getMachineNode(Ty == MVT::i32 ? Mips::MFHI : Mips::MFHI64, dl,
199 Ty, InFlag);
200
201 return std::make_pair(Lo, Hi);
202}
203
204
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000205/// Select instructions not customized! Used for
206/// expanded, promoted and normal instructions
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000207SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000208 unsigned Opcode = Node->getOpcode();
Dale Johannesena05dca42009-02-04 23:02:30 +0000209 DebugLoc dl = Node->getDebugLoc();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210
211 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000212 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000213
214 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000215 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000216 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000217 return NULL;
218 }
219
220 ///
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000221 // Instruction Selection not handled by the auto-generated
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000222 // tablegen selection should be handled here.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000223 ///
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000224 EVT NodeTy = Node->getValueType(0);
225 unsigned MultOpc;
226
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000227 switch(Opcode) {
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000228 default: break;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000229
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000230 case ISD::SUBE:
231 case ISD::ADDE: {
232 SDValue InFlag = Node->getOperand(2), CmpLHS;
233 unsigned Opc = InFlag.getOpcode(); (void)Opc;
234 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
235 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
236 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000237
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000238 unsigned MOp;
239 if (Opcode == ISD::ADDE) {
240 CmpLHS = InFlag.getValue(0);
241 MOp = Mips::ADDu;
242 } else {
243 CmpLHS = InFlag.getOperand(0);
244 MOp = Mips::SUBu;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000245 }
246
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000247 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000248
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000249 SDValue LHS = Node->getOperand(0);
250 SDValue RHS = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000251
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000252 EVT VT = LHS.getValueType();
253 SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
254 SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
255 SDValue(Carry,0), RHS);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000256
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000257 return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue,
258 LHS, SDValue(AddCarry,0));
259 }
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000260
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000261 /// Mul with two results
262 case ISD::SMUL_LOHI:
263 case ISD::UMUL_LOHI: {
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000264 if (NodeTy == MVT::i32)
265 MultOpc = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
266 else
267 MultOpc = (Opcode == ISD::UMUL_LOHI ? Mips::DMULTu : Mips::DMULT);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000268
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000269 std::pair<SDNode*, SDNode*> LoHi = SelectMULT(Node, MultOpc, dl, NodeTy,
270 true, true);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000271
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000272 if (!SDValue(Node, 0).use_empty())
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000273 ReplaceUses(SDValue(Node, 0), SDValue(LoHi.first, 0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000274
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000275 if (!SDValue(Node, 1).use_empty())
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000276 ReplaceUses(SDValue(Node, 1), SDValue(LoHi.second, 0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000277
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000278 return NULL;
279 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000280
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000281 /// Special Muls
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000282 case ISD::MUL: {
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000283 // Mips32 has a 32-bit three operand mul instruction.
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000284 if (Subtarget.hasMips32() && NodeTy == MVT::i32)
Bruno Cardoso Lopesa8173b92009-11-13 18:49:59 +0000285 break;
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000286 return SelectMULT(Node, NodeTy == MVT::i32 ? Mips::MULT : Mips::DMULT,
287 dl, NodeTy, true, false).first;
288 }
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000289 case ISD::MULHS:
290 case ISD::MULHU: {
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000291 if (NodeTy == MVT::i32)
292 MultOpc = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT);
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000293 else
Akira Hatanaka2fd04752011-12-20 23:10:57 +0000294 MultOpc = (Opcode == ISD::MULHU ? Mips::DMULTu : Mips::DMULT);
295
296 return SelectMULT(Node, MultOpc, dl, NodeTy, false, true).second;
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000297 }
Bruno Cardoso Lopesa8173b92009-11-13 18:49:59 +0000298
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000299 // Get target GOT address.
300 case ISD::GLOBAL_OFFSET_TABLE:
301 return getGlobalBaseReg();
Akira Hatanakaca074792011-12-08 20:34:32 +0000302
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000303 case ISD::ConstantFP: {
304 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
305 if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
306 if (Subtarget.hasMips64()) {
307 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
308 Mips::ZERO_64, MVT::i64);
309 return CurDAG->getMachineNode(Mips::DMTC1, dl, MVT::f64, Zero);
Akira Hatanakaca074792011-12-08 20:34:32 +0000310 }
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000311
312 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
313 Mips::ZERO, MVT::i32);
314 return CurDAG->getMachineNode(Mips::BuildPairF64, dl, MVT::f64, Zero,
315 Zero);
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000316 }
Akira Hatanaka49d534b2011-12-20 22:58:01 +0000317 break;
318 }
319
320 case MipsISD::ThreadPointer: {
321 EVT PtrVT = TLI.getPointerTy();
322 unsigned RdhwrOpc, SrcReg, DestReg;
323
324 if (PtrVT == MVT::i32) {
325 RdhwrOpc = Mips::RDHWR;
326 SrcReg = Mips::HWR29;
327 DestReg = Mips::V1;
328 } else {
329 RdhwrOpc = Mips::RDHWR64;
330 SrcReg = Mips::HWR29_64;
331 DestReg = Mips::V1_64;
332 }
333
334 SDNode *Rdhwr =
335 CurDAG->getMachineNode(RdhwrOpc, Node->getDebugLoc(),
336 Node->getValueType(0),
337 CurDAG->getRegister(SrcReg, PtrVT));
338 SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, DestReg,
339 SDValue(Rdhwr, 0));
340 SDValue ResNode = CurDAG->getCopyFromReg(Chain, dl, DestReg, PtrVT);
341 ReplaceUses(SDValue(Node, 0), ResNode);
342 return ResNode.getNode();
343 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000344 }
345
346 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000347 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000348
Chris Lattner7c306da2010-03-02 06:34:30 +0000349 DEBUG(errs() << "=> ");
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000350 if (ResNode == NULL || ResNode == Node)
351 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000352 else
353 DEBUG(ResNode->dump(CurDAG));
Chris Lattner893e1c92009-08-23 06:49:22 +0000354 DEBUG(errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000355 return ResNode;
356}
357
Akira Hatanaka21afc632011-06-21 00:40:49 +0000358bool MipsDAGToDAGISel::
359SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
360 std::vector<SDValue> &OutOps) {
361 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
362 OutOps.push_back(Op);
363 return false;
364}
365
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000366/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000367/// MIPS-specific DAG, ready for instruction scheduling.
368FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
369 return new MipsDAGToDAGISel(TM);
370}