blob: 3face6e342a2edc836895afaf55c9c4a7bedf538 [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +00001//===-- MipsISelDAGToDAG.cpp - A dag to dag inst selector for Mips --------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// This file defines an instruction selector for the MIPS target.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
14#define DEBUG_TYPE "mips-isel"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000015#include "Mips.h"
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +000016#include "MipsMachineFunction.h"
Bruno Cardoso Lopes35e43c42007-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 Lattnera10fff52007-12-31 04:13:23 +000029#include "llvm/CodeGen/MachineRegisterInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000030#include "llvm/CodeGen/SelectionDAGISel.h"
31#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000032#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000035using namespace llvm;
36
Akira Hatanakae2489122011-04-15 21:51:11 +000037//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000038// Instruction Selector Implementation
Akira Hatanakae2489122011-04-15 21:51:11 +000039//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000040
Akira Hatanakae2489122011-04-15 21:51:11 +000041//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000042// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
43// instructions for SelectionDAG operations.
Akira Hatanakae2489122011-04-15 21:51:11 +000044//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000045namespace {
46
Nick Lewycky02d5f772009-10-25 06:33:48 +000047class MipsDAGToDAGISel : public SelectionDAGISel {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000048
49 /// TM - Keep a reference to MipsTargetMachine.
50 MipsTargetMachine &TM;
51
Bruno Cardoso Lopes35e43c42007-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 Lopesc9c3f492008-07-05 19:05:21 +000054 const MipsSubtarget &Subtarget;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000055
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000056public:
Dan Gohman56e3f632008-07-07 18:00:37 +000057 explicit MipsDAGToDAGISel(MipsTargetMachine &tm) :
Dan Gohman619ef482009-01-15 19:20:50 +000058 SelectionDAGISel(tm),
Dan Gohman2c836cf2008-10-03 16:55:19 +000059 TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {}
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000060
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000061 // Pass Name
62 virtual const char *getPassName() const {
63 return "MIPS DAG->DAG Pattern Instruction Selection";
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000064 }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000065
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000066
67private:
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000068 // Include the pieces autogenerated from the target description.
69 #include "MipsGenDAGISel.inc"
70
Dan Gohmand5ca70642009-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();
Dan Gohmanea6f91f2010-01-05 01:24:18 +000084 SDNode *Select(SDNode *N);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000085
86 // Complex Pattern.
Chris Lattner0e023ea2010-09-21 20:31:19 +000087 bool SelectAddr(SDValue N, SDValue &Base, SDValue &Offset);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000088
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000089 // getI32Imm - Return a target constant with the specified
90 // value, of type i32.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000091 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000092 return CurDAG->getTargetConstant(Imm, MVT::i32);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000093 }
Akira Hatanaka4c406e72011-06-21 00:40:49 +000094
95 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
96 char ConstraintCode,
97 std::vector<SDValue> &OutOps);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000098};
99
100}
101
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000102
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000103/// getGlobalBaseReg - Output the instructions required to put the
104/// GOT address into a register.
Dan Gohmand5ca70642009-06-03 20:30:14 +0000105SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Dan Gohmand5ca70642009-06-03 20:30:14 +0000106 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
107 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000108}
109
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000110/// ComplexPattern used on MipsInstrInfo
111/// Used on Mips Load/Store instructions
112bool MipsDAGToDAGISel::
Akira Hatanaka2e766ed2011-07-07 18:57:00 +0000113SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000114 // if Address is FI, get the TargetFrameIndex.
115 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Owen Anderson9f944592009-08-11 20:47:22 +0000116 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
117 Offset = CurDAG->getTargetConstant(0, MVT::i32);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000118 return true;
119 }
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000120
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000121 // on PIC code Load GA
122 if (TM.getRelocationModel() == Reloc::PIC_) {
Akira Hatanakab4068432011-05-28 01:07:07 +0000123 if (Addr.getOpcode() == MipsISD::WrapperPIC) {
Owen Anderson9f944592009-08-11 20:47:22 +0000124 Base = CurDAG->getRegister(Mips::GP, MVT::i32);
Akira Hatanakab4068432011-05-28 01:07:07 +0000125 Offset = Addr.getOperand(0);
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000126 return true;
127 }
128 } else {
Bill Wendling24c79f22008-09-16 21:48:12 +0000129 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000130 Addr.getOpcode() == ISD::TargetGlobalAddress))
131 return false;
Bruno Cardoso Lopesbf3c1252011-05-31 02:53:58 +0000132 else if (Addr.getOpcode() == ISD::TargetGlobalTLSAddress) {
133 Base = CurDAG->getRegister(Mips::GP, MVT::i32);
134 Offset = Addr;
135 return true;
136 }
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000137 }
138
Akira Hatanaka24468692011-06-02 01:03:14 +0000139 // Addresses of the form FI+const or FI|const
140 if (CurDAG->isBaseWithConstantOffset(Addr)) {
141 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
142 if (isInt<16>(CN->getSExtValue())) {
143
144 // If the first operand is a FI, get the TargetFI Node
145 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
146 (Addr.getOperand(0)))
147 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
148 else
149 Base = Addr.getOperand(0);
150
151 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
152 return true;
153 }
154 }
155
Bruno Cardoso Lopes4bd7f4d2007-08-18 02:16:30 +0000156 // Operand is a result from an ADD.
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000157 if (Addr.getOpcode() == ISD::ADD) {
Bruno Cardoso Lopes537e4092009-11-16 04:33:42 +0000158 // When loading from constant pools, load the lower address part in
Bruno Cardoso Lopes2db07582009-11-25 12:17:58 +0000159 // the instruction itself. Example, instead of:
Bruno Cardoso Lopes537e4092009-11-16 04:33:42 +0000160 // lui $2, %hi($CPI1_0)
161 // addiu $2, $2, %lo($CPI1_0)
162 // lwc1 $f0, 0($2)
163 // Generate:
164 // lui $2, %hi($CPI1_0)
165 // lwc1 $f0, %lo($CPI1_0)($2)
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000166 if ((Addr.getOperand(0).getOpcode() == MipsISD::Hi ||
Bruno Cardoso Lopes2db07582009-11-25 12:17:58 +0000167 Addr.getOperand(0).getOpcode() == ISD::LOAD) &&
Bruno Cardoso Lopes537e4092009-11-16 04:33:42 +0000168 Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000169 SDValue LoVal = Addr.getOperand(1);
Akira Hatanakaca88b4a2011-06-24 17:55:19 +0000170 if (isa<ConstantPoolSDNode>(LoVal.getOperand(0)) ||
171 isa<GlobalAddressSDNode>(LoVal.getOperand(0))) {
Bruno Cardoso Lopes2db07582009-11-25 12:17:58 +0000172 Base = Addr.getOperand(0);
173 Offset = LoVal.getOperand(0);
174 return true;
Bruno Cardoso Lopes537e4092009-11-16 04:33:42 +0000175 }
176 }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000177 }
178
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +0000179 Base = Addr;
Owen Anderson9f944592009-08-11 20:47:22 +0000180 Offset = CurDAG->getTargetConstant(0, MVT::i32);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000181 return true;
182}
183
184/// Select instructions not customized! Used for
185/// expanded, promoted and normal instructions
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000186SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000187 unsigned Opcode = Node->getOpcode();
Dale Johannesenf08a47b2009-02-04 23:02:30 +0000188 DebugLoc dl = Node->getDebugLoc();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000189
190 // Dump information about the Node being selected
Chris Lattnerf98f1242010-03-02 06:34:30 +0000191 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000192
193 // If we have a custom node, we already have selected!
Dan Gohman17059682008-07-17 19:10:17 +0000194 if (Node->isMachineOpcode()) {
Chris Lattnerf98f1242010-03-02 06:34:30 +0000195 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000196 return NULL;
197 }
198
199 ///
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000200 // Instruction Selection not handled by the auto-generated
Bruno Cardoso Lopes6d5ada22007-09-24 20:15:11 +0000201 // tablegen selection should be handled here.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000202 ///
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000203 switch(Opcode) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000204 default: break;
205
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000206 case ISD::SUBE:
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000207 case ISD::ADDE: {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000208 SDValue InFlag = Node->getOperand(2), CmpLHS;
Jeffrey Yasskin9b43f332010-12-23 00:58:24 +0000209 unsigned Opc = InFlag.getOpcode(); (void)Opc;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000210 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
211 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000212 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
213
Chris Lattnera66e9f42008-12-14 21:38:24 +0000214 unsigned MOp;
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000215 if (Opcode == ISD::ADDE) {
216 CmpLHS = InFlag.getValue(0);
217 MOp = Mips::ADDu;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000218 } else {
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000219 CmpLHS = InFlag.getOperand(0);
220 MOp = Mips::SUBu;
221 }
222
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000223 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000224
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000225 SDValue LHS = Node->getOperand(0);
226 SDValue RHS = Node->getOperand(1);
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000227
Owen Anderson53aa7a92009-08-10 22:56:29 +0000228 EVT VT = LHS.getValueType();
Dan Gohman32f71d72009-09-25 18:54:59 +0000229 SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000230 SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
Dan Gohman32f71d72009-09-25 18:54:59 +0000231 SDValue(Carry,0), RHS);
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000232
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000233 return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000234 LHS, SDValue(AddCarry,0));
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000235 }
236
Akira Hatanakae99b08d2011-06-07 19:03:14 +0000237 /// Mul with two results
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000238 case ISD::SMUL_LOHI:
239 case ISD::UMUL_LOHI: {
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000240 assert(Node->getValueType(0) != MVT::i64 &&
241 "64-bit multiplication with two results not handled.");
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000242 SDValue Op1 = Node->getOperand(0);
243 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000244
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000245 unsigned Op;
Bruno Cardoso Lopes434248a62011-03-04 21:03:24 +0000246 Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000247
Bruno Cardoso Lopes434248a62011-03-04 21:03:24 +0000248 SDNode *Mul = CurDAG->getMachineNode(Op, dl, MVT::Glue, Op1, Op2);
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000249
Bruno Cardoso Lopes434248a62011-03-04 21:03:24 +0000250 SDValue InFlag = SDValue(Mul, 0);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000251 SDNode *Lo = CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32,
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000252 MVT::Glue, InFlag);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000253 InFlag = SDValue(Lo,1);
Dan Gohman32f71d72009-09-25 18:54:59 +0000254 SDNode *Hi = CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000255
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000256 if (!SDValue(Node, 0).use_empty())
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000257 ReplaceUses(SDValue(Node, 0), SDValue(Lo,0));
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000258
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000259 if (!SDValue(Node, 1).use_empty())
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000260 ReplaceUses(SDValue(Node, 1), SDValue(Hi,0));
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000261
262 return NULL;
Bruno Cardoso Lopes4eed3af2008-06-06 00:58:26 +0000263 }
264
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000265 /// Special Muls
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000266 case ISD::MUL:
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000267 // Mips32 has a 32-bit three operand mul instruction.
268 if (Subtarget.hasMips32() && Node->getValueType(0) == MVT::i32)
Bruno Cardoso Lopes03c03302010-11-12 00:38:32 +0000269 break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000270 case ISD::MULHS:
271 case ISD::MULHU: {
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000272 assert((Opcode == ISD::MUL || Node->getValueType(0) != MVT::i64) &&
273 "64-bit MULH* not handled.");
274 EVT Ty = Node->getValueType(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000275 SDValue MulOp1 = Node->getOperand(0);
276 SDValue MulOp2 = Node->getOperand(1);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000277
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000278 unsigned MulOp = (Opcode == ISD::MULHU ?
279 Mips::MULTu :
280 (Ty == MVT::i32 ? Mips::MULT : Mips::DMULT));
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000281 SDNode *MulNode = CurDAG->getMachineNode(MulOp, dl,
Chris Lattner3e5fbd72010-12-21 02:38:05 +0000282 MVT::Glue, MulOp1, MulOp2);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000283
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000284 SDValue InFlag = SDValue(MulNode, 0);
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000285
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000286 if (Opcode == ISD::MUL) {
287 unsigned Opc = (Ty == MVT::i32 ? Mips::MFLO : Mips::MFLO64);
288 return CurDAG->getMachineNode(Opc, dl, Ty, InFlag);
289 }
Bruno Cardoso Lopes1a6e0d62008-06-06 06:37:31 +0000290 else
Dan Gohman32f71d72009-09-25 18:54:59 +0000291 return CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000292 }
293
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000294 // Get target GOT address.
Dan Gohmand5ca70642009-06-03 20:30:14 +0000295 case ISD::GLOBAL_OFFSET_TABLE:
296 return getGlobalBaseReg();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000297
Bruno Cardoso Lopesa03b5b42009-11-13 18:49:59 +0000298 case ISD::ConstantFP: {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000299 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000300 if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
301 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Bruno Cardoso Lopesc9818a72010-01-19 12:53:04 +0000302 Mips::ZERO, MVT::i32);
Akira Hatanaka7bd6e6e2011-08-12 18:09:59 +0000303 return CurDAG->getMachineNode(Mips::BuildPairF64, dl, MVT::f64, Zero,
304 Zero);
Bruno Cardoso Lopesa03b5b42009-11-13 18:49:59 +0000305 }
306 break;
307 }
308
Bruno Cardoso Lopesbf3c1252011-05-31 02:53:58 +0000309 case MipsISD::ThreadPointer: {
310 unsigned SrcReg = Mips::HWR29;
311 unsigned DestReg = Mips::V1;
312 SDNode *Rdhwr = CurDAG->getMachineNode(Mips::RDHWR, Node->getDebugLoc(),
313 Node->getValueType(0), CurDAG->getRegister(SrcReg, MVT::i32));
314 SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, DestReg,
315 SDValue(Rdhwr, 0));
316 SDValue ResNode = CurDAG->getCopyFromReg(Chain, dl, DestReg, MVT::i32);
317 ReplaceUses(SDValue(Node, 0), ResNode);
318 return ResNode.getNode();
319 }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000320 }
321
322 // Select the default instruction
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000323 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000324
Chris Lattnerf98f1242010-03-02 06:34:30 +0000325 DEBUG(errs() << "=> ");
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000326 if (ResNode == NULL || ResNode == Node)
327 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000328 else
329 DEBUG(ResNode->dump(CurDAG));
Chris Lattneraf29ea62009-08-23 06:49:22 +0000330 DEBUG(errs() << "\n");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000331 return ResNode;
332}
333
Akira Hatanaka4c406e72011-06-21 00:40:49 +0000334bool MipsDAGToDAGISel::
335SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
336 std::vector<SDValue> &OutOps) {
337 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
338 OutOps.push_back(Op);
339 return false;
340}
341
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000342/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000343/// MIPS-specific DAG, ready for instruction scheduling.
344FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
345 return new MipsDAGToDAGISel(TM);
346}