blob: 59de205f945e70a4b92fd5ec9ae79de1208a3199 [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) {
146 const APFloat &apf = FPN->getValueAPF();
147 float fval = apf.convertToFloat();
148 int val = *((int *) &fval);
149 int sval = (int) ((val << 16) >> 16);
150 Imm = (short) val;
151 return val == sval;
152 }
153
154 return false;
155 }
156
157 //===------------------------------------------------------------------===//
Scott Michel86c041f2007-12-20 00:44:13 +0000158 //! MVT::ValueType to "useful stuff" mapping structure:
Scott Michel266bc8f2007-12-04 22:23:35 +0000159
160 struct valtype_map_s {
161 MVT::ValueType VT;
162 unsigned ldresult_ins; /// LDRESULT instruction (0 = undefined)
163 int prefslot_byte; /// Byte offset of the "preferred" slot
164 unsigned brcc_eq_ins; /// br_cc equal instruction
165 unsigned brcc_neq_ins; /// br_cc not equal instruction
166 };
167
168 const valtype_map_s valtype_map[] = {
Scott Michel86c041f2007-12-20 00:44:13 +0000169 { MVT::i1, 0, 3, 0, 0 },
170 { MVT::i8, 0, 3, 0, 0 },
171 { MVT::i16, SPU::ORHIr16, 2, SPU::BRHZ, SPU::BRHNZ },
172 { MVT::i32, SPU::ORIr32, 0, SPU::BRZ, SPU::BRNZ },
173 { MVT::i64, SPU::ORIr64, 0, 0, 0 },
174 { MVT::f32, 0, 0, 0, 0 },
175 { MVT::f64, 0, 0, 0, 0 }
Scott Michel266bc8f2007-12-04 22:23:35 +0000176 };
177
178 const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]);
179
180 const valtype_map_s *getValueTypeMapEntry(MVT::ValueType VT)
181 {
182 const valtype_map_s *retval = 0;
183 for (size_t i = 0; i < n_valtype_map; ++i) {
184 if (valtype_map[i].VT == VT) {
185 retval = valtype_map + i;
186 break;
187 }
188 }
189
190
191#ifndef NDEBUG
192 if (retval == 0) {
193 cerr << "SPUISelDAGToDAG.cpp: getValueTypeMapEntry returns NULL for "
194 << MVT::getValueTypeString(VT)
195 << "\n";
196 abort();
197 }
198#endif
199
200 return retval;
201 }
202}
203
204//===--------------------------------------------------------------------===//
205/// SPUDAGToDAGISel - Cell SPU-specific code to select SPU machine
206/// instructions for SelectionDAG operations.
207///
208class SPUDAGToDAGISel :
209 public SelectionDAGISel
210{
211 SPUTargetMachine &TM;
212 SPUTargetLowering &SPUtli;
213 unsigned GlobalBaseReg;
214
215public:
216 SPUDAGToDAGISel(SPUTargetMachine &tm) :
217 SelectionDAGISel(*tm.getTargetLowering()),
218 TM(tm),
219 SPUtli(*tm.getTargetLowering())
220 {}
221
222 virtual bool runOnFunction(Function &Fn) {
223 // Make sure we re-emit a set of the global base reg if necessary
224 GlobalBaseReg = 0;
225 SelectionDAGISel::runOnFunction(Fn);
226 return true;
227 }
228
229 /// getI32Imm - Return a target constant with the specified value, of type
230 /// i32.
231 inline SDOperand getI32Imm(uint32_t Imm) {
232 return CurDAG->getTargetConstant(Imm, MVT::i32);
233 }
234
235 /// getI64Imm - Return a target constant with the specified value, of type
236 /// i64.
237 inline SDOperand getI64Imm(uint64_t Imm) {
238 return CurDAG->getTargetConstant(Imm, MVT::i64);
239 }
240
241 /// getSmallIPtrImm - Return a target constant of pointer type.
242 inline SDOperand getSmallIPtrImm(unsigned Imm) {
243 return CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy());
244 }
245
246 /// Select - Convert the specified operand from a target-independent to a
247 /// target-specific node if it hasn't already been changed.
248 SDNode *Select(SDOperand Op);
249
250 /// Return true if the address N is a RI7 format address [r+imm]
251 bool SelectDForm2Addr(SDOperand Op, SDOperand N, SDOperand &Disp,
252 SDOperand &Base);
253
254 //! Returns true if the address N is an A-form (local store) address
255 bool SelectAFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
256 SDOperand &Index);
257
258 //! D-form address predicate
259 bool SelectDFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
260 SDOperand &Index);
261
262 //! Address predicate if N can be expressed as an indexed [r+r] operation.
263 bool SelectXFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
264 SDOperand &Index);
265
266 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
267 /// inline asm expressions.
268 virtual bool SelectInlineAsmMemoryOperand(const SDOperand &Op,
269 char ConstraintCode,
270 std::vector<SDOperand> &OutOps,
271 SelectionDAG &DAG) {
272 SDOperand Op0, Op1;
273 switch (ConstraintCode) {
274 default: return true;
275 case 'm': // memory
276 if (!SelectDFormAddr(Op, Op, Op0, Op1)
277 && !SelectAFormAddr(Op, Op, Op0, Op1))
278 SelectXFormAddr(Op, Op, Op0, Op1);
279 break;
280 case 'o': // offsetable
281 if (!SelectDFormAddr(Op, Op, Op0, Op1)
282 && !SelectAFormAddr(Op, Op, Op0, Op1)) {
283 Op0 = Op;
284 AddToISelQueue(Op0); // r+0.
285 Op1 = getSmallIPtrImm(0);
286 }
287 break;
288 case 'v': // not offsetable
289#if 1
290 assert(0 && "InlineAsmMemoryOperand 'v' constraint not handled.");
291#else
292 SelectAddrIdxOnly(Op, Op, Op0, Op1);
293#endif
294 break;
295 }
296
297 OutOps.push_back(Op0);
298 OutOps.push_back(Op1);
299 return false;
300 }
301
302 /// InstructionSelectBasicBlock - This callback is invoked by
303 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
304 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
305
306 virtual const char *getPassName() const {
307 return "Cell SPU DAG->DAG Pattern Instruction Selection";
308 }
309
310 /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
311 /// this target when scheduling the DAG.
312 virtual HazardRecognizer *CreateTargetHazardRecognizer() {
313 const TargetInstrInfo *II = SPUtli.getTargetMachine().getInstrInfo();
314 assert(II && "No InstrInfo?");
315 return new SPUHazardRecognizer(*II);
316 }
317
318 // Include the pieces autogenerated from the target description.
319#include "SPUGenDAGISel.inc"
320};
321
322/// InstructionSelectBasicBlock - This callback is invoked by
323/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
324void
325SPUDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG)
326{
327 DEBUG(BB->dump());
328
329 // Select target instructions for the DAG.
330 DAG.setRoot(SelectRoot(DAG.getRoot()));
331 DAG.RemoveDeadNodes();
332
333 // Emit machine code to BB.
334 ScheduleAndEmitDAG(DAG);
335}
336
337bool
338SPUDAGToDAGISel::SelectDForm2Addr(SDOperand Op, SDOperand N, SDOperand &Disp,
339 SDOperand &Base) {
340 unsigned Opc = N.getOpcode();
341 unsigned VT = N.getValueType();
342 MVT::ValueType PtrVT = SPUtli.getPointerTy();
343 ConstantSDNode *CN = 0;
344 int Imm;
345
346 if (Opc == ISD::ADD) {
347 SDOperand Op0 = N.getOperand(0);
348 SDOperand Op1 = N.getOperand(1);
349 if (Op1.getOpcode() == ISD::Constant ||
350 Op1.getOpcode() == ISD::TargetConstant) {
351 CN = cast<ConstantSDNode>(Op1);
352 Imm = int(CN->getValue());
353 if (Imm <= 0xff) {
354 Disp = CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy());
355 Base = Op0;
356 return true;
357 }
358 }
359 } else if (Opc == ISD::GlobalAddress
360 || Opc == ISD::TargetGlobalAddress
361 || Opc == ISD::Register) {
362 // Plain old local store address:
363 Disp = CurDAG->getTargetConstant(0, VT);
364 Base = N;
365 return true;
366 } else if (Opc == SPUISD::DFormAddr) {
367 // D-Form address: This is pretty straightforward, naturally...
368 CN = cast<ConstantSDNode>(N.getOperand(1));
369 assert(CN != 0 && "SelectDFormAddr/SPUISD::DForm2Addr expecting constant");
370 Imm = unsigned(CN->getValue());
371 if (Imm < 0xff) {
372 Disp = CurDAG->getTargetConstant(CN->getValue(), PtrVT);
373 Base = N.getOperand(0);
374 return true;
375 }
376 }
377
378 return false;
379}
380
381/*!
382 \arg Op The ISD instructio operand
383 \arg N The address to be tested
384 \arg Base The base address
385 \arg Index The base address index
386 */
387bool
388SPUDAGToDAGISel::SelectAFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
389 SDOperand &Index) {
390 // These match the addr256k operand type:
391 MVT::ValueType PtrVT = SPUtli.getPointerTy();
392 MVT::ValueType OffsVT = MVT::i16;
393
394 switch (N.getOpcode()) {
395 case ISD::Constant:
396 case ISD::TargetConstant: {
397 // Loading from a constant address.
398 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);
399 int Imm = (int)CN->getValue();
400 if (Imm < 0x3ffff && (Imm & 0x3) == 0) {
401 Base = CurDAG->getTargetConstant(Imm, PtrVT);
402 // Note that this operand will be ignored by the assembly printer...
403 Index = CurDAG->getTargetConstant(0, OffsVT);
404 return true;
405 }
406 }
407 case ISD::ConstantPool:
408 case ISD::TargetConstantPool: {
409 // The constant pool address is N. Base is a dummy that will be ignored by
410 // the assembly printer.
411 Base = N;
412 Index = CurDAG->getTargetConstant(0, OffsVT);
413 return true;
414 }
415
416 case ISD::GlobalAddress:
417 case ISD::TargetGlobalAddress: {
418 // The global address is N. Base is a dummy that is ignored by the
419 // assembly printer.
420 Base = N;
421 Index = CurDAG->getTargetConstant(0, OffsVT);
422 return true;
423 }
424 }
425
426 return false;
427}
428
429/*!
430 \arg Op The ISD instruction (ignored)
431 \arg N The address to be tested
432 \arg Base Base address register/pointer
433 \arg Index Base address index
434
435 Examine the input address by a base register plus a signed 10-bit
436 displacement, [r+I10] (D-form address).
437
438 \return true if \a N is a D-form address with \a Base and \a Index set
439 to non-empty SDOperand instances.
440*/
441bool
442SPUDAGToDAGISel::SelectDFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
443 SDOperand &Index) {
444 unsigned Opc = N.getOpcode();
445 unsigned PtrTy = SPUtli.getPointerTy();
446
447 if (Opc == ISD::Register) {
448 Base = N;
449 Index = CurDAG->getTargetConstant(0, PtrTy);
450 return true;
451 } else if (Opc == ISD::FrameIndex) {
452 // Stack frame index must be less than 512 (divided by 16):
453 FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N);
454 DEBUG(cerr << "SelectDFormAddr: ISD::FrameIndex = "
455 << FI->getIndex() << "\n");
456 if (FI->getIndex() < SPUFrameInfo::maxFrameOffset()) {
457 Base = CurDAG->getTargetConstant(0, PtrTy);
458 Index = CurDAG->getTargetFrameIndex(FI->getIndex(), PtrTy);
459 return true;
460 }
461 } else if (Opc == ISD::ADD) {
462 // Generated by getelementptr
463 const SDOperand Op0 = N.getOperand(0); // Frame index/base
464 const SDOperand Op1 = N.getOperand(1); // Offset within base
465 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op1);
466
467 // Not a constant?
468 if (CN == 0)
469 return false;
470
471 int32_t offset = (int32_t) CN->getSignExtended();
472 unsigned Opc0 = Op0.getOpcode();
473
474 if ((offset & 0xf) != 0) {
475 cerr << "SelectDFormAddr: unaligned offset = " << offset << "\n";
476 abort();
477 /*NOTREACHED*/
478 }
479
480 if (Opc0 == ISD::FrameIndex) {
481 FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op0);
482 DEBUG(cerr << "SelectDFormAddr: ISD::ADD offset = " << offset
483 << " frame index = " << FI->getIndex() << "\n");
484
485 if (FI->getIndex() < SPUFrameInfo::maxFrameOffset()) {
486 Base = CurDAG->getTargetConstant(offset, PtrTy);
487 Index = CurDAG->getTargetFrameIndex(FI->getIndex(), PtrTy);
488 return true;
489 }
490 } else if (offset > SPUFrameInfo::minFrameOffset()
491 && offset < SPUFrameInfo::maxFrameOffset()) {
492 Base = CurDAG->getTargetConstant(offset, PtrTy);
493 if (Opc0 == ISD::GlobalAddress) {
494 // Convert global address to target global address
495 GlobalAddressSDNode *GV = dyn_cast<GlobalAddressSDNode>(Op0);
496 Index = CurDAG->getTargetGlobalAddress(GV->getGlobal(), PtrTy);
497 return true;
498 } else {
499 // Otherwise, just take operand 0
500 Index = Op0;
501 return true;
502 }
503 }
504 } else if (Opc == SPUISD::DFormAddr) {
505 // D-Form address: This is pretty straightforward, naturally...
506 ConstantSDNode *CN = cast<ConstantSDNode>(N.getOperand(1));
507 assert(CN != 0 && "SelectDFormAddr/SPUISD::DFormAddr expecting constant");
508 Base = CurDAG->getTargetConstant(CN->getValue(), PtrTy);
509 Index = N.getOperand(0);
510 return true;
511 }
512
513 return false;
514}
515
516/*!
517 \arg Op The ISD instruction operand
518 \arg N The address operand
519 \arg Base The base pointer operand
520 \arg Index The offset/index operand
521
522 If the address \a N can be expressed as a [r + s10imm] address, returns false.
523 Otherwise, creates two operands, Base and Index that will become the [r+r]
524 address.
525*/
526bool
527SPUDAGToDAGISel::SelectXFormAddr(SDOperand Op, SDOperand N, SDOperand &Base,
528 SDOperand &Index) {
529 if (SelectAFormAddr(Op, N, Base, Index)
530 || SelectDFormAddr(Op, N, Base, Index))
531 return false;
532
533 unsigned Opc = N.getOpcode();
534
535 if (Opc == ISD::ADD) {
536 SDOperand N1 = N.getOperand(0);
537 SDOperand N2 = N.getOperand(1);
538 unsigned N1Opc = N1.getOpcode();
539 unsigned N2Opc = N2.getOpcode();
540
541 if ((N1Opc == SPUISD::Hi && N2Opc == SPUISD::Lo)
542 || (N1Opc == SPUISD::Lo && N2Opc == SPUISD::Hi)) {
543 Base = N.getOperand(0);
544 Index = N.getOperand(1);
545 return true;
546 } else {
547 cerr << "SelectXFormAddr: Unhandled ADD operands:\n";
548 N1.Val->dump();
549 cerr << "\n";
550 N2.Val->dump();
551 cerr << "\n";
552 abort();
553 /*UNREACHED*/
554 }
555 } else if (N.getNumOperands() == 2) {
556 SDOperand N1 = N.getOperand(0);
557 SDOperand N2 = N.getOperand(1);
558 unsigned N1Opc = N1.getOpcode();
559 unsigned N2Opc = N2.getOpcode();
560
561 if ((N1Opc == ISD::CopyToReg || N1Opc == ISD::Register)
562 && (N2Opc == ISD::CopyToReg || N2Opc == ISD::Register)) {
563 Base = N.getOperand(0);
564 Index = N.getOperand(1);
565 return true;
566 /*UNREACHED*/
567 } else {
568 cerr << "SelectXFormAddr: 2-operand unhandled operand:\n";
569 N.Val->dump();
570 cerr << "\n";
571 abort();
572 /*UNREACHED*/
573 }
574 } else {
575 cerr << "SelectXFormAddr: Unhandled operand type:\n";
576 N.Val->dump();
577 cerr << "\n";
578 abort();
579 /*UNREACHED*/
580 }
581
582 return false;
583}
584
585//! Convert the operand from a target-independent to a target-specific node
586/*!
587 */
588SDNode *
589SPUDAGToDAGISel::Select(SDOperand Op) {
590 SDNode *N = Op.Val;
591 unsigned Opc = N->getOpcode();
592
593 if (Opc >= ISD::BUILTIN_OP_END && Opc < SPUISD::FIRST_NUMBER) {
594 return NULL; // Already selected.
595 } else if (Opc == ISD::FrameIndex) {
596 // Selects to AIr32 FI, 0 which in turn will become AIr32 SP, imm.
597 int FI = cast<FrameIndexSDNode>(N)->getIndex();
598 SDOperand TFI = CurDAG->getTargetFrameIndex(FI, SPUtli.getPointerTy());
599
Scott Michel9999e682007-12-19 07:35:06 +0000600 DEBUG(cerr << "SPUDAGToDAGISel: Replacing FrameIndex with AI32 <FI>, 0\n");
Scott Michel266bc8f2007-12-04 22:23:35 +0000601 return CurDAG->SelectNodeTo(N, SPU::AIr32, Op.getValueType(), TFI,
602 CurDAG->getTargetConstant(0, MVT::i32));
603 } else if (Opc == SPUISD::LDRESULT) {
604 // Custom select instructions for LDRESULT
605 unsigned VT = N->getValueType(0);
606 SDOperand Arg = N->getOperand(0);
607 SDOperand Chain = N->getOperand(1);
Scott Michel266bc8f2007-12-04 22:23:35 +0000608 SDNode *Result;
Scott Michel266bc8f2007-12-04 22:23:35 +0000609
610 AddToISelQueue(Arg);
Scott Michel86c041f2007-12-20 00:44:13 +0000611 if (!MVT::isFloatingPoint(VT)) {
612 SDOperand Zero = CurDAG->getTargetConstant(0, VT);
613 const valtype_map_s *vtm = getValueTypeMapEntry(VT);
614
615 if (vtm->ldresult_ins == 0) {
616 cerr << "LDRESULT for unsupported type: "
617 << MVT::getValueTypeString(VT)
618 << "\n";
619 abort();
620 } else
621 Opc = vtm->ldresult_ins;
622
623 AddToISelQueue(Zero);
624 Result = CurDAG->SelectNodeTo(N, Opc, VT, MVT::Other, Arg, Zero, Chain);
625 } else {
626 Result =
627 CurDAG->SelectNodeTo(N, (VT == MVT::f32 ? SPU::ORf32 : SPU::ORf64),
628 MVT::Other, Arg, Arg, Chain);
629 }
630
Scott Michel266bc8f2007-12-04 22:23:35 +0000631 Chain = SDOperand(Result, 1);
Scott Michel86c041f2007-12-20 00:44:13 +0000632 AddToISelQueue(Chain);
633
Scott Michel266bc8f2007-12-04 22:23:35 +0000634 return Result;
635 }
636
637 return SelectCode(Op);
638}
639
640/// createPPCISelDag - This pass converts a legalized DAG into a
641/// SPU-specific DAG, ready for instruction scheduling.
642///
643FunctionPass *llvm::createSPUISelDag(SPUTargetMachine &TM) {
644 return new SPUDAGToDAGISel(TM);
645}