blob: 11299bd0aec3d9b4f692a9f52962d3a4c5d90942 [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
450 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
451 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
452 unsigned Tmp3 = MakeReg(MVT::f64);
453 BuildMI(BB, Alpha::SUBT, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
454
455 switch (SetCC->getCondition()) {
456 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
457 case ISD::SETEQ: Opc = Alpha::FBEQ; break;
458 case ISD::SETLT: Opc = Alpha::FBLT; break;
459 case ISD::SETLE: Opc = Alpha::FBLE; break;
460 case ISD::SETGT: Opc = Alpha::FBGT; break;
461 case ISD::SETGE: Opc = Alpha::FBGE; break;
462 case ISD::SETNE: Opc = Alpha::FBNE; break;
463 }
464 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000465 return;
466 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000467 abort(); //Should never be reached
468 } else {
469 //Giveup and do the stupid thing
470 unsigned Tmp1 = SelectExpr(CC);
471 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
472 return;
473 }
Andrew Lenharth445171a2005-02-08 00:40:03 +0000474 abort(); //Should never be reached
475}
476
Andrew Lenharth40831c52005-01-28 06:57:18 +0000477unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
478{
479 unsigned Tmp1, Tmp2, Tmp3;
480 unsigned Opc = 0;
481 SDNode *Node = N.Val;
482 MVT::ValueType DestType = N.getValueType();
483 unsigned opcode = N.getOpcode();
484
485 switch (opcode) {
486 default:
487 Node->dump();
488 assert(0 && "Node not handled!\n");
Andrew Lenharth2c594352005-01-29 15:42:07 +0000489
Andrew Lenharth9818c052005-02-05 13:19:12 +0000490 case ISD::SELECT:
491 {
492 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
493 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
494 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000495
496
497 // Spill the cond to memory and reload it from there.
498 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
499 MachineFunction *F = BB->getParent();
500 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
501 unsigned Tmp4 = MakeReg(MVT::f64);
502 BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31);
503 BuildMI(BB, Alpha::LDT, 2, Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31);
504 //now ideally, we don't have to do anything to the flag...
Andrew Lenharth9818c052005-02-05 13:19:12 +0000505 // Get the condition into the zero flag.
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000506 BuildMI(BB, Alpha::FCMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp4);
Andrew Lenharth9818c052005-02-05 13:19:12 +0000507 return Result;
508 }
509
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000510 case ISD::FP_ROUND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000511 assert (DestType == MVT::f32 &&
512 N.getOperand(0).getValueType() == MVT::f64 &&
513 "only f64 to f32 conversion supported here");
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000514 Tmp1 = SelectExpr(N.getOperand(0));
515 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
516 return Result;
517
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000518 case ISD::FP_EXTEND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000519 assert (DestType == MVT::f64 &&
520 N.getOperand(0).getValueType() == MVT::f32 &&
521 "only f32 to f64 conversion supported here");
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000522 Tmp1 = SelectExpr(N.getOperand(0));
523 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
524 return Result;
525
Andrew Lenharth2c594352005-01-29 15:42:07 +0000526 case ISD::CopyFromReg:
527 {
528 // Make sure we generate both values.
529 if (Result != notIn)
530 ExprMap[N.getValue(1)] = notIn; // Generate the token
531 else
532 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
533
534 SDOperand Chain = N.getOperand(0);
535
536 Select(Chain);
537 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
538 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
539 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
540 return Result;
541 }
542
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000543 case ISD::LOAD:
544 {
545 // Make sure we generate both values.
546 if (Result != notIn)
547 ExprMap[N.getValue(1)] = notIn; // Generate the token
548 else
549 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000550
Andrew Lenharth29219162005-02-07 06:31:44 +0000551 DestType = N.getValue(0).getValueType();
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000552
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000553 SDOperand Chain = N.getOperand(0);
554 SDOperand Address = N.getOperand(1);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000555 Select(Chain);
Andrew Lenharth65838902005-02-06 16:22:15 +0000556 Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS;
557
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000558 if (Address.getOpcode() == ISD::GlobalAddress) {
559 AlphaLowering.restoreGP(BB);
560 Opc = GetSymVersion(Opc);
561 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
562 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000563 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000564 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +0000565 Opc = GetSymVersion(Opc);
Andrew Lenharth97127a12005-02-05 17:41:39 +0000566 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000567 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000568 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000569 BuildMI(BB, Opc, 2, Result)
570 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
571 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000572 } else {
573 long offset;
574 SelectAddr(Address, Tmp1, offset);
575 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
576 }
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000577 return Result;
578 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000579 case ISD::ConstantFP:
580 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
581 if (CN->isExactlyValue(+0.0)) {
582 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000583 } else if ( CN->isExactlyValue(-0.0)) {
584 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000585 } else {
586 abort();
587 }
588 }
589 return Result;
590
591 case ISD::MUL:
592 case ISD::ADD:
593 case ISD::SUB:
594 case ISD::SDIV:
595 switch( opcode ) {
596 case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break;
597 case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break;
598 case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break;
599 case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break;
600 };
601 Tmp1 = SelectExpr(N.getOperand(0));
602 Tmp2 = SelectExpr(N.getOperand(1));
603 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
604 return Result;
605
Andrew Lenharth2c594352005-01-29 15:42:07 +0000606 case ISD::EXTLOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000607 {
608 //include a conversion sequence for float loads to double
609 if (Result != notIn)
610 ExprMap[N.getValue(1)] = notIn; // Generate the token
611 else
612 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
613
Andrew Lenhartha549deb2005-02-07 05:33:15 +0000614 Tmp1 = MakeReg(MVT::f32);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000615
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000616 assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 &&
617 "EXTLOAD not from f32");
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000618 assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64");
619
620 SDOperand Chain = N.getOperand(0);
621 SDOperand Address = N.getOperand(1);
622 Select(Chain);
623
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000624 if (Address.getOpcode() == ISD::GlobalAddress) {
625 AlphaLowering.restoreGP(BB);
626 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
627 }
628 else if (ConstantPoolSDNode *CP =
629 dyn_cast<ConstantPoolSDNode>(N.getOperand(1)))
630 {
631 AlphaLowering.restoreGP(BB);
632 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex());
633 }
634 else if(Address.getOpcode() == ISD::FrameIndex) {
635 Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
Andrew Lenharth032f2352005-02-22 21:59:48 +0000636 BuildMI(BB, Alpha::LDS, 2, Tmp1)
637 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
638 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000639 } else {
640 long offset;
641 SelectAddr(Address, Tmp2, offset);
642 BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2);
643 }
Andrew Lenharth29219162005-02-07 06:31:44 +0000644 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000645 return Result;
646 }
Andrew Lenharth2c594352005-01-29 15:42:07 +0000647
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000648 case ISD::UINT_TO_FP:
649 case ISD::SINT_TO_FP:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000650 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000651 assert (N.getOperand(0).getValueType() == MVT::i64
652 && "only quads can be loaded from");
Andrew Lenharth40831c52005-01-28 06:57:18 +0000653 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000654 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000655
656 //The hard way:
657 // Spill the integer to memory and reload it from there.
658 unsigned Size = MVT::getSizeInBits(MVT::i64)/8;
659 MachineFunction *F = BB->getParent();
660 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, Size);
661
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000662 BuildMI(BB, Alpha::STQ, 3).addReg(Tmp1).addFrameIndex(FrameIdx).addReg(Alpha::F31);
663 BuildMI(BB, Alpha::LDT, 2, Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
664 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
665 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000666
667 //The easy way: doesn't work
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000668 // //so these instructions are not supported on ev56
669 // Opc = DestType == MVT::f64 ? Alpha::ITOFT : Alpha::ITOFS;
670 // BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp1);
671 // Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
672 // BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000673
Andrew Lenharth40831c52005-01-28 06:57:18 +0000674 return Result;
675 }
676 }
677 assert(0 && "should not get here");
678 return 0;
679}
680
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000681unsigned ISel::SelectExpr(SDOperand N) {
682 unsigned Result;
683 unsigned Tmp1, Tmp2, Tmp3;
684 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000685 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000686
687 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000688 MVT::ValueType DestType = N.getValueType();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000689
690 unsigned &Reg = ExprMap[N];
691 if (Reg) return Reg;
692
693 if (N.getOpcode() != ISD::CALL)
694 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000695 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000696 else {
697 // If this is a call instruction, make sure to prepare ALL of the result
698 // values as well as the chain.
699 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000700 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000701 else {
702 Result = MakeReg(Node->getValueType(0));
703 ExprMap[N.getValue(0)] = Result;
704 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
705 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000706 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000707 }
708 }
709
Andrew Lenharth22088bb2005-02-02 15:05:33 +0000710 if (DestType == MVT::f64 || DestType == MVT::f32 ||
Andrew Lenharth06342c32005-02-07 06:21:37 +0000711 (
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000712 (opcode == ISD::LOAD || opcode == ISD::CopyFromReg ||
713 opcode == ISD::EXTLOAD) &&
714 (N.getValue(0).getValueType() == MVT::f32 ||
715 N.getValue(0).getValueType() == MVT::f64)
Andrew Lenharth06342c32005-02-07 06:21:37 +0000716 )
717 )
Andrew Lenharth40831c52005-01-28 06:57:18 +0000718 return SelectExprFP(N, Result);
719
720 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000721 default:
722 Node->dump();
723 assert(0 && "Node not handled!\n");
724
Andrew Lenharth032f2352005-02-22 21:59:48 +0000725 case ISD::DYNAMIC_STACKALLOC:
726 // Generate both result values.
Andrew Lenharth3a7118d2005-02-23 17:33:42 +0000727 if (Result != notIn)
728 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth032f2352005-02-22 21:59:48 +0000729 else
730 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
731
732 // FIXME: We are currently ignoring the requested alignment for handling
733 // greater than the stack alignment. This will need to be revisited at some
734 // point. Align = N.getOperand(2);
735
736 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
737 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
738 std::cerr << "Cannot allocate stack object with greater alignment than"
739 << " the stack alignment yet!";
740 abort();
741 }
742
743 Select(N.getOperand(0));
744 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
745 {
746 if (CN->getValue() < 32000)
747 {
748 BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
749 .addImm(-CN->getValue()).addReg(Alpha::R30);
750 } else {
751 Tmp1 = SelectExpr(N.getOperand(1));
752 // Subtract size from stack pointer, thereby allocating some space.
753 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
754 }
755 } else {
756 Tmp1 = SelectExpr(N.getOperand(1));
757 // Subtract size from stack pointer, thereby allocating some space.
758 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
759 }
760
761 // Put a pointer to the space into the result register, by copying the stack
762 // pointer.
Andrew Lenharth7bc47022005-02-22 23:29:25 +0000763 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
Andrew Lenharth032f2352005-02-22 21:59:48 +0000764 return Result;
765
Andrew Lenharth2c594352005-01-29 15:42:07 +0000766 case ISD::ConstantPool:
767 Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
768 AlphaLowering.restoreGP(BB);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000769 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1);
Andrew Lenharth2c594352005-01-29 15:42:07 +0000770 return Result;
771
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000772 case ISD::FrameIndex:
Andrew Lenharth032f2352005-02-22 21:59:48 +0000773 BuildMI(BB, Alpha::LDA, 2, Result)
774 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
775 .addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000776 return Result;
777
778 case ISD::EXTLOAD:
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000779 case ISD::ZEXTLOAD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000780 case ISD::SEXTLOAD:
Andrew Lenhartha549deb2005-02-07 05:33:15 +0000781 case ISD::LOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000782 {
783 // Make sure we generate both values.
784 if (Result != notIn)
785 ExprMap[N.getValue(1)] = notIn; // Generate the token
786 else
787 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000788
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000789 SDOperand Chain = N.getOperand(0);
790 SDOperand Address = N.getOperand(1);
791 Select(Chain);
792
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000793 assert(Node->getValueType(0) == MVT::i64 &&
794 "Unknown type to sign extend to.");
Andrew Lenharth03824012005-02-07 05:55:55 +0000795 if (opcode == ISD::LOAD)
796 Opc = Alpha::LDQ;
797 else
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000798 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
799 default: Node->dump(); assert(0 && "Bad sign extend!");
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000800 case MVT::i32: Opc = Alpha::LDL;
801 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
802 case MVT::i16: Opc = Alpha::LDWU;
803 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000804 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000805 case MVT::i8: Opc = Alpha::LDBU;
806 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000807 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000808
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000809 if (Address.getOpcode() == ISD::GlobalAddress) {
810 AlphaLowering.restoreGP(BB);
811 Opc = GetSymVersion(Opc);
812 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
813 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000814 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
815 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +0000816 Opc = GetSymVersion(Opc);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000817 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000818 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000819 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000820 BuildMI(BB, Opc, 2, Result)
821 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
822 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000823 } else {
824 long offset;
825 SelectAddr(Address, Tmp1, offset);
826 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
827 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000828 return Result;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000829 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000830
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000831 case ISD::GlobalAddress:
832 AlphaLowering.restoreGP(BB);
833 BuildMI(BB, Alpha::LOAD_ADDR, 1, Result)
834 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal());
835 return Result;
836
837 case ISD::CALL:
838 {
839 Select(N.getOperand(0));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000840
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000841 // The chain for this call is now lowered.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000842 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000843
844 //grab the arguments
845 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000846 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000847 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000848 argvregs.push_back(SelectExpr(N.getOperand(i)));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000849
Andrew Lenharth684f2292005-01-30 00:35:27 +0000850 //in reg args
851 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000852 {
853 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
854 Alpha::R19, Alpha::R20, Alpha::R21};
855 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
856 Alpha::F19, Alpha::F20, Alpha::F21};
857 switch(N.getOperand(i+2).getValueType()) {
858 default:
859 Node->dump();
860 N.getOperand(i).Val->dump();
861 std::cerr << "Type for " << i << " is: " <<
862 N.getOperand(i+2).getValueType() << "\n";
863 assert(0 && "Unknown value type for call");
864 case MVT::i1:
865 case MVT::i8:
866 case MVT::i16:
867 case MVT::i32:
868 case MVT::i64:
869 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]);
870 break;
871 case MVT::f32:
872 case MVT::f64:
873 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]);
874 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000875 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000876 }
Andrew Lenharth684f2292005-01-30 00:35:27 +0000877 //in mem args
878 for (int i = 6, e = argvregs.size(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000879 {
880 switch(N.getOperand(i+2).getValueType()) {
881 default:
882 Node->dump();
883 N.getOperand(i).Val->dump();
884 std::cerr << "Type for " << i << " is: " <<
885 N.getOperand(i+2).getValueType() << "\n";
886 assert(0 && "Unknown value type for call");
887 case MVT::i1:
888 case MVT::i8:
889 case MVT::i16:
890 case MVT::i32:
891 case MVT::i64:
892 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
893 break;
894 case MVT::f32:
895 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
896 break;
897 case MVT::f64:
898 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
899 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000900 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000901 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000902 //build the right kind of call
903 if (GlobalAddressSDNode *GASD =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000904 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000905 {
Andrew Lenharth3e315922005-02-10 20:10:38 +0000906 //if (GASD->getGlobal()->isExternal()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000907 //use safe calling convention
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000908 AlphaLowering.restoreGP(BB);
909 BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true);
Andrew Lenharth3e315922005-02-10 20:10:38 +0000910 //} else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000911 //use PC relative branch call
Andrew Lenharth3e315922005-02-10 20:10:38 +0000912 //BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
913 //}
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000914 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000915 else if (ExternalSymbolSDNode *ESSDN =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000916 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000917 {
918 AlphaLowering.restoreGP(BB);
919 BuildMI(BB, Alpha::CALL, 0).addExternalSymbol(ESSDN->getSymbol(), true);
920 } else {
921 //no need to restore GP as we are doing an indirect call
922 Tmp1 = SelectExpr(N.getOperand(1));
923 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
924 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
925 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000926
927 //push the result into a virtual register
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000928
929 switch (Node->getValueType(0)) {
930 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000931 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000932 case MVT::i1:
933 case MVT::i8:
934 case MVT::i16:
935 case MVT::i32:
936 case MVT::i64:
937 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
938 break;
939 case MVT::f32:
940 case MVT::f64:
941 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
942 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000943 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000944 return Result+N.ResNo;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000945 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000946
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000947 case ISD::SIGN_EXTEND:
Andrew Lenharth3d65d312005-01-27 03:49:45 +0000948 abort();
949
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000950 case ISD::SIGN_EXTEND_INREG:
951 {
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000952 //Alpha has instructions for a bunch of signed 32 bit stuff
953 if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000954 {
955 switch (N.getOperand(0).getOpcode()) {
956 case ISD::ADD:
957 case ISD::SUB:
958 case ISD::MUL:
959 {
960 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
961 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
962 //FIXME: first check for Scaled Adds and Subs!
963 if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
964 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
965 { //Normal imm add/sub
966 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
Andrew Lenharth093f3272005-02-12 21:11:17 +0000967 //if the value was really originally a i32, skip the up conversion
968 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
969 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
970 ->getExtraValueType() == MVT::i32)
971 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
972 else
973 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000974 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
975 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000976 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000977 else
978 { //Normal add/sub
979 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULLi : Alpha::SUBL);
Andrew Lenharth093f3272005-02-12 21:11:17 +0000980 //if the value was really originally a i32, skip the up conversion
981 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
982 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
983 ->getExtraValueType() == MVT::i32)
984 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
985 else
986 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
987 //if the value was really originally a i32, skip the up conversion
988 if (N.getOperand(0).getOperand(1).getOpcode() == ISD::SIGN_EXTEND_INREG &&
989 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(1).Val)
990 ->getExtraValueType() == MVT::i32)
991 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
992 else
993 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
994
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000995 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
996 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
997 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
998 }
999 return Result;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001000 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001001 default: break; //Fall Though;
1002 }
1003 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001004 Tmp1 = SelectExpr(N.getOperand(0));
1005 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001006 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001007 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001008 {
1009 default:
1010 Node->dump();
1011 assert(0 && "Sign Extend InReg not there yet");
1012 break;
1013 case MVT::i32:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001014 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001015 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001016 break;
1017 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001018 case MVT::i16:
1019 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
1020 break;
1021 case MVT::i8:
1022 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
1023 break;
Andrew Lenharthebce5042005-02-12 19:35:12 +00001024 case MVT::i1:
1025 Tmp2 = MakeReg(MVT::i64);
1026 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
Andrew Lenharth7536eea2005-02-12 20:42:09 +00001027 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::F31).addReg(Tmp2);
Andrew Lenharthebce5042005-02-12 19:35:12 +00001028 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001029 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001030 return Result;
1031 }
1032 case ISD::ZERO_EXTEND_INREG:
1033 {
1034 Tmp1 = SelectExpr(N.getOperand(0));
1035 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001036 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001037 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001038 {
1039 default:
1040 Node->dump();
1041 assert(0 && "Zero Extend InReg not there yet");
1042 break;
1043 case MVT::i32: Tmp2 = 0xf0; break;
1044 case MVT::i16: Tmp2 = 0xfc; break;
1045 case MVT::i8: Tmp2 = 0xfe; break;
1046 case MVT::i1: //handle this one special
1047 BuildMI(BB, Alpha::ANDi, 2, Result).addReg(Tmp1).addImm(1);
1048 return Result;
1049 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001050 BuildMI(BB, Alpha::ZAPi, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001051 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001052 }
1053
1054 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001055 {
1056 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1057 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
1058 bool isConst1 = false;
1059 bool isConst2 = false;
1060 int dir;
Andrew Lenharth9818c052005-02-05 13:19:12 +00001061
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001062 //Tmp1 = SelectExpr(N.getOperand(0));
1063 if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001064 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255)
1065 isConst1 = true;
1066 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001067 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1068 isConst2 = true;
1069
1070 switch (SetCC->getCondition()) {
1071 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1072 case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001073 case ISD::SETLT:
1074 Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
1075 case ISD::SETLE:
1076 Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
1077 case ISD::SETGT:
1078 Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break;
1079 case ISD::SETGE:
1080 Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break;
1081 case ISD::SETULT:
1082 Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
1083 case ISD::SETUGT:
1084 Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break;
1085 case ISD::SETULE:
1086 Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
1087 case ISD::SETUGE:
1088 Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001089 case ISD::SETNE: {//Handle this one special
1090 //std::cerr << "Alpha does not have a setne.\n";
1091 //abort();
1092 Tmp1 = SelectExpr(N.getOperand(0));
1093 Tmp2 = SelectExpr(N.getOperand(1));
1094 Tmp3 = MakeReg(MVT::i64);
1095 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth445171a2005-02-08 00:40:03 +00001096 //Remeber we have the Inv for this CC
1097 CCInvMap[N] = Tmp3;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001098 //and invert
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001099 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001100 return Result;
1101 }
1102 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001103 if (dir == 1) {
1104 Tmp1 = SelectExpr(N.getOperand(0));
1105 if (isConst2) {
1106 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1107 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1108 } else {
1109 Tmp2 = SelectExpr(N.getOperand(1));
1110 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1111 }
1112 } else if (dir == 2) {
1113 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001114 if (isConst1) {
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001115 Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1116 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1117 } else {
1118 Tmp2 = SelectExpr(N.getOperand(0));
1119 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1120 }
1121 } else { //dir == 0
1122 if (isConst1) {
1123 Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1124 Tmp2 = SelectExpr(N.getOperand(1));
1125 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1);
1126 } else if (isConst2) {
1127 Tmp1 = SelectExpr(N.getOperand(0));
1128 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1129 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2);
1130 } else {
1131 Tmp1 = SelectExpr(N.getOperand(0));
1132 Tmp2 = SelectExpr(N.getOperand(1));
1133 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1134 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001135 }
1136 } else {
1137 //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted");
1138 bool rev = false;
1139 bool inv = false;
1140
1141 switch (SetCC->getCondition()) {
1142 default: Node->dump(); assert(0 && "Unknown FP comparison!");
1143 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
1144 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
1145 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
1146 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
1147 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
1148 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
1149 }
1150
1151 Tmp1 = SelectExpr(N.getOperand(0));
1152 Tmp2 = SelectExpr(N.getOperand(1));
1153 //Can only compare doubles, and dag won't promote for me
1154 if (SetCC->getOperand(0).getValueType() == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001155 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001156 //assert(0 && "Setcc On float?\n");
1157 std::cerr << "Setcc on float!\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001158 Tmp3 = MakeReg(MVT::f64);
1159 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
1160 Tmp1 = Tmp3;
1161 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001162 if (SetCC->getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001163 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001164 //assert (0 && "Setcc On float?\n");
1165 std::cerr << "Setcc on float!\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001166 Tmp3 = MakeReg(MVT::f64);
1167 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
Andrew Lenharth572af902005-02-14 05:41:43 +00001168 Tmp2 = Tmp3;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001169 }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001170
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001171 if (rev) std::swap(Tmp1, Tmp2);
1172 Tmp3 = MakeReg(MVT::f64);
1173 //do the comparison
1174 BuildMI(BB, Opc, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1175
1176 //now arrange for Result (int) to have a 1 or 0
1177
1178 // Spill the FP to memory and reload it from there.
1179 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1180 MachineFunction *F = BB->getParent();
1181 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
1182 unsigned Tmp4 = MakeReg(MVT::f64);
1183 BuildMI(BB, Alpha::CVTTQ, 1, Tmp4).addReg(Tmp3);
1184 BuildMI(BB, Alpha::STT, 3).addReg(Tmp4).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1185 unsigned Tmp5 = MakeReg(MVT::i64);
1186 BuildMI(BB, Alpha::LDQ, 2, Tmp5).addFrameIndex(FrameIdx).addReg(Alpha::F31);
Andrew Lenharth9818c052005-02-05 13:19:12 +00001187
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001188 //now, set result based on Tmp5
1189 //Set Tmp6 if fp cmp was false
1190 unsigned Tmp6 = MakeReg(MVT::i64);
1191 BuildMI(BB, Alpha::CMPEQ, 2, Tmp6).addReg(Tmp5).addReg(Alpha::R31);
1192 //and invert
1193 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp6).addReg(Alpha::R31);
1194
1195 }
1196 // else
1197 // {
1198 // Node->dump();
1199 // assert(0 && "Not a setcc in setcc");
1200 // }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001201 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001202 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001203 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001204
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001205 case ISD::CopyFromReg:
1206 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001207 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001208 if (Result != notIn)
1209 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +00001210 else
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001211 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth40831c52005-01-28 06:57:18 +00001212
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001213 SDOperand Chain = N.getOperand(0);
1214
1215 Select(Chain);
1216 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1217 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1218 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
1219 return Result;
1220 }
1221
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001222 //Most of the plain arithmetic and logic share the same form, and the same
1223 //constant immediate test
1224 case ISD::AND:
1225 case ISD::OR:
1226 case ISD::XOR:
1227 case ISD::SHL:
1228 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +00001229 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001230 case ISD::MUL:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001231 assert (DestType == MVT::i64 && "Only do arithmetic on i64s!");
1232 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001233 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001234 {
1235 switch(opcode) {
1236 case ISD::AND: Opc = Alpha::ANDi; break;
1237 case ISD::OR: Opc = Alpha::BISi; break;
1238 case ISD::XOR: Opc = Alpha::XORi; break;
1239 case ISD::SHL: Opc = Alpha::SLi; break;
1240 case ISD::SRL: Opc = Alpha::SRLi; break;
1241 case ISD::SRA: Opc = Alpha::SRAi; break;
1242 case ISD::MUL: Opc = Alpha::MULQi; break;
1243 };
1244 Tmp1 = SelectExpr(N.getOperand(0));
1245 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1246 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1247 } else {
1248 switch(opcode) {
1249 case ISD::AND: Opc = Alpha::AND; break;
1250 case ISD::OR: Opc = Alpha::BIS; break;
1251 case ISD::XOR: Opc = Alpha::XOR; break;
1252 case ISD::SHL: Opc = Alpha::SL; break;
1253 case ISD::SRL: Opc = Alpha::SRL; break;
1254 case ISD::SRA: Opc = Alpha::SRA; break;
1255 case ISD::MUL: Opc = Alpha::MULQ; break;
1256 };
1257 Tmp1 = SelectExpr(N.getOperand(0));
1258 Tmp2 = SelectExpr(N.getOperand(1));
1259 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1260 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001261 return Result;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001262
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001263 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001264 case ISD::SUB:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001265 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001266 bool isAdd = opcode == ISD::ADD;
1267
1268 //FIXME: first check for Scaled Adds and Subs!
1269 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001270 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001271 { //Normal imm add/sub
1272 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
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 }
Andrew Lenharth40831c52005-01-28 06:57:18 +00001277 else if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001278 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001279 { //LDA //FIXME: expand the above condition a bit
1280 Tmp1 = SelectExpr(N.getOperand(0));
1281 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1282 if (!isAdd)
1283 Tmp2 = -Tmp2;
1284 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
1285 } else {
1286 //Normal add/sub
1287 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1288 Tmp1 = SelectExpr(N.getOperand(0));
1289 Tmp2 = SelectExpr(N.getOperand(1));
1290 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1291 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001292 return Result;
1293 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001294
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001295 case ISD::UREM:
Andrew Lenharth02981182005-01-26 01:24:38 +00001296 case ISD::SREM:
1297 case ISD::SDIV:
1298 case ISD::UDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001299 //FIXME: alpha really doesn't support any of these operations,
1300 // the ops are expanded into special library calls with
1301 // special calling conventions
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001302 //Restore GP because it is a call after all...
Andrew Lenharth40831c52005-01-28 06:57:18 +00001303 switch(opcode) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001304 case ISD::UREM: AlphaLowering.restoreGP(BB); Opc = Alpha::REMQU; break;
1305 case ISD::SREM: AlphaLowering.restoreGP(BB); Opc = Alpha::REMQ; break;
1306 case ISD::UDIV: AlphaLowering.restoreGP(BB); Opc = Alpha::DIVQU; break;
1307 case ISD::SDIV: AlphaLowering.restoreGP(BB); Opc = Alpha::DIVQ; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001308 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001309 Tmp1 = SelectExpr(N.getOperand(0));
1310 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth02981182005-01-26 01:24:38 +00001311 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001312 return Result;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001313
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001314 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001315 case ISD::FP_TO_SINT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001316 {
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001317 assert (DestType == MVT::i64 && "only quads can be loaded to");
1318 MVT::ValueType SrcType = N.getOperand(0).getValueType();
Andrew Lenharth03824012005-02-07 05:55:55 +00001319 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001320 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
1321
1322 //The hard way:
1323 // Spill the integer to memory and reload it from there.
1324 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1325 MachineFunction *F = BB->getParent();
1326 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
1327
1328 //CVTTQ STT LDQ
1329 //CVTST CVTTQ STT LDQ
1330 if (SrcType == MVT::f32)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001331 {
1332 Tmp2 = MakeReg(MVT::f64);
1333 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
1334 Tmp1 = Tmp2;
1335 }
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001336 Tmp2 = MakeReg(MVT::f64);
1337 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
1338 BuildMI(BB, Alpha::STT, 3).addReg(Tmp2).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1339 BuildMI(BB, Alpha::LDQ, 2, Result).addFrameIndex(FrameIdx).addReg(Alpha::F31);
1340
1341 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001342 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001343
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001344 // // case ISD::FP_TO_UINT:
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001345
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001346 case ISD::SELECT:
1347 {
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001348 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001349 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1350 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001351 // Get the condition into the zero flag.
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001352 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001353 return Result;
1354 }
1355
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001356 case ISD::Constant:
1357 {
Andrew Lenharth22d5a412005-02-02 00:51:15 +00001358 unsigned long val = cast<ConstantSDNode>(N)->getValue();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001359 if (val < 32000 && (long)val > -32000)
1360 BuildMI(BB, Alpha::LOAD_IMM, 1, Result).addImm(val);
1361 else {
1362 MachineConstantPool *CP = BB->getParent()->getConstantPool();
1363 ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
1364 unsigned CPI = CP->getConstantPoolIndex(C);
1365 AlphaLowering.restoreGP(BB);
1366 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI);
1367 }
1368 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001369 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001370 }
1371
1372 return 0;
1373}
1374
1375void ISel::Select(SDOperand N) {
1376 unsigned Tmp1, Tmp2, Opc;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001377 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001378
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001379 // FIXME: Disable for our current expansion model!
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001380 if (/*!N->hasOneUse() &&*/ !ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001381 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001382
1383 SDNode *Node = N.Val;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001384
Andrew Lenharth760270d2005-02-07 23:02:23 +00001385 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001386
1387 default:
1388 Node->dump(); std::cerr << "\n";
1389 assert(0 && "Node not handled yet!");
1390
1391 case ISD::BRCOND: {
Andrew Lenharth445171a2005-02-08 00:40:03 +00001392 SelectBranchCC(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001393 return;
1394 }
1395
1396 case ISD::BR: {
1397 MachineBasicBlock *Dest =
1398 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1399
1400 Select(N.getOperand(0));
1401 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
1402 return;
1403 }
1404
1405 case ISD::ImplicitDef:
1406 Select(N.getOperand(0));
1407 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
1408 return;
1409
1410 case ISD::EntryToken: return; // Noop
1411
1412 case ISD::TokenFactor:
1413 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1414 Select(Node->getOperand(i));
1415
1416 //N.Val->dump(); std::cerr << "\n";
1417 //assert(0 && "Node not handled yet!");
1418
1419 return;
1420
1421 case ISD::CopyToReg:
1422 Select(N.getOperand(0));
1423 Tmp1 = SelectExpr(N.getOperand(1));
1424 Tmp2 = cast<RegSDNode>(N)->getReg();
1425
1426 if (Tmp1 != Tmp2) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001427 if (N.getOperand(1).getValueType() == MVT::f64 ||
1428 N.getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth29219162005-02-07 06:31:44 +00001429 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1430 else
1431 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001432 }
1433 return;
1434
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001435 case ISD::RET:
1436 switch (N.getNumOperands()) {
1437 default:
1438 std::cerr << N.getNumOperands() << "\n";
1439 for (unsigned i = 0; i < N.getNumOperands(); ++i)
1440 std::cerr << N.getOperand(i).getValueType() << "\n";
1441 Node->dump();
1442 assert(0 && "Unknown return instruction!");
1443 case 2:
1444 Select(N.getOperand(0));
1445 Tmp1 = SelectExpr(N.getOperand(1));
1446 switch (N.getOperand(1).getValueType()) {
1447 default: Node->dump();
1448 assert(0 && "All other types should have been promoted!!");
1449 case MVT::f64:
1450 case MVT::f32:
1451 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
1452 break;
1453 case MVT::i32:
1454 case MVT::i64:
1455 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
1456 break;
1457 }
1458 break;
1459 case 1:
1460 Select(N.getOperand(0));
1461 break;
1462 }
1463 //Tmp2 = AlphaLowering.getRetAddr();
1464 //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2);
1465 BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction
1466 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001467
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001468 case ISD::TRUNCSTORE:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001469 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001470 {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001471 SDOperand Chain = N.getOperand(0);
1472 SDOperand Value = N.getOperand(1);
1473 SDOperand Address = N.getOperand(2);
1474 Select(Chain);
1475
1476 Tmp1 = SelectExpr(Value); //value
Andrew Lenharth760270d2005-02-07 23:02:23 +00001477
1478 if (opcode == ISD::STORE) {
1479 switch(Value.getValueType()) {
1480 default: assert(0 && "unknown Type in store");
1481 case MVT::i64: Opc = Alpha::STQ; break;
1482 case MVT::f64: Opc = Alpha::STT; break;
1483 case MVT::f32: Opc = Alpha::STS; break;
1484 }
1485 } else { //ISD::TRUNCSTORE
1486 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1487 default: assert(0 && "unknown Type in store");
1488 case MVT::i1: //FIXME: DAG does not promote this load
1489 case MVT::i8: Opc = Alpha::STB; break;
1490 case MVT::i16: Opc = Alpha::STW; break;
1491 case MVT::i32: Opc = Alpha::STL; break;
1492 }
Andrew Lenharth65838902005-02-06 16:22:15 +00001493 }
Andrew Lenharth760270d2005-02-07 23:02:23 +00001494
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001495 if (Address.getOpcode() == ISD::GlobalAddress)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001496 {
1497 AlphaLowering.restoreGP(BB);
1498 Opc = GetSymVersion(Opc);
1499 BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1500 }
Andrew Lenharth05380342005-02-07 05:07:00 +00001501 else if(Address.getOpcode() == ISD::FrameIndex)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001502 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001503 BuildMI(BB, Opc, 3).addReg(Tmp1)
1504 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1505 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001506 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001507 else
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001508 {
1509 long offset;
1510 SelectAddr(Address, Tmp2, offset);
1511 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1512 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001513 return;
1514 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001515
1516 case ISD::EXTLOAD:
1517 case ISD::SEXTLOAD:
1518 case ISD::ZEXTLOAD:
1519 case ISD::LOAD:
1520 case ISD::CopyFromReg:
1521 case ISD::CALL:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001522 case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001523 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001524 SelectExpr(N);
1525 return;
1526
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001527 case ISD::ADJCALLSTACKDOWN:
1528 case ISD::ADJCALLSTACKUP:
1529 Select(N.getOperand(0));
1530 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1531
1532 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? Alpha::ADJUSTSTACKDOWN :
1533 Alpha::ADJUSTSTACKUP;
1534 BuildMI(BB, Opc, 1).addImm(Tmp1);
1535 return;
1536 }
1537 assert(0 && "Should not be reached!");
1538}
1539
1540
1541/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
1542/// into a machine code representation using pattern matching and a machine
1543/// description file.
1544///
1545FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
1546 return new ISel(TM);
1547}