blob: 6d71a2cb61f103466c6b89e22bc07a6e51eb4c2e [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>
Chris Lattner2c2c6c62006-01-22 23:41:00 +000031#include <iostream>
Andrew Lenharthd97591a2005-10-20 00:29:02 +000032using namespace llvm;
33
34namespace {
35
36 //===--------------------------------------------------------------------===//
37 /// AlphaDAGToDAGISel - Alpha specific code to select Alpha machine
38 /// instructions for SelectionDAG operations.
Andrew Lenharthd97591a2005-10-20 00:29:02 +000039 class AlphaDAGToDAGISel : public SelectionDAGISel {
40 AlphaTargetLowering AlphaLowering;
41
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +000042 static const int64_t IMM_LOW = -32768;
43 static const int64_t IMM_HIGH = 32767;
44 static const int64_t IMM_MULT = 65536;
Andrew Lenharthfeab2f82006-01-01 22:16:14 +000045 static const int64_t IMM_FULLHIGH = IMM_HIGH + IMM_HIGH * IMM_MULT;
46 static const int64_t IMM_FULLLOW = IMM_LOW + IMM_LOW * IMM_MULT;
47
48 static int64_t get_ldah16(int64_t x) {
49 int64_t y = x / IMM_MULT;
50 if (x % IMM_MULT > IMM_HIGH)
51 ++y;
52 return y;
53 }
54
55 static int64_t get_lda16(int64_t x) {
56 return x - get_ldah16(x) * IMM_MULT;
57 }
58
59 static uint64_t get_zapImm(uint64_t x) {
60 unsigned int build = 0;
61 for(int i = 0; i < 8; ++i)
62 {
63 if ((x & 0x00FF) == 0x00FF)
64 build |= 1 << i;
65 else if ((x & 0x00FF) != 0)
66 { build = 0; break; }
67 x >>= 8;
68 }
Andrew Lenharth5d423602006-01-02 21:15:53 +000069 return build;
Andrew Lenharthfeab2f82006-01-01 22:16:14 +000070 }
71
72 static bool isFPZ(SDOperand N) {
73 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
74 return (CN && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)));
75 }
76 static bool isFPZn(SDOperand N) {
77 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
78 return (CN && CN->isExactlyValue(-0.0));
79 }
80 static bool isFPZp(SDOperand N) {
81 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
82 return (CN && CN->isExactlyValue(+0.0));
83 }
84
Andrew Lenharthd97591a2005-10-20 00:29:02 +000085 public:
86 AlphaDAGToDAGISel(TargetMachine &TM)
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +000087 : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
88 {}
Andrew Lenharthd97591a2005-10-20 00:29:02 +000089
90 /// getI64Imm - Return a target constant with the specified value, of type
91 /// i64.
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000092 inline SDOperand getI64Imm(int64_t Imm) {
Andrew Lenharthd97591a2005-10-20 00:29:02 +000093 return CurDAG->getTargetConstant(Imm, MVT::i64);
94 }
95
Andrew Lenharthd97591a2005-10-20 00:29:02 +000096 // Select - Convert the specified operand from a target-independent to a
97 // target-specific node if it hasn't already been changed.
98 SDOperand Select(SDOperand Op);
99
100 /// InstructionSelectBasicBlock - This callback is invoked by
101 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
102 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
103
104 virtual const char *getPassName() const {
105 return "Alpha DAG->DAG Pattern Instruction Selection";
106 }
107
108// Include the pieces autogenerated from the target description.
109#include "AlphaGenDAGISel.inc"
110
111private:
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000112 SDOperand getGlobalBaseReg();
Andrew Lenharth93526222005-12-01 01:53:10 +0000113 SDOperand getRASaveReg();
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000114 SDOperand SelectCALL(SDOperand Op);
115
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000116 };
117}
118
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000119/// getGlobalBaseReg - Output the instructions required to put the
120/// GOT address into a register.
121///
122SDOperand AlphaDAGToDAGISel::getGlobalBaseReg() {
Andrew Lenharth93526222005-12-01 01:53:10 +0000123 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
124 AlphaLowering.getVRegGP(),
125 MVT::i64);
126}
127
128/// getRASaveReg - Grab the return address
129///
130SDOperand AlphaDAGToDAGISel::getRASaveReg() {
131 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
132 AlphaLowering.getVRegRA(),
133 MVT::i64);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000134}
135
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000136/// InstructionSelectBasicBlock - This callback is invoked by
137/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
138void AlphaDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
139 DEBUG(BB->dump());
140
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000141 // Select target instructions for the DAG.
142 DAG.setRoot(Select(DAG.getRoot()));
143 CodeGenMap.clear();
144 DAG.RemoveDeadNodes();
145
146 // Emit machine code to BB.
147 ScheduleAndEmitDAG(DAG);
148}
149
150// Select - Convert the specified operand from a target-independent to a
151// target-specific node if it hasn't already been changed.
152SDOperand AlphaDAGToDAGISel::Select(SDOperand Op) {
153 SDNode *N = Op.Val;
154 if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
155 N->getOpcode() < AlphaISD::FIRST_NUMBER)
156 return Op; // Already selected.
157
158 // If this has already been converted, use it.
159 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op);
160 if (CGMI != CodeGenMap.end()) return CGMI->second;
161
162 switch (N->getOpcode()) {
163 default: break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000164 case ISD::TAILCALL:
165 case ISD::CALL: return SelectCALL(Op);
166
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000167 case ISD::FrameIndex: {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000168 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000169 return CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64,
170 CurDAG->getTargetFrameIndex(FI, MVT::i32),
171 getI64Imm(0));
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000172 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000173 case AlphaISD::GlobalBaseReg:
174 return getGlobalBaseReg();
175
Andrew Lenharth53d89702005-12-25 01:34:27 +0000176 case AlphaISD::DivCall: {
177 SDOperand Chain = CurDAG->getEntryNode();
178 Chain = CurDAG->getCopyToReg(Chain, Alpha::R24, Select(Op.getOperand(1)),
179 SDOperand(0,0));
180 Chain = CurDAG->getCopyToReg(Chain, Alpha::R25, Select(Op.getOperand(2)),
181 Chain.getValue(1));
182 Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Select(Op.getOperand(0)),
183 Chain.getValue(1));
Andrew Lenhartheececba2005-12-25 17:36:48 +0000184 Chain = CurDAG->getTargetNode(Alpha::JSRs, MVT::Other, MVT::Flag,
Andrew Lenharth53d89702005-12-25 01:34:27 +0000185 Chain, Chain.getValue(1));
186 Chain = CurDAG->getCopyFromReg(Chain, Alpha::R27, MVT::i64,
187 Chain.getValue(1));
188 return CurDAG->SelectNodeTo(N, Alpha::BIS, MVT::i64, Chain, Chain);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000189 }
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000190
Andrew Lenharth739027e2006-01-16 21:22:38 +0000191 case ISD::READCYCLECOUNTER: {
192 SDOperand Chain = Select(N->getOperand(0)); //Select chain
193 return CurDAG->SelectNodeTo(N, Alpha::RPCC, MVT::i64, Chain);
194 }
195
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000196 case ISD::RET: {
197 SDOperand Chain = Select(N->getOperand(0)); // Token chain.
Andrew Lenharth93526222005-12-01 01:53:10 +0000198 SDOperand InFlag;
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000199
200 if (N->getNumOperands() == 2) {
201 SDOperand Val = Select(N->getOperand(1));
202 if (N->getOperand(1).getValueType() == MVT::i64) {
Andrew Lenharth93526222005-12-01 01:53:10 +0000203 Chain = CurDAG->getCopyToReg(Chain, Alpha::R0, Val, InFlag);
204 InFlag = Chain.getValue(1);
Andrew Lenharthe41419f2005-12-11 03:54:31 +0000205 } else if (N->getOperand(1).getValueType() == MVT::f64 ||
206 N->getOperand(1).getValueType() == MVT::f32) {
207 Chain = CurDAG->getCopyToReg(Chain, Alpha::F0, Val, InFlag);
208 InFlag = Chain.getValue(1);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000209 }
210 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000211 Chain = CurDAG->getCopyToReg(Chain, Alpha::R26, getRASaveReg(), InFlag);
212 InFlag = Chain.getValue(1);
213
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000214 // Finally, select this to a ret instruction.
Andrew Lenharth93526222005-12-01 01:53:10 +0000215 return CurDAG->SelectNodeTo(N, Alpha::RETDAG, MVT::Other, Chain, InFlag);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000216 }
Andrew Lenharth50b37842005-11-22 04:20:06 +0000217 case ISD::Constant: {
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +0000218 uint64_t uval = cast<ConstantSDNode>(N)->getValue();
Andrew Lenharth919e6662006-01-06 19:41:51 +0000219
220 if (uval == 0)
221 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), Alpha::R31, MVT::i64);
222
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +0000223 int64_t val = (int64_t)uval;
224 int32_t val32 = (int32_t)val;
225 if (val <= IMM_HIGH + IMM_HIGH * IMM_MULT &&
226 val >= IMM_LOW + IMM_LOW * IMM_MULT)
227 break; //(LDAH (LDA))
228 if ((uval >> 32) == 0 && //empty upper bits
Andrew Lenharthfeab2f82006-01-01 22:16:14 +0000229 val32 <= IMM_HIGH + IMM_HIGH * IMM_MULT)
230 // val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +0000231 break; //(zext (LDAH (LDA)))
232 //Else use the constant pool
233 MachineConstantPool *CP = BB->getParent()->getConstantPool();
234 ConstantUInt *C =
235 ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , uval);
236 SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
237 Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg());
238 return CurDAG->SelectNodeTo(N, Alpha::LDQr, MVT::i64, MVT::Other,
239 CPI, Tmp, CurDAG->getEntryNode());
Andrew Lenharth50b37842005-11-22 04:20:06 +0000240 }
241 case ISD::ConstantFP:
242 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
243 bool isDouble = N->getValueType(0) == MVT::f64;
244 MVT::ValueType T = isDouble ? MVT::f64 : MVT::f32;
245 if (CN->isExactlyValue(+0.0)) {
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000246 return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS,
247 T, CurDAG->getRegister(Alpha::F31, T),
248 CurDAG->getRegister(Alpha::F31, T));
Andrew Lenharth50b37842005-11-22 04:20:06 +0000249 } else if ( CN->isExactlyValue(-0.0)) {
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000250 return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS,
251 T, CurDAG->getRegister(Alpha::F31, T),
252 CurDAG->getRegister(Alpha::F31, T));
Andrew Lenharth50b37842005-11-22 04:20:06 +0000253 } else {
254 abort();
255 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000256 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000257 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000258
259 case ISD::SETCC:
260 if (MVT::isFloatingPoint(N->getOperand(0).Val->getValueType(0))) {
261 unsigned Opc = Alpha::WTF;
262 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
263 bool rev = false;
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000264 bool isNE = false;
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000265 switch(CC) {
266 default: N->dump(); assert(0 && "Unknown FP comparison!");
267 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
268 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
269 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
270 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
271 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000272 case ISD::SETNE: Opc = Alpha::CMPTEQ; isNE = true; break;
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000273 };
274 SDOperand tmp1 = Select(N->getOperand(0)),
275 tmp2 = Select(N->getOperand(1));
276 SDOperand cmp = CurDAG->getTargetNode(Opc, MVT::f64,
277 rev?tmp2:tmp1,
278 rev?tmp1:tmp2);
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000279 if (isNE)
280 cmp = CurDAG->getTargetNode(Alpha::CMPTEQ, MVT::f64, cmp,
281 CurDAG->getRegister(Alpha::F31, MVT::f64));
282
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000283 SDOperand LD;
284 if (AlphaLowering.hasITOF()) {
285 LD = CurDAG->getNode(AlphaISD::FTOIT_, MVT::i64, cmp);
286 } else {
287 int FrameIdx =
288 CurDAG->getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
289 SDOperand FI = CurDAG->getFrameIndex(FrameIdx, MVT::i64);
290 SDOperand ST = CurDAG->getTargetNode(Alpha::STT, MVT::Other,
291 cmp, FI, CurDAG->getRegister(Alpha::R31, MVT::i64));
292 LD = CurDAG->getTargetNode(Alpha::LDQ, MVT::i64, FI,
293 CurDAG->getRegister(Alpha::R31, MVT::i64),
294 ST);
295 }
296 SDOperand FP = CurDAG->getTargetNode(Alpha::CMPULT, MVT::i64,
297 CurDAG->getRegister(Alpha::R31, MVT::i64),
298 LD);
299 return FP;
300 }
301 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000302
Andrew Lenharth361f45a2005-12-12 17:43:52 +0000303 case ISD::SELECT:
304 if (MVT::isFloatingPoint(N->getValueType(0)) &&
305 (N->getOperand(0).getOpcode() != ISD::SETCC ||
306 !MVT::isFloatingPoint(N->getOperand(0).getOperand(1).getValueType()))) {
307 //This should be the condition not covered by the Patterns
308 //FIXME: Don't have SelectCode die, but rather return something testable
309 // so that things like this can be caught in fall though code
310 //move int to fp
311 bool isDouble = N->getValueType(0) == MVT::f64;
312 SDOperand LD,
313 cond = Select(N->getOperand(0)),
314 TV = Select(N->getOperand(1)),
315 FV = Select(N->getOperand(2));
316
317 if (AlphaLowering.hasITOF()) {
318 LD = CurDAG->getNode(AlphaISD::ITOFT_, MVT::f64, cond);
319 } else {
320 int FrameIdx =
321 CurDAG->getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
322 SDOperand FI = CurDAG->getFrameIndex(FrameIdx, MVT::i64);
323 SDOperand ST = CurDAG->getTargetNode(Alpha::STQ, MVT::Other,
324 cond, FI, CurDAG->getRegister(Alpha::R31, MVT::i64));
325 LD = CurDAG->getTargetNode(Alpha::LDT, MVT::f64, FI,
326 CurDAG->getRegister(Alpha::R31, MVT::i64),
327 ST);
328 }
Andrew Lenharth110f2242005-12-12 20:30:09 +0000329 SDOperand FP = CurDAG->getTargetNode(isDouble?Alpha::FCMOVNET:Alpha::FCMOVNES,
Andrew Lenharth361f45a2005-12-12 17:43:52 +0000330 MVT::f64, FV, TV, LD);
331 return FP;
332 }
333 break;
334
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000335 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000336
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000337 return SelectCode(Op);
338}
339
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000340SDOperand AlphaDAGToDAGISel::SelectCALL(SDOperand Op) {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000341 //TODO: add flag stuff to prevent nondeturministic breakage!
342
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000343 SDNode *N = Op.Val;
344 SDOperand Chain = Select(N->getOperand(0));
Andrew Lenhartheececba2005-12-25 17:36:48 +0000345 SDOperand Addr = N->getOperand(1);
Andrew Lenharth93526222005-12-01 01:53:10 +0000346 SDOperand InFlag; // Null incoming flag value.
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000347
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000348 std::vector<SDOperand> CallOperands;
349 std::vector<MVT::ValueType> TypeOperands;
350
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000351 //grab the arguments
352 for(int i = 2, e = N->getNumOperands(); i < e; ++i) {
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000353 TypeOperands.push_back(N->getOperand(i).getValueType());
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000354 CallOperands.push_back(Select(N->getOperand(i)));
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000355 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000356 int count = N->getNumOperands() - 2;
357
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000358 static const unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
359 Alpha::R19, Alpha::R20, Alpha::R21};
360 static const unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
361 Alpha::F19, Alpha::F20, Alpha::F21};
362
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000363 for (int i = 6; i < count; ++i) {
364 unsigned Opc = Alpha::WTF;
365 if (MVT::isInteger(TypeOperands[i])) {
366 Opc = Alpha::STQ;
367 } else if (TypeOperands[i] == MVT::f32) {
368 Opc = Alpha::STS;
369 } else if (TypeOperands[i] == MVT::f64) {
370 Opc = Alpha::STT;
371 } else
372 assert(0 && "Unknown operand");
373 Chain = CurDAG->getTargetNode(Opc, MVT::Other, CallOperands[i],
374 getI64Imm((i - 6) * 8),
Andrew Lenharth93526222005-12-01 01:53:10 +0000375 CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64),
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000376 Chain);
377 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000378 for (int i = 0; i < std::min(6, count); ++i) {
379 if (MVT::isInteger(TypeOperands[i])) {
380 Chain = CurDAG->getCopyToReg(Chain, args_int[i], CallOperands[i], InFlag);
381 InFlag = Chain.getValue(1);
382 } else if (TypeOperands[i] == MVT::f32 || TypeOperands[i] == MVT::f64) {
383 Chain = CurDAG->getCopyToReg(Chain, args_float[i], CallOperands[i], InFlag);
384 InFlag = Chain.getValue(1);
385 } else
386 assert(0 && "Unknown operand");
387 }
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000388
Andrew Lenharth93526222005-12-01 01:53:10 +0000389
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000390 // Finally, once everything is in registers to pass to the call, emit the
391 // call itself.
Andrew Lenhartheececba2005-12-25 17:36:48 +0000392 if (Addr.getOpcode() == AlphaISD::GPRelLo) {
393 SDOperand GOT = getGlobalBaseReg();
394 Chain = CurDAG->getCopyToReg(Chain, Alpha::R29, GOT, InFlag);
395 InFlag = Chain.getValue(1);
396 Chain = CurDAG->getTargetNode(Alpha::BSR, MVT::Other, MVT::Flag,
397 Addr.getOperand(0), Chain, InFlag);
398 } else {
399 Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Select(Addr), InFlag);
400 InFlag = Chain.getValue(1);
401 Chain = CurDAG->getTargetNode(Alpha::JSR, MVT::Other, MVT::Flag,
402 Chain, InFlag );
403 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000404 InFlag = Chain.getValue(1);
405
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000406 std::vector<SDOperand> CallResults;
407
408 switch (N->getValueType(0)) {
409 default: assert(0 && "Unexpected ret value!");
410 case MVT::Other: break;
411 case MVT::i64:
Andrew Lenharth93526222005-12-01 01:53:10 +0000412 Chain = CurDAG->getCopyFromReg(Chain, Alpha::R0, MVT::i64, InFlag).getValue(1);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000413 CallResults.push_back(Chain.getValue(0));
414 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000415 case MVT::f32:
Andrew Lenharth93526222005-12-01 01:53:10 +0000416 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f32, InFlag).getValue(1);
Andrew Lenharth50b37842005-11-22 04:20:06 +0000417 CallResults.push_back(Chain.getValue(0));
418 break;
419 case MVT::f64:
Andrew Lenharth93526222005-12-01 01:53:10 +0000420 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f64, InFlag).getValue(1);
Andrew Lenharth50b37842005-11-22 04:20:06 +0000421 CallResults.push_back(Chain.getValue(0));
422 break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000423 }
424
425 CallResults.push_back(Chain);
426 for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
427 CodeGenMap[Op.getValue(i)] = CallResults[i];
428 return CallResults[Op.ResNo];
429}
430
431
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000432/// createAlphaISelDag - This pass converts a legalized DAG into a
433/// Alpha-specific DAG, ready for instruction scheduling.
434///
435FunctionPass *llvm::createAlphaISelDag(TargetMachine &TM) {
436 return new AlphaDAGToDAGISel(TM);
437}