blob: 50ff1b09d01b4968a3717fd9c0cdbcd99ad8cd6c [file] [log] [blame]
Andrew Lenharthd97591a2005-10-20 00:29:02 +00001//===-- AlphaISelDAGToDAG.cpp - Alpha pattern matching inst selector ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Andrew Lenharth and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a pattern matching instruction selector for Alpha,
11// converting from a legalized dag to a Alpha dag.
12//
13//===----------------------------------------------------------------------===//
14
15#include "Alpha.h"
16#include "AlphaTargetMachine.h"
17#include "AlphaISelLowering.h"
18#include "llvm/CodeGen/MachineInstrBuilder.h"
Andrew Lenharth7f0db912005-11-30 07:19:56 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Andrew Lenharthd97591a2005-10-20 00:29:02 +000020#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/SSARegMap.h"
22#include "llvm/CodeGen/SelectionDAG.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
24#include "llvm/Target/TargetOptions.h"
25#include "llvm/ADT/Statistic.h"
26#include "llvm/Constants.h"
27#include "llvm/GlobalValue.h"
28#include "llvm/Support/Debug.h"
29#include "llvm/Support/MathExtras.h"
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000030#include <algorithm>
Andrew Lenharthd97591a2005-10-20 00:29:02 +000031using namespace llvm;
32
33namespace {
34
35 //===--------------------------------------------------------------------===//
36 /// AlphaDAGToDAGISel - Alpha specific code to select Alpha machine
37 /// instructions for SelectionDAG operations.
38 ///
39 class AlphaDAGToDAGISel : public SelectionDAGISel {
40 AlphaTargetLowering AlphaLowering;
41
Andrew Lenharth50b37842005-11-22 04:20:06 +000042 static const int IMM_LOW = -32768;
43 static const int IMM_HIGH = 32767;
44 static const int IMM_MULT = 65536;
45
Andrew Lenharthd97591a2005-10-20 00:29:02 +000046 public:
47 AlphaDAGToDAGISel(TargetMachine &TM)
48 : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) {}
49
50 /// getI64Imm - Return a target constant with the specified value, of type
51 /// i64.
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000052 inline SDOperand getI64Imm(int64_t Imm) {
Andrew Lenharthd97591a2005-10-20 00:29:02 +000053 return CurDAG->getTargetConstant(Imm, MVT::i64);
54 }
55
Andrew Lenharthd97591a2005-10-20 00:29:02 +000056 // Select - Convert the specified operand from a target-independent to a
57 // target-specific node if it hasn't already been changed.
58 SDOperand Select(SDOperand Op);
59
60 /// InstructionSelectBasicBlock - This callback is invoked by
61 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
62 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
63
64 virtual const char *getPassName() const {
65 return "Alpha DAG->DAG Pattern Instruction Selection";
66 }
67
68// Include the pieces autogenerated from the target description.
69#include "AlphaGenDAGISel.inc"
70
71private:
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000072 SDOperand getGlobalBaseReg();
73 SDOperand SelectCALL(SDOperand Op);
74
Andrew Lenharthd97591a2005-10-20 00:29:02 +000075 };
76}
77
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000078/// getGlobalBaseReg - Output the instructions required to put the
79/// GOT address into a register.
80///
81SDOperand AlphaDAGToDAGISel::getGlobalBaseReg() {
82 return CurDAG->getRegister(AlphaLowering.getVRegGP(), MVT::i64);
83}
84
Andrew Lenharthd97591a2005-10-20 00:29:02 +000085/// InstructionSelectBasicBlock - This callback is invoked by
86/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
87void AlphaDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
88 DEBUG(BB->dump());
89
Andrew Lenharthd97591a2005-10-20 00:29:02 +000090 // Select target instructions for the DAG.
91 DAG.setRoot(Select(DAG.getRoot()));
92 CodeGenMap.clear();
93 DAG.RemoveDeadNodes();
94
95 // Emit machine code to BB.
96 ScheduleAndEmitDAG(DAG);
97}
98
99// Select - Convert the specified operand from a target-independent to a
100// target-specific node if it hasn't already been changed.
101SDOperand AlphaDAGToDAGISel::Select(SDOperand Op) {
102 SDNode *N = Op.Val;
103 if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
104 N->getOpcode() < AlphaISD::FIRST_NUMBER)
105 return Op; // Already selected.
106
107 // If this has already been converted, use it.
108 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op);
109 if (CGMI != CodeGenMap.end()) return CGMI->second;
110
111 switch (N->getOpcode()) {
112 default: break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000113 case ISD::TAILCALL:
114 case ISD::CALL: return SelectCALL(Op);
115
Andrew Lenharth50b37842005-11-22 04:20:06 +0000116 case ISD::DYNAMIC_STACKALLOC: {
117 if (!isa<ConstantSDNode>(N->getOperand(2)) ||
118 cast<ConstantSDNode>(N->getOperand(2))->getValue() != 0) {
119 std::cerr << "Cannot allocate stack object with greater alignment than"
120 << " the stack alignment yet!";
121 abort();
122 }
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000123
Andrew Lenharth50b37842005-11-22 04:20:06 +0000124 SDOperand Chain = Select(N->getOperand(0));
125 SDOperand Amt = Select(N->getOperand(1));
126 SDOperand Reg = CurDAG->getRegister(Alpha::R30, MVT::i64);
127 SDOperand Val = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
128 Chain = Val.getValue(1);
129
130 // Subtract the amount (guaranteed to be a multiple of the stack alignment)
131 // from the stack pointer, giving us the result pointer.
132 SDOperand Result = CurDAG->getTargetNode(Alpha::SUBQ, MVT::i64, Val, Amt);
133
134 // Copy this result back into R30.
135 Chain = CurDAG->getNode(ISD::CopyToReg, MVT::Other, Chain, Reg, Result);
136
137 // Copy this result back out of R30 to make sure we're not using the stack
138 // space without decrementing the stack pointer.
139 Result = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
140
141 // Finally, replace the DYNAMIC_STACKALLOC with the copyfromreg.
142 CodeGenMap[Op.getValue(0)] = Result;
143 CodeGenMap[Op.getValue(1)] = Result.getValue(1);
144 return SDOperand(Result.Val, Op.ResNo);
145 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000146 case ISD::BRCOND: {
147 SDOperand Chain = Select(N->getOperand(0));
148 SDOperand CC = Select(N->getOperand(1));
Andrew Lenharth50b37842005-11-22 04:20:06 +0000149 MachineBasicBlock *Dest =
150 cast<BasicBlockSDNode>(N->getOperand(2))->getBasicBlock();
151 CurDAG->SelectNodeTo(N, Alpha::BNE, MVT::Other, CC, CurDAG->getBasicBlock(Dest), Chain);
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000152 return SDOperand(N, 0);
153 }
154 case ISD::LOAD:
155 case ISD::EXTLOAD:
156 case ISD::ZEXTLOAD:
157 case ISD::SEXTLOAD: {
158 SDOperand Chain = Select(N->getOperand(0));
159 SDOperand Address = Select(N->getOperand(1));
160 unsigned opcode = N->getOpcode();
161 unsigned Opc = Alpha::WTF;
162 if (opcode == ISD::LOAD)
163 switch (N->getValueType(0)) {
164 default: N->dump(); assert(0 && "Bad load!");
165 case MVT::i64: Opc = Alpha::LDQ; break;
166 case MVT::f64: Opc = Alpha::LDT; break;
167 case MVT::f32: Opc = Alpha::LDS; break;
168 }
169 else
170 switch (cast<VTSDNode>(N->getOperand(3))->getVT()) {
171 default: N->dump(); assert(0 && "Bad sign extend!");
172 case MVT::i32: Opc = Alpha::LDL;
173 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
174 case MVT::i16: Opc = Alpha::LDWU;
175 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
176 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
177 case MVT::i8: Opc = Alpha::LDBU;
178 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
179 }
180
181 CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), MVT::Other,
182 getI64Imm(0), Address, Chain);
183 return SDOperand(N, Op.ResNo);
184 }
Andrew Lenharth50b37842005-11-22 04:20:06 +0000185 case ISD::STORE:
186 case ISD::TRUNCSTORE: {
187 SDOperand Chain = Select(N->getOperand(0));
188 SDOperand Value = Select(N->getOperand(1));
189 SDOperand Address = Select(N->getOperand(2));
190
191 unsigned Opc = Alpha::WTF;
192
193 if (N->getOpcode() == ISD::STORE) {
194 switch (N->getOperand(1).getValueType()) {
195 case MVT::i64: Opc = Alpha::STQ; break;
196 case MVT::f64: Opc = Alpha::STT; break;
197 case MVT::f32: Opc = Alpha::STS; break;
198 default: assert(0 && "Bad store!");
199 };
200 } else { //TRUNCSTORE
201 switch (cast<VTSDNode>(N->getOperand(4))->getVT()) {
202 case MVT::i32: Opc = Alpha::STL; break;
203 case MVT::i16: Opc = Alpha::STW; break;
204 case MVT::i8: Opc = Alpha::STB; break;
205 default: assert(0 && "Bad truncstore!");
206 };
207 }
208 CurDAG->SelectNodeTo(N, Opc, MVT::Other, Value, getI64Imm(0), Address,
209 Chain);
210 return SDOperand(N, 0);
211 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000212
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000213 case ISD::BR: {
214 CurDAG->SelectNodeTo(N, Alpha::BR_DAG, MVT::Other, N->getOperand(1),
215 Select(N->getOperand(0)));
216 return SDOperand(N, 0);
217 }
218
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000219 case ISD::FrameIndex: {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000220 int FI = cast<FrameIndexSDNode>(N)->getIndex();
221 CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64,
222 CurDAG->getTargetFrameIndex(FI, MVT::i32),
223 getI64Imm(0));
224 return SDOperand(N, 0);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000225 }
226 case ISD::ConstantPool: {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000227 Constant *C = cast<ConstantPoolSDNode>(N)->get();
228 SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
229 Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg());
230 CurDAG->SelectNodeTo(N, Alpha::LDAr, MVT::i64, CPI, Tmp);
231 return SDOperand(N, 0);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000232 }
233 case ISD::GlobalAddress: {
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000234 GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal();
235 SDOperand GA = CurDAG->getTargetGlobalAddress(GV, MVT::i64);
236 CurDAG->SelectNodeTo(N, Alpha::LDQl, MVT::i64, GA, getGlobalBaseReg());
237 return SDOperand(N, 0);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000238 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000239 case ISD::ExternalSymbol:
240 CurDAG->SelectNodeTo(N, Alpha::LDQl, MVT::i64,
241 CurDAG->getTargetExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol(), MVT::i64),
242 CurDAG->getRegister(AlphaLowering.getVRegGP(), MVT::i64));
243 return SDOperand(N, 0);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000244
245 case ISD::CALLSEQ_START:
246 case ISD::CALLSEQ_END: {
247 unsigned Amt = cast<ConstantSDNode>(N->getOperand(1))->getValue();
248 unsigned Opc = N->getOpcode() == ISD::CALLSEQ_START ?
249 Alpha::ADJUSTSTACKDOWN : Alpha::ADJUSTSTACKUP;
250 CurDAG->SelectNodeTo(N, Opc, MVT::Other,
251 getI64Imm(Amt), Select(N->getOperand(0)));
252 return SDOperand(N, 0);
253 }
254 case ISD::RET: {
255 SDOperand Chain = Select(N->getOperand(0)); // Token chain.
256
257 if (N->getNumOperands() == 2) {
258 SDOperand Val = Select(N->getOperand(1));
259 if (N->getOperand(1).getValueType() == MVT::i64) {
260 Chain = CurDAG->getCopyToReg(Chain, Alpha::R0, Val);
261 }
262 }
263 //BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1);
264
265 // FIXME: add restoring of the RA to R26 to the chain
266 // Finally, select this to a ret instruction.
267 CurDAG->SelectNodeTo(N, Alpha::RETDAG, MVT::Other, Chain);
268 return SDOperand(N, 0);
269 }
Andrew Lenharth50b37842005-11-22 04:20:06 +0000270 case ISD::Constant: {
271 int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
272 if (val > (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT ||
273 val < (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
274 MachineConstantPool *CP = BB->getParent()->getConstantPool();
275 ConstantUInt *C =
276 ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
277 SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
278 Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg());
279 CurDAG->SelectNodeTo(N, Alpha::LDAr, MVT::i64, CPI, Tmp);
280 return SDOperand(N, 0);
281 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000282 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000283 }
284 case ISD::ConstantFP:
285 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
286 bool isDouble = N->getValueType(0) == MVT::f64;
287 MVT::ValueType T = isDouble ? MVT::f64 : MVT::f32;
288 if (CN->isExactlyValue(+0.0)) {
289 CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS, T,
290 CurDAG->getRegister(Alpha::F31, T),
291 CurDAG->getRegister(Alpha::F31, T));
292 return SDOperand(N, 0);
293 } else if ( CN->isExactlyValue(-0.0)) {
294 CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS, T,
295 CurDAG->getRegister(Alpha::F31, T),
296 CurDAG->getRegister(Alpha::F31, T));
297 return SDOperand(N, 0);
298 } else {
299 abort();
300 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000301 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000302 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000303 case ISD::SDIV:
304 case ISD::UDIV:
305 case ISD::UREM:
306 case ISD::SREM:
307 if (MVT::isInteger(N->getValueType(0))) {
308 const char* opstr = 0;
309 switch(N->getOpcode()) {
310 case ISD::UREM: opstr = "__remqu"; break;
311 case ISD::SREM: opstr = "__remq"; break;
312 case ISD::UDIV: opstr = "__divqu"; break;
313 case ISD::SDIV: opstr = "__divq"; break;
314 }
315 SDOperand Tmp1 = Select(N->getOperand(0)),
316 Tmp2 = Select(N->getOperand(1)),
317 Addr = CurDAG->getExternalSymbol(opstr, AlphaLowering.getPointerTy());
318 SDOperand Tmp3 = Select(Addr);
319 SDOperand Chain = CurDAG->getCopyToReg(CurDAG->getRoot(), Alpha::R24,
320 Tmp1, SDOperand());
321 Chain = CurDAG->getCopyToReg(CurDAG->getRoot(), Alpha::R25,
322 Tmp2, Chain.getValue(1));
323 Chain = CurDAG->getCopyToReg(CurDAG->getRoot(), Alpha::R27,
324 Tmp3, Chain.getValue(1));
325 Chain = CurDAG->getTargetNode(Alpha::JSRs, MVT::i64, MVT::Flag,
326 CurDAG->getRegister(Alpha::R27, MVT::i64),
327 getI64Imm(0));
328 return CurDAG->getCopyFromReg(Chain.getValue(1), Alpha::R27, MVT::i64,
329 Chain.getValue(1));
330 }
331 break;
332
333 case ISD::SETCC:
334 if (MVT::isFloatingPoint(N->getOperand(0).Val->getValueType(0))) {
335 unsigned Opc = Alpha::WTF;
336 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
337 bool rev = false;
338 switch(CC) {
339 default: N->dump(); assert(0 && "Unknown FP comparison!");
340 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
341 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
342 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
343 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
344 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
345 //case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
346 };
347 SDOperand tmp1 = Select(N->getOperand(0)),
348 tmp2 = Select(N->getOperand(1));
349 SDOperand cmp = CurDAG->getTargetNode(Opc, MVT::f64,
350 rev?tmp2:tmp1,
351 rev?tmp1:tmp2);
352 SDOperand LD;
353 if (AlphaLowering.hasITOF()) {
354 LD = CurDAG->getNode(AlphaISD::FTOIT_, MVT::i64, cmp);
355 } else {
356 int FrameIdx =
357 CurDAG->getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
358 SDOperand FI = CurDAG->getFrameIndex(FrameIdx, MVT::i64);
359 SDOperand ST = CurDAG->getTargetNode(Alpha::STT, MVT::Other,
360 cmp, FI, CurDAG->getRegister(Alpha::R31, MVT::i64));
361 LD = CurDAG->getTargetNode(Alpha::LDQ, MVT::i64, FI,
362 CurDAG->getRegister(Alpha::R31, MVT::i64),
363 ST);
364 }
365 SDOperand FP = CurDAG->getTargetNode(Alpha::CMPULT, MVT::i64,
366 CurDAG->getRegister(Alpha::R31, MVT::i64),
367 LD);
368 return FP;
369 }
370 break;
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000371 }
372
373 return SelectCode(Op);
374}
375
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000376SDOperand AlphaDAGToDAGISel::SelectCALL(SDOperand Op) {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000377 //TODO: add flag stuff to prevent nondeturministic breakage!
378
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000379 SDNode *N = Op.Val;
380 SDOperand Chain = Select(N->getOperand(0));
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000381 SDOperand Addr = Select(N->getOperand(1));
382
383// unsigned CallOpcode;
384 std::vector<SDOperand> CallOperands;
385 std::vector<MVT::ValueType> TypeOperands;
386
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000387 //grab the arguments
388 for(int i = 2, e = N->getNumOperands(); i < e; ++i) {
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000389 TypeOperands.push_back(N->getOperand(i).getValueType());
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000390 CallOperands.push_back(Select(N->getOperand(i)));
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000391 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000392 int count = N->getNumOperands() - 2;
393
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000394 static const unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
395 Alpha::R19, Alpha::R20, Alpha::R21};
396 static const unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
397 Alpha::F19, Alpha::F20, Alpha::F21};
398
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000399 for (int i = 0; i < std::min(6, count); ++i) {
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000400 if (MVT::isInteger(TypeOperands[i])) {
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000401 Chain = CurDAG->getCopyToReg(Chain, args_int[i], CallOperands[i]);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000402 } else if (TypeOperands[i] == MVT::f32 || TypeOperands[i] == MVT::f64) {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000403 Chain = CurDAG->getCopyToReg(Chain, args_float[i], CallOperands[i]);
404 } else
405 assert(0 && "Unknown operand");
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000406 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000407 for (int i = 6; i < count; ++i) {
408 unsigned Opc = Alpha::WTF;
409 if (MVT::isInteger(TypeOperands[i])) {
410 Opc = Alpha::STQ;
411 } else if (TypeOperands[i] == MVT::f32) {
412 Opc = Alpha::STS;
413 } else if (TypeOperands[i] == MVT::f64) {
414 Opc = Alpha::STT;
415 } else
416 assert(0 && "Unknown operand");
417 Chain = CurDAG->getTargetNode(Opc, MVT::Other, CallOperands[i],
418 getI64Imm((i - 6) * 8),
419 CurDAG->getRegister(Alpha::R30, MVT::i64),
420 Chain);
421 }
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000422
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000423 Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Addr);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000424 // Finally, once everything is in registers to pass to the call, emit the
425 // call itself.
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000426 Chain = CurDAG->getTargetNode(Alpha::JSRDAG, MVT::Other, Chain );
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000427
428 std::vector<SDOperand> CallResults;
429
430 switch (N->getValueType(0)) {
431 default: assert(0 && "Unexpected ret value!");
432 case MVT::Other: break;
433 case MVT::i64:
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000434 Chain = CurDAG->getCopyFromReg(Chain, Alpha::R0, MVT::i64).getValue(1);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000435 CallResults.push_back(Chain.getValue(0));
436 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000437 case MVT::f32:
438 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f32).getValue(1);
439 CallResults.push_back(Chain.getValue(0));
440 break;
441 case MVT::f64:
442 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f64).getValue(1);
443 CallResults.push_back(Chain.getValue(0));
444 break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000445 }
446
447 CallResults.push_back(Chain);
448 for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
449 CodeGenMap[Op.getValue(i)] = CallResults[i];
450 return CallResults[Op.ResNo];
451}
452
453
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000454/// createAlphaISelDag - This pass converts a legalized DAG into a
455/// Alpha-specific DAG, ready for instruction scheduling.
456///
457FunctionPass *llvm::createAlphaISelDag(TargetMachine &TM) {
458 return new AlphaDAGToDAGISel(TM);
459}