blob: 863cf6f857bf5f8af688e016ea7a217ebbf1acf1 [file] [log] [blame]
Tim Northover72062f52013-01-31 12:12:40 +00001//===-- AArch64ISelDAGToDAG.cpp - A dag to dag inst selector for AArch64 --===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the AArch64 target.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "aarch64-isel"
15#include "AArch64.h"
16#include "AArch64InstrInfo.h"
17#include "AArch64Subtarget.h"
18#include "AArch64TargetMachine.h"
Tim Northover19254c42013-02-05 13:24:47 +000019#include "Utils/AArch64BaseInfo.h"
Tim Northover72062f52013-01-31 12:12:40 +000020#include "llvm/ADT/APSInt.h"
21#include "llvm/CodeGen/SelectionDAGISel.h"
22#include "llvm/IR/GlobalValue.h"
23#include "llvm/Support/Debug.h"
24#include "llvm/Support/raw_ostream.h"
25
26using namespace llvm;
27
28//===--------------------------------------------------------------------===//
29/// AArch64 specific code to select AArch64 machine instructions for
30/// SelectionDAG operations.
31///
32namespace {
33
34class AArch64DAGToDAGISel : public SelectionDAGISel {
35 AArch64TargetMachine &TM;
36 const AArch64InstrInfo *TII;
37
38 /// Keep a pointer to the AArch64Subtarget around so that we can
39 /// make the right decision when generating code for different targets.
40 const AArch64Subtarget *Subtarget;
41
42public:
43 explicit AArch64DAGToDAGISel(AArch64TargetMachine &tm,
44 CodeGenOpt::Level OptLevel)
45 : SelectionDAGISel(tm, OptLevel), TM(tm),
46 TII(static_cast<const AArch64InstrInfo*>(TM.getInstrInfo())),
47 Subtarget(&TM.getSubtarget<AArch64Subtarget>()) {
48 }
49
50 virtual const char *getPassName() const {
51 return "AArch64 Instruction Selection";
52 }
53
54 // Include the pieces autogenerated from the target description.
55#include "AArch64GenDAGISel.inc"
56
57 template<unsigned MemSize>
58 bool SelectOffsetUImm12(SDValue N, SDValue &UImm12) {
59 const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);
60 if (!CN || CN->getZExtValue() % MemSize != 0
61 || CN->getZExtValue() / MemSize > 0xfff)
62 return false;
63
64 UImm12 = CurDAG->getTargetConstant(CN->getZExtValue() / MemSize, MVT::i64);
65 return true;
66 }
67
68 template<unsigned RegWidth>
69 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos) {
70 return SelectCVTFixedPosOperand(N, FixedPos, RegWidth);
71 }
72
Tim Northover45db9202013-05-04 16:53:46 +000073 /// Used for pre-lowered address-reference nodes, so we already know
74 /// the fields match. This operand's job is simply to add an
75 /// appropriate shift operand (i.e. 0) to the MOVZ/MOVK instruction.
76 bool SelectMOVWAddressRef(SDValue N, SDValue &Imm, SDValue &Shift) {
77 Imm = N;
78 Shift = CurDAG->getTargetConstant(0, MVT::i32);
79 return true;
80 }
81
Tim Northover72062f52013-01-31 12:12:40 +000082 bool SelectFPZeroOperand(SDValue N, SDValue &Dummy);
83
Tim Northoverdfe076a2013-02-05 13:24:56 +000084 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
85 unsigned RegWidth);
Tim Northover72062f52013-01-31 12:12:40 +000086
87 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
88 char ConstraintCode,
89 std::vector<SDValue> &OutOps);
90
91 bool SelectLogicalImm(SDValue N, SDValue &Imm);
92
93 template<unsigned RegWidth>
94 bool SelectTSTBOperand(SDValue N, SDValue &FixedPos) {
95 return SelectTSTBOperand(N, FixedPos, RegWidth);
96 }
97
98 bool SelectTSTBOperand(SDValue N, SDValue &FixedPos, unsigned RegWidth);
99
Tim Northover211ffd22013-04-08 08:40:41 +0000100 SDNode *SelectAtomic(SDNode *N, unsigned Op8, unsigned Op16, unsigned Op32, unsigned Op64);
101
Tim Northover72062f52013-01-31 12:12:40 +0000102 SDNode *TrySelectToMoveImm(SDNode *N);
Tim Northover1e883932013-02-15 09:33:43 +0000103 SDNode *LowerToFPLitPool(SDNode *Node);
Tim Northover72062f52013-01-31 12:12:40 +0000104 SDNode *SelectToLitPool(SDNode *N);
Tim Northover72062f52013-01-31 12:12:40 +0000105
106 SDNode* Select(SDNode*);
107private:
108};
109}
110
111bool
112AArch64DAGToDAGISel::SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
113 unsigned RegWidth) {
114 const ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
115 if (!CN) return false;
116
117 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
118 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
119 // x-register.
120 //
121 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
122 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
123 // integers.
124 bool IsExact;
125
126 // fbits is between 1 and 64 in the worst-case, which means the fmul
127 // could have 2^64 as an actual operand. Need 65 bits of precision.
128 APSInt IntVal(65, true);
129 CN->getValueAPF().convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
130
131 // N.b. isPowerOf2 also checks for > 0.
132 if (!IsExact || !IntVal.isPowerOf2()) return false;
133 unsigned FBits = IntVal.logBase2();
134
135 // Checks above should have guaranteed that we haven't lost information in
136 // finding FBits, but it must still be in range.
137 if (FBits == 0 || FBits > RegWidth) return false;
138
139 FixedPos = CurDAG->getTargetConstant(64 - FBits, MVT::i32);
140 return true;
141}
142
143bool
144AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(const SDValue &Op,
Tim Northoverdfe076a2013-02-05 13:24:56 +0000145 char ConstraintCode,
146 std::vector<SDValue> &OutOps) {
Tim Northover72062f52013-01-31 12:12:40 +0000147 switch (ConstraintCode) {
148 default: llvm_unreachable("Unrecognised AArch64 memory constraint");
149 case 'm':
150 // FIXME: more freedom is actually permitted for 'm'. We can go
151 // hunting for a base and an offset if we want. Of course, since
152 // we don't really know how the operand is going to be used we're
153 // probably restricted to the load/store pair's simm7 as an offset
154 // range anyway.
155 case 'Q':
156 OutOps.push_back(Op);
157 }
158
159 return false;
160}
161
162bool
163AArch64DAGToDAGISel::SelectFPZeroOperand(SDValue N, SDValue &Dummy) {
164 ConstantFPSDNode *Imm = dyn_cast<ConstantFPSDNode>(N);
165 if (!Imm || !Imm->getValueAPF().isPosZero())
166 return false;
Tim Northoverdfe076a2013-02-05 13:24:56 +0000167
Tim Northover72062f52013-01-31 12:12:40 +0000168 // Doesn't actually carry any information, but keeps TableGen quiet.
169 Dummy = CurDAG->getTargetConstant(0, MVT::i32);
170 return true;
171}
172
173bool AArch64DAGToDAGISel::SelectLogicalImm(SDValue N, SDValue &Imm) {
174 uint32_t Bits;
175 uint32_t RegWidth = N.getValueType().getSizeInBits();
176
177 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);
178 if (!CN) return false;
179
180 if (!A64Imms::isLogicalImm(RegWidth, CN->getZExtValue(), Bits))
181 return false;
182
183 Imm = CurDAG->getTargetConstant(Bits, MVT::i32);
184 return true;
185}
186
187SDNode *AArch64DAGToDAGISel::TrySelectToMoveImm(SDNode *Node) {
188 SDNode *ResNode;
189 DebugLoc dl = Node->getDebugLoc();
190 EVT DestType = Node->getValueType(0);
191 unsigned DestWidth = DestType.getSizeInBits();
192
193 unsigned MOVOpcode;
194 EVT MOVType;
195 int UImm16, Shift;
196 uint32_t LogicalBits;
197
198 uint64_t BitPat = cast<ConstantSDNode>(Node)->getZExtValue();
199 if (A64Imms::isMOVZImm(DestWidth, BitPat, UImm16, Shift)) {
200 MOVType = DestType;
201 MOVOpcode = DestWidth == 64 ? AArch64::MOVZxii : AArch64::MOVZwii;
202 } else if (A64Imms::isMOVNImm(DestWidth, BitPat, UImm16, Shift)) {
203 MOVType = DestType;
204 MOVOpcode = DestWidth == 64 ? AArch64::MOVNxii : AArch64::MOVNwii;
205 } else if (DestWidth == 64 && A64Imms::isMOVNImm(32, BitPat, UImm16, Shift)) {
206 // To get something like 0x0000_0000_ffff_1234 into a 64-bit register we can
207 // use a 32-bit instruction: "movn w0, 0xedbc".
208 MOVType = MVT::i32;
209 MOVOpcode = AArch64::MOVNwii;
210 } else if (A64Imms::isLogicalImm(DestWidth, BitPat, LogicalBits)) {
211 MOVOpcode = DestWidth == 64 ? AArch64::ORRxxi : AArch64::ORRwwi;
212 uint16_t ZR = DestWidth == 64 ? AArch64::XZR : AArch64::WZR;
213
214 return CurDAG->getMachineNode(MOVOpcode, dl, DestType,
215 CurDAG->getRegister(ZR, DestType),
216 CurDAG->getTargetConstant(LogicalBits, MVT::i32));
217 } else {
218 // Can't handle it in one instruction. There's scope for permitting two (or
219 // more) instructions, but that'll need more thought.
220 return NULL;
221 }
222
223 ResNode = CurDAG->getMachineNode(MOVOpcode, dl, MOVType,
224 CurDAG->getTargetConstant(UImm16, MVT::i32),
225 CurDAG->getTargetConstant(Shift, MVT::i32));
226
227 if (MOVType != DestType) {
228 ResNode = CurDAG->getMachineNode(TargetOpcode::SUBREG_TO_REG, dl,
229 MVT::i64, MVT::i32, MVT::Other,
230 CurDAG->getTargetConstant(0, MVT::i64),
231 SDValue(ResNode, 0),
232 CurDAG->getTargetConstant(AArch64::sub_32, MVT::i32));
233 }
234
235 return ResNode;
236}
237
238SDNode *AArch64DAGToDAGISel::SelectToLitPool(SDNode *Node) {
Tim Northover1e883932013-02-15 09:33:43 +0000239 DebugLoc DL = Node->getDebugLoc();
Tim Northover72062f52013-01-31 12:12:40 +0000240 uint64_t UnsignedVal = cast<ConstantSDNode>(Node)->getZExtValue();
241 int64_t SignedVal = cast<ConstantSDNode>(Node)->getSExtValue();
242 EVT DestType = Node->getValueType(0);
Tim Northover1e883932013-02-15 09:33:43 +0000243 EVT PtrVT = TLI.getPointerTy();
Tim Northover72062f52013-01-31 12:12:40 +0000244
245 // Since we may end up loading a 64-bit constant from a 32-bit entry the
246 // constant in the pool may have a different type to the eventual node.
Tim Northover1e883932013-02-15 09:33:43 +0000247 ISD::LoadExtType Extension;
248 EVT MemType;
Tim Northover72062f52013-01-31 12:12:40 +0000249
250 assert((DestType == MVT::i64 || DestType == MVT::i32)
251 && "Only expect integer constants at the moment");
252
Tim Northover1e883932013-02-15 09:33:43 +0000253 if (DestType == MVT::i32) {
254 Extension = ISD::NON_EXTLOAD;
255 MemType = MVT::i32;
256 } else if (UnsignedVal <= UINT32_MAX) {
257 Extension = ISD::ZEXTLOAD;
258 MemType = MVT::i32;
Tim Northover72062f52013-01-31 12:12:40 +0000259 } else if (SignedVal >= INT32_MIN && SignedVal <= INT32_MAX) {
Tim Northover1e883932013-02-15 09:33:43 +0000260 Extension = ISD::SEXTLOAD;
261 MemType = MVT::i32;
Tim Northover72062f52013-01-31 12:12:40 +0000262 } else {
Tim Northover1e883932013-02-15 09:33:43 +0000263 Extension = ISD::NON_EXTLOAD;
264 MemType = MVT::i64;
Tim Northover72062f52013-01-31 12:12:40 +0000265 }
266
Tim Northover1e883932013-02-15 09:33:43 +0000267 Constant *CV = ConstantInt::get(Type::getIntNTy(*CurDAG->getContext(),
268 MemType.getSizeInBits()),
269 UnsignedVal);
270 SDValue PoolAddr;
271 unsigned Alignment = TLI.getDataLayout()->getABITypeAlignment(CV->getType());
272 PoolAddr = CurDAG->getNode(AArch64ISD::WrapperSmall, DL, PtrVT,
273 CurDAG->getTargetConstantPool(CV, PtrVT, 0, 0,
274 AArch64II::MO_NO_FLAG),
275 CurDAG->getTargetConstantPool(CV, PtrVT, 0, 0,
276 AArch64II::MO_LO12),
277 CurDAG->getConstant(Alignment, MVT::i32));
Tim Northover72062f52013-01-31 12:12:40 +0000278
Tim Northover1e883932013-02-15 09:33:43 +0000279 return CurDAG->getExtLoad(Extension, DL, DestType, CurDAG->getEntryNode(),
280 PoolAddr,
281 MachinePointerInfo::getConstantPool(), MemType,
282 /* isVolatile = */ false,
283 /* isNonTemporal = */ false,
284 Alignment).getNode();
Tim Northover72062f52013-01-31 12:12:40 +0000285}
286
Tim Northover1e883932013-02-15 09:33:43 +0000287SDNode *AArch64DAGToDAGISel::LowerToFPLitPool(SDNode *Node) {
288 DebugLoc DL = Node->getDebugLoc();
Tim Northover72062f52013-01-31 12:12:40 +0000289 const ConstantFP *FV = cast<ConstantFPSDNode>(Node)->getConstantFPValue();
Tim Northover1e883932013-02-15 09:33:43 +0000290 EVT PtrVT = TLI.getPointerTy();
Tim Northover72062f52013-01-31 12:12:40 +0000291 EVT DestType = Node->getValueType(0);
292
Tim Northover1e883932013-02-15 09:33:43 +0000293 unsigned Alignment = TLI.getDataLayout()->getABITypeAlignment(FV->getType());
294 SDValue PoolAddr;
Tim Northover72062f52013-01-31 12:12:40 +0000295
Tim Northover1e883932013-02-15 09:33:43 +0000296 assert(TM.getCodeModel() == CodeModel::Small &&
297 "Only small code model supported");
298 PoolAddr = CurDAG->getNode(AArch64ISD::WrapperSmall, DL, PtrVT,
299 CurDAG->getTargetConstantPool(FV, PtrVT, 0, 0,
300 AArch64II::MO_NO_FLAG),
301 CurDAG->getTargetConstantPool(FV, PtrVT, 0, 0,
302 AArch64II::MO_LO12),
303 CurDAG->getConstant(Alignment, MVT::i32));
Tim Northover72062f52013-01-31 12:12:40 +0000304
Tim Northover1e883932013-02-15 09:33:43 +0000305 return CurDAG->getLoad(DestType, DL, CurDAG->getEntryNode(), PoolAddr,
306 MachinePointerInfo::getConstantPool(),
307 /* isVolatile = */ false,
308 /* isNonTemporal = */ false,
309 /* isInvariant = */ true,
310 Alignment).getNode();
Tim Northover72062f52013-01-31 12:12:40 +0000311}
312
313bool
314AArch64DAGToDAGISel::SelectTSTBOperand(SDValue N, SDValue &FixedPos,
315 unsigned RegWidth) {
316 const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);
317 if (!CN) return false;
318
319 uint64_t Val = CN->getZExtValue();
320
321 if (!isPowerOf2_64(Val)) return false;
322
323 unsigned TestedBit = Log2_64(Val);
324 // Checks above should have guaranteed that we haven't lost information in
325 // finding TestedBit, but it must still be in range.
326 if (TestedBit >= RegWidth) return false;
327
328 FixedPos = CurDAG->getTargetConstant(TestedBit, MVT::i64);
329 return true;
330}
331
Tim Northover211ffd22013-04-08 08:40:41 +0000332SDNode *AArch64DAGToDAGISel::SelectAtomic(SDNode *Node, unsigned Op8,
333 unsigned Op16,unsigned Op32,
334 unsigned Op64) {
335 // Mostly direct translation to the given operations, except that we preserve
336 // the AtomicOrdering for use later on.
337 AtomicSDNode *AN = cast<AtomicSDNode>(Node);
338 EVT VT = AN->getMemoryVT();
339
340 unsigned Op;
341 if (VT == MVT::i8)
342 Op = Op8;
343 else if (VT == MVT::i16)
344 Op = Op16;
345 else if (VT == MVT::i32)
346 Op = Op32;
347 else if (VT == MVT::i64)
348 Op = Op64;
349 else
350 llvm_unreachable("Unexpected atomic operation");
351
352 SmallVector<SDValue, 4> Ops;
353 for (unsigned i = 1; i < AN->getNumOperands(); ++i)
354 Ops.push_back(AN->getOperand(i));
355
356 Ops.push_back(CurDAG->getTargetConstant(AN->getOrdering(), MVT::i32));
357 Ops.push_back(AN->getOperand(0)); // Chain moves to the end
358
359 return CurDAG->SelectNodeTo(Node, Op,
360 AN->getValueType(0), MVT::Other,
361 &Ops[0], Ops.size());
362}
363
Tim Northover72062f52013-01-31 12:12:40 +0000364SDNode *AArch64DAGToDAGISel::Select(SDNode *Node) {
365 // Dump information about the Node being selected
366 DEBUG(dbgs() << "Selecting: "; Node->dump(CurDAG); dbgs() << "\n");
367
368 if (Node->isMachineOpcode()) {
369 DEBUG(dbgs() << "== "; Node->dump(CurDAG); dbgs() << "\n");
370 return NULL;
371 }
372
373 switch (Node->getOpcode()) {
Tim Northover211ffd22013-04-08 08:40:41 +0000374 case ISD::ATOMIC_LOAD_ADD:
375 return SelectAtomic(Node,
376 AArch64::ATOMIC_LOAD_ADD_I8,
377 AArch64::ATOMIC_LOAD_ADD_I16,
378 AArch64::ATOMIC_LOAD_ADD_I32,
379 AArch64::ATOMIC_LOAD_ADD_I64);
380 case ISD::ATOMIC_LOAD_SUB:
381 return SelectAtomic(Node,
382 AArch64::ATOMIC_LOAD_SUB_I8,
383 AArch64::ATOMIC_LOAD_SUB_I16,
384 AArch64::ATOMIC_LOAD_SUB_I32,
385 AArch64::ATOMIC_LOAD_SUB_I64);
386 case ISD::ATOMIC_LOAD_AND:
387 return SelectAtomic(Node,
388 AArch64::ATOMIC_LOAD_AND_I8,
389 AArch64::ATOMIC_LOAD_AND_I16,
390 AArch64::ATOMIC_LOAD_AND_I32,
391 AArch64::ATOMIC_LOAD_AND_I64);
392 case ISD::ATOMIC_LOAD_OR:
393 return SelectAtomic(Node,
394 AArch64::ATOMIC_LOAD_OR_I8,
395 AArch64::ATOMIC_LOAD_OR_I16,
396 AArch64::ATOMIC_LOAD_OR_I32,
397 AArch64::ATOMIC_LOAD_OR_I64);
398 case ISD::ATOMIC_LOAD_XOR:
399 return SelectAtomic(Node,
400 AArch64::ATOMIC_LOAD_XOR_I8,
401 AArch64::ATOMIC_LOAD_XOR_I16,
402 AArch64::ATOMIC_LOAD_XOR_I32,
403 AArch64::ATOMIC_LOAD_XOR_I64);
404 case ISD::ATOMIC_LOAD_NAND:
405 return SelectAtomic(Node,
406 AArch64::ATOMIC_LOAD_NAND_I8,
407 AArch64::ATOMIC_LOAD_NAND_I16,
408 AArch64::ATOMIC_LOAD_NAND_I32,
409 AArch64::ATOMIC_LOAD_NAND_I64);
410 case ISD::ATOMIC_LOAD_MIN:
411 return SelectAtomic(Node,
412 AArch64::ATOMIC_LOAD_MIN_I8,
413 AArch64::ATOMIC_LOAD_MIN_I16,
414 AArch64::ATOMIC_LOAD_MIN_I32,
415 AArch64::ATOMIC_LOAD_MIN_I64);
416 case ISD::ATOMIC_LOAD_MAX:
417 return SelectAtomic(Node,
418 AArch64::ATOMIC_LOAD_MAX_I8,
419 AArch64::ATOMIC_LOAD_MAX_I16,
420 AArch64::ATOMIC_LOAD_MAX_I32,
421 AArch64::ATOMIC_LOAD_MAX_I64);
422 case ISD::ATOMIC_LOAD_UMIN:
423 return SelectAtomic(Node,
424 AArch64::ATOMIC_LOAD_UMIN_I8,
425 AArch64::ATOMIC_LOAD_UMIN_I16,
426 AArch64::ATOMIC_LOAD_UMIN_I32,
427 AArch64::ATOMIC_LOAD_UMIN_I64);
428 case ISD::ATOMIC_LOAD_UMAX:
429 return SelectAtomic(Node,
430 AArch64::ATOMIC_LOAD_UMAX_I8,
431 AArch64::ATOMIC_LOAD_UMAX_I16,
432 AArch64::ATOMIC_LOAD_UMAX_I32,
433 AArch64::ATOMIC_LOAD_UMAX_I64);
434 case ISD::ATOMIC_SWAP:
435 return SelectAtomic(Node,
436 AArch64::ATOMIC_SWAP_I8,
437 AArch64::ATOMIC_SWAP_I16,
438 AArch64::ATOMIC_SWAP_I32,
439 AArch64::ATOMIC_SWAP_I64);
440 case ISD::ATOMIC_CMP_SWAP:
441 return SelectAtomic(Node,
442 AArch64::ATOMIC_CMP_SWAP_I8,
443 AArch64::ATOMIC_CMP_SWAP_I16,
444 AArch64::ATOMIC_CMP_SWAP_I32,
445 AArch64::ATOMIC_CMP_SWAP_I64);
Tim Northover72062f52013-01-31 12:12:40 +0000446 case ISD::FrameIndex: {
447 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
448 EVT PtrTy = TLI.getPointerTy();
449 SDValue TFI = CurDAG->getTargetFrameIndex(FI, PtrTy);
450 return CurDAG->SelectNodeTo(Node, AArch64::ADDxxi_lsl0_s, PtrTy,
451 TFI, CurDAG->getTargetConstant(0, PtrTy));
452 }
453 case ISD::ConstantPool: {
454 // Constant pools are fine, just create a Target entry.
455 ConstantPoolSDNode *CN = cast<ConstantPoolSDNode>(Node);
456 const Constant *C = CN->getConstVal();
457 SDValue CP = CurDAG->getTargetConstantPool(C, CN->getValueType(0));
458
459 ReplaceUses(SDValue(Node, 0), CP);
460 return NULL;
461 }
462 case ISD::Constant: {
463 SDNode *ResNode = 0;
464 if (cast<ConstantSDNode>(Node)->getZExtValue() == 0) {
465 // XZR and WZR are probably even better than an actual move: most of the
466 // time they can be folded into another instruction with *no* cost.
467
468 EVT Ty = Node->getValueType(0);
469 assert((Ty == MVT::i32 || Ty == MVT::i64) && "unexpected type");
470 uint16_t Register = Ty == MVT::i32 ? AArch64::WZR : AArch64::XZR;
471 ResNode = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
472 Node->getDebugLoc(),
473 Register, Ty).getNode();
474 }
475
476 // Next best option is a move-immediate, see if we can do that.
477 if (!ResNode) {
478 ResNode = TrySelectToMoveImm(Node);
479 }
480
Tim Northover1e883932013-02-15 09:33:43 +0000481 if (ResNode)
482 return ResNode;
Tim Northover72062f52013-01-31 12:12:40 +0000483
Tim Northover1e883932013-02-15 09:33:43 +0000484 // If even that fails we fall back to a lit-pool entry at the moment. Future
485 // tuning may change this to a sequence of MOVZ/MOVN/MOVK instructions.
486 ResNode = SelectToLitPool(Node);
Tim Northover72062f52013-01-31 12:12:40 +0000487 assert(ResNode && "We need *some* way to materialise a constant");
488
Tim Northover1e883932013-02-15 09:33:43 +0000489 // We want to continue selection at this point since the litpool access
490 // generated used generic nodes for simplicity.
Tim Northover72062f52013-01-31 12:12:40 +0000491 ReplaceUses(SDValue(Node, 0), SDValue(ResNode, 0));
Tim Northover1e883932013-02-15 09:33:43 +0000492 Node = ResNode;
493 break;
Tim Northover72062f52013-01-31 12:12:40 +0000494 }
495 case ISD::ConstantFP: {
496 if (A64Imms::isFPImm(cast<ConstantFPSDNode>(Node)->getValueAPF())) {
497 // FMOV will take care of it from TableGen
498 break;
499 }
500
Tim Northover1e883932013-02-15 09:33:43 +0000501 SDNode *ResNode = LowerToFPLitPool(Node);
Tim Northover72062f52013-01-31 12:12:40 +0000502 ReplaceUses(SDValue(Node, 0), SDValue(ResNode, 0));
Tim Northover1e883932013-02-15 09:33:43 +0000503
504 // We want to continue selection at this point since the litpool access
505 // generated used generic nodes for simplicity.
506 Node = ResNode;
507 break;
Tim Northover72062f52013-01-31 12:12:40 +0000508 }
509 default:
510 break; // Let generic code handle it
511 }
512
513 SDNode *ResNode = SelectCode(Node);
514
515 DEBUG(dbgs() << "=> ";
516 if (ResNode == NULL || ResNode == Node)
517 Node->dump(CurDAG);
518 else
519 ResNode->dump(CurDAG);
520 dbgs() << "\n");
521
522 return ResNode;
523}
524
525/// This pass converts a legalized DAG into a AArch64-specific DAG, ready for
526/// instruction scheduling.
527FunctionPass *llvm::createAArch64ISelDAG(AArch64TargetMachine &TM,
528 CodeGenOpt::Level OptLevel) {
529 return new AArch64DAGToDAGISel(TM, OptLevel);
530}