blob: f6891da8e739e5831553820b99f1a33fc7fa4f01 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
15#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000016#include "llvm/CallingConv.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "llvm/DerivedTypes.h"
18#include "llvm/Function.h"
19#include "llvm/Intrinsics.h"
20#include "llvm/CodeGen/MachineFrameInfo.h"
21#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
25#include "llvm/CodeGen/SSARegMap.h"
26#include "llvm/Target/TargetLowering.h"
27#include "llvm/Support/Debug.h"
28#include <iostream>
Evan Cheng2ef88a02006-08-07 22:28:20 +000029#include <queue>
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include <set>
31using namespace llvm;
32
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033namespace {
34 class ARMTargetLowering : public TargetLowering {
35 public:
36 ARMTargetLowering(TargetMachine &TM);
37 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
Rafael Espindola84b19be2006-07-16 01:02:57 +000038 virtual const char *getTargetNodeName(unsigned Opcode) const;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000039 };
40
41}
42
43ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
44 : TargetLowering(TM) {
Rafael Espindola3717ca92006-08-20 01:49:49 +000045 addRegisterClass(MVT::i32, ARM::IntRegsRegisterClass);
46
47 //LLVM requires that a register class supports MVT::f64!
48 addRegisterClass(MVT::f64, ARM::IntRegsRegisterClass);
49
Rafael Espindola06c1e7e2006-08-01 12:58:43 +000050 setOperationAction(ISD::RET, MVT::Other, Custom);
51 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
52 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
Rafael Espindola341b8642006-08-04 12:48:42 +000053
Rafael Espindola3c000bf2006-08-21 22:00:32 +000054 setOperationAction(ISD::SETCC, MVT::i32, Expand);
55 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
56
Rafael Espindola341b8642006-08-04 12:48:42 +000057 setSchedulingPreference(SchedulingForRegPressure);
Rafael Espindola3717ca92006-08-20 01:49:49 +000058 computeRegisterProperties();
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000059}
60
Rafael Espindola84b19be2006-07-16 01:02:57 +000061namespace llvm {
62 namespace ARMISD {
63 enum NodeType {
64 // Start the numbering where the builting ops and target ops leave off.
65 FIRST_NUMBER = ISD::BUILTIN_OP_END+ARM::INSTRUCTION_LIST_END,
66 /// CALL - A direct function call.
Rafael Espindolaf4fda802006-08-03 17:02:20 +000067 CALL,
68
69 /// Return with a flag operand.
Rafael Espindola3c000bf2006-08-21 22:00:32 +000070 RET_FLAG,
71
72 CMP,
73
74 SELECT
Rafael Espindola84b19be2006-07-16 01:02:57 +000075 };
76 }
77}
78
79const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
80 switch (Opcode) {
81 default: return 0;
82 case ARMISD::CALL: return "ARMISD::CALL";
Rafael Espindolaf4fda802006-08-03 17:02:20 +000083 case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG";
Rafael Espindola3c000bf2006-08-21 22:00:32 +000084 case ARMISD::SELECT: return "ARMISD::SELECT";
85 case ARMISD::CMP: return "ARMISD::CMP";
Rafael Espindola84b19be2006-07-16 01:02:57 +000086 }
87}
88
89// This transforms a ISD::CALL node into a
90// callseq_star <- ARMISD:CALL <- callseq_end
91// chain
Rafael Espindolac3c1a862006-05-25 11:00:18 +000092static SDOperand LowerCALL(SDOperand Op, SelectionDAG &DAG) {
Rafael Espindola84b19be2006-07-16 01:02:57 +000093 SDOperand Chain = Op.getOperand(0);
94 unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
95 assert(CallConv == CallingConv::C && "unknown calling convention");
96 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
Rafael Espindola84b19be2006-07-16 01:02:57 +000097 bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0;
98 assert(isTailCall == false && "tail call not supported");
99 SDOperand Callee = Op.getOperand(4);
100 unsigned NumOps = (Op.getNumOperands() - 5) / 2;
Rafael Espindola84b19be2006-07-16 01:02:57 +0000101
Rafael Espindolaec46ea32006-08-16 14:43:33 +0000102 // Count how many bytes are to be pushed on the stack.
103 unsigned NumBytes = 0;
Rafael Espindola84b19be2006-07-16 01:02:57 +0000104
Rafael Espindola1a009462006-08-08 13:02:29 +0000105 // Add up all the space actually used.
106 for (unsigned i = 4; i < NumOps; ++i)
107 NumBytes += MVT::getSizeInBits(Op.getOperand(5+2*i).getValueType())/8;
Rafael Espindolafac00a92006-07-25 20:17:20 +0000108
Rafael Espindola84b19be2006-07-16 01:02:57 +0000109 // Adjust the stack pointer for the new arguments...
110 // These operations are automatically eliminated by the prolog/epilog pass
111 Chain = DAG.getCALLSEQ_START(Chain,
112 DAG.getConstant(NumBytes, MVT::i32));
113
Rafael Espindola1a009462006-08-08 13:02:29 +0000114 SDOperand StackPtr = DAG.getRegister(ARM::R13, MVT::i32);
115
116 static const unsigned int num_regs = 4;
117 static const unsigned regs[num_regs] = {
Rafael Espindolafac00a92006-07-25 20:17:20 +0000118 ARM::R0, ARM::R1, ARM::R2, ARM::R3
119 };
120
121 std::vector<std::pair<unsigned, SDOperand> > RegsToPass;
Rafael Espindola1a009462006-08-08 13:02:29 +0000122 std::vector<SDOperand> MemOpChains;
Rafael Espindolafac00a92006-07-25 20:17:20 +0000123
124 for (unsigned i = 0; i != NumOps; ++i) {
125 SDOperand Arg = Op.getOperand(5+2*i);
Rafael Espindola1a009462006-08-08 13:02:29 +0000126 assert(Arg.getValueType() == MVT::i32);
127 if (i < num_regs)
128 RegsToPass.push_back(std::make_pair(regs[i], Arg));
129 else {
130 unsigned ArgOffset = (i - num_regs) * 4;
131 SDOperand PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
132 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
133 MemOpChains.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
134 Arg, PtrOff, DAG.getSrcValue(NULL)));
135 }
Rafael Espindolafac00a92006-07-25 20:17:20 +0000136 }
Rafael Espindola1a009462006-08-08 13:02:29 +0000137 if (!MemOpChains.empty())
Chris Lattnere2199452006-08-11 17:38:39 +0000138 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
139 &MemOpChains[0], MemOpChains.size());
Rafael Espindolafac00a92006-07-25 20:17:20 +0000140
141 // Build a sequence of copy-to-reg nodes chained together with token chain
142 // and flag operands which copy the outgoing args into the appropriate regs.
143 SDOperand InFlag;
144 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
145 Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second,
146 InFlag);
147 InFlag = Chain.getValue(1);
148 }
149
Rafael Espindola84b19be2006-07-16 01:02:57 +0000150 std::vector<MVT::ValueType> NodeTys;
151 NodeTys.push_back(MVT::Other); // Returns a chain
152 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
153
154 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
155 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
156 // node so that legalize doesn't hack it.
157 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
158 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), Callee.getValueType());
159
160 // If this is a direct call, pass the chain and the callee.
161 assert (Callee.Val);
162 std::vector<SDOperand> Ops;
163 Ops.push_back(Chain);
164 Ops.push_back(Callee);
165
Rafael Espindola7a53bd02006-08-09 16:41:12 +0000166 // Add argument registers to the end of the list so that they are known live
167 // into the call.
168 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
169 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
170 RegsToPass[i].second.getValueType()));
171
Rafael Espindola84b19be2006-07-16 01:02:57 +0000172 unsigned CallOpc = ARMISD::CALL;
Rafael Espindolafac00a92006-07-25 20:17:20 +0000173 if (InFlag.Val)
174 Ops.push_back(InFlag);
Chris Lattner87428672006-08-11 17:22:35 +0000175 Chain = DAG.getNode(CallOpc, NodeTys, &Ops[0], Ops.size());
Rafael Espindolafac00a92006-07-25 20:17:20 +0000176 InFlag = Chain.getValue(1);
Rafael Espindola84b19be2006-07-16 01:02:57 +0000177
Rafael Espindolafac00a92006-07-25 20:17:20 +0000178 std::vector<SDOperand> ResultVals;
179 NodeTys.clear();
180
181 // If the call has results, copy the values out of the ret val registers.
182 switch (Op.Val->getValueType(0)) {
183 default: assert(0 && "Unexpected ret value!");
184 case MVT::Other:
185 break;
186 case MVT::i32:
187 Chain = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag).getValue(1);
188 ResultVals.push_back(Chain.getValue(0));
189 NodeTys.push_back(MVT::i32);
190 }
Rafael Espindola84b19be2006-07-16 01:02:57 +0000191
192 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
193 DAG.getConstant(NumBytes, MVT::i32));
Rafael Espindolafac00a92006-07-25 20:17:20 +0000194 NodeTys.push_back(MVT::Other);
Rafael Espindola84b19be2006-07-16 01:02:57 +0000195
Rafael Espindolafac00a92006-07-25 20:17:20 +0000196 if (ResultVals.empty())
197 return Chain;
198
199 ResultVals.push_back(Chain);
Chris Lattner87428672006-08-11 17:22:35 +0000200 SDOperand Res = DAG.getNode(ISD::MERGE_VALUES, NodeTys, &ResultVals[0],
201 ResultVals.size());
Rafael Espindolafac00a92006-07-25 20:17:20 +0000202 return Res.getValue(Op.ResNo);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000203}
204
205static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
206 SDOperand Copy;
Rafael Espindola4b023672006-06-05 22:26:14 +0000207 SDOperand Chain = Op.getOperand(0);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000208 switch(Op.getNumOperands()) {
209 default:
210 assert(0 && "Do not know how to return this many arguments!");
211 abort();
Rafael Espindola4b023672006-06-05 22:26:14 +0000212 case 1: {
213 SDOperand LR = DAG.getRegister(ARM::R14, MVT::i32);
Rafael Espindola6312da02006-08-03 22:50:11 +0000214 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Chain);
Rafael Espindola4b023672006-06-05 22:26:14 +0000215 }
Evan Cheng6848be12006-05-26 23:10:12 +0000216 case 3:
Rafael Espindola4b023672006-06-05 22:26:14 +0000217 Copy = DAG.getCopyToReg(Chain, ARM::R0, Op.getOperand(1), SDOperand());
218 if (DAG.getMachineFunction().liveout_empty())
219 DAG.getMachineFunction().addLiveOut(ARM::R0);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000220 break;
221 }
Rafael Espindola4b023672006-06-05 22:26:14 +0000222
Rafael Espindolaf4fda802006-08-03 17:02:20 +0000223 //We must use RET_FLAG instead of BRIND because BRIND doesn't have a flag
224 return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000225}
226
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000227static SDOperand LowerFORMAL_ARGUMENT(SDOperand Op, SelectionDAG &DAG,
228 unsigned ArgNo) {
Rafael Espindola4b442b52006-05-23 02:48:20 +0000229 MachineFunction &MF = DAG.getMachineFunction();
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000230 MVT::ValueType ObjectVT = Op.getValue(ArgNo).getValueType();
231 assert (ObjectVT == MVT::i32);
Rafael Espindola4b442b52006-05-23 02:48:20 +0000232 SDOperand Root = Op.getOperand(0);
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000233 SSARegMap *RegMap = MF.getSSARegMap();
Rafael Espindola4b442b52006-05-23 02:48:20 +0000234
Rafael Espindola4b442b52006-05-23 02:48:20 +0000235 unsigned num_regs = 4;
Rafael Espindola4b442b52006-05-23 02:48:20 +0000236 static const unsigned REGS[] = {
237 ARM::R0, ARM::R1, ARM::R2, ARM::R3
238 };
239
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000240 if(ArgNo < num_regs) {
Rafael Espindola4b442b52006-05-23 02:48:20 +0000241 unsigned VReg = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000242 MF.addLiveIn(REGS[ArgNo], VReg);
243 return DAG.getCopyFromReg(Root, VReg, MVT::i32);
244 } else {
245 // If the argument is actually used, emit a load from the right stack
246 // slot.
247 if (!Op.Val->hasNUsesOfValue(0, ArgNo)) {
Rafael Espindolaaefe1422006-07-10 01:41:35 +0000248 unsigned ArgOffset = (ArgNo - num_regs) * 4;
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000249
250 MachineFrameInfo *MFI = MF.getFrameInfo();
251 unsigned ObjSize = MVT::getSizeInBits(ObjectVT)/8;
252 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
253 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
254 return DAG.getLoad(ObjectVT, Root, FIN,
255 DAG.getSrcValue(NULL));
256 } else {
257 // Don't emit a dead load.
258 return DAG.getNode(ISD::UNDEF, ObjectVT);
259 }
260 }
261}
262
Rafael Espindola06c1e7e2006-08-01 12:58:43 +0000263static SDOperand LowerConstantPool(SDOperand Op, SelectionDAG &DAG) {
264 MVT::ValueType PtrVT = Op.getValueType();
265 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
266 Constant *C = CP->get();
267 SDOperand CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment());
268
269 return CPI;
270}
271
272static SDOperand LowerGlobalAddress(SDOperand Op,
273 SelectionDAG &DAG) {
274 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
Rafael Espindola61369da2006-08-14 19:01:24 +0000275 int alignment = 2;
276 SDOperand CPAddr = DAG.getConstantPool(GV, MVT::i32, alignment);
Rafael Espindola06c1e7e2006-08-01 12:58:43 +0000277 return DAG.getLoad(MVT::i32, DAG.getEntryNode(), CPAddr,
278 DAG.getSrcValue(NULL));
279}
280
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000281static SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
282 std::vector<SDOperand> ArgValues;
283 SDOperand Root = Op.getOperand(0);
284
285 for (unsigned ArgNo = 0, e = Op.Val->getNumValues()-1; ArgNo != e; ++ArgNo) {
286 SDOperand ArgVal = LowerFORMAL_ARGUMENT(Op, DAG, ArgNo);
Rafael Espindola4b442b52006-05-23 02:48:20 +0000287
288 ArgValues.push_back(ArgVal);
289 }
290
291 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
292 assert(!isVarArg);
293
294 ArgValues.push_back(Root);
295
296 // Return the new list of results.
297 std::vector<MVT::ValueType> RetVT(Op.Val->value_begin(),
298 Op.Val->value_end());
Chris Lattner87428672006-08-11 17:22:35 +0000299 return DAG.getNode(ISD::MERGE_VALUES, RetVT, &ArgValues[0], ArgValues.size());
Rafael Espindoladc124a22006-05-18 21:45:49 +0000300}
301
Rafael Espindola3c000bf2006-08-21 22:00:32 +0000302static SDOperand LowerSELECT_CC(SDOperand Op, SelectionDAG &DAG) {
303 SDOperand LHS = Op.getOperand(0);
304 SDOperand RHS = Op.getOperand(1);
305 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
306 SDOperand TrueVal = Op.getOperand(2);
307 SDOperand FalseVal = Op.getOperand(3);
308
309 assert(CC == ISD::SETEQ);
310
311 SDOperand Cmp = DAG.getNode(ARMISD::CMP, MVT::Flag, LHS, RHS);
312 return DAG.getNode(ARMISD::SELECT, MVT::i32, FalseVal, TrueVal, Cmp);
313}
314
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000315SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
316 switch (Op.getOpcode()) {
317 default:
318 assert(0 && "Should not custom lower this!");
Rafael Espindola1c8f0532006-05-15 22:34:39 +0000319 abort();
Rafael Espindola06c1e7e2006-08-01 12:58:43 +0000320 case ISD::ConstantPool:
321 return LowerConstantPool(Op, DAG);
322 case ISD::GlobalAddress:
323 return LowerGlobalAddress(Op, DAG);
Rafael Espindoladc124a22006-05-18 21:45:49 +0000324 case ISD::FORMAL_ARGUMENTS:
325 return LowerFORMAL_ARGUMENTS(Op, DAG);
Rafael Espindolac3c1a862006-05-25 11:00:18 +0000326 case ISD::CALL:
327 return LowerCALL(Op, DAG);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000328 case ISD::RET:
329 return LowerRET(Op, DAG);
Rafael Espindola3c000bf2006-08-21 22:00:32 +0000330 case ISD::SELECT_CC:
331 return LowerSELECT_CC(Op, DAG);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000332 }
333}
334
335//===----------------------------------------------------------------------===//
336// Instruction Selector Implementation
337//===----------------------------------------------------------------------===//
338
339//===--------------------------------------------------------------------===//
340/// ARMDAGToDAGISel - ARM specific code to select ARM machine
341/// instructions for SelectionDAG operations.
342///
343namespace {
344class ARMDAGToDAGISel : public SelectionDAGISel {
345 ARMTargetLowering Lowering;
346
347public:
348 ARMDAGToDAGISel(TargetMachine &TM)
349 : SelectionDAGISel(Lowering), Lowering(TM) {
350 }
351
Evan Cheng64a752f2006-08-11 09:08:15 +0000352 SDNode *Select(SDOperand &Result, SDOperand Op);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000353 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
Rafael Espindolaa4e64352006-07-11 11:36:48 +0000354 bool SelectAddrRegImm(SDOperand N, SDOperand &Offset, SDOperand &Base);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000355
356 // Include the pieces autogenerated from the target description.
357#include "ARMGenDAGISel.inc"
358};
359
360void ARMDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
361 DEBUG(BB->dump());
362
363 DAG.setRoot(SelectRoot(DAG.getRoot()));
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000364 DAG.RemoveDeadNodes();
365
366 ScheduleAndEmitDAG(DAG);
367}
368
Rafael Espindola61369da2006-08-14 19:01:24 +0000369static bool isInt12Immediate(SDNode *N, short &Imm) {
370 if (N->getOpcode() != ISD::Constant)
371 return false;
372
373 int32_t t = cast<ConstantSDNode>(N)->getValue();
374 int max = 2<<12 - 1;
375 int min = -max;
376 if (t > min && t < max) {
377 Imm = t;
378 return true;
379 }
380 else
381 return false;
382}
383
384static bool isInt12Immediate(SDOperand Op, short &Imm) {
385 return isInt12Immediate(Op.Val, Imm);
386}
387
Rafael Espindolaa4e64352006-07-11 11:36:48 +0000388//register plus/minus 12 bit offset
389bool ARMDAGToDAGISel::SelectAddrRegImm(SDOperand N, SDOperand &Offset,
390 SDOperand &Base) {
Rafael Espindolaf3a335c2006-08-17 17:09:40 +0000391 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(N)) {
392 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
393 Offset = CurDAG->getTargetConstant(0, MVT::i32);
394 return true;
395 }
Rafael Espindola61369da2006-08-14 19:01:24 +0000396 if (N.getOpcode() == ISD::ADD) {
397 short imm = 0;
398 if (isInt12Immediate(N.getOperand(1), imm)) {
399 Offset = CurDAG->getTargetConstant(imm, MVT::i32);
400 if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N.getOperand(0))) {
401 Base = CurDAG->getTargetFrameIndex(FI->getIndex(), N.getValueType());
402 } else {
403 Base = N.getOperand(0);
404 }
405 return true; // [r+i]
406 }
407 }
408
Rafael Espindolaa4e64352006-07-11 11:36:48 +0000409 Offset = CurDAG->getTargetConstant(0, MVT::i32);
Rafael Espindolaaefe1422006-07-10 01:41:35 +0000410 if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N)) {
411 Base = CurDAG->getTargetFrameIndex(FI->getIndex(), N.getValueType());
412 }
413 else
414 Base = N;
415 return true; //any address fits in a register
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000416}
417
Evan Cheng64a752f2006-08-11 09:08:15 +0000418SDNode *ARMDAGToDAGISel::Select(SDOperand &Result, SDOperand Op) {
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000419 SDNode *N = Op.Val;
420
421 switch (N->getOpcode()) {
422 default:
Evan Cheng64a752f2006-08-11 09:08:15 +0000423 return SelectCode(Result, Op);
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000424 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +0000425 }
Evan Cheng64a752f2006-08-11 09:08:15 +0000426 return NULL;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000427}
428
429} // end anonymous namespace
430
431/// createARMISelDag - This pass converts a legalized DAG into a
432/// ARM-specific DAG, ready for instruction scheduling.
433///
434FunctionPass *llvm::createARMISelDag(TargetMachine &TM) {
435 return new ARMDAGToDAGISel(TM);
436}