blob: b33a4e6c09b611706e586a590fc149b477bbb6c5 [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();
Dan Gohmaneeb3a002010-01-05 01:24:18 +000084 SDNode *Select(SDNode *N);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000085
86 // Complex Pattern.
Chris Lattner52a261b2010-09-21 20:31:19 +000087 bool SelectAddr(SDValue N, SDValue &Base, SDValue &Offset);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000088
Akira Hatanakabd150902011-12-07 20:15:01 +000089 // getImm - Return a target constant with the specified value.
Akira Hatanaka4d0eb632011-12-07 20:10:24 +000090 inline SDValue getImm(const SDNode *Node, unsigned Imm) {
91 return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092 }
Akira Hatanaka21afc632011-06-21 00:40:49 +000093
94 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
95 char ConstraintCode,
96 std::vector<SDValue> &OutOps);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000097};
98
99}
100
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000101
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000102/// getGlobalBaseReg - Output the instructions required to put the
103/// GOT address into a register.
Dan Gohman99114052009-06-03 20:30:14 +0000104SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Dan Gohman99114052009-06-03 20:30:14 +0000105 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
106 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000107}
108
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109/// ComplexPattern used on MipsInstrInfo
110/// Used on Mips Load/Store instructions
111bool MipsDAGToDAGISel::
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000112SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000113 EVT ValTy = Addr.getValueType();
114 unsigned GPReg = ValTy == MVT::i32 ? Mips::GP : Mips::GP_64;
115
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000116 // if Address is FI, get the TargetFrameIndex.
117 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000118 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
119 Offset = CurDAG->getTargetConstant(0, ValTy);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000120 return true;
121 }
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000122
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000123 // on PIC code Load GA
Akira Hatanaka6df7e232011-12-09 01:53:17 +0000124 if (Addr.getOpcode() == MipsISD::Wrapper) {
Akira Hatanakaca074792011-12-08 20:34:32 +0000125 Base = CurDAG->getRegister(GPReg, ValTy);
126 Offset = Addr.getOperand(0);
127 return true;
128 }
129
130 if (TM.getRelocationModel() != Reloc::PIC_) {
Bill Wendling056292f2008-09-16 21:48:12 +0000131 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000132 Addr.getOpcode() == ISD::TargetGlobalAddress))
133 return false;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000134 }
135
Akira Hatanaka5e069032011-06-02 01:03:14 +0000136 // Addresses of the form FI+const or FI|const
137 if (CurDAG->isBaseWithConstantOffset(Addr)) {
138 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
139 if (isInt<16>(CN->getSExtValue())) {
140
141 // If the first operand is a FI, get the TargetFI Node
142 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
143 (Addr.getOperand(0)))
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000144 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
Akira Hatanaka5e069032011-06-02 01:03:14 +0000145 else
146 Base = Addr.getOperand(0);
147
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000148 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), ValTy);
Akira Hatanaka5e069032011-06-02 01:03:14 +0000149 return true;
150 }
151 }
152
Bruno Cardoso Lopes7ff6fa22007-08-18 02:16:30 +0000153 // Operand is a result from an ADD.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000154 if (Addr.getOpcode() == ISD::ADD) {
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000155 // When loading from constant pools, load the lower address part in
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000156 // the instruction itself. Example, instead of:
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000157 // lui $2, %hi($CPI1_0)
158 // addiu $2, $2, %lo($CPI1_0)
159 // lwc1 $f0, 0($2)
160 // Generate:
161 // lui $2, %hi($CPI1_0)
162 // lwc1 $f0, %lo($CPI1_0)($2)
Akira Hatanaka89dc8d72011-12-19 19:28:37 +0000163 if (Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000164 SDValue LoVal = Addr.getOperand(1);
Akira Hatanaka8b2b7132011-06-24 17:55:19 +0000165 if (isa<ConstantPoolSDNode>(LoVal.getOperand(0)) ||
166 isa<GlobalAddressSDNode>(LoVal.getOperand(0))) {
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000167 Base = Addr.getOperand(0);
168 Offset = LoVal.getOperand(0);
169 return true;
Bruno Cardoso Lopes6e0b6582009-11-16 04:33:42 +0000170 }
171 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000172 }
173
Bruno Cardoso Lopesa4e82002007-07-11 23:24:41 +0000174 Base = Addr;
Akira Hatanaka381e97d2011-10-11 00:44:20 +0000175 Offset = CurDAG->getTargetConstant(0, ValTy);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176 return true;
177}
178
179/// Select instructions not customized! Used for
180/// expanded, promoted and normal instructions
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000181SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000182 unsigned Opcode = Node->getOpcode();
Dale Johannesena05dca42009-02-04 23:02:30 +0000183 DebugLoc dl = Node->getDebugLoc();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184
185 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000186 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000187
188 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000189 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000190 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191 return NULL;
192 }
193
194 ///
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000195 // Instruction Selection not handled by the auto-generated
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000196 // tablegen selection should be handled here.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000197 ///
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198 switch(Opcode) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199 default: break;
200
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000201 case ISD::SUBE:
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000202 case ISD::ADDE: {
Dan Gohman475871a2008-07-27 21:46:04 +0000203 SDValue InFlag = Node->getOperand(2), CmpLHS;
Jeffrey Yasskin8e68c382010-12-23 00:58:24 +0000204 unsigned Opc = InFlag.getOpcode(); (void)Opc;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000205 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
206 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000207 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
208
Chris Lattner30baa952008-12-14 21:38:24 +0000209 unsigned MOp;
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000210 if (Opcode == ISD::ADDE) {
211 CmpLHS = InFlag.getValue(0);
212 MOp = Mips::ADDu;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000213 } else {
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000214 CmpLHS = InFlag.getOperand(0);
215 MOp = Mips::SUBu;
216 }
217
Dan Gohman475871a2008-07-27 21:46:04 +0000218 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000219
Dan Gohman475871a2008-07-27 21:46:04 +0000220 SDValue LHS = Node->getOperand(0);
221 SDValue RHS = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000222
Owen Andersone50ed302009-08-10 22:56:29 +0000223 EVT VT = LHS.getValueType();
Dan Gohman602b0c82009-09-25 18:54:59 +0000224 SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000225 SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000226 SDValue(Carry,0), RHS);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000227
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000228 return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue,
Dan Gohman475871a2008-07-27 21:46:04 +0000229 LHS, SDValue(AddCarry,0));
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000230 }
231
Akira Hatanakac079ad02011-06-07 19:03:14 +0000232 /// Mul with two results
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000233 case ISD::SMUL_LOHI:
234 case ISD::UMUL_LOHI: {
Akira Hatanaka04d37622011-10-03 20:01:11 +0000235 assert(Node->getValueType(0) != MVT::i64 &&
236 "64-bit multiplication with two results not handled.");
Dan Gohman475871a2008-07-27 21:46:04 +0000237 SDValue Op1 = Node->getOperand(0);
238 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000239
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000240 unsigned Op;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000241 Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000242
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000243 SDNode *Mul = CurDAG->getMachineNode(Op, dl, MVT::Glue, Op1, Op2);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000244
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000245 SDValue InFlag = SDValue(Mul, 0);
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000246 SDNode *Lo = CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000247 MVT::Glue, InFlag);
Dan Gohman475871a2008-07-27 21:46:04 +0000248 InFlag = SDValue(Lo,1);
Dan Gohman602b0c82009-09-25 18:54:59 +0000249 SDNode *Hi = CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000250
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000251 if (!SDValue(Node, 0).use_empty())
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000252 ReplaceUses(SDValue(Node, 0), SDValue(Lo,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000253
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000254 if (!SDValue(Node, 1).use_empty())
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000255 ReplaceUses(SDValue(Node, 1), SDValue(Hi,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000256
257 return NULL;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000258 }
259
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000260 /// Special Muls
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000261 case ISD::MUL:
Akira Hatanaka04d37622011-10-03 20:01:11 +0000262 // Mips32 has a 32-bit three operand mul instruction.
263 if (Subtarget.hasMips32() && Node->getValueType(0) == MVT::i32)
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000264 break;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000265 case ISD::MULHS:
266 case ISD::MULHU: {
Akira Hatanaka04d37622011-10-03 20:01:11 +0000267 assert((Opcode == ISD::MUL || Node->getValueType(0) != MVT::i64) &&
268 "64-bit MULH* not handled.");
269 EVT Ty = Node->getValueType(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000270 SDValue MulOp1 = Node->getOperand(0);
271 SDValue MulOp2 = Node->getOperand(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000272
Akira Hatanaka04d37622011-10-03 20:01:11 +0000273 unsigned MulOp = (Opcode == ISD::MULHU ?
274 Mips::MULTu :
275 (Ty == MVT::i32 ? Mips::MULT : Mips::DMULT));
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000276 SDNode *MulNode = CurDAG->getMachineNode(MulOp, dl,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000277 MVT::Glue, MulOp1, MulOp2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000278
Dan Gohman475871a2008-07-27 21:46:04 +0000279 SDValue InFlag = SDValue(MulNode, 0);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000280
Akira Hatanaka04d37622011-10-03 20:01:11 +0000281 if (Opcode == ISD::MUL) {
282 unsigned Opc = (Ty == MVT::i32 ? Mips::MFLO : Mips::MFLO64);
283 return CurDAG->getMachineNode(Opc, dl, Ty, InFlag);
284 }
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000285 else
Dan Gohman602b0c82009-09-25 18:54:59 +0000286 return CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000287 }
288
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000289 // Get target GOT address.
Dan Gohman99114052009-06-03 20:30:14 +0000290 case ISD::GLOBAL_OFFSET_TABLE:
291 return getGlobalBaseReg();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000292
Bruno Cardoso Lopesa8173b92009-11-13 18:49:59 +0000293 case ISD::ConstantFP: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000294 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000295 if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
296 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Akira Hatanaka82099682011-12-19 19:52:25 +0000297 Mips::ZERO, MVT::i32);
Akira Hatanaka0285e7d2011-08-12 18:09:59 +0000298 return CurDAG->getMachineNode(Mips::BuildPairF64, dl, MVT::f64, Zero,
299 Zero);
Bruno Cardoso Lopesa8173b92009-11-13 18:49:59 +0000300 }
301 break;
302 }
303
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000304 case MipsISD::ThreadPointer: {
Akira Hatanakaca074792011-12-08 20:34:32 +0000305 EVT PtrVT = TLI.getPointerTy();
306 unsigned RdhwrOpc, SrcReg, DestReg;
307
308 if (PtrVT == MVT::i32) {
309 RdhwrOpc = Mips::RDHWR;
310 SrcReg = Mips::HWR29;
311 DestReg = Mips::V1;
312 } else {
313 RdhwrOpc = Mips::RDHWR64;
314 SrcReg = Mips::HWR29_64;
315 DestReg = Mips::V1_64;
316 }
317
Akira Hatanaka82099682011-12-19 19:52:25 +0000318 SDNode *Rdhwr =
319 CurDAG->getMachineNode(RdhwrOpc, Node->getDebugLoc(),
320 Node->getValueType(0),
321 CurDAG->getRegister(SrcReg, PtrVT));
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000322 SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, DestReg,
Akira Hatanaka82099682011-12-19 19:52:25 +0000323 SDValue(Rdhwr, 0));
Akira Hatanakaca074792011-12-08 20:34:32 +0000324 SDValue ResNode = CurDAG->getCopyFromReg(Chain, dl, DestReg, PtrVT);
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000325 ReplaceUses(SDValue(Node, 0), ResNode);
326 return ResNode.getNode();
327 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000328 }
329
330 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000331 SDNode *ResNode = SelectCode(Node);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000332
Chris Lattner7c306da2010-03-02 06:34:30 +0000333 DEBUG(errs() << "=> ");
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000334 if (ResNode == NULL || ResNode == Node)
335 DEBUG(Node->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000336 else
337 DEBUG(ResNode->dump(CurDAG));
Chris Lattner893e1c92009-08-23 06:49:22 +0000338 DEBUG(errs() << "\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000339 return ResNode;
340}
341
Akira Hatanaka21afc632011-06-21 00:40:49 +0000342bool MipsDAGToDAGISel::
343SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
344 std::vector<SDValue> &OutOps) {
345 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
346 OutOps.push_back(Op);
347 return false;
348}
349
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000350/// createMipsISelDag - This pass converts a legalized DAG into a
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000351/// MIPS-specific DAG, ready for instruction scheduling.
352FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
353 return new MipsDAGToDAGISel(TM);
354}