blob: bef34f831c824e10b8dde913aea299bb53c61dd7 [file] [log] [blame]
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001//===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha -===//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group 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//
12//===----------------------------------------------------------------------===//
13
14#include "Alpha.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000015#include "AlphaRegisterInfo.h"
16#include "llvm/Constants.h" // FIXME: REMOVE
17#include "llvm/Function.h"
18#include "llvm/CodeGen/MachineInstrBuilder.h"
19#include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineFrameInfo.h"
22#include "llvm/CodeGen/SelectionDAG.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
24#include "llvm/CodeGen/SSARegMap.h"
25#include "llvm/Target/TargetData.h"
26#include "llvm/Target/TargetLowering.h"
27#include "llvm/Support/MathExtras.h"
28#include "llvm/ADT/Statistic.h"
29#include <set>
Andrew Lenharth684f2292005-01-30 00:35:27 +000030#include <algorithm>
Andrew Lenharth304d0f32005-01-22 23:41:55 +000031using namespace llvm;
32
33//===----------------------------------------------------------------------===//
34// AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
35namespace {
36 class AlphaTargetLowering : public TargetLowering {
37 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
38 unsigned GP; //GOT vreg
39 public:
40 AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
41 // Set up the TargetLowering object.
Andrew Lenharth3d65d312005-01-27 03:49:45 +000042 //I am having problems with shr n ubyte 1
Andrew Lenharth879ef222005-02-02 17:00:21 +000043 setShiftAmountType(MVT::i64);
44 setSetCCResultType(MVT::i64);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000045
Andrew Lenharth304d0f32005-01-22 23:41:55 +000046 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
47 addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000048 addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000049
Andrew Lenharthd2bb9602005-01-27 07:50:35 +000050 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000051
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000052 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000053 setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000054
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000055 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000056 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
57 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
58
Andrew Lenharth3d65d312005-01-27 03:49:45 +000059 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); //what is the sign expansion of 1? 1 or -1?
Andrew Lenharth02981182005-01-26 01:24:38 +000060
Andrew Lenharth3d65d312005-01-27 03:49:45 +000061 setOperationAction(ISD::SREM, MVT::f32, Expand);
62 setOperationAction(ISD::SREM, MVT::f64, Expand);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +000063
Andrew Lenharth8d163d22005-02-02 05:49:42 +000064 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
65 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
66 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
67
Andrew Lenharth3d65d312005-01-27 03:49:45 +000068 computeRegisterProperties();
Andrew Lenharth304d0f32005-01-22 23:41:55 +000069
Andrew Lenharthd2bb9602005-01-27 07:50:35 +000070 addLegalFPImmediate(+0.0); //F31
Andrew Lenharth304d0f32005-01-22 23:41:55 +000071 }
72
73 /// LowerArguments - This hook must be implemented to indicate how we should
74 /// lower the arguments for the specified function, into the specified DAG.
75 virtual std::vector<SDOperand>
76 LowerArguments(Function &F, SelectionDAG &DAG);
77
78 /// LowerCallTo - This hook lowers an abstract call to a function into an
79 /// actual call.
80 virtual std::pair<SDOperand, SDOperand>
81 LowerCallTo(SDOperand Chain, const Type *RetTy, SDOperand Callee,
82 ArgListTy &Args, SelectionDAG &DAG);
83
84 virtual std::pair<SDOperand, SDOperand>
85 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
86
87 virtual std::pair<SDOperand,SDOperand>
88 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
89 const Type *ArgTy, SelectionDAG &DAG);
90
91 virtual std::pair<SDOperand, SDOperand>
92 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
93 SelectionDAG &DAG);
94
95 void restoreGP(MachineBasicBlock* BB)
96 {
97 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
98 }
99 };
100}
101
102//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
103
104//For now, just use variable size stack frame format
105
106//In a standard call, the first six items are passed in registers $16
107//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
108//of argument-to-register correspondence.) The remaining items are
109//collected in a memory argument list that is a naturally aligned
110//array of quadwords. In a standard call, this list, if present, must
111//be passed at 0(SP).
112//7 ... n 0(SP) ... (n-7)*8(SP)
113
114std::vector<SDOperand>
115AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
116{
117 std::vector<SDOperand> ArgValues;
118
119 // //#define FP $15
120 // //#define RA $26
121 // //#define PV $27
122 // //#define GP $29
123 // //#define SP $30
124
125 // assert(0 && "TODO");
126 MachineFunction &MF = DAG.getMachineFunction();
127 MachineFrameInfo *MFI = MF.getFrameInfo();
128
129 GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
130 MachineBasicBlock& BB = MF.front();
131
132 //Handle the return address
133 //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26);
134
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000135 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
136 Alpha::R19, Alpha::R20, Alpha::R21};
137 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
138 Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000139 std::vector<unsigned> argVreg;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000140 std::vector<unsigned> argPreg;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000141 std::vector<unsigned> argOpc;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000142 int count = 0;
143 for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
144 {
Andrew Lenharth40831c52005-01-28 06:57:18 +0000145 SDOperand newroot, argt;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000146 if (count < 6) {
147 switch (getValueType(I->getType())) {
148 default: std::cerr << "Unknown Type " << getValueType(I->getType()) << "\n"; abort();
149 case MVT::f64:
150 case MVT::f32:
151 BuildMI(&BB, Alpha::IDEF, 0, args_float[count]);
152 argVreg.push_back(MF.getSSARegMap()->createVirtualRegister(getRegClassFor(getValueType(I->getType()))));
153 argPreg.push_back(args_float[count]);
154 argOpc.push_back(Alpha::CPYS);
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000155 argt = newroot = DAG.getCopyFromReg(argVreg[count], getValueType(I->getType()), DAG.getRoot());
Andrew Lenharth684f2292005-01-30 00:35:27 +0000156 break;
157 case MVT::i1:
158 case MVT::i8:
159 case MVT::i16:
160 case MVT::i32:
161 case MVT::i64:
162 BuildMI(&BB, Alpha::IDEF, 0, args_int[count]);
163 argVreg.push_back(MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64)));
164 argPreg.push_back(args_int[count]);
165 argOpc.push_back(Alpha::BIS);
166 argt = newroot = DAG.getCopyFromReg(argVreg[count], MVT::i64, DAG.getRoot());
167 if (getValueType(I->getType()) != MVT::i64)
168 argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot);
169 break;
170 }
171 } else { //more args
172 // Create the frame index object for this incoming parameter...
173 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
174
175 // Create the SelectionDAG nodes corresponding to a load from this parameter
176 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
177 argt = newroot = DAG.getLoad(getValueType(I->getType()), DAG.getEntryNode(), FIN);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000178 }
179 DAG.setRoot(newroot.getValue(1));
180 ArgValues.push_back(argt);
Andrew Lenharth684f2292005-01-30 00:35:27 +0000181 ++count;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000182 }
183
184 BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29);
185 BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29);
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000186 for (int i = 0; i < std::min(count,6); ++i)
Andrew Lenharth40831c52005-01-28 06:57:18 +0000187 BuildMI(&BB, argOpc[i], 2, argVreg[i]).addReg(argPreg[i]).addReg(argPreg[i]);
188
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000189 return ArgValues;
190}
191
192std::pair<SDOperand, SDOperand>
193AlphaTargetLowering::LowerCallTo(SDOperand Chain,
194 const Type *RetTy, SDOperand Callee,
195 ArgListTy &Args, SelectionDAG &DAG) {
196 int NumBytes = 0;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000197 if (Args.size() > 6)
198 NumBytes = (Args.size() - 6) * 8;
199
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000200 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
201 DAG.getConstant(NumBytes, getPointerTy()));
202 std::vector<SDOperand> args_to_use;
203 for (unsigned i = 0, e = Args.size(); i != e; ++i)
204 {
205 switch (getValueType(Args[i].second)) {
206 default: assert(0 && "Unexpected ValueType for argument!");
207 case MVT::i1:
208 case MVT::i8:
209 case MVT::i16:
210 case MVT::i32:
Andrew Lenharthd2bb9602005-01-27 07:50:35 +0000211 // Promote the integer to 64 bits. If the input type is signed use a
212 // sign extend, otherwise use a zero extend.
213 if (Args[i].second->isSigned())
Andrew Lenharth40831c52005-01-28 06:57:18 +0000214 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +0000215 else
Andrew Lenharth40831c52005-01-28 06:57:18 +0000216 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +0000217 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000218 case MVT::i64:
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000219 case MVT::f64:
220 case MVT::f32:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000221 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000222 }
223 args_to_use.push_back(Args[i].first);
224 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000225
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000226 std::vector<MVT::ValueType> RetVals;
227 MVT::ValueType RetTyVT = getValueType(RetTy);
228 if (RetTyVT != MVT::isVoid)
229 RetVals.push_back(RetTyVT);
230 RetVals.push_back(MVT::Other);
231
232 SDOperand TheCall = SDOperand(DAG.getCall(RetVals, Chain, Callee, args_to_use), 0);
233 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
234 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
235 DAG.getConstant(NumBytes, getPointerTy()));
236 return std::make_pair(TheCall, Chain);
237}
238
239std::pair<SDOperand, SDOperand>
240AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
241 //vastart just returns the address of the VarArgsFrameIndex slot.
242 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
243}
244
245std::pair<SDOperand,SDOperand> AlphaTargetLowering::
246LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
247 const Type *ArgTy, SelectionDAG &DAG) {
248 abort();
249}
250
251
252std::pair<SDOperand, SDOperand> AlphaTargetLowering::
253LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
254 SelectionDAG &DAG) {
255 abort();
256}
257
258
259
260
261
262namespace {
263
264 //===--------------------------------------------------------------------===//
265 /// ISel - Alpha specific code to select Alpha machine instructions for
266 /// SelectionDAG operations.
267 ///
268 class ISel : public SelectionDAGISel {
269
270 /// AlphaLowering - This object fully describes how to lower LLVM code to an
271 /// Alpha-specific SelectionDAG.
272 AlphaTargetLowering AlphaLowering;
273
274
275 /// ExprMap - As shared expressions are codegen'd, we keep track of which
276 /// vreg the value is produced in, so we only emit one copy of each compiled
277 /// tree.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000278 static const unsigned notIn = (unsigned)(-1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000279 std::map<SDOperand, unsigned> ExprMap;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000280
281 public:
282 ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) {
283 }
284
285 /// InstructionSelectBasicBlock - This callback is invoked by
286 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
287 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
288 // Codegen the basic block.
289 Select(DAG.getRoot());
290
291 // Clear state used for selection.
292 ExprMap.clear();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000293 }
294
295 unsigned SelectExpr(SDOperand N);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000296 unsigned SelectExprFP(SDOperand N, unsigned Result);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000297 void Select(SDOperand N);
298 };
299}
300
Andrew Lenharth40831c52005-01-28 06:57:18 +0000301unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
302{
303 unsigned Tmp1, Tmp2, Tmp3;
304 unsigned Opc = 0;
305 SDNode *Node = N.Val;
306 MVT::ValueType DestType = N.getValueType();
307 unsigned opcode = N.getOpcode();
308
309 switch (opcode) {
310 default:
311 Node->dump();
312 assert(0 && "Node not handled!\n");
Andrew Lenharth2c594352005-01-29 15:42:07 +0000313
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000314 case ISD::FP_ROUND:
315 assert (DestType == MVT::f32 && N.getOperand(0).getValueType() == MVT::f64 && "only f64 to f32 conversion supported here");
316 Tmp1 = SelectExpr(N.getOperand(0));
317 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
318 return Result;
319
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000320 case ISD::FP_EXTEND:
321 assert (DestType == MVT::f64 && N.getOperand(0).getValueType() == MVT::f32 && "only f32 to f64 conversion supported here");
322 Tmp1 = SelectExpr(N.getOperand(0));
323 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
324 return Result;
325
Andrew Lenharth2c594352005-01-29 15:42:07 +0000326 case ISD::CopyFromReg:
327 {
328 // Make sure we generate both values.
329 if (Result != notIn)
330 ExprMap[N.getValue(1)] = notIn; // Generate the token
331 else
332 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
333
334 SDOperand Chain = N.getOperand(0);
335
336 Select(Chain);
337 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
338 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
339 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
340 return Result;
341 }
342
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000343 case ISD::LOAD:
344 {
345 // Make sure we generate both values.
346 if (Result != notIn)
347 ExprMap[N.getValue(1)] = notIn; // Generate the token
348 else
349 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
350
351 SDOperand Chain = N.getOperand(0);
352 SDOperand Address = N.getOperand(1);
353
354 if (Address.getOpcode() == ISD::GlobalAddress)
355 {
356 Select(Chain);
357 AlphaLowering.restoreGP(BB);
Andrew Lenharth2afc8212005-02-02 03:36:35 +0000358 Opc = DestType == MVT::f64 ? Alpha::LDS_SYM : Alpha::LDT_SYM;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000359 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
360 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000361 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
362 AlphaLowering.restoreGP(BB);
363 if (DestType == MVT::f64) {
364 BuildMI(BB, Alpha::LDT_SYM, 1, Result).addConstantPoolIndex(CP->getIndex());
365 } else {
366 BuildMI(BB, Alpha::LDS_SYM, 1, Result).addConstantPoolIndex(CP->getIndex());
367 }
368 }
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000369 else
370 {
371 Select(Chain);
372 Tmp2 = SelectExpr(Address);
373 Opc = DestType == MVT::f64 ? Alpha::LDS : Alpha::LDT;
374 BuildMI(BB, Opc, 2, Result).addImm(0).addReg(Tmp2);
375 }
376 return Result;
377 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000378 case ISD::ConstantFP:
379 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
380 if (CN->isExactlyValue(+0.0)) {
381 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
382 } else {
383 abort();
384 }
385 }
386 return Result;
387
388 case ISD::MUL:
389 case ISD::ADD:
390 case ISD::SUB:
391 case ISD::SDIV:
392 switch( opcode ) {
393 case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break;
394 case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break;
395 case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break;
396 case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break;
397 };
398 Tmp1 = SelectExpr(N.getOperand(0));
399 Tmp2 = SelectExpr(N.getOperand(1));
400 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
401 return Result;
402
Andrew Lenharth2c594352005-01-29 15:42:07 +0000403 case ISD::EXTLOAD:
404 //include a conversion sequence for float loads to double
405 if (Result != notIn)
406 ExprMap[N.getValue(1)] = notIn; // Generate the token
407 else
408 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
409
410 Tmp2 = MakeReg(MVT::f32);
411
412 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N.getOperand(1)))
413 if (Node->getValueType(0) == MVT::f64) {
414 assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 &&
415 "Bad EXTLOAD!");
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000416 AlphaLowering.restoreGP(BB);
417 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp2).addConstantPoolIndex(CP->getIndex());
Andrew Lenharth2c594352005-01-29 15:42:07 +0000418 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp2);
419 return Result;
420 }
421 Select(Node->getOperand(0)); // chain
422 Tmp1 = SelectExpr(Node->getOperand(1));
423 BuildMI(BB, Alpha::LDS, 1, Tmp2).addReg(Tmp1);
424 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp2);
425 return Result;
426
427
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000428 case ISD::UINT_TO_FP:
429 case ISD::SINT_TO_FP:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000430 {
431 assert (N.getOperand(0).getValueType() == MVT::i64 && "only quads can be loaded from");
432 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000433 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000434
435 //The hard way:
436 // Spill the integer to memory and reload it from there.
437 unsigned Size = MVT::getSizeInBits(MVT::i64)/8;
438 MachineFunction *F = BB->getParent();
439 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, Size);
440
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000441 BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31);
442 BuildMI(BB, Alpha::LDT, 2, Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
443 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
444 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000445
446 //The easy way: doesn't work
447// //so these instructions are not supported on ev56
448// Opc = DestType == MVT::f64 ? Alpha::ITOFT : Alpha::ITOFS;
449// BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp1);
450// Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
451// BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
452
Andrew Lenharth40831c52005-01-28 06:57:18 +0000453 return Result;
454 }
455 }
456 assert(0 && "should not get here");
457 return 0;
458}
459
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000460unsigned ISel::SelectExpr(SDOperand N) {
461 unsigned Result;
462 unsigned Tmp1, Tmp2, Tmp3;
463 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000464 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000465
466 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000467 MVT::ValueType DestType = N.getValueType();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000468
469 unsigned &Reg = ExprMap[N];
470 if (Reg) return Reg;
471
472 if (N.getOpcode() != ISD::CALL)
473 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000474 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000475 else {
476 // If this is a call instruction, make sure to prepare ALL of the result
477 // values as well as the chain.
478 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000479 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000480 else {
481 Result = MakeReg(Node->getValueType(0));
482 ExprMap[N.getValue(0)] = Result;
483 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
484 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000485 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000486 }
487 }
488
Andrew Lenharth22088bb2005-02-02 15:05:33 +0000489 if (DestType == MVT::f64 || DestType == MVT::f32 ||
490 (opcode == ISD::LOAD &&
491 (N.getValue(0).getValueType() == MVT::f32 || N.getValue(0).getValueType() == MVT::f64)))
Andrew Lenharth40831c52005-01-28 06:57:18 +0000492 return SelectExprFP(N, Result);
493
494 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000495 default:
496 Node->dump();
497 assert(0 && "Node not handled!\n");
498
Andrew Lenharth2c594352005-01-29 15:42:07 +0000499 case ISD::ConstantPool:
500 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
501 AlphaLowering.restoreGP(BB);
502 BuildMI(BB, Alpha::LOAD, 1, Result).addConstantPoolIndex(Tmp1);
503 return Result;
504
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000505 case ISD::FrameIndex:
506 Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
Andrew Lenharth684f2292005-01-30 00:35:27 +0000507 BuildMI(BB, Alpha::LDA, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000508 return Result;
509
510 case ISD::EXTLOAD:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000511 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000512 if (Result != notIn)
513 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000514 else
515 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
516
517 Select(Node->getOperand(0)); // chain
518 Tmp1 = SelectExpr(Node->getOperand(1));
519
520 switch(Node->getValueType(0)) {
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000521 default: Node->dump(); assert(0 && "Unknown type to sign extend to.");
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000522 case MVT::i64:
523 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
524 default:
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000525 Node->dump();
526 assert(0 && "Bad extend load!");
Andrew Lenharthd279b412005-01-25 19:58:40 +0000527 case MVT::i64:
528 BuildMI(BB, Alpha::LDQ, 2, Result).addImm(0).addReg(Tmp1);
529 break;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000530 case MVT::i32:
531 BuildMI(BB, Alpha::LDL, 2, Result).addImm(0).addReg(Tmp1);
532 break;
533 case MVT::i16:
534 BuildMI(BB, Alpha::LDWU, 2, Result).addImm(0).addReg(Tmp1);
535 break;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000536 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000537 case MVT::i8:
538 BuildMI(BB, Alpha::LDBU, 2, Result).addImm(0).addReg(Tmp1);
539 break;
540 }
541 break;
542 }
543 return Result;
544
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000545 case ISD::SEXTLOAD:
546 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000547 if (Result != notIn)
548 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000549 else
550 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
551
552 Select(Node->getOperand(0)); // chain
553 Tmp1 = SelectExpr(Node->getOperand(1));
554 switch(Node->getValueType(0)) {
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000555 default: Node->dump(); assert(0 && "Unknown type to sign extend to.");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000556 case MVT::i64:
557 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
558 default:
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000559 Node->dump();
560 assert(0 && "Bad sign extend!");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000561 case MVT::i32:
562 BuildMI(BB, Alpha::LDL, 2, Result).addImm(0).addReg(Tmp1);
563 break;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000564 }
565 break;
566 }
567 return Result;
568
569 case ISD::ZEXTLOAD:
570 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000571 if (Result != notIn)
572 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000573 else
574 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
575
576 Select(Node->getOperand(0)); // chain
577 Tmp1 = SelectExpr(Node->getOperand(1));
578 switch(Node->getValueType(0)) {
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000579 default: Node->dump(); assert(0 && "Unknown type to zero extend to.");
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000580 case MVT::i64:
581 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
582 default:
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000583 Node->dump();
584 assert(0 && "Bad sign extend!");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000585 case MVT::i16:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000586 BuildMI(BB, Alpha::LDWU, 2, Result).addImm(0).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000587 break;
588 case MVT::i8:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000589 BuildMI(BB, Alpha::LDBU, 2, Result).addImm(0).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000590 break;
591 }
592 break;
593 }
594 return Result;
595
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000596
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000597 case ISD::GlobalAddress:
598 AlphaLowering.restoreGP(BB);
599 BuildMI(BB, Alpha::LOAD_ADDR, 1, Result)
600 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal());
601 return Result;
602
603 case ISD::CALL:
604 {
605 Select(N.getOperand(0));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000606
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000607 // The chain for this call is now lowered.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000608 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000609
610 //grab the arguments
611 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000612 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000613 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000614 argvregs.push_back(SelectExpr(N.getOperand(i)));
615
Andrew Lenharth684f2292005-01-30 00:35:27 +0000616 //in reg args
617 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
618 {
619 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
620 Alpha::R19, Alpha::R20, Alpha::R21};
621 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
622 Alpha::F19, Alpha::F20, Alpha::F21};
623 switch(N.getOperand(i+2).getValueType()) {
624 default:
625 Node->dump();
626 N.getOperand(i).Val->dump();
627 std::cerr << "Type for " << i << " is: " << N.getOperand(i+2).getValueType() << "\n";
628 assert(0 && "Unknown value type for call");
629 case MVT::i1:
630 case MVT::i8:
631 case MVT::i16:
632 case MVT::i32:
633 case MVT::i64:
634 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]);
635 break;
636 case MVT::f32:
637 case MVT::f64:
638 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]);
639 break;
640 }
641 }
642 //in mem args
643 for (int i = 6, e = argvregs.size(); i < e; ++i)
644 {
645 switch(N.getOperand(i+2).getValueType()) {
646 default:
647 Node->dump();
648 N.getOperand(i).Val->dump();
649 std::cerr << "Type for " << i << " is: " << N.getOperand(i+2).getValueType() << "\n";
650 assert(0 && "Unknown value type for call");
651 case MVT::i1:
652 case MVT::i8:
653 case MVT::i16:
654 case MVT::i32:
655 case MVT::i64:
656 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
657 break;
658 case MVT::f32:
659 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
660 break;
661 case MVT::f64:
662 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
663 break;
664 }
665 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000666 //build the right kind of call
667 if (GlobalAddressSDNode *GASD =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000668 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
669 {
670 AlphaLowering.restoreGP(BB);
671 BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true);
672 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000673 else if (ExternalSymbolSDNode *ESSDN =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000674 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
675 {
676 AlphaLowering.restoreGP(BB);
677 BuildMI(BB, Alpha::CALL, 0).addExternalSymbol(ESSDN->getSymbol(), true);
678 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000679 else
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000680 {
681 //no need to restore GP as we are doing an indirect call
682 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000683 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
684 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000685 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000686
687 //push the result into a virtual register
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000688
689 switch (Node->getValueType(0)) {
690 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000691 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000692 case MVT::i1:
693 case MVT::i8:
694 case MVT::i16:
695 case MVT::i32:
696 case MVT::i64:
697 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
698 break;
699 case MVT::f32:
700 case MVT::f64:
701 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
702 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000703 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000704 return Result+N.ResNo;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000705 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000706
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000707 case ISD::SIGN_EXTEND:
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000708 abort();
709
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000710 case ISD::SIGN_EXTEND_INREG:
711 {
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000712 //Alpha has instructions for a bunch of signed 32 bit stuff
713 if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
714 {
715 switch (N.getOperand(0).getOpcode()) {
716 case ISD::ADD:
717 case ISD::SUB:
718 case ISD::MUL:
719 {
720 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
721 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
722 //FIXME: first check for Scaled Adds and Subs!
723 if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
724 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
725 { //Normal imm add/sub
726 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
727 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
728 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
729 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
730 }
731 else
732 { //Normal add/sub
733 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULLi : Alpha::SUBL);
734 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
735 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
736 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
737 }
738 return Result;
739 }
740 default: break; //Fall Though;
741 }
742 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000743 Tmp1 = SelectExpr(N.getOperand(0));
744 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000745 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000746 switch(MVN->getExtraValueType())
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000747 {
748 default:
749 Node->dump();
750 assert(0 && "Sign Extend InReg not there yet");
751 break;
752 case MVT::i32:
753 {
754 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
755 break;
756 }
757 case MVT::i16:
758 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
759 break;
760 case MVT::i8:
761 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
762 break;
763 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000764 return Result;
765 }
766 case ISD::ZERO_EXTEND_INREG:
767 {
768 Tmp1 = SelectExpr(N.getOperand(0));
769 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000770 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000771 switch(MVN->getExtraValueType())
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000772 {
773 default:
774 Node->dump();
775 assert(0 && "Zero Extend InReg not there yet");
776 break;
777 case MVT::i32: Tmp2 = 0xf0; break;
778 case MVT::i16: Tmp2 = 0xfc; break;
779 case MVT::i8: Tmp2 = 0xfe; break;
780 case MVT::i1: //handle this one special
781 BuildMI(BB, Alpha::ANDi, 2, Result).addReg(Tmp1).addImm(1);
782 return Result;
783 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000784 BuildMI(BB, Alpha::ZAPi, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000785 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000786 }
787
788 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000789 {
790 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
791 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
792 bool isConst1 = false;
793 bool isConst2 = false;
794 int dir;
795
796 //Tmp1 = SelectExpr(N.getOperand(0));
797 if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000798 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255)
799 isConst1 = true;
800 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000801 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
802 isConst2 = true;
803
804 switch (SetCC->getCondition()) {
805 default: Node->dump(); assert(0 && "Unknown integer comparison!");
806 case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break;
807 case ISD::SETLT: Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
808 case ISD::SETLE: Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
809 case ISD::SETGT: Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break;
810 case ISD::SETGE: Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break;
811 case ISD::SETULT: Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
812 case ISD::SETUGT: Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break;
813 case ISD::SETULE: Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
814 case ISD::SETUGE: Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +0000815 case ISD::SETNE: {//Handle this one special
816 //std::cerr << "Alpha does not have a setne.\n";
817 //abort();
818 Tmp1 = SelectExpr(N.getOperand(0));
819 Tmp2 = SelectExpr(N.getOperand(1));
820 Tmp3 = MakeReg(MVT::i64);
821 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
822 //and invert
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000823 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
824 //BuildMI(BB,Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +0000825 return Result;
826 }
827 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000828 if (dir == 1) {
829 Tmp1 = SelectExpr(N.getOperand(0));
830 if (isConst2) {
831 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
832 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
833 } else {
834 Tmp2 = SelectExpr(N.getOperand(1));
835 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
836 }
837 } else if (dir == 2) {
838 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth6b9870a2005-01-28 14:06:46 +0000839 if (isConst1) {
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000840 Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
841 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
842 } else {
843 Tmp2 = SelectExpr(N.getOperand(0));
844 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
845 }
846 } else { //dir == 0
847 if (isConst1) {
848 Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
849 Tmp2 = SelectExpr(N.getOperand(1));
850 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1);
851 } else if (isConst2) {
852 Tmp1 = SelectExpr(N.getOperand(0));
853 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
854 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2);
855 } else {
856 Tmp1 = SelectExpr(N.getOperand(0));
857 Tmp2 = SelectExpr(N.getOperand(1));
858 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
859 }
860 }
861 }
862 else
863 {
864 Node->dump();
865 assert(0 && "only integer");
866 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000867 }
868 else
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000869 {
870 Node->dump();
871 assert(0 && "Not a setcc in setcc");
872 }
873 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000874 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000875
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000876 case ISD::CopyFromReg:
877 {
Andrew Lenharth40831c52005-01-28 06:57:18 +0000878 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000879 if (Result != notIn)
880 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +0000881 else
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000882 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth40831c52005-01-28 06:57:18 +0000883
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000884 SDOperand Chain = N.getOperand(0);
885
886 Select(Chain);
887 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
888 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
889 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
890 return Result;
891 }
892
Andrew Lenharth2d6f0222005-01-24 19:44:07 +0000893 //Most of the plain arithmetic and logic share the same form, and the same
894 //constant immediate test
895 case ISD::AND:
896 case ISD::OR:
897 case ISD::XOR:
898 case ISD::SHL:
899 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +0000900 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +0000901 case ISD::MUL:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000902 assert (DestType == MVT::i64 && "Only do arithmetic on i64s!");
903 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +0000904 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
905 {
906 switch(opcode) {
907 case ISD::AND: Opc = Alpha::ANDi; break;
908 case ISD::OR: Opc = Alpha::BISi; break;
909 case ISD::XOR: Opc = Alpha::XORi; break;
910 case ISD::SHL: Opc = Alpha::SLi; break;
911 case ISD::SRL: Opc = Alpha::SRLi; break;
912 case ISD::SRA: Opc = Alpha::SRAi; break;
913 case ISD::MUL: Opc = Alpha::MULQi; break;
914 };
915 Tmp1 = SelectExpr(N.getOperand(0));
916 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
917 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
918 }
919 else
920 {
921 switch(opcode) {
922 case ISD::AND: Opc = Alpha::AND; break;
923 case ISD::OR: Opc = Alpha::BIS; break;
924 case ISD::XOR: Opc = Alpha::XOR; break;
925 case ISD::SHL: Opc = Alpha::SL; break;
926 case ISD::SRL: Opc = Alpha::SRL; break;
927 case ISD::SRA: Opc = Alpha::SRA; break;
928 case ISD::MUL: Opc = Alpha::MULQ; break;
929 };
930 Tmp1 = SelectExpr(N.getOperand(0));
931 Tmp2 = SelectExpr(N.getOperand(1));
932 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
933 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +0000934 return Result;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000935
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000936 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000937 case ISD::SUB:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000938 {
Andrew Lenharth40831c52005-01-28 06:57:18 +0000939 bool isAdd = opcode == ISD::ADD;
940
941 //FIXME: first check for Scaled Adds and Subs!
942 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +0000943 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
944 { //Normal imm add/sub
945 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
946 Tmp1 = SelectExpr(N.getOperand(0));
947 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
948 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
949 }
950 else if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +0000951 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
952 { //LDA //FIXME: expand the above condition a bit
953 Tmp1 = SelectExpr(N.getOperand(0));
954 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
955 if (!isAdd)
956 Tmp2 = -Tmp2;
957 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
958 }
959 else
960 { //Normal add/sub
961 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
962 Tmp1 = SelectExpr(N.getOperand(0));
963 Tmp2 = SelectExpr(N.getOperand(1));
964 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
965 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000966 return Result;
967 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000968
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000969 case ISD::UREM:
Andrew Lenharth02981182005-01-26 01:24:38 +0000970 case ISD::SREM:
971 case ISD::SDIV:
972 case ISD::UDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000973 //FIXME: alpha really doesn't support any of these operations,
974 // the ops are expanded into special library calls with
975 // special calling conventions
976 switch(opcode) {
977 case ISD::UREM: Opc = Alpha::REMQU; break;
978 case ISD::SREM: Opc = Alpha::REMQ; break;
979 case ISD::UDIV: Opc = Alpha::DIVQU; break;
980 case ISD::SDIV: Opc = Alpha::DIVQ; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000981 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000982 Tmp1 = SelectExpr(N.getOperand(0));
983 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth02981182005-01-26 01:24:38 +0000984 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000985 return Result;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000986
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000987 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000988 case ISD::FP_TO_SINT:
989 {
990 assert (DestType == MVT::i64 && "only quads can be loaded to");
991 MVT::ValueType SrcType = N.getOperand(0).getValueType();
992 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
993
994 //The hard way:
995 // Spill the integer to memory and reload it from there.
996 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
997 MachineFunction *F = BB->getParent();
998 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
999
1000 //CVTTQ STT LDQ
1001 //CVTST CVTTQ STT LDQ
1002 if (SrcType == MVT::f32)
1003 {
1004 Tmp2 = MakeReg(MVT::f64);
1005 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
1006 Tmp1 = Tmp2;
1007 }
1008 Tmp2 = MakeReg(MVT::f64);
1009 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
1010 BuildMI(BB, Alpha::STT, 3).addReg(Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1011 BuildMI(BB, Alpha::LDQ, 2, Result).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1012
1013 return Result;
1014 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001015
1016// // case ISD::FP_TO_UINT:
1017
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001018 case ISD::SELECT:
1019 {
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001020 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001021 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1022 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001023 // Get the condition into the zero flag.
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001024 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001025 return Result;
1026 }
1027
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001028 case ISD::Constant:
1029 {
Andrew Lenharth22d5a412005-02-02 00:51:15 +00001030 unsigned long val = cast<ConstantSDNode>(N)->getValue();
1031 if (val < 32000 && (long)val > -32000)
1032 BuildMI(BB, Alpha::LOAD_IMM, 1, Result).addImm(val);
1033 else
1034 {
1035 MachineConstantPool *CP = BB->getParent()->getConstantPool();
1036 ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
1037 unsigned CPI = CP->getConstantPoolIndex(C);
1038 AlphaLowering.restoreGP(BB);
1039 BuildMI(BB, Alpha::LOAD, 1, Result).addConstantPoolIndex(CPI);
1040 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001041 return Result;
1042 }
1043
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001044 case ISD::LOAD:
1045 {
1046 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001047 if (Result != notIn)
1048 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001049 else
1050 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1051
1052 SDOperand Chain = N.getOperand(0);
1053 SDOperand Address = N.getOperand(1);
1054
Andrew Lenharthc23d6962005-02-02 04:35:44 +00001055 assert(N.getValue(0).getValueType() == MVT::i64 && "unknown Load dest type");
Andrew Lenharth2afc8212005-02-02 03:36:35 +00001056
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001057 if (Address.getOpcode() == ISD::GlobalAddress)
Andrew Lenharth2afc8212005-02-02 03:36:35 +00001058 {
1059 Select(Chain);
1060 AlphaLowering.restoreGP(BB);
1061 BuildMI(BB, Alpha::LOAD, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1062 }
1063 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1064 AlphaLowering.restoreGP(BB);
1065 BuildMI(BB, Alpha::LOAD, 1, Result).addConstantPoolIndex(CP->getIndex());
1066 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001067 else
Andrew Lenharth2afc8212005-02-02 03:36:35 +00001068 {
1069 Select(Chain);
1070 Tmp2 = SelectExpr(Address);
1071 BuildMI(BB, Alpha::LDQ, 2, Result).addImm(0).addReg(Tmp2);
1072 }
1073 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001074 }
1075 }
1076
1077 return 0;
1078}
1079
1080void ISel::Select(SDOperand N) {
1081 unsigned Tmp1, Tmp2, Opc;
1082
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001083 // FIXME: Disable for our current expansion model!
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001084 if (/*!N->hasOneUse() &&*/ !ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001085 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001086
1087 SDNode *Node = N.Val;
1088
1089 switch (N.getOpcode()) {
1090
1091 default:
1092 Node->dump(); std::cerr << "\n";
1093 assert(0 && "Node not handled yet!");
1094
1095 case ISD::BRCOND: {
1096 MachineBasicBlock *Dest =
1097 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
1098
1099 Select(N.getOperand(0));
1100 Tmp1 = SelectExpr(N.getOperand(1));
1101 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
1102 return;
1103 }
1104
1105 case ISD::BR: {
1106 MachineBasicBlock *Dest =
1107 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1108
1109 Select(N.getOperand(0));
1110 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
1111 return;
1112 }
1113
1114 case ISD::ImplicitDef:
1115 Select(N.getOperand(0));
1116 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
1117 return;
1118
1119 case ISD::EntryToken: return; // Noop
1120
1121 case ISD::TokenFactor:
1122 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1123 Select(Node->getOperand(i));
1124
1125 //N.Val->dump(); std::cerr << "\n";
1126 //assert(0 && "Node not handled yet!");
1127
1128 return;
1129
1130 case ISD::CopyToReg:
1131 Select(N.getOperand(0));
1132 Tmp1 = SelectExpr(N.getOperand(1));
1133 Tmp2 = cast<RegSDNode>(N)->getReg();
1134
1135 if (Tmp1 != Tmp2) {
1136 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1137 }
1138 return;
1139
1140 case ISD::RET:
1141 switch (N.getNumOperands()) {
1142 default:
1143 std::cerr << N.getNumOperands() << "\n";
1144 for (unsigned i = 0; i < N.getNumOperands(); ++i)
1145 std::cerr << N.getOperand(i).getValueType() << "\n";
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001146 Node->dump();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001147 assert(0 && "Unknown return instruction!");
1148 case 2:
1149 Select(N.getOperand(0));
1150 Tmp1 = SelectExpr(N.getOperand(1));
1151 switch (N.getOperand(1).getValueType()) {
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001152 default: Node->dump(); assert(0 && "All other types should have been promoted!!");
1153 case MVT::f64:
1154 case MVT::f32:
1155 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
1156 break;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001157 case MVT::i32:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001158 case MVT::i64:
1159 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
1160 break;
1161 }
1162 break;
1163 case 1:
1164 Select(N.getOperand(0));
1165 break;
1166 }
1167 //Tmp2 = AlphaLowering.getRetAddr();
1168 //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2);
1169 BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction
1170 return;
1171
1172 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001173 {
1174 Select(N.getOperand(0));
1175 Tmp1 = SelectExpr(N.getOperand(1)); //value
1176 MVT::ValueType DestType = N.getOperand(1).getValueType();
1177 if (N.getOperand(2).getOpcode() == ISD::GlobalAddress)
1178 {
1179 AlphaLowering.restoreGP(BB);
1180 if (DestType == MVT::i64) Opc = Alpha::STORE;
1181 else if (DestType == MVT::f64) Opc = Alpha::STT_SYM;
1182 else if (DestType == MVT::f32) Opc = Alpha::STS_SYM;
1183 else assert(0 && "unknown Type in store");
1184 BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(N.getOperand(2))->getGlobal());
1185 }
1186 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N.getOperand(2)))
1187 {
1188 AlphaLowering.restoreGP(BB);
1189 if (DestType == MVT::i64) Opc = Alpha::STORE;
1190 else if (DestType == MVT::f64) Opc = Alpha::STT_SYM;
1191 else if (DestType == MVT::f32) Opc = Alpha::STS_SYM;
1192 else assert(0 && "unknown Type in store");
1193 BuildMI(BB, Opc, 2).addReg(Tmp1).addConstantPoolIndex(CP->getIndex());
1194 }
1195 else
1196 {
1197 Tmp2 = SelectExpr(N.getOperand(2)); //address
1198 if (DestType == MVT::i64) Opc = Alpha::STQ;
1199 else if (DestType == MVT::f64) Opc = Alpha::STT;
1200 else if (DestType == MVT::f32) Opc = Alpha::STS;
1201 else assert(0 && "unknown Type in store");
1202 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(0).addReg(Tmp2);
1203 }
1204 return;
1205 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001206
1207 case ISD::EXTLOAD:
1208 case ISD::SEXTLOAD:
1209 case ISD::ZEXTLOAD:
1210 case ISD::LOAD:
1211 case ISD::CopyFromReg:
1212 case ISD::CALL:
1213// case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001214 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001215 SelectExpr(N);
1216 return;
1217
1218
1219 case ISD::TRUNCSTORE: { // truncstore chain, val, ptr :storety
1220 MVT::ValueType StoredTy = cast<MVTSDNode>(Node)->getExtraValueType();
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001221 if (StoredTy == MVT::i64) {
1222 Node->dump();
1223 assert(StoredTy != MVT::i64 && "Unsupported TRUNCSTORE for this target!");
1224 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001225
1226 Select(N.getOperand(0));
1227 Tmp1 = SelectExpr(N.getOperand(1));
1228 Tmp2 = SelectExpr(N.getOperand(2));
1229
1230 switch (StoredTy) {
Chris Lattnerd7b59d02005-01-30 16:32:48 +00001231 default: Node->dump(); assert(0 && "Unhandled Type");
Andrew Lenharthd279b412005-01-25 19:58:40 +00001232 case MVT::i1: //FIXME: DAG does not promote this load
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001233 case MVT::i8: Opc = Alpha::STB; break;
1234 case MVT::i16: Opc = Alpha::STW; break;
1235 case MVT::i32: Opc = Alpha::STL; break;
1236 }
1237
1238 BuildMI(BB, Opc, 2).addReg(Tmp1).addImm(0).addReg(Tmp2);
1239 return;
1240 }
1241
1242 case ISD::ADJCALLSTACKDOWN:
1243 case ISD::ADJCALLSTACKUP:
1244 Select(N.getOperand(0));
1245 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1246
1247 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? Alpha::ADJUSTSTACKDOWN :
1248 Alpha::ADJUSTSTACKUP;
1249 BuildMI(BB, Opc, 1).addImm(Tmp1);
1250 return;
1251 }
1252 assert(0 && "Should not be reached!");
1253}
1254
1255
1256/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
1257/// into a machine code representation using pattern matching and a machine
1258/// description file.
1259///
1260FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
1261 return new ISel(TM);
1262}