blob: 8a377d056a15c9163bb2f8be4aab5733f42f7327 [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"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000016#include "AlphaISelLowering.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000017#include "llvm/Constants.h" // FIXME: REMOVE
18#include "llvm/Function.h"
Andrew Lenharthb69f3422005-06-22 17:19:45 +000019#include "llvm/Module.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000020#include "llvm/CodeGen/MachineInstrBuilder.h"
21#include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/SelectionDAG.h"
25#include "llvm/CodeGen/SelectionDAGISel.h"
26#include "llvm/CodeGen/SSARegMap.h"
27#include "llvm/Target/TargetData.h"
28#include "llvm/Target/TargetLowering.h"
29#include "llvm/Support/MathExtras.h"
30#include "llvm/ADT/Statistic.h"
Andrew Lenharth032f2352005-02-22 21:59:48 +000031#include "llvm/Support/Debug.h"
Andrew Lenharth95762122005-03-31 21:24:06 +000032#include "llvm/Support/CommandLine.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000033#include <set>
Andrew Lenharth684f2292005-01-30 00:35:27 +000034#include <algorithm>
Andrew Lenharth304d0f32005-01-22 23:41:55 +000035using namespace llvm;
36
Andrew Lenharth95762122005-03-31 21:24:06 +000037namespace llvm {
Misha Brukman4633f1c2005-04-21 23:13:11 +000038 cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
Andrew Lenharthd4653b12005-06-27 17:39:17 +000039 cl::desc("Use the FP div instruction for integer div when possible"),
Andrew Lenharth95762122005-03-31 21:24:06 +000040 cl::Hidden);
Andrew Lenharth59009192005-05-04 19:12:09 +000041 cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI",
Andrew Lenharthd4653b12005-06-27 17:39:17 +000042 cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"),
Andrew Lenharth95762122005-03-31 21:24:06 +000043 cl::Hidden);
Andrew Lenharth59009192005-05-04 19:12:09 +000044 cl::opt<bool> EnableAlphaCT("enable-alpha-CT",
Andrew Lenharthd4653b12005-06-27 17:39:17 +000045 cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"),
Andrew Lenharth59009192005-05-04 19:12:09 +000046 cl::Hidden);
Misha Brukman4633f1c2005-04-21 23:13:11 +000047 cl::opt<bool> EnableAlphaCount("enable-alpha-count",
Andrew Lenharthd4653b12005-06-27 17:39:17 +000048 cl::desc("Print estimates on live ins and outs"),
49 cl::Hidden);
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +000050 cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark",
Andrew Lenharthd4653b12005-06-27 17:39:17 +000051 cl::desc("Emit symbols to correlate Mem ops to LLVM Values"),
52 cl::Hidden);
Andrew Lenharth95762122005-03-31 21:24:06 +000053}
54
Andrew Lenharthe3c8c0a42005-05-31 19:49:34 +000055namespace {
Andrew Lenharth304d0f32005-01-22 23:41:55 +000056
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000057//===--------------------------------------------------------------------===//
58/// ISel - Alpha specific code to select Alpha machine instructions for
59/// SelectionDAG operations.
60//===--------------------------------------------------------------------===//
Andrew Lenharthb69f3422005-06-22 17:19:45 +000061class AlphaISel : public SelectionDAGISel {
Misha Brukman4633f1c2005-04-21 23:13:11 +000062
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000063 /// AlphaLowering - This object fully describes how to lower LLVM code to an
64 /// Alpha-specific SelectionDAG.
65 AlphaTargetLowering AlphaLowering;
Misha Brukman4633f1c2005-04-21 23:13:11 +000066
Andrew Lenharth4b8ac152005-04-06 20:25:34 +000067 SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform
68 // for sdiv and udiv until it is put into the future
69 // dag combiner.
70
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000071 /// ExprMap - As shared expressions are codegen'd, we keep track of which
72 /// vreg the value is produced in, so we only emit one copy of each compiled
73 /// tree.
74 static const unsigned notIn = (unsigned)(-1);
75 std::map<SDOperand, unsigned> ExprMap;
Misha Brukman4633f1c2005-04-21 23:13:11 +000076
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000077 //CCInvMap sometimes (SetNE) we have the inverse CC code for free
78 std::map<SDOperand, unsigned> CCInvMap;
Misha Brukman4633f1c2005-04-21 23:13:11 +000079
Andrew Lenhartha32b9e32005-04-08 17:28:49 +000080 int count_ins;
81 int count_outs;
82 bool has_sym;
Andrew Lenharth500b4db2005-04-22 13:35:18 +000083 int max_depth;
Andrew Lenhartha32b9e32005-04-08 17:28:49 +000084
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000085public:
Jeff Cohen00b168892005-07-27 06:12:32 +000086 AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering),
Andrew Lenharthd4653b12005-06-27 17:39:17 +000087 AlphaLowering(TM)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000088 {}
Misha Brukman4633f1c2005-04-21 23:13:11 +000089
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000090 /// InstructionSelectBasicBlock - This callback is invoked by
91 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
92 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
Andrew Lenharth032f2352005-02-22 21:59:48 +000093 DEBUG(BB->dump());
Andrew Lenhartha32b9e32005-04-08 17:28:49 +000094 count_ins = 0;
95 count_outs = 0;
Andrew Lenharth500b4db2005-04-22 13:35:18 +000096 max_depth = 0;
Andrew Lenhartha32b9e32005-04-08 17:28:49 +000097 has_sym = false;
98
Andrew Lenharth63f2ab22005-02-10 06:25:22 +000099 // Codegen the basic block.
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000100 ISelDAG = &DAG;
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000101 max_depth = DAG.getRoot().getNodeDepth();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000102 Select(DAG.getRoot());
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000103
104 if(has_sym)
105 ++count_ins;
106 if(EnableAlphaCount)
Jeff Cohen00b168892005-07-27 06:12:32 +0000107 std::cerr << "COUNT: "
108 << BB->getParent()->getFunction ()->getName() << " "
109 << BB->getNumber() << " "
Andrew Lenharth500b4db2005-04-22 13:35:18 +0000110 << max_depth << " "
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000111 << count_ins << " "
112 << count_outs << "\n";
Misha Brukman4633f1c2005-04-21 23:13:11 +0000113
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000114 // Clear state used for selection.
115 ExprMap.clear();
116 CCInvMap.clear();
117 }
Jeff Cohen00b168892005-07-27 06:12:32 +0000118
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000119 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000120
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000121 unsigned SelectExpr(SDOperand N);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000122 void Select(SDOperand N);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000123
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000124 void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
125 void SelectBranchCC(SDOperand N);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000126 void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
127 void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000128 //returns whether the sense of the comparison was inverted
129 bool SelectFPSetCC(SDOperand N, unsigned dst);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000130
131 // dag -> dag expanders for integer divide by constant
132 SDOperand BuildSDIVSequence(SDOperand N);
133 SDOperand BuildUDIVSequence(SDOperand N);
134
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000135};
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000136}
137
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000138void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000139 // If this function has live-in values, emit the copies from pregs to vregs at
140 // the top of the function, before anything else.
141 MachineBasicBlock *BB = MF.begin();
142 if (MF.livein_begin() != MF.livein_end()) {
143 SSARegMap *RegMap = MF.getSSARegMap();
144 for (MachineFunction::livein_iterator LI = MF.livein_begin(),
145 E = MF.livein_end(); LI != E; ++LI) {
146 const TargetRegisterClass *RC = RegMap->getRegClass(LI->second);
147 if (RC == Alpha::GPRCRegisterClass) {
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000148 BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first)
149 .addReg(LI->first);
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000150 } else if (RC == Alpha::FPRCRegisterClass) {
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000151 BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first)
152 .addReg(LI->first);
Andrew Lenharthfd5e4b72005-05-31 18:35:43 +0000153 } else {
154 assert(0 && "Unknown regclass!");
155 }
156 }
157 }
158}
159
Andrew Lenharthd2284272005-08-15 14:31:37 +0000160static bool isSIntImmediate(SDOperand N, int64_t& Imm) {
161 // test for constant
162 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) {
163 // retrieve value
164 Imm = CN->getSignExtended();
165 // passes muster
166 return true;
167 }
168 // not a constant
169 return false;
170}
171
172// isSIntImmediateBounded - This method tests to see if a constant operand
173// bounded s.t. low <= Imm <= high
174// If so Imm will receive the 64 bit value.
175static bool isSIntImmediateBounded(SDOperand N, int64_t& Imm,
176 int64_t low, int64_t high) {
Andrew Lenharth035b8ab2005-08-17 00:47:24 +0000177 if (isSIntImmediate(N, Imm) && Imm <= high && Imm >= low)
Andrew Lenharthd2284272005-08-15 14:31:37 +0000178 return true;
179 return false;
180}
181static bool isUIntImmediate(SDOperand N, uint64_t& Imm) {
182 // test for constant
183 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) {
184 // retrieve value
185 Imm = (uint64_t)CN->getValue();
186 // passes muster
187 return true;
188 }
189 // not a constant
190 return false;
191}
192
193static bool isUIntImmediateBounded(SDOperand N, uint64_t& Imm,
194 uint64_t low, uint64_t high) {
Andrew Lenharth035b8ab2005-08-17 00:47:24 +0000195 if (isUIntImmediate(N, Imm) && Imm <= high && Imm >= low)
Andrew Lenharthd2284272005-08-15 14:31:37 +0000196 return true;
197 return false;
198}
199
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000200static void getValueInfo(const Value* v, int& type, int& fun, int& offset)
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +0000201{
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000202 fun = type = offset = 0;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000203 if (v == NULL) {
204 type = 0;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000205 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) {
206 type = 1;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000207 const Module* M = GV->getParent();
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000208 for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii)
209 ++offset;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000210 } else if (const Argument* Arg = dyn_cast<Argument>(v)) {
211 type = 2;
212 const Function* F = Arg->getParent();
213 const Module* M = F->getParent();
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000214 for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000215 ++fun;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000216 for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii)
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000217 ++offset;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000218 } else if (const Instruction* I = dyn_cast<Instruction>(v)) {
Andrew Lenhartha48f3ce2005-07-07 19:52:58 +0000219 assert(dyn_cast<PointerType>(I->getType()));
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000220 type = 3;
221 const BasicBlock* bb = I->getParent();
222 const Function* F = bb->getParent();
223 const Module* M = F->getParent();
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000224 for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000225 ++fun;
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000226 for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii)
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000227 offset += ii->size();
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000228 for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii)
Andrew Lenharthfec0e402005-07-12 04:20:52 +0000229 ++offset;
Andrew Lenhartha48f3ce2005-07-07 19:52:58 +0000230 } else if (const Constant* C = dyn_cast<Constant>(v)) {
231 //Don't know how to look these up yet
232 type = 0;
Andrew Lenhartha48f3ce2005-07-07 19:52:58 +0000233 } else {
234 assert(0 && "Error in value marking");
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000235 }
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000236 //type = 4: register spilling
237 //type = 5: global address loading or constant loading
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000238}
239
240static int getUID()
241{
242 static int id = 0;
243 return ++id;
244}
Andrew Lenharthcd7f8cf2005-06-06 19:03:55 +0000245
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000246//Factorize a number using the list of constants
247static bool factorize(int v[], int res[], int size, uint64_t c)
248{
249 bool cont = true;
250 while (c != 1 && cont)
251 {
252 cont = false;
253 for(int i = 0; i < size; ++i)
254 {
255 if (c % v[i] == 0)
256 {
257 c /= v[i];
258 ++res[i];
259 cont=true;
260 }
261 }
262 }
263 return c == 1;
264}
265
266
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000267//Shamelessly adapted from PPC32
Misha Brukman4633f1c2005-04-21 23:13:11 +0000268// Structure used to return the necessary information to codegen an SDIV as
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000269// a multiply.
270struct ms {
271 int64_t m; // magic number
272 int64_t s; // shift amount
273};
274
275struct mu {
276 uint64_t m; // magic number
277 int64_t a; // add indicator
278 int64_t s; // shift amount
279};
280
281/// magic - calculate the magic numbers required to codegen an integer sdiv as
Misha Brukman4633f1c2005-04-21 23:13:11 +0000282/// a sequence of multiply and shifts. Requires that the divisor not be 0, 1,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000283/// or -1.
284static struct ms magic(int64_t d) {
285 int64_t p;
286 uint64_t ad, anc, delta, q1, r1, q2, r2, t;
287 const uint64_t two63 = 9223372036854775808ULL; // 2^63
288 struct ms mag;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000289
Andrew Lenharth01c8f6e2005-08-01 17:47:28 +0000290 ad = llabs(d);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000291 t = two63 + ((uint64_t)d >> 63);
292 anc = t - 1 - t%ad; // absolute value of nc
Andrew Lenharth320174f2005-04-07 17:19:16 +0000293 p = 63; // initialize p
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000294 q1 = two63/anc; // initialize q1 = 2p/abs(nc)
295 r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc))
296 q2 = two63/ad; // initialize q2 = 2p/abs(d)
297 r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d))
298 do {
299 p = p + 1;
300 q1 = 2*q1; // update q1 = 2p/abs(nc)
301 r1 = 2*r1; // update r1 = rem(2p/abs(nc))
302 if (r1 >= anc) { // must be unsigned comparison
303 q1 = q1 + 1;
304 r1 = r1 - anc;
305 }
306 q2 = 2*q2; // update q2 = 2p/abs(d)
307 r2 = 2*r2; // update r2 = rem(2p/abs(d))
308 if (r2 >= ad) { // must be unsigned comparison
309 q2 = q2 + 1;
310 r2 = r2 - ad;
311 }
312 delta = ad - r2;
313 } while (q1 < delta || (q1 == delta && r1 == 0));
314
315 mag.m = q2 + 1;
316 if (d < 0) mag.m = -mag.m; // resulting magic number
317 mag.s = p - 64; // resulting shift
318 return mag;
319}
320
321/// magicu - calculate the magic numbers required to codegen an integer udiv as
322/// a sequence of multiply, add and shifts. Requires that the divisor not be 0.
323static struct mu magicu(uint64_t d)
324{
325 int64_t p;
326 uint64_t nc, delta, q1, r1, q2, r2;
327 struct mu magu;
328 magu.a = 0; // initialize "add" indicator
329 nc = - 1 - (-d)%d;
Andrew Lenharth320174f2005-04-07 17:19:16 +0000330 p = 63; // initialize p
331 q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc
332 r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc)
333 q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d
334 r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d)
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000335 do {
336 p = p + 1;
337 if (r1 >= nc - r1 ) {
338 q1 = 2*q1 + 1; // update q1
339 r1 = 2*r1 - nc; // update r1
340 }
341 else {
342 q1 = 2*q1; // update q1
343 r1 = 2*r1; // update r1
344 }
345 if (r2 + 1 >= d - r2) {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000346 if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000347 q2 = 2*q2 + 1; // update q2
348 r2 = 2*r2 + 1 - d; // update r2
349 }
350 else {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000351 if (q2 >= 0x8000000000000000ull) magu.a = 1;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000352 q2 = 2*q2; // update q2
353 r2 = 2*r2 + 1; // update r2
354 }
355 delta = d - 1 - r2;
356 } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0)));
357 magu.m = q2 + 1; // resulting magic number
Andrew Lenharth320174f2005-04-07 17:19:16 +0000358 magu.s = p - 64; // resulting shift
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000359 return magu;
360}
361
362/// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant,
363/// return a DAG expression to select that will generate the same value by
364/// multiplying by a magic number. See:
365/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000366SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) {
Andrew Lenharth320174f2005-04-07 17:19:16 +0000367 int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000368 ms magics = magic(d);
369 // Multiply the numerator (operand 0) by the magic value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000370 SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0),
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000371 ISelDAG->getConstant(magics.m, MVT::i64));
372 // If d > 0 and m < 0, add the numerator
373 if (d > 0 && magics.m < 0)
374 Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0));
375 // If d < 0 and m > 0, subtract the numerator.
376 if (d < 0 && magics.m > 0)
377 Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0));
378 // Shift right algebraic if shift value is nonzero
379 if (magics.s > 0)
Misha Brukman4633f1c2005-04-21 23:13:11 +0000380 Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000381 ISelDAG->getConstant(magics.s, MVT::i64));
382 // Extract the sign bit and add it to the quotient
Misha Brukman4633f1c2005-04-21 23:13:11 +0000383 SDOperand T =
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000384 ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64));
385 return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T);
386}
387
388/// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
389/// return a DAG expression to select that will generate the same value by
390/// multiplying by a magic number. See:
391/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000392SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000393 unsigned d =
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000394 (unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
395 mu magics = magicu(d);
396 // Multiply the numerator (operand 0) by the magic value
Misha Brukman4633f1c2005-04-21 23:13:11 +0000397 SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0),
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000398 ISelDAG->getConstant(magics.m, MVT::i64));
399 if (magics.a == 0) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000400 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000401 ISelDAG->getConstant(magics.s, MVT::i64));
402 } else {
403 SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000404 NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000405 ISelDAG->getConstant(1, MVT::i64));
406 NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000407 Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000408 ISelDAG->getConstant(magics.s-1, MVT::i64));
409 }
410 return Q;
411}
412
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000413//These describe LDAx
Andrew Lenharthc0513832005-03-29 19:24:04 +0000414static const int IMM_LOW = -32768;
415static const int IMM_HIGH = 32767;
Andrew Lenharthe87f6c32005-03-11 17:48:05 +0000416static const int IMM_MULT = 65536;
417
418static long getUpper16(long l)
419{
420 long y = l / IMM_MULT;
421 if (l % IMM_MULT > IMM_HIGH)
422 ++y;
423 return y;
424}
425
426static long getLower16(long l)
427{
428 long h = getUpper16(l);
429 return l - h * IMM_MULT;
430}
431
Andrew Lenharthfe895e32005-06-27 17:15:36 +0000432static unsigned GetRelVersion(unsigned opcode)
433{
434 switch (opcode) {
435 default: assert(0 && "unknown load or store"); return 0;
436 case Alpha::LDQ: return Alpha::LDQr;
437 case Alpha::LDS: return Alpha::LDSr;
438 case Alpha::LDT: return Alpha::LDTr;
439 case Alpha::LDL: return Alpha::LDLr;
440 case Alpha::LDBU: return Alpha::LDBUr;
441 case Alpha::LDWU: return Alpha::LDWUr;
Andrew Lenharthfce587e2005-06-29 00:39:17 +0000442 case Alpha::STB: return Alpha::STBr;
443 case Alpha::STW: return Alpha::STWr;
444 case Alpha::STL: return Alpha::STLr;
445 case Alpha::STQ: return Alpha::STQr;
446 case Alpha::STS: return Alpha::STSr;
447 case Alpha::STT: return Alpha::STTr;
448
Andrew Lenharthfe895e32005-06-27 17:15:36 +0000449 }
450}
Andrew Lenharth65838902005-02-06 16:22:15 +0000451
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000452void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000453{
454 unsigned Opc;
455 if (EnableAlphaFTOI) {
456 Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
Andrew Lenharth98169be2005-07-28 18:14:47 +0000457 BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::F31);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000458 } else {
459 //The hard way:
460 // Spill the integer to memory and reload it from there.
461 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
462 MachineFunction *F = BB->getParent();
463 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
464
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000465 if (EnableAlphaLSMark)
466 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
467 .addImm(getUID());
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000468 Opc = isDouble ? Alpha::STT : Alpha::STS;
469 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000470
471 if (EnableAlphaLSMark)
472 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
473 .addImm(getUID());
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000474 Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
475 BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
476 }
477}
478
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000479void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000480{
481 unsigned Opc;
482 if (EnableAlphaFTOI) {
483 Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
Andrew Lenharth98169be2005-07-28 18:14:47 +0000484 BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::R31);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000485 } else {
486 //The hard way:
487 // Spill the integer to memory and reload it from there.
488 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
489 MachineFunction *F = BB->getParent();
490 int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
491
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000492 if (EnableAlphaLSMark)
493 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
494 .addImm(getUID());
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000495 Opc = isDouble ? Alpha::STQ : Alpha::STL;
496 BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000497
498 if (EnableAlphaLSMark)
499 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
500 .addImm(getUID());
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +0000501 Opc = isDouble ? Alpha::LDT : Alpha::LDS;
502 BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
503 }
504}
505
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000506bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst)
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000507{
Chris Lattner88ac32c2005-08-09 20:21:10 +0000508 SDNode *SetCC = N.Val;
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000509 unsigned Opc, Tmp1, Tmp2, Tmp3;
Chris Lattner88ac32c2005-08-09 20:21:10 +0000510 ISD::CondCode CC = cast<CondCodeSDNode>(SetCC->getOperand(2))->get();
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000511 bool rev = false;
512 bool inv = false;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000513
Chris Lattner88ac32c2005-08-09 20:21:10 +0000514 switch (CC) {
515 default: SetCC->dump(); assert(0 && "Unknown FP comparison!");
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000516 case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
517 case ISD::SETLT: Opc = Alpha::CMPTLT; break;
518 case ISD::SETLE: Opc = Alpha::CMPTLE; break;
519 case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
520 case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
521 case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
522 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000523
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000524 ConstantFPSDNode *CN;
525 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
526 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
527 Tmp1 = Alpha::F31;
528 else
529 Tmp1 = SelectExpr(N.getOperand(0));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000530
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000531 if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
532 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
533 Tmp2 = Alpha::F31;
534 else
Chris Lattner9c9183a2005-04-30 04:44:07 +0000535 Tmp2 = SelectExpr(N.getOperand(1));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000536
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000537 //Can only compare doubles, and dag won't promote for me
538 if (SetCC->getOperand(0).getValueType() == MVT::f32)
539 {
540 //assert(0 && "Setcc On float?\n");
541 std::cerr << "Setcc on float!\n";
542 Tmp3 = MakeReg(MVT::f64);
Andrew Lenharth98169be2005-07-28 18:14:47 +0000543 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000544 Tmp1 = Tmp3;
545 }
546 if (SetCC->getOperand(1).getValueType() == MVT::f32)
547 {
548 //assert (0 && "Setcc On float?\n");
549 std::cerr << "Setcc on float!\n";
550 Tmp3 = MakeReg(MVT::f64);
Andrew Lenharth98169be2005-07-28 18:14:47 +0000551 BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Alpha::F31).addReg(Tmp2);
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000552 Tmp2 = Tmp3;
553 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000554
Andrew Lenharth10c085b2005-04-02 22:32:39 +0000555 if (rev) std::swap(Tmp1, Tmp2);
556 //do the comparison
557 BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
558 return inv;
559}
560
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000561//Check to see if the load is a constant offset from a base register
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000562void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000563{
564 unsigned opcode = N.getOpcode();
Andrew Lenharth694c2982005-06-26 23:01:11 +0000565 if (opcode == ISD::ADD && N.getOperand(1).getOpcode() == ISD::Constant &&
566 cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
567 { //Normal imm add
568 Reg = SelectExpr(N.getOperand(0));
569 offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
570 return;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000571 }
572 Reg = SelectExpr(N);
573 offset = 0;
574 return;
575}
576
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000577void AlphaISel::SelectBranchCC(SDOperand N)
Andrew Lenharth445171a2005-02-08 00:40:03 +0000578{
579 assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
Misha Brukman4633f1c2005-04-21 23:13:11 +0000580 MachineBasicBlock *Dest =
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000581 cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
582 unsigned Opc = Alpha::WTF;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000583
Andrew Lenharth445171a2005-02-08 00:40:03 +0000584 Select(N.getOperand(0)); //chain
585 SDOperand CC = N.getOperand(1);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000586
Andrew Lenharth445171a2005-02-08 00:40:03 +0000587 if (CC.getOpcode() == ISD::SETCC)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000588 {
Chris Lattner88ac32c2005-08-09 20:21:10 +0000589 ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get();
590 if (MVT::isInteger(CC.getOperand(0).getValueType())) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000591 //Dropping the CC is only useful if we are comparing to 0
Chris Lattner88ac32c2005-08-09 20:21:10 +0000592 bool RightZero = CC.getOperand(1).getOpcode() == ISD::Constant &&
593 cast<ConstantSDNode>(CC.getOperand(1))->getValue() == 0;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000594 bool isNE = false;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000595
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000596 //Fix up CC
Andrew Lenharth63b720a2005-04-03 20:35:21 +0000597 if(cCode == ISD::SETNE)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000598 isNE = true;
Andrew Lenharth445171a2005-02-08 00:40:03 +0000599
Andrew Lenharth694c2982005-06-26 23:01:11 +0000600 if (RightZero) {
Andrew Lenharth09552bf2005-06-08 18:02:21 +0000601 switch (cCode) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000602 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
603 case ISD::SETEQ: Opc = Alpha::BEQ; break;
604 case ISD::SETLT: Opc = Alpha::BLT; break;
605 case ISD::SETLE: Opc = Alpha::BLE; break;
606 case ISD::SETGT: Opc = Alpha::BGT; break;
607 case ISD::SETGE: Opc = Alpha::BGE; break;
608 case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
609 case ISD::SETUGT: Opc = Alpha::BNE; break;
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000610 //Technically you could have this CC
611 case ISD::SETULE: Opc = Alpha::BEQ; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000612 case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
613 case ISD::SETNE: Opc = Alpha::BNE; break;
614 }
Chris Lattner88ac32c2005-08-09 20:21:10 +0000615 unsigned Tmp1 = SelectExpr(CC.getOperand(0)); //Cond
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000616 BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
617 return;
618 } else {
619 unsigned Tmp1 = SelectExpr(CC);
620 if (isNE)
621 BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
622 else
623 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000624 return;
625 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000626 } else { //FP
Jeff Cohen00b168892005-07-27 06:12:32 +0000627 //Any comparison between 2 values should be codegened as an folded
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000628 //branch, as moving CC to the integer register is very expensive
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000629 //for a cmp b: c = a - b;
630 //a = b: c = 0
631 //a < b: c < 0
632 //a > b: c > 0
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000633
634 bool invTest = false;
635 unsigned Tmp3;
636
637 ConstantFPSDNode *CN;
Chris Lattner88ac32c2005-08-09 20:21:10 +0000638 if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1)))
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000639 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
Chris Lattner88ac32c2005-08-09 20:21:10 +0000640 Tmp3 = SelectExpr(CC.getOperand(0));
641 else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0)))
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000642 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
643 {
Chris Lattner88ac32c2005-08-09 20:21:10 +0000644 Tmp3 = SelectExpr(CC.getOperand(1));
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000645 invTest = true;
646 }
647 else
648 {
Chris Lattner88ac32c2005-08-09 20:21:10 +0000649 unsigned Tmp1 = SelectExpr(CC.getOperand(0));
650 unsigned Tmp2 = SelectExpr(CC.getOperand(1));
651 bool isD = CC.getOperand(0).getValueType() == MVT::f64;
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000652 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
653 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
654 .addReg(Tmp1).addReg(Tmp2);
655 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000656
Chris Lattner88ac32c2005-08-09 20:21:10 +0000657 switch (cCode) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000658 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
Andrew Lenharth2b6c4f52005-02-25 22:55:15 +0000659 case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
660 case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
661 case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
662 case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
663 case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
664 case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000665 }
666 BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
Andrew Lenharth445171a2005-02-08 00:40:03 +0000667 return;
668 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000669 abort(); //Should never be reached
670 } else {
671 //Giveup and do the stupid thing
672 unsigned Tmp1 = SelectExpr(CC);
673 BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
674 return;
675 }
Andrew Lenharth445171a2005-02-08 00:40:03 +0000676 abort(); //Should never be reached
677}
678
Andrew Lenharthb69f3422005-06-22 17:19:45 +0000679unsigned AlphaISel::SelectExpr(SDOperand N) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000680 unsigned Result;
Andrew Lenharth2966e842005-04-07 18:15:28 +0000681 unsigned Tmp1, Tmp2 = 0, Tmp3;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000682 unsigned Opc = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000683 unsigned opcode = N.getOpcode();
Andrew Lenharthd2284272005-08-15 14:31:37 +0000684 int64_t SImm;
685 uint64_t UImm;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000686
687 SDNode *Node = N.Val;
Andrew Lenharth40831c52005-01-28 06:57:18 +0000688 MVT::ValueType DestType = N.getValueType();
Andrew Lenharthf4da9452005-06-29 12:49:51 +0000689 bool isFP = DestType == MVT::f64 || DestType == MVT::f32;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000690
691 unsigned &Reg = ExprMap[N];
692 if (Reg) return Reg;
693
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000694 switch(N.getOpcode()) {
695 default:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000696 Reg = Result = (N.getValueType() != MVT::Other) ?
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000697 MakeReg(N.getValueType()) : notIn;
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000698 break;
699 case ISD::AssertSext:
700 case ISD::AssertZext:
701 return Reg = SelectExpr(N.getOperand(0));
702 case ISD::CALL:
703 case ISD::TAILCALL:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000704 // If this is a call instruction, make sure to prepare ALL of the result
705 // values as well as the chain.
706 if (Node->getNumValues() == 1)
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000707 Reg = Result = notIn; // Void call, just a chain.
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000708 else {
709 Result = MakeReg(Node->getValueType(0));
710 ExprMap[N.getValue(0)] = Result;
711 for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
712 ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +0000713 ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000714 }
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000715 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000716 }
717
Andrew Lenharth40831c52005-01-28 06:57:18 +0000718 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000719 default:
720 Node->dump();
721 assert(0 && "Node not handled!\n");
Misha Brukman4633f1c2005-04-21 23:13:11 +0000722
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000723 case ISD::CTPOP:
724 case ISD::CTTZ:
725 case ISD::CTLZ:
726 Opc = opcode == ISD::CTPOP ? Alpha::CTPOP :
727 (opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ);
728 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharthf3f951a2005-07-22 20:50:29 +0000729 BuildMI(BB, Opc, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000730 return Result;
731
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000732 case ISD::MULHU:
733 Tmp1 = SelectExpr(N.getOperand(0));
734 Tmp2 = SelectExpr(N.getOperand(1));
735 BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth706be912005-04-07 13:55:53 +0000736 return Result;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000737 case ISD::MULHS:
738 {
739 //MULHU - Ra<63>*Rb - Rb<63>*Ra
740 Tmp1 = SelectExpr(N.getOperand(0));
741 Tmp2 = SelectExpr(N.getOperand(1));
742 Tmp3 = MakeReg(MVT::i64);
743 BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
744 unsigned V1 = MakeReg(MVT::i64);
745 unsigned V2 = MakeReg(MVT::i64);
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000746 BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31)
747 .addReg(Tmp1);
748 BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31)
749 .addReg(Tmp2);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +0000750 unsigned IRes = MakeReg(MVT::i64);
751 BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1);
752 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2);
753 return Result;
754 }
Andrew Lenharth7332f3e2005-04-02 19:11:07 +0000755 case ISD::UNDEF: {
756 BuildMI(BB, Alpha::IDEF, 0, Result);
757 return Result;
758 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000759
Andrew Lenharth032f2352005-02-22 21:59:48 +0000760 case ISD::DYNAMIC_STACKALLOC:
761 // Generate both result values.
Andrew Lenharth3a7118d2005-02-23 17:33:42 +0000762 if (Result != notIn)
763 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth032f2352005-02-22 21:59:48 +0000764 else
765 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
766
767 // FIXME: We are currently ignoring the requested alignment for handling
768 // greater than the stack alignment. This will need to be revisited at some
769 // point. Align = N.getOperand(2);
770
771 if (!isa<ConstantSDNode>(N.getOperand(2)) ||
772 cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
773 std::cerr << "Cannot allocate stack object with greater alignment than"
774 << " the stack alignment yet!";
775 abort();
776 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000777
Andrew Lenharth032f2352005-02-22 21:59:48 +0000778 Select(N.getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +0000779 if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 32767))
780 BuildMI(BB, Alpha::LDA, 2, Alpha::R30).addImm(-SImm).addReg(Alpha::R30);
781 else {
Andrew Lenharth032f2352005-02-22 21:59:48 +0000782 Tmp1 = SelectExpr(N.getOperand(1));
783 // Subtract size from stack pointer, thereby allocating some space.
784 BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
785 }
786
787 // Put a pointer to the space into the result register, by copying the stack
788 // pointer.
Andrew Lenharth7bc47022005-02-22 23:29:25 +0000789 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
Andrew Lenharth032f2352005-02-22 21:59:48 +0000790 return Result;
791
Andrew Lenharth02c318e2005-06-27 21:02:56 +0000792 case ISD::ConstantPool:
Chris Lattner5839bf22005-08-26 17:15:30 +0000793 Tmp1 = BB->getParent()->getConstantPool()->
794 getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
Andrew Lenharth02c318e2005-06-27 21:02:56 +0000795 AlphaLowering.restoreGP(BB);
796 Tmp2 = MakeReg(MVT::i64);
797 BuildMI(BB, Alpha::LDAHr, 2, Tmp2).addConstantPoolIndex(Tmp1)
798 .addReg(Alpha::R29);
799 BuildMI(BB, Alpha::LDAr, 2, Result).addConstantPoolIndex(Tmp1)
800 .addReg(Tmp2);
801 return Result;
Andrew Lenharth2c594352005-01-29 15:42:07 +0000802
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000803 case ISD::FrameIndex:
Andrew Lenharth032f2352005-02-22 21:59:48 +0000804 BuildMI(BB, Alpha::LDA, 2, Result)
805 .addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
806 .addReg(Alpha::F31);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000807 return Result;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000808
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000809 case ISD::EXTLOAD:
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000810 case ISD::ZEXTLOAD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000811 case ISD::SEXTLOAD:
Misha Brukman4633f1c2005-04-21 23:13:11 +0000812 case ISD::LOAD:
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000813 {
814 // Make sure we generate both values.
815 if (Result != notIn)
816 ExprMap[N.getValue(1)] = notIn; // Generate the token
817 else
818 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +0000819
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000820 SDOperand Chain = N.getOperand(0);
821 SDOperand Address = N.getOperand(1);
822 Select(Chain);
823
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000824 bool fpext = true;
825
Andrew Lenharth03824012005-02-07 05:55:55 +0000826 if (opcode == ISD::LOAD)
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000827 switch (Node->getValueType(0)) {
828 default: Node->dump(); assert(0 && "Bad load!");
829 case MVT::i64: Opc = Alpha::LDQ; break;
830 case MVT::f64: Opc = Alpha::LDT; break;
831 case MVT::f32: Opc = Alpha::LDS; break;
832 }
Andrew Lenharth03824012005-02-07 05:55:55 +0000833 else
Chris Lattnerbce81ae2005-07-10 01:56:13 +0000834 switch (cast<VTSDNode>(Node->getOperand(3))->getVT()) {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000835 default: Node->dump(); assert(0 && "Bad sign extend!");
Misha Brukman4633f1c2005-04-21 23:13:11 +0000836 case MVT::i32: Opc = Alpha::LDL;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000837 assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000838 case MVT::i16: Opc = Alpha::LDWU;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000839 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharthf311e8b2005-02-07 05:18:02 +0000840 case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
Misha Brukman4633f1c2005-04-21 23:13:11 +0000841 case MVT::i8: Opc = Alpha::LDBU;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000842 assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000843 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000844
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000845 int i, j, k;
846 if (EnableAlphaLSMark)
847 getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue(),
848 i, j, k);
849
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000850 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
851 if (GASD && !GASD->getGlobal()->isExternal()) {
852 Tmp1 = MakeReg(MVT::i64);
853 AlphaLowering.restoreGP(BB);
854 BuildMI(BB, Alpha::LDAHr, 2, Tmp1)
855 .addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
856 if (EnableAlphaLSMark)
857 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
858 .addImm(getUID());
859 BuildMI(BB, GetRelVersion(Opc), 2, Result)
860 .addGlobalAddress(GASD->getGlobal()).addReg(Tmp1);
Chris Lattnerbce81ae2005-07-10 01:56:13 +0000861 } else if (ConstantPoolSDNode *CP =
862 dyn_cast<ConstantPoolSDNode>(Address)) {
Chris Lattner5839bf22005-08-26 17:15:30 +0000863 unsigned CPIdx = BB->getParent()->getConstantPool()->
864 getConstantPoolIndex(CP->get());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000865 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000866 has_sym = true;
Andrew Lenharthfe895e32005-06-27 17:15:36 +0000867 Tmp1 = MakeReg(MVT::i64);
Chris Lattner5839bf22005-08-26 17:15:30 +0000868 BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPIdx)
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000869 .addReg(Alpha::R29);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000870 if (EnableAlphaLSMark)
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000871 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
872 .addImm(getUID());
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000873 BuildMI(BB, GetRelVersion(Opc), 2, Result)
Chris Lattner5839bf22005-08-26 17:15:30 +0000874 .addConstantPoolIndex(CPIdx).addReg(Tmp1);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000875 } else if(Address.getOpcode() == ISD::FrameIndex) {
876 if (EnableAlphaLSMark)
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000877 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
878 .addImm(getUID());
Andrew Lenharth032f2352005-02-22 21:59:48 +0000879 BuildMI(BB, Opc, 2, Result)
880 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
881 .addReg(Alpha::F31);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000882 } else {
883 long offset;
884 SelectAddr(Address, Tmp1, offset);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000885 if (EnableAlphaLSMark)
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000886 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
887 .addImm(getUID());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000888 BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
889 }
Andrew Lenharth9e8d1092005-02-06 15:40:40 +0000890 return Result;
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000891 }
Andrew Lenharth2f8fb772005-01-25 00:35:34 +0000892
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000893 case ISD::GlobalAddress:
894 AlphaLowering.restoreGP(BB);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +0000895 has_sym = true;
Jeff Cohen00b168892005-07-27 06:12:32 +0000896
Andrew Lenharth2f5bca52005-07-03 20:06:13 +0000897 Reg = Result = MakeReg(MVT::i64);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000898
899 if (EnableAlphaLSMark)
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000900 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
Andrew Lenharth06ef8842005-06-29 18:54:02 +0000901 .addImm(getUID());
Andrew Lenharthc7989ce2005-06-29 00:31:08 +0000902
903 BuildMI(BB, Alpha::LDQl, 2, Result)
Andrew Lenharthc95d9842005-06-27 21:11:40 +0000904 .addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal())
905 .addReg(Alpha::R29);
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000906 return Result;
907
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000908 case ISD::ExternalSymbol:
909 AlphaLowering.restoreGP(BB);
910 has_sym = true;
911
Andrew Lenharth2f5bca52005-07-03 20:06:13 +0000912 Reg = Result = MakeReg(MVT::i64);
913
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000914 if (EnableAlphaLSMark)
915 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
916 .addImm(getUID());
917
918 BuildMI(BB, Alpha::LDQl, 2, Result)
919 .addExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol())
920 .addReg(Alpha::R29);
921 return Result;
922
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +0000923 case ISD::TAILCALL:
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000924 case ISD::CALL:
925 {
926 Select(N.getOperand(0));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000927
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000928 // The chain for this call is now lowered.
Andrew Lenharthf3f951a2005-07-22 20:50:29 +0000929 ExprMap[N.getValue(Node->getNumValues()-1)] = notIn;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000930
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000931 //grab the arguments
932 std::vector<unsigned> argvregs;
Andrew Lenharth7b2a5272005-01-30 20:42:36 +0000933 //assert(Node->getNumOperands() < 8 && "Only 6 args supported");
Andrew Lenharth304d0f32005-01-22 23:41:55 +0000934 for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000935 argvregs.push_back(SelectExpr(N.getOperand(i)));
Misha Brukman4633f1c2005-04-21 23:13:11 +0000936
Andrew Lenharth684f2292005-01-30 00:35:27 +0000937 //in reg args
938 for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000939 {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000940 unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000941 Alpha::R19, Alpha::R20, Alpha::R21};
Misha Brukman4633f1c2005-04-21 23:13:11 +0000942 unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000943 Alpha::F19, Alpha::F20, Alpha::F21};
944 switch(N.getOperand(i+2).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000945 default:
946 Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000947 N.getOperand(i).Val->dump();
Misha Brukman4633f1c2005-04-21 23:13:11 +0000948 std::cerr << "Type for " << i << " is: " <<
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000949 N.getOperand(i+2).getValueType() << "\n";
950 assert(0 && "Unknown value type for call");
951 case MVT::i1:
952 case MVT::i8:
953 case MVT::i16:
954 case MVT::i32:
955 case MVT::i64:
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000956 BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i])
957 .addReg(argvregs[i]);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000958 break;
959 case MVT::f32:
960 case MVT::f64:
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000961 BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i])
962 .addReg(argvregs[i]);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000963 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000964 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000965 }
Andrew Lenharth684f2292005-01-30 00:35:27 +0000966 //in mem args
967 for (int i = 6, e = argvregs.size(); i < e; ++i)
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000968 {
969 switch(N.getOperand(i+2).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000970 default:
971 Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000972 N.getOperand(i).Val->dump();
Misha Brukman4633f1c2005-04-21 23:13:11 +0000973 std::cerr << "Type for " << i << " is: " <<
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000974 N.getOperand(i+2).getValueType() << "\n";
975 assert(0 && "Unknown value type for call");
976 case MVT::i1:
977 case MVT::i8:
978 case MVT::i16:
979 case MVT::i32:
980 case MVT::i64:
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000981 BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
982 .addReg(Alpha::R30);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000983 break;
984 case MVT::f32:
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000985 BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
986 .addReg(Alpha::R30);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000987 break;
988 case MVT::f64:
Andrew Lenharthd4653b12005-06-27 17:39:17 +0000989 BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
990 .addReg(Alpha::R30);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000991 break;
Andrew Lenharth684f2292005-01-30 00:35:27 +0000992 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000993 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +0000994 //build the right kind of call
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000995 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(N.getOperand(1));
996 if (GASD && !GASD->getGlobal()->isExternal()) {
997 //use PC relative branch call
Andrew Lenharth63f2ab22005-02-10 06:25:22 +0000998 AlphaLowering.restoreGP(BB);
Andrew Lenharthcf8bf382005-07-01 19:12:13 +0000999 BuildMI(BB, Alpha::BSR, 1, Alpha::R26)
1000 .addGlobalAddress(GASD->getGlobal(),true);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001001 } else {
1002 //no need to restore GP as we are doing an indirect call
1003 Tmp1 = SelectExpr(N.getOperand(1));
1004 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
1005 BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
1006 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001007
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001008 //push the result into a virtual register
Misha Brukman4633f1c2005-04-21 23:13:11 +00001009
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001010 switch (Node->getValueType(0)) {
1011 default: Node->dump(); assert(0 && "Unknown value type for call result!");
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001012 case MVT::Other: return notIn;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001013 case MVT::i64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001014 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
1015 break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001016 case MVT::f32:
1017 case MVT::f64:
Misha Brukman7847fca2005-04-22 17:54:37 +00001018 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
1019 break;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001020 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001021 return Result+N.ResNo;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001022 }
1023
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001024 case ISD::SIGN_EXTEND_INREG:
1025 {
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001026 //do SDIV opt for all levels of ints if not dividing by a constant
1027 if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV
1028 && N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant)
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001029 {
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001030 unsigned Tmp4 = MakeReg(MVT::f64);
1031 unsigned Tmp5 = MakeReg(MVT::f64);
1032 unsigned Tmp6 = MakeReg(MVT::f64);
1033 unsigned Tmp7 = MakeReg(MVT::f64);
1034 unsigned Tmp8 = MakeReg(MVT::f64);
1035 unsigned Tmp9 = MakeReg(MVT::f64);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001036
1037 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1038 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1039 MoveInt2FP(Tmp1, Tmp4, true);
1040 MoveInt2FP(Tmp2, Tmp5, true);
Andrew Lenharth98169be2005-07-28 18:14:47 +00001041 BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Alpha::F31).addReg(Tmp4);
1042 BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Alpha::F31).addReg(Tmp5);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001043 BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
Andrew Lenharth98169be2005-07-28 18:14:47 +00001044 BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Alpha::F31).addReg(Tmp8);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001045 MoveFP2Int(Tmp9, Result, true);
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001046 return Result;
1047 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001048
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001049 //Alpha has instructions for a bunch of signed 32 bit stuff
Chris Lattnerbce81ae2005-07-10 01:56:13 +00001050 if(cast<VTSDNode>(Node->getOperand(1))->getVT() == MVT::i32) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001051 switch (N.getOperand(0).getOpcode()) {
1052 case ISD::ADD:
1053 case ISD::SUB:
1054 case ISD::MUL:
1055 {
1056 bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
1057 bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
1058 //FIXME: first check for Scaled Adds and Subs!
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001059 if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL &&
Andrew Lenharthd2284272005-08-15 14:31:37 +00001060 isSIntImmediateBounded(N.getOperand(0).getOperand(0).getOperand(1), SImm, 2, 3))
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001061 {
Andrew Lenharthd2284272005-08-15 14:31:37 +00001062 bool use4 = SImm == 2;
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001063 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
1064 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
1065 BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL),
1066 2,Result).addReg(Tmp1).addReg(Tmp2);
1067 }
1068 else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL &&
Andrew Lenharthd2284272005-08-15 14:31:37 +00001069 isSIntImmediateBounded(N.getOperand(0).getOperand(1).getOperand(1), SImm, 2, 3))
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001070 {
Andrew Lenharthd2284272005-08-15 14:31:37 +00001071 bool use4 = SImm == 2;
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001072 Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
1073 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1074 BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2);
1075 }
Andrew Lenharthd2284272005-08-15 14:31:37 +00001076 else if(isSIntImmediateBounded(N.getOperand(0).getOperand(1), SImm, 0, 255))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001077 { //Normal imm add/sub
1078 Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001079 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001080 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001081 }
Andrew Lenharthd2284272005-08-15 14:31:37 +00001082 else if(!isMul && isSIntImmediate(N.getOperand(0).getOperand(1), SImm) &&
1083 (((SImm << 32) >> 32) >= -255) && (((SImm << 32) >> 32) <= 0))
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001084 { //handle canonicalization
1085 Opc = isAdd ? Alpha::SUBLi : Alpha::ADDLi;
1086 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001087 SImm = 0 - ((SImm << 32) >> 32);
1088 assert(SImm >= 0 && SImm <= 255);
1089 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001090 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001091 else
1092 { //Normal add/sub
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001093 Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001094 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001095 Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001096 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1097 }
1098 return Result;
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001099 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001100 default: break; //Fall Though;
1101 }
1102 } //Every thing else fall though too, including unhandled opcodes above
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001103 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001104 //std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
Chris Lattnerbce81ae2005-07-10 01:56:13 +00001105 switch(cast<VTSDNode>(Node->getOperand(1))->getVT()) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001106 default:
1107 Node->dump();
1108 assert(0 && "Sign Extend InReg not there yet");
1109 break;
1110 case MVT::i32:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001111 {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001112 BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001113 break;
1114 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001115 case MVT::i16:
Andrew Lenharthf3f951a2005-07-22 20:50:29 +00001116 BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001117 break;
1118 case MVT::i8:
Andrew Lenharthf3f951a2005-07-22 20:50:29 +00001119 BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Alpha::R31).addReg(Tmp1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001120 break;
Andrew Lenharthebce5042005-02-12 19:35:12 +00001121 case MVT::i1:
1122 Tmp2 = MakeReg(MVT::i64);
1123 BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001124 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2);
Andrew Lenharthebce5042005-02-12 19:35:12 +00001125 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001126 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001127 return Result;
1128 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001129
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001130 case ISD::SETCC:
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001131 {
Chris Lattner88ac32c2005-08-09 20:21:10 +00001132 ISD::CondCode CC = cast<CondCodeSDNode>(N.getOperand(2))->get();
1133 if (MVT::isInteger(N.getOperand(0).getValueType())) {
1134 bool isConst = false;
1135 int dir;
Misha Brukman7847fca2005-04-22 17:54:37 +00001136
Chris Lattner88ac32c2005-08-09 20:21:10 +00001137 //Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001138 if(isSIntImmediate(N.getOperand(1), SImm) && SImm <= 255 && SImm >= 0)
Chris Lattner88ac32c2005-08-09 20:21:10 +00001139 isConst = true;
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001140
Chris Lattner88ac32c2005-08-09 20:21:10 +00001141 switch (CC) {
1142 default: Node->dump(); assert(0 && "Unknown integer comparison!");
1143 case ISD::SETEQ:
1144 Opc = isConst ? Alpha::CMPEQi : Alpha::CMPEQ; dir=1; break;
1145 case ISD::SETLT:
1146 Opc = isConst ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
1147 case ISD::SETLE:
1148 Opc = isConst ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
1149 case ISD::SETGT: Opc = Alpha::CMPLT; dir = 2; break;
1150 case ISD::SETGE: Opc = Alpha::CMPLE; dir = 2; break;
1151 case ISD::SETULT:
1152 Opc = isConst ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
1153 case ISD::SETUGT: Opc = Alpha::CMPULT; dir = 2; break;
1154 case ISD::SETULE:
1155 Opc = isConst ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
1156 case ISD::SETUGE: Opc = Alpha::CMPULE; dir = 2; break;
1157 case ISD::SETNE: {//Handle this one special
1158 //std::cerr << "Alpha does not have a setne.\n";
1159 //abort();
1160 Tmp1 = SelectExpr(N.getOperand(0));
1161 Tmp2 = SelectExpr(N.getOperand(1));
1162 Tmp3 = MakeReg(MVT::i64);
1163 BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
1164 //Remeber we have the Inv for this CC
1165 CCInvMap[N] = Tmp3;
1166 //and invert
1167 BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
1168 return Result;
1169 }
1170 }
1171 if (dir == 1) {
1172 Tmp1 = SelectExpr(N.getOperand(0));
1173 if (isConst) {
Andrew Lenharthd2284272005-08-15 14:31:37 +00001174 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
Chris Lattner88ac32c2005-08-09 20:21:10 +00001175 } else {
Andrew Lenharthd2bb9602005-01-27 07:50:35 +00001176 Tmp2 = SelectExpr(N.getOperand(1));
Andrew Lenharth694c2982005-06-26 23:01:11 +00001177 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001178 }
Chris Lattner88ac32c2005-08-09 20:21:10 +00001179 } else { //if (dir == 2) {
1180 Tmp1 = SelectExpr(N.getOperand(1));
1181 Tmp2 = SelectExpr(N.getOperand(0));
1182 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
Andrew Lenharthd4bdd542005-02-05 16:41:03 +00001183 }
Chris Lattner88ac32c2005-08-09 20:21:10 +00001184 } else {
1185 //do the comparison
1186 Tmp1 = MakeReg(MVT::f64);
1187 bool inv = SelectFPSetCC(N, Tmp1);
1188
1189 //now arrange for Result (int) to have a 1 or 0
1190 Tmp2 = MakeReg(MVT::i64);
1191 BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
1192 Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
1193 BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
Andrew Lenharth9818c052005-02-05 13:19:12 +00001194 }
Andrew Lenharth3d65d312005-01-27 03:49:45 +00001195 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001196 }
Misha Brukman4633f1c2005-04-21 23:13:11 +00001197
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001198 case ISD::CopyFromReg:
1199 {
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001200 ++count_ins;
1201
Andrew Lenharth40831c52005-01-28 06:57:18 +00001202 // Make sure we generate both values.
Andrew Lenharthcc1b16f2005-01-28 23:17:54 +00001203 if (Result != notIn)
Misha Brukman7847fca2005-04-22 17:54:37 +00001204 ExprMap[N.getValue(1)] = notIn; // Generate the token
Andrew Lenharth40831c52005-01-28 06:57:18 +00001205 else
Misha Brukman7847fca2005-04-22 17:54:37 +00001206 Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
Misha Brukman4633f1c2005-04-21 23:13:11 +00001207
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001208 SDOperand Chain = N.getOperand(0);
1209
1210 Select(Chain);
Chris Lattner707ebc52005-08-16 21:56:37 +00001211 unsigned r = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001212 //std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
Andrew Lenharth619fb522005-07-04 20:07:21 +00001213 if (MVT::isFloatingPoint(N.getValue(0).getValueType()))
Andrew Lenharthc7989ce2005-06-29 00:31:08 +00001214 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
1215 else
1216 BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001217 return Result;
1218 }
1219
Misha Brukman4633f1c2005-04-21 23:13:11 +00001220 //Most of the plain arithmetic and logic share the same form, and the same
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001221 //constant immediate test
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001222 case ISD::XOR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001223 //Match Not
Andrew Lenharthd2284272005-08-15 14:31:37 +00001224 if (isSIntImmediate(N.getOperand(1), SImm) && SImm == -1) {
1225 Tmp1 = SelectExpr(N.getOperand(0));
1226 BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
1227 return Result;
1228 }
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001229 //Fall through
1230 case ISD::AND:
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001231 //handle zap
Andrew Lenharthd2284272005-08-15 14:31:37 +00001232 if (opcode == ISD::AND && isUIntImmediate(N.getOperand(1), UImm))
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001233 {
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001234 unsigned int build = 0;
1235 for(int i = 0; i < 8; ++i)
1236 {
Andrew Lenharthd2284272005-08-15 14:31:37 +00001237 if ((UImm & 0x00FF) == 0x00FF)
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001238 build |= 1 << i;
Andrew Lenharthd2284272005-08-15 14:31:37 +00001239 else if ((UImm & 0x00FF) != 0)
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001240 { build = 0; break; }
Andrew Lenharthd2284272005-08-15 14:31:37 +00001241 UImm >>= 8;
Andrew Lenharth483f22d2005-04-13 03:47:03 +00001242 }
1243 if (build)
1244 {
1245 Tmp1 = SelectExpr(N.getOperand(0));
1246 BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build);
1247 return Result;
1248 }
1249 }
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001250 case ISD::OR:
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001251 //Check operand(0) == Not
Misha Brukman4633f1c2005-04-21 23:13:11 +00001252 if (N.getOperand(0).getOpcode() == ISD::XOR &&
Andrew Lenharthd2284272005-08-15 14:31:37 +00001253 isSIntImmediate(N.getOperand(0).getOperand(1), SImm) && SImm == -1) {
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001254 switch(opcode) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001255 case ISD::AND: Opc = Alpha::BIC; break;
1256 case ISD::OR: Opc = Alpha::ORNOT; break;
1257 case ISD::XOR: Opc = Alpha::EQV; break;
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001258 }
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001259 Tmp1 = SelectExpr(N.getOperand(1));
1260 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
1261 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1262 return Result;
1263 }
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001264 //Check operand(1) == Not
Misha Brukman4633f1c2005-04-21 23:13:11 +00001265 if (N.getOperand(1).getOpcode() == ISD::XOR &&
Andrew Lenharthd2284272005-08-15 14:31:37 +00001266 isSIntImmediate(N.getOperand(1).getOperand(1), SImm) && SImm == -1) {
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001267 switch(opcode) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001268 case ISD::AND: Opc = Alpha::BIC; break;
1269 case ISD::OR: Opc = Alpha::ORNOT; break;
1270 case ISD::XOR: Opc = Alpha::EQV; break;
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001271 }
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001272 Tmp1 = SelectExpr(N.getOperand(0));
1273 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
1274 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1275 return Result;
1276 }
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001277 //Fall through
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001278 case ISD::SHL:
1279 case ISD::SRL:
Andrew Lenharth2c594352005-01-29 15:42:07 +00001280 case ISD::SRA:
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001281 case ISD::MUL:
Andrew Lenharthd2284272005-08-15 14:31:37 +00001282 if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255)) {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001283 switch(opcode) {
1284 case ISD::AND: Opc = Alpha::ANDi; break;
1285 case ISD::OR: Opc = Alpha::BISi; break;
1286 case ISD::XOR: Opc = Alpha::XORi; break;
1287 case ISD::SHL: Opc = Alpha::SLi; break;
1288 case ISD::SRL: Opc = Alpha::SRLi; break;
1289 case ISD::SRA: Opc = Alpha::SRAi; break;
1290 case ISD::MUL: Opc = Alpha::MULQi; break;
1291 };
1292 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001293 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001294 } else {
1295 switch(opcode) {
1296 case ISD::AND: Opc = Alpha::AND; break;
1297 case ISD::OR: Opc = Alpha::BIS; break;
1298 case ISD::XOR: Opc = Alpha::XOR; break;
1299 case ISD::SHL: Opc = Alpha::SL; break;
1300 case ISD::SRL: Opc = Alpha::SRL; break;
1301 case ISD::SRA: Opc = Alpha::SRA; break;
Jeff Cohen00b168892005-07-27 06:12:32 +00001302 case ISD::MUL:
1303 Opc = isFP ? (DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS)
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001304 : Alpha::MULQ;
1305 break;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001306 };
1307 Tmp1 = SelectExpr(N.getOperand(0));
1308 Tmp2 = SelectExpr(N.getOperand(1));
1309 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1310 }
Andrew Lenharth2d6f0222005-01-24 19:44:07 +00001311 return Result;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001312
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001313 case ISD::ADD:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001314 case ISD::SUB:
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001315 if (isFP) {
1316 ConstantFPSDNode *CN;
1317 if (opcode == ISD::ADD)
1318 Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS;
1319 else
1320 Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS;
1321 if (opcode == ISD::SUB
1322 && (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
1323 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1324 {
1325 Tmp2 = SelectExpr(N.getOperand(1));
1326 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
1327 } else {
1328 Tmp1 = SelectExpr(N.getOperand(0));
1329 Tmp2 = SelectExpr(N.getOperand(1));
1330 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1331 }
1332 return Result;
1333 } else {
Andrew Lenharth40831c52005-01-28 06:57:18 +00001334 bool isAdd = opcode == ISD::ADD;
1335
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001336 //first check for Scaled Adds and Subs!
1337 //Valid for add and sub
Andrew Lenharthd2284272005-08-15 14:31:37 +00001338 if(N.getOperand(0).getOpcode() == ISD::SHL &&
1339 isSIntImmediate(N.getOperand(0).getOperand(1), SImm) &&
1340 (SImm == 2 || SImm == 3)) {
1341 bool use4 = SImm == 2;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001342 Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001343 if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255))
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001344 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
Andrew Lenharthd2284272005-08-15 14:31:37 +00001345 2, Result).addReg(Tmp2).addImm(SImm);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001346 else {
1347 Tmp1 = SelectExpr(N.getOperand(1));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001348 BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
1349 2, Result).addReg(Tmp2).addReg(Tmp1);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001350 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001351 }
1352 //Position prevents subs
Andrew Lenharth273a1f92005-04-07 14:18:13 +00001353 else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd &&
Andrew Lenharthd2284272005-08-15 14:31:37 +00001354 isSIntImmediate(N.getOperand(1).getOperand(1), SImm) &&
1355 (SImm == 2 || SImm == 3)) {
1356 bool use4 = SImm == 2;
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001357 Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001358 if (isSIntImmediateBounded(N.getOperand(0), SImm, 0, 255))
1359 BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2).addImm(SImm);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001360 else {
1361 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001362 BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1);
Andrew Lenharthf77f3952005-04-06 20:59:59 +00001363 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001364 }
1365 //small addi
Andrew Lenharthd2284272005-08-15 14:31:37 +00001366 else if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255))
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001367 { //Normal imm add/sub
1368 Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
1369 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001370 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001371 }
Andrew Lenharthd2284272005-08-15 14:31:37 +00001372 else if(isSIntImmediateBounded(N.getOperand(1), SImm, -255, 0))
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001373 { //inverted imm add/sub
1374 Opc = isAdd ? Alpha::SUBQi : Alpha::ADDQi;
1375 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharthd2284272005-08-15 14:31:37 +00001376 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(-SImm);
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001377 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001378 //larger addi
Andrew Lenharthd2284272005-08-15 14:31:37 +00001379 else if(isSIntImmediateBounded(N.getOperand(1), SImm, -32767, 32767))
Andrew Lenharth74d00d82005-03-02 17:23:03 +00001380 { //LDA
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001381 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001382 if (!isAdd)
Andrew Lenharthd2284272005-08-15 14:31:37 +00001383 SImm = -SImm;
1384 BuildMI(BB, Alpha::LDA, 2, Result).addImm(SImm).addReg(Tmp1);
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001385 }
1386 //give up and do the operation
1387 else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001388 //Normal add/sub
1389 Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
1390 Tmp1 = SelectExpr(N.getOperand(0));
1391 Tmp2 = SelectExpr(N.getOperand(1));
1392 BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
1393 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001394 return Result;
1395 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001396
Andrew Lenharthdc0b71b2005-03-22 00:24:07 +00001397 case ISD::SDIV:
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001398 if (isFP) {
1399 Tmp1 = SelectExpr(N.getOperand(0));
1400 Tmp2 = SelectExpr(N.getOperand(1));
1401 BuildMI(BB, DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS, 2, Result)
1402 .addReg(Tmp1).addReg(Tmp2);
Andrew Lenharth0cab3752005-06-29 13:35:05 +00001403 return Result;
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001404 } else {
Andrew Lenhartha565c272005-04-06 22:03:13 +00001405 //check if we can convert into a shift!
Andrew Lenharthd2284272005-08-15 14:31:37 +00001406 if (isSIntImmediate(N.getOperand(1), SImm) &&
1407 SImm != 0 && isPowerOf2_64(llabs(SImm))) {
1408 unsigned k = Log2_64(llabs(SImm));
Andrew Lenhartha565c272005-04-06 22:03:13 +00001409 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenhartha565c272005-04-06 22:03:13 +00001410 if (k == 1)
1411 Tmp2 = Tmp1;
1412 else
1413 {
1414 Tmp2 = MakeReg(MVT::i64);
1415 BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1);
1416 }
1417 Tmp3 = MakeReg(MVT::i64);
1418 BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k);
1419 unsigned Tmp4 = MakeReg(MVT::i64);
1420 BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharthd2284272005-08-15 14:31:37 +00001421 if (SImm > 0)
Andrew Lenhartha565c272005-04-06 22:03:13 +00001422 BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k);
1423 else
1424 {
1425 unsigned Tmp5 = MakeReg(MVT::i64);
1426 BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k);
1427 BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5);
1428 }
1429 return Result;
1430 }
1431 }
1432 //Else fall through
1433
1434 case ISD::UDIV:
1435 {
Andrew Lenharthd2284272005-08-15 14:31:37 +00001436 if (isSIntImmediate(N.getOperand(1), SImm) && (SImm >= 2 || SImm <= -2))
Andrew Lenhartha565c272005-04-06 22:03:13 +00001437 {
1438 // If this is a divide by constant, we can emit code using some magic
1439 // constants to implement it as a multiply instead.
1440 ExprMap.erase(N);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001441 if (opcode == ISD::SDIV)
Andrew Lenhartha565c272005-04-06 22:03:13 +00001442 return SelectExpr(BuildSDIVSequence(N));
1443 else
1444 return SelectExpr(BuildUDIVSequence(N));
1445 }
Andrew Lenharth4b8ac152005-04-06 20:25:34 +00001446 }
1447 //else fall though
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001448 case ISD::UREM:
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001449 case ISD::SREM: {
1450 const char* opstr = 0;
Andrew Lenharth40831c52005-01-28 06:57:18 +00001451 switch(opcode) {
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001452 case ISD::UREM: opstr = "__remqu"; break;
1453 case ISD::SREM: opstr = "__remq"; break;
1454 case ISD::UDIV: opstr = "__divqu"; break;
1455 case ISD::SDIV: opstr = "__divq"; break;
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001456 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001457 Tmp1 = SelectExpr(N.getOperand(0));
1458 Tmp2 = SelectExpr(N.getOperand(1));
Jeff Cohen00b168892005-07-27 06:12:32 +00001459 SDOperand Addr =
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001460 ISelDAG->getExternalSymbol(opstr, AlphaLowering.getPointerTy());
1461 Tmp3 = SelectExpr(Addr);
Andrew Lenharth33819132005-03-04 20:09:23 +00001462 //set up regs explicitly (helps Reg alloc)
1463 BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001464 BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001465 BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp3).addReg(Tmp3);
1466 BuildMI(BB, Alpha::JSRs, 2, Alpha::R23).addReg(Alpha::R27).addImm(0);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001467 BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001468 return Result;
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001469 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001470
Andrew Lenharthe76797c2005-02-01 20:40:27 +00001471 case ISD::FP_TO_UINT:
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001472 case ISD::FP_TO_SINT:
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001473 {
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001474 assert (DestType == MVT::i64 && "only quads can be loaded to");
1475 MVT::ValueType SrcType = N.getOperand(0).getValueType();
Andrew Lenharth03824012005-02-07 05:55:55 +00001476 assert (SrcType == MVT::f32 || SrcType == MVT::f64);
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001477 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001478 if (SrcType == MVT::f32)
Misha Brukman7847fca2005-04-22 17:54:37 +00001479 {
1480 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth98169be2005-07-28 18:14:47 +00001481 BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Alpha::F31).addReg(Tmp1);
Misha Brukman7847fca2005-04-22 17:54:37 +00001482 Tmp1 = Tmp2;
1483 }
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001484 Tmp2 = MakeReg(MVT::f64);
Andrew Lenharth98169be2005-07-28 18:14:47 +00001485 BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharth0eaf6ce2005-04-02 21:06:51 +00001486 MoveFP2Int(Tmp2, Result, true);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001487
Andrew Lenharth7efadce2005-01-31 01:44:26 +00001488 return Result;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001489 }
Andrew Lenharth3e98fde2005-01-26 21:54:09 +00001490
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001491 case ISD::SELECT:
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001492 if (isFP) {
1493 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1494 unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE
1495 unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE
1496
1497 SDOperand CC = N.getOperand(0);
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001498
Chris Lattner88ac32c2005-08-09 20:21:10 +00001499 if (CC.getOpcode() == ISD::SETCC &&
1500 !MVT::isInteger(CC.getOperand(0).getValueType())) {
1501 //FP Setcc -> Select yay!
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001502
Jeff Cohen00b168892005-07-27 06:12:32 +00001503
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001504 //for a cmp b: c = a - b;
1505 //a = b: c = 0
1506 //a < b: c < 0
1507 //a > b: c > 0
1508
1509 bool invTest = false;
1510 unsigned Tmp3;
1511
1512 ConstantFPSDNode *CN;
Chris Lattner88ac32c2005-08-09 20:21:10 +00001513 if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1)))
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001514 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
Chris Lattner88ac32c2005-08-09 20:21:10 +00001515 Tmp3 = SelectExpr(CC.getOperand(0));
1516 else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0)))
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001517 && (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
1518 {
Chris Lattner88ac32c2005-08-09 20:21:10 +00001519 Tmp3 = SelectExpr(CC.getOperand(1));
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001520 invTest = true;
1521 }
1522 else
1523 {
Chris Lattner88ac32c2005-08-09 20:21:10 +00001524 unsigned Tmp1 = SelectExpr(CC.getOperand(0));
1525 unsigned Tmp2 = SelectExpr(CC.getOperand(1));
1526 bool isD = CC.getOperand(0).getValueType() == MVT::f64;
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001527 Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
1528 BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
1529 .addReg(Tmp1).addReg(Tmp2);
1530 }
1531
Chris Lattner88ac32c2005-08-09 20:21:10 +00001532 switch (cast<CondCodeSDNode>(CC.getOperand(2))->get()) {
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001533 default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
1534 case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break;
1535 case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break;
1536 case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break;
1537 case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break;
1538 case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break;
1539 case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break;
1540 }
1541 BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3);
1542 return Result;
1543 }
1544 else
1545 {
1546 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
1547 BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV)
1548 .addReg(Tmp1);
1549// // Spill the cond to memory and reload it from there.
1550// unsigned Tmp4 = MakeReg(MVT::f64);
1551// MoveIntFP(Tmp1, Tmp4, true);
1552// //now ideally, we don't have to do anything to the flag...
1553// // Get the condition into the zero flag.
1554// BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4);
1555 return Result;
Jeff Cohen00b168892005-07-27 06:12:32 +00001556 }
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001557 } else {
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001558 //FIXME: look at parent to decide if intCC can be folded, or if setCC(FP)
1559 //and can save stack use
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001560 //Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001561 //Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1562 //Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001563 // Get the condition into the zero flag.
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001564 //BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001565
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001566 SDOperand CC = N.getOperand(0);
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001567
Misha Brukman4633f1c2005-04-21 23:13:11 +00001568 if (CC.getOpcode() == ISD::SETCC &&
Chris Lattner88ac32c2005-08-09 20:21:10 +00001569 !MVT::isInteger(CC.getOperand(0).getValueType()))
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001570 { //FP Setcc -> Int Select
Misha Brukman7847fca2005-04-22 17:54:37 +00001571 Tmp1 = MakeReg(MVT::f64);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001572 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1573 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Misha Brukman7847fca2005-04-22 17:54:37 +00001574 bool inv = SelectFPSetCC(CC, Tmp1);
1575 BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result)
1576 .addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
1577 return Result;
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001578 }
1579 if (CC.getOpcode() == ISD::SETCC) {
Misha Brukman7847fca2005-04-22 17:54:37 +00001580 //Int SetCC -> Select
1581 //Dropping the CC is only useful if we are comparing to 0
Andrew Lenharthd2284272005-08-15 14:31:37 +00001582 if(isSIntImmediateBounded(CC.getOperand(1), SImm, 0, 0)) {
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001583 //figure out a few things
Andrew Lenharthd2284272005-08-15 14:31:37 +00001584 bool useImm = isSIntImmediateBounded(N.getOperand(2), SImm, 0, 255);
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001585
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001586 //Fix up CC
Chris Lattner88ac32c2005-08-09 20:21:10 +00001587 ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get();
Andrew Lenharth694c2982005-06-26 23:01:11 +00001588 if (useImm) //Invert sense to get Imm field right
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001589 cCode = ISD::getSetCCInverse(cCode, true);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001590
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001591 //Choose the CMOV
1592 switch (cCode) {
1593 default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001594 case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
1595 case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break;
1596 case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break;
1597 case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break;
1598 case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break;
1599 case ISD::SETULT: assert(0 && "unsigned < 0 is never true"); break;
1600 case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
1601 //Technically you could have this CC
1602 case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
1603 case ISD::SETUGE: assert(0 && "unsgined >= 0 is always true"); break;
1604 case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001605 }
Chris Lattner88ac32c2005-08-09 20:21:10 +00001606 Tmp1 = SelectExpr(CC.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001607
Andrew Lenharth694c2982005-06-26 23:01:11 +00001608 if (useImm) {
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001609 Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
Andrew Lenharthd2284272005-08-15 14:31:37 +00001610 BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addImm(SImm).addReg(Tmp1);
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001611 } else {
1612 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1613 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
1614 BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1);
1615 }
1616 return Result;
1617 }
Misha Brukman7847fca2005-04-22 17:54:37 +00001618 //Otherwise, fall though
Andrew Lenharth10c085b2005-04-02 22:32:39 +00001619 }
1620 Tmp1 = SelectExpr(N.getOperand(0)); //Cond
Andrew Lenharth63b720a2005-04-03 20:35:21 +00001621 Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
1622 Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001623 BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3)
1624 .addReg(Tmp1);
Misha Brukman4633f1c2005-04-21 23:13:11 +00001625
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001626 return Result;
1627 }
1628
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001629 case ISD::Constant:
1630 {
Andrew Lenharthc0513832005-03-29 19:24:04 +00001631 int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001632 int zero_extend_top = 0;
Andrew Lenharthf075cac2005-07-23 07:46:48 +00001633 if (val > 0 && (val & 0xFFFFFFFF00000000ULL) == 0 &&
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001634 ((int32_t)val < 0)) {
1635 //try a small load and zero extend
1636 val = (int32_t)val;
1637 zero_extend_top = 15;
1638 }
1639
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00001640 if (val <= IMM_HIGH && val >= IMM_LOW) {
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001641 if(!zero_extend_top)
1642 BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
1643 else {
1644 Tmp1 = MakeReg(MVT::i64);
1645 BuildMI(BB, Alpha::LDA, 2, Tmp1).addImm(val).addReg(Alpha::R31);
1646 BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp1).addImm(zero_extend_top);
1647 }
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00001648 }
Misha Brukman7847fca2005-04-22 17:54:37 +00001649 else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT &&
1650 val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
1651 Tmp1 = MakeReg(MVT::i64);
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001652 BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val))
1653 .addReg(Alpha::R31);
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001654 if (!zero_extend_top)
1655 BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
1656 else {
1657 Tmp3 = MakeReg(MVT::i64);
1658 BuildMI(BB, Alpha::LDA, 2, Tmp3).addImm(getLower16(val)).addReg(Tmp1);
1659 BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp3).addImm(zero_extend_top);
1660 }
Andrew Lenharthe87f6c32005-03-11 17:48:05 +00001661 }
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001662 else {
Andrew Lenharth6b137d82005-07-22 22:24:01 +00001663 //re-get the val since we are going to mem anyway
1664 val = (int64_t)cast<ConstantSDNode>(N)->getValue();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001665 MachineConstantPool *CP = BB->getParent()->getConstantPool();
Jeff Cohen00b168892005-07-27 06:12:32 +00001666 ConstantUInt *C =
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001667 ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001668 unsigned CPI = CP->getConstantPoolIndex(C);
1669 AlphaLowering.restoreGP(BB);
Andrew Lenharthfe895e32005-06-27 17:15:36 +00001670 has_sym = true;
1671 Tmp1 = MakeReg(MVT::i64);
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001672 BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPI)
1673 .addReg(Alpha::R29);
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001674 if (EnableAlphaLSMark)
1675 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
1676 .addImm(getUID());
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001677 BuildMI(BB, Alpha::LDQr, 2, Result).addConstantPoolIndex(CPI)
1678 .addReg(Tmp1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001679 }
1680 return Result;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001681 }
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001682 case ISD::FNEG:
1683 if(ISD::FABS == N.getOperand(0).getOpcode())
1684 {
1685 Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
1686 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
1687 } else {
1688 Tmp1 = SelectExpr(N.getOperand(0));
1689 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1);
1690 }
1691 return Result;
1692
1693 case ISD::FABS:
1694 Tmp1 = SelectExpr(N.getOperand(0));
1695 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
1696 return Result;
1697
1698 case ISD::FP_ROUND:
1699 assert (DestType == MVT::f32 &&
1700 N.getOperand(0).getValueType() == MVT::f64 &&
1701 "only f64 to f32 conversion supported here");
1702 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth98169be2005-07-28 18:14:47 +00001703 BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001704 return Result;
1705
1706 case ISD::FP_EXTEND:
1707 assert (DestType == MVT::f64 &&
1708 N.getOperand(0).getValueType() == MVT::f32 &&
1709 "only f32 to f64 conversion supported here");
1710 Tmp1 = SelectExpr(N.getOperand(0));
Andrew Lenharth98169be2005-07-28 18:14:47 +00001711 BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Alpha::F31).addReg(Tmp1);
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001712 return Result;
1713
1714 case ISD::ConstantFP:
1715 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
1716 if (CN->isExactlyValue(+0.0)) {
1717 BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31)
1718 .addReg(Alpha::F31);
1719 } else if ( CN->isExactlyValue(-0.0)) {
1720 BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31)
1721 .addReg(Alpha::F31);
1722 } else {
1723 abort();
1724 }
1725 }
1726 return Result;
1727
1728 case ISD::SINT_TO_FP:
1729 {
1730 assert (N.getOperand(0).getValueType() == MVT::i64
1731 && "only quads can be loaded from");
1732 Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
1733 Tmp2 = MakeReg(MVT::f64);
1734 MoveInt2FP(Tmp1, Tmp2, true);
1735 Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
Andrew Lenharth98169be2005-07-28 18:14:47 +00001736 BuildMI(BB, Opc, 1, Result).addReg(Alpha::F31).addReg(Tmp2);
Andrew Lenharthf4da9452005-06-29 12:49:51 +00001737 return Result;
1738 }
Andrew Lenharthf71df332005-09-04 06:12:19 +00001739
1740 case ISD::AssertSext:
1741 case ISD::AssertZext:
1742 return SelectExpr(N.getOperand(0));
1743
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001744 }
1745
1746 return 0;
1747}
1748
Andrew Lenharthb69f3422005-06-22 17:19:45 +00001749void AlphaISel::Select(SDOperand N) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001750 unsigned Tmp1, Tmp2, Opc;
Andrew Lenharth760270d2005-02-07 23:02:23 +00001751 unsigned opcode = N.getOpcode();
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001752
Nate Begeman85fdeb22005-03-24 04:39:54 +00001753 if (!ExprMap.insert(std::make_pair(N, notIn)).second)
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001754 return; // Already selected.
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001755
1756 SDNode *Node = N.Val;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001757
Andrew Lenharth760270d2005-02-07 23:02:23 +00001758 switch (opcode) {
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001759
1760 default:
1761 Node->dump(); std::cerr << "\n";
1762 assert(0 && "Node not handled yet!");
1763
1764 case ISD::BRCOND: {
Andrew Lenharth445171a2005-02-08 00:40:03 +00001765 SelectBranchCC(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001766 return;
1767 }
1768
1769 case ISD::BR: {
1770 MachineBasicBlock *Dest =
1771 cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
1772
1773 Select(N.getOperand(0));
1774 BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
1775 return;
1776 }
1777
1778 case ISD::ImplicitDef:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001779 ++count_ins;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001780 Select(N.getOperand(0));
Chris Lattner707ebc52005-08-16 21:56:37 +00001781 BuildMI(BB, Alpha::IDEF, 0,
1782 cast<RegisterSDNode>(N.getOperand(1))->getReg());
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001783 return;
Misha Brukman4633f1c2005-04-21 23:13:11 +00001784
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001785 case ISD::EntryToken: return; // Noop
1786
1787 case ISD::TokenFactor:
1788 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
1789 Select(Node->getOperand(i));
Misha Brukman4633f1c2005-04-21 23:13:11 +00001790
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001791 //N.Val->dump(); std::cerr << "\n";
1792 //assert(0 && "Node not handled yet!");
Misha Brukman4633f1c2005-04-21 23:13:11 +00001793
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001794 return;
1795
1796 case ISD::CopyToReg:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001797 ++count_outs;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001798 Select(N.getOperand(0));
Chris Lattner707ebc52005-08-16 21:56:37 +00001799 Tmp1 = SelectExpr(N.getOperand(2));
1800 Tmp2 = cast<RegisterSDNode>(N.getOperand(1))->getReg();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001801
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001802 if (Tmp1 != Tmp2) {
Chris Lattner707ebc52005-08-16 21:56:37 +00001803 if (N.getOperand(2).getValueType() == MVT::f64 ||
1804 N.getOperand(2).getValueType() == MVT::f32)
Andrew Lenharth29219162005-02-07 06:31:44 +00001805 BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
1806 else
1807 BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001808 }
1809 return;
1810
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001811 case ISD::RET:
Andrew Lenhartha32b9e32005-04-08 17:28:49 +00001812 ++count_outs;
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001813 switch (N.getNumOperands()) {
1814 default:
1815 std::cerr << N.getNumOperands() << "\n";
1816 for (unsigned i = 0; i < N.getNumOperands(); ++i)
1817 std::cerr << N.getOperand(i).getValueType() << "\n";
1818 Node->dump();
1819 assert(0 && "Unknown return instruction!");
1820 case 2:
1821 Select(N.getOperand(0));
1822 Tmp1 = SelectExpr(N.getOperand(1));
1823 switch (N.getOperand(1).getValueType()) {
Misha Brukman4633f1c2005-04-21 23:13:11 +00001824 default: Node->dump();
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001825 assert(0 && "All other types should have been promoted!!");
1826 case MVT::f64:
1827 case MVT::f32:
1828 BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
1829 break;
1830 case MVT::i32:
1831 case MVT::i64:
1832 BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
1833 break;
1834 }
1835 break;
1836 case 1:
1837 Select(N.getOperand(0));
1838 break;
1839 }
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001840 // Just emit a 'ret' instruction
Andrew Lenharth6968bff2005-06-27 23:24:11 +00001841 AlphaLowering.restoreRA(BB);
Andrew Lenharthf3f951a2005-07-22 20:50:29 +00001842 BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1);
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001843 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001844
Misha Brukman4633f1c2005-04-21 23:13:11 +00001845 case ISD::TRUNCSTORE:
1846 case ISD::STORE:
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001847 {
Andrew Lenharth9e8d1092005-02-06 15:40:40 +00001848 SDOperand Chain = N.getOperand(0);
1849 SDOperand Value = N.getOperand(1);
1850 SDOperand Address = N.getOperand(2);
1851 Select(Chain);
1852
1853 Tmp1 = SelectExpr(Value); //value
Andrew Lenharth760270d2005-02-07 23:02:23 +00001854
1855 if (opcode == ISD::STORE) {
1856 switch(Value.getValueType()) {
1857 default: assert(0 && "unknown Type in store");
1858 case MVT::i64: Opc = Alpha::STQ; break;
1859 case MVT::f64: Opc = Alpha::STT; break;
1860 case MVT::f32: Opc = Alpha::STS; break;
1861 }
1862 } else { //ISD::TRUNCSTORE
Chris Lattner9fadb4c2005-07-10 00:29:18 +00001863 switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) {
Andrew Lenharth760270d2005-02-07 23:02:23 +00001864 default: assert(0 && "unknown Type in store");
1865 case MVT::i1: //FIXME: DAG does not promote this load
1866 case MVT::i8: Opc = Alpha::STB; break;
1867 case MVT::i16: Opc = Alpha::STW; break;
1868 case MVT::i32: Opc = Alpha::STL; break;
1869 }
Andrew Lenharth65838902005-02-06 16:22:15 +00001870 }
Andrew Lenharth760270d2005-02-07 23:02:23 +00001871
Andrew Lenharth06ef8842005-06-29 18:54:02 +00001872 int i, j, k;
Jeff Cohen00b168892005-07-27 06:12:32 +00001873 if (EnableAlphaLSMark)
1874 getValueInfo(cast<SrcValueSDNode>(N.getOperand(3))->getValue(),
Andrew Lenharth06ef8842005-06-29 18:54:02 +00001875 i, j, k);
Andrew Lenharthb69f3422005-06-22 17:19:45 +00001876
Andrew Lenharthcf8bf382005-07-01 19:12:13 +00001877 GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
1878 if (GASD && !GASD->getGlobal()->isExternal()) {
1879 Tmp2 = MakeReg(MVT::i64);
1880 AlphaLowering.restoreGP(BB);
1881 BuildMI(BB, Alpha::LDAHr, 2, Tmp2)
1882 .addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
1883 if (EnableAlphaLSMark)
1884 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1885 .addImm(getUID());
1886 BuildMI(BB, GetRelVersion(Opc), 3).addReg(Tmp1)
1887 .addGlobalAddress(GASD->getGlobal()).addReg(Tmp2);
Andrew Lenharthfce587e2005-06-29 00:39:17 +00001888 } else if(Address.getOpcode() == ISD::FrameIndex) {
Andrew Lenharthc7989ce2005-06-29 00:31:08 +00001889 if (EnableAlphaLSMark)
Andrew Lenharth06ef8842005-06-29 18:54:02 +00001890 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1891 .addImm(getUID());
Andrew Lenharth032f2352005-02-22 21:59:48 +00001892 BuildMI(BB, Opc, 3).addReg(Tmp1)
1893 .addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
1894 .addReg(Alpha::F31);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +00001895 } else {
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001896 long offset;
1897 SelectAddr(Address, Tmp2, offset);
Andrew Lenharthc7989ce2005-06-29 00:31:08 +00001898 if (EnableAlphaLSMark)
Andrew Lenharth06ef8842005-06-29 18:54:02 +00001899 BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
1900 .addImm(getUID());
Andrew Lenharth63f2ab22005-02-10 06:25:22 +00001901 BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
1902 }
Andrew Lenharthb014d3e2005-02-02 17:32:39 +00001903 return;
1904 }
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001905
1906 case ISD::EXTLOAD:
1907 case ISD::SEXTLOAD:
1908 case ISD::ZEXTLOAD:
1909 case ISD::LOAD:
1910 case ISD::CopyFromReg:
Chris Lattnerb5d8e6e2005-05-13 20:29:26 +00001911 case ISD::TAILCALL:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001912 case ISD::CALL:
Andrew Lenharth032f2352005-02-22 21:59:48 +00001913 case ISD::DYNAMIC_STACKALLOC:
Andrew Lenharth6b9870a2005-01-28 14:06:46 +00001914 ExprMap.erase(N);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001915 SelectExpr(N);
1916 return;
1917
Chris Lattner16cd04d2005-05-12 23:24:06 +00001918 case ISD::CALLSEQ_START:
1919 case ISD::CALLSEQ_END:
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001920 Select(N.getOperand(0));
1921 Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
Misha Brukman4633f1c2005-04-21 23:13:11 +00001922
Chris Lattner16cd04d2005-05-12 23:24:06 +00001923 Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN :
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001924 Alpha::ADJUSTSTACKUP;
1925 BuildMI(BB, Opc, 1).addImm(Tmp1);
1926 return;
Andrew Lenharth95762122005-03-31 21:24:06 +00001927
1928 case ISD::PCMARKER:
1929 Select(N.getOperand(0)); //Chain
Andrew Lenharthd4653b12005-06-27 17:39:17 +00001930 BuildMI(BB, Alpha::PCLABEL, 2)
1931 .addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
Andrew Lenharth95762122005-03-31 21:24:06 +00001932 return;
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001933 }
1934 assert(0 && "Should not be reached!");
1935}
1936
1937
1938/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
1939/// into a machine code representation using pattern matching and a machine
1940/// description file.
1941///
1942FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
Andrew Lenharthb69f3422005-06-22 17:19:45 +00001943 return new AlphaISel(TM);
Andrew Lenharth304d0f32005-01-22 23:41:55 +00001944}
Andrew Lenharth4f7cba52005-04-13 05:19:55 +00001945