blob: 41028da7a255d2af3b96f03232124609b5976c12 [file] [log] [blame]
Misha Brukman2a8350a2005-02-05 02:24:26 +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"
Andrew Lenharth032f2352005-02-22 21:59:48 +000029#include "llvm/Support/Debug.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000030#include <set>
Andrew Lenharth684f2292005-01-30 00:35:27 +000031#include <algorithm>
Andrew Lenharth304d0f32005-01-22 23:41:55 +000032using namespace llvm;
33
34//===----------------------------------------------------------------------===//
35// AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
36namespace {
37 class AlphaTargetLowering : public TargetLowering {
38 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
39 unsigned GP; //GOT vreg
40 public:
41 AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
42 // Set up the TargetLowering object.
Andrew Lenharth3d65d312005-01-27 03:49:45 +000043 //I am having problems with shr n ubyte 1
Andrew Lenharth879ef222005-02-02 17:00:21 +000044 setShiftAmountType(MVT::i64);
45 setSetCCResultType(MVT::i64);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000046
Andrew Lenharth304d0f32005-01-22 23:41:55 +000047 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
48 addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000049 addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000050
Andrew Lenharthd2bb9602005-01-27 07:50:35 +000051 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000052
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000053 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000054 setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000055
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000056 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000057 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
58 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
59
Andrew Lenharth9818c052005-02-05 13:19:12 +000060 setOperationAction(ISD::SREM , MVT::f32 , Expand);
61 setOperationAction(ISD::SREM , MVT::f64 , Expand);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +000062
Andrew Lenharth8d163d22005-02-02 05:49:42 +000063 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
Andrew Lenharth9818c052005-02-05 13:19:12 +000064 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
65 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
66
Andrew Lenharth572af902005-02-14 05:41:43 +000067 setOperationAction(ISD::SETCC , MVT::f32, Promote);
68
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000069 computeRegisterProperties();
Andrew Lenharth304d0f32005-01-22 23:41:55 +000070
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000071 addLegalFPImmediate(+0.0); //F31
72 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth304d0f32005-01-22 23:41:55 +000073 }
74
75 /// LowerArguments - This hook must be implemented to indicate how we should
76 /// lower the arguments for the specified function, into the specified DAG.
77 virtual std::vector<SDOperand>
78 LowerArguments(Function &F, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000079
Andrew Lenharth304d0f32005-01-22 23:41:55 +000080 /// LowerCallTo - This hook lowers an abstract call to a function into an
81 /// actual call.
82 virtual std::pair<SDOperand, SDOperand>
83 LowerCallTo(SDOperand Chain, const Type *RetTy, SDOperand Callee,
84 ArgListTy &Args, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000085
Andrew Lenharth304d0f32005-01-22 23:41:55 +000086 virtual std::pair<SDOperand, SDOperand>
87 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000088
Andrew Lenharth304d0f32005-01-22 23:41:55 +000089 virtual std::pair<SDOperand,SDOperand>
90 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
91 const Type *ArgTy, SelectionDAG &DAG);
92
93 virtual std::pair<SDOperand, SDOperand>
94 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
95 SelectionDAG &DAG);
96
97 void restoreGP(MachineBasicBlock* BB)
98 {
99 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
100 }
101 };
102}
103
104//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
105
106//For now, just use variable size stack frame format
107
108//In a standard call, the first six items are passed in registers $16
109//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
110//of argument-to-register correspondence.) The remaining items are
111//collected in a memory argument list that is a naturally aligned
112//array of quadwords. In a standard call, this list, if present, must
113//be passed at 0(SP).
114//7 ... n 0(SP) ... (n-7)*8(SP)
115
116std::vector<SDOperand>
117AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
118{
119 std::vector<SDOperand> ArgValues;
120
121 // //#define FP $15
122 // //#define RA $26
123 // //#define PV $27
124 // //#define GP $29
125 // //#define SP $30
126
127 // assert(0 && "TODO");
128 MachineFunction &MF = DAG.getMachineFunction();
Andrew Lenharth05380342005-02-07 05:07:00 +0000129 MachineFrameInfo*MFI = MF.getFrameInfo();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000130
131 GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
132 MachineBasicBlock& BB = MF.front();
133
134 //Handle the return address
135 //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26);
136
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000137 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
138 Alpha::R19, Alpha::R20, Alpha::R21};
139 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
140 Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharth2c9e38c2005-02-06 21:07:31 +0000141 unsigned argVreg[6];
142 unsigned argPreg[6];
143 unsigned argOpc[6];
144
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000145 int count = 0;
Andrew Lenharth2c9e38c2005-02-06 21:07:31 +0000146
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000147 for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000148 {
149 SDOperand newroot, argt;
150 if (count < 6) {
151 switch (getValueType(I->getType())) {
152 default:
153 std::cerr << "Unknown Type " << getValueType(I->getType()) << "\n";
154 abort();
155 case MVT::f64:
156 case MVT::f32:
157 BuildMI(&BB, Alpha::IDEF, 0, args_float[count]);
158 argVreg[count] =
159 MF.getSSARegMap()->createVirtualRegister(
Andrew Lenharth032f2352005-02-22 21:59:48 +0000160 getRegClassFor(getValueType(I->getType())));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000161 argPreg[count] = args_float[count];
162 argOpc[count] = Alpha::CPYS;
163 argt = newroot = DAG.getCopyFromReg(argVreg[count],
164 getValueType(I->getType()),
165 DAG.getRoot());
166 break;
167 case MVT::i1:
168 case MVT::i8:
169 case MVT::i16:
170 case MVT::i32:
171 case MVT::i64:
172 BuildMI(&BB, Alpha::IDEF, 0, args_int[count]);
173 argVreg[count] =
174 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
175 argPreg[count] = args_int[count];
176 argOpc[count] = Alpha::BIS;
177 argt = newroot =
178 DAG.getCopyFromReg(argVreg[count], MVT::i64, DAG.getRoot());
179 if (getValueType(I->getType()) != MVT::i64)
180 argt =
181 DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot);
182 break;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000183 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000184 } else { //more args
185 // Create the frame index object for this incoming parameter...
186 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
187
188 // Create the SelectionDAG nodes corresponding to a load
189 //from this parameter
190 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
191 argt = newroot = DAG.getLoad(getValueType(I->getType()),
192 DAG.getEntryNode(), FIN);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000193 }
Andrew Lenharth032f2352005-02-22 21:59:48 +0000194 ++count;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000195 DAG.setRoot(newroot.getValue(1));
196 ArgValues.push_back(argt);
197 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000198
199 BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29);
200 BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29);
Andrew Lenharth032f2352005-02-22 21:59:48 +0000201 for (int i = 0; i < count && i < 6; ++i) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000202 BuildMI(&BB, argOpc[i], 2,
203 argVreg[i]).addReg(argPreg[i]).addReg(argPreg[i]);
204 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000205
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000206 return ArgValues;
207}
208
209std::pair<SDOperand, SDOperand>
210AlphaTargetLowering::LowerCallTo(SDOperand Chain,
211 const Type *RetTy, SDOperand Callee,
212 ArgListTy &Args, SelectionDAG &DAG) {
213 int NumBytes = 0;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000214 if (Args.size() > 6)
215 NumBytes = (Args.size() - 6) * 8;
216
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000217 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
218 DAG.getConstant(NumBytes, getPointerTy()));
219 std::vector<SDOperand> args_to_use;
220 for (unsigned i = 0, e = Args.size(); i != e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000221 {
222 switch (getValueType(Args[i].second)) {
223 default: assert(0 && "Unexpected ValueType for argument!");
224 case MVT::i1:
225 case MVT::i8:
226 case MVT::i16:
227 case MVT::i32:
228 // Promote the integer to 64 bits. If the input type is signed use a
229 // sign extend, otherwise use a zero extend.
230 if (Args[i].second->isSigned())
231 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
232 else
233 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
234 break;
235 case MVT::i64:
236 case MVT::f64:
237 case MVT::f32:
238 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000239 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000240 args_to_use.push_back(Args[i].first);
241 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000242
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000243 std::vector<MVT::ValueType> RetVals;
244 MVT::ValueType RetTyVT = getValueType(RetTy);
245 if (RetTyVT != MVT::isVoid)
246 RetVals.push_back(RetTyVT);
247 RetVals.push_back(MVT::Other);
248
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000249 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
250 Chain, Callee, args_to_use), 0);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000251 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
252 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
253 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000254 return std::make_pair(TheCall, Chain);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000255}
256
257std::pair<SDOperand, SDOperand>
258AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
259 //vastart just returns the address of the VarArgsFrameIndex slot.
260 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
261}
262
263std::pair<SDOperand,SDOperand> AlphaTargetLowering::
264LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000265 const Type *ArgTy, SelectionDAG &DAG) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000266 abort();
267}
268
269
270std::pair<SDOperand, SDOperand> AlphaTargetLowering::
271LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
272 SelectionDAG &DAG) {
273 abort();
274}
275
276
277
278
279
280namespace {
281
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000282//===--------------------------------------------------------------------===//
283/// ISel - Alpha specific code to select Alpha machine instructions for
284/// SelectionDAG operations.
285//===--------------------------------------------------------------------===//
286class ISel : public SelectionDAGISel {
287
288 /// AlphaLowering - This object fully describes how to lower LLVM code to an
289 /// Alpha-specific SelectionDAG.
290 AlphaTargetLowering AlphaLowering;
291
292
293 /// ExprMap - As shared expressions are codegen'd, we keep track of which
294 /// vreg the value is produced in, so we only emit one copy of each compiled
295 /// tree.
296 static const unsigned notIn = (unsigned)(-1);
297 std::map<SDOperand, unsigned> ExprMap;
298
299 //CCInvMap sometimes (SetNE) we have the inverse CC code for free
300 std::map<SDOperand, unsigned> CCInvMap;
301
302public:
303 ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
304 {}
305
306 /// InstructionSelectBasicBlock - This callback is invoked by
307 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
308 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000309 DEBUG(BB->dump());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000310 // Codegen the basic block.
311 Select(DAG.getRoot());
312
313 // Clear state used for selection.
314 ExprMap.clear();
315 CCInvMap.clear();
316 }
317
318 unsigned SelectExpr(SDOperand N);
319 unsigned SelectExprFP(SDOperand N, unsigned Result);
320 void Select(SDOperand N);
321
322 void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
323 void SelectBranchCC(SDOperand N);
324};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000325}
326
Andrew Lenharth65838902005-02-06 16:22:15 +0000327static unsigned GetSymVersion(unsigned opcode)
328{
329 switch (opcode) {
330 default: assert(0 && "unknown load or store"); return 0;
331 case Alpha::LDQ: return Alpha::LDQ_SYM;
332 case Alpha::LDS: return Alpha::LDS_SYM;
333 case Alpha::LDT: return Alpha::LDT_SYM;
334 case Alpha::LDL: return Alpha::LDL_SYM;
335 case Alpha::LDBU: return Alpha::LDBU_SYM;
336 case Alpha::LDWU: return Alpha::LDWU_SYM;
337 case Alpha::LDW: return Alpha::LDW_SYM;
338 case Alpha::LDB: return Alpha::LDB_SYM;
339 case Alpha::STQ: return Alpha::STQ_SYM;
340 case Alpha::STS: return Alpha::STS_SYM;
341 case Alpha::STT: return Alpha::STT_SYM;
342 case Alpha::STL: return Alpha::STL_SYM;
343 case Alpha::STW: return Alpha::STW_SYM;
344 case Alpha::STB: return Alpha::STB_SYM;
345 }
346}
347
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000348//Check to see if the load is a constant offset from a base register
349void ISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
350{
351 unsigned opcode = N.getOpcode();
352 if (opcode == ISD::ADD) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000353 if(N.getOperand(1).getOpcode() == ISD::Constant &&
354 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
355 { //Normal imm add
356 Reg = SelectExpr(N.getOperand(0));
357 offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
358 return;
359 }
360 else if(N.getOperand(0).getOpcode() == ISD::Constant &&
361 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767)
362 {
363 Reg = SelectExpr(N.getOperand(1));
364 offset = cast<ConstantSDNode>(N.getOperand(0))->getValue();
365 return;
366 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000367 }
368 Reg = SelectExpr(N);
369 offset = 0;
370 return;
371}
372
Andrew Lenharth445171a2005-02-08 00:40:03 +0000373void ISel::SelectBranchCC(SDOperand N)
374{
375 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000376 MachineBasicBlock *Dest =
377 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
378 unsigned Opc = Alpha::WTF;
379
Andrew Lenharth445171a2005-02-08 00:40:03 +0000380 Select(N.getOperand(0)); //chain
381 SDOperand CC = N.getOperand(1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000382
Andrew Lenharth445171a2005-02-08 00:40:03 +0000383 if (CC.getOpcode() == ISD::SETCC)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000384 {
385 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
386 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
387 //Dropping the CC is only useful if we are comparing to 0
388 bool isZero0 = false;
389 bool isZero1 = false;
390 bool isNE = false;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000391
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000392 if(SetCC->getOperand(0).getOpcode() == ISD::Constant &&
393 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0)
394 isZero0 = true;
395 if(SetCC->getOperand(1).getOpcode() == ISD::Constant &&
396 cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0)
397 isZero1 = true;
398 if(SetCC->getCondition() == ISD::SETNE)
399 isNE = true;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000400
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000401 if (isZero0) {
Andrew Lenharth445171a2005-02-08 00:40:03 +0000402 switch (SetCC->getCondition()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000403 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
404 case ISD::SETEQ: Opc = Alpha::BEQ; break;
405 case ISD::SETLT: Opc = Alpha::BGT; break;
406 case ISD::SETLE: Opc = Alpha::BGE; break;
407 case ISD::SETGT: Opc = Alpha::BLT; break;
408 case ISD::SETGE: Opc = Alpha::BLE; break;
409 case ISD::SETULT: Opc = Alpha::BNE; break;
410 case ISD::SETUGT: assert(0 && "0 > (unsigned) x is never true"); break;
411 case ISD::SETULE: assert(0 && "0 <= (unsigned) x is always true"); break;
412 case ISD::SETUGE: Opc = Alpha::BEQ; break; //Technically you could have this CC
413 case ISD::SETNE: Opc = Alpha::BNE; break;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000414 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000415 unsigned Tmp1 = SelectExpr(SetCC->getOperand(1));
416 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
417 return;
418 } else if (isZero1) {
419 switch (SetCC->getCondition()) {
420 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
421 case ISD::SETEQ: Opc = Alpha::BEQ; break;
422 case ISD::SETLT: Opc = Alpha::BLT; break;
423 case ISD::SETLE: Opc = Alpha::BLE; break;
424 case ISD::SETGT: Opc = Alpha::BGT; break;
425 case ISD::SETGE: Opc = Alpha::BGE; break;
426 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
427 case ISD::SETUGT: Opc = Alpha::BNE; break;
428 case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC
429 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
430 case ISD::SETNE: Opc = Alpha::BNE; break;
431 }
432 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
433 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
434 return;
435 } else {
436 unsigned Tmp1 = SelectExpr(CC);
437 if (isNE)
438 BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
439 else
440 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000441 return;
442 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000443 } else { //FP
444 //Any comparison between 2 values should be codegened as an folded branch, as moving
445 //CC to the integer register is very expensive
446 //for a cmp b: c = a - b;
447 //a = b: c = 0
448 //a < b: c < 0
449 //a > b: c > 0
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000450
451 bool invTest = false;
452 unsigned Tmp3;
453
454 ConstantFPSDNode *CN;
455 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
456 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
457 Tmp3 = SelectExpr(SetCC->getOperand(0));
458 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
459 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
460 {
461 Tmp3 = SelectExpr(SetCC->getOperand(1));
462 invTest = true;
463 }
464 else
465 {
466 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
467 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
468 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
469 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
470 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
471 .addReg(Tmp1).addReg(Tmp2);
472 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000473
474 switch (SetCC->getCondition()) {
475 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000476 case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
477 case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
478 case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
479 case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
480 case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
481 case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000482 }
483 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000484 return;
485 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000486 abort(); //Should never be reached
487 } else {
488 //Giveup and do the stupid thing
489 unsigned Tmp1 = SelectExpr(CC);
490 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
491 return;
492 }
Andrew Lenharth445171a2005-02-08 00:40:03 +0000493 abort(); //Should never be reached
494}
495
Andrew Lenharth40831c52005-01-28 06:57:18 +0000496unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
497{
498 unsigned Tmp1, Tmp2, Tmp3;
499 unsigned Opc = 0;
500 SDNode *Node = N.Val;
501 MVT::ValueType DestType = N.getValueType();
502 unsigned opcode = N.getOpcode();
503
504 switch (opcode) {
505 default:
506 Node->dump();
507 assert(0 && "Node not handled!\n");
Andrew Lenharth2c594352005-01-29 15:42:07 +0000508
Andrew Lenharth9818c052005-02-05 13:19:12 +0000509 case ISD::SELECT:
510 {
511 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
512 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
513 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000514
515
516 // Spill the cond to memory and reload it from there.
517 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
518 MachineFunction *F = BB->getParent();
519 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
520 unsigned Tmp4 = MakeReg(MVT::f64);
521 BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31);
522 BuildMI(BB, Alpha::LDT, 2, Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31);
523 //now ideally, we don't have to do anything to the flag...
Andrew Lenharth9818c052005-02-05 13:19:12 +0000524 // Get the condition into the zero flag.
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000525 BuildMI(BB, Alpha::FCMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp4);
Andrew Lenharth9818c052005-02-05 13:19:12 +0000526 return Result;
527 }
528
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000529 case ISD::FP_ROUND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000530 assert (DestType == MVT::f32 &&
531 N.getOperand(0).getValueType() == MVT::f64 &&
532 "only f64 to f32 conversion supported here");
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000533 Tmp1 = SelectExpr(N.getOperand(0));
534 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
535 return Result;
536
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000537 case ISD::FP_EXTEND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000538 assert (DestType == MVT::f64 &&
539 N.getOperand(0).getValueType() == MVT::f32 &&
540 "only f32 to f64 conversion supported here");
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000541 Tmp1 = SelectExpr(N.getOperand(0));
542 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
543 return Result;
544
Andrew Lenharth2c594352005-01-29 15:42:07 +0000545 case ISD::CopyFromReg:
546 {
547 // Make sure we generate both values.
548 if (Result != notIn)
549 ExprMap[N.getValue(1)] = notIn; // Generate the token
550 else
551 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
552
553 SDOperand Chain = N.getOperand(0);
554
555 Select(Chain);
556 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
557 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
558 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
559 return Result;
560 }
561
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000562 case ISD::LOAD:
563 {
564 // Make sure we generate both values.
565 if (Result != notIn)
566 ExprMap[N.getValue(1)] = notIn; // Generate the token
567 else
568 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000569
Andrew Lenharth29219162005-02-07 06:31:44 +0000570 DestType = N.getValue(0).getValueType();
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000571
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000572 SDOperand Chain = N.getOperand(0);
573 SDOperand Address = N.getOperand(1);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000574 Select(Chain);
Andrew Lenharth65838902005-02-06 16:22:15 +0000575 Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS;
576
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000577 if (Address.getOpcode() == ISD::GlobalAddress) {
578 AlphaLowering.restoreGP(BB);
579 Opc = GetSymVersion(Opc);
580 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
581 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000582 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000583 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +0000584 Opc = GetSymVersion(Opc);
Andrew Lenharth97127a12005-02-05 17:41:39 +0000585 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000586 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000587 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000588 BuildMI(BB, Opc, 2, Result)
589 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
590 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000591 } else {
592 long offset;
593 SelectAddr(Address, Tmp1, offset);
594 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
595 }
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000596 return Result;
597 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000598 case ISD::ConstantFP:
599 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
600 if (CN->isExactlyValue(+0.0)) {
601 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000602 } else if ( CN->isExactlyValue(-0.0)) {
603 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000604 } else {
605 abort();
606 }
607 }
608 return Result;
609
610 case ISD::MUL:
611 case ISD::ADD:
612 case ISD::SUB:
613 case ISD::SDIV:
614 switch( opcode ) {
615 case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break;
616 case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break;
617 case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break;
618 case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break;
619 };
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000620
621 ConstantFPSDNode *CN;
622 if (opcode == ISD::SUB
623 && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
624 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
625 {
626 Tmp2 = SelectExpr(N.getOperand(1));
627 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
628 } else {
629 Tmp1 = SelectExpr(N.getOperand(0));
630 Tmp2 = SelectExpr(N.getOperand(1));
631 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
632 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000633 return Result;
634
Andrew Lenharth2c594352005-01-29 15:42:07 +0000635 case ISD::EXTLOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000636 {
637 //include a conversion sequence for float loads to double
638 if (Result != notIn)
639 ExprMap[N.getValue(1)] = notIn; // Generate the token
640 else
641 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
642
Andrew Lenhartha549deb2005-02-07 05:33:15 +0000643 Tmp1 = MakeReg(MVT::f32);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000644
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000645 assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 &&
646 "EXTLOAD not from f32");
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000647 assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64");
648
649 SDOperand Chain = N.getOperand(0);
650 SDOperand Address = N.getOperand(1);
651 Select(Chain);
652
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000653 if (Address.getOpcode() == ISD::GlobalAddress) {
654 AlphaLowering.restoreGP(BB);
655 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
656 }
657 else if (ConstantPoolSDNode *CP =
658 dyn_cast<ConstantPoolSDNode>(N.getOperand(1)))
659 {
660 AlphaLowering.restoreGP(BB);
661 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex());
662 }
663 else if(Address.getOpcode() == ISD::FrameIndex) {
664 Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
Andrew Lenharth032f2352005-02-22 21:59:48 +0000665 BuildMI(BB, Alpha::LDS, 2, Tmp1)
666 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
667 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000668 } else {
669 long offset;
670 SelectAddr(Address, Tmp2, offset);
671 BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2);
672 }
Andrew Lenharth29219162005-02-07 06:31:44 +0000673 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000674 return Result;
675 }
Andrew Lenharth2c594352005-01-29 15:42:07 +0000676
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000677 case ISD::UINT_TO_FP:
678 case ISD::SINT_TO_FP:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000679 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000680 assert (N.getOperand(0).getValueType() == MVT::i64
681 && "only quads can be loaded from");
Andrew Lenharth40831c52005-01-28 06:57:18 +0000682 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000683 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000684
685 //The hard way:
686 // Spill the integer to memory and reload it from there.
687 unsigned Size = MVT::getSizeInBits(MVT::i64)/8;
688 MachineFunction *F = BB->getParent();
689 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, Size);
690
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000691 BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31);
692 BuildMI(BB, Alpha::LDT, 2, Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
693 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
694 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000695
696 //The easy way: doesn't work
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000697 // //so these instructions are not supported on ev56
698 // Opc = DestType == MVT::f64 ? Alpha::ITOFT : Alpha::ITOFS;
699 // BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp1);
700 // Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
701 // BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000702
Andrew Lenharth40831c52005-01-28 06:57:18 +0000703 return Result;
704 }
705 }
706 assert(0 && "should not get here");
707 return 0;
708}
709
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000710unsigned ISel::SelectExpr(SDOperand N) {
711 unsigned Result;
712 unsigned Tmp1, Tmp2, Tmp3;
713 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000714 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000715
716 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000717 MVT::ValueType DestType = N.getValueType();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000718
719 unsigned &Reg = ExprMap[N];
720 if (Reg) return Reg;
721
722 if (N.getOpcode() != ISD::CALL)
723 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000724 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000725 else {
726 // If this is a call instruction, make sure to prepare ALL of the result
727 // values as well as the chain.
728 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000729 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000730 else {
731 Result = MakeReg(Node->getValueType(0));
732 ExprMap[N.getValue(0)] = Result;
733 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
734 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000735 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000736 }
737 }
738
Andrew Lenharth22088bb2005-02-02 15:05:33 +0000739 if (DestType == MVT::f64 || DestType == MVT::f32 ||
Andrew Lenharth06342c32005-02-07 06:21:37 +0000740 (
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000741 (opcode == ISD::LOAD || opcode == ISD::CopyFromReg ||
742 opcode == ISD::EXTLOAD) &&
743 (N.getValue(0).getValueType() == MVT::f32 ||
744 N.getValue(0).getValueType() == MVT::f64)
Andrew Lenharth06342c32005-02-07 06:21:37 +0000745 )
746 )
Andrew Lenharth40831c52005-01-28 06:57:18 +0000747 return SelectExprFP(N, Result);
748
749 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000750 default:
751 Node->dump();
752 assert(0 && "Node not handled!\n");
753
Andrew Lenharth032f2352005-02-22 21:59:48 +0000754 case ISD::DYNAMIC_STACKALLOC:
755 // Generate both result values.
Andrew Lenharth3a7118d2005-02-23 17:33:42 +0000756 if (Result != notIn)
757 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth032f2352005-02-22 21:59:48 +0000758 else
759 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
760
761 // FIXME: We are currently ignoring the requested alignment for handling
762 // greater than the stack alignment. This will need to be revisited at some
763 // point. Align = N.getOperand(2);
764
765 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
766 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
767 std::cerr << "Cannot allocate stack object with greater alignment than"
768 << " the stack alignment yet!";
769 abort();
770 }
771
772 Select(N.getOperand(0));
773 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
774 {
775 if (CN->getValue() < 32000)
776 {
777 BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
778 .addImm(-CN->getValue()).addReg(Alpha::R30);
779 } else {
780 Tmp1 = SelectExpr(N.getOperand(1));
781 // Subtract size from stack pointer, thereby allocating some space.
782 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
783 }
784 } else {
785 Tmp1 = SelectExpr(N.getOperand(1));
786 // Subtract size from stack pointer, thereby allocating some space.
787 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
788 }
789
790 // Put a pointer to the space into the result register, by copying the stack
791 // pointer.
Andrew Lenharth7bc47022005-02-22 23:29:25 +0000792 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
Andrew Lenharth032f2352005-02-22 21:59:48 +0000793 return Result;
794
Andrew Lenharth2c594352005-01-29 15:42:07 +0000795 case ISD::ConstantPool:
796 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
797 AlphaLowering.restoreGP(BB);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000798 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000799 return Result;
800
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000801 case ISD::FrameIndex:
Andrew Lenharth032f2352005-02-22 21:59:48 +0000802 BuildMI(BB, Alpha::LDA, 2, Result)
803 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
804 .addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000805 return Result;
806
807 case ISD::EXTLOAD:
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000808 case ISD::ZEXTLOAD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000809 case ISD::SEXTLOAD:
Andrew Lenhartha549deb2005-02-07 05:33:15 +0000810 case ISD::LOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000811 {
812 // Make sure we generate both values.
813 if (Result != notIn)
814 ExprMap[N.getValue(1)] = notIn; // Generate the token
815 else
816 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000817
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000818 SDOperand Chain = N.getOperand(0);
819 SDOperand Address = N.getOperand(1);
820 Select(Chain);
821
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000822 assert(Node->getValueType(0) == MVT::i64 &&
823 "Unknown type to sign extend to.");
Andrew Lenharth03824012005-02-07 05:55:55 +0000824 if (opcode == ISD::LOAD)
825 Opc = Alpha::LDQ;
826 else
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000827 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
828 default: Node->dump(); assert(0 && "Bad sign extend!");
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000829 case MVT::i32: Opc = Alpha::LDL;
830 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
831 case MVT::i16: Opc = Alpha::LDWU;
832 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000833 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000834 case MVT::i8: Opc = Alpha::LDBU;
835 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000836 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000837
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000838 if (Address.getOpcode() == ISD::GlobalAddress) {
839 AlphaLowering.restoreGP(BB);
840 Opc = GetSymVersion(Opc);
841 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
842 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000843 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
844 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +0000845 Opc = GetSymVersion(Opc);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000846 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000847 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000848 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000849 BuildMI(BB, Opc, 2, Result)
850 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
851 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000852 } else {
853 long offset;
854 SelectAddr(Address, Tmp1, offset);
855 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
856 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000857 return Result;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000858 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000859
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000860 case ISD::GlobalAddress:
861 AlphaLowering.restoreGP(BB);
862 BuildMI(BB, Alpha::LOAD_ADDR, 1, Result)
863 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal());
864 return Result;
865
866 case ISD::CALL:
867 {
868 Select(N.getOperand(0));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000869
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000870 // The chain for this call is now lowered.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000871 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000872
873 //grab the arguments
874 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000875 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000876 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000877 argvregs.push_back(SelectExpr(N.getOperand(i)));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000878
Andrew Lenharth684f2292005-01-30 00:35:27 +0000879 //in reg args
880 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000881 {
882 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
883 Alpha::R19, Alpha::R20, Alpha::R21};
884 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
885 Alpha::F19, Alpha::F20, Alpha::F21};
886 switch(N.getOperand(i+2).getValueType()) {
887 default:
888 Node->dump();
889 N.getOperand(i).Val->dump();
890 std::cerr << "Type for " << i << " is: " <<
891 N.getOperand(i+2).getValueType() << "\n";
892 assert(0 && "Unknown value type for call");
893 case MVT::i1:
894 case MVT::i8:
895 case MVT::i16:
896 case MVT::i32:
897 case MVT::i64:
898 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]);
899 break;
900 case MVT::f32:
901 case MVT::f64:
902 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]);
903 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000904 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000905 }
Andrew Lenharth684f2292005-01-30 00:35:27 +0000906 //in mem args
907 for (int i = 6, e = argvregs.size(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000908 {
909 switch(N.getOperand(i+2).getValueType()) {
910 default:
911 Node->dump();
912 N.getOperand(i).Val->dump();
913 std::cerr << "Type for " << i << " is: " <<
914 N.getOperand(i+2).getValueType() << "\n";
915 assert(0 && "Unknown value type for call");
916 case MVT::i1:
917 case MVT::i8:
918 case MVT::i16:
919 case MVT::i32:
920 case MVT::i64:
921 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
922 break;
923 case MVT::f32:
924 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
925 break;
926 case MVT::f64:
927 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
928 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000929 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000930 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000931 //build the right kind of call
932 if (GlobalAddressSDNode *GASD =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000933 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000934 {
Andrew Lenharth3e315922005-02-10 20:10:38 +0000935 //if (GASD->getGlobal()->isExternal()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000936 //use safe calling convention
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000937 AlphaLowering.restoreGP(BB);
938 BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true);
Andrew Lenharth3e315922005-02-10 20:10:38 +0000939 //} else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000940 //use PC relative branch call
Andrew Lenharth3e315922005-02-10 20:10:38 +0000941 //BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
942 //}
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000943 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000944 else if (ExternalSymbolSDNode *ESSDN =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000945 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000946 {
947 AlphaLowering.restoreGP(BB);
948 BuildMI(BB, Alpha::CALL, 0).addExternalSymbol(ESSDN->getSymbol(), true);
949 } else {
950 //no need to restore GP as we are doing an indirect call
951 Tmp1 = SelectExpr(N.getOperand(1));
952 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
953 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
954 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000955
956 //push the result into a virtual register
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000957
958 switch (Node->getValueType(0)) {
959 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000960 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000961 case MVT::i1:
962 case MVT::i8:
963 case MVT::i16:
964 case MVT::i32:
965 case MVT::i64:
966 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
967 break;
968 case MVT::f32:
969 case MVT::f64:
970 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
971 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000972 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000973 return Result+N.ResNo;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000974 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000975
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000976 case ISD::SIGN_EXTEND:
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000977 abort();
978
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000979 case ISD::SIGN_EXTEND_INREG:
980 {
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000981 //Alpha has instructions for a bunch of signed 32 bit stuff
982 if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000983 {
984 switch (N.getOperand(0).getOpcode()) {
985 case ISD::ADD:
986 case ISD::SUB:
987 case ISD::MUL:
988 {
989 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
990 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
991 //FIXME: first check for Scaled Adds and Subs!
992 if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
993 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
994 { //Normal imm add/sub
995 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
Andrew Lenharth093f3272005-02-12 21:11:17 +0000996 //if the value was really originally a i32, skip the up conversion
997 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
998 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
999 ->getExtraValueType() == MVT::i32)
1000 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1001 else
1002 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001003 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
1004 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001005 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001006 else
1007 { //Normal add/sub
1008 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULLi : Alpha::SUBL);
Andrew Lenharth093f3272005-02-12 21:11:17 +00001009 //if the value was really originally a i32, skip the up conversion
1010 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
1011 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
1012 ->getExtraValueType() == MVT::i32)
1013 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1014 else
1015 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1016 //if the value was really originally a i32, skip the up conversion
1017 if (N.getOperand(0).getOperand(1).getOpcode() == ISD::SIGN_EXTEND_INREG &&
1018 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(1).Val)
1019 ->getExtraValueType() == MVT::i32)
1020 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
1021 else
1022 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1023
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001024 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1025 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1026 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1027 }
1028 return Result;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001029 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001030 default: break; //Fall Though;
1031 }
1032 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001033 Tmp1 = SelectExpr(N.getOperand(0));
1034 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001035 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001036 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001037 {
1038 default:
1039 Node->dump();
1040 assert(0 && "Sign Extend InReg not there yet");
1041 break;
1042 case MVT::i32:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001043 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001044 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001045 break;
1046 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001047 case MVT::i16:
1048 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
1049 break;
1050 case MVT::i8:
1051 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
1052 break;
Andrew Lenharthebce5042005-02-12 19:35:12 +00001053 case MVT::i1:
1054 Tmp2 = MakeReg(MVT::i64);
1055 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
Andrew Lenharth7536eea2005-02-12 20:42:09 +00001056 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::F31).addReg(Tmp2);
Andrew Lenharthebce5042005-02-12 19:35:12 +00001057 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001058 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001059 return Result;
1060 }
1061 case ISD::ZERO_EXTEND_INREG:
1062 {
1063 Tmp1 = SelectExpr(N.getOperand(0));
1064 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001065 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001066 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001067 {
1068 default:
1069 Node->dump();
1070 assert(0 && "Zero Extend InReg not there yet");
1071 break;
1072 case MVT::i32: Tmp2 = 0xf0; break;
1073 case MVT::i16: Tmp2 = 0xfc; break;
1074 case MVT::i8: Tmp2 = 0xfe; break;
1075 case MVT::i1: //handle this one special
1076 BuildMI(BB, Alpha::ANDi, 2, Result).addReg(Tmp1).addImm(1);
1077 return Result;
1078 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001079 BuildMI(BB, Alpha::ZAPi, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001080 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001081 }
1082
1083 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001084 {
1085 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1086 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
1087 bool isConst1 = false;
1088 bool isConst2 = false;
1089 int dir;
Andrew Lenharth9818c052005-02-05 13:19:12 +00001090
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001091 //Tmp1 = SelectExpr(N.getOperand(0));
1092 if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001093 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255)
1094 isConst1 = true;
1095 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001096 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1097 isConst2 = true;
1098
1099 switch (SetCC->getCondition()) {
1100 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1101 case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001102 case ISD::SETLT:
1103 Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
1104 case ISD::SETLE:
1105 Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
1106 case ISD::SETGT:
1107 Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break;
1108 case ISD::SETGE:
1109 Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break;
1110 case ISD::SETULT:
1111 Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
1112 case ISD::SETUGT:
1113 Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break;
1114 case ISD::SETULE:
1115 Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
1116 case ISD::SETUGE:
1117 Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001118 case ISD::SETNE: {//Handle this one special
1119 //std::cerr << "Alpha does not have a setne.\n";
1120 //abort();
1121 Tmp1 = SelectExpr(N.getOperand(0));
1122 Tmp2 = SelectExpr(N.getOperand(1));
1123 Tmp3 = MakeReg(MVT::i64);
1124 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth445171a2005-02-08 00:40:03 +00001125 //Remeber we have the Inv for this CC
1126 CCInvMap[N] = Tmp3;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001127 //and invert
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001128 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001129 return Result;
1130 }
1131 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001132 if (dir == 1) {
1133 Tmp1 = SelectExpr(N.getOperand(0));
1134 if (isConst2) {
1135 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1136 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1137 } else {
1138 Tmp2 = SelectExpr(N.getOperand(1));
1139 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1140 }
1141 } else if (dir == 2) {
1142 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001143 if (isConst1) {
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001144 Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1145 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1146 } else {
1147 Tmp2 = SelectExpr(N.getOperand(0));
1148 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1149 }
1150 } else { //dir == 0
1151 if (isConst1) {
1152 Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1153 Tmp2 = SelectExpr(N.getOperand(1));
1154 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1);
1155 } else if (isConst2) {
1156 Tmp1 = SelectExpr(N.getOperand(0));
1157 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1158 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2);
1159 } else {
1160 Tmp1 = SelectExpr(N.getOperand(0));
1161 Tmp2 = SelectExpr(N.getOperand(1));
1162 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1163 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001164 }
1165 } else {
1166 //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted");
1167 bool rev = false;
1168 bool inv = false;
1169
1170 switch (SetCC->getCondition()) {
1171 default: Node->dump(); assert(0 && "Unknown FP comparison!");
1172 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
1173 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
1174 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
1175 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
1176 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
1177 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
1178 }
1179
1180 Tmp1 = SelectExpr(N.getOperand(0));
1181 Tmp2 = SelectExpr(N.getOperand(1));
1182 //Can only compare doubles, and dag won't promote for me
1183 if (SetCC->getOperand(0).getValueType() == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001184 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001185 //assert(0 && "Setcc On float?\n");
1186 std::cerr << "Setcc on float!\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001187 Tmp3 = MakeReg(MVT::f64);
1188 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
1189 Tmp1 = Tmp3;
1190 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001191 if (SetCC->getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001192 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001193 //assert (0 && "Setcc On float?\n");
1194 std::cerr << "Setcc on float!\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001195 Tmp3 = MakeReg(MVT::f64);
1196 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
Andrew Lenharth572af902005-02-14 05:41:43 +00001197 Tmp2 = Tmp3;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001198 }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001199
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001200 if (rev) std::swap(Tmp1, Tmp2);
1201 Tmp3 = MakeReg(MVT::f64);
1202 //do the comparison
1203 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1204
1205 //now arrange for Result (int) to have a 1 or 0
1206
1207 // Spill the FP to memory and reload it from there.
1208 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1209 MachineFunction *F = BB->getParent();
1210 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
1211 unsigned Tmp4 = MakeReg(MVT::f64);
1212 BuildMI(BB, Alpha::CVTTQ, 1, Tmp4).addReg(Tmp3);
1213 BuildMI(BB, Alpha::STT, 3).addReg(Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1214 unsigned Tmp5 = MakeReg(MVT::i64);
1215 BuildMI(BB, Alpha::LDQ, 2, Tmp5).addFrameIndex(FrameIdx).addReg(Alpha::F31);
Andrew Lenharth9818c052005-02-05 13:19:12 +00001216
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001217 //now, set result based on Tmp5
1218 //Set Tmp6 if fp cmp was false
1219 unsigned Tmp6 = MakeReg(MVT::i64);
1220 BuildMI(BB, Alpha::CMPEQ, 2, Tmp6).addReg(Tmp5).addReg(Alpha::R31);
1221 //and invert
1222 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp6).addReg(Alpha::R31);
1223
1224 }
1225 // else
1226 // {
1227 // Node->dump();
1228 // assert(0 && "Not a setcc in setcc");
1229 // }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001230 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001231 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001232 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001233
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001234 case ISD::CopyFromReg:
1235 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001236 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001237 if (Result != notIn)
1238 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +00001239 else
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001240 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth40831c52005-01-28 06:57:18 +00001241
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001242 SDOperand Chain = N.getOperand(0);
1243
1244 Select(Chain);
1245 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1246 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1247 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
1248 return Result;
1249 }
1250
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001251 //Most of the plain arithmetic and logic share the same form, and the same
1252 //constant immediate test
1253 case ISD::AND:
1254 case ISD::OR:
1255 case ISD::XOR:
1256 case ISD::SHL:
1257 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +00001258 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001259 case ISD::MUL:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001260 assert (DestType == MVT::i64 && "Only do arithmetic on i64s!");
1261 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001262 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001263 {
1264 switch(opcode) {
1265 case ISD::AND: Opc = Alpha::ANDi; break;
1266 case ISD::OR: Opc = Alpha::BISi; break;
1267 case ISD::XOR: Opc = Alpha::XORi; break;
1268 case ISD::SHL: Opc = Alpha::SLi; break;
1269 case ISD::SRL: Opc = Alpha::SRLi; break;
1270 case ISD::SRA: Opc = Alpha::SRAi; break;
1271 case ISD::MUL: Opc = Alpha::MULQi; break;
1272 };
1273 Tmp1 = SelectExpr(N.getOperand(0));
1274 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1275 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1276 } else {
1277 switch(opcode) {
1278 case ISD::AND: Opc = Alpha::AND; break;
1279 case ISD::OR: Opc = Alpha::BIS; break;
1280 case ISD::XOR: Opc = Alpha::XOR; break;
1281 case ISD::SHL: Opc = Alpha::SL; break;
1282 case ISD::SRL: Opc = Alpha::SRL; break;
1283 case ISD::SRA: Opc = Alpha::SRA; break;
1284 case ISD::MUL: Opc = Alpha::MULQ; break;
1285 };
1286 Tmp1 = SelectExpr(N.getOperand(0));
1287 Tmp2 = SelectExpr(N.getOperand(1));
1288 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1289 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001290 return Result;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001291
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001292 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001293 case ISD::SUB:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001294 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001295 bool isAdd = opcode == ISD::ADD;
1296
1297 //FIXME: first check for Scaled Adds and Subs!
1298 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001299 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001300 { //Normal imm add/sub
1301 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
1302 Tmp1 = SelectExpr(N.getOperand(0));
1303 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1304 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1305 }
Andrew Lenharth40831c52005-01-28 06:57:18 +00001306 else if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001307 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001308 { //LDA //FIXME: expand the above condition a bit
1309 Tmp1 = SelectExpr(N.getOperand(0));
1310 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1311 if (!isAdd)
1312 Tmp2 = -Tmp2;
1313 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
1314 } else {
1315 //Normal add/sub
1316 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1317 Tmp1 = SelectExpr(N.getOperand(0));
1318 Tmp2 = SelectExpr(N.getOperand(1));
1319 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1320 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001321 return Result;
1322 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001323
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001324 case ISD::UREM:
Andrew Lenharth02981182005-01-26 01:24:38 +00001325 case ISD::SREM:
1326 case ISD::SDIV:
1327 case ISD::UDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001328 //FIXME: alpha really doesn't support any of these operations,
1329 // the ops are expanded into special library calls with
1330 // special calling conventions
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001331 //Restore GP because it is a call after all...
Andrew Lenharth40831c52005-01-28 06:57:18 +00001332 switch(opcode) {
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001333 case ISD::UREM: Opc = Alpha::REMQU; break;
1334 case ISD::SREM: Opc = Alpha::REMQ; break;
1335 case ISD::UDIV: Opc = Alpha::DIVQU; break;
1336 case ISD::SDIV: Opc = Alpha::DIVQ; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001337 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001338 Tmp1 = SelectExpr(N.getOperand(0));
1339 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001340 AlphaLowering.restoreGP(BB);
Andrew Lenharth02981182005-01-26 01:24:38 +00001341 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001342 return Result;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001343
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001344 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001345 case ISD::FP_TO_SINT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001346 {
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001347 assert (DestType == MVT::i64 && "only quads can be loaded to");
1348 MVT::ValueType SrcType = N.getOperand(0).getValueType();
Andrew Lenharth03824012005-02-07 05:55:55 +00001349 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001350 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
1351
1352 //The hard way:
1353 // Spill the integer to memory and reload it from there.
1354 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1355 MachineFunction *F = BB->getParent();
1356 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
1357
1358 //CVTTQ STT LDQ
1359 //CVTST CVTTQ STT LDQ
1360 if (SrcType == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001361 {
1362 Tmp2 = MakeReg(MVT::f64);
1363 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
1364 Tmp1 = Tmp2;
1365 }
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001366 Tmp2 = MakeReg(MVT::f64);
1367 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
1368 BuildMI(BB, Alpha::STT, 3).addReg(Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1369 BuildMI(BB, Alpha::LDQ, 2, Result).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1370
1371 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001372 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001373
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001374 // // case ISD::FP_TO_UINT:
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001375
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001376 case ISD::SELECT:
1377 {
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001378 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001379 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1380 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001381 // Get the condition into the zero flag.
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001382 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001383 return Result;
1384 }
1385
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001386 case ISD::Constant:
1387 {
Andrew Lenharth22d5a412005-02-02 00:51:15 +00001388 unsigned long val = cast<ConstantSDNode>(N)->getValue();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001389 if (val < 32000 && (long)val > -32000)
1390 BuildMI(BB, Alpha::LOAD_IMM, 1, Result).addImm(val);
1391 else {
1392 MachineConstantPool *CP = BB->getParent()->getConstantPool();
1393 ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
1394 unsigned CPI = CP->getConstantPoolIndex(C);
1395 AlphaLowering.restoreGP(BB);
1396 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI);
1397 }
1398 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001399 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001400 }
1401
1402 return 0;
1403}
1404
1405void ISel::Select(SDOperand N) {
1406 unsigned Tmp1, Tmp2, Opc;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001407 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001408
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001409 // FIXME: Disable for our current expansion model!
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001410 if (/*!N->hasOneUse() &&*/ !ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001411 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001412
1413 SDNode *Node = N.Val;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001414
Andrew Lenharth760270d2005-02-07 23:02:23 +00001415 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001416
1417 default:
1418 Node->dump(); std::cerr << "\n";
1419 assert(0 && "Node not handled yet!");
1420
1421 case ISD::BRCOND: {
Andrew Lenharth445171a2005-02-08 00:40:03 +00001422 SelectBranchCC(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001423 return;
1424 }
1425
1426 case ISD::BR: {
1427 MachineBasicBlock *Dest =
1428 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1429
1430 Select(N.getOperand(0));
1431 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
1432 return;
1433 }
1434
1435 case ISD::ImplicitDef:
1436 Select(N.getOperand(0));
1437 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
1438 return;
1439
1440 case ISD::EntryToken: return; // Noop
1441
1442 case ISD::TokenFactor:
1443 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1444 Select(Node->getOperand(i));
1445
1446 //N.Val->dump(); std::cerr << "\n";
1447 //assert(0 && "Node not handled yet!");
1448
1449 return;
1450
1451 case ISD::CopyToReg:
1452 Select(N.getOperand(0));
1453 Tmp1 = SelectExpr(N.getOperand(1));
1454 Tmp2 = cast<RegSDNode>(N)->getReg();
1455
1456 if (Tmp1 != Tmp2) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001457 if (N.getOperand(1).getValueType() == MVT::f64 ||
1458 N.getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth29219162005-02-07 06:31:44 +00001459 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1460 else
1461 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001462 }
1463 return;
1464
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001465 case ISD::RET:
1466 switch (N.getNumOperands()) {
1467 default:
1468 std::cerr << N.getNumOperands() << "\n";
1469 for (unsigned i = 0; i < N.getNumOperands(); ++i)
1470 std::cerr << N.getOperand(i).getValueType() << "\n";
1471 Node->dump();
1472 assert(0 && "Unknown return instruction!");
1473 case 2:
1474 Select(N.getOperand(0));
1475 Tmp1 = SelectExpr(N.getOperand(1));
1476 switch (N.getOperand(1).getValueType()) {
1477 default: Node->dump();
1478 assert(0 && "All other types should have been promoted!!");
1479 case MVT::f64:
1480 case MVT::f32:
1481 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
1482 break;
1483 case MVT::i32:
1484 case MVT::i64:
1485 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
1486 break;
1487 }
1488 break;
1489 case 1:
1490 Select(N.getOperand(0));
1491 break;
1492 }
1493 //Tmp2 = AlphaLowering.getRetAddr();
1494 //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2);
1495 BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction
1496 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001497
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001498 case ISD::TRUNCSTORE:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001499 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001500 {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001501 SDOperand Chain = N.getOperand(0);
1502 SDOperand Value = N.getOperand(1);
1503 SDOperand Address = N.getOperand(2);
1504 Select(Chain);
1505
1506 Tmp1 = SelectExpr(Value); //value
Andrew Lenharth760270d2005-02-07 23:02:23 +00001507
1508 if (opcode == ISD::STORE) {
1509 switch(Value.getValueType()) {
1510 default: assert(0 && "unknown Type in store");
1511 case MVT::i64: Opc = Alpha::STQ; break;
1512 case MVT::f64: Opc = Alpha::STT; break;
1513 case MVT::f32: Opc = Alpha::STS; break;
1514 }
1515 } else { //ISD::TRUNCSTORE
1516 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1517 default: assert(0 && "unknown Type in store");
1518 case MVT::i1: //FIXME: DAG does not promote this load
1519 case MVT::i8: Opc = Alpha::STB; break;
1520 case MVT::i16: Opc = Alpha::STW; break;
1521 case MVT::i32: Opc = Alpha::STL; break;
1522 }
Andrew Lenharth65838902005-02-06 16:22:15 +00001523 }
Andrew Lenharth760270d2005-02-07 23:02:23 +00001524
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001525 if (Address.getOpcode() == ISD::GlobalAddress)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001526 {
1527 AlphaLowering.restoreGP(BB);
1528 Opc = GetSymVersion(Opc);
1529 BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1530 }
Andrew Lenharth05380342005-02-07 05:07:00 +00001531 else if(Address.getOpcode() == ISD::FrameIndex)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001532 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001533 BuildMI(BB, Opc, 3).addReg(Tmp1)
1534 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1535 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001536 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001537 else
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001538 {
1539 long offset;
1540 SelectAddr(Address, Tmp2, offset);
1541 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1542 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001543 return;
1544 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001545
1546 case ISD::EXTLOAD:
1547 case ISD::SEXTLOAD:
1548 case ISD::ZEXTLOAD:
1549 case ISD::LOAD:
1550 case ISD::CopyFromReg:
1551 case ISD::CALL:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001552 case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001553 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001554 SelectExpr(N);
1555 return;
1556
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001557 case ISD::ADJCALLSTACKDOWN:
1558 case ISD::ADJCALLSTACKUP:
1559 Select(N.getOperand(0));
1560 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1561
1562 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? Alpha::ADJUSTSTACKDOWN :
1563 Alpha::ADJUSTSTACKUP;
1564 BuildMI(BB, Opc, 1).addImm(Tmp1);
1565 return;
1566 }
1567 assert(0 && "Should not be reached!");
1568}
1569
1570
1571/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
1572/// into a machine code representation using pattern matching and a machine
1573/// description file.
1574///
1575FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
1576 return new ISel(TM);
1577}