blob: b3c910a3d74d7450f3b6f667e732561f66a8dc6a [file] [log] [blame]
Scott Michel266bc8f2007-12-04 22:23:35 +00001//===-- SPUISelDAGToDAG.cpp - CellSPU -pattern matching inst selector -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by a team from the Computer Systems Research
Scott Michel2466c372007-12-05 01:40:25 +00006// Department at The Aerospace Corporation and is distributed under the
7// University of Illinois Open Source License. See LICENSE.TXT for details.
Scott Michel266bc8f2007-12-04 22:23:35 +00008//
9//===----------------------------------------------------------------------===//
10//
11// This file defines a pattern matching instruction selector for the Cell SPU,
12// converting from a legalized dag to a SPU-target dag.
13//
14//===----------------------------------------------------------------------===//
15
16#include "SPU.h"
17#include "SPUTargetMachine.h"
18#include "SPUISelLowering.h"
19#include "SPUHazardRecognizers.h"
20#include "SPUFrameInfo.h"
21#include "llvm/CodeGen/MachineConstantPool.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/SSARegMap.h"
25#include "llvm/CodeGen/SelectionDAG.h"
26#include "llvm/CodeGen/SelectionDAGISel.h"
27#include "llvm/Target/TargetOptions.h"
28#include "llvm/ADT/Statistic.h"
29#include "llvm/Constants.h"
30#include "llvm/GlobalValue.h"
31#include "llvm/Intrinsics.h"
32#include "llvm/Support/Debug.h"
33#include "llvm/Support/MathExtras.h"
34#include "llvm/Support/Compiler.h"
35#include <iostream>
36#include <queue>
37#include <set>
38
39using namespace llvm;
40
41namespace {
42 //! ConstantSDNode predicate for i32 sign-extended, 10-bit immediates
43 bool
44 isI64IntS10Immediate(ConstantSDNode *CN)
45 {
46 return isS10Constant(CN->getValue());
47 }
48
49 //! ConstantSDNode predicate for i32 sign-extended, 10-bit immediates
50 bool
51 isI32IntS10Immediate(ConstantSDNode *CN)
52 {
53 return isS10Constant((int) CN->getValue());
54 }
55
56#if 0
57 //! SDNode predicate for sign-extended, 10-bit immediate values
58 bool
59 isI32IntS10Immediate(SDNode *N)
60 {
61 return (N->getOpcode() == ISD::Constant
62 && isI32IntS10Immediate(cast<ConstantSDNode>(N)));
63 }
64#endif
65
Scott Michel504c3692007-12-17 22:32:34 +000066 //! ConstantSDNode predicate for i32 unsigned 10-bit immediate values
67 bool
68 isI32IntU10Immediate(ConstantSDNode *CN)
69 {
70 return isU10Constant((int) CN->getValue());
71 }
72
Scott Michel266bc8f2007-12-04 22:23:35 +000073 //! ConstantSDNode predicate for i16 sign-extended, 10-bit immediate values
74 bool
75 isI16IntS10Immediate(ConstantSDNode *CN)
76 {
77 return isS10Constant((short) CN->getValue());
78 }
79
80 //! SDNode predicate for i16 sign-extended, 10-bit immediate values
81 bool
82 isI16IntS10Immediate(SDNode *N)
83 {
84 return (N->getOpcode() == ISD::Constant
85 && isI16IntS10Immediate(cast<ConstantSDNode>(N)));
86 }
87
Scott Michelec2a08f2007-12-15 00:38:50 +000088 //! ConstantSDNode predicate for i16 unsigned 10-bit immediate values
89 bool
90 isI16IntU10Immediate(ConstantSDNode *CN)
91 {
92 return isU10Constant((short) CN->getValue());
93 }
94
95 //! SDNode predicate for i16 sign-extended, 10-bit immediate values
96 bool
97 isI16IntU10Immediate(SDNode *N)
98 {
99 return (N->getOpcode() == ISD::Constant
100 && isI16IntU10Immediate(cast<ConstantSDNode>(N)));
101 }
102
Scott Michel266bc8f2007-12-04 22:23:35 +0000103 //! ConstantSDNode predicate for signed 16-bit values
104 /*!
105 \arg CN The constant SelectionDAG node holding the value
106 \arg Imm The returned 16-bit value, if returning true
107
108 This predicate tests the value in \a CN to see whether it can be
109 represented as a 16-bit, sign-extended quantity. Returns true if
110 this is the case.
111 */
112 bool
113 isIntS16Immediate(ConstantSDNode *CN, short &Imm)
114 {
115 MVT::ValueType vt = CN->getValueType(0);
116 Imm = (short) CN->getValue();
117 if (vt >= MVT::i1 && vt <= MVT::i16) {
118 return true;
119 } else if (vt == MVT::i32) {
120 int32_t i_val = (int32_t) CN->getValue();
121 short s_val = (short) i_val;
122 return i_val == s_val;
123 } else {
124 int64_t i_val = (int64_t) CN->getValue();
125 short s_val = (short) i_val;
126 return i_val == s_val;
127 }
128
129 return false;
130 }
131
132 //! SDNode predicate for signed 16-bit values.
133 bool
134 isIntS16Immediate(SDNode *N, short &Imm)
135 {
136 return (N->getOpcode() == ISD::Constant
137 && isIntS16Immediate(cast<ConstantSDNode>(N), Imm));
138 }
139
140 //! ConstantFPSDNode predicate for representing floats as 16-bit sign ext.
141 static bool
142 isFPS16Immediate(ConstantFPSDNode *FPN, short &Imm)
143 {
144 MVT::ValueType vt = FPN->getValueType(0);
145 if (vt == MVT::f32) {
Chris Lattnerd3ada752007-12-22 22:45:38 +0000146 int val = FloatToBits(FPN->getValueAPF().convertToFloat());
Scott Michel266bc8f2007-12-04 22:23:35 +0000147 int sval = (int) ((val << 16) >> 16);
148 Imm = (short) val;
149 return val == sval;
150 }
151
152 return false;
153 }
154
155 //===------------------------------------------------------------------===//
Scott Michel86c041f2007-12-20 00:44:13 +0000156 //! MVT::ValueType to "useful stuff" mapping structure:
Scott Michel266bc8f2007-12-04 22:23:35 +0000157
158 struct valtype_map_s {
159 MVT::ValueType VT;
160 unsigned ldresult_ins; /// LDRESULT instruction (0 = undefined)
161 int prefslot_byte; /// Byte offset of the "preferred" slot
162 unsigned brcc_eq_ins; /// br_cc equal instruction
163 unsigned brcc_neq_ins; /// br_cc not equal instruction
164 };
165
166 const valtype_map_s valtype_map[] = {
Scott Michel86c041f2007-12-20 00:44:13 +0000167 { MVT::i1, 0, 3, 0, 0 },
168 { MVT::i8, 0, 3, 0, 0 },
169 { MVT::i16, SPU::ORHIr16, 2, SPU::BRHZ, SPU::BRHNZ },
170 { MVT::i32, SPU::ORIr32, 0, SPU::BRZ, SPU::BRNZ },
171 { MVT::i64, SPU::ORIr64, 0, 0, 0 },
172 { MVT::f32, 0, 0, 0, 0 },
173 { MVT::f64, 0, 0, 0, 0 }
Scott Michel266bc8f2007-12-04 22:23:35 +0000174 };
175
176 const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]);
177
178 const valtype_map_s *getValueTypeMapEntry(MVT::ValueType VT)
179 {
180 const valtype_map_s *retval = 0;
181 for (size_t i = 0; i < n_valtype_map; ++i) {
182 if (valtype_map[i].VT == VT) {
183 retval = valtype_map + i;
184 break;
185 }
186 }
187
188
189#ifndef NDEBUG
190 if (retval == 0) {
191 cerr << "SPUISelDAGToDAG.cpp: getValueTypeMapEntry returns NULL for "
192 << MVT::getValueTypeString(VT)
193 << "\n";
194 abort();
195 }
196#endif
197
198 return retval;
199 }
200}
201
202//===--------------------------------------------------------------------===//
203/// SPUDAGToDAGISel - Cell SPU-specific code to select SPU machine
204/// instructions for SelectionDAG operations.
205///
206class SPUDAGToDAGISel :
207 public SelectionDAGISel
208{
209 SPUTargetMachine &TM;
210 SPUTargetLowering &SPUtli;
211 unsigned GlobalBaseReg;
212
213public:
214 SPUDAGToDAGISel(SPUTargetMachine &tm) :
215 SelectionDAGISel(*tm.getTargetLowering()),
216 TM(tm),
217 SPUtli(*tm.getTargetLowering())
218 {}
219
220 virtual bool runOnFunction(Function &Fn) {
221 // Make sure we re-emit a set of the global base reg if necessary
222 GlobalBaseReg = 0;
223 SelectionDAGISel::runOnFunction(Fn);
224 return true;
225 }
226
227 /// getI32Imm - Return a target constant with the specified value, of type
228 /// i32.
229 inline SDOperand getI32Imm(uint32_t Imm) {
230 return CurDAG->getTargetConstant(Imm, MVT::i32);
231 }
232
233 /// getI64Imm - Return a target constant with the specified value, of type
234 /// i64.
235 inline SDOperand getI64Imm(uint64_t Imm) {
236 return CurDAG->getTargetConstant(Imm, MVT::i64);
237 }
238
239 /// getSmallIPtrImm - Return a target constant of pointer type.
240 inline SDOperand getSmallIPtrImm(unsigned Imm) {
241 return CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy());
242 }
243
244 /// Select - Convert the specified operand from a target-independent to a
245 /// target-specific node if it hasn't already been changed.
246 SDNode *Select(SDOperand Op);
247
248 /// Return true if the address N is a RI7 format address [r+imm]
249 bool SelectDForm2Addr(SDOperand Op, SDOperand N, SDOperand &Disp,
250 SDOperand &Base);
251
252 //! Returns true if the address N is an A-form (local store) address
253 bool SelectAFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
254 SDOperand &Index);
255
256 //! D-form address predicate
257 bool SelectDFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
258 SDOperand &Index);
259
260 //! Address predicate if N can be expressed as an indexed [r+r] operation.
261 bool SelectXFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
262 SDOperand &Index);
263
264 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
265 /// inline asm expressions.
266 virtual bool SelectInlineAsmMemoryOperand(const SDOperand &Op,
267 char ConstraintCode,
268 std::vector<SDOperand> &OutOps,
269 SelectionDAG &DAG) {
270 SDOperand Op0, Op1;
271 switch (ConstraintCode) {
272 default: return true;
273 case 'm': // memory
274 if (!SelectDFormAddr(Op, Op, Op0, Op1)
275 && !SelectAFormAddr(Op, Op, Op0, Op1))
276 SelectXFormAddr(Op, Op, Op0, Op1);
277 break;
278 case 'o': // offsetable
279 if (!SelectDFormAddr(Op, Op, Op0, Op1)
280 && !SelectAFormAddr(Op, Op, Op0, Op1)) {
281 Op0 = Op;
282 AddToISelQueue(Op0); // r+0.
283 Op1 = getSmallIPtrImm(0);
284 }
285 break;
286 case 'v': // not offsetable
287#if 1
288 assert(0 && "InlineAsmMemoryOperand 'v' constraint not handled.");
289#else
290 SelectAddrIdxOnly(Op, Op, Op0, Op1);
291#endif
292 break;
293 }
294
295 OutOps.push_back(Op0);
296 OutOps.push_back(Op1);
297 return false;
298 }
299
300 /// InstructionSelectBasicBlock - This callback is invoked by
301 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
302 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
303
304 virtual const char *getPassName() const {
305 return "Cell SPU DAG->DAG Pattern Instruction Selection";
306 }
307
308 /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
309 /// this target when scheduling the DAG.
310 virtual HazardRecognizer *CreateTargetHazardRecognizer() {
311 const TargetInstrInfo *II = SPUtli.getTargetMachine().getInstrInfo();
312 assert(II && "No InstrInfo?");
313 return new SPUHazardRecognizer(*II);
314 }
315
316 // Include the pieces autogenerated from the target description.
317#include "SPUGenDAGISel.inc"
318};
319
320/// InstructionSelectBasicBlock - This callback is invoked by
321/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
322void
323SPUDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG)
324{
325 DEBUG(BB->dump());
326
327 // Select target instructions for the DAG.
328 DAG.setRoot(SelectRoot(DAG.getRoot()));
329 DAG.RemoveDeadNodes();
330
331 // Emit machine code to BB.
332 ScheduleAndEmitDAG(DAG);
333}
334
335bool
336SPUDAGToDAGISel::SelectDForm2Addr(SDOperand Op, SDOperand N, SDOperand &Disp,
337 SDOperand &Base) {
338 unsigned Opc = N.getOpcode();
339 unsigned VT = N.getValueType();
340 MVT::ValueType PtrVT = SPUtli.getPointerTy();
341 ConstantSDNode *CN = 0;
342 int Imm;
343
344 if (Opc == ISD::ADD) {
345 SDOperand Op0 = N.getOperand(0);
346 SDOperand Op1 = N.getOperand(1);
347 if (Op1.getOpcode() == ISD::Constant ||
348 Op1.getOpcode() == ISD::TargetConstant) {
349 CN = cast<ConstantSDNode>(Op1);
350 Imm = int(CN->getValue());
351 if (Imm <= 0xff) {
352 Disp = CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy());
353 Base = Op0;
354 return true;
355 }
356 }
357 } else if (Opc == ISD::GlobalAddress
358 || Opc == ISD::TargetGlobalAddress
359 || Opc == ISD::Register) {
360 // Plain old local store address:
361 Disp = CurDAG->getTargetConstant(0, VT);
362 Base = N;
363 return true;
364 } else if (Opc == SPUISD::DFormAddr) {
365 // D-Form address: This is pretty straightforward, naturally...
366 CN = cast<ConstantSDNode>(N.getOperand(1));
367 assert(CN != 0 && "SelectDFormAddr/SPUISD::DForm2Addr expecting constant");
368 Imm = unsigned(CN->getValue());
369 if (Imm < 0xff) {
370 Disp = CurDAG->getTargetConstant(CN->getValue(), PtrVT);
371 Base = N.getOperand(0);
372 return true;
373 }
374 }
375
376 return false;
377}
378
379/*!
380 \arg Op The ISD instructio operand
381 \arg N The address to be tested
382 \arg Base The base address
383 \arg Index The base address index
384 */
385bool
386SPUDAGToDAGISel::SelectAFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
387 SDOperand &Index) {
388 // These match the addr256k operand type:
389 MVT::ValueType PtrVT = SPUtli.getPointerTy();
390 MVT::ValueType OffsVT = MVT::i16;
391
392 switch (N.getOpcode()) {
393 case ISD::Constant:
394 case ISD::TargetConstant: {
395 // Loading from a constant address.
396 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);
397 int Imm = (int)CN->getValue();
398 if (Imm < 0x3ffff && (Imm & 0x3) == 0) {
399 Base = CurDAG->getTargetConstant(Imm, PtrVT);
400 // Note that this operand will be ignored by the assembly printer...
401 Index = CurDAG->getTargetConstant(0, OffsVT);
402 return true;
403 }
404 }
405 case ISD::ConstantPool:
406 case ISD::TargetConstantPool: {
407 // The constant pool address is N. Base is a dummy that will be ignored by
408 // the assembly printer.
409 Base = N;
410 Index = CurDAG->getTargetConstant(0, OffsVT);
411 return true;
412 }
413
414 case ISD::GlobalAddress:
415 case ISD::TargetGlobalAddress: {
416 // The global address is N. Base is a dummy that is ignored by the
417 // assembly printer.
418 Base = N;
419 Index = CurDAG->getTargetConstant(0, OffsVT);
420 return true;
421 }
422 }
423
424 return false;
425}
426
427/*!
428 \arg Op The ISD instruction (ignored)
429 \arg N The address to be tested
430 \arg Base Base address register/pointer
431 \arg Index Base address index
432
433 Examine the input address by a base register plus a signed 10-bit
434 displacement, [r+I10] (D-form address).
435
436 \return true if \a N is a D-form address with \a Base and \a Index set
437 to non-empty SDOperand instances.
438*/
439bool
440SPUDAGToDAGISel::SelectDFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
441 SDOperand &Index) {
442 unsigned Opc = N.getOpcode();
443 unsigned PtrTy = SPUtli.getPointerTy();
444
445 if (Opc == ISD::Register) {
446 Base = N;
447 Index = CurDAG->getTargetConstant(0, PtrTy);
448 return true;
449 } else if (Opc == ISD::FrameIndex) {
450 // Stack frame index must be less than 512 (divided by 16):
451 FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N);
452 DEBUG(cerr << "SelectDFormAddr: ISD::FrameIndex = "
453 << FI->getIndex() << "\n");
454 if (FI->getIndex() < SPUFrameInfo::maxFrameOffset()) {
455 Base = CurDAG->getTargetConstant(0, PtrTy);
456 Index = CurDAG->getTargetFrameIndex(FI->getIndex(), PtrTy);
457 return true;
458 }
459 } else if (Opc == ISD::ADD) {
460 // Generated by getelementptr
461 const SDOperand Op0 = N.getOperand(0); // Frame index/base
462 const SDOperand Op1 = N.getOperand(1); // Offset within base
463 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op1);
464
465 // Not a constant?
466 if (CN == 0)
467 return false;
468
469 int32_t offset = (int32_t) CN->getSignExtended();
470 unsigned Opc0 = Op0.getOpcode();
471
472 if ((offset & 0xf) != 0) {
473 cerr << "SelectDFormAddr: unaligned offset = " << offset << "\n";
474 abort();
475 /*NOTREACHED*/
476 }
477
478 if (Opc0 == ISD::FrameIndex) {
479 FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op0);
480 DEBUG(cerr << "SelectDFormAddr: ISD::ADD offset = " << offset
481 << " frame index = " << FI->getIndex() << "\n");
482
483 if (FI->getIndex() < SPUFrameInfo::maxFrameOffset()) {
484 Base = CurDAG->getTargetConstant(offset, PtrTy);
485 Index = CurDAG->getTargetFrameIndex(FI->getIndex(), PtrTy);
486 return true;
487 }
488 } else if (offset > SPUFrameInfo::minFrameOffset()
489 && offset < SPUFrameInfo::maxFrameOffset()) {
490 Base = CurDAG->getTargetConstant(offset, PtrTy);
491 if (Opc0 == ISD::GlobalAddress) {
492 // Convert global address to target global address
493 GlobalAddressSDNode *GV = dyn_cast<GlobalAddressSDNode>(Op0);
494 Index = CurDAG->getTargetGlobalAddress(GV->getGlobal(), PtrTy);
495 return true;
496 } else {
497 // Otherwise, just take operand 0
498 Index = Op0;
499 return true;
500 }
501 }
502 } else if (Opc == SPUISD::DFormAddr) {
503 // D-Form address: This is pretty straightforward, naturally...
504 ConstantSDNode *CN = cast<ConstantSDNode>(N.getOperand(1));
505 assert(CN != 0 && "SelectDFormAddr/SPUISD::DFormAddr expecting constant");
506 Base = CurDAG->getTargetConstant(CN->getValue(), PtrTy);
507 Index = N.getOperand(0);
508 return true;
509 }
510
511 return false;
512}
513
514/*!
515 \arg Op The ISD instruction operand
516 \arg N The address operand
517 \arg Base The base pointer operand
518 \arg Index The offset/index operand
519
520 If the address \a N can be expressed as a [r + s10imm] address, returns false.
521 Otherwise, creates two operands, Base and Index that will become the [r+r]
522 address.
523*/
524bool
525SPUDAGToDAGISel::SelectXFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
526 SDOperand &Index) {
527 if (SelectAFormAddr(Op, N, Base, Index)
528 || SelectDFormAddr(Op, N, Base, Index))
529 return false;
530
531 unsigned Opc = N.getOpcode();
532
533 if (Opc == ISD::ADD) {
534 SDOperand N1 = N.getOperand(0);
535 SDOperand N2 = N.getOperand(1);
536 unsigned N1Opc = N1.getOpcode();
537 unsigned N2Opc = N2.getOpcode();
538
539 if ((N1Opc == SPUISD::Hi && N2Opc == SPUISD::Lo)
540 || (N1Opc == SPUISD::Lo && N2Opc == SPUISD::Hi)) {
541 Base = N.getOperand(0);
542 Index = N.getOperand(1);
543 return true;
544 } else {
545 cerr << "SelectXFormAddr: Unhandled ADD operands:\n";
546 N1.Val->dump();
547 cerr << "\n";
548 N2.Val->dump();
549 cerr << "\n";
550 abort();
551 /*UNREACHED*/
552 }
553 } else if (N.getNumOperands() == 2) {
554 SDOperand N1 = N.getOperand(0);
555 SDOperand N2 = N.getOperand(1);
556 unsigned N1Opc = N1.getOpcode();
557 unsigned N2Opc = N2.getOpcode();
558
559 if ((N1Opc == ISD::CopyToReg || N1Opc == ISD::Register)
560 && (N2Opc == ISD::CopyToReg || N2Opc == ISD::Register)) {
561 Base = N.getOperand(0);
562 Index = N.getOperand(1);
563 return true;
564 /*UNREACHED*/
565 } else {
566 cerr << "SelectXFormAddr: 2-operand unhandled operand:\n";
567 N.Val->dump();
568 cerr << "\n";
569 abort();
570 /*UNREACHED*/
571 }
572 } else {
573 cerr << "SelectXFormAddr: Unhandled operand type:\n";
574 N.Val->dump();
575 cerr << "\n";
576 abort();
577 /*UNREACHED*/
578 }
579
580 return false;
581}
582
583//! Convert the operand from a target-independent to a target-specific node
584/*!
585 */
586SDNode *
587SPUDAGToDAGISel::Select(SDOperand Op) {
588 SDNode *N = Op.Val;
589 unsigned Opc = N->getOpcode();
590
591 if (Opc >= ISD::BUILTIN_OP_END && Opc < SPUISD::FIRST_NUMBER) {
592 return NULL; // Already selected.
593 } else if (Opc == ISD::FrameIndex) {
594 // Selects to AIr32 FI, 0 which in turn will become AIr32 SP, imm.
595 int FI = cast<FrameIndexSDNode>(N)->getIndex();
596 SDOperand TFI = CurDAG->getTargetFrameIndex(FI, SPUtli.getPointerTy());
597
Scott Michel9999e682007-12-19 07:35:06 +0000598 DEBUG(cerr << "SPUDAGToDAGISel: Replacing FrameIndex with AI32 <FI>, 0\n");
Scott Michel266bc8f2007-12-04 22:23:35 +0000599 return CurDAG->SelectNodeTo(N, SPU::AIr32, Op.getValueType(), TFI,
600 CurDAG->getTargetConstant(0, MVT::i32));
601 } else if (Opc == SPUISD::LDRESULT) {
602 // Custom select instructions for LDRESULT
603 unsigned VT = N->getValueType(0);
604 SDOperand Arg = N->getOperand(0);
605 SDOperand Chain = N->getOperand(1);
Scott Michel266bc8f2007-12-04 22:23:35 +0000606 SDNode *Result;
Scott Michel266bc8f2007-12-04 22:23:35 +0000607
608 AddToISelQueue(Arg);
Scott Michel86c041f2007-12-20 00:44:13 +0000609 if (!MVT::isFloatingPoint(VT)) {
610 SDOperand Zero = CurDAG->getTargetConstant(0, VT);
611 const valtype_map_s *vtm = getValueTypeMapEntry(VT);
612
613 if (vtm->ldresult_ins == 0) {
614 cerr << "LDRESULT for unsupported type: "
615 << MVT::getValueTypeString(VT)
616 << "\n";
617 abort();
618 } else
619 Opc = vtm->ldresult_ins;
620
621 AddToISelQueue(Zero);
622 Result = CurDAG->SelectNodeTo(N, Opc, VT, MVT::Other, Arg, Zero, Chain);
623 } else {
624 Result =
625 CurDAG->SelectNodeTo(N, (VT == MVT::f32 ? SPU::ORf32 : SPU::ORf64),
626 MVT::Other, Arg, Arg, Chain);
627 }
628
Scott Michel266bc8f2007-12-04 22:23:35 +0000629 Chain = SDOperand(Result, 1);
Scott Michel86c041f2007-12-20 00:44:13 +0000630 AddToISelQueue(Chain);
631
Scott Michel266bc8f2007-12-04 22:23:35 +0000632 return Result;
633 }
634
635 return SelectCode(Op);
636}
637
638/// createPPCISelDag - This pass converts a legalized DAG into a
639/// SPU-specific DAG, ready for instruction scheduling.
640///
641FunctionPass *llvm::createSPUISelDag(SPUTargetMachine &TM) {
642 return new SPUDAGToDAGISel(TM);
643}