blob: f14b56bd89157c130b4eadf4f89ee963812a97c9 [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 Lenharth95762122005-03-31 21:24:06 +000030#include "llvm/Support/CommandLine.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000031#include <set>
Andrew Lenharth684f2292005-01-30 00:35:27 +000032#include <algorithm>
Andrew Lenharth304d0f32005-01-22 23:41:55 +000033using namespace llvm;
34
Andrew Lenharth95762122005-03-31 21:24:06 +000035namespace llvm {
36 cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
37 cl::desc("Use the FP div instruction for integer div when possible"),
38 cl::Hidden);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +000039 cl::opt<bool> EnableAlphaFTOI("enable-alpha-ftoi",
Andrew Lenharth5e99dd92005-03-31 22:02:25 +000040 cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"),
Andrew Lenharth95762122005-03-31 21:24:06 +000041 cl::Hidden);
42}
43
Andrew Lenharth304d0f32005-01-22 23:41:55 +000044//===----------------------------------------------------------------------===//
45// AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
46namespace {
47 class AlphaTargetLowering : public TargetLowering {
48 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
49 unsigned GP; //GOT vreg
50 public:
51 AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
52 // Set up the TargetLowering object.
Andrew Lenharth3d65d312005-01-27 03:49:45 +000053 //I am having problems with shr n ubyte 1
Andrew Lenharth879ef222005-02-02 17:00:21 +000054 setShiftAmountType(MVT::i64);
55 setSetCCResultType(MVT::i64);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000056
Andrew Lenharth304d0f32005-01-22 23:41:55 +000057 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
58 addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000059 addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000060
Andrew Lenharthd2bb9602005-01-27 07:50:35 +000061 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
Andrew Lenharth33819132005-03-04 20:09:23 +000062 setOperationAction(ISD::EXTLOAD , MVT::f32 , Promote);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000063
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000064 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000065 setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000066
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +000067 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000068 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
69 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
70
Andrew Lenharth9818c052005-02-05 13:19:12 +000071 setOperationAction(ISD::SREM , MVT::f32 , Expand);
72 setOperationAction(ISD::SREM , MVT::f64 , Expand);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +000073
Andrew Lenharth8d163d22005-02-02 05:49:42 +000074 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
Andrew Lenharth9818c052005-02-05 13:19:12 +000075 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
76 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
77
Andrew Lenharth33819132005-03-04 20:09:23 +000078 //Doesn't work yet
Andrew Lenharth572af902005-02-14 05:41:43 +000079 setOperationAction(ISD::SETCC , MVT::f32, Promote);
80
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000081 computeRegisterProperties();
Andrew Lenharth304d0f32005-01-22 23:41:55 +000082
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000083 addLegalFPImmediate(+0.0); //F31
84 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth304d0f32005-01-22 23:41:55 +000085 }
86
87 /// LowerArguments - This hook must be implemented to indicate how we should
88 /// lower the arguments for the specified function, into the specified DAG.
89 virtual std::vector<SDOperand>
90 LowerArguments(Function &F, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000091
Andrew Lenharth304d0f32005-01-22 23:41:55 +000092 /// LowerCallTo - This hook lowers an abstract call to a function into an
93 /// actual call.
94 virtual std::pair<SDOperand, SDOperand>
Nate Begeman8e21e712005-03-26 01:29:23 +000095 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
96 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000097
Andrew Lenharth304d0f32005-01-22 23:41:55 +000098 virtual std::pair<SDOperand, SDOperand>
99 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000100
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000101 virtual std::pair<SDOperand,SDOperand>
102 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
103 const Type *ArgTy, SelectionDAG &DAG);
104
105 virtual std::pair<SDOperand, SDOperand>
106 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
107 SelectionDAG &DAG);
108
109 void restoreGP(MachineBasicBlock* BB)
110 {
111 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
112 }
113 };
114}
115
116//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
117
118//For now, just use variable size stack frame format
119
120//In a standard call, the first six items are passed in registers $16
121//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
122//of argument-to-register correspondence.) The remaining items are
123//collected in a memory argument list that is a naturally aligned
124//array of quadwords. In a standard call, this list, if present, must
125//be passed at 0(SP).
126//7 ... n 0(SP) ... (n-7)*8(SP)
127
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000128// //#define FP $15
129// //#define RA $26
130// //#define PV $27
131// //#define GP $29
132// //#define SP $30
133
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000134std::vector<SDOperand>
135AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
136{
137 std::vector<SDOperand> ArgValues;
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000138 std::vector<SDOperand> LS;
139 SDOperand Chain = DAG.getRoot();
140
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000141 // assert(0 && "TODO");
142 MachineFunction &MF = DAG.getMachineFunction();
Andrew Lenharth05380342005-02-07 05:07:00 +0000143 MachineFrameInfo*MFI = MF.getFrameInfo();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000144
145 GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
146 MachineBasicBlock& BB = MF.front();
147
148 //Handle the return address
149 //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26);
150
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000151 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
152 Alpha::R19, Alpha::R20, Alpha::R21};
153 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
154 Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000155 int count = 0;
Andrew Lenharth2c9e38c2005-02-06 21:07:31 +0000156
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000157 //Def incoming registers
158 {
159 Function::arg_iterator I = F.arg_begin();
160 Function::arg_iterator E = F.arg_end();
161 for (int i = 0; i < 6; ++i)
162 {
163 if (F.isVarArg()) {
164 BuildMI(&BB, Alpha::IDEF, 0, args_int[i]);
165 BuildMI(&BB, Alpha::IDEF, 0, args_float[i]);
166 } else if (I != E)
167 {
168 if(MVT::isInteger(getValueType(I->getType())))
169 BuildMI(&BB, Alpha::IDEF, 0, args_int[i]);
170 else
171 BuildMI(&BB, Alpha::IDEF, 0, args_float[i]);
172 ++I;
173 }
174 }
175 }
176
177 BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29);
178 BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29);
179
Chris Lattnere4d5c442005-03-15 04:54:21 +0000180 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000181 {
182 SDOperand newroot, argt;
183 if (count < 6) {
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000184 unsigned Vreg;
185 MVT::ValueType VT = getValueType(I->getType());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000186 switch (getValueType(I->getType())) {
187 default:
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000188 std::cerr << "Unknown Type " << VT << "\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000189 abort();
190 case MVT::f64:
191 case MVT::f32:
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000192 Vreg = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(VT));
193 BuildMI(&BB, Alpha::CPYS, 2, Vreg).addReg(args_float[count]).addReg(args_float[count]);
194 argt = newroot = DAG.getCopyFromReg(Vreg,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000195 getValueType(I->getType()),
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000196 Chain);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000197 break;
198 case MVT::i1:
199 case MVT::i8:
200 case MVT::i16:
201 case MVT::i32:
202 case MVT::i64:
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000203 Vreg = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
204 BuildMI(&BB, Alpha::BIS, 2, Vreg).addReg(args_int[count]).addReg(args_int[count]);
205 argt = newroot = DAG.getCopyFromReg(Vreg, MVT::i64, Chain);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000206 if (getValueType(I->getType()) != MVT::i64)
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000207 argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000208 break;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000209 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000210 } else { //more args
211 // Create the frame index object for this incoming parameter...
212 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
213
214 // Create the SelectionDAG nodes corresponding to a load
215 //from this parameter
216 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
217 argt = newroot = DAG.getLoad(getValueType(I->getType()),
218 DAG.getEntryNode(), FIN);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000219 }
Andrew Lenharth032f2352005-02-22 21:59:48 +0000220 ++count;
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000221 LS.push_back(newroot.getValue(1));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000222 ArgValues.push_back(argt);
223 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000224
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000225 // If the functions takes variable number of arguments, copy all regs to stack
226 if (F.isVarArg())
227 for (int i = 0; i < 6; ++i)
228 {
229 unsigned Vreg = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
230 BuildMI(&BB, Alpha::BIS, 2, Vreg).addReg(args_int[i]).addReg(args_int[i]);
231 SDOperand argt = DAG.getCopyFromReg(Vreg, MVT::i64, Chain);
232 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
233 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
234 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, argt, SDFI));
235
236 Vreg = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::f64));
237 BuildMI(&BB, Alpha::CPYS, 2, Vreg).addReg(args_float[i]).addReg(args_float[i]);
238 argt = DAG.getCopyFromReg(Vreg, MVT::f64, Chain);
239 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
240 SDFI = DAG.getFrameIndex(FI, MVT::i64);
241 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, argt, SDFI));
242 }
243
244 // If the function takes variable number of arguments, make a frame index for
245 // the start of the first arg value... for expansion of llvm.va_start.
246 // if (F.isVarArg())
247 // VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
248
249 //Set up a token factor with all the stack traffic
250 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
251 //return the arguments
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000252 return ArgValues;
253}
254
255std::pair<SDOperand, SDOperand>
256AlphaTargetLowering::LowerCallTo(SDOperand Chain,
Nate Begeman8e21e712005-03-26 01:29:23 +0000257 const Type *RetTy, bool isVarArg,
258 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000259 int NumBytes = 0;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000260 if (Args.size() > 6)
261 NumBytes = (Args.size() - 6) * 8;
262
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000263 Chain = DAG.getNode(ISD::ADJCALLSTACKDOWN, MVT::Other, Chain,
264 DAG.getConstant(NumBytes, getPointerTy()));
265 std::vector<SDOperand> args_to_use;
266 for (unsigned i = 0, e = Args.size(); i != e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000267 {
268 switch (getValueType(Args[i].second)) {
269 default: assert(0 && "Unexpected ValueType for argument!");
270 case MVT::i1:
271 case MVT::i8:
272 case MVT::i16:
273 case MVT::i32:
274 // Promote the integer to 64 bits. If the input type is signed use a
275 // sign extend, otherwise use a zero extend.
276 if (Args[i].second->isSigned())
277 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
278 else
279 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
280 break;
281 case MVT::i64:
282 case MVT::f64:
283 case MVT::f32:
284 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000285 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000286 args_to_use.push_back(Args[i].first);
287 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000288
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000289 std::vector<MVT::ValueType> RetVals;
290 MVT::ValueType RetTyVT = getValueType(RetTy);
291 if (RetTyVT != MVT::isVoid)
292 RetVals.push_back(RetTyVT);
293 RetVals.push_back(MVT::Other);
294
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000295 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
296 Chain, Callee, args_to_use), 0);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000297 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
298 Chain = DAG.getNode(ISD::ADJCALLSTACKUP, MVT::Other, Chain,
299 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000300 return std::make_pair(TheCall, Chain);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000301}
302
303std::pair<SDOperand, SDOperand>
304AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
305 //vastart just returns the address of the VarArgsFrameIndex slot.
306 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
307}
308
309std::pair<SDOperand,SDOperand> AlphaTargetLowering::
310LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000311 const Type *ArgTy, SelectionDAG &DAG) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000312 abort();
313}
314
315
316std::pair<SDOperand, SDOperand> AlphaTargetLowering::
317LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
318 SelectionDAG &DAG) {
319 abort();
320}
321
322
323
324
325
326namespace {
327
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000328//===--------------------------------------------------------------------===//
329/// ISel - Alpha specific code to select Alpha machine instructions for
330/// SelectionDAG operations.
331//===--------------------------------------------------------------------===//
332class ISel : public SelectionDAGISel {
333
334 /// AlphaLowering - This object fully describes how to lower LLVM code to an
335 /// Alpha-specific SelectionDAG.
336 AlphaTargetLowering AlphaLowering;
337
338
339 /// ExprMap - As shared expressions are codegen'd, we keep track of which
340 /// vreg the value is produced in, so we only emit one copy of each compiled
341 /// tree.
342 static const unsigned notIn = (unsigned)(-1);
343 std::map<SDOperand, unsigned> ExprMap;
344
345 //CCInvMap sometimes (SetNE) we have the inverse CC code for free
346 std::map<SDOperand, unsigned> CCInvMap;
347
348public:
349 ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
350 {}
351
352 /// InstructionSelectBasicBlock - This callback is invoked by
353 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
354 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000355 DEBUG(BB->dump());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000356 // Codegen the basic block.
357 Select(DAG.getRoot());
358
359 // Clear state used for selection.
360 ExprMap.clear();
361 CCInvMap.clear();
362 }
363
364 unsigned SelectExpr(SDOperand N);
365 unsigned SelectExprFP(SDOperand N, unsigned Result);
366 void Select(SDOperand N);
367
368 void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
369 void SelectBranchCC(SDOperand N);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000370 void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
371 void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000372 //returns whether the sense of the comparison was inverted
373 bool SelectFPSetCC(SDOperand N, unsigned dst);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000374};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000375}
376
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000377//These describe LDAx
Andrew Lenharthc0513832005-03-29 19:24:04 +0000378static const int IMM_LOW = -32768;
379static const int IMM_HIGH = 32767;
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000380static const int IMM_MULT = 65536;
381
382static long getUpper16(long l)
383{
384 long y = l / IMM_MULT;
385 if (l % IMM_MULT > IMM_HIGH)
386 ++y;
387 return y;
388}
389
390static long getLower16(long l)
391{
392 long h = getUpper16(l);
393 return l - h * IMM_MULT;
394}
395
Andrew Lenharth65838902005-02-06 16:22:15 +0000396static unsigned GetSymVersion(unsigned opcode)
397{
398 switch (opcode) {
399 default: assert(0 && "unknown load or store"); return 0;
400 case Alpha::LDQ: return Alpha::LDQ_SYM;
401 case Alpha::LDS: return Alpha::LDS_SYM;
402 case Alpha::LDT: return Alpha::LDT_SYM;
403 case Alpha::LDL: return Alpha::LDL_SYM;
404 case Alpha::LDBU: return Alpha::LDBU_SYM;
405 case Alpha::LDWU: return Alpha::LDWU_SYM;
406 case Alpha::LDW: return Alpha::LDW_SYM;
407 case Alpha::LDB: return Alpha::LDB_SYM;
408 case Alpha::STQ: return Alpha::STQ_SYM;
409 case Alpha::STS: return Alpha::STS_SYM;
410 case Alpha::STT: return Alpha::STT_SYM;
411 case Alpha::STL: return Alpha::STL_SYM;
412 case Alpha::STW: return Alpha::STW_SYM;
413 case Alpha::STB: return Alpha::STB_SYM;
414 }
415}
416
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000417void ISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
418{
419 unsigned Opc;
420 if (EnableAlphaFTOI) {
421 Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
422 BuildMI(BB, Opc, 1, dst).addReg(src);
423 } else {
424 //The hard way:
425 // Spill the integer to memory and reload it from there.
426 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
427 MachineFunction *F = BB->getParent();
428 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
429
430 Opc = isDouble ? Alpha::STT : Alpha::STS;
431 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
432 Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
433 BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
434 }
435}
436
437void ISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
438{
439 unsigned Opc;
440 if (EnableAlphaFTOI) {
441 Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
442 BuildMI(BB, Opc, 1, dst).addReg(src);
443 } else {
444 //The hard way:
445 // Spill the integer to memory and reload it from there.
446 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
447 MachineFunction *F = BB->getParent();
448 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
449
450 Opc = isDouble ? Alpha::STQ : Alpha::STL;
451 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
452 Opc = isDouble ? Alpha::LDT : Alpha::LDS;
453 BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
454 }
455}
456
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000457bool ISel::SelectFPSetCC(SDOperand N, unsigned dst)
458{
459 SDNode *Node = N.Val;
460 unsigned Opc, Tmp1, Tmp2, Tmp3;
461 SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node);
462
463 //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted");
464 bool rev = false;
465 bool inv = false;
466
467 switch (SetCC->getCondition()) {
468 default: Node->dump(); assert(0 && "Unknown FP comparison!");
469 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
470 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
471 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
472 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
473 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
474 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
475 }
476
477 //FIXME: check for constant 0.0
478 ConstantFPSDNode *CN;
479 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
480 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
481 Tmp1 = Alpha::F31;
482 else
483 Tmp1 = SelectExpr(N.getOperand(0));
484
485 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
486 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
487 Tmp2 = Alpha::F31;
488 else
489 Tmp2 = SelectExpr(N.getOperand(1));
490
491 //Can only compare doubles, and dag won't promote for me
492 if (SetCC->getOperand(0).getValueType() == MVT::f32)
493 {
494 //assert(0 && "Setcc On float?\n");
495 std::cerr << "Setcc on float!\n";
496 Tmp3 = MakeReg(MVT::f64);
497 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
498 Tmp1 = Tmp3;
499 }
500 if (SetCC->getOperand(1).getValueType() == MVT::f32)
501 {
502 //assert (0 && "Setcc On float?\n");
503 std::cerr << "Setcc on float!\n";
504 Tmp3 = MakeReg(MVT::f64);
505 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
506 Tmp2 = Tmp3;
507 }
508
509 if (rev) std::swap(Tmp1, Tmp2);
510 //do the comparison
511 BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
512 return inv;
513}
514
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000515//Check to see if the load is a constant offset from a base register
516void ISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
517{
518 unsigned opcode = N.getOpcode();
519 if (opcode == ISD::ADD) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000520 if(N.getOperand(1).getOpcode() == ISD::Constant &&
521 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
522 { //Normal imm add
523 Reg = SelectExpr(N.getOperand(0));
524 offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
525 return;
526 }
527 else if(N.getOperand(0).getOpcode() == ISD::Constant &&
528 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767)
529 {
530 Reg = SelectExpr(N.getOperand(1));
531 offset = cast<ConstantSDNode>(N.getOperand(0))->getValue();
532 return;
533 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000534 }
535 Reg = SelectExpr(N);
536 offset = 0;
537 return;
538}
539
Andrew Lenharth445171a2005-02-08 00:40:03 +0000540void ISel::SelectBranchCC(SDOperand N)
541{
542 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000543 MachineBasicBlock *Dest =
544 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
545 unsigned Opc = Alpha::WTF;
546
Andrew Lenharth445171a2005-02-08 00:40:03 +0000547 Select(N.getOperand(0)); //chain
548 SDOperand CC = N.getOperand(1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000549
Andrew Lenharth445171a2005-02-08 00:40:03 +0000550 if (CC.getOpcode() == ISD::SETCC)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000551 {
552 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
553 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
554 //Dropping the CC is only useful if we are comparing to 0
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000555 bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
556 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
557 bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
558 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000559 bool isNE = false;
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000560
561 //Fix up CC
562 ISD::CondCode cCode= SetCC->getCondition();
563 if (LeftZero && !RightZero) //Swap Operands
564 cCode = ISD::getSetCCSwappedOperands(cCode);
565
566 if(cCode == ISD::SETNE)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000567 isNE = true;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000568
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000569 if (LeftZero || RightZero) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000570 switch (SetCC->getCondition()) {
571 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
572 case ISD::SETEQ: Opc = Alpha::BEQ; break;
573 case ISD::SETLT: Opc = Alpha::BLT; break;
574 case ISD::SETLE: Opc = Alpha::BLE; break;
575 case ISD::SETGT: Opc = Alpha::BGT; break;
576 case ISD::SETGE: Opc = Alpha::BGE; break;
577 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
578 case ISD::SETUGT: Opc = Alpha::BNE; break;
579 case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC
580 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
581 case ISD::SETNE: Opc = Alpha::BNE; break;
582 }
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000583 unsigned Tmp1;
584 if(LeftZero && !RightZero) //swap Operands
585 Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond
586 else
587 Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000588 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
589 return;
590 } else {
591 unsigned Tmp1 = SelectExpr(CC);
592 if (isNE)
593 BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
594 else
595 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000596 return;
597 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000598 } else { //FP
599 //Any comparison between 2 values should be codegened as an folded branch, as moving
600 //CC to the integer register is very expensive
601 //for a cmp b: c = a - b;
602 //a = b: c = 0
603 //a < b: c < 0
604 //a > b: c > 0
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000605
606 bool invTest = false;
607 unsigned Tmp3;
608
609 ConstantFPSDNode *CN;
610 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
611 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
612 Tmp3 = SelectExpr(SetCC->getOperand(0));
613 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
614 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
615 {
616 Tmp3 = SelectExpr(SetCC->getOperand(1));
617 invTest = true;
618 }
619 else
620 {
621 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
622 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
623 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
624 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
625 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
626 .addReg(Tmp1).addReg(Tmp2);
627 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000628
629 switch (SetCC->getCondition()) {
630 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000631 case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
632 case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
633 case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
634 case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
635 case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
636 case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000637 }
638 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000639 return;
640 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000641 abort(); //Should never be reached
642 } else {
643 //Giveup and do the stupid thing
644 unsigned Tmp1 = SelectExpr(CC);
645 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
646 return;
647 }
Andrew Lenharth445171a2005-02-08 00:40:03 +0000648 abort(); //Should never be reached
649}
650
Andrew Lenharth40831c52005-01-28 06:57:18 +0000651unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
652{
653 unsigned Tmp1, Tmp2, Tmp3;
654 unsigned Opc = 0;
655 SDNode *Node = N.Val;
656 MVT::ValueType DestType = N.getValueType();
657 unsigned opcode = N.getOpcode();
658
659 switch (opcode) {
660 default:
661 Node->dump();
662 assert(0 && "Node not handled!\n");
Andrew Lenharth2c594352005-01-29 15:42:07 +0000663
Andrew Lenharth7332f3e2005-04-02 19:11:07 +0000664 case ISD::UNDEF: {
665 BuildMI(BB, Alpha::IDEF, 0, Result);
666 return Result;
667 }
668
Andrew Lenharth30b46d42005-04-02 19:04:58 +0000669 case ISD::FNEG:
670 if(ISD::FABS == N.getOperand(0).getOpcode())
671 {
672 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth7332f3e2005-04-02 19:11:07 +0000673 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharth30b46d42005-04-02 19:04:58 +0000674 } else {
675 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth7332f3e2005-04-02 19:11:07 +0000676 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth30b46d42005-04-02 19:04:58 +0000677 }
678 return Result;
679
680 case ISD::FABS:
681 Tmp1 = SelectExpr(N.getOperand(0));
682 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
683 return Result;
684
Andrew Lenharth9818c052005-02-05 13:19:12 +0000685 case ISD::SELECT:
686 {
Andrew Lenharth45859692005-03-03 21:47:53 +0000687 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
688 unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE
689 unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE
690
691 SDOperand CC = N.getOperand(0);
692 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
693
694 if (CC.getOpcode() == ISD::SETCC &&
695 !MVT::isInteger(SetCC->getOperand(0).getValueType()))
696 { //FP Setcc -> Select yay!
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000697
698
Andrew Lenharth45859692005-03-03 21:47:53 +0000699 //for a cmp b: c = a - b;
700 //a = b: c = 0
701 //a < b: c < 0
702 //a > b: c > 0
703
704 bool invTest = false;
705 unsigned Tmp3;
706
707 ConstantFPSDNode *CN;
708 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
709 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
710 Tmp3 = SelectExpr(SetCC->getOperand(0));
711 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
712 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
713 {
714 Tmp3 = SelectExpr(SetCC->getOperand(1));
715 invTest = true;
716 }
717 else
718 {
719 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
720 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
721 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
722 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
723 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
724 .addReg(Tmp1).addReg(Tmp2);
725 }
726
727 switch (SetCC->getCondition()) {
728 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
729 case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break;
730 case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break;
731 case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break;
732 case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break;
733 case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break;
734 case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break;
735 }
Andrew Lenharth33819132005-03-04 20:09:23 +0000736 BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3);
Andrew Lenharth45859692005-03-03 21:47:53 +0000737 return Result;
738 }
739 else
740 {
741 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000742 BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV).addReg(Tmp1);
743// // Spill the cond to memory and reload it from there.
744// unsigned Tmp4 = MakeReg(MVT::f64);
745// MoveIntFP(Tmp1, Tmp4, true);
746// //now ideally, we don't have to do anything to the flag...
747// // Get the condition into the zero flag.
748// BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4);
Andrew Lenharth45859692005-03-03 21:47:53 +0000749 return Result;
750 }
Andrew Lenharth9818c052005-02-05 13:19:12 +0000751 }
752
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000753 case ISD::FP_ROUND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000754 assert (DestType == MVT::f32 &&
755 N.getOperand(0).getValueType() == MVT::f64 &&
756 "only f64 to f32 conversion supported here");
Andrew Lenharthc1faced2005-02-01 01:37:24 +0000757 Tmp1 = SelectExpr(N.getOperand(0));
758 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
759 return Result;
760
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000761 case ISD::FP_EXTEND:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000762 assert (DestType == MVT::f64 &&
763 N.getOperand(0).getValueType() == MVT::f32 &&
764 "only f32 to f64 conversion supported here");
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000765 Tmp1 = SelectExpr(N.getOperand(0));
766 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
767 return Result;
768
Andrew Lenharth2c594352005-01-29 15:42:07 +0000769 case ISD::CopyFromReg:
770 {
771 // Make sure we generate both values.
772 if (Result != notIn)
773 ExprMap[N.getValue(1)] = notIn; // Generate the token
774 else
775 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
776
777 SDOperand Chain = N.getOperand(0);
778
779 Select(Chain);
780 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
781 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
782 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
783 return Result;
784 }
785
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000786 case ISD::LOAD:
787 {
788 // Make sure we generate both values.
789 if (Result != notIn)
790 ExprMap[N.getValue(1)] = notIn; // Generate the token
791 else
792 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000793
Andrew Lenharth29219162005-02-07 06:31:44 +0000794 DestType = N.getValue(0).getValueType();
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000795
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000796 SDOperand Chain = N.getOperand(0);
797 SDOperand Address = N.getOperand(1);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000798 Select(Chain);
Andrew Lenharth65838902005-02-06 16:22:15 +0000799 Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS;
800
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000801 if (Address.getOpcode() == ISD::GlobalAddress) {
802 AlphaLowering.restoreGP(BB);
803 Opc = GetSymVersion(Opc);
804 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
805 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000806 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +0000807 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +0000808 Opc = GetSymVersion(Opc);
Andrew Lenharth97127a12005-02-05 17:41:39 +0000809 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000810 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000811 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000812 BuildMI(BB, Opc, 2, Result)
813 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
814 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000815 } else {
816 long offset;
817 SelectAddr(Address, Tmp1, offset);
818 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
819 }
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000820 return Result;
821 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000822 case ISD::ConstantFP:
823 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
824 if (CN->isExactlyValue(+0.0)) {
825 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000826 } else if ( CN->isExactlyValue(-0.0)) {
827 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000828 } else {
829 abort();
830 }
831 }
832 return Result;
833
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +0000834 case ISD::SDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000835 case ISD::MUL:
836 case ISD::ADD:
837 case ISD::SUB:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000838 switch( opcode ) {
839 case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break;
840 case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break;
841 case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break;
842 case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break;
843 };
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000844
845 ConstantFPSDNode *CN;
846 if (opcode == ISD::SUB
847 && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
848 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
849 {
850 Tmp2 = SelectExpr(N.getOperand(1));
851 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
852 } else {
853 Tmp1 = SelectExpr(N.getOperand(0));
854 Tmp2 = SelectExpr(N.getOperand(1));
855 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
856 }
Andrew Lenharth40831c52005-01-28 06:57:18 +0000857 return Result;
858
Andrew Lenharth2c594352005-01-29 15:42:07 +0000859 case ISD::EXTLOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000860 {
861 //include a conversion sequence for float loads to double
862 if (Result != notIn)
863 ExprMap[N.getValue(1)] = notIn; // Generate the token
864 else
865 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
866
Andrew Lenhartha549deb2005-02-07 05:33:15 +0000867 Tmp1 = MakeReg(MVT::f32);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000868
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000869 assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 &&
870 "EXTLOAD not from f32");
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000871 assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64");
872
873 SDOperand Chain = N.getOperand(0);
874 SDOperand Address = N.getOperand(1);
875 Select(Chain);
876
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000877 if (Address.getOpcode() == ISD::GlobalAddress) {
878 AlphaLowering.restoreGP(BB);
879 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
880 }
881 else if (ConstantPoolSDNode *CP =
882 dyn_cast<ConstantPoolSDNode>(N.getOperand(1)))
883 {
884 AlphaLowering.restoreGP(BB);
885 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex());
886 }
887 else if(Address.getOpcode() == ISD::FrameIndex) {
888 Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
Andrew Lenharth032f2352005-02-22 21:59:48 +0000889 BuildMI(BB, Alpha::LDS, 2, Tmp1)
890 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
891 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000892 } else {
893 long offset;
894 SelectAddr(Address, Tmp2, offset);
895 BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2);
896 }
Andrew Lenharth29219162005-02-07 06:31:44 +0000897 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
Andrew Lenharth12dd2622005-02-03 21:01:15 +0000898 return Result;
899 }
Andrew Lenharth2c594352005-01-29 15:42:07 +0000900
Andrew Lenharthe76797c2005-02-01 20:40:27 +0000901 case ISD::UINT_TO_FP:
902 case ISD::SINT_TO_FP:
Andrew Lenharth40831c52005-01-28 06:57:18 +0000903 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000904 assert (N.getOperand(0).getValueType() == MVT::i64
905 && "only quads can be loaded from");
Andrew Lenharth40831c52005-01-28 06:57:18 +0000906 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000907 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000908 MoveInt2FP(Tmp1, Tmp2, true);
Andrew Lenharth7efadce2005-01-31 01:44:26 +0000909 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
910 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Andrew Lenharth40831c52005-01-28 06:57:18 +0000911 return Result;
912 }
913 }
914 assert(0 && "should not get here");
915 return 0;
916}
917
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000918unsigned ISel::SelectExpr(SDOperand N) {
919 unsigned Result;
920 unsigned Tmp1, Tmp2, Tmp3;
921 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000922 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000923
924 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000925 MVT::ValueType DestType = N.getValueType();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000926
927 unsigned &Reg = ExprMap[N];
928 if (Reg) return Reg;
929
930 if (N.getOpcode() != ISD::CALL)
931 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000932 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000933 else {
934 // If this is a call instruction, make sure to prepare ALL of the result
935 // values as well as the chain.
936 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000937 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000938 else {
939 Result = MakeReg(Node->getValueType(0));
940 ExprMap[N.getValue(0)] = Result;
941 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
942 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000943 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000944 }
945 }
946
Andrew Lenharth22088bb2005-02-02 15:05:33 +0000947 if (DestType == MVT::f64 || DestType == MVT::f32 ||
Andrew Lenharth06342c32005-02-07 06:21:37 +0000948 (
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000949 (opcode == ISD::LOAD || opcode == ISD::CopyFromReg ||
950 opcode == ISD::EXTLOAD) &&
951 (N.getValue(0).getValueType() == MVT::f32 ||
952 N.getValue(0).getValueType() == MVT::f64)
Andrew Lenharth06342c32005-02-07 06:21:37 +0000953 )
954 )
Andrew Lenharth40831c52005-01-28 06:57:18 +0000955 return SelectExprFP(N, Result);
956
957 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000958 default:
959 Node->dump();
960 assert(0 && "Node not handled!\n");
961
Andrew Lenharth7332f3e2005-04-02 19:11:07 +0000962
963 case ISD::UNDEF: {
964 BuildMI(BB, Alpha::IDEF, 0, Result);
965 return Result;
966 }
967
Andrew Lenharth032f2352005-02-22 21:59:48 +0000968 case ISD::DYNAMIC_STACKALLOC:
969 // Generate both result values.
Andrew Lenharth3a7118d2005-02-23 17:33:42 +0000970 if (Result != notIn)
971 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth032f2352005-02-22 21:59:48 +0000972 else
973 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
974
975 // FIXME: We are currently ignoring the requested alignment for handling
976 // greater than the stack alignment. This will need to be revisited at some
977 // point. Align = N.getOperand(2);
978
979 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
980 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
981 std::cerr << "Cannot allocate stack object with greater alignment than"
982 << " the stack alignment yet!";
983 abort();
984 }
985
986 Select(N.getOperand(0));
987 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
988 {
989 if (CN->getValue() < 32000)
990 {
991 BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
992 .addImm(-CN->getValue()).addReg(Alpha::R30);
993 } else {
994 Tmp1 = SelectExpr(N.getOperand(1));
995 // Subtract size from stack pointer, thereby allocating some space.
996 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
997 }
998 } else {
999 Tmp1 = SelectExpr(N.getOperand(1));
1000 // Subtract size from stack pointer, thereby allocating some space.
1001 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
1002 }
1003
1004 // Put a pointer to the space into the result register, by copying the stack
1005 // pointer.
Andrew Lenharth7bc47022005-02-22 23:29:25 +00001006 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
Andrew Lenharth032f2352005-02-22 21:59:48 +00001007 return Result;
1008
Andrew Lenharth33819132005-03-04 20:09:23 +00001009// case ISD::ConstantPool:
1010// Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
1011// AlphaLowering.restoreGP(BB);
1012// BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1);
1013// return Result;
Andrew Lenharth2c594352005-01-29 15:42:07 +00001014
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001015 case ISD::FrameIndex:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001016 BuildMI(BB, Alpha::LDA, 2, Result)
1017 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
1018 .addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001019 return Result;
1020
1021 case ISD::EXTLOAD:
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001022 case ISD::ZEXTLOAD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001023 case ISD::SEXTLOAD:
Andrew Lenhartha549deb2005-02-07 05:33:15 +00001024 case ISD::LOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001025 {
1026 // Make sure we generate both values.
1027 if (Result != notIn)
1028 ExprMap[N.getValue(1)] = notIn; // Generate the token
1029 else
1030 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001031
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001032 SDOperand Chain = N.getOperand(0);
1033 SDOperand Address = N.getOperand(1);
1034 Select(Chain);
1035
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001036 assert(Node->getValueType(0) == MVT::i64 &&
1037 "Unknown type to sign extend to.");
Andrew Lenharth03824012005-02-07 05:55:55 +00001038 if (opcode == ISD::LOAD)
1039 Opc = Alpha::LDQ;
1040 else
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001041 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
1042 default: Node->dump(); assert(0 && "Bad sign extend!");
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001043 case MVT::i32: Opc = Alpha::LDL;
1044 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
1045 case MVT::i16: Opc = Alpha::LDWU;
1046 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001047 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001048 case MVT::i8: Opc = Alpha::LDBU;
1049 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001050 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001051
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001052 if (Address.getOpcode() == ISD::GlobalAddress) {
1053 AlphaLowering.restoreGP(BB);
1054 Opc = GetSymVersion(Opc);
1055 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1056 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001057 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1058 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +00001059 Opc = GetSymVersion(Opc);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001060 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001061 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001062 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001063 BuildMI(BB, Opc, 2, Result)
1064 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1065 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001066 } else {
1067 long offset;
1068 SelectAddr(Address, Tmp1, offset);
1069 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
1070 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001071 return Result;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001072 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001073
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001074 case ISD::GlobalAddress:
1075 AlphaLowering.restoreGP(BB);
1076 BuildMI(BB, Alpha::LOAD_ADDR, 1, Result)
1077 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal());
1078 return Result;
1079
1080 case ISD::CALL:
1081 {
1082 Select(N.getOperand(0));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001083
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001084 // The chain for this call is now lowered.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001085 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001086
1087 //grab the arguments
1088 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001089 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001090 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001091 argvregs.push_back(SelectExpr(N.getOperand(i)));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001092
Andrew Lenharth684f2292005-01-30 00:35:27 +00001093 //in reg args
1094 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001095 {
1096 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
1097 Alpha::R19, Alpha::R20, Alpha::R21};
1098 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
1099 Alpha::F19, Alpha::F20, Alpha::F21};
1100 switch(N.getOperand(i+2).getValueType()) {
1101 default:
1102 Node->dump();
1103 N.getOperand(i).Val->dump();
1104 std::cerr << "Type for " << i << " is: " <<
1105 N.getOperand(i+2).getValueType() << "\n";
1106 assert(0 && "Unknown value type for call");
1107 case MVT::i1:
1108 case MVT::i8:
1109 case MVT::i16:
1110 case MVT::i32:
1111 case MVT::i64:
1112 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]);
1113 break;
1114 case MVT::f32:
1115 case MVT::f64:
1116 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]);
1117 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +00001118 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001119 }
Andrew Lenharth684f2292005-01-30 00:35:27 +00001120 //in mem args
1121 for (int i = 6, e = argvregs.size(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001122 {
1123 switch(N.getOperand(i+2).getValueType()) {
1124 default:
1125 Node->dump();
1126 N.getOperand(i).Val->dump();
1127 std::cerr << "Type for " << i << " is: " <<
1128 N.getOperand(i+2).getValueType() << "\n";
1129 assert(0 && "Unknown value type for call");
1130 case MVT::i1:
1131 case MVT::i8:
1132 case MVT::i16:
1133 case MVT::i32:
1134 case MVT::i64:
1135 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1136 break;
1137 case MVT::f32:
1138 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1139 break;
1140 case MVT::f64:
1141 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1142 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +00001143 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001144 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001145 //build the right kind of call
1146 if (GlobalAddressSDNode *GASD =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001147 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001148 {
Andrew Lenharth3e315922005-02-10 20:10:38 +00001149 //if (GASD->getGlobal()->isExternal()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001150 //use safe calling convention
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001151 AlphaLowering.restoreGP(BB);
1152 BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal(),true);
Andrew Lenharth3e315922005-02-10 20:10:38 +00001153 //} else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001154 //use PC relative branch call
Andrew Lenharth3e315922005-02-10 20:10:38 +00001155 //BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
1156 //}
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001157 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001158 else if (ExternalSymbolSDNode *ESSDN =
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001159 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001160 {
1161 AlphaLowering.restoreGP(BB);
Andrew Lenharthba05ad62005-03-30 18:22:52 +00001162 BuildMI(BB, Alpha::CALL, 1).addExternalSymbol(ESSDN->getSymbol(), true);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001163 } else {
1164 //no need to restore GP as we are doing an indirect call
1165 Tmp1 = SelectExpr(N.getOperand(1));
1166 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
1167 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
1168 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001169
1170 //push the result into a virtual register
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001171
1172 switch (Node->getValueType(0)) {
1173 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001174 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001175 case MVT::i1:
1176 case MVT::i8:
1177 case MVT::i16:
1178 case MVT::i32:
1179 case MVT::i64:
1180 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
1181 break;
1182 case MVT::f32:
1183 case MVT::f64:
1184 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
1185 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001186 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001187 return Result+N.ResNo;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001188 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001189
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001190 case ISD::SIGN_EXTEND_INREG:
1191 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001192 //do SDIV opt for all levels of ints
Andrew Lenharth5e99dd92005-03-31 22:02:25 +00001193 if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV)
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001194 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001195 unsigned Tmp4 = MakeReg(MVT::f64);
1196 unsigned Tmp5 = MakeReg(MVT::f64);
1197 unsigned Tmp6 = MakeReg(MVT::f64);
1198 unsigned Tmp7 = MakeReg(MVT::f64);
1199 unsigned Tmp8 = MakeReg(MVT::f64);
1200 unsigned Tmp9 = MakeReg(MVT::f64);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001201
1202 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1203 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1204 MoveInt2FP(Tmp1, Tmp4, true);
1205 MoveInt2FP(Tmp2, Tmp5, true);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001206 BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4);
1207 BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5);
1208 BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
1209 BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001210 MoveFP2Int(Tmp9, Result, true);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001211 return Result;
1212 }
1213
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001214 //Alpha has instructions for a bunch of signed 32 bit stuff
1215 if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001216 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001217 switch (N.getOperand(0).getOpcode()) {
1218 case ISD::ADD:
1219 case ISD::SUB:
1220 case ISD::MUL:
1221 {
1222 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
1223 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
1224 //FIXME: first check for Scaled Adds and Subs!
1225 if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1226 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
1227 { //Normal imm add/sub
1228 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
Andrew Lenharth093f3272005-02-12 21:11:17 +00001229 //if the value was really originally a i32, skip the up conversion
1230 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
1231 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
1232 ->getExtraValueType() == MVT::i32)
1233 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1234 else
1235 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001236 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
1237 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001238 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001239 else
1240 { //Normal add/sub
1241 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULLi : Alpha::SUBL);
Andrew Lenharth093f3272005-02-12 21:11:17 +00001242 //if the value was really originally a i32, skip the up conversion
1243 if (N.getOperand(0).getOperand(0).getOpcode() == ISD::SIGN_EXTEND_INREG &&
1244 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(0).Val)
1245 ->getExtraValueType() == MVT::i32)
1246 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1247 else
1248 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1249 //if the value was really originally a i32, skip the up conversion
1250 if (N.getOperand(0).getOperand(1).getOpcode() == ISD::SIGN_EXTEND_INREG &&
1251 dyn_cast<MVTSDNode>(N.getOperand(0).getOperand(1).Val)
1252 ->getExtraValueType() == MVT::i32)
1253 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
1254 else
1255 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1256
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001257 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1258 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1259 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1260 }
1261 return Result;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001262 }
Andrew Lenharth74d00d82005-03-02 17:23:03 +00001263 case ISD::SEXTLOAD:
1264 //SelectionDag isn't deleting the signextend after sextloads
1265 Reg = Result = SelectExpr(N.getOperand(0));
1266 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001267 default: break; //Fall Though;
1268 }
1269 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001270 Tmp1 = SelectExpr(N.getOperand(0));
1271 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001272 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001273 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001274 {
1275 default:
1276 Node->dump();
1277 assert(0 && "Sign Extend InReg not there yet");
1278 break;
1279 case MVT::i32:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001280 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001281 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001282 break;
1283 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001284 case MVT::i16:
1285 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
1286 break;
1287 case MVT::i8:
1288 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
1289 break;
Andrew Lenharthebce5042005-02-12 19:35:12 +00001290 case MVT::i1:
1291 Tmp2 = MakeReg(MVT::i64);
1292 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
Andrew Lenharth7536eea2005-02-12 20:42:09 +00001293 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::F31).addReg(Tmp2);
Andrew Lenharthebce5042005-02-12 19:35:12 +00001294 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001295 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001296 return Result;
1297 }
1298 case ISD::ZERO_EXTEND_INREG:
1299 {
1300 Tmp1 = SelectExpr(N.getOperand(0));
1301 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001302 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001303 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001304 {
1305 default:
1306 Node->dump();
1307 assert(0 && "Zero Extend InReg not there yet");
1308 break;
1309 case MVT::i32: Tmp2 = 0xf0; break;
1310 case MVT::i16: Tmp2 = 0xfc; break;
1311 case MVT::i8: Tmp2 = 0xfe; break;
1312 case MVT::i1: //handle this one special
1313 BuildMI(BB, Alpha::ANDi, 2, Result).addReg(Tmp1).addImm(1);
1314 return Result;
1315 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001316 BuildMI(BB, Alpha::ZAPi, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001317 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001318 }
1319
1320 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001321 {
1322 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1323 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
1324 bool isConst1 = false;
1325 bool isConst2 = false;
1326 int dir;
Andrew Lenharth9818c052005-02-05 13:19:12 +00001327
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001328 //Tmp1 = SelectExpr(N.getOperand(0));
1329 if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001330 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255)
1331 isConst1 = true;
1332 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001333 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1334 isConst2 = true;
1335
1336 switch (SetCC->getCondition()) {
1337 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1338 case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001339 case ISD::SETLT:
1340 Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
1341 case ISD::SETLE:
1342 Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
1343 case ISD::SETGT:
1344 Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break;
1345 case ISD::SETGE:
1346 Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break;
1347 case ISD::SETULT:
1348 Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
1349 case ISD::SETUGT:
1350 Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break;
1351 case ISD::SETULE:
1352 Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
1353 case ISD::SETUGE:
1354 Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001355 case ISD::SETNE: {//Handle this one special
1356 //std::cerr << "Alpha does not have a setne.\n";
1357 //abort();
1358 Tmp1 = SelectExpr(N.getOperand(0));
1359 Tmp2 = SelectExpr(N.getOperand(1));
1360 Tmp3 = MakeReg(MVT::i64);
1361 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth445171a2005-02-08 00:40:03 +00001362 //Remeber we have the Inv for this CC
1363 CCInvMap[N] = Tmp3;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001364 //and invert
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001365 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001366 return Result;
1367 }
1368 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001369 if (dir == 1) {
1370 Tmp1 = SelectExpr(N.getOperand(0));
1371 if (isConst2) {
1372 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1373 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1374 } else {
1375 Tmp2 = SelectExpr(N.getOperand(1));
1376 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1377 }
1378 } else if (dir == 2) {
1379 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001380 if (isConst1) {
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001381 Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1382 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1383 } else {
1384 Tmp2 = SelectExpr(N.getOperand(0));
1385 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1386 }
1387 } else { //dir == 0
1388 if (isConst1) {
1389 Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1390 Tmp2 = SelectExpr(N.getOperand(1));
1391 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1);
1392 } else if (isConst2) {
1393 Tmp1 = SelectExpr(N.getOperand(0));
1394 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1395 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2);
1396 } else {
1397 Tmp1 = SelectExpr(N.getOperand(0));
1398 Tmp2 = SelectExpr(N.getOperand(1));
1399 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1400 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001401 }
1402 } else {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001403 //do the comparison
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001404 Tmp1 = MakeReg(MVT::f64);
1405 bool inv = SelectFPSetCC(N, Tmp1);
1406
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001407 //now arrange for Result (int) to have a 1 or 0
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001408 Tmp2 = MakeReg(MVT::i64);
1409 BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001410 Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001411 BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001412 }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001413 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001414 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001415 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001416
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001417 case ISD::CopyFromReg:
1418 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001419 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001420 if (Result != notIn)
1421 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +00001422 else
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001423 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth40831c52005-01-28 06:57:18 +00001424
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001425 SDOperand Chain = N.getOperand(0);
1426
1427 Select(Chain);
1428 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1429 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1430 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
1431 return Result;
1432 }
1433
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001434 //Most of the plain arithmetic and logic share the same form, and the same
1435 //constant immediate test
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001436 case ISD::OR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001437 //Match Not
1438 if (N.getOperand(1).getOpcode() == ISD::Constant &&
1439 cast<ConstantSDNode>(N.getOperand(1))->isAllOnesValue())
1440 {
1441 Tmp1 = SelectExpr(N.getOperand(0));
1442 BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
1443 return Result;
1444 }
1445 //Fall through
1446 case ISD::AND:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001447 case ISD::XOR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001448 //Check operand(0) == Not
1449 if (N.getOperand(0).getOpcode() == ISD::OR &&
1450 N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
1451 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->isAllOnesValue())
1452 {
1453 switch(opcode) {
1454 case ISD::AND: Opc = Alpha::BIC; break;
1455 case ISD::OR: Opc = Alpha::ORNOT; break;
1456 case ISD::XOR: Opc = Alpha::EQV; break;
1457 }
1458 Tmp1 = SelectExpr(N.getOperand(1));
1459 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1460 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1461 return Result;
1462 }
1463 //Check operand(1) == Not
1464 if (N.getOperand(1).getOpcode() == ISD::OR &&
1465 N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant &&
1466 cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->isAllOnesValue())
1467 {
1468 switch(opcode) {
1469 case ISD::AND: Opc = Alpha::BIC; break;
1470 case ISD::OR: Opc = Alpha::ORNOT; break;
1471 case ISD::XOR: Opc = Alpha::EQV; break;
1472 }
1473 Tmp1 = SelectExpr(N.getOperand(0));
1474 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
1475 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1476 return Result;
1477 }
1478 //Fall through
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001479 case ISD::SHL:
1480 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +00001481 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001482 case ISD::MUL:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001483 assert (DestType == MVT::i64 && "Only do arithmetic on i64s!");
1484 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001485 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001486 {
1487 switch(opcode) {
1488 case ISD::AND: Opc = Alpha::ANDi; break;
1489 case ISD::OR: Opc = Alpha::BISi; break;
1490 case ISD::XOR: Opc = Alpha::XORi; break;
1491 case ISD::SHL: Opc = Alpha::SLi; break;
1492 case ISD::SRL: Opc = Alpha::SRLi; break;
1493 case ISD::SRA: Opc = Alpha::SRAi; break;
1494 case ISD::MUL: Opc = Alpha::MULQi; break;
1495 };
1496 Tmp1 = SelectExpr(N.getOperand(0));
1497 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1498 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1499 } else {
1500 switch(opcode) {
1501 case ISD::AND: Opc = Alpha::AND; break;
1502 case ISD::OR: Opc = Alpha::BIS; break;
1503 case ISD::XOR: Opc = Alpha::XOR; break;
1504 case ISD::SHL: Opc = Alpha::SL; break;
1505 case ISD::SRL: Opc = Alpha::SRL; break;
1506 case ISD::SRA: Opc = Alpha::SRA; break;
1507 case ISD::MUL: Opc = Alpha::MULQ; break;
1508 };
1509 Tmp1 = SelectExpr(N.getOperand(0));
1510 Tmp2 = SelectExpr(N.getOperand(1));
1511 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1512 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001513 return Result;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001514
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001515 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001516 case ISD::SUB:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001517 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001518 bool isAdd = opcode == ISD::ADD;
1519
1520 //FIXME: first check for Scaled Adds and Subs!
1521 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001522 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001523 { //Normal imm add/sub
1524 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
1525 Tmp1 = SelectExpr(N.getOperand(0));
1526 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1527 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1528 }
Andrew Lenharth40831c52005-01-28 06:57:18 +00001529 else if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth74d00d82005-03-02 17:23:03 +00001530 (cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767 ||
1531 (long)cast<ConstantSDNode>(N.getOperand(1))->getValue() >= -32767))
1532 { //LDA
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001533 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth74d00d82005-03-02 17:23:03 +00001534 Tmp2 = (long)cast<ConstantSDNode>(N.getOperand(1))->getValue();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001535 if (!isAdd)
1536 Tmp2 = -Tmp2;
1537 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
1538 } else {
1539 //Normal add/sub
1540 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1541 Tmp1 = SelectExpr(N.getOperand(0));
1542 Tmp2 = SelectExpr(N.getOperand(1));
1543 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1544 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001545 return Result;
1546 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001547
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001548 case ISD::SDIV:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001549 case ISD::UREM:
Andrew Lenharth02981182005-01-26 01:24:38 +00001550 case ISD::SREM:
Andrew Lenharth02981182005-01-26 01:24:38 +00001551 case ISD::UDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001552 //FIXME: alpha really doesn't support any of these operations,
1553 // the ops are expanded into special library calls with
1554 // special calling conventions
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001555 //Restore GP because it is a call after all...
Andrew Lenharth40831c52005-01-28 06:57:18 +00001556 switch(opcode) {
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001557 case ISD::UREM: Opc = Alpha::REMQU; break;
1558 case ISD::SREM: Opc = Alpha::REMQ; break;
1559 case ISD::UDIV: Opc = Alpha::DIVQU; break;
1560 case ISD::SDIV: Opc = Alpha::DIVQ; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001561 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001562 Tmp1 = SelectExpr(N.getOperand(0));
1563 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth33819132005-03-04 20:09:23 +00001564 //set up regs explicitly (helps Reg alloc)
1565 BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
1566 BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001567 AlphaLowering.restoreGP(BB);
Andrew Lenharth33819132005-03-04 20:09:23 +00001568 BuildMI(BB, Opc, 2).addReg(Alpha::R24).addReg(Alpha::R25);
1569 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001570 return Result;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001571
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001572 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001573 case ISD::FP_TO_SINT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001574 {
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001575 assert (DestType == MVT::i64 && "only quads can be loaded to");
1576 MVT::ValueType SrcType = N.getOperand(0).getValueType();
Andrew Lenharth03824012005-02-07 05:55:55 +00001577 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001578 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001579 if (SrcType == MVT::f32)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001580 {
1581 Tmp2 = MakeReg(MVT::f64);
1582 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
1583 Tmp1 = Tmp2;
1584 }
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001585 Tmp2 = MakeReg(MVT::f64);
1586 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001587 MoveFP2Int(Tmp2, Result, true);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001588
1589 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001590 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001591
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001592 case ISD::SELECT:
1593 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001594 //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP) and can save stack use
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001595 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001596 //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1597 //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001598 // Get the condition into the zero flag.
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001599 //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001600
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001601 SDOperand CC = N.getOperand(0);
1602 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
1603
1604 if (CC.getOpcode() == ISD::SETCC &&
1605 !MVT::isInteger(SetCC->getOperand(0).getValueType()))
1606 { //FP Setcc -> Int Select
1607 Tmp1 = MakeReg(MVT::f64);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001608 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1609 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001610 bool inv = SelectFPSetCC(CC, Tmp1);
1611 BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result)
1612 .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
1613 return Result;
1614 }
1615 if (CC.getOpcode() == ISD::SETCC) {
1616 //Int SetCC -> Select
1617 //Dropping the CC is only useful if we are comparing to 0
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001618 if((SetCC->getOperand(1).getOpcode() == ISD::Constant &&
1619 cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0) ||
1620 (SetCC->getOperand(0).getOpcode() == ISD::Constant &&
1621 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0))
1622 {
1623 //figure out a few things
1624 bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
1625 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
1626 bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
1627 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
1628 bool LeftConst = N.getOperand(1).getOpcode() == ISD::Constant &&
1629 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255;
1630 bool RightConst = N.getOperand(2).getOpcode() == ISD::Constant &&
1631 cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255;
1632 bool useImm = LeftConst || RightConst;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001633
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001634 //Fix up CC
1635 ISD::CondCode cCode= SetCC->getCondition();
1636 if (RightConst && !LeftConst) //Invert sense to get Imm field right
1637 cCode = ISD::getSetCCInverse(cCode, true);
1638 if (LeftZero && !RightZero) //Swap Operands
1639 cCode = ISD::getSetCCSwappedOperands(cCode);
1640
1641 //Choose the CMOV
1642 switch (cCode) {
1643 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
1644 case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
1645 case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break;
1646 case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break;
1647 case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break;
1648 case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break;
1649 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
1650 case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
1651 case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; //Technically you could have this CC
1652 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
1653 case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
1654 }
1655 if(LeftZero && !RightZero) //swap Operands
1656 Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond
1657 else
1658 Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
1659
1660 if (LeftConst) {
1661 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
1662 BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
1663 .addImm(cast<ConstantSDNode>(N.getOperand(1))->getValue())
1664 .addReg(Tmp1);
1665 } else if (RightConst) {
1666 Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
1667 BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
1668 .addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue())
1669 .addReg(Tmp1);
1670 } else {
1671 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1672 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
1673 BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1);
1674 }
1675 return Result;
1676 }
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001677 //Otherwise, fall though
1678 }
1679 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001680 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1681 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001682 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001683
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001684 return Result;
1685 }
1686
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001687 case ISD::Constant:
1688 {
Andrew Lenharthc0513832005-03-29 19:24:04 +00001689 int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00001690 if (val <= IMM_HIGH && val >= IMM_LOW) {
1691 BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
1692 }
1693 else if (val <= (int64_t)IMM_HIGH + (int64_t)IMM_HIGH * (int64_t)IMM_MULT &&
1694 val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
1695 Tmp1 = MakeReg(MVT::i64);
1696 BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val)).addReg(Alpha::R31);
1697 BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
1698 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001699 else {
1700 MachineConstantPool *CP = BB->getParent()->getConstantPool();
1701 ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
1702 unsigned CPI = CP->getConstantPoolIndex(C);
1703 AlphaLowering.restoreGP(BB);
1704 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI);
1705 }
1706 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001707 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001708 }
1709
1710 return 0;
1711}
1712
1713void ISel::Select(SDOperand N) {
1714 unsigned Tmp1, Tmp2, Opc;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001715 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001716
Nate Begeman85fdeb22005-03-24 04:39:54 +00001717 if (!ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001718 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001719
1720 SDNode *Node = N.Val;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001721
Andrew Lenharth760270d2005-02-07 23:02:23 +00001722 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001723
1724 default:
1725 Node->dump(); std::cerr << "\n";
1726 assert(0 && "Node not handled yet!");
1727
1728 case ISD::BRCOND: {
Andrew Lenharth445171a2005-02-08 00:40:03 +00001729 SelectBranchCC(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001730 return;
1731 }
1732
1733 case ISD::BR: {
1734 MachineBasicBlock *Dest =
1735 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1736
1737 Select(N.getOperand(0));
1738 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
1739 return;
1740 }
1741
1742 case ISD::ImplicitDef:
1743 Select(N.getOperand(0));
1744 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
1745 return;
1746
1747 case ISD::EntryToken: return; // Noop
1748
1749 case ISD::TokenFactor:
1750 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1751 Select(Node->getOperand(i));
1752
1753 //N.Val->dump(); std::cerr << "\n";
1754 //assert(0 && "Node not handled yet!");
1755
1756 return;
1757
1758 case ISD::CopyToReg:
1759 Select(N.getOperand(0));
1760 Tmp1 = SelectExpr(N.getOperand(1));
1761 Tmp2 = cast<RegSDNode>(N)->getReg();
1762
1763 if (Tmp1 != Tmp2) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001764 if (N.getOperand(1).getValueType() == MVT::f64 ||
1765 N.getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth29219162005-02-07 06:31:44 +00001766 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1767 else
1768 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001769 }
1770 return;
1771
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001772 case ISD::RET:
1773 switch (N.getNumOperands()) {
1774 default:
1775 std::cerr << N.getNumOperands() << "\n";
1776 for (unsigned i = 0; i < N.getNumOperands(); ++i)
1777 std::cerr << N.getOperand(i).getValueType() << "\n";
1778 Node->dump();
1779 assert(0 && "Unknown return instruction!");
1780 case 2:
1781 Select(N.getOperand(0));
1782 Tmp1 = SelectExpr(N.getOperand(1));
1783 switch (N.getOperand(1).getValueType()) {
1784 default: Node->dump();
1785 assert(0 && "All other types should have been promoted!!");
1786 case MVT::f64:
1787 case MVT::f32:
1788 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
1789 break;
1790 case MVT::i32:
1791 case MVT::i64:
1792 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
1793 break;
1794 }
1795 break;
1796 case 1:
1797 Select(N.getOperand(0));
1798 break;
1799 }
1800 //Tmp2 = AlphaLowering.getRetAddr();
1801 //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2);
1802 BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction
1803 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001804
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001805 case ISD::TRUNCSTORE:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001806 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001807 {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001808 SDOperand Chain = N.getOperand(0);
1809 SDOperand Value = N.getOperand(1);
1810 SDOperand Address = N.getOperand(2);
1811 Select(Chain);
1812
1813 Tmp1 = SelectExpr(Value); //value
Andrew Lenharth760270d2005-02-07 23:02:23 +00001814
1815 if (opcode == ISD::STORE) {
1816 switch(Value.getValueType()) {
1817 default: assert(0 && "unknown Type in store");
1818 case MVT::i64: Opc = Alpha::STQ; break;
1819 case MVT::f64: Opc = Alpha::STT; break;
1820 case MVT::f32: Opc = Alpha::STS; break;
1821 }
1822 } else { //ISD::TRUNCSTORE
1823 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
1824 default: assert(0 && "unknown Type in store");
1825 case MVT::i1: //FIXME: DAG does not promote this load
1826 case MVT::i8: Opc = Alpha::STB; break;
1827 case MVT::i16: Opc = Alpha::STW; break;
1828 case MVT::i32: Opc = Alpha::STL; break;
1829 }
Andrew Lenharth65838902005-02-06 16:22:15 +00001830 }
Andrew Lenharth760270d2005-02-07 23:02:23 +00001831
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001832 if (Address.getOpcode() == ISD::GlobalAddress)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001833 {
1834 AlphaLowering.restoreGP(BB);
1835 Opc = GetSymVersion(Opc);
1836 BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1837 }
Andrew Lenharth05380342005-02-07 05:07:00 +00001838 else if(Address.getOpcode() == ISD::FrameIndex)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001839 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001840 BuildMI(BB, Opc, 3).addReg(Tmp1)
1841 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1842 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001843 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001844 else
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001845 {
1846 long offset;
1847 SelectAddr(Address, Tmp2, offset);
1848 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1849 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001850 return;
1851 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001852
1853 case ISD::EXTLOAD:
1854 case ISD::SEXTLOAD:
1855 case ISD::ZEXTLOAD:
1856 case ISD::LOAD:
1857 case ISD::CopyFromReg:
1858 case ISD::CALL:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001859 case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001860 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001861 SelectExpr(N);
1862 return;
1863
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001864 case ISD::ADJCALLSTACKDOWN:
1865 case ISD::ADJCALLSTACKUP:
1866 Select(N.getOperand(0));
1867 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1868
1869 Opc = N.getOpcode() == ISD::ADJCALLSTACKDOWN ? Alpha::ADJUSTSTACKDOWN :
1870 Alpha::ADJUSTSTACKUP;
1871 BuildMI(BB, Opc, 1).addImm(Tmp1);
1872 return;
Andrew Lenharth95762122005-03-31 21:24:06 +00001873
1874 case ISD::PCMARKER:
1875 Select(N.getOperand(0)); //Chain
1876 BuildMI(BB, Alpha::PCLABEL, 2).addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
1877 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001878 }
1879 assert(0 && "Should not be reached!");
1880}
1881
1882
1883/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
1884/// into a machine code representation using pattern matching and a machine
1885/// description file.
1886///
1887FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
1888 return new ISel(TM);
1889}