blob: cc20dd7b4ff638f2600f1cd00a3a357970d20aa0 [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===-- MipsISelDAGToDAG.cpp - A dag to dag inst selector for Mips --------===//
2//
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//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the MIPS target.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "mips-isel"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015#include "Mips.h"
16#include "MipsISelLowering.h"
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000017#include "MipsMachineFunction.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000018#include "MipsRegisterInfo.h"
19#include "MipsSubtarget.h"
20#include "MipsTargetMachine.h"
21#include "llvm/GlobalValue.h"
22#include "llvm/Instructions.h"
23#include "llvm/Intrinsics.h"
24#include "llvm/Support/CFG.h"
25#include "llvm/Type.h"
26#include "llvm/CodeGen/MachineConstantPool.h"
27#include "llvm/CodeGen/MachineFunction.h"
28#include "llvm/CodeGen/MachineFrameInfo.h"
29#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000030#include "llvm/CodeGen/MachineRegisterInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000031#include "llvm/CodeGen/SelectionDAGISel.h"
32#include "llvm/Target/TargetMachine.h"
33#include "llvm/Support/Compiler.h"
34#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000037using namespace llvm;
38
39//===----------------------------------------------------------------------===//
40// Instruction Selector Implementation
41//===----------------------------------------------------------------------===//
42
43//===----------------------------------------------------------------------===//
44// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
45// instructions for SelectionDAG operations.
46//===----------------------------------------------------------------------===//
47namespace {
48
49class VISIBILITY_HIDDEN MipsDAGToDAGISel : public SelectionDAGISel {
50
51 /// TM - Keep a reference to MipsTargetMachine.
52 MipsTargetMachine &TM;
53
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000054 /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
55 /// make the right decision when generating code for different targets.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000056 const MipsSubtarget &Subtarget;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000057
58public:
Dan Gohman1002c022008-07-07 18:00:37 +000059 explicit MipsDAGToDAGISel(MipsTargetMachine &tm) :
Dan Gohman79ce2762009-01-15 19:20:50 +000060 SelectionDAGISel(tm),
Dan Gohmanda8ac5f2008-10-03 16:55:19 +000061 TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000062
Dan Gohmanf350b272008-08-23 02:25:05 +000063 virtual void InstructionSelect();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000064
65 // Pass Name
66 virtual const char *getPassName() const {
67 return "MIPS DAG->DAG Pattern Instruction Selection";
68 }
69
70
71private:
72 // Include the pieces autogenerated from the target description.
73 #include "MipsGenDAGISel.inc"
74
Dan Gohman99114052009-06-03 20:30:14 +000075 /// 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();
Dan Gohman475871a2008-07-27 21:46:04 +000088 SDNode *Select(SDValue N);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089
90 // Complex Pattern.
Dan Gohman475871a2008-07-27 21:46:04 +000091 bool SelectAddr(SDValue Op, SDValue N,
92 SDValue &Base, SDValue &Offset);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000093
94
95 // getI32Imm - Return a target constant with the specified
96 // value, of type i32.
Dan Gohman475871a2008-07-27 21:46:04 +000097 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000098 return CurDAG->getTargetConstant(Imm, MVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000099 }
100
101
102 #ifndef NDEBUG
103 unsigned Indent;
104 #endif
105};
106
107}
108
Evan Chengdb8d56b2008-06-30 20:45:06 +0000109/// InstructionSelect - This callback is invoked by
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000110/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
Chris Lattner893e1c92009-08-23 06:49:22 +0000111void MipsDAGToDAGISel::InstructionSelect() {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112 DEBUG(BB->dump());
113 // Codegen the basic block.
Chris Lattner893e1c92009-08-23 06:49:22 +0000114 DEBUG(errs() << "===== Instruction selection begins:\n");
Daniel Dunbar43ed2672009-08-23 08:50:52 +0000115 DEBUG(Indent = 0);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000116
117 // Select target instructions for the DAG.
David Greene8ad4c002008-10-27 21:56:29 +0000118 SelectRoot(*CurDAG);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000119
Chris Lattner893e1c92009-08-23 06:49:22 +0000120 DEBUG(errs() << "===== Instruction selection ends:\n");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000121
Dan Gohmanf350b272008-08-23 02:25:05 +0000122 CurDAG->RemoveDeadNodes();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000123}
124
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000125/// getGlobalBaseReg - Output the instructions required to put the
126/// GOT address into a register.
Dan Gohman99114052009-06-03 20:30:14 +0000127SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Dan Gohman99114052009-06-03 20:30:14 +0000128 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
129 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000130}
131
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132/// ComplexPattern used on MipsInstrInfo
133/// Used on Mips Load/Store instructions
134bool MipsDAGToDAGISel::
Dan Gohman475871a2008-07-27 21:46:04 +0000135SelectAddr(SDValue Op, SDValue Addr, SDValue &Offset, SDValue &Base)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000136{
137 // if Address is FI, get the TargetFrameIndex.
138 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000139 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
140 Offset = CurDAG->getTargetConstant(0, MVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000141 return true;
142 }
143
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000144 // on PIC code Load GA
145 if (TM.getRelocationModel() == Reloc::PIC_) {
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000146 if ((Addr.getOpcode() == ISD::TargetGlobalAddress) ||
147 (Addr.getOpcode() == ISD::TargetJumpTable)){
Owen Anderson825b72b2009-08-11 20:47:22 +0000148 Base = CurDAG->getRegister(Mips::GP, MVT::i32);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000149 Offset = Addr;
150 return true;
151 }
152 } else {
Bill Wendling056292f2008-09-16 21:48:12 +0000153 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000154 Addr.getOpcode() == ISD::TargetGlobalAddress))
155 return false;
156 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000157
Bruno Cardoso Lopes7ff6fa22007-08-18 02:16:30 +0000158 // Operand is a result from an ADD.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000159 if (Addr.getOpcode() == ISD::ADD) {
160 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
161 if (Predicate_immSExt16(CN)) {
162
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000163 // If the first operand is a FI, get the TargetFI Node
164 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
165 (Addr.getOperand(0))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000166 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000167 } else {
168 Base = Addr.getOperand(0);
169 }
170
Owen Anderson825b72b2009-08-11 20:47:22 +0000171 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000172 return true;
173 }
174 }
175 }
176
Bruno Cardoso Lopesa4e82002007-07-11 23:24:41 +0000177 Base = Addr;
Owen Anderson825b72b2009-08-11 20:47:22 +0000178 Offset = CurDAG->getTargetConstant(0, MVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000179 return true;
180}
181
182/// Select instructions not customized! Used for
183/// expanded, promoted and normal instructions
Chris Lattner893e1c92009-08-23 06:49:22 +0000184SDNode* MipsDAGToDAGISel::Select(SDValue N) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000185 SDNode *Node = N.getNode();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000186 unsigned Opcode = Node->getOpcode();
Dale Johannesena05dca42009-02-04 23:02:30 +0000187 DebugLoc dl = Node->getDebugLoc();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000188
189 // Dump information about the Node being selected
Chris Lattner893e1c92009-08-23 06:49:22 +0000190 DEBUG(errs().indent(Indent) << "Selecting: ";
191 Node->dump(CurDAG);
192 errs() << "\n");
Daniel Dunbar43ed2672009-08-23 08:50:52 +0000193 DEBUG(Indent += 2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194
195 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000196 if (Node->isMachineOpcode()) {
Chris Lattner893e1c92009-08-23 06:49:22 +0000197 DEBUG(errs().indent(Indent-2) << "== ";
198 Node->dump(CurDAG);
199 errs() << "\n");
Daniel Dunbar43ed2672009-08-23 08:50:52 +0000200 DEBUG(Indent -= 2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000201 return NULL;
202 }
203
204 ///
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000205 // Instruction Selection not handled by the auto-generated
206 // tablegen selection should be handled here.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000207 ///
208 switch(Opcode) {
209
210 default: break;
211
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000212 case ISD::SUBE:
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000213 case ISD::ADDE: {
Dan Gohman475871a2008-07-27 21:46:04 +0000214 SDValue InFlag = Node->getOperand(2), CmpLHS;
Chris Lattner30baa952008-12-14 21:38:24 +0000215 unsigned Opc = InFlag.getOpcode(); Opc=Opc;
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000216 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
217 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
218 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
219
Chris Lattner30baa952008-12-14 21:38:24 +0000220 unsigned MOp;
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000221 if (Opcode == ISD::ADDE) {
222 CmpLHS = InFlag.getValue(0);
223 MOp = Mips::ADDu;
224 } else {
225 CmpLHS = InFlag.getOperand(0);
226 MOp = Mips::SUBu;
227 }
228
Dan Gohman475871a2008-07-27 21:46:04 +0000229 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000230
Dan Gohman475871a2008-07-27 21:46:04 +0000231 SDValue LHS = Node->getOperand(0);
232 SDValue RHS = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000233
Owen Andersone50ed302009-08-10 22:56:29 +0000234 EVT VT = LHS.getValueType();
Dan Gohman602b0c82009-09-25 18:54:59 +0000235 SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
236 SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
237 SDValue(Carry,0), RHS);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000238
Owen Anderson825b72b2009-08-11 20:47:22 +0000239 return CurDAG->SelectNodeTo(N.getNode(), MOp, VT, MVT::Flag,
Dan Gohman475871a2008-07-27 21:46:04 +0000240 LHS, SDValue(AddCarry,0));
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000241 }
242
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000243 /// Mul/Div with two results
244 case ISD::SDIVREM:
245 case ISD::UDIVREM:
246 case ISD::SMUL_LOHI:
247 case ISD::UMUL_LOHI: {
Dan Gohman475871a2008-07-27 21:46:04 +0000248 SDValue Op1 = Node->getOperand(0);
249 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000250
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000251 unsigned Op;
252 if (Opcode == ISD::UMUL_LOHI || Opcode == ISD::SMUL_LOHI)
253 Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
254 else
255 Op = (Opcode == ISD::UDIVREM ? Mips::DIVu : Mips::DIV);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000256
Dan Gohman602b0c82009-09-25 18:54:59 +0000257 SDNode *Node = CurDAG->getMachineNode(Op, dl, MVT::Flag, Op1, Op2);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000258
Dan Gohman475871a2008-07-27 21:46:04 +0000259 SDValue InFlag = SDValue(Node, 0);
Dan Gohman602b0c82009-09-25 18:54:59 +0000260 SDNode *Lo = CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32,
261 MVT::Flag, InFlag);
Dan Gohman475871a2008-07-27 21:46:04 +0000262 InFlag = SDValue(Lo,1);
Dan Gohman602b0c82009-09-25 18:54:59 +0000263 SDNode *Hi = CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000264
265 if (!N.getValue(0).use_empty())
Dan Gohman475871a2008-07-27 21:46:04 +0000266 ReplaceUses(N.getValue(0), SDValue(Lo,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000267
268 if (!N.getValue(1).use_empty())
Dan Gohman475871a2008-07-27 21:46:04 +0000269 ReplaceUses(N.getValue(1), SDValue(Hi,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000270
271 return NULL;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000272 }
273
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000274 /// Special Muls
275 case ISD::MUL:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000276 case ISD::MULHS:
277 case ISD::MULHU: {
Dan Gohman475871a2008-07-27 21:46:04 +0000278 SDValue MulOp1 = Node->getOperand(0);
279 SDValue MulOp2 = Node->getOperand(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000280
281 unsigned MulOp = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT);
Dan Gohman602b0c82009-09-25 18:54:59 +0000282 SDNode *MulNode = CurDAG->getMachineNode(MulOp, dl,
283 MVT::Flag, MulOp1, MulOp2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000284
Dan Gohman475871a2008-07-27 21:46:04 +0000285 SDValue InFlag = SDValue(MulNode, 0);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000286
287 if (MulOp == ISD::MUL)
Dan Gohman602b0c82009-09-25 18:54:59 +0000288 return CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000289 else
Dan Gohman602b0c82009-09-25 18:54:59 +0000290 return CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000291 }
292
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000293 /// Div/Rem operations
294 case ISD::SREM:
295 case ISD::UREM:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000296 case ISD::SDIV:
297 case ISD::UDIV: {
Dan Gohman475871a2008-07-27 21:46:04 +0000298 SDValue Op1 = Node->getOperand(0);
299 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000300
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000301 unsigned Op, MOp;
302 if (Opcode == ISD::SDIV || Opcode == ISD::UDIV) {
303 Op = (Opcode == ISD::SDIV ? Mips::DIV : Mips::DIVu);
304 MOp = Mips::MFLO;
305 } else {
306 Op = (Opcode == ISD::SREM ? Mips::DIV : Mips::DIVu);
307 MOp = Mips::MFHI;
308 }
Dan Gohman602b0c82009-09-25 18:54:59 +0000309 SDNode *Node = CurDAG->getMachineNode(Op, dl, MVT::Flag, Op1, Op2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000310
Dan Gohman475871a2008-07-27 21:46:04 +0000311 SDValue InFlag = SDValue(Node, 0);
Dan Gohman602b0c82009-09-25 18:54:59 +0000312 return CurDAG->getMachineNode(MOp, dl, MVT::i32, InFlag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000313 }
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000314
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000315 // Get target GOT address.
Dan Gohman99114052009-06-03 20:30:14 +0000316 case ISD::GLOBAL_OFFSET_TABLE:
317 return getGlobalBaseReg();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000318
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000319 /// Handle direct and indirect calls when using PIC. On PIC, when
320 /// GOT is smaller than about 64k (small code) the GA target is
321 /// loaded with only one instruction. Otherwise GA's target must
322 /// be loaded with 3 instructions.
323 case MipsISD::JmpLink: {
324 if (TM.getRelocationModel() == Reloc::PIC_) {
Dan Gohman475871a2008-07-27 21:46:04 +0000325 SDValue Chain = Node->getOperand(0);
326 SDValue Callee = Node->getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000327 SDValue T9Reg = CurDAG->getRegister(Mips::T9, MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +0000328 SDValue InFlag(0, 0);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000329
330 if ( (isa<GlobalAddressSDNode>(Callee)) ||
Bill Wendling056292f2008-09-16 21:48:12 +0000331 (isa<ExternalSymbolSDNode>(Callee)) )
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000332 {
333 /// Direct call for global addresses and external symbols
Owen Anderson825b72b2009-08-11 20:47:22 +0000334 SDValue GPReg = CurDAG->getRegister(Mips::GP, MVT::i32);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000335
336 // Use load to get GOT target
Dan Gohman475871a2008-07-27 21:46:04 +0000337 SDValue Ops[] = { Callee, GPReg, Chain };
Dan Gohman602b0c82009-09-25 18:54:59 +0000338 SDValue Load = SDValue(CurDAG->getMachineNode(Mips::LW, dl, MVT::i32,
Owen Anderson825b72b2009-08-11 20:47:22 +0000339 MVT::Other, Ops, 3), 0);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000340 Chain = Load.getValue(1);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000341
342 // Call target must be on T9
Dale Johannesena05dca42009-02-04 23:02:30 +0000343 Chain = CurDAG->getCopyToReg(Chain, dl, T9Reg, Load, InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000344 } else
345 /// Indirect call
Dale Johannesena05dca42009-02-04 23:02:30 +0000346 Chain = CurDAG->getCopyToReg(Chain, dl, T9Reg, Callee, InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000347
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000348 // Emit Jump and Link Register
Dan Gohman602b0c82009-09-25 18:54:59 +0000349 SDNode *ResNode = CurDAG->getMachineNode(Mips::JALR, dl, MVT::Other,
Owen Anderson825b72b2009-08-11 20:47:22 +0000350 MVT::Flag, T9Reg, Chain);
Dan Gohman475871a2008-07-27 21:46:04 +0000351 Chain = SDValue(ResNode, 0);
352 InFlag = SDValue(ResNode, 1);
353 ReplaceUses(SDValue(Node, 0), Chain);
354 ReplaceUses(SDValue(Node, 1), InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000355 return ResNode;
356 }
357 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000358 }
359
360 // Select the default instruction
361 SDNode *ResNode = SelectCode(N);
362
Chris Lattner893e1c92009-08-23 06:49:22 +0000363 DEBUG(errs().indent(Indent-2) << "=> ");
Gabor Greifba36cb52008-08-28 21:40:38 +0000364 if (ResNode == NULL || ResNode == N.getNode())
365 DEBUG(N.getNode()->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000366 else
367 DEBUG(ResNode->dump(CurDAG));
Chris Lattner893e1c92009-08-23 06:49:22 +0000368 DEBUG(errs() << "\n");
Daniel Dunbar43ed2672009-08-23 08:50:52 +0000369 DEBUG(Indent -= 2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000370
371 return ResNode;
372}
373
374/// createMipsISelDag - This pass converts a legalized DAG into a
375/// MIPS-specific DAG, ready for instruction scheduling.
376FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
377 return new MipsDAGToDAGISel(TM);
378}