blob: b03f7859c79ff81be66d0b34d2c548386e9498d4 [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 Andersone50ed302009-08-10 22:56:29 +000098 return CurDAG->getTargetConstant(Imm, EVT::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.
111void MipsDAGToDAGISel::
Dan Gohmanf350b272008-08-23 02:25:05 +0000112InstructionSelect()
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000113{
114 DEBUG(BB->dump());
115 // Codegen the basic block.
116 #ifndef NDEBUG
117 DOUT << "===== Instruction selection begins:\n";
118 Indent = 0;
119 #endif
120
121 // Select target instructions for the DAG.
David Greene8ad4c002008-10-27 21:56:29 +0000122 SelectRoot(*CurDAG);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000123
124 #ifndef NDEBUG
125 DOUT << "===== Instruction selection ends:\n";
126 #endif
127
Dan Gohmanf350b272008-08-23 02:25:05 +0000128 CurDAG->RemoveDeadNodes();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000129}
130
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000131/// getGlobalBaseReg - Output the instructions required to put the
132/// GOT address into a register.
Dan Gohman99114052009-06-03 20:30:14 +0000133SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Dan Gohman99114052009-06-03 20:30:14 +0000134 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
135 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000136}
137
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000138/// ComplexPattern used on MipsInstrInfo
139/// Used on Mips Load/Store instructions
140bool MipsDAGToDAGISel::
Dan Gohman475871a2008-07-27 21:46:04 +0000141SelectAddr(SDValue Op, SDValue Addr, SDValue &Offset, SDValue &Base)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000142{
143 // if Address is FI, get the TargetFrameIndex.
144 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Owen Andersone50ed302009-08-10 22:56:29 +0000145 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), EVT::i32);
146 Offset = CurDAG->getTargetConstant(0, EVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000147 return true;
148 }
149
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000150 // on PIC code Load GA
151 if (TM.getRelocationModel() == Reloc::PIC_) {
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000152 if ((Addr.getOpcode() == ISD::TargetGlobalAddress) ||
153 (Addr.getOpcode() == ISD::TargetJumpTable)){
Owen Andersone50ed302009-08-10 22:56:29 +0000154 Base = CurDAG->getRegister(Mips::GP, EVT::i32);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000155 Offset = Addr;
156 return true;
157 }
158 } else {
Bill Wendling056292f2008-09-16 21:48:12 +0000159 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000160 Addr.getOpcode() == ISD::TargetGlobalAddress))
161 return false;
162 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000163
Bruno Cardoso Lopes7ff6fa22007-08-18 02:16:30 +0000164 // Operand is a result from an ADD.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000165 if (Addr.getOpcode() == ISD::ADD) {
166 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
167 if (Predicate_immSExt16(CN)) {
168
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000169 // If the first operand is a FI, get the TargetFI Node
170 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
171 (Addr.getOperand(0))) {
Owen Andersone50ed302009-08-10 22:56:29 +0000172 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), EVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173 } else {
174 Base = Addr.getOperand(0);
175 }
176
Owen Andersone50ed302009-08-10 22:56:29 +0000177 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), EVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000178 return true;
179 }
180 }
181 }
182
Bruno Cardoso Lopesa4e82002007-07-11 23:24:41 +0000183 Base = Addr;
Owen Andersone50ed302009-08-10 22:56:29 +0000184 Offset = CurDAG->getTargetConstant(0, EVT::i32);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000185 return true;
186}
187
188/// Select instructions not customized! Used for
189/// expanded, promoted and normal instructions
190SDNode* MipsDAGToDAGISel::
Dan Gohman475871a2008-07-27 21:46:04 +0000191Select(SDValue N)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000192{
Gabor Greifba36cb52008-08-28 21:40:38 +0000193 SDNode *Node = N.getNode();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194 unsigned Opcode = Node->getOpcode();
Dale Johannesena05dca42009-02-04 23:02:30 +0000195 DebugLoc dl = Node->getDebugLoc();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000196
197 // Dump information about the Node being selected
198 #ifndef NDEBUG
199 DOUT << std::string(Indent, ' ') << "Selecting: ";
200 DEBUG(Node->dump(CurDAG));
201 DOUT << "\n";
202 Indent += 2;
203 #endif
204
205 // If we have a custom node, we already have selected!
Dan Gohmane8be6c62008-07-17 19:10:17 +0000206 if (Node->isMachineOpcode()) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000207 #ifndef NDEBUG
208 DOUT << std::string(Indent-2, ' ') << "== ";
209 DEBUG(Node->dump(CurDAG));
210 DOUT << "\n";
211 Indent -= 2;
212 #endif
213 return NULL;
214 }
215
216 ///
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000217 // Instruction Selection not handled by the auto-generated
218 // tablegen selection should be handled here.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000219 ///
220 switch(Opcode) {
221
222 default: break;
223
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000224 case ISD::SUBE:
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000225 case ISD::ADDE: {
Dan Gohman475871a2008-07-27 21:46:04 +0000226 SDValue InFlag = Node->getOperand(2), CmpLHS;
Chris Lattner30baa952008-12-14 21:38:24 +0000227 unsigned Opc = InFlag.getOpcode(); Opc=Opc;
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000228 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
229 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
230 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
231
Chris Lattner30baa952008-12-14 21:38:24 +0000232 unsigned MOp;
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000233 if (Opcode == ISD::ADDE) {
234 CmpLHS = InFlag.getValue(0);
235 MOp = Mips::ADDu;
236 } else {
237 CmpLHS = InFlag.getOperand(0);
238 MOp = Mips::SUBu;
239 }
240
Dan Gohman475871a2008-07-27 21:46:04 +0000241 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000242
Dan Gohman475871a2008-07-27 21:46:04 +0000243 SDValue LHS = Node->getOperand(0);
244 SDValue RHS = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000245
Owen Andersone50ed302009-08-10 22:56:29 +0000246 EVT VT = LHS.getValueType();
Dale Johannesena05dca42009-02-04 23:02:30 +0000247 SDNode *Carry = CurDAG->getTargetNode(Mips::SLTu, dl, VT, Ops, 2);
248 SDNode *AddCarry = CurDAG->getTargetNode(Mips::ADDu, dl, VT,
Dan Gohman475871a2008-07-27 21:46:04 +0000249 SDValue(Carry,0), RHS);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000250
Owen Andersone50ed302009-08-10 22:56:29 +0000251 return CurDAG->SelectNodeTo(N.getNode(), MOp, VT, EVT::Flag,
Dan Gohman475871a2008-07-27 21:46:04 +0000252 LHS, SDValue(AddCarry,0));
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000253 }
254
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000255 /// Mul/Div with two results
256 case ISD::SDIVREM:
257 case ISD::UDIVREM:
258 case ISD::SMUL_LOHI:
259 case ISD::UMUL_LOHI: {
Dan Gohman475871a2008-07-27 21:46:04 +0000260 SDValue Op1 = Node->getOperand(0);
261 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000262
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000263 unsigned Op;
264 if (Opcode == ISD::UMUL_LOHI || Opcode == ISD::SMUL_LOHI)
265 Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
266 else
267 Op = (Opcode == ISD::UDIVREM ? Mips::DIVu : Mips::DIV);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000268
Owen Andersone50ed302009-08-10 22:56:29 +0000269 SDNode *Node = CurDAG->getTargetNode(Op, dl, EVT::Flag, Op1, Op2);
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000270
Dan Gohman475871a2008-07-27 21:46:04 +0000271 SDValue InFlag = SDValue(Node, 0);
Owen Andersone50ed302009-08-10 22:56:29 +0000272 SDNode *Lo = CurDAG->getTargetNode(Mips::MFLO, dl, EVT::i32,
273 EVT::Flag, InFlag);
Dan Gohman475871a2008-07-27 21:46:04 +0000274 InFlag = SDValue(Lo,1);
Owen Andersone50ed302009-08-10 22:56:29 +0000275 SDNode *Hi = CurDAG->getTargetNode(Mips::MFHI, dl, EVT::i32, InFlag);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000276
277 if (!N.getValue(0).use_empty())
Dan Gohman475871a2008-07-27 21:46:04 +0000278 ReplaceUses(N.getValue(0), SDValue(Lo,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000279
280 if (!N.getValue(1).use_empty())
Dan Gohman475871a2008-07-27 21:46:04 +0000281 ReplaceUses(N.getValue(1), SDValue(Hi,0));
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000282
283 return NULL;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000284 }
285
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000286 /// Special Muls
287 case ISD::MUL:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000288 case ISD::MULHS:
289 case ISD::MULHU: {
Dan Gohman475871a2008-07-27 21:46:04 +0000290 SDValue MulOp1 = Node->getOperand(0);
291 SDValue MulOp2 = Node->getOperand(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292
293 unsigned MulOp = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT);
Dale Johannesena05dca42009-02-04 23:02:30 +0000294 SDNode *MulNode = CurDAG->getTargetNode(MulOp, dl,
Owen Andersone50ed302009-08-10 22:56:29 +0000295 EVT::Flag, MulOp1, MulOp2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000296
Dan Gohman475871a2008-07-27 21:46:04 +0000297 SDValue InFlag = SDValue(MulNode, 0);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000298
299 if (MulOp == ISD::MUL)
Owen Andersone50ed302009-08-10 22:56:29 +0000300 return CurDAG->getTargetNode(Mips::MFLO, dl, EVT::i32, InFlag);
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000301 else
Owen Andersone50ed302009-08-10 22:56:29 +0000302 return CurDAG->getTargetNode(Mips::MFHI, dl, EVT::i32, InFlag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000303 }
304
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000305 /// Div/Rem operations
306 case ISD::SREM:
307 case ISD::UREM:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000308 case ISD::SDIV:
309 case ISD::UDIV: {
Dan Gohman475871a2008-07-27 21:46:04 +0000310 SDValue Op1 = Node->getOperand(0);
311 SDValue Op2 = Node->getOperand(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000312
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000313 unsigned Op, MOp;
314 if (Opcode == ISD::SDIV || Opcode == ISD::UDIV) {
315 Op = (Opcode == ISD::SDIV ? Mips::DIV : Mips::DIVu);
316 MOp = Mips::MFLO;
317 } else {
318 Op = (Opcode == ISD::SREM ? Mips::DIV : Mips::DIVu);
319 MOp = Mips::MFHI;
320 }
Owen Andersone50ed302009-08-10 22:56:29 +0000321 SDNode *Node = CurDAG->getTargetNode(Op, dl, EVT::Flag, Op1, Op2);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000322
Dan Gohman475871a2008-07-27 21:46:04 +0000323 SDValue InFlag = SDValue(Node, 0);
Owen Andersone50ed302009-08-10 22:56:29 +0000324 return CurDAG->getTargetNode(MOp, dl, EVT::i32, InFlag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000325 }
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000326
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000327 // Get target GOT address.
Dan Gohman99114052009-06-03 20:30:14 +0000328 case ISD::GLOBAL_OFFSET_TABLE:
329 return getGlobalBaseReg();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000330
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000331 /// Handle direct and indirect calls when using PIC. On PIC, when
332 /// GOT is smaller than about 64k (small code) the GA target is
333 /// loaded with only one instruction. Otherwise GA's target must
334 /// be loaded with 3 instructions.
335 case MipsISD::JmpLink: {
336 if (TM.getRelocationModel() == Reloc::PIC_) {
337 //bool isCodeLarge = (TM.getCodeModel() == CodeModel::Large);
Dan Gohman475871a2008-07-27 21:46:04 +0000338 SDValue Chain = Node->getOperand(0);
339 SDValue Callee = Node->getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +0000340 SDValue T9Reg = CurDAG->getRegister(Mips::T9, EVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +0000341 SDValue InFlag(0, 0);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000342
343 if ( (isa<GlobalAddressSDNode>(Callee)) ||
Bill Wendling056292f2008-09-16 21:48:12 +0000344 (isa<ExternalSymbolSDNode>(Callee)) )
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000345 {
346 /// Direct call for global addresses and external symbols
Owen Andersone50ed302009-08-10 22:56:29 +0000347 SDValue GPReg = CurDAG->getRegister(Mips::GP, EVT::i32);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000348
349 // Use load to get GOT target
Dan Gohman475871a2008-07-27 21:46:04 +0000350 SDValue Ops[] = { Callee, GPReg, Chain };
Owen Andersone50ed302009-08-10 22:56:29 +0000351 SDValue Load = SDValue(CurDAG->getTargetNode(Mips::LW, dl, EVT::i32,
352 EVT::Other, Ops, 3), 0);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000353 Chain = Load.getValue(1);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000354
355 // Call target must be on T9
Dale Johannesena05dca42009-02-04 23:02:30 +0000356 Chain = CurDAG->getCopyToReg(Chain, dl, T9Reg, Load, InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000357 } else
358 /// Indirect call
Dale Johannesena05dca42009-02-04 23:02:30 +0000359 Chain = CurDAG->getCopyToReg(Chain, dl, T9Reg, Callee, InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000360
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000361 // Emit Jump and Link Register
Owen Andersone50ed302009-08-10 22:56:29 +0000362 SDNode *ResNode = CurDAG->getTargetNode(Mips::JALR, dl, EVT::Other,
363 EVT::Flag, T9Reg, Chain);
Dan Gohman475871a2008-07-27 21:46:04 +0000364 Chain = SDValue(ResNode, 0);
365 InFlag = SDValue(ResNode, 1);
366 ReplaceUses(SDValue(Node, 0), Chain);
367 ReplaceUses(SDValue(Node, 1), InFlag);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000368 return ResNode;
369 }
370 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000371 }
372
373 // Select the default instruction
374 SDNode *ResNode = SelectCode(N);
375
376 #ifndef NDEBUG
377 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +0000378 if (ResNode == NULL || ResNode == N.getNode())
379 DEBUG(N.getNode()->dump(CurDAG));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000380 else
381 DEBUG(ResNode->dump(CurDAG));
382 DOUT << "\n";
383 Indent -= 2;
384 #endif
385
386 return ResNode;
387}
388
389/// createMipsISelDag - This pass converts a legalized DAG into a
390/// MIPS-specific DAG, ready for instruction scheduling.
391FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
392 return new MipsDAGToDAGISel(TM);
393}