blob: 1f11065971dcb7b6a3c8ac845c91e6b87cd79e23 [file] [log] [blame]
Misha Brukman2a8350a2005-02-05 02:24:26 +00001//===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00003// 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.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
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 {
Misha Brukman4633f1c2005-04-21 23:13:11 +000036 cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
37 cl::desc("Use the FP div instruction for integer div when possible"),
Andrew Lenharth95762122005-03-31 21:24:06 +000038 cl::Hidden);
Andrew Lenharth59009192005-05-04 19:12:09 +000039 cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI",
Misha Brukman4633f1c2005-04-21 23:13:11 +000040 cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"),
Andrew Lenharth95762122005-03-31 21:24:06 +000041 cl::Hidden);
Andrew Lenharth59009192005-05-04 19:12:09 +000042 cl::opt<bool> EnableAlphaCT("enable-alpha-CT",
43 cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"),
44 cl::Hidden);
Misha Brukman4633f1c2005-04-21 23:13:11 +000045 cl::opt<bool> EnableAlphaCount("enable-alpha-count",
46 cl::desc("Print estimates on live ins and outs"),
Andrew Lenhartha32b9e32005-04-08 17:28:49 +000047 cl::Hidden);
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +000048 cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark",
49 cl::desc("Emit symbols to corrolate Mem ops to LLVM Values"),
50 cl::Hidden);
Andrew Lenharth95762122005-03-31 21:24:06 +000051}
52
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +000053namespace {
54 // Alpha Specific DAG Nodes
55 namespace AlphaISD {
56 enum NodeType {
57 // Start the numbering where the builtin ops leave off.
58 FIRST_NUMBER = ISD::BUILTIN_OP_END,
59
60 //Convert an int bit pattern in an FP reg to a Double or Float
61 //Has a dest type and a source
62 CVTQ,
63 //Move an Ireg to a FPreg
64 ITOF,
65 //Move a FPreg to an Ireg
66 FTOI,
67 };
68 }
69}
70
Andrew Lenharth304d0f32005-01-22 23:41:55 +000071//===----------------------------------------------------------------------===//
72// AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
73namespace {
74 class AlphaTargetLowering : public TargetLowering {
75 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
76 unsigned GP; //GOT vreg
77 public:
78 AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
79 // Set up the TargetLowering object.
Andrew Lenharth3d65d312005-01-27 03:49:45 +000080 //I am having problems with shr n ubyte 1
Andrew Lenharth879ef222005-02-02 17:00:21 +000081 setShiftAmountType(MVT::i64);
82 setSetCCResultType(MVT::i64);
Andrew Lenharthd3355e22005-04-07 20:11:32 +000083 setSetCCResultContents(ZeroOrOneSetCCResult);
Misha Brukman4633f1c2005-04-21 23:13:11 +000084
Andrew Lenharth304d0f32005-01-22 23:41:55 +000085 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
86 addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
Andrew Lenharth3d65d312005-01-27 03:49:45 +000087 addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
Misha Brukman4633f1c2005-04-21 23:13:11 +000088
Chris Lattnerda4d4692005-04-09 03:22:37 +000089 setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +000090 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
91 setOperationAction(ISD::EXTLOAD , MVT::f32 , Promote);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000092
Andrew Lenharth4b8ac152005-04-06 20:25:34 +000093 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
94 setOperationAction(ISD::ZEXTLOAD , MVT::i32 , Expand);
Andrew Lenharth2f8fb772005-01-25 00:35:34 +000095
Andrew Lenharth4b8ac152005-04-06 20:25:34 +000096 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
97 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
98 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
Andrew Lenharth304d0f32005-01-22 23:41:55 +000099
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000100 setOperationAction(ISD::SREM , MVT::f32 , Expand);
101 setOperationAction(ISD::SREM , MVT::f64 , Expand);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000102
Andrew Lenharth59009192005-05-04 19:12:09 +0000103 if (!EnableAlphaCT) {
104 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
105 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
Andrew Lenharthb5884d32005-05-04 19:25:37 +0000106 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
Andrew Lenharth59009192005-05-04 19:12:09 +0000107 }
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000108
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000109 //If this didn't legalize into a div....
110 // setOperationAction(ISD::SREM , MVT::i64, Expand);
111 // setOperationAction(ISD::UREM , MVT::i64, Expand);
112
113 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
114 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
115 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
Andrew Lenharth9818c052005-02-05 13:19:12 +0000116
Chris Lattner17234b72005-04-30 04:26:06 +0000117 // We don't support sin/cos/sqrt
118 setOperationAction(ISD::FSIN , MVT::f64, Expand);
119 setOperationAction(ISD::FCOS , MVT::f64, Expand);
120 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
121 setOperationAction(ISD::FSIN , MVT::f32, Expand);
122 setOperationAction(ISD::FCOS , MVT::f32, Expand);
123 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
124
Andrew Lenharth33819132005-03-04 20:09:23 +0000125 //Doesn't work yet
Chris Lattner17234b72005-04-30 04:26:06 +0000126 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Andrew Lenharth572af902005-02-14 05:41:43 +0000127
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +0000128 //Try a couple things with a custom expander
129 //setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
130
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000131 computeRegisterProperties();
Misha Brukman4633f1c2005-04-21 23:13:11 +0000132
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000133 addLegalFPImmediate(+0.0); //F31
134 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000135 }
136
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +0000137 /// LowerOperation - Provide custom lowering hooks for some operations.
138 ///
139 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
140
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000141 /// LowerArguments - This hook must be implemented to indicate how we should
142 /// lower the arguments for the specified function, into the specified DAG.
143 virtual std::vector<SDOperand>
144 LowerArguments(Function &F, SelectionDAG &DAG);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000145
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000146 /// LowerCallTo - This hook lowers an abstract call to a function into an
147 /// actual call.
148 virtual std::pair<SDOperand, SDOperand>
Chris Lattnerc57f6822005-05-12 19:56:45 +0000149 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
Chris Lattneradf6a962005-05-13 18:50:42 +0000150 bool isTailCall, SDOperand Callee, ArgListTy &Args,
151 SelectionDAG &DAG);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000152
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000153 virtual std::pair<SDOperand, SDOperand>
154 LowerVAStart(SDOperand Chain, SelectionDAG &DAG);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000155
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000156 virtual std::pair<SDOperand,SDOperand>
157 LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
158 const Type *ArgTy, SelectionDAG &DAG);
159
160 virtual std::pair<SDOperand, SDOperand>
161 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
162 SelectionDAG &DAG);
163
164 void restoreGP(MachineBasicBlock* BB)
165 {
166 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
167 }
168 };
169}
170
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +0000171/// LowerOperation - Provide custom lowering hooks for some operations.
172///
173SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
174 MachineFunction &MF = DAG.getMachineFunction();
175 switch (Op.getOpcode()) {
176 default: assert(0 && "Should not custom lower this!");
Misha Brukmanb8ee91a2005-06-06 17:39:46 +0000177#if 0
178 case ISD::SINT_TO_FP:
179 {
180 assert (Op.getOperand(0).getValueType() == MVT::i64
181 && "only quads can be loaded from");
182 SDOperand SRC;
183 if (EnableAlphaFTOI)
184 {
185 std::vector<MVT::ValueType> RTs;
186 RTs.push_back(Op.getValueType());
187 std::vector<SDOperand> Ops;
188 Ops.push_back(Op.getOperand(0));
189 SRC = DAG.getNode(AlphaISD::ITOF, RTs, Ops);
190 } else {
191 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
192 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
193 SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
194 Op.getOperand(0), StackSlot, DAG.getSrcValue(NULL));
195 SRC = DAG.getLoad(Op.getValueType(), Store.getValue(0), StackSlot,
196 DAG.getSrcValue(NULL));
197 }
198 std::vector<MVT::ValueType> RTs;
199 RTs.push_back(Op.getValueType());
200 std::vector<SDOperand> Ops;
201 Ops.push_back(SRC);
202 return DAG.getNode(AlphaISD::CVTQ, RTs, Ops);
203 }
204#endif
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +0000205 }
Misha Brukmanb8ee91a2005-06-06 17:39:46 +0000206 return SDOperand();
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +0000207}
208
209
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000210/// AddLiveIn - This helper function adds the specified physical register to the
211/// MachineFunction as a live in value. It also creates a corresponding virtual
212/// register for it.
213static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
214 TargetRegisterClass *RC) {
215 assert(RC->contains(PReg) && "Not the correct regclass!");
216 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
217 MF.addLiveIn(PReg, VReg);
218 return VReg;
219}
220
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000221//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
222
223//For now, just use variable size stack frame format
224
225//In a standard call, the first six items are passed in registers $16
226//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
227//of argument-to-register correspondence.) The remaining items are
228//collected in a memory argument list that is a naturally aligned
229//array of quadwords. In a standard call, this list, if present, must
230//be passed at 0(SP).
Misha Brukman7847fca2005-04-22 17:54:37 +0000231//7 ... n 0(SP) ... (n-7)*8(SP)
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000232
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000233// //#define FP $15
234// //#define RA $26
235// //#define PV $27
236// //#define GP $29
237// //#define SP $30
Misha Brukman4633f1c2005-04-21 23:13:11 +0000238
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000239std::vector<SDOperand>
Misha Brukman4633f1c2005-04-21 23:13:11 +0000240AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000241{
242 std::vector<SDOperand> ArgValues;
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000243
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000244 MachineFunction &MF = DAG.getMachineFunction();
Andrew Lenharth05380342005-02-07 05:07:00 +0000245 MachineFrameInfo*MFI = MF.getFrameInfo();
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000246
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000247 MachineBasicBlock& BB = MF.front();
248
249 //Handle the return address
250 //BuildMI(&BB, Alpha::IDEF, 0, Alpha::R26);
251
Misha Brukman4633f1c2005-04-21 23:13:11 +0000252 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
Misha Brukman7847fca2005-04-22 17:54:37 +0000253 Alpha::R19, Alpha::R20, Alpha::R21};
Misha Brukman4633f1c2005-04-21 23:13:11 +0000254 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
Misha Brukman7847fca2005-04-22 17:54:37 +0000255 Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000256 int count = 0;
Andrew Lenharth2c9e38c2005-02-06 21:07:31 +0000257
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000258 GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000259
Chris Lattnere4d5c442005-03-15 04:54:21 +0000260 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000261 {
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000262 SDOperand argt;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000263 if (count < 6) {
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000264 unsigned Vreg;
265 MVT::ValueType VT = getValueType(I->getType());
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000266 switch (VT) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000267 default:
268 std::cerr << "Unknown Type " << VT << "\n";
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000269 abort();
270 case MVT::f64:
271 case MVT::f32:
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000272 args_float[count] = AddLiveIn(MF,args_float[count], getRegClassFor(VT));
273 argt = DAG.getCopyFromReg(args_float[count], VT, DAG.getRoot());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000274 break;
275 case MVT::i1:
276 case MVT::i8:
277 case MVT::i16:
278 case MVT::i32:
279 case MVT::i64:
Andrew Lenharth591ec572005-05-31 18:42:18 +0000280 args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64));
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000281 argt = DAG.getCopyFromReg(args_int[count], VT, DAG.getRoot());
Andrew Lenharth14f30c92005-05-31 18:37:16 +0000282 if (VT != MVT::i64)
283 argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000284 break;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000285 }
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000286 DAG.setRoot(argt.getValue(1));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000287 } else { //more args
288 // Create the frame index object for this incoming parameter...
289 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000290
291 // Create the SelectionDAG nodes corresponding to a load
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000292 //from this parameter
293 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000294 argt = DAG.getLoad(getValueType(I->getType()),
295 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000296 }
Andrew Lenharth032f2352005-02-22 21:59:48 +0000297 ++count;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000298 ArgValues.push_back(argt);
299 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000300
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000301 // If the functions takes variable number of arguments, copy all regs to stack
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000302 if (F.isVarArg()) {
303 std::vector<SDOperand> LS;
304 for (int i = 0; i < 6; ++i) {
305 if (args_int[i] < 1024)
306 args_int[i] = AddLiveIn(MF,args_int[i], getRegClassFor(MVT::i64));
307 SDOperand argt = DAG.getCopyFromReg(args_int[i], MVT::i64, DAG.getRoot());
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000308 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
309 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000310 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL)));
311
312 if (args_float[i] < 1024)
313 args_float[i] = AddLiveIn(MF,args_float[i], getRegClassFor(MVT::f64));
314 argt = DAG.getCopyFromReg(args_float[i], MVT::f64, DAG.getRoot());
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000315 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
316 SDFI = DAG.getFrameIndex(FI, MVT::i64);
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000317 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, SDFI, DAG.getSrcValue(NULL)));
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000318 }
319
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000320 //Set up a token factor with all the stack traffic
321 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
322 }
Andrew Lenharthe1c5a002005-04-12 17:35:16 +0000323
324 // Finally, inform the code generator which regs we return values in.
325 switch (getValueType(F.getReturnType())) {
326 default: assert(0 && "Unknown type!");
327 case MVT::isVoid: break;
328 case MVT::i1:
329 case MVT::i8:
330 case MVT::i16:
331 case MVT::i32:
332 case MVT::i64:
333 MF.addLiveOut(Alpha::R0);
334 break;
335 case MVT::f32:
336 case MVT::f64:
337 MF.addLiveOut(Alpha::F0);
338 break;
339 }
340
Andrew Lenharth2513ddc2005-04-05 20:51:46 +0000341 //return the arguments
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000342 return ArgValues;
343}
344
345std::pair<SDOperand, SDOperand>
346AlphaTargetLowering::LowerCallTo(SDOperand Chain,
Misha Brukman7847fca2005-04-22 17:54:37 +0000347 const Type *RetTy, bool isVarArg,
Chris Lattneradf6a962005-05-13 18:50:42 +0000348 unsigned CallingConv, bool isTailCall,
Misha Brukman7847fca2005-04-22 17:54:37 +0000349 SDOperand Callee, ArgListTy &Args,
350 SelectionDAG &DAG) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000351 int NumBytes = 0;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000352 if (Args.size() > 6)
353 NumBytes = (Args.size() - 6) * 8;
354
Chris Lattner16cd04d2005-05-12 23:24:06 +0000355 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
Misha Brukman7847fca2005-04-22 17:54:37 +0000356 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000357 std::vector<SDOperand> args_to_use;
358 for (unsigned i = 0, e = Args.size(); i != e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000359 {
360 switch (getValueType(Args[i].second)) {
361 default: assert(0 && "Unexpected ValueType for argument!");
362 case MVT::i1:
363 case MVT::i8:
364 case MVT::i16:
365 case MVT::i32:
366 // Promote the integer to 64 bits. If the input type is signed use a
367 // sign extend, otherwise use a zero extend.
368 if (Args[i].second->isSigned())
369 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
370 else
371 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
372 break;
373 case MVT::i64:
374 case MVT::f64:
375 case MVT::f32:
376 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000377 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000378 args_to_use.push_back(Args[i].first);
379 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000380
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000381 std::vector<MVT::ValueType> RetVals;
382 MVT::ValueType RetTyVT = getValueType(RetTy);
383 if (RetTyVT != MVT::isVoid)
384 RetVals.push_back(RetTyVT);
385 RetVals.push_back(MVT::Other);
386
Misha Brukman4633f1c2005-04-21 23:13:11 +0000387 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000388 Chain, Callee, args_to_use), 0);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000389 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
Chris Lattner16cd04d2005-05-12 23:24:06 +0000390 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000391 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000392 return std::make_pair(TheCall, Chain);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000393}
394
395std::pair<SDOperand, SDOperand>
396AlphaTargetLowering::LowerVAStart(SDOperand Chain, SelectionDAG &DAG) {
397 //vastart just returns the address of the VarArgsFrameIndex slot.
398 return std::make_pair(DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64), Chain);
399}
400
401std::pair<SDOperand,SDOperand> AlphaTargetLowering::
402LowerVAArgNext(bool isVANext, SDOperand Chain, SDOperand VAList,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000403 const Type *ArgTy, SelectionDAG &DAG) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000404 abort();
405}
Misha Brukman4633f1c2005-04-21 23:13:11 +0000406
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000407
408std::pair<SDOperand, SDOperand> AlphaTargetLowering::
409LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
410 SelectionDAG &DAG) {
411 abort();
412}
413
414
415
416
417
418namespace {
419
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000420//===--------------------------------------------------------------------===//
421/// ISel - Alpha specific code to select Alpha machine instructions for
422/// SelectionDAG operations.
423//===--------------------------------------------------------------------===//
424class ISel : public SelectionDAGISel {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000425
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000426 /// AlphaLowering - This object fully describes how to lower LLVM code to an
427 /// Alpha-specific SelectionDAG.
428 AlphaTargetLowering AlphaLowering;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000429
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000430 SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform
431 // for sdiv and udiv until it is put into the future
432 // dag combiner.
433
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000434 /// ExprMap - As shared expressions are codegen'd, we keep track of which
435 /// vreg the value is produced in, so we only emit one copy of each compiled
436 /// tree.
437 static const unsigned notIn = (unsigned)(-1);
438 std::map<SDOperand, unsigned> ExprMap;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000439
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000440 //CCInvMap sometimes (SetNE) we have the inverse CC code for free
441 std::map<SDOperand, unsigned> CCInvMap;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000442
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000443 int count_ins;
444 int count_outs;
445 bool has_sym;
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000446 int max_depth;
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000447
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000448public:
Misha Brukman4633f1c2005-04-21 23:13:11 +0000449 ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000450 {}
Misha Brukman4633f1c2005-04-21 23:13:11 +0000451
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000452 /// InstructionSelectBasicBlock - This callback is invoked by
453 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
454 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000455 DEBUG(BB->dump());
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000456 count_ins = 0;
457 count_outs = 0;
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000458 max_depth = 0;
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000459 has_sym = false;
460
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000461 // Codegen the basic block.
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000462 ISelDAG = &DAG;
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000463 max_depth = DAG.getRoot().getNodeDepth();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000464 Select(DAG.getRoot());
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000465
466 if(has_sym)
467 ++count_ins;
468 if(EnableAlphaCount)
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000469 std::cerr << "COUNT: " << BB->getParent()->getFunction ()->getName() << " "
470 << BB->getNumber() << " "
471 << max_depth << " "
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000472 << count_ins << " "
473 << count_outs << "\n";
Misha Brukman4633f1c2005-04-21 23:13:11 +0000474
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000475 // Clear state used for selection.
476 ExprMap.clear();
477 CCInvMap.clear();
478 }
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000479
480 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000481
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000482 unsigned SelectExpr(SDOperand N);
483 unsigned SelectExprFP(SDOperand N, unsigned Result);
484 void Select(SDOperand N);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000485
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000486 void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
487 void SelectBranchCC(SDOperand N);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000488 void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
489 void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000490 //returns whether the sense of the comparison was inverted
491 bool SelectFPSetCC(SDOperand N, unsigned dst);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000492
493 // dag -> dag expanders for integer divide by constant
494 SDOperand BuildSDIVSequence(SDOperand N);
495 SDOperand BuildUDIVSequence(SDOperand N);
496
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000497};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000498}
499
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000500void ISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
501 // If this function has live-in values, emit the copies from pregs to vregs at
502 // the top of the function, before anything else.
503 MachineBasicBlock *BB = MF.begin();
504 if (MF.livein_begin() != MF.livein_end()) {
505 SSARegMap *RegMap = MF.getSSARegMap();
506 for (MachineFunction::livein_iterator LI = MF.livein_begin(),
507 E = MF.livein_end(); LI != E; ++LI) {
508 const TargetRegisterClass *RC = RegMap->getRegClass(LI->second);
509 if (RC == Alpha::GPRCRegisterClass) {
510 BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first).addReg(LI->first);
511 } else if (RC == Alpha::FPRCRegisterClass) {
512 BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first).addReg(LI->first);
513 } else {
514 assert(0 && "Unknown regclass!");
515 }
516 }
517 }
518}
519
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +0000520//Find the offset of the arg in it's parent's function
521static int getValueOffset(const Value* v)
522{
523 if (v == NULL)
524 return 0;
525
526 const Instruction* itarget = dyn_cast<Instruction>(v);
527 const BasicBlock* btarget = itarget->getParent();
528 const Function* ftarget = btarget->getParent();
529
530 //offset due to earlier BBs
531 int i = 0;
532 for(Function::const_iterator ii = ftarget->begin(); &*ii != btarget; ++ii)
533 i += ii->size();
534
535 for(BasicBlock::const_iterator ii = btarget->begin(); &*ii != itarget; ++ii)
536 ++i;
537
538 return i;
539}
540
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000541//Factorize a number using the list of constants
542static bool factorize(int v[], int res[], int size, uint64_t c)
543{
544 bool cont = true;
545 while (c != 1 && cont)
546 {
547 cont = false;
548 for(int i = 0; i < size; ++i)
549 {
550 if (c % v[i] == 0)
551 {
552 c /= v[i];
553 ++res[i];
554 cont=true;
555 }
556 }
557 }
558 return c == 1;
559}
560
561
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000562//Shamelessly adapted from PPC32
Misha Brukman4633f1c2005-04-21 23:13:11 +0000563// Structure used to return the necessary information to codegen an SDIV as
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000564// a multiply.
565struct ms {
566 int64_t m; // magic number
567 int64_t s; // shift amount
568};
569
570struct mu {
571 uint64_t m; // magic number
572 int64_t a; // add indicator
573 int64_t s; // shift amount
574};
575
576/// magic - calculate the magic numbers required to codegen an integer sdiv as
Misha Brukman4633f1c2005-04-21 23:13:11 +0000577/// a sequence of multiply and shifts. Requires that the divisor not be 0, 1,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000578/// or -1.
579static struct ms magic(int64_t d) {
580 int64_t p;
581 uint64_t ad, anc, delta, q1, r1, q2, r2, t;
582 const uint64_t two63 = 9223372036854775808ULL; // 2^63
583 struct ms mag;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000584
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000585 ad = abs(d);
586 t = two63 + ((uint64_t)d >> 63);
587 anc = t - 1 - t%ad; // absolute value of nc
Andrew Lenharth320174f2005-04-07 17:19:16 +0000588 p = 63; // initialize p
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000589 q1 = two63/anc; // initialize q1 = 2p/abs(nc)
590 r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc))
591 q2 = two63/ad; // initialize q2 = 2p/abs(d)
592 r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d))
593 do {
594 p = p + 1;
595 q1 = 2*q1; // update q1 = 2p/abs(nc)
596 r1 = 2*r1; // update r1 = rem(2p/abs(nc))
597 if (r1 >= anc) { // must be unsigned comparison
598 q1 = q1 + 1;
599 r1 = r1 - anc;
600 }
601 q2 = 2*q2; // update q2 = 2p/abs(d)
602 r2 = 2*r2; // update r2 = rem(2p/abs(d))
603 if (r2 >= ad) { // must be unsigned comparison
604 q2 = q2 + 1;
605 r2 = r2 - ad;
606 }
607 delta = ad - r2;
608 } while (q1 < delta || (q1 == delta && r1 == 0));
609
610 mag.m = q2 + 1;
611 if (d < 0) mag.m = -mag.m; // resulting magic number
612 mag.s = p - 64; // resulting shift
613 return mag;
614}
615
616/// magicu - calculate the magic numbers required to codegen an integer udiv as
617/// a sequence of multiply, add and shifts. Requires that the divisor not be 0.
618static struct mu magicu(uint64_t d)
619{
620 int64_t p;
621 uint64_t nc, delta, q1, r1, q2, r2;
622 struct mu magu;
623 magu.a = 0; // initialize "add" indicator
624 nc = - 1 - (-d)%d;
Andrew Lenharth320174f2005-04-07 17:19:16 +0000625 p = 63; // initialize p
626 q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc
627 r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc)
628 q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d
629 r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d)
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000630 do {
631 p = p + 1;
632 if (r1 >= nc - r1 ) {
633 q1 = 2*q1 + 1; // update q1
634 r1 = 2*r1 - nc; // update r1
635 }
636 else {
637 q1 = 2*q1; // update q1
638 r1 = 2*r1; // update r1
639 }
640 if (r2 + 1 >= d - r2) {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000641 if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000642 q2 = 2*q2 + 1; // update q2
643 r2 = 2*r2 + 1 - d; // update r2
644 }
645 else {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000646 if (q2 >= 0x8000000000000000ull) magu.a = 1;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000647 q2 = 2*q2; // update q2
648 r2 = 2*r2 + 1; // update r2
649 }
650 delta = d - 1 - r2;
651 } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0)));
652 magu.m = q2 + 1; // resulting magic number
Andrew Lenharth320174f2005-04-07 17:19:16 +0000653 magu.s = p - 64; // resulting shift
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000654 return magu;
655}
656
657/// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant,
658/// return a DAG expression to select that will generate the same value by
659/// multiplying by a magic number. See:
660/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
661SDOperand ISel::BuildSDIVSequence(SDOperand N) {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000662 int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000663 ms magics = magic(d);
664 // Multiply the numerator (operand 0) by the magic value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000665 SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0),
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000666 ISelDAG->getConstant(magics.m, MVT::i64));
667 // If d > 0 and m < 0, add the numerator
668 if (d > 0 && magics.m < 0)
669 Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0));
670 // If d < 0 and m > 0, subtract the numerator.
671 if (d < 0 && magics.m > 0)
672 Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0));
673 // Shift right algebraic if shift value is nonzero
674 if (magics.s > 0)
Misha Brukman4633f1c2005-04-21 23:13:11 +0000675 Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000676 ISelDAG->getConstant(magics.s, MVT::i64));
677 // Extract the sign bit and add it to the quotient
Misha Brukman4633f1c2005-04-21 23:13:11 +0000678 SDOperand T =
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000679 ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64));
680 return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T);
681}
682
683/// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
684/// return a DAG expression to select that will generate the same value by
685/// multiplying by a magic number. See:
686/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
687SDOperand ISel::BuildUDIVSequence(SDOperand N) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000688 unsigned d =
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000689 (unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
690 mu magics = magicu(d);
691 // Multiply the numerator (operand 0) by the magic value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000692 SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0),
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000693 ISelDAG->getConstant(magics.m, MVT::i64));
694 if (magics.a == 0) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000695 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000696 ISelDAG->getConstant(magics.s, MVT::i64));
697 } else {
698 SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000699 NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000700 ISelDAG->getConstant(1, MVT::i64));
701 NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000702 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000703 ISelDAG->getConstant(magics.s-1, MVT::i64));
704 }
705 return Q;
706}
707
Andrew Lenhartha565c272005-04-06 22:03:13 +0000708//From PPC32
709/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
710/// returns zero when the input is not exactly a power of two.
711static unsigned ExactLog2(uint64_t Val) {
712 if (Val == 0 || (Val & (Val-1))) return 0;
713 unsigned Count = 0;
714 while (Val != 1) {
715 Val >>= 1;
716 ++Count;
717 }
718 return Count;
719}
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000720
721
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000722//These describe LDAx
Andrew Lenharthc0513832005-03-29 19:24:04 +0000723static const int IMM_LOW = -32768;
724static const int IMM_HIGH = 32767;
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000725static const int IMM_MULT = 65536;
726
727static long getUpper16(long l)
728{
729 long y = l / IMM_MULT;
730 if (l % IMM_MULT > IMM_HIGH)
731 ++y;
732 return y;
733}
734
735static long getLower16(long l)
736{
737 long h = getUpper16(l);
738 return l - h * IMM_MULT;
739}
740
Andrew Lenharth65838902005-02-06 16:22:15 +0000741static unsigned GetSymVersion(unsigned opcode)
742{
743 switch (opcode) {
744 default: assert(0 && "unknown load or store"); return 0;
745 case Alpha::LDQ: return Alpha::LDQ_SYM;
746 case Alpha::LDS: return Alpha::LDS_SYM;
747 case Alpha::LDT: return Alpha::LDT_SYM;
748 case Alpha::LDL: return Alpha::LDL_SYM;
749 case Alpha::LDBU: return Alpha::LDBU_SYM;
750 case Alpha::LDWU: return Alpha::LDWU_SYM;
751 case Alpha::LDW: return Alpha::LDW_SYM;
752 case Alpha::LDB: return Alpha::LDB_SYM;
753 case Alpha::STQ: return Alpha::STQ_SYM;
754 case Alpha::STS: return Alpha::STS_SYM;
755 case Alpha::STT: return Alpha::STT_SYM;
756 case Alpha::STL: return Alpha::STL_SYM;
757 case Alpha::STW: return Alpha::STW_SYM;
758 case Alpha::STB: return Alpha::STB_SYM;
759 }
760}
761
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000762void ISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
763{
764 unsigned Opc;
765 if (EnableAlphaFTOI) {
766 Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
767 BuildMI(BB, Opc, 1, dst).addReg(src);
768 } else {
769 //The hard way:
770 // Spill the integer to memory and reload it from there.
771 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
772 MachineFunction *F = BB->getParent();
773 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
774
775 Opc = isDouble ? Alpha::STT : Alpha::STS;
776 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
777 Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
778 BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
779 }
780}
781
782void ISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
783{
784 unsigned Opc;
785 if (EnableAlphaFTOI) {
786 Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
787 BuildMI(BB, Opc, 1, dst).addReg(src);
788 } else {
789 //The hard way:
790 // Spill the integer to memory and reload it from there.
791 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
792 MachineFunction *F = BB->getParent();
793 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
794
795 Opc = isDouble ? Alpha::STQ : Alpha::STL;
796 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
797 Opc = isDouble ? Alpha::LDT : Alpha::LDS;
798 BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
799 }
800}
801
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000802bool ISel::SelectFPSetCC(SDOperand N, unsigned dst)
803{
804 SDNode *Node = N.Val;
805 unsigned Opc, Tmp1, Tmp2, Tmp3;
806 SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node);
807
808 //assert(SetCC->getOperand(0).getValueType() != MVT::f32 && "SetCC f32 should have been promoted");
809 bool rev = false;
810 bool inv = false;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000811
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000812 switch (SetCC->getCondition()) {
813 default: Node->dump(); assert(0 && "Unknown FP comparison!");
814 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
815 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
816 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
817 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
818 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
819 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
820 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000821
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000822 //FIXME: check for constant 0.0
823 ConstantFPSDNode *CN;
824 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
825 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
826 Tmp1 = Alpha::F31;
827 else
828 Tmp1 = SelectExpr(N.getOperand(0));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000829
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000830 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
831 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
832 Tmp2 = Alpha::F31;
833 else
Chris Lattner9c9183a2005-04-30 04:44:07 +0000834 Tmp2 = SelectExpr(N.getOperand(1));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000835
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000836 //Can only compare doubles, and dag won't promote for me
837 if (SetCC->getOperand(0).getValueType() == MVT::f32)
838 {
839 //assert(0 && "Setcc On float?\n");
840 std::cerr << "Setcc on float!\n";
841 Tmp3 = MakeReg(MVT::f64);
842 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
843 Tmp1 = Tmp3;
844 }
845 if (SetCC->getOperand(1).getValueType() == MVT::f32)
846 {
847 //assert (0 && "Setcc On float?\n");
848 std::cerr << "Setcc on float!\n";
849 Tmp3 = MakeReg(MVT::f64);
850 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
851 Tmp2 = Tmp3;
852 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000853
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000854 if (rev) std::swap(Tmp1, Tmp2);
855 //do the comparison
856 BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
857 return inv;
858}
859
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000860//Check to see if the load is a constant offset from a base register
861void ISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
862{
863 unsigned opcode = N.getOpcode();
864 if (opcode == ISD::ADD) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000865 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000866 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
867 { //Normal imm add
868 Reg = SelectExpr(N.getOperand(0));
869 offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
870 return;
871 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000872 else if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000873 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 32767)
874 {
875 Reg = SelectExpr(N.getOperand(1));
876 offset = cast<ConstantSDNode>(N.getOperand(0))->getValue();
877 return;
878 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000879 }
880 Reg = SelectExpr(N);
881 offset = 0;
882 return;
883}
884
Andrew Lenharth445171a2005-02-08 00:40:03 +0000885void ISel::SelectBranchCC(SDOperand N)
886{
887 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
Misha Brukman4633f1c2005-04-21 23:13:11 +0000888 MachineBasicBlock *Dest =
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000889 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
890 unsigned Opc = Alpha::WTF;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000891
Andrew Lenharth445171a2005-02-08 00:40:03 +0000892 Select(N.getOperand(0)); //chain
893 SDOperand CC = N.getOperand(1);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000894
Andrew Lenharth445171a2005-02-08 00:40:03 +0000895 if (CC.getOpcode() == ISD::SETCC)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000896 {
897 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
898 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
899 //Dropping the CC is only useful if we are comparing to 0
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000900 bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
901 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
902 bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
903 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000904 bool isNE = false;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000905
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000906 //Fix up CC
907 ISD::CondCode cCode= SetCC->getCondition();
908 if (LeftZero && !RightZero) //Swap Operands
909 cCode = ISD::getSetCCSwappedOperands(cCode);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000910
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000911 if(cCode == ISD::SETNE)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000912 isNE = true;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000913
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000914 if (LeftZero || RightZero) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000915 switch (SetCC->getCondition()) {
916 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
917 case ISD::SETEQ: Opc = Alpha::BEQ; break;
918 case ISD::SETLT: Opc = Alpha::BLT; break;
919 case ISD::SETLE: Opc = Alpha::BLE; break;
920 case ISD::SETGT: Opc = Alpha::BGT; break;
921 case ISD::SETGE: Opc = Alpha::BGE; break;
922 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
923 case ISD::SETUGT: Opc = Alpha::BNE; break;
924 case ISD::SETULE: Opc = Alpha::BEQ; break; //Technically you could have this CC
925 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
926 case ISD::SETNE: Opc = Alpha::BNE; break;
927 }
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000928 unsigned Tmp1;
929 if(LeftZero && !RightZero) //swap Operands
930 Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond
931 else
932 Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000933 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
934 return;
935 } else {
936 unsigned Tmp1 = SelectExpr(CC);
937 if (isNE)
938 BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
939 else
940 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000941 return;
942 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000943 } else { //FP
944 //Any comparison between 2 values should be codegened as an folded branch, as moving
945 //CC to the integer register is very expensive
946 //for a cmp b: c = a - b;
947 //a = b: c = 0
948 //a < b: c < 0
949 //a > b: c > 0
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000950
951 bool invTest = false;
952 unsigned Tmp3;
953
954 ConstantFPSDNode *CN;
955 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
956 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
957 Tmp3 = SelectExpr(SetCC->getOperand(0));
958 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
959 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
960 {
961 Tmp3 = SelectExpr(SetCC->getOperand(1));
962 invTest = true;
963 }
964 else
965 {
966 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
967 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
968 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
969 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
970 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
971 .addReg(Tmp1).addReg(Tmp2);
972 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000973
974 switch (SetCC->getCondition()) {
975 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000976 case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
977 case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
978 case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
979 case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
980 case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
981 case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000982 }
983 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000984 return;
985 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000986 abort(); //Should never be reached
987 } else {
988 //Giveup and do the stupid thing
989 unsigned Tmp1 = SelectExpr(CC);
990 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
991 return;
992 }
Andrew Lenharth445171a2005-02-08 00:40:03 +0000993 abort(); //Should never be reached
994}
995
Andrew Lenharth40831c52005-01-28 06:57:18 +0000996unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
997{
998 unsigned Tmp1, Tmp2, Tmp3;
999 unsigned Opc = 0;
1000 SDNode *Node = N.Val;
1001 MVT::ValueType DestType = N.getValueType();
1002 unsigned opcode = N.getOpcode();
1003
1004 switch (opcode) {
1005 default:
1006 Node->dump();
1007 assert(0 && "Node not handled!\n");
Andrew Lenharth2c594352005-01-29 15:42:07 +00001008
Andrew Lenharth7332f3e2005-04-02 19:11:07 +00001009 case ISD::UNDEF: {
1010 BuildMI(BB, Alpha::IDEF, 0, Result);
1011 return Result;
1012 }
1013
Andrew Lenharth30b46d42005-04-02 19:04:58 +00001014 case ISD::FNEG:
1015 if(ISD::FABS == N.getOperand(0).getOpcode())
1016 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001017 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1018 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharth30b46d42005-04-02 19:04:58 +00001019 } else {
Misha Brukman7847fca2005-04-22 17:54:37 +00001020 Tmp1 = SelectExpr(N.getOperand(0));
1021 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth30b46d42005-04-02 19:04:58 +00001022 }
1023 return Result;
1024
1025 case ISD::FABS:
1026 Tmp1 = SelectExpr(N.getOperand(0));
1027 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
1028 return Result;
1029
Andrew Lenharth9818c052005-02-05 13:19:12 +00001030 case ISD::SELECT:
1031 {
Andrew Lenharth45859692005-03-03 21:47:53 +00001032 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1033 unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE
1034 unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE
1035
1036 SDOperand CC = N.getOperand(0);
1037 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
1038
Misha Brukman4633f1c2005-04-21 23:13:11 +00001039 if (CC.getOpcode() == ISD::SETCC &&
Andrew Lenharth45859692005-03-03 21:47:53 +00001040 !MVT::isInteger(SetCC->getOperand(0).getValueType()))
1041 { //FP Setcc -> Select yay!
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001042
1043
Andrew Lenharth45859692005-03-03 21:47:53 +00001044 //for a cmp b: c = a - b;
1045 //a = b: c = 0
1046 //a < b: c < 0
1047 //a > b: c > 0
Misha Brukman4633f1c2005-04-21 23:13:11 +00001048
Andrew Lenharth45859692005-03-03 21:47:53 +00001049 bool invTest = false;
1050 unsigned Tmp3;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001051
Andrew Lenharth45859692005-03-03 21:47:53 +00001052 ConstantFPSDNode *CN;
1053 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
1054 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1055 Tmp3 = SelectExpr(SetCC->getOperand(0));
1056 else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
1057 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1058 {
1059 Tmp3 = SelectExpr(SetCC->getOperand(1));
1060 invTest = true;
1061 }
1062 else
1063 {
1064 unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
1065 unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
1066 bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
1067 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
1068 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
1069 .addReg(Tmp1).addReg(Tmp2);
1070 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001071
Andrew Lenharth45859692005-03-03 21:47:53 +00001072 switch (SetCC->getCondition()) {
1073 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
1074 case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break;
1075 case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break;
1076 case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break;
1077 case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break;
1078 case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break;
1079 case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break;
1080 }
Andrew Lenharth33819132005-03-04 20:09:23 +00001081 BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3);
Andrew Lenharth45859692005-03-03 21:47:53 +00001082 return Result;
1083 }
1084 else
1085 {
1086 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001087 BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV).addReg(Tmp1);
1088// // Spill the cond to memory and reload it from there.
1089// unsigned Tmp4 = MakeReg(MVT::f64);
1090// MoveIntFP(Tmp1, Tmp4, true);
1091// //now ideally, we don't have to do anything to the flag...
1092// // Get the condition into the zero flag.
1093// BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4);
Andrew Lenharth45859692005-03-03 21:47:53 +00001094 return Result;
1095 }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001096 }
1097
Andrew Lenharthc1faced2005-02-01 01:37:24 +00001098 case ISD::FP_ROUND:
Misha Brukman4633f1c2005-04-21 23:13:11 +00001099 assert (DestType == MVT::f32 &&
1100 N.getOperand(0).getValueType() == MVT::f64 &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001101 "only f64 to f32 conversion supported here");
Andrew Lenharthc1faced2005-02-01 01:37:24 +00001102 Tmp1 = SelectExpr(N.getOperand(0));
1103 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
1104 return Result;
1105
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001106 case ISD::FP_EXTEND:
Misha Brukman4633f1c2005-04-21 23:13:11 +00001107 assert (DestType == MVT::f64 &&
1108 N.getOperand(0).getValueType() == MVT::f32 &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001109 "only f32 to f64 conversion supported here");
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001110 Tmp1 = SelectExpr(N.getOperand(0));
1111 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
1112 return Result;
1113
Andrew Lenharth2c594352005-01-29 15:42:07 +00001114 case ISD::CopyFromReg:
1115 {
1116 // Make sure we generate both values.
1117 if (Result != notIn)
1118 ExprMap[N.getValue(1)] = notIn; // Generate the token
1119 else
1120 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001121
Andrew Lenharth2c594352005-01-29 15:42:07 +00001122 SDOperand Chain = N.getOperand(0);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001123
Andrew Lenharth2c594352005-01-29 15:42:07 +00001124 Select(Chain);
1125 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1126 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1127 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
1128 return Result;
1129 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001130
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001131 case ISD::LOAD:
1132 {
1133 // Make sure we generate both values.
1134 if (Result != notIn)
Misha Brukman7847fca2005-04-22 17:54:37 +00001135 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001136 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001137 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Andrew Lenharth12dd2622005-02-03 21:01:15 +00001138
Andrew Lenharth29219162005-02-07 06:31:44 +00001139 DestType = N.getValue(0).getValueType();
Andrew Lenharth12dd2622005-02-03 21:01:15 +00001140
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001141 SDOperand Chain = N.getOperand(0);
1142 SDOperand Address = N.getOperand(1);
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001143 Select(Chain);
Andrew Lenharth65838902005-02-06 16:22:15 +00001144 Opc = DestType == MVT::f64 ? Alpha::LDT : Alpha::LDS;
1145
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +00001146 if (EnableAlphaLSMark)
1147 {
1148 int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue());
1149 BuildMI(BB, Alpha::MEMLABEL, 2).addImm(i);
1150 }
1151
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001152 if (Address.getOpcode() == ISD::GlobalAddress) {
1153 AlphaLowering.restoreGP(BB);
1154 Opc = GetSymVersion(Opc);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001155 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001156 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1157 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001158 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001159 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +00001160 Opc = GetSymVersion(Opc);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001161 has_sym = true;
Andrew Lenharth97127a12005-02-05 17:41:39 +00001162 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001163 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001164 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001165 BuildMI(BB, Opc, 2, Result)
1166 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1167 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001168 } else {
1169 long offset;
1170 SelectAddr(Address, Tmp1, offset);
1171 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
1172 }
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001173 return Result;
1174 }
Andrew Lenharth40831c52005-01-28 06:57:18 +00001175 case ISD::ConstantFP:
1176 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
1177 if (CN->isExactlyValue(+0.0)) {
1178 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth12dd2622005-02-03 21:01:15 +00001179 } else if ( CN->isExactlyValue(-0.0)) {
1180 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Alpha::F31);
Andrew Lenharth40831c52005-01-28 06:57:18 +00001181 } else {
1182 abort();
1183 }
1184 }
1185 return Result;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001186
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001187 case ISD::SDIV:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001188 case ISD::MUL:
1189 case ISD::ADD:
1190 case ISD::SUB:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001191 switch( opcode ) {
1192 case ISD::MUL: Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS; break;
1193 case ISD::ADD: Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS; break;
1194 case ISD::SUB: Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS; break;
1195 case ISD::SDIV: Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS; break;
1196 };
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001197
1198 ConstantFPSDNode *CN;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001199 if (opcode == ISD::SUB
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00001200 && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
1201 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1202 {
1203 Tmp2 = SelectExpr(N.getOperand(1));
1204 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
1205 } else {
1206 Tmp1 = SelectExpr(N.getOperand(0));
1207 Tmp2 = SelectExpr(N.getOperand(1));
1208 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1209 }
Andrew Lenharth40831c52005-01-28 06:57:18 +00001210 return Result;
1211
Andrew Lenharth2c594352005-01-29 15:42:07 +00001212 case ISD::EXTLOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001213 {
1214 //include a conversion sequence for float loads to double
1215 if (Result != notIn)
1216 ExprMap[N.getValue(1)] = notIn; // Generate the token
1217 else
1218 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001219
Andrew Lenhartha549deb2005-02-07 05:33:15 +00001220 Tmp1 = MakeReg(MVT::f32);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001221
1222 assert(cast<MVTSDNode>(Node)->getExtraValueType() == MVT::f32 &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001223 "EXTLOAD not from f32");
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001224 assert(Node->getValueType(0) == MVT::f64 && "EXTLOAD not to f64");
Misha Brukman4633f1c2005-04-21 23:13:11 +00001225
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001226 SDOperand Chain = N.getOperand(0);
1227 SDOperand Address = N.getOperand(1);
1228 Select(Chain);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001229
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001230 if (Address.getOpcode() == ISD::GlobalAddress) {
1231 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001232 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001233 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1234 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001235 else if (ConstantPoolSDNode *CP =
1236 dyn_cast<ConstantPoolSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001237 {
1238 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001239 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001240 BuildMI(BB, Alpha::LDS_SYM, 1, Tmp1).addConstantPoolIndex(CP->getIndex());
1241 }
1242 else if(Address.getOpcode() == ISD::FrameIndex) {
1243 Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
Andrew Lenharth032f2352005-02-22 21:59:48 +00001244 BuildMI(BB, Alpha::LDS, 2, Tmp1)
1245 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1246 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001247 } else {
1248 long offset;
1249 SelectAddr(Address, Tmp2, offset);
1250 BuildMI(BB, Alpha::LDS, 1, Tmp1).addImm(offset).addReg(Tmp2);
1251 }
Andrew Lenharth29219162005-02-07 06:31:44 +00001252 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
Andrew Lenharth12dd2622005-02-03 21:01:15 +00001253 return Result;
1254 }
Andrew Lenharth2c594352005-01-29 15:42:07 +00001255
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001256 case ISD::UINT_TO_FP:
Andrew Lenharth69520ed2005-05-26 18:18:34 +00001257 {
1258 //FIXME: First test if we will have problems with the sign bit before doing the slow thing
1259 assert (N.getOperand(0).getValueType() == MVT::i64
1260 && "only quads can be loaded from");
1261 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
1262 Tmp2 = MakeReg(MVT::i64);
1263 BuildMI(BB, Alpha::SRL, 2, Tmp2).addReg(Tmp1).addImm(1);
1264 Tmp3 = MakeReg(MVT::i64);
1265 BuildMI(BB, Alpha::CMPLT, 2, Tmp3).addReg(Tmp1).addReg(Alpha::R31);
1266 unsigned Tmp4 = MakeReg(MVT::f64), Tmp5 = MakeReg(MVT::f64), Tmp6 = MakeReg(MVT::f64);
1267 MoveInt2FP(Tmp1, Tmp4, true);
1268 MoveInt2FP(Tmp2, Tmp5, true);
1269 MoveInt2FP(Tmp3, Tmp6, true);
1270 Tmp1 = MakeReg(MVT::f64);
1271 Tmp2 = MakeReg(MVT::f64);
1272 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
1273 BuildMI(BB, Opc, 1, Tmp1).addReg(Tmp4);
1274 BuildMI(BB, Opc, 1, Tmp2).addReg(Tmp5);
1275 Tmp3 = MakeReg(MVT::f64);
1276 BuildMI(BB, Alpha::ADDT, 2, Tmp3).addReg(Tmp2).addReg(Tmp2);
1277 //Ok, now tmp1 had the plain covereted
1278 //tmp3 has the reduced converted and added
1279 //tmp6 has the conditional to use
1280 BuildMI(BB, Alpha::FCMOVNE, 3, Result).addReg(Tmp1).addReg(Tmp3).addReg(Tmp6);
1281 return Result;
1282 }
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001283 case ISD::SINT_TO_FP:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001284 {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001285 assert (N.getOperand(0).getValueType() == MVT::i64
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001286 && "only quads can be loaded from");
Andrew Lenharth40831c52005-01-28 06:57:18 +00001287 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001288 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001289 MoveInt2FP(Tmp1, Tmp2, true);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001290 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
1291 BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
Andrew Lenharth40831c52005-01-28 06:57:18 +00001292 return Result;
1293 }
1294 }
1295 assert(0 && "should not get here");
1296 return 0;
1297}
1298
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001299unsigned ISel::SelectExpr(SDOperand N) {
1300 unsigned Result;
Andrew Lenharth2966e842005-04-07 18:15:28 +00001301 unsigned Tmp1, Tmp2 = 0, Tmp3;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001302 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001303 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001304
1305 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001306 MVT::ValueType DestType = N.getValueType();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001307
1308 unsigned &Reg = ExprMap[N];
1309 if (Reg) return Reg;
1310
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +00001311 if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL)
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001312 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001313 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001314 else {
1315 // If this is a call instruction, make sure to prepare ALL of the result
1316 // values as well as the chain.
1317 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001318 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001319 else {
1320 Result = MakeReg(Node->getValueType(0));
1321 ExprMap[N.getValue(0)] = Result;
1322 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
1323 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001324 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001325 }
1326 }
1327
Andrew Lenharth50d91d72005-04-30 14:19:13 +00001328 if ((DestType == MVT::f64 || DestType == MVT::f32 ||
1329 (
1330 (opcode == ISD::LOAD || opcode == ISD::CopyFromReg ||
1331 opcode == ISD::EXTLOAD) &&
1332 (N.getValue(0).getValueType() == MVT::f32 ||
1333 N.getValue(0).getValueType() == MVT::f64)
1334 ))
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +00001335 && opcode != ISD::CALL && opcode != ISD::TAILCALL
Andrew Lenharth06342c32005-02-07 06:21:37 +00001336 )
Andrew Lenharth40831c52005-01-28 06:57:18 +00001337 return SelectExprFP(N, Result);
1338
1339 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001340 default:
1341 Node->dump();
1342 assert(0 && "Node not handled!\n");
Misha Brukman4633f1c2005-04-21 23:13:11 +00001343
Andrew Lenharth691ef2b2005-05-03 17:19:30 +00001344 case ISD::CTPOP:
1345 case ISD::CTTZ:
1346 case ISD::CTLZ:
1347 Opc = opcode == ISD::CTPOP ? Alpha::CTPOP :
1348 (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ);
1349 Tmp1 = SelectExpr(N.getOperand(0));
1350 BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
1351 return Result;
1352
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001353 case ISD::MULHU:
1354 Tmp1 = SelectExpr(N.getOperand(0));
1355 Tmp2 = SelectExpr(N.getOperand(1));
1356 BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth706be912005-04-07 13:55:53 +00001357 return Result;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001358 case ISD::MULHS:
1359 {
1360 //MULHU - Ra<63>*Rb - Rb<63>*Ra
1361 Tmp1 = SelectExpr(N.getOperand(0));
1362 Tmp2 = SelectExpr(N.getOperand(1));
1363 Tmp3 = MakeReg(MVT::i64);
1364 BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1365 unsigned V1 = MakeReg(MVT::i64);
1366 unsigned V2 = MakeReg(MVT::i64);
1367 BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31).addReg(Tmp1);
1368 BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31).addReg(Tmp2);
1369 unsigned IRes = MakeReg(MVT::i64);
1370 BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1);
1371 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2);
1372 return Result;
1373 }
Andrew Lenharth7332f3e2005-04-02 19:11:07 +00001374 case ISD::UNDEF: {
1375 BuildMI(BB, Alpha::IDEF, 0, Result);
1376 return Result;
1377 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001378
Andrew Lenharth032f2352005-02-22 21:59:48 +00001379 case ISD::DYNAMIC_STACKALLOC:
1380 // Generate both result values.
Andrew Lenharth3a7118d2005-02-23 17:33:42 +00001381 if (Result != notIn)
1382 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth032f2352005-02-22 21:59:48 +00001383 else
1384 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
1385
1386 // FIXME: We are currently ignoring the requested alignment for handling
1387 // greater than the stack alignment. This will need to be revisited at some
1388 // point. Align = N.getOperand(2);
1389
1390 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
1391 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
1392 std::cerr << "Cannot allocate stack object with greater alignment than"
1393 << " the stack alignment yet!";
1394 abort();
1395 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001396
Andrew Lenharth032f2352005-02-22 21:59:48 +00001397 Select(N.getOperand(0));
1398 if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
1399 {
1400 if (CN->getValue() < 32000)
1401 {
1402 BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
1403 .addImm(-CN->getValue()).addReg(Alpha::R30);
1404 } else {
1405 Tmp1 = SelectExpr(N.getOperand(1));
1406 // Subtract size from stack pointer, thereby allocating some space.
1407 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
1408 }
1409 } else {
1410 Tmp1 = SelectExpr(N.getOperand(1));
1411 // Subtract size from stack pointer, thereby allocating some space.
1412 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
1413 }
1414
1415 // Put a pointer to the space into the result register, by copying the stack
1416 // pointer.
Andrew Lenharth7bc47022005-02-22 23:29:25 +00001417 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
Andrew Lenharth032f2352005-02-22 21:59:48 +00001418 return Result;
1419
Andrew Lenharth33819132005-03-04 20:09:23 +00001420// case ISD::ConstantPool:
1421// Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
1422// AlphaLowering.restoreGP(BB);
1423// BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(Tmp1);
1424// return Result;
Andrew Lenharth2c594352005-01-29 15:42:07 +00001425
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001426 case ISD::FrameIndex:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001427 BuildMI(BB, Alpha::LDA, 2, Result)
1428 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
1429 .addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001430 return Result;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001431
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001432 case ISD::EXTLOAD:
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001433 case ISD::ZEXTLOAD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001434 case ISD::SEXTLOAD:
Misha Brukman4633f1c2005-04-21 23:13:11 +00001435 case ISD::LOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001436 {
1437 // Make sure we generate both values.
1438 if (Result != notIn)
1439 ExprMap[N.getValue(1)] = notIn; // Generate the token
1440 else
1441 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001442
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001443 SDOperand Chain = N.getOperand(0);
1444 SDOperand Address = N.getOperand(1);
1445 Select(Chain);
1446
Misha Brukman4633f1c2005-04-21 23:13:11 +00001447 assert(Node->getValueType(0) == MVT::i64 &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001448 "Unknown type to sign extend to.");
Andrew Lenharth03824012005-02-07 05:55:55 +00001449 if (opcode == ISD::LOAD)
1450 Opc = Alpha::LDQ;
1451 else
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001452 switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
1453 default: Node->dump(); assert(0 && "Bad sign extend!");
Misha Brukman4633f1c2005-04-21 23:13:11 +00001454 case MVT::i32: Opc = Alpha::LDL;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001455 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001456 case MVT::i16: Opc = Alpha::LDWU;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001457 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharthf311e8b2005-02-07 05:18:02 +00001458 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Misha Brukman4633f1c2005-04-21 23:13:11 +00001459 case MVT::i8: Opc = Alpha::LDBU;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001460 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001461 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001462
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001463 if (Address.getOpcode() == ISD::GlobalAddress) {
1464 AlphaLowering.restoreGP(BB);
1465 Opc = GetSymVersion(Opc);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001466 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001467 BuildMI(BB, Opc, 1, Result).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
1468 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001469 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
1470 AlphaLowering.restoreGP(BB);
Andrew Lenharth65838902005-02-06 16:22:15 +00001471 Opc = GetSymVersion(Opc);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001472 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001473 BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001474 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001475 else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharth032f2352005-02-22 21:59:48 +00001476 BuildMI(BB, Opc, 2, Result)
1477 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1478 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001479 } else {
1480 long offset;
1481 SelectAddr(Address, Tmp1, offset);
1482 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
1483 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001484 return Result;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001485 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001486
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001487 case ISD::GlobalAddress:
1488 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001489 has_sym = true;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001490 BuildMI(BB, Alpha::LOAD_ADDR, 1, Result)
1491 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal());
1492 return Result;
1493
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +00001494 case ISD::TAILCALL:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001495 case ISD::CALL:
1496 {
1497 Select(N.getOperand(0));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001498
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001499 // The chain for this call is now lowered.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001500 ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001501
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001502 //grab the arguments
1503 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001504 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001505 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001506 argvregs.push_back(SelectExpr(N.getOperand(i)));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001507
Andrew Lenharth684f2292005-01-30 00:35:27 +00001508 //in reg args
1509 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001510 {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001511 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001512 Alpha::R19, Alpha::R20, Alpha::R21};
Misha Brukman4633f1c2005-04-21 23:13:11 +00001513 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001514 Alpha::F19, Alpha::F20, Alpha::F21};
1515 switch(N.getOperand(i+2).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001516 default:
1517 Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001518 N.getOperand(i).Val->dump();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001519 std::cerr << "Type for " << i << " is: " <<
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001520 N.getOperand(i+2).getValueType() << "\n";
1521 assert(0 && "Unknown value type for call");
1522 case MVT::i1:
1523 case MVT::i8:
1524 case MVT::i16:
1525 case MVT::i32:
1526 case MVT::i64:
1527 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i]).addReg(argvregs[i]);
1528 break;
1529 case MVT::f32:
1530 case MVT::f64:
1531 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i]).addReg(argvregs[i]);
1532 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +00001533 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001534 }
Andrew Lenharth684f2292005-01-30 00:35:27 +00001535 //in mem args
1536 for (int i = 6, e = argvregs.size(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001537 {
1538 switch(N.getOperand(i+2).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001539 default:
1540 Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001541 N.getOperand(i).Val->dump();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001542 std::cerr << "Type for " << i << " is: " <<
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001543 N.getOperand(i+2).getValueType() << "\n";
1544 assert(0 && "Unknown value type for call");
1545 case MVT::i1:
1546 case MVT::i8:
1547 case MVT::i16:
1548 case MVT::i32:
1549 case MVT::i64:
1550 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1551 break;
1552 case MVT::f32:
1553 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1554 break;
1555 case MVT::f64:
1556 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8).addReg(Alpha::R30);
1557 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +00001558 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001559 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001560 //build the right kind of call
1561 if (GlobalAddressSDNode *GASD =
Misha Brukman4633f1c2005-04-21 23:13:11 +00001562 dyn_cast<GlobalAddressSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001563 {
Andrew Lenharthc24b5372005-04-13 17:17:28 +00001564 if (GASD->getGlobal()->isExternal()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001565 //use safe calling convention
Andrew Lenharth7b2a5272005-01-30 20:42:36 +00001566 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001567 has_sym = true;
Andrew Lenharthc24b5372005-04-13 17:17:28 +00001568 BuildMI(BB, Alpha::CALL, 1).addGlobalAddress(GASD->getGlobal());
1569 } else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001570 //use PC relative branch call
Andrew Lenharth1e0d9bd2005-04-14 17:34:20 +00001571 AlphaLowering.restoreGP(BB);
Andrew Lenharthc24b5372005-04-13 17:17:28 +00001572 BuildMI(BB, Alpha::BSR, 1, Alpha::R26).addGlobalAddress(GASD->getGlobal(),true);
1573 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001574 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001575 else if (ExternalSymbolSDNode *ESSDN =
Misha Brukman4633f1c2005-04-21 23:13:11 +00001576 dyn_cast<ExternalSymbolSDNode>(N.getOperand(1)))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001577 {
1578 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001579 has_sym = true;
Andrew Lenharthba05ad62005-03-30 18:22:52 +00001580 BuildMI(BB, Alpha::CALL, 1).addExternalSymbol(ESSDN->getSymbol(), true);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001581 } else {
1582 //no need to restore GP as we are doing an indirect call
1583 Tmp1 = SelectExpr(N.getOperand(1));
1584 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
1585 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
1586 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001587
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001588 //push the result into a virtual register
Misha Brukman4633f1c2005-04-21 23:13:11 +00001589
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001590 switch (Node->getValueType(0)) {
1591 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001592 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001593 case MVT::i1:
1594 case MVT::i8:
1595 case MVT::i16:
1596 case MVT::i32:
1597 case MVT::i64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001598 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
1599 break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001600 case MVT::f32:
1601 case MVT::f64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001602 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
1603 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001604 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001605 return Result+N.ResNo;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001606 }
1607
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001608 case ISD::SIGN_EXTEND_INREG:
1609 {
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001610 //do SDIV opt for all levels of ints if not dividing by a constant
1611 if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV
1612 && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant)
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001613 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001614 unsigned Tmp4 = MakeReg(MVT::f64);
1615 unsigned Tmp5 = MakeReg(MVT::f64);
1616 unsigned Tmp6 = MakeReg(MVT::f64);
1617 unsigned Tmp7 = MakeReg(MVT::f64);
1618 unsigned Tmp8 = MakeReg(MVT::f64);
1619 unsigned Tmp9 = MakeReg(MVT::f64);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001620
1621 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1622 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1623 MoveInt2FP(Tmp1, Tmp4, true);
1624 MoveInt2FP(Tmp2, Tmp5, true);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001625 BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4);
1626 BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5);
1627 BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
1628 BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001629 MoveFP2Int(Tmp9, Result, true);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001630 return Result;
1631 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001632
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001633 //Alpha has instructions for a bunch of signed 32 bit stuff
1634 if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001635 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001636 switch (N.getOperand(0).getOpcode()) {
1637 case ISD::ADD:
1638 case ISD::SUB:
1639 case ISD::MUL:
1640 {
1641 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
1642 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
1643 //FIXME: first check for Scaled Adds and Subs!
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001644 ConstantSDNode* CSD = NULL;
1645 if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL &&
1646 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(0).getOperand(1))) &&
1647 (CSD->getValue() == 2 || CSD->getValue() == 3))
1648 {
1649 bool use4 = CSD->getValue() == 2;
1650 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1651 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1652 BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL),
1653 2,Result).addReg(Tmp1).addReg(Tmp2);
1654 }
1655 else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL &&
1656 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1).getOperand(1))) &&
1657 (CSD->getValue() == 2 || CSD->getValue() == 3))
1658 {
1659 bool use4 = CSD->getValue() == 2;
1660 Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
1661 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1662 BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2);
1663 }
1664 else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001665 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
1666 { //Normal imm add/sub
1667 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001668 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001669 Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
1670 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001671 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001672 else
1673 { //Normal add/sub
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001674 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001675 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001676 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001677 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1678 }
1679 return Result;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001680 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001681 default: break; //Fall Though;
1682 }
1683 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001684 Tmp1 = SelectExpr(N.getOperand(0));
1685 MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001686 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001687 switch(MVN->getExtraValueType())
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001688 {
1689 default:
1690 Node->dump();
1691 assert(0 && "Sign Extend InReg not there yet");
1692 break;
1693 case MVT::i32:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001694 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001695 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001696 break;
1697 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001698 case MVT::i16:
1699 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
1700 break;
1701 case MVT::i8:
1702 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
1703 break;
Andrew Lenharthebce5042005-02-12 19:35:12 +00001704 case MVT::i1:
1705 Tmp2 = MakeReg(MVT::i64);
1706 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001707 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2);
Andrew Lenharthebce5042005-02-12 19:35:12 +00001708 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001709 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001710 return Result;
1711 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001712
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001713 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001714 {
1715 if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
1716 if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
1717 bool isConst1 = false;
1718 bool isConst2 = false;
1719 int dir;
Misha Brukman7847fca2005-04-22 17:54:37 +00001720
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001721 //Tmp1 = SelectExpr(N.getOperand(0));
1722 if(N.getOperand(0).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001723 cast<ConstantSDNode>(N.getOperand(0))->getValue() <= 255)
1724 isConst1 = true;
1725 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001726 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
1727 isConst2 = true;
1728
1729 switch (SetCC->getCondition()) {
1730 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1731 case ISD::SETEQ: Opc = Alpha::CMPEQ; dir=0; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001732 case ISD::SETLT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001733 Opc = isConst2 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001734 case ISD::SETLE:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001735 Opc = isConst2 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001736 case ISD::SETGT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001737 Opc = isConst1 ? Alpha::CMPLTi : Alpha::CMPLT; dir = 2; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001738 case ISD::SETGE:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001739 Opc = isConst1 ? Alpha::CMPLEi : Alpha::CMPLE; dir = 2; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001740 case ISD::SETULT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001741 Opc = isConst2 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001742 case ISD::SETUGT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001743 Opc = isConst1 ? Alpha::CMPULTi : Alpha::CMPULT; dir = 2; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001744 case ISD::SETULE:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001745 Opc = isConst2 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001746 case ISD::SETUGE:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001747 Opc = isConst1 ? Alpha::CMPULEi : Alpha::CMPULE; dir = 2; break;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001748 case ISD::SETNE: {//Handle this one special
1749 //std::cerr << "Alpha does not have a setne.\n";
1750 //abort();
1751 Tmp1 = SelectExpr(N.getOperand(0));
1752 Tmp2 = SelectExpr(N.getOperand(1));
1753 Tmp3 = MakeReg(MVT::i64);
1754 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth445171a2005-02-08 00:40:03 +00001755 //Remeber we have the Inv for this CC
1756 CCInvMap[N] = Tmp3;
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001757 //and invert
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001758 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001759 return Result;
1760 }
1761 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001762 if (dir == 1) {
1763 Tmp1 = SelectExpr(N.getOperand(0));
1764 if (isConst2) {
1765 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1766 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1767 } else {
1768 Tmp2 = SelectExpr(N.getOperand(1));
1769 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1770 }
1771 } else if (dir == 2) {
1772 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001773 if (isConst1) {
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001774 Tmp2 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1775 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1776 } else {
1777 Tmp2 = SelectExpr(N.getOperand(0));
1778 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1779 }
1780 } else { //dir == 0
1781 if (isConst1) {
1782 Tmp1 = cast<ConstantSDNode>(N.getOperand(0))->getValue();
1783 Tmp2 = SelectExpr(N.getOperand(1));
1784 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp2).addImm(Tmp1);
1785 } else if (isConst2) {
1786 Tmp1 = SelectExpr(N.getOperand(0));
1787 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1788 BuildMI(BB, Alpha::CMPEQi, 2, Result).addReg(Tmp1).addImm(Tmp2);
1789 } else {
1790 Tmp1 = SelectExpr(N.getOperand(0));
1791 Tmp2 = SelectExpr(N.getOperand(1));
1792 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Tmp1).addReg(Tmp2);
1793 }
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001794 }
1795 } else {
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001796 //do the comparison
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001797 Tmp1 = MakeReg(MVT::f64);
1798 bool inv = SelectFPSetCC(N, Tmp1);
1799
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001800 //now arrange for Result (int) to have a 1 or 0
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001801 Tmp2 = MakeReg(MVT::i64);
1802 BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001803 Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001804 BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001805 }
Andrew Lenharth9818c052005-02-05 13:19:12 +00001806 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001807 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001808 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001809
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001810 case ISD::CopyFromReg:
1811 {
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001812 ++count_ins;
1813
Andrew Lenharth40831c52005-01-28 06:57:18 +00001814 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001815 if (Result != notIn)
Misha Brukman7847fca2005-04-22 17:54:37 +00001816 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +00001817 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001818 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001819
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001820 SDOperand Chain = N.getOperand(0);
1821
1822 Select(Chain);
1823 unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
1824 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
1825 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
1826 return Result;
1827 }
1828
Misha Brukman4633f1c2005-04-21 23:13:11 +00001829 //Most of the plain arithmetic and logic share the same form, and the same
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001830 //constant immediate test
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001831 case ISD::XOR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001832 //Match Not
1833 if (N.getOperand(1).getOpcode() == ISD::Constant &&
Misha Brukman7847fca2005-04-22 17:54:37 +00001834 cast<ConstantSDNode>(N.getOperand(1))->getSignExtended() == -1)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001835 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001836 Tmp1 = SelectExpr(N.getOperand(0));
1837 BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
1838 return Result;
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001839 }
1840 //Fall through
1841 case ISD::AND:
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001842 //handle zap
1843 if (opcode == ISD::AND && N.getOperand(1).getOpcode() == ISD::Constant)
1844 {
1845 uint64_t k = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1846 unsigned int build = 0;
1847 for(int i = 0; i < 8; ++i)
1848 {
Andrew Lenharth3ae18292005-04-14 16:24:00 +00001849 if ((k & 0x00FF) == 0x00FF)
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001850 build |= 1 << i;
Andrew Lenharth3ae18292005-04-14 16:24:00 +00001851 else if ((k & 0x00FF) != 0)
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001852 { build = 0; break; }
1853 k >>= 8;
1854 }
1855 if (build)
1856 {
1857 Tmp1 = SelectExpr(N.getOperand(0));
1858 BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build);
1859 return Result;
1860 }
1861 }
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001862 case ISD::OR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001863 //Check operand(0) == Not
Misha Brukman4633f1c2005-04-21 23:13:11 +00001864 if (N.getOperand(0).getOpcode() == ISD::XOR &&
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001865 N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
Misha Brukman7847fca2005-04-22 17:54:37 +00001866 cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getSignExtended() == -1)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001867 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001868 switch(opcode) {
1869 case ISD::AND: Opc = Alpha::BIC; break;
1870 case ISD::OR: Opc = Alpha::ORNOT; break;
1871 case ISD::XOR: Opc = Alpha::EQV; break;
1872 }
1873 Tmp1 = SelectExpr(N.getOperand(1));
1874 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1875 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1876 return Result;
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001877 }
1878 //Check operand(1) == Not
Misha Brukman4633f1c2005-04-21 23:13:11 +00001879 if (N.getOperand(1).getOpcode() == ISD::XOR &&
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001880 N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant &&
Misha Brukman7847fca2005-04-22 17:54:37 +00001881 cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getSignExtended() == -1)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001882 {
Misha Brukman7847fca2005-04-22 17:54:37 +00001883 switch(opcode) {
1884 case ISD::AND: Opc = Alpha::BIC; break;
1885 case ISD::OR: Opc = Alpha::ORNOT; break;
1886 case ISD::XOR: Opc = Alpha::EQV; break;
1887 }
1888 Tmp1 = SelectExpr(N.getOperand(0));
1889 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
1890 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1891 return Result;
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001892 }
1893 //Fall through
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001894 case ISD::SHL:
1895 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +00001896 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001897 case ISD::MUL:
Andrew Lenharth40831c52005-01-28 06:57:18 +00001898 assert (DestType == MVT::i64 && "Only do arithmetic on i64s!");
1899 if(N.getOperand(1).getOpcode() == ISD::Constant &&
Andrew Lenharth40831c52005-01-28 06:57:18 +00001900 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001901 {
1902 switch(opcode) {
1903 case ISD::AND: Opc = Alpha::ANDi; break;
1904 case ISD::OR: Opc = Alpha::BISi; break;
1905 case ISD::XOR: Opc = Alpha::XORi; break;
1906 case ISD::SHL: Opc = Alpha::SLi; break;
1907 case ISD::SRL: Opc = Alpha::SRLi; break;
1908 case ISD::SRA: Opc = Alpha::SRAi; break;
1909 case ISD::MUL: Opc = Alpha::MULQi; break;
1910 };
1911 Tmp1 = SelectExpr(N.getOperand(0));
1912 Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
1913 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
1914 } else {
1915 switch(opcode) {
1916 case ISD::AND: Opc = Alpha::AND; break;
1917 case ISD::OR: Opc = Alpha::BIS; break;
1918 case ISD::XOR: Opc = Alpha::XOR; break;
1919 case ISD::SHL: Opc = Alpha::SL; break;
1920 case ISD::SRL: Opc = Alpha::SRL; break;
1921 case ISD::SRA: Opc = Alpha::SRA; break;
1922 case ISD::MUL: Opc = Alpha::MULQ; break;
1923 };
1924 Tmp1 = SelectExpr(N.getOperand(0));
1925 Tmp2 = SelectExpr(N.getOperand(1));
1926 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1927 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001928 return Result;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001929
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001930 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001931 case ISD::SUB:
Andrew Lenharth2f8fb772005-01-25 00:35:34 +00001932 {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001933 bool isAdd = opcode == ISD::ADD;
1934
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001935 //first check for Scaled Adds and Subs!
1936 //Valid for add and sub
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001937 ConstantSDNode* CSD = NULL;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001938 if(N.getOperand(0).getOpcode() == ISD::SHL &&
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001939 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) &&
1940 (CSD->getValue() == 2 || CSD->getValue() == 3))
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001941 {
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001942 bool use4 = CSD->getValue() == 2;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001943 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001944 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && CSD->getValue() <= 255)
1945 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
1946 2, Result).addReg(Tmp2).addImm(CSD->getValue());
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001947 else {
1948 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001949 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
1950 2, Result).addReg(Tmp2).addReg(Tmp1);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001951 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001952 }
1953 //Position prevents subs
Andrew Lenharth273a1f92005-04-07 14:18:13 +00001954 else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd &&
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001955 (CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) &&
1956 (CSD->getValue() == 2 || CSD->getValue() == 3))
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001957 {
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001958 bool use4 = CSD->getValue() == 2;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001959 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001960 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0))) && CSD->getValue() <= 255)
1961 BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2)
1962 .addImm(CSD->getValue());
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001963 else {
1964 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001965 BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001966 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001967 }
1968 //small addi
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001969 else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
1970 CSD->getValue() <= 255)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001971 { //Normal imm add/sub
1972 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
1973 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001974 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(CSD->getValue());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001975 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001976 //larger addi
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001977 else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
1978 CSD->getSignExtended() <= 32767 &&
1979 CSD->getSignExtended() >= -32767)
Andrew Lenharth74d00d82005-03-02 17:23:03 +00001980 { //LDA
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001981 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001982 Tmp2 = (long)CSD->getSignExtended();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001983 if (!isAdd)
1984 Tmp2 = -Tmp2;
1985 BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001986 }
1987 //give up and do the operation
1988 else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001989 //Normal add/sub
1990 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1991 Tmp1 = SelectExpr(N.getOperand(0));
1992 Tmp2 = SelectExpr(N.getOperand(1));
1993 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1994 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001995 return Result;
1996 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001997
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001998 case ISD::SDIV:
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001999 {
Andrew Lenhartha565c272005-04-06 22:03:13 +00002000 ConstantSDNode* CSD;
2001 //check if we can convert into a shift!
2002 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
2003 (int64_t)CSD->getSignExtended() != 0 &&
2004 ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0)
2005 {
2006 unsigned k = ExactLog2(abs(CSD->getSignExtended()));
2007 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenhartha565c272005-04-06 22:03:13 +00002008 if (k == 1)
2009 Tmp2 = Tmp1;
2010 else
2011 {
2012 Tmp2 = MakeReg(MVT::i64);
2013 BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1);
2014 }
2015 Tmp3 = MakeReg(MVT::i64);
2016 BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k);
2017 unsigned Tmp4 = MakeReg(MVT::i64);
2018 BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1);
2019 if ((int64_t)CSD->getSignExtended() > 0)
2020 BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k);
2021 else
2022 {
2023 unsigned Tmp5 = MakeReg(MVT::i64);
2024 BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k);
2025 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5);
2026 }
2027 return Result;
2028 }
2029 }
2030 //Else fall through
2031
2032 case ISD::UDIV:
2033 {
2034 ConstantSDNode* CSD;
2035 if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
2036 ((int64_t)CSD->getSignExtended() >= 2 ||
2037 (int64_t)CSD->getSignExtended() <= -2))
2038 {
2039 // If this is a divide by constant, we can emit code using some magic
2040 // constants to implement it as a multiply instead.
2041 ExprMap.erase(N);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002042 if (opcode == ISD::SDIV)
Andrew Lenhartha565c272005-04-06 22:03:13 +00002043 return SelectExpr(BuildSDIVSequence(N));
2044 else
2045 return SelectExpr(BuildUDIVSequence(N));
2046 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00002047 }
2048 //else fall though
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002049 case ISD::UREM:
Andrew Lenharth02981182005-01-26 01:24:38 +00002050 case ISD::SREM:
Misha Brukman4633f1c2005-04-21 23:13:11 +00002051 //FIXME: alpha really doesn't support any of these operations,
Andrew Lenharth40831c52005-01-28 06:57:18 +00002052 // the ops are expanded into special library calls with
2053 // special calling conventions
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002054 //Restore GP because it is a call after all...
Andrew Lenharth40831c52005-01-28 06:57:18 +00002055 switch(opcode) {
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00002056 case ISD::UREM: Opc = Alpha::REMQU; break;
2057 case ISD::SREM: Opc = Alpha::REMQ; break;
2058 case ISD::UDIV: Opc = Alpha::DIVQU; break;
2059 case ISD::SDIV: Opc = Alpha::DIVQ; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00002060 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002061 Tmp1 = SelectExpr(N.getOperand(0));
2062 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth33819132005-03-04 20:09:23 +00002063 //set up regs explicitly (helps Reg alloc)
2064 BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002065 BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +00002066 AlphaLowering.restoreGP(BB);
Andrew Lenharth33819132005-03-04 20:09:23 +00002067 BuildMI(BB, Opc, 2).addReg(Alpha::R24).addReg(Alpha::R25);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002068 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002069 return Result;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00002070
Andrew Lenharthe76797c2005-02-01 20:40:27 +00002071 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002072 case ISD::FP_TO_SINT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002073 {
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002074 assert (DestType == MVT::i64 && "only quads can be loaded to");
2075 MVT::ValueType SrcType = N.getOperand(0).getValueType();
Andrew Lenharth03824012005-02-07 05:55:55 +00002076 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002077 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002078 if (SrcType == MVT::f32)
Misha Brukman7847fca2005-04-22 17:54:37 +00002079 {
2080 Tmp2 = MakeReg(MVT::f64);
2081 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
2082 Tmp1 = Tmp2;
2083 }
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002084 Tmp2 = MakeReg(MVT::f64);
2085 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00002086 MoveFP2Int(Tmp2, Result, true);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002087
Andrew Lenharth7efadce2005-01-31 01:44:26 +00002088 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002089 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00002090
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002091 case ISD::SELECT:
2092 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00002093 //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 +00002094 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002095 //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2096 //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002097 // Get the condition into the zero flag.
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002098 //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002099
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002100 SDOperand CC = N.getOperand(0);
2101 SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
2102
Misha Brukman4633f1c2005-04-21 23:13:11 +00002103 if (CC.getOpcode() == ISD::SETCC &&
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002104 !MVT::isInteger(SetCC->getOperand(0).getValueType()))
2105 { //FP Setcc -> Int Select
Misha Brukman7847fca2005-04-22 17:54:37 +00002106 Tmp1 = MakeReg(MVT::f64);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002107 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2108 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Misha Brukman7847fca2005-04-22 17:54:37 +00002109 bool inv = SelectFPSetCC(CC, Tmp1);
2110 BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result)
2111 .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
2112 return Result;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002113 }
2114 if (CC.getOpcode() == ISD::SETCC) {
Misha Brukman7847fca2005-04-22 17:54:37 +00002115 //Int SetCC -> Select
2116 //Dropping the CC is only useful if we are comparing to 0
2117 if((SetCC->getOperand(1).getOpcode() == ISD::Constant &&
2118 cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0) ||
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002119 (SetCC->getOperand(0).getOpcode() == ISD::Constant &&
2120 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0))
2121 {
2122 //figure out a few things
2123 bool LeftZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
2124 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
2125 bool RightZero = SetCC->getOperand(0).getOpcode() == ISD::Constant &&
2126 cast<ConstantSDNode>(SetCC->getOperand(0))->getValue() == 0;
2127 bool LeftConst = N.getOperand(1).getOpcode() == ISD::Constant &&
2128 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255;
2129 bool RightConst = N.getOperand(2).getOpcode() == ISD::Constant &&
2130 cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255;
2131 bool useImm = LeftConst || RightConst;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002132
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002133 //Fix up CC
2134 ISD::CondCode cCode= SetCC->getCondition();
2135 if (RightConst && !LeftConst) //Invert sense to get Imm field right
2136 cCode = ISD::getSetCCInverse(cCode, true);
2137 if (LeftZero && !RightZero) //Swap Operands
2138 cCode = ISD::getSetCCSwappedOperands(cCode);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002139
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002140 //Choose the CMOV
2141 switch (cCode) {
2142 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
2143 case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
2144 case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break;
2145 case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break;
2146 case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break;
2147 case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break;
2148 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
2149 case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
2150 case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break; //Technically you could have this CC
2151 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
2152 case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
2153 }
2154 if(LeftZero && !RightZero) //swap Operands
2155 Tmp1 = SelectExpr(SetCC->getOperand(1)); //Cond
2156 else
2157 Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
2158
2159 if (LeftConst) {
2160 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2161 BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
Misha Brukman7847fca2005-04-22 17:54:37 +00002162 .addImm(cast<ConstantSDNode>(N.getOperand(1))->getValue())
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002163 .addReg(Tmp1);
2164 } else if (RightConst) {
2165 Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
2166 BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
Misha Brukman7847fca2005-04-22 17:54:37 +00002167 .addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue())
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002168 .addReg(Tmp1);
2169 } else {
2170 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2171 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
2172 BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1);
2173 }
2174 return Result;
2175 }
Misha Brukman7847fca2005-04-22 17:54:37 +00002176 //Otherwise, fall though
Andrew Lenharth10c085b2005-04-02 22:32:39 +00002177 }
2178 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00002179 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
2180 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharthe76797c2005-02-01 20:40:27 +00002181 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00002182
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002183 return Result;
2184 }
2185
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002186 case ISD::Constant:
2187 {
Andrew Lenharthc0513832005-03-29 19:24:04 +00002188 int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00002189 if (val <= IMM_HIGH && val >= IMM_LOW) {
Misha Brukman7847fca2005-04-22 17:54:37 +00002190 BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00002191 }
Misha Brukman7847fca2005-04-22 17:54:37 +00002192 else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT &&
2193 val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
2194 Tmp1 = MakeReg(MVT::i64);
2195 BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val)).addReg(Alpha::R31);
2196 BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00002197 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002198 else {
2199 MachineConstantPool *CP = BB->getParent()->getConstantPool();
2200 ConstantUInt *C = ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
2201 unsigned CPI = CP->getConstantPoolIndex(C);
2202 AlphaLowering.restoreGP(BB);
2203 BuildMI(BB, Alpha::LDQ_SYM, 1, Result).addConstantPoolIndex(CPI);
2204 }
2205 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002206 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002207 }
2208
2209 return 0;
2210}
2211
2212void ISel::Select(SDOperand N) {
2213 unsigned Tmp1, Tmp2, Opc;
Andrew Lenharth760270d2005-02-07 23:02:23 +00002214 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002215
Nate Begeman85fdeb22005-03-24 04:39:54 +00002216 if (!ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00002217 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002218
2219 SDNode *Node = N.Val;
Misha Brukman4633f1c2005-04-21 23:13:11 +00002220
Andrew Lenharth760270d2005-02-07 23:02:23 +00002221 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002222
2223 default:
2224 Node->dump(); std::cerr << "\n";
2225 assert(0 && "Node not handled yet!");
2226
2227 case ISD::BRCOND: {
Andrew Lenharth445171a2005-02-08 00:40:03 +00002228 SelectBranchCC(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002229 return;
2230 }
2231
2232 case ISD::BR: {
2233 MachineBasicBlock *Dest =
2234 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
2235
2236 Select(N.getOperand(0));
2237 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
2238 return;
2239 }
2240
2241 case ISD::ImplicitDef:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00002242 ++count_ins;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002243 Select(N.getOperand(0));
2244 BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
2245 return;
Misha Brukman4633f1c2005-04-21 23:13:11 +00002246
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002247 case ISD::EntryToken: return; // Noop
2248
2249 case ISD::TokenFactor:
2250 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
2251 Select(Node->getOperand(i));
Misha Brukman4633f1c2005-04-21 23:13:11 +00002252
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002253 //N.Val->dump(); std::cerr << "\n";
2254 //assert(0 && "Node not handled yet!");
Misha Brukman4633f1c2005-04-21 23:13:11 +00002255
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002256 return;
2257
2258 case ISD::CopyToReg:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00002259 ++count_outs;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002260 Select(N.getOperand(0));
2261 Tmp1 = SelectExpr(N.getOperand(1));
2262 Tmp2 = cast<RegSDNode>(N)->getReg();
Misha Brukman4633f1c2005-04-21 23:13:11 +00002263
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002264 if (Tmp1 != Tmp2) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00002265 if (N.getOperand(1).getValueType() == MVT::f64 ||
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002266 N.getOperand(1).getValueType() == MVT::f32)
Andrew Lenharth29219162005-02-07 06:31:44 +00002267 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
2268 else
2269 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002270 }
2271 return;
2272
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002273 case ISD::RET:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00002274 ++count_outs;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002275 switch (N.getNumOperands()) {
2276 default:
2277 std::cerr << N.getNumOperands() << "\n";
2278 for (unsigned i = 0; i < N.getNumOperands(); ++i)
2279 std::cerr << N.getOperand(i).getValueType() << "\n";
2280 Node->dump();
2281 assert(0 && "Unknown return instruction!");
2282 case 2:
2283 Select(N.getOperand(0));
2284 Tmp1 = SelectExpr(N.getOperand(1));
2285 switch (N.getOperand(1).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00002286 default: Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002287 assert(0 && "All other types should have been promoted!!");
2288 case MVT::f64:
2289 case MVT::f32:
2290 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
2291 break;
2292 case MVT::i32:
2293 case MVT::i64:
2294 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
2295 break;
2296 }
2297 break;
2298 case 1:
2299 Select(N.getOperand(0));
2300 break;
2301 }
2302 //Tmp2 = AlphaLowering.getRetAddr();
2303 //BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(Tmp2).addReg(Tmp2);
2304 BuildMI(BB, Alpha::RETURN, 0); // Just emit a 'ret' instruction
2305 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002306
Misha Brukman4633f1c2005-04-21 23:13:11 +00002307 case ISD::TRUNCSTORE:
2308 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00002309 {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00002310 SDOperand Chain = N.getOperand(0);
2311 SDOperand Value = N.getOperand(1);
2312 SDOperand Address = N.getOperand(2);
2313 Select(Chain);
2314
2315 Tmp1 = SelectExpr(Value); //value
Andrew Lenharth760270d2005-02-07 23:02:23 +00002316
2317 if (opcode == ISD::STORE) {
2318 switch(Value.getValueType()) {
2319 default: assert(0 && "unknown Type in store");
2320 case MVT::i64: Opc = Alpha::STQ; break;
2321 case MVT::f64: Opc = Alpha::STT; break;
2322 case MVT::f32: Opc = Alpha::STS; break;
2323 }
2324 } else { //ISD::TRUNCSTORE
2325 switch(cast<MVTSDNode>(Node)->getExtraValueType()) {
2326 default: assert(0 && "unknown Type in store");
2327 case MVT::i1: //FIXME: DAG does not promote this load
2328 case MVT::i8: Opc = Alpha::STB; break;
2329 case MVT::i16: Opc = Alpha::STW; break;
2330 case MVT::i32: Opc = Alpha::STL; break;
2331 }
Andrew Lenharth65838902005-02-06 16:22:15 +00002332 }
Andrew Lenharth760270d2005-02-07 23:02:23 +00002333
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00002334 if (Address.getOpcode() == ISD::GlobalAddress)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002335 {
2336 AlphaLowering.restoreGP(BB);
2337 Opc = GetSymVersion(Opc);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00002338 has_sym = true;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002339 BuildMI(BB, Opc, 2).addReg(Tmp1).addGlobalAddress(cast<GlobalAddressSDNode>(Address)->getGlobal());
2340 }
Andrew Lenharth05380342005-02-07 05:07:00 +00002341 else if(Address.getOpcode() == ISD::FrameIndex)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002342 {
Andrew Lenharth032f2352005-02-22 21:59:48 +00002343 BuildMI(BB, Opc, 3).addReg(Tmp1)
2344 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
2345 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002346 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00002347 else
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00002348 {
2349 long offset;
2350 SelectAddr(Address, Tmp2, offset);
2351 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
2352 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00002353 return;
2354 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002355
2356 case ISD::EXTLOAD:
2357 case ISD::SEXTLOAD:
2358 case ISD::ZEXTLOAD:
2359 case ISD::LOAD:
2360 case ISD::CopyFromReg:
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +00002361 case ISD::TAILCALL:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002362 case ISD::CALL:
Andrew Lenharth032f2352005-02-22 21:59:48 +00002363 case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00002364 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002365 SelectExpr(N);
2366 return;
2367
Chris Lattner16cd04d2005-05-12 23:24:06 +00002368 case ISD::CALLSEQ_START:
2369 case ISD::CALLSEQ_END:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002370 Select(N.getOperand(0));
2371 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
Misha Brukman4633f1c2005-04-21 23:13:11 +00002372
Chris Lattner16cd04d2005-05-12 23:24:06 +00002373 Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN :
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002374 Alpha::ADJUSTSTACKUP;
2375 BuildMI(BB, Opc, 1).addImm(Tmp1);
2376 return;
Andrew Lenharth95762122005-03-31 21:24:06 +00002377
2378 case ISD::PCMARKER:
2379 Select(N.getOperand(0)); //Chain
2380 BuildMI(BB, Alpha::PCLABEL, 2).addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
2381 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002382 }
2383 assert(0 && "Should not be reached!");
2384}
2385
2386
2387/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
2388/// into a machine code representation using pattern matching and a machine
2389/// description file.
2390///
2391FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00002392 return new ISel(TM);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00002393}
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00002394