1 //===---- IA64ISelDAGToDAG.cpp - IA64 pattern matching inst selector ------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Duraid Madina and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a pattern matching instruction selector for IA64,
11 // converting a legalized dag to an IA64 dag.
13 //===----------------------------------------------------------------------===//
16 #include "IA64TargetMachine.h"
17 #include "IA64ISelLowering.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/SSARegMap.h"
21 #include "llvm/CodeGen/SelectionDAG.h"
22 #include "llvm/CodeGen/SelectionDAGISel.h"
23 #include "llvm/Target/TargetOptions.h"
24 #include "llvm/ADT/Statistic.h"
25 #include "llvm/Constants.h"
26 #include "llvm/GlobalValue.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/MathExtras.h"
32 Statistic<> FusedFP ("ia64-codegen", "Number of fused fp operations");
33 Statistic<> FrameOff("ia64-codegen", "Number of frame idx offsets collapsed");
35 //===--------------------------------------------------------------------===//
36 /// IA64DAGToDAGISel - IA64 specific code to select IA64 machine
37 /// instructions for SelectionDAG operations.
39 class IA64DAGToDAGISel : public SelectionDAGISel {
40 IA64TargetLowering IA64Lowering;
41 unsigned GlobalBaseReg;
43 IA64DAGToDAGISel(TargetMachine &TM)
44 : SelectionDAGISel(IA64Lowering), IA64Lowering(TM) {}
46 virtual bool runOnFunction(Function &Fn) {
47 // Make sure we re-emit a set of the global base reg if necessary
49 return SelectionDAGISel::runOnFunction(Fn);
52 /// getI64Imm - Return a target constant with the specified value, of type
54 inline SDOperand getI64Imm(uint64_t Imm) {
55 return CurDAG->getTargetConstant(Imm, MVT::i64);
58 /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
59 /// base register. Return the virtual register that holds this value.
60 // SDOperand getGlobalBaseReg(); TODO: hmm
62 // Select - Convert the specified operand from a target-independent to a
63 // target-specific node if it hasn't already been changed.
64 SDOperand Select(SDOperand Op);
66 SDNode *SelectIntImmediateExpr(SDOperand LHS, SDOperand RHS,
67 unsigned OCHi, unsigned OCLo,
68 bool IsArithmetic = false,
70 SDNode *SelectBitfieldInsert(SDNode *N);
72 /// SelectCC - Select a comparison of the specified values with the
73 /// specified condition code, returning the CR# of the expression.
74 SDOperand SelectCC(SDOperand LHS, SDOperand RHS, ISD::CondCode CC);
76 /// SelectAddr - Given the specified address, return the two operands for a
77 /// load/store instruction, and return true if it should be an indexed [r+r]
79 bool SelectAddr(SDOperand Addr, SDOperand &Op1, SDOperand &Op2);
81 SDOperand BuildSDIVSequence(SDNode *N);
82 SDOperand BuildUDIVSequence(SDNode *N);
84 /// InstructionSelectBasicBlock - This callback is invoked by
85 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
86 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
88 virtual const char *getPassName() const {
89 return "IA64 (Itanium) DAG->DAG Instruction Selector";
92 // Include the pieces autogenerated from the target description.
93 #include "IA64GenDAGISel.inc"
96 SDOperand SelectDIV(SDOperand Op);
100 /// InstructionSelectBasicBlock - This callback is invoked by
101 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
102 void IA64DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
105 // The selection process is inherently a bottom-up recursive process (users
106 // select their uses before themselves). Given infinite stack space, we
107 // could just start selecting on the root and traverse the whole graph. In
108 // practice however, this causes us to run out of stack space on large basic
109 // blocks. To avoid this problem, select the entry node, then all its uses,
110 // iteratively instead of recursively.
111 std::vector<SDOperand> Worklist;
112 Worklist.push_back(DAG.getEntryNode());
114 // Note that we can do this in the IA64 target (scanning forward across token
115 // chain edges) because no nodes ever get folded across these edges. On a
116 // target like X86 which supports load/modify/store operations, this would
117 // have to be more careful.
118 while (!Worklist.empty()) {
119 SDOperand Node = Worklist.back();
122 // Chose from the least deep of the top two nodes.
123 if (!Worklist.empty() &&
124 Worklist.back().Val->getNodeDepth() < Node.Val->getNodeDepth())
125 std::swap(Worklist.back(), Node);
127 if ((Node.Val->getOpcode() >= ISD::BUILTIN_OP_END &&
128 Node.Val->getOpcode() < IA64ISD::FIRST_NUMBER) ||
129 CodeGenMap.count(Node)) continue;
131 for (SDNode::use_iterator UI = Node.Val->use_begin(),
132 E = Node.Val->use_end(); UI != E; ++UI) {
133 // Scan the values. If this use has a value that is a token chain, add it
136 for (unsigned i = 0, e = User->getNumValues(); i != e; ++i)
137 if (User->getValueType(i) == MVT::Other) {
138 Worklist.push_back(SDOperand(User, i));
143 // Finally, legalize this node.
147 // Select target instructions for the DAG.
148 DAG.setRoot(Select(DAG.getRoot()));
150 DAG.RemoveDeadNodes();
152 // Emit machine code to BB.
153 ScheduleAndEmitDAG(DAG);
156 SDOperand IA64DAGToDAGISel::SelectDIV(SDOperand Op) {
158 SDOperand Chain = Select(N->getOperand(0));
160 SDOperand Tmp1 = Select(N->getOperand(0));
161 SDOperand Tmp2 = Select(N->getOperand(1));
165 if(MVT::isFloatingPoint(Tmp1.getValueType()))
168 bool isModulus=false; // is it a division or a modulus?
171 switch(N->getOpcode()) {
173 case ISD::SDIV: isModulus=false; isSigned=true; break;
174 case ISD::UDIV: isModulus=false; isSigned=false; break;
176 case ISD::SREM: isModulus=true; isSigned=true; break;
177 case ISD::UREM: isModulus=true; isSigned=false; break;
180 // TODO: check for integer divides by powers of 2 (or other simple patterns?)
182 SDOperand TmpPR, TmpPR2;
183 SDOperand TmpF1, TmpF2, TmpF3, TmpF4, TmpF5, TmpF6, TmpF7, TmpF8;
184 SDOperand TmpF9, TmpF10,TmpF11,TmpF12,TmpF13,TmpF14,TmpF15;
187 // we'll need copies of F0 and F1
188 SDOperand F0 = CurDAG->getRegister(IA64::F0, MVT::f64);
189 SDOperand F1 = CurDAG->getRegister(IA64::F1, MVT::f64);
191 // OK, emit some code:
194 // first, load the inputs into FP regs.
195 TmpF1 = CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64, Tmp1);
196 Chain = TmpF1.getValue(1);
197 TmpF2 = CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64, Tmp2);
198 Chain = TmpF2.getValue(1);
200 // next, convert the inputs to FP
202 TmpF3 = CurDAG->getTargetNode(IA64::FCVTXF, MVT::f64, TmpF1);
203 Chain = TmpF3.getValue(1);
204 TmpF4 = CurDAG->getTargetNode(IA64::FCVTXF, MVT::f64, TmpF2);
205 Chain = TmpF4.getValue(1);
206 } else { // is unsigned
207 TmpF3 = CurDAG->getTargetNode(IA64::FCVTXUFS1, MVT::f64, TmpF1);
208 Chain = TmpF3.getValue(1);
209 TmpF4 = CurDAG->getTargetNode(IA64::FCVTXUFS1, MVT::f64, TmpF2);
210 Chain = TmpF4.getValue(1);
213 } else { // this is an FP divide/remainder, so we 'leak' some temp
214 // regs and assign TmpF3=Tmp1, TmpF4=Tmp2
219 // we start by computing an approximate reciprocal (good to 9 bits?)
220 // note, this instruction writes _both_ TmpF5 (answer) and TmpPR (predicate)
222 TmpF5 = CurDAG->getTargetNode(IA64::FRCPAS0, MVT::f64, MVT::i1,
225 TmpF5 = CurDAG->getTargetNode(IA64::FRCPAS1, MVT::f64, MVT::i1,
228 TmpPR = TmpF5.getValue(1);
229 Chain = TmpF5.getValue(2);
232 if(isModulus) { // for remainders, it'll be handy to have
233 // copies of -input_b
234 minusB = CurDAG->getTargetNode(IA64::SUB, MVT::i64,
235 CurDAG->getRegister(IA64::r0, MVT::i64), Tmp2);
236 Chain = minusB.getValue(1);
239 SDOperand TmpE0, TmpY1, TmpE1, TmpY2;
241 TmpE0 = CurDAG->getTargetNode(IA64::CFNMAS1, MVT::f64,
242 TmpF4, TmpF5, F1, TmpPR);
243 Chain = TmpE0.getValue(1);
244 TmpY1 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
245 TmpF5, TmpE0, TmpF5, TmpPR);
246 Chain = TmpY1.getValue(1);
247 TmpE1 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
248 TmpE0, TmpE0, F0, TmpPR);
249 Chain = TmpE1.getValue(1);
250 TmpY2 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
251 TmpY1, TmpE1, TmpY1, TmpPR);
252 Chain = TmpY2.getValue(1);
254 if(isFP) { // if this is an FP divide, we finish up here and exit early
256 assert(0 && "Sorry, try another FORTRAN compiler.");
258 SDOperand TmpE2, TmpY3, TmpQ0, TmpR0;
260 TmpE2 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
261 TmpE1, TmpE1, F0, TmpPR);
262 Chain = TmpE2.getValue(1);
263 TmpY3 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
264 TmpY2, TmpE2, TmpY2, TmpPR);
265 Chain = TmpY3.getValue(1);
266 TmpQ0 = CurDAG->getTargetNode(IA64::CFMADS1, MVT::f64, // double prec!
267 Tmp1, TmpY3, F0, TmpPR);
268 Chain = TmpQ0.getValue(1);
269 TmpR0 = CurDAG->getTargetNode(IA64::CFNMADS1, MVT::f64, // double prec!
270 Tmp2, TmpQ0, Tmp1, TmpPR);
271 Chain = TmpR0.getValue(1);
273 // we want Result to have the same target register as the frcpa, so
274 // we two-address hack it. See the comment "for this to work..." on
275 // page 48 of Intel application note #245415
276 Result = CurDAG->getTargetNode(IA64::TCFMADS0, MVT::f64, // d.p. s0 rndg!
277 TmpF5, TmpY3, TmpR0, TmpQ0, TmpPR);
278 Chain = Result.getValue(1);
279 return Result; // XXX: early exit!
280 } else { // this is *not* an FP divide, so there's a bit left to do:
282 SDOperand TmpQ2, TmpR2, TmpQ3, TmpQ;
284 TmpQ2 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
285 TmpF3, TmpY2, F0, TmpPR);
286 Chain = TmpQ2.getValue(1);
287 TmpR2 = CurDAG->getTargetNode(IA64::CFNMAS1, MVT::f64,
288 TmpF4, TmpQ2, TmpF3, TmpPR);
289 Chain = TmpR2.getValue(1);
291 // we want TmpQ3 to have the same target register as the frcpa? maybe we
292 // should two-address hack it. See the comment "for this to work..." on page
293 // 48 of Intel application note #245415
294 TmpQ3 = CurDAG->getTargetNode(IA64::CFMAS1, MVT::f64,
295 TmpR2, TmpY2, TmpQ2, TmpPR);
296 Chain = TmpQ3.getValue(1);
298 // FIXME: this is unfortunate :(
299 // the story is that the dest reg of the fnma above and the fma below it
300 // (and therefore the src of the fcvt.fx[u] below as well) cannot
301 // be the same register, or this code breaks if the first argument is
302 // zero. (e.g. without this hack, 0%8 yields -64, not 0.)
303 /* XXX: these two lines do nothing */
304 SDOperand bogus = CurDAG->getTargetNode(IA64::IUSE, MVT::Other, TmpR2);
305 Chain = bogus.getValue(0);
308 TmpQ = CurDAG->getTargetNode(IA64::FCVTFXTRUNCS1, MVT::f64, TmpQ3);
310 TmpQ = CurDAG->getTargetNode(IA64::FCVTFXUTRUNCS1, MVT::f64, TmpQ3);
312 Chain = TmpQ.getValue(1);
315 SDOperand FPminusB = CurDAG->getTargetNode(IA64::SETFSIG, MVT::f64,
317 Chain = FPminusB.getValue(1);
318 SDOperand Remainder = CurDAG->getTargetNode(IA64::XMAL, MVT::f64,
319 TmpQ, FPminusB, TmpF1);
320 Chain = Remainder.getValue(1);
321 Result = CurDAG->getTargetNode(IA64::GETFSIG, MVT::i64, Remainder);
322 Chain = Result.getValue(1);
323 } else { // just an integer divide
324 Result = CurDAG->getTargetNode(IA64::GETFSIG, MVT::i64, TmpQ);
325 Chain = Result.getValue(1);
329 } // wasn't an FP divide
332 // Select - Convert the specified operand from a target-independent to a
333 // target-specific node if it hasn't already been changed.
334 SDOperand IA64DAGToDAGISel::Select(SDOperand Op) {
336 if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
337 N->getOpcode() < IA64ISD::FIRST_NUMBER)
338 return Op; // Already selected.
340 // If this has already been converted, use it.
341 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op);
342 if (CGMI != CodeGenMap.end()) return CGMI->second;
344 switch (N->getOpcode()) {
347 case IA64ISD::BRCALL: { // XXX: this is also a hack!
348 SDOperand Chain = Select(N->getOperand(0));
349 SDOperand InFlag; // Null incoming flag value.
351 if(N->getNumOperands()==3) // we have an incoming chain, callee and flag
352 InFlag = Select(N->getOperand(2));
355 SDOperand CallOperand;
357 // if we can call directly, do so
358 if (GlobalAddressSDNode *GASD =
359 dyn_cast<GlobalAddressSDNode>(N->getOperand(1))) {
360 CallOpcode = IA64::BRCALL_IPREL_GA;
361 CallOperand = CurDAG->getTargetGlobalAddress(GASD->getGlobal(), MVT::i64);
362 } else if (ExternalSymbolSDNode *ESSDN = // FIXME: we currently NEED this
363 // case for correctness, to avoid
364 // "non-pic code with imm reloc.n
365 // against dynamic symbol" errors
366 dyn_cast<ExternalSymbolSDNode>(N->getOperand(1))) {
367 CallOpcode = IA64::BRCALL_IPREL_ES;
368 CallOperand = N->getOperand(1);
370 // otherwise we need to load the function descriptor,
371 // load the branch target (function)'s entry point and GP,
372 // branch (call) then restore the GP
373 SDOperand FnDescriptor = Select(N->getOperand(1));
375 // load the branch target's entry point [mem] and
377 SDOperand targetEntryPoint=CurDAG->getTargetNode(IA64::LD8, MVT::i64,
379 Chain = targetEntryPoint.getValue(1);
380 SDOperand targetGPAddr=CurDAG->getTargetNode(IA64::ADDS, MVT::i64,
381 FnDescriptor, CurDAG->getConstant(8, MVT::i64));
382 Chain = targetGPAddr.getValue(1);
383 SDOperand targetGP=CurDAG->getTargetNode(IA64::LD8, MVT::i64,
385 Chain = targetGP.getValue(1);
387 Chain = CurDAG->getCopyToReg(Chain, IA64::r1, targetGP, InFlag);
388 InFlag = Chain.getValue(1);
389 Chain = CurDAG->getCopyToReg(Chain, IA64::B6, targetEntryPoint, InFlag); // FLAG these?
390 InFlag = Chain.getValue(1);
392 CallOperand = CurDAG->getRegister(IA64::B6, MVT::i64);
393 CallOpcode = IA64::BRCALL_INDIRECT;
396 // Finally, once everything is setup, emit the call itself
398 Chain = CurDAG->getTargetNode(CallOpcode, MVT::Other, MVT::Flag, CallOperand, InFlag);
399 else // there might be no arguments
400 Chain = CurDAG->getTargetNode(CallOpcode, MVT::Other, MVT::Flag, CallOperand, Chain);
401 InFlag = Chain.getValue(1);
403 std::vector<SDOperand> CallResults;
405 CallResults.push_back(Chain);
406 CallResults.push_back(InFlag);
408 for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
409 CodeGenMap[Op.getValue(i)] = CallResults[i];
410 return CallResults[Op.ResNo];
413 case IA64ISD::GETFD: {
414 SDOperand Input = Select(N->getOperand(0));
415 SDOperand Result = CurDAG->getTargetNode(IA64::GETFD, MVT::i64, Input);
416 CodeGenMap[Op] = Result;
421 case ISD::TAILCALL: { {
422 // FIXME: This is a workaround for a bug in tblgen.
423 // Pattern #47: (call:Flag (tglobaladdr:i32):$dst, ICC:Flag)
424 // Emits: (CALL:void (tglobaladdr:i32):$dst)
425 // Pattern complexity = 2 cost = 1
426 SDOperand N1 = N->getOperand(1);
427 if (N1.getOpcode() != ISD::TargetGlobalAddress &&
428 N1.getOpcode() != ISD::ExternalSymbol) goto P47Fail;
429 SDOperand InFlag = SDOperand(0, 0);
430 SDOperand Chain = N->getOperand(0);
432 Chain = Select(Chain);
434 if (N->getNumOperands() == 3) {
435 InFlag = Select(N->getOperand(2));
436 Result = CurDAG->getTargetNode(IA64::BRCALL, MVT::Other, MVT::Flag, Tmp0,
439 Result = CurDAG->getTargetNode(IA64::BRCALL, MVT::Other, MVT::Flag, Tmp0,
442 Chain = CodeGenMap[SDOperand(N, 0)] = Result.getValue(0);
443 CodeGenMap[SDOperand(N, 1)] = Result.getValue(1);
444 return Result.getValue(Op.ResNo);
454 case ISD::UREM: return SelectDIV(Op);
456 case ISD::ConstantFP: {
457 SDOperand Chain = CurDAG->getEntryNode(); // this is a constant, so..
459 if (cast<ConstantFPSDNode>(N)->isExactlyValue(+0.0))
460 return CurDAG->getCopyFromReg(Chain, IA64::F0, MVT::f64);
461 else if (cast<ConstantFPSDNode>(N)->isExactlyValue(+1.0))
462 return CurDAG->getCopyFromReg(Chain, IA64::F1, MVT::f64);
464 assert(0 && "Unexpected FP constant!");
467 case ISD::FrameIndex: { // TODO: reduce creepyness
468 int FI = cast<FrameIndexSDNode>(N)->getIndex();
470 return CurDAG->SelectNodeTo(N, IA64::MOV, MVT::i64,
471 CurDAG->getTargetFrameIndex(FI, MVT::i64));
472 return CurDAG->getTargetNode(IA64::MOV, MVT::i64,
473 CurDAG->getTargetFrameIndex(FI, MVT::i64));
476 case ISD::ConstantPool: { // TODO: nuke the constant pool
477 // (ia64 doesn't need one)
478 Constant *C = cast<ConstantPoolSDNode>(N)->get();
479 SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
480 return CurDAG->getTargetNode(IA64::ADDL_GA, MVT::i64, // ?
481 CurDAG->getRegister(IA64::r1, MVT::i64), CPI);
484 case ISD::GlobalAddress: {
485 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
486 SDOperand GA = CurDAG->getTargetGlobalAddress(GV, MVT::i64);
487 SDOperand Tmp = CurDAG->getTargetNode(IA64::ADDL_GA, MVT::i64,
488 CurDAG->getRegister(IA64::r1, MVT::i64), GA);
489 return CurDAG->getTargetNode(IA64::LD8, MVT::i64, Tmp);
492 /* XXX case ISD::ExternalSymbol: {
493 SDOperand EA = CurDAG->getTargetExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol(),
495 SDOperand Tmp = CurDAG->getTargetNode(IA64::ADDL_EA, MVT::i64,
496 CurDAG->getRegister(IA64::r1, MVT::i64), EA);
497 return CurDAG->getTargetNode(IA64::LD8, MVT::i64, Tmp);
503 case ISD::ZEXTLOAD: {
504 SDOperand Chain = Select(N->getOperand(0));
505 SDOperand Address = Select(N->getOperand(1));
507 MVT::ValueType TypeBeingLoaded = (N->getOpcode() == ISD::LOAD) ?
508 N->getValueType(0) : cast<VTSDNode>(N->getOperand(3))->getVT();
510 switch (TypeBeingLoaded) {
511 default: N->dump(); assert(0 && "Cannot load this type!");
512 case MVT::i1: { // this is a bool
513 Opc = IA64::LD1; // first we load a byte, then compare for != 0
514 if(N->getValueType(0) == MVT::i1) // XXX: early exit!
515 return CurDAG->SelectNodeTo(N, IA64::CMPNE, MVT::i1, MVT::Other,
516 CurDAG->getTargetNode(Opc, MVT::i64, Address),
517 CurDAG->getRegister(IA64::r0, MVT::i64),
518 Chain).getValue(Op.ResNo);
519 /* otherwise, we want to load a bool into something bigger: LD1
520 will do that for us, so we just fall through */
522 case MVT::i8: Opc = IA64::LD1; break;
523 case MVT::i16: Opc = IA64::LD2; break;
524 case MVT::i32: Opc = IA64::LD4; break;
525 case MVT::i64: Opc = IA64::LD8; break;
527 case MVT::f32: Opc = IA64::LDF4; break;
528 case MVT::f64: Opc = IA64::LDF8; break;
531 // TODO: comment this
532 return CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), MVT::Other,
533 Address, Chain).getValue(Op.ResNo);
536 case ISD::TRUNCSTORE:
538 SDOperand Address = Select(N->getOperand(2));
539 SDOperand Chain = Select(N->getOperand(0));
542 if (N->getOpcode() == ISD::STORE) {
543 switch (N->getOperand(1).getValueType()) {
544 default: assert(0 && "unknown type in store");
545 case MVT::i1: { // this is a bool
546 Opc = IA64::ST1; // we store either 0 or 1 as a byte
548 SDOperand Initial = CurDAG->getCopyFromReg(Chain, IA64::r0, MVT::i64);
549 Chain = Initial.getValue(1);
550 // then load 1 iff the predicate to store is 1
552 CurDAG->getTargetNode(IA64::PADDS, MVT::i64, Initial,
553 CurDAG->getConstant(1, MVT::i64),
554 Select(N->getOperand(1)));
555 return CurDAG->SelectNodeTo(N, Opc, MVT::Other, Address, Tmp, Chain);
557 case MVT::i64: Opc = IA64::ST8; break;
558 case MVT::f64: Opc = IA64::STF8; break;
560 } else { //ISD::TRUNCSTORE
561 switch(cast<VTSDNode>(N->getOperand(4))->getVT()) {
562 default: assert(0 && "unknown type in truncstore");
563 case MVT::i8: Opc = IA64::ST1; break;
564 case MVT::i16: Opc = IA64::ST2; break;
565 case MVT::i32: Opc = IA64::ST4; break;
566 case MVT::f32: Opc = IA64::STF4; break;
570 return CurDAG->SelectNodeTo(N, Opc, MVT::Other, Select(N->getOperand(2)),
571 Select(N->getOperand(1)), Chain);
575 SDOperand Chain = Select(N->getOperand(0));
576 SDOperand CC = Select(N->getOperand(1));
577 MachineBasicBlock *Dest =
578 cast<BasicBlockSDNode>(N->getOperand(2))->getBasicBlock();
579 //FIXME - we do NOT need long branches all the time
580 return CurDAG->SelectNodeTo(N, IA64::BRLCOND_NOTCALL, MVT::Other, CC,
581 CurDAG->getBasicBlock(Dest), Chain);
584 case ISD::CALLSEQ_START:
585 case ISD::CALLSEQ_END: {
586 int64_t Amt = cast<ConstantSDNode>(N->getOperand(1))->getValue();
587 unsigned Opc = N->getOpcode() == ISD::CALLSEQ_START ?
588 IA64::ADJUSTCALLSTACKDOWN : IA64::ADJUSTCALLSTACKUP;
589 return CurDAG->SelectNodeTo(N, Opc, MVT::Other,
590 getI64Imm(Amt), Select(N->getOperand(0)));
594 SDOperand Chain = Select(N->getOperand(0)); // Token chain.
597 switch (N->getNumOperands()) {
599 assert(0 && "Unknown return instruction!");
601 SDOperand RetVal = Select(N->getOperand(1));
602 switch (RetVal.getValueType()) {
603 default: assert(0 && "I don't know how to return this type! (promote?)");
604 // FIXME: do I need to add support for bools here?
605 // (return '0' or '1' in r8, basically...)
607 // FIXME: need to round floats - 80 bits is bad, the tester
610 // we mark r8 as live on exit up above in LowerArguments()
611 // BuildMI(BB, IA64::MOV, 1, IA64::r8).addReg(Tmp1);
612 Chain = CurDAG->getCopyToReg(Chain, IA64::r8, RetVal);
613 InFlag = Chain.getValue(1);
616 // we mark F8 as live on exit up above in LowerArguments()
617 // BuildMI(BB, IA64::FMOV, 1, IA64::F8).addReg(Tmp1);
618 Chain = CurDAG->getCopyToReg(Chain, IA64::F8, RetVal);
619 InFlag = Chain.getValue(1);
628 // we need to copy VirtGPR (the vreg (to become a real reg)) that holds
629 // the output of this function's alloc instruction back into ar.pfs
630 // before we return. this copy must not float up above the last
631 // outgoing call in this function!!!
632 SDOperand AR_PFSVal = CurDAG->getCopyFromReg(Chain, IA64Lowering.VirtGPR,
634 Chain = AR_PFSVal.getValue(1);
635 Chain = CurDAG->getCopyToReg(Chain, IA64::AR_PFS, AR_PFSVal);
637 // and then just emit a 'ret' instruction
638 // before returning, restore the ar.pfs register (set by the 'alloc' up top)
639 // BuildMI(BB, IA64::MOV, 1).addReg(IA64::AR_PFS).addReg(IA64Lowering.VirtGPR);
641 return CurDAG->SelectNodeTo(N, IA64::RET, MVT::Other, Chain);
645 // FIXME: we don't need long branches all the time!
646 return CurDAG->SelectNodeTo(N, IA64::BRL_NOTCALL, MVT::Other,
647 N->getOperand(1), Select(N->getOperand(0)));
650 return SelectCode(Op);
654 /// createIA64DAGToDAGInstructionSelector - This pass converts a legalized DAG
655 /// into an IA64-specific DAG, ready for instruction scheduling.
657 FunctionPass *llvm::createIA64DAGToDAGInstructionSelector(TargetMachine &TM) {
658 return new IA64DAGToDAGISel(TM);