blob: f207664f04861a44c6e86440719389a8bf7dea1a [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.
Andrew Lenharthd97591a2005-10-20 00:29:02 +000038 class AlphaDAGToDAGISel : public SelectionDAGISel {
39 AlphaTargetLowering AlphaLowering;
40
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +000041 static const int64_t IMM_LOW = -32768;
42 static const int64_t IMM_HIGH = 32767;
43 static const int64_t IMM_MULT = 65536;
Andrew Lenharthfeab2f82006-01-01 22:16:14 +000044 static const int64_t IMM_FULLHIGH = IMM_HIGH + IMM_HIGH * IMM_MULT;
45 static const int64_t IMM_FULLLOW = IMM_LOW + IMM_LOW * IMM_MULT;
46
47 static int64_t get_ldah16(int64_t x) {
48 int64_t y = x / IMM_MULT;
49 if (x % IMM_MULT > IMM_HIGH)
50 ++y;
51 return y;
52 }
53
54 static int64_t get_lda16(int64_t x) {
55 return x - get_ldah16(x) * IMM_MULT;
56 }
57
58 static uint64_t get_zapImm(uint64_t x) {
59 unsigned int build = 0;
60 for(int i = 0; i < 8; ++i)
61 {
62 if ((x & 0x00FF) == 0x00FF)
63 build |= 1 << i;
64 else if ((x & 0x00FF) != 0)
65 { build = 0; break; }
66 x >>= 8;
67 }
Andrew Lenharth5d423602006-01-02 21:15:53 +000068 return build;
Andrew Lenharthfeab2f82006-01-01 22:16:14 +000069 }
70
71 static bool isFPZ(SDOperand N) {
72 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
73 return (CN && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)));
74 }
75 static bool isFPZn(SDOperand N) {
76 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
77 return (CN && CN->isExactlyValue(-0.0));
78 }
79 static bool isFPZp(SDOperand N) {
80 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
81 return (CN && CN->isExactlyValue(+0.0));
82 }
83
Andrew Lenharthd97591a2005-10-20 00:29:02 +000084 public:
85 AlphaDAGToDAGISel(TargetMachine &TM)
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +000086 : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
87 {}
Andrew Lenharthd97591a2005-10-20 00:29:02 +000088
89 /// getI64Imm - Return a target constant with the specified value, of type
90 /// i64.
Andrew Lenharth756fbeb2005-10-22 22:06:58 +000091 inline SDOperand getI64Imm(int64_t Imm) {
Andrew Lenharthd97591a2005-10-20 00:29:02 +000092 return CurDAG->getTargetConstant(Imm, MVT::i64);
93 }
94
Andrew Lenharthd97591a2005-10-20 00:29:02 +000095 // Select - Convert the specified operand from a target-independent to a
96 // target-specific node if it hasn't already been changed.
97 SDOperand Select(SDOperand Op);
98
99 /// InstructionSelectBasicBlock - This callback is invoked by
100 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
101 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
102
103 virtual const char *getPassName() const {
104 return "Alpha DAG->DAG Pattern Instruction Selection";
105 }
106
107// Include the pieces autogenerated from the target description.
108#include "AlphaGenDAGISel.inc"
109
110private:
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000111 SDOperand getGlobalBaseReg();
Andrew Lenharth93526222005-12-01 01:53:10 +0000112 SDOperand getRASaveReg();
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000113 SDOperand SelectCALL(SDOperand Op);
114
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000115 };
116}
117
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000118/// getGlobalBaseReg - Output the instructions required to put the
119/// GOT address into a register.
120///
121SDOperand AlphaDAGToDAGISel::getGlobalBaseReg() {
Andrew Lenharth93526222005-12-01 01:53:10 +0000122 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
123 AlphaLowering.getVRegGP(),
124 MVT::i64);
125}
126
127/// getRASaveReg - Grab the return address
128///
129SDOperand AlphaDAGToDAGISel::getRASaveReg() {
130 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
131 AlphaLowering.getVRegRA(),
132 MVT::i64);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000133}
134
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000135/// InstructionSelectBasicBlock - This callback is invoked by
136/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
137void AlphaDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
138 DEBUG(BB->dump());
139
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000140 // Select target instructions for the DAG.
141 DAG.setRoot(Select(DAG.getRoot()));
142 CodeGenMap.clear();
143 DAG.RemoveDeadNodes();
144
145 // Emit machine code to BB.
146 ScheduleAndEmitDAG(DAG);
147}
148
149// Select - Convert the specified operand from a target-independent to a
150// target-specific node if it hasn't already been changed.
151SDOperand AlphaDAGToDAGISel::Select(SDOperand Op) {
152 SDNode *N = Op.Val;
153 if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
154 N->getOpcode() < AlphaISD::FIRST_NUMBER)
155 return Op; // Already selected.
156
157 // If this has already been converted, use it.
158 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op);
159 if (CGMI != CodeGenMap.end()) return CGMI->second;
160
161 switch (N->getOpcode()) {
162 default: break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000163 case ISD::TAILCALL:
164 case ISD::CALL: return SelectCALL(Op);
165
Andrew Lenharth50b37842005-11-22 04:20:06 +0000166 case ISD::DYNAMIC_STACKALLOC: {
167 if (!isa<ConstantSDNode>(N->getOperand(2)) ||
168 cast<ConstantSDNode>(N->getOperand(2))->getValue() != 0) {
169 std::cerr << "Cannot allocate stack object with greater alignment than"
170 << " the stack alignment yet!";
171 abort();
172 }
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000173
Andrew Lenharth50b37842005-11-22 04:20:06 +0000174 SDOperand Chain = Select(N->getOperand(0));
175 SDOperand Amt = Select(N->getOperand(1));
176 SDOperand Reg = CurDAG->getRegister(Alpha::R30, MVT::i64);
177 SDOperand Val = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
178 Chain = Val.getValue(1);
179
180 // Subtract the amount (guaranteed to be a multiple of the stack alignment)
181 // from the stack pointer, giving us the result pointer.
182 SDOperand Result = CurDAG->getTargetNode(Alpha::SUBQ, MVT::i64, Val, Amt);
183
184 // Copy this result back into R30.
185 Chain = CurDAG->getNode(ISD::CopyToReg, MVT::Other, Chain, Reg, Result);
186
187 // Copy this result back out of R30 to make sure we're not using the stack
188 // space without decrementing the stack pointer.
189 Result = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
190
191 // Finally, replace the DYNAMIC_STACKALLOC with the copyfromreg.
192 CodeGenMap[Op.getValue(0)] = Result;
193 CodeGenMap[Op.getValue(1)] = Result.getValue(1);
194 return SDOperand(Result.Val, Op.ResNo);
195 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000196
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000197 case ISD::FrameIndex: {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000198 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000199 return CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64,
200 CurDAG->getTargetFrameIndex(FI, MVT::i32),
201 getI64Imm(0));
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000202 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000203 case AlphaISD::GlobalBaseReg:
204 return getGlobalBaseReg();
205
Andrew Lenharth53d89702005-12-25 01:34:27 +0000206 case AlphaISD::DivCall: {
207 SDOperand Chain = CurDAG->getEntryNode();
208 Chain = CurDAG->getCopyToReg(Chain, Alpha::R24, Select(Op.getOperand(1)),
209 SDOperand(0,0));
210 Chain = CurDAG->getCopyToReg(Chain, Alpha::R25, Select(Op.getOperand(2)),
211 Chain.getValue(1));
212 Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Select(Op.getOperand(0)),
213 Chain.getValue(1));
Andrew Lenhartheececba2005-12-25 17:36:48 +0000214 Chain = CurDAG->getTargetNode(Alpha::JSRs, MVT::Other, MVT::Flag,
Andrew Lenharth53d89702005-12-25 01:34:27 +0000215 Chain, Chain.getValue(1));
216 Chain = CurDAG->getCopyFromReg(Chain, Alpha::R27, MVT::i64,
217 Chain.getValue(1));
218 return CurDAG->SelectNodeTo(N, Alpha::BIS, MVT::i64, Chain, Chain);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000219 }
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000220
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000221 case ISD::RET: {
222 SDOperand Chain = Select(N->getOperand(0)); // Token chain.
Andrew Lenharth93526222005-12-01 01:53:10 +0000223 SDOperand InFlag;
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000224
225 if (N->getNumOperands() == 2) {
226 SDOperand Val = Select(N->getOperand(1));
227 if (N->getOperand(1).getValueType() == MVT::i64) {
Andrew Lenharth93526222005-12-01 01:53:10 +0000228 Chain = CurDAG->getCopyToReg(Chain, Alpha::R0, Val, InFlag);
229 InFlag = Chain.getValue(1);
Andrew Lenharthe41419f2005-12-11 03:54:31 +0000230 } else if (N->getOperand(1).getValueType() == MVT::f64 ||
231 N->getOperand(1).getValueType() == MVT::f32) {
232 Chain = CurDAG->getCopyToReg(Chain, Alpha::F0, Val, InFlag);
233 InFlag = Chain.getValue(1);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000234 }
235 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000236 Chain = CurDAG->getCopyToReg(Chain, Alpha::R26, getRASaveReg(), InFlag);
237 InFlag = Chain.getValue(1);
238
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000239 // Finally, select this to a ret instruction.
Andrew Lenharth93526222005-12-01 01:53:10 +0000240 return CurDAG->SelectNodeTo(N, Alpha::RETDAG, MVT::Other, Chain, InFlag);
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000241 }
Andrew Lenharth50b37842005-11-22 04:20:06 +0000242 case ISD::Constant: {
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +0000243 uint64_t uval = cast<ConstantSDNode>(N)->getValue();
244 int64_t val = (int64_t)uval;
245 int32_t val32 = (int32_t)val;
246 if (val <= IMM_HIGH + IMM_HIGH * IMM_MULT &&
247 val >= IMM_LOW + IMM_LOW * IMM_MULT)
248 break; //(LDAH (LDA))
249 if ((uval >> 32) == 0 && //empty upper bits
Andrew Lenharthfeab2f82006-01-01 22:16:14 +0000250 val32 <= IMM_HIGH + IMM_HIGH * IMM_MULT)
251 // val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
Andrew Lenharthdcbaf8a2005-12-30 02:30:02 +0000252 break; //(zext (LDAH (LDA)))
253 //Else use the constant pool
254 MachineConstantPool *CP = BB->getParent()->getConstantPool();
255 ConstantUInt *C =
256 ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , uval);
257 SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
258 Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg());
259 return CurDAG->SelectNodeTo(N, Alpha::LDQr, MVT::i64, MVT::Other,
260 CPI, Tmp, CurDAG->getEntryNode());
Andrew Lenharth50b37842005-11-22 04:20:06 +0000261 }
262 case ISD::ConstantFP:
263 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
264 bool isDouble = N->getValueType(0) == MVT::f64;
265 MVT::ValueType T = isDouble ? MVT::f64 : MVT::f32;
266 if (CN->isExactlyValue(+0.0)) {
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000267 return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS,
268 T, CurDAG->getRegister(Alpha::F31, T),
269 CurDAG->getRegister(Alpha::F31, T));
Andrew Lenharth50b37842005-11-22 04:20:06 +0000270 } else if ( CN->isExactlyValue(-0.0)) {
Chris Lattnerd5acfb42005-11-30 23:04:38 +0000271 return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS,
272 T, CurDAG->getRegister(Alpha::F31, T),
273 CurDAG->getRegister(Alpha::F31, T));
Andrew Lenharth50b37842005-11-22 04:20:06 +0000274 } else {
275 abort();
276 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000277 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000278 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000279
280 case ISD::SETCC:
281 if (MVT::isFloatingPoint(N->getOperand(0).Val->getValueType(0))) {
282 unsigned Opc = Alpha::WTF;
283 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
284 bool rev = false;
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000285 bool isNE = false;
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000286 switch(CC) {
287 default: N->dump(); assert(0 && "Unknown FP comparison!");
288 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
289 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
290 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
291 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
292 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000293 case ISD::SETNE: Opc = Alpha::CMPTEQ; isNE = true; break;
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000294 };
295 SDOperand tmp1 = Select(N->getOperand(0)),
296 tmp2 = Select(N->getOperand(1));
297 SDOperand cmp = CurDAG->getTargetNode(Opc, MVT::f64,
298 rev?tmp2:tmp1,
299 rev?tmp1:tmp2);
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000300 if (isNE)
301 cmp = CurDAG->getTargetNode(Alpha::CMPTEQ, MVT::f64, cmp,
302 CurDAG->getRegister(Alpha::F31, MVT::f64));
303
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000304 SDOperand LD;
305 if (AlphaLowering.hasITOF()) {
306 LD = CurDAG->getNode(AlphaISD::FTOIT_, MVT::i64, cmp);
307 } else {
308 int FrameIdx =
309 CurDAG->getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
310 SDOperand FI = CurDAG->getFrameIndex(FrameIdx, MVT::i64);
311 SDOperand ST = CurDAG->getTargetNode(Alpha::STT, MVT::Other,
312 cmp, FI, CurDAG->getRegister(Alpha::R31, MVT::i64));
313 LD = CurDAG->getTargetNode(Alpha::LDQ, MVT::i64, FI,
314 CurDAG->getRegister(Alpha::R31, MVT::i64),
315 ST);
316 }
317 SDOperand FP = CurDAG->getTargetNode(Alpha::CMPULT, MVT::i64,
318 CurDAG->getRegister(Alpha::R31, MVT::i64),
319 LD);
320 return FP;
321 }
322 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000323
Andrew Lenharth361f45a2005-12-12 17:43:52 +0000324 case ISD::SELECT:
325 if (MVT::isFloatingPoint(N->getValueType(0)) &&
326 (N->getOperand(0).getOpcode() != ISD::SETCC ||
327 !MVT::isFloatingPoint(N->getOperand(0).getOperand(1).getValueType()))) {
328 //This should be the condition not covered by the Patterns
329 //FIXME: Don't have SelectCode die, but rather return something testable
330 // so that things like this can be caught in fall though code
331 //move int to fp
332 bool isDouble = N->getValueType(0) == MVT::f64;
333 SDOperand LD,
334 cond = Select(N->getOperand(0)),
335 TV = Select(N->getOperand(1)),
336 FV = Select(N->getOperand(2));
337
338 if (AlphaLowering.hasITOF()) {
339 LD = CurDAG->getNode(AlphaISD::ITOFT_, MVT::f64, cond);
340 } else {
341 int FrameIdx =
342 CurDAG->getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
343 SDOperand FI = CurDAG->getFrameIndex(FrameIdx, MVT::i64);
344 SDOperand ST = CurDAG->getTargetNode(Alpha::STQ, MVT::Other,
345 cond, FI, CurDAG->getRegister(Alpha::R31, MVT::i64));
346 LD = CurDAG->getTargetNode(Alpha::LDT, MVT::f64, FI,
347 CurDAG->getRegister(Alpha::R31, MVT::i64),
348 ST);
349 }
Andrew Lenharth110f2242005-12-12 20:30:09 +0000350 SDOperand FP = CurDAG->getTargetNode(isDouble?Alpha::FCMOVNET:Alpha::FCMOVNES,
Andrew Lenharth361f45a2005-12-12 17:43:52 +0000351 MVT::f64, FV, TV, LD);
352 return FP;
353 }
354 break;
355
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000356 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000357
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000358 return SelectCode(Op);
359}
360
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000361SDOperand AlphaDAGToDAGISel::SelectCALL(SDOperand Op) {
Andrew Lenharth50b37842005-11-22 04:20:06 +0000362 //TODO: add flag stuff to prevent nondeturministic breakage!
363
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000364 SDNode *N = Op.Val;
365 SDOperand Chain = Select(N->getOperand(0));
Andrew Lenhartheececba2005-12-25 17:36:48 +0000366 SDOperand Addr = N->getOperand(1);
Andrew Lenharth93526222005-12-01 01:53:10 +0000367 SDOperand InFlag; // Null incoming flag value.
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000368
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000369 std::vector<SDOperand> CallOperands;
370 std::vector<MVT::ValueType> TypeOperands;
371
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000372 //grab the arguments
373 for(int i = 2, e = N->getNumOperands(); i < e; ++i) {
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000374 TypeOperands.push_back(N->getOperand(i).getValueType());
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000375 CallOperands.push_back(Select(N->getOperand(i)));
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000376 }
Andrew Lenharth8b7f14e2005-10-23 03:43:48 +0000377 int count = N->getNumOperands() - 2;
378
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000379 static const unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
380 Alpha::R19, Alpha::R20, Alpha::R21};
381 static const unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
382 Alpha::F19, Alpha::F20, Alpha::F21};
383
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000384 for (int i = 6; i < count; ++i) {
385 unsigned Opc = Alpha::WTF;
386 if (MVT::isInteger(TypeOperands[i])) {
387 Opc = Alpha::STQ;
388 } else if (TypeOperands[i] == MVT::f32) {
389 Opc = Alpha::STS;
390 } else if (TypeOperands[i] == MVT::f64) {
391 Opc = Alpha::STT;
392 } else
393 assert(0 && "Unknown operand");
394 Chain = CurDAG->getTargetNode(Opc, MVT::Other, CallOperands[i],
395 getI64Imm((i - 6) * 8),
Andrew Lenharth93526222005-12-01 01:53:10 +0000396 CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64),
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000397 Chain);
398 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000399 for (int i = 0; i < std::min(6, count); ++i) {
400 if (MVT::isInteger(TypeOperands[i])) {
401 Chain = CurDAG->getCopyToReg(Chain, args_int[i], CallOperands[i], InFlag);
402 InFlag = Chain.getValue(1);
403 } else if (TypeOperands[i] == MVT::f32 || TypeOperands[i] == MVT::f64) {
404 Chain = CurDAG->getCopyToReg(Chain, args_float[i], CallOperands[i], InFlag);
405 InFlag = Chain.getValue(1);
406 } else
407 assert(0 && "Unknown operand");
408 }
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000409
Andrew Lenharth93526222005-12-01 01:53:10 +0000410
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000411 // Finally, once everything is in registers to pass to the call, emit the
412 // call itself.
Andrew Lenhartheececba2005-12-25 17:36:48 +0000413 if (Addr.getOpcode() == AlphaISD::GPRelLo) {
414 SDOperand GOT = getGlobalBaseReg();
415 Chain = CurDAG->getCopyToReg(Chain, Alpha::R29, GOT, InFlag);
416 InFlag = Chain.getValue(1);
417 Chain = CurDAG->getTargetNode(Alpha::BSR, MVT::Other, MVT::Flag,
418 Addr.getOperand(0), Chain, InFlag);
419 } else {
420 Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Select(Addr), InFlag);
421 InFlag = Chain.getValue(1);
422 Chain = CurDAG->getTargetNode(Alpha::JSR, MVT::Other, MVT::Flag,
423 Chain, InFlag );
424 }
Andrew Lenharth93526222005-12-01 01:53:10 +0000425 InFlag = Chain.getValue(1);
426
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000427 std::vector<SDOperand> CallResults;
428
429 switch (N->getValueType(0)) {
430 default: assert(0 && "Unexpected ret value!");
431 case MVT::Other: break;
432 case MVT::i64:
Andrew Lenharth93526222005-12-01 01:53:10 +0000433 Chain = CurDAG->getCopyFromReg(Chain, Alpha::R0, MVT::i64, InFlag).getValue(1);
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000434 CallResults.push_back(Chain.getValue(0));
435 break;
Andrew Lenharth50b37842005-11-22 04:20:06 +0000436 case MVT::f32:
Andrew Lenharth93526222005-12-01 01:53:10 +0000437 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f32, InFlag).getValue(1);
Andrew Lenharth50b37842005-11-22 04:20:06 +0000438 CallResults.push_back(Chain.getValue(0));
439 break;
440 case MVT::f64:
Andrew Lenharth93526222005-12-01 01:53:10 +0000441 Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f64, InFlag).getValue(1);
Andrew Lenharth50b37842005-11-22 04:20:06 +0000442 CallResults.push_back(Chain.getValue(0));
443 break;
Andrew Lenharth756fbeb2005-10-22 22:06:58 +0000444 }
445
446 CallResults.push_back(Chain);
447 for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
448 CodeGenMap[Op.getValue(i)] = CallResults[i];
449 return CallResults[Op.ResNo];
450}
451
452
Andrew Lenharthd97591a2005-10-20 00:29:02 +0000453/// createAlphaISelDag - This pass converts a legalized DAG into a
454/// Alpha-specific DAG, ready for instruction scheduling.
455///
456FunctionPass *llvm::createAlphaISelDag(TargetMachine &TM) {
457 return new AlphaDAGToDAGISel(TM);
458}