blob: e266eda743c99a806c7030953f03defd463976e2 [file] [log] [blame]
Andrew Lenharthaa38ce42005-09-02 18:46:02 +00001//===-- AlphaISelLowering.cpp - Alpha DAG Lowering Implementation ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Andrew Lenharthaa38ce42005-09-02 18:46:02 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AlphaISelLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AlphaISelLowering.h"
15#include "AlphaTargetMachine.h"
Dan Gohman1e93df62010-04-17 14:41:14 +000016#include "AlphaMachineFunctionInfo.h"
Eli Friedman796492d2009-07-19 01:11:32 +000017#include "llvm/CodeGen/CallingConvLower.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000018#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000022#include "llvm/CodeGen/SelectionDAG.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Eli Friedman796492d2009-07-19 01:11:32 +000024#include "llvm/CodeGen/PseudoSourceValue.h"
Anton Korobeynikov362dd0b2010-02-15 22:37:53 +000025#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000026#include "llvm/Constants.h"
27#include "llvm/Function.h"
Andrew Lenharth167bc6e2006-01-23 20:59:50 +000028#include "llvm/Module.h"
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000029#include "llvm/Intrinsics.h"
John Thompson44ab89e2010-10-29 17:29:13 +000030#include "llvm/Type.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000031#include "llvm/Support/CommandLine.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000032#include "llvm/Support/ErrorHandling.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/raw_ostream.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000034using namespace llvm;
35
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000036/// AddLiveIn - This helper function adds the specified physical register to the
37/// MachineFunction as a live in value. It also creates a corresponding virtual
38/// register for it.
39static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
40 TargetRegisterClass *RC) {
41 assert(RC->contains(PReg) && "Not the correct regclass!");
Chris Lattner84bc5422007-12-31 04:13:23 +000042 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
43 MF.getRegInfo().addLiveIn(PReg, VReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000044 return VReg;
45}
46
Chris Lattnerf0144122009-07-28 03:13:23 +000047AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM)
Andrew Lenharth7f285c82009-08-05 18:13:04 +000048 : TargetLowering(TM, new TargetLoweringObjectFileELF()) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000049 // Set up the TargetLowering object.
Dan Gohmana119de82009-06-14 23:30:43 +000050 //I am having problems with shr n i8 1
Owen Anderson825b72b2009-08-11 20:47:22 +000051 setShiftAmountType(MVT::i64);
Duncan Sands03228082008-11-23 15:47:28 +000052 setBooleanContents(ZeroOrOneBooleanContent);
Daniel Dunbara279bc32009-09-20 02:20:51 +000053
Owen Anderson825b72b2009-08-11 20:47:22 +000054 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
55 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
56 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000057
58 // We want to custom lower some of our intrinsics.
Owen Anderson825b72b2009-08-11 20:47:22 +000059 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000060
Owen Anderson825b72b2009-08-11 20:47:22 +000061 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
62 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000063
Owen Anderson825b72b2009-08-11 20:47:22 +000064 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
65 setLoadExtAction(ISD::ZEXTLOAD, MVT::i32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000066
Owen Anderson825b72b2009-08-11 20:47:22 +000067 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
68 setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand);
69 setLoadExtAction(ISD::SEXTLOAD, MVT::i16, Expand);
Evan Cheng8b2794a2006-10-13 21:14:26 +000070
Owen Anderson825b72b2009-08-11 20:47:22 +000071 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Eli Friedman18d643a2009-07-17 05:23:03 +000072
Owen Anderson825b72b2009-08-11 20:47:22 +000073 // setOperationAction(ISD::BRIND, MVT::Other, Expand);
74 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
75 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000076 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
Andrew Lenharthf3fb71b2005-10-06 16:54:29 +000077
Owen Anderson825b72b2009-08-11 20:47:22 +000078 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Andrew Lenharth7794bd32006-06-27 23:19:14 +000079
Owen Anderson825b72b2009-08-11 20:47:22 +000080 setOperationAction(ISD::FREM, MVT::f32, Expand);
81 setOperationAction(ISD::FREM, MVT::f64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000082
Owen Anderson825b72b2009-08-11 20:47:22 +000083 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
84 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
85 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
86 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
Andrew Lenharthcd804962005-11-30 16:10:29 +000087
Andrew Lenharth120ab482005-09-29 22:54:56 +000088 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Owen Anderson825b72b2009-08-11 20:47:22 +000089 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
90 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
91 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000092 }
Owen Anderson825b72b2009-08-11 20:47:22 +000093 setOperationAction(ISD::BSWAP , MVT::i64, Expand);
94 setOperationAction(ISD::ROTL , MVT::i64, Expand);
95 setOperationAction(ISD::ROTR , MVT::i64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000096
Owen Anderson825b72b2009-08-11 20:47:22 +000097 setOperationAction(ISD::SREM , MVT::i64, Custom);
98 setOperationAction(ISD::UREM , MVT::i64, Custom);
99 setOperationAction(ISD::SDIV , MVT::i64, Custom);
100 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthafe3f492006-04-03 03:18:59 +0000101
Owen Anderson825b72b2009-08-11 20:47:22 +0000102 setOperationAction(ISD::ADDC , MVT::i64, Expand);
103 setOperationAction(ISD::ADDE , MVT::i64, Expand);
104 setOperationAction(ISD::SUBC , MVT::i64, Expand);
105 setOperationAction(ISD::SUBE , MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000106
Owen Anderson825b72b2009-08-11 20:47:22 +0000107 setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
108 setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
Chris Lattnerd2a27ee2008-10-09 04:50:56 +0000109
Owen Anderson825b72b2009-08-11 20:47:22 +0000110 setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom);
111 setOperationAction(ISD::SRA_PARTS, MVT::i64, Expand);
112 setOperationAction(ISD::SHL_PARTS, MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000113
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000114 // We don't support sin/cos/sqrt/pow
Owen Anderson825b72b2009-08-11 20:47:22 +0000115 setOperationAction(ISD::FSIN , MVT::f64, Expand);
116 setOperationAction(ISD::FCOS , MVT::f64, Expand);
117 setOperationAction(ISD::FSIN , MVT::f32, Expand);
118 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Andrew Lenharth39424472006-01-19 21:10:38 +0000119
Owen Anderson825b72b2009-08-11 20:47:22 +0000120 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
121 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000122
Owen Anderson825b72b2009-08-11 20:47:22 +0000123 setOperationAction(ISD::FPOW , MVT::f32, Expand);
124 setOperationAction(ISD::FPOW , MVT::f64, Expand);
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000125
Owen Anderson825b72b2009-08-11 20:47:22 +0000126 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000127
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000128 setOperationAction(ISD::BITCAST, MVT::f32, Promote);
Andrew Lenharth3553d862007-01-24 21:09:16 +0000129
Owen Anderson825b72b2009-08-11 20:47:22 +0000130 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000131
132 // Not implemented yet.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000133 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
Owen Anderson825b72b2009-08-11 20:47:22 +0000134 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
135 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Andrew Lenharth739027e2006-01-16 21:22:38 +0000136
Bill Wendling056292f2008-09-16 21:48:12 +0000137 // We want to legalize GlobalAddress and ConstantPool and
138 // ExternalSymbols nodes into the appropriate instructions to
139 // materialize the address.
Owen Anderson825b72b2009-08-11 20:47:22 +0000140 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
141 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
142 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
143 setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000144
Owen Anderson825b72b2009-08-11 20:47:22 +0000145 setOperationAction(ISD::VASTART, MVT::Other, Custom);
146 setOperationAction(ISD::VAEND, MVT::Other, Expand);
147 setOperationAction(ISD::VACOPY, MVT::Other, Custom);
148 setOperationAction(ISD::VAARG, MVT::Other, Custom);
149 setOperationAction(ISD::VAARG, MVT::i32, Custom);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000150
Owen Anderson825b72b2009-08-11 20:47:22 +0000151 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
152 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000153
Andrew Lenharth739027e2006-01-16 21:22:38 +0000154 setStackPointerRegisterToSaveRestore(Alpha::R30);
155
Andrew Lenharth89c0b4a2006-09-05 00:22:25 +0000156 setJumpBufSize(272);
157 setJumpBufAlignment(16);
158
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000159 computeRegisterProperties();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000160}
161
Owen Anderson825b72b2009-08-11 20:47:22 +0000162MVT::SimpleValueType AlphaTargetLowering::getSetCCResultType(EVT VT) const {
163 return MVT::i64;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000164}
165
Andrew Lenharth84a06052006-01-16 19:53:25 +0000166const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
167 switch (Opcode) {
168 default: return 0;
Andrew Lenharth84a06052006-01-16 19:53:25 +0000169 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
170 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
171 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
172 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
173 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
174 case AlphaISD::RelLit: return "Alpha::RelLit";
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000175 case AlphaISD::GlobalRetAddr: return "Alpha::GlobalRetAddr";
Chris Lattner2d90bd52006-01-27 23:39:00 +0000176 case AlphaISD::CALL: return "Alpha::CALL";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000177 case AlphaISD::DivCall: return "Alpha::DivCall";
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000178 case AlphaISD::RET_FLAG: return "Alpha::RET_FLAG";
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000179 case AlphaISD::COND_BRANCH_I: return "Alpha::COND_BRANCH_I";
180 case AlphaISD::COND_BRANCH_F: return "Alpha::COND_BRANCH_F";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000181 }
182}
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000183
Bill Wendlingb4202b82009-07-01 18:50:55 +0000184/// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling20c568f2009-06-30 22:38:32 +0000185unsigned AlphaTargetLowering::getFunctionAlignment(const Function *F) const {
186 return 4;
187}
188
Dan Gohman475871a2008-07-27 21:46:04 +0000189static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +0000190 EVT PtrVT = Op.getValueType();
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000191 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Dan Gohman475871a2008-07-27 21:46:04 +0000192 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
Dale Johannesende064702009-02-06 21:50:26 +0000193 // FIXME there isn't really any debug info here
194 DebugLoc dl = Op.getDebugLoc();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000195
Owen Anderson825b72b2009-08-11 20:47:22 +0000196 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, JTI,
197 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
198 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, JTI, Hi);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000199 return Lo;
200}
201
Chris Lattnere21492b2006-08-11 17:19:54 +0000202//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/
203//AA-PY8AC-TET1_html/callCH3.html#BLOCK21
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000204
205//For now, just use variable size stack frame format
206
207//In a standard call, the first six items are passed in registers $16
208//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
209//of argument-to-register correspondence.) The remaining items are
210//collected in a memory argument list that is a naturally aligned
211//array of quadwords. In a standard call, this list, if present, must
212//be passed at 0(SP).
213//7 ... n 0(SP) ... (n-7)*8(SP)
214
215// //#define FP $15
216// //#define RA $26
217// //#define PV $27
218// //#define GP $29
219// //#define SP $30
220
Eli Friedman796492d2009-07-19 01:11:32 +0000221#include "AlphaGenCallingConv.inc"
222
Dan Gohman98ca4f22009-08-05 01:29:28 +0000223SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000224AlphaTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000225 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000226 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000227 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000228 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000229 const SmallVectorImpl<ISD::InputArg> &Ins,
230 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000231 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000232 // Alpha target does not yet support tail call optimization.
233 isTailCall = false;
Eli Friedman796492d2009-07-19 01:11:32 +0000234
235 // Analyze operands of the call, assigning locations to each operand.
236 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000237 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
238 ArgLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000239
Dan Gohman98ca4f22009-08-05 01:29:28 +0000240 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000241
242 // Get a count of how many bytes are to be pushed on the stack.
243 unsigned NumBytes = CCInfo.getNextStackOffset();
244
245 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
246 getPointerTy(), true));
247
248 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
249 SmallVector<SDValue, 12> MemOpChains;
250 SDValue StackPtr;
251
252 // Walk the register/memloc assignments, inserting copies/loads.
253 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
254 CCValAssign &VA = ArgLocs[i];
255
Dan Gohmanc9403652010-07-07 15:54:55 +0000256 SDValue Arg = OutVals[i];
Eli Friedman796492d2009-07-19 01:11:32 +0000257
258 // Promote the value if needed.
259 switch (VA.getLocInfo()) {
260 default: assert(0 && "Unknown loc info!");
261 case CCValAssign::Full: break;
262 case CCValAssign::SExt:
263 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
264 break;
265 case CCValAssign::ZExt:
266 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
267 break;
268 case CCValAssign::AExt:
269 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
270 break;
271 }
272
273 // Arguments that can be passed on register must be kept at RegsToPass
274 // vector
275 if (VA.isRegLoc()) {
276 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
277 } else {
278 assert(VA.isMemLoc());
279
280 if (StackPtr.getNode() == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +0000281 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedman796492d2009-07-19 01:11:32 +0000282
283 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
284 StackPtr,
285 DAG.getIntPtrConstant(VA.getLocMemOffset()));
286
287 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000288 MachinePointerInfo(),false, false, 0));
Eli Friedman796492d2009-07-19 01:11:32 +0000289 }
290 }
291
292 // Transform all store nodes into one single node because all store nodes are
293 // independent of each other.
294 if (!MemOpChains.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +0000295 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Eli Friedman796492d2009-07-19 01:11:32 +0000296 &MemOpChains[0], MemOpChains.size());
297
298 // Build a sequence of copy-to-reg nodes chained together with token chain and
299 // flag operands which copy the outgoing args into registers. The InFlag in
300 // necessary since all emited instructions must be stuck together.
301 SDValue InFlag;
302 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
303 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
304 RegsToPass[i].second, InFlag);
305 InFlag = Chain.getValue(1);
306 }
307
308 // Returns a chain & a flag for retval copy to use.
Owen Anderson825b72b2009-08-11 20:47:22 +0000309 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
Eli Friedman796492d2009-07-19 01:11:32 +0000310 SmallVector<SDValue, 8> Ops;
311 Ops.push_back(Chain);
312 Ops.push_back(Callee);
313
314 // Add argument registers to the end of the list so that they are
315 // known live into the call.
316 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
317 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
318 RegsToPass[i].second.getValueType()));
319
320 if (InFlag.getNode())
321 Ops.push_back(InFlag);
322
323 Chain = DAG.getNode(AlphaISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
324 InFlag = Chain.getValue(1);
325
326 // Create the CALLSEQ_END node.
327 Chain = DAG.getCALLSEQ_END(Chain,
328 DAG.getConstant(NumBytes, getPointerTy(), true),
329 DAG.getConstant(0, getPointerTy(), true),
330 InFlag);
331 InFlag = Chain.getValue(1);
332
333 // Handle result values, copying them out of physregs into vregs that we
334 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000335 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
336 Ins, dl, DAG, InVals);
Eli Friedman796492d2009-07-19 01:11:32 +0000337}
338
Dan Gohman98ca4f22009-08-05 01:29:28 +0000339/// LowerCallResult - Lower the result values of a call into the
340/// appropriate copies out of appropriate physical registers.
341///
342SDValue
Eli Friedman796492d2009-07-19 01:11:32 +0000343AlphaTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000344 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000345 const SmallVectorImpl<ISD::InputArg> &Ins,
346 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000347 SmallVectorImpl<SDValue> &InVals) const {
Eli Friedman796492d2009-07-19 01:11:32 +0000348
349 // Assign locations to each value returned by this call.
350 SmallVector<CCValAssign, 16> RVLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000351 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs,
Owen Andersone922c022009-07-22 00:24:57 +0000352 *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000353
Dan Gohman98ca4f22009-08-05 01:29:28 +0000354 CCInfo.AnalyzeCallResult(Ins, RetCC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000355
356 // Copy all of the result registers out of their specified physreg.
357 for (unsigned i = 0; i != RVLocs.size(); ++i) {
358 CCValAssign &VA = RVLocs[i];
359
360 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
361 VA.getLocVT(), InFlag).getValue(1);
362 SDValue RetValue = Chain.getValue(0);
363 InFlag = Chain.getValue(2);
364
365 // If this is an 8/16/32-bit value, it is really passed promoted to 64
366 // bits. Insert an assert[sz]ext to capture this, then truncate to the
367 // right size.
368 if (VA.getLocInfo() == CCValAssign::SExt)
369 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
370 DAG.getValueType(VA.getValVT()));
371 else if (VA.getLocInfo() == CCValAssign::ZExt)
372 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
373 DAG.getValueType(VA.getValVT()));
374
375 if (VA.getLocInfo() != CCValAssign::Full)
376 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
377
Dan Gohman98ca4f22009-08-05 01:29:28 +0000378 InVals.push_back(RetValue);
Eli Friedman796492d2009-07-19 01:11:32 +0000379 }
380
Dan Gohman98ca4f22009-08-05 01:29:28 +0000381 return Chain;
Eli Friedman796492d2009-07-19 01:11:32 +0000382}
383
Dan Gohman98ca4f22009-08-05 01:29:28 +0000384SDValue
385AlphaTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000386 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000387 const SmallVectorImpl<ISD::InputArg>
388 &Ins,
389 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000390 SmallVectorImpl<SDValue> &InVals)
391 const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000392
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000393 MachineFunction &MF = DAG.getMachineFunction();
394 MachineFrameInfo *MFI = MF.getFrameInfo();
Dan Gohman1e93df62010-04-17 14:41:14 +0000395 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000396
Andrew Lenharthf71df332005-09-04 06:12:19 +0000397 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000398 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000399 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000400 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Daniel Dunbara279bc32009-09-20 02:20:51 +0000401
Dan Gohman98ca4f22009-08-05 01:29:28 +0000402 for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
Dan Gohman475871a2008-07-27 21:46:04 +0000403 SDValue argt;
Owen Andersone50ed302009-08-10 22:56:29 +0000404 EVT ObjectVT = Ins[ArgNo].VT;
Dan Gohman475871a2008-07-27 21:46:04 +0000405 SDValue ArgVal;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000406
407 if (ArgNo < 6) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000408 switch (ObjectVT.getSimpleVT().SimpleTy) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000409 default:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000410 assert(false && "Invalid value type!");
Owen Anderson825b72b2009-08-11 20:47:22 +0000411 case MVT::f64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000412 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000413 &Alpha::F8RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000414 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000415 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 case MVT::f32:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000417 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000418 &Alpha::F4RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000419 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthd1aab352006-06-21 01:00:43 +0000420 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000421 case MVT::i64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000422 args_int[ArgNo] = AddLiveIn(MF, args_int[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000423 &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000424 ArgVal = DAG.getCopyFromReg(Chain, dl, args_int[ArgNo], MVT::i64);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000425 break;
426 }
427 } else { //more args
428 // Create the frame index object for this incoming parameter...
Evan Chenged2ae132010-07-03 00:40:23 +0000429 int FI = MFI->CreateFixedObject(8, 8 * (ArgNo - 6), true);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000430
431 // Create the SelectionDAG nodes corresponding to a load
432 //from this parameter
Owen Anderson825b72b2009-08-11 20:47:22 +0000433 SDValue FIN = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000434 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000435 false, false, 0);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000436 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000437 InVals.push_back(ArgVal);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000438 }
439
440 // If the functions takes variable number of arguments, copy all regs to stack
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000441 if (isVarArg) {
Dan Gohman1e93df62010-04-17 14:41:14 +0000442 FuncInfo->setVarArgsOffset(Ins.size() * 8);
Dan Gohman475871a2008-07-27 21:46:04 +0000443 std::vector<SDValue> LS;
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000444 for (int i = 0; i < 6; ++i) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000445 if (TargetRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000446 args_int[i] = AddLiveIn(MF, args_int[i], &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000447 SDValue argt = DAG.getCopyFromReg(Chain, dl, args_int[i], MVT::i64);
Evan Chenged2ae132010-07-03 00:40:23 +0000448 int FI = MFI->CreateFixedObject(8, -8 * (6 - i), true);
Dan Gohman1e93df62010-04-17 14:41:14 +0000449 if (i == 0) FuncInfo->setVarArgsBase(FI);
Owen Anderson825b72b2009-08-11 20:47:22 +0000450 SDValue SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000451 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000452 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000453
Dan Gohman6f0d0242008-02-10 18:45:23 +0000454 if (TargetRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000455 args_float[i] = AddLiveIn(MF, args_float[i], &Alpha::F8RCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000456 argt = DAG.getCopyFromReg(Chain, dl, args_float[i], MVT::f64);
Evan Chenged2ae132010-07-03 00:40:23 +0000457 FI = MFI->CreateFixedObject(8, - 8 * (12 - i), true);
Owen Anderson825b72b2009-08-11 20:47:22 +0000458 SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000459 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000460 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000461 }
462
463 //Set up a token factor with all the stack traffic
Owen Anderson825b72b2009-08-11 20:47:22 +0000464 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LS[0], LS.size());
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000465 }
466
Dan Gohman98ca4f22009-08-05 01:29:28 +0000467 return Chain;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000468}
469
Dan Gohman98ca4f22009-08-05 01:29:28 +0000470SDValue
471AlphaTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000472 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000473 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000474 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +0000475 DebugLoc dl, SelectionDAG &DAG) const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000476
477 SDValue Copy = DAG.getCopyToReg(Chain, dl, Alpha::R26,
478 DAG.getNode(AlphaISD::GlobalRetAddr,
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000479 DebugLoc(), MVT::i64),
Dan Gohman98ca4f22009-08-05 01:29:28 +0000480 SDValue());
481 switch (Outs.size()) {
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000482 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000483 llvm_unreachable("Do not know how to return this many arguments!");
Dan Gohman98ca4f22009-08-05 01:29:28 +0000484 case 0:
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000485 break;
Dan Gohman475871a2008-07-27 21:46:04 +0000486 //return SDValue(); // ret void is legal
Dan Gohman98ca4f22009-08-05 01:29:28 +0000487 case 1: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000488 EVT ArgVT = Outs[0].VT;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000489 unsigned ArgReg;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000490 if (ArgVT.isInteger())
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000491 ArgReg = Alpha::R0;
492 else {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000493 assert(ArgVT.isFloatingPoint());
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000494 ArgReg = Alpha::F0;
495 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000496 Copy = DAG.getCopyToReg(Copy, dl, ArgReg,
Dan Gohmanc9403652010-07-07 15:54:55 +0000497 OutVals[0], Copy.getValue(1));
Chris Lattner84bc5422007-12-31 04:13:23 +0000498 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
499 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000500 break;
501 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000502 case 2: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000503 EVT ArgVT = Outs[0].VT;
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000504 unsigned ArgReg1, ArgReg2;
505 if (ArgVT.isInteger()) {
506 ArgReg1 = Alpha::R0;
507 ArgReg2 = Alpha::R1;
508 } else {
509 assert(ArgVT.isFloatingPoint());
510 ArgReg1 = Alpha::F0;
511 ArgReg2 = Alpha::F1;
512 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000513 Copy = DAG.getCopyToReg(Copy, dl, ArgReg1,
Dan Gohmanc9403652010-07-07 15:54:55 +0000514 OutVals[0], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000515 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000516 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg1)
517 == DAG.getMachineFunction().getRegInfo().liveout_end())
518 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg1);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000519 Copy = DAG.getCopyToReg(Copy, dl, ArgReg2,
Dan Gohmanc9403652010-07-07 15:54:55 +0000520 OutVals[1], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000521 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000522 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg2)
523 == DAG.getMachineFunction().getRegInfo().liveout_end())
524 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg2);
525 break;
526 }
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000527 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000528 return DAG.getNode(AlphaISD::RET_FLAG, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000529 MVT::Other, Copy, Copy.getValue(1));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000530}
531
Dan Gohman475871a2008-07-27 21:46:04 +0000532void AlphaTargetLowering::LowerVAARG(SDNode *N, SDValue &Chain,
Dan Gohmand858e902010-04-17 15:26:15 +0000533 SDValue &DataPtr,
534 SelectionDAG &DAG) const {
Duncan Sands126d9072008-07-04 11:47:58 +0000535 Chain = N->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000536 SDValue VAListP = N->getOperand(1);
Duncan Sands126d9072008-07-04 11:47:58 +0000537 const Value *VAListS = cast<SrcValueSDNode>(N->getOperand(2))->getValue();
Dale Johannesenf5d97892009-02-04 01:48:28 +0000538 DebugLoc dl = N->getDebugLoc();
Duncan Sands126d9072008-07-04 11:47:58 +0000539
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000540 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP,
541 MachinePointerInfo(VAListS),
David Greene0e2236c2010-02-15 16:55:07 +0000542 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000543 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
544 DAG.getConstant(8, MVT::i64));
Evan Chengbcc80172010-07-07 22:15:37 +0000545 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Base.getValue(1),
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000546 Tmp, MachinePointerInfo(),
547 MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000548 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sands126d9072008-07-04 11:47:58 +0000549 if (N->getValueType(0).isFloatingPoint())
550 {
551 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson825b72b2009-08-11 20:47:22 +0000552 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
553 DAG.getConstant(8*6, MVT::i64));
554 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
555 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
556 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sands126d9072008-07-04 11:47:58 +0000557 }
558
Owen Anderson825b72b2009-08-11 20:47:22 +0000559 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
560 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000561 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp,
562 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000563 MVT::i32, false, false, 0);
Duncan Sands126d9072008-07-04 11:47:58 +0000564}
565
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000566/// LowerOperation - Provide custom lowering hooks for some operations.
567///
Dan Gohmand858e902010-04-17 15:26:15 +0000568SDValue AlphaTargetLowering::LowerOperation(SDValue Op,
569 SelectionDAG &DAG) const {
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000570 DebugLoc dl = Op.getDebugLoc();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000571 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000572 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000573 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
574
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000575 case ISD::INTRINSIC_WO_CHAIN: {
576 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
577 switch (IntNo) {
578 default: break; // Don't custom lower most intrinsics.
579 case Intrinsic::alpha_umulh:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000580 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesende064702009-02-06 21:50:26 +0000581 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000582 }
583 }
584
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000585 case ISD::SRL_PARTS: {
586 SDValue ShOpLo = Op.getOperand(0);
587 SDValue ShOpHi = Op.getOperand(1);
588 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000589 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
590 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson825b72b2009-08-11 20:47:22 +0000591 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
592 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000593 // if 64 - shAmt <= 0
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
595 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000596 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson825b72b2009-08-11 20:47:22 +0000597 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000598 // else
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
600 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
601 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
602 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000603 // Merge
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
605 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000606 SDValue Ops[2] = { Lo, Hi };
607 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000608 }
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000609 // case ISD::SRA_PARTS:
610
611 // case ISD::SHL_PARTS:
612
613
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000614 case ISD::SINT_TO_FP: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000616 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman475871a2008-07-27 21:46:04 +0000617 SDValue LD;
Owen Anderson825b72b2009-08-11 20:47:22 +0000618 bool isDouble = Op.getValueType() == MVT::f64;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000619 LD = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +0000620 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000621 isDouble?MVT::f64:MVT::f32, LD);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000622 return FP;
623 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000624 case ISD::FP_TO_SINT: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman475871a2008-07-27 21:46:04 +0000626 SDValue src = Op.getOperand(0);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000627
628 if (!isDouble) //Promote
Owen Anderson825b72b2009-08-11 20:47:22 +0000629 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000630
Owen Anderson825b72b2009-08-11 20:47:22 +0000631 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000632
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000633 return DAG.getNode(ISD::BITCAST, dl, MVT::i64, src);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000634 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000635 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000636 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000637 const Constant *C = CP->getConstVal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000638 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesende064702009-02-06 21:50:26 +0000639 // FIXME there isn't really any debug info here
Daniel Dunbara279bc32009-09-20 02:20:51 +0000640
Owen Anderson825b72b2009-08-11 20:47:22 +0000641 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
642 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
643 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000644 return Lo;
645 }
Lauro Ramos Venancio75ce0102007-07-11 17:19:51 +0000646 case ISD::GlobalTLSAddress:
Torok Edwinc23197a2009-07-14 16:55:14 +0000647 llvm_unreachable("TLS not implemented for Alpha.");
Andrew Lenharth4e629512005-12-24 05:36:33 +0000648 case ISD::GlobalAddress: {
649 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000650 const GlobalValue *GV = GSDN->getGlobal();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000651 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i64,
Devang Patel0d881da2010-07-06 22:08:15 +0000652 GSDN->getOffset());
Dale Johannesende064702009-02-06 21:50:26 +0000653 // FIXME there isn't really any debug info here
Andrew Lenharth4e629512005-12-24 05:36:33 +0000654
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000655 // if (!GV->hasWeakLinkage() && !GV->isDeclaration()
Devang Patel0d881da2010-07-06 22:08:15 +0000656 // && !GV->hasLinkOnceLinkage()) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000657 if (GV->hasLocalLinkage()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000658 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
659 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
660 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000661 return Lo;
662 } else
Daniel Dunbara279bc32009-09-20 02:20:51 +0000663 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson825b72b2009-08-11 20:47:22 +0000664 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000665 }
Bill Wendling056292f2008-09-16 21:48:12 +0000666 case ISD::ExternalSymbol: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000667 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendling056292f2008-09-16 21:48:12 +0000668 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson825b72b2009-08-11 20:47:22 +0000669 ->getSymbol(), MVT::i64),
670 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth53d89702005-12-25 01:34:27 +0000671 }
Bill Wendling056292f2008-09-16 21:48:12 +0000672
Andrew Lenharth53d89702005-12-25 01:34:27 +0000673 case ISD::UREM:
674 case ISD::SREM:
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000675 //Expand only on constant case
676 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersone50ed302009-08-10 22:56:29 +0000677 EVT VT = Op.getNode()->getValueType(0);
Gabor Greifba36cb52008-08-28 21:40:38 +0000678 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
679 BuildUDIV(Op.getNode(), DAG, NULL) :
680 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesende064702009-02-06 21:50:26 +0000681 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
682 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000683 return Tmp1;
684 }
685 //fall through
686 case ISD::SDIV:
687 case ISD::UDIV:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000688 if (Op.getValueType().isInteger()) {
Andrew Lenharth253b9e72006-04-06 21:26:32 +0000689 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbara279bc32009-09-20 02:20:51 +0000690 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greifba36cb52008-08-28 21:40:38 +0000691 : BuildUDIV(Op.getNode(), DAG, NULL);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000692 const char* opstr = 0;
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000693 switch (Op.getOpcode()) {
Andrew Lenharth53d89702005-12-25 01:34:27 +0000694 case ISD::UREM: opstr = "__remqu"; break;
695 case ISD::SREM: opstr = "__remq"; break;
696 case ISD::UDIV: opstr = "__divqu"; break;
697 case ISD::SDIV: opstr = "__divq"; break;
698 }
Dan Gohman475871a2008-07-27 21:46:04 +0000699 SDValue Tmp1 = Op.getOperand(0),
Andrew Lenharth53d89702005-12-25 01:34:27 +0000700 Tmp2 = Op.getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +0000701 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
702 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000703 }
704 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000705
Nate Begemanacc398c2006-01-25 18:21:52 +0000706 case ISD::VAARG: {
Dan Gohman475871a2008-07-27 21:46:04 +0000707 SDValue Chain, DataPtr;
Gabor Greifba36cb52008-08-28 21:40:38 +0000708 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Andrew Lenharth66e49582006-01-23 21:51:33 +0000709
Dan Gohman475871a2008-07-27 21:46:04 +0000710 SDValue Result;
Owen Anderson825b72b2009-08-11 20:47:22 +0000711 if (Op.getValueType() == MVT::i32)
Evan Chengbcc80172010-07-07 22:15:37 +0000712 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Chain, DataPtr,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000713 MachinePointerInfo(), MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000714 else
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000715 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr,
716 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000717 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000718 return Result;
719 }
720 case ISD::VACOPY: {
Dan Gohman475871a2008-07-27 21:46:04 +0000721 SDValue Chain = Op.getOperand(0);
722 SDValue DestP = Op.getOperand(1);
723 SDValue SrcP = Op.getOperand(2);
Dan Gohman69de1932008-02-06 22:27:42 +0000724 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
725 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000726
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000727 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP,
728 MachinePointerInfo(SrcS),
David Greene0e2236c2010-02-15 16:55:07 +0000729 false, false, 0);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000730 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000731 MachinePointerInfo(DestS),
David Greene0e2236c2010-02-15 16:55:07 +0000732 false, false, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000733 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson825b72b2009-08-11 20:47:22 +0000734 DAG.getConstant(8, MVT::i64));
Evan Chengbcc80172010-07-07 22:15:37 +0000735 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Result,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000736 NP, MachinePointerInfo(), MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000737 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
738 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000739 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD,
740 MachinePointerInfo(), MVT::i32,
David Greene0e2236c2010-02-15 16:55:07 +0000741 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000742 }
743 case ISD::VASTART: {
Dan Gohman1e93df62010-04-17 14:41:14 +0000744 MachineFunction &MF = DAG.getMachineFunction();
745 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
746
Dan Gohman475871a2008-07-27 21:46:04 +0000747 SDValue Chain = Op.getOperand(0);
748 SDValue VAListP = Op.getOperand(1);
Dan Gohman69de1932008-02-06 22:27:42 +0000749 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000750
Nate Begemanacc398c2006-01-25 18:21:52 +0000751 // vastart stores the address of the VarArgsBase and VarArgsOffset
Dan Gohman1e93df62010-04-17 14:41:14 +0000752 SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsBase(), MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000753 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP,
754 MachinePointerInfo(VAListS), false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
756 DAG.getConstant(8, MVT::i64));
Dan Gohman1e93df62010-04-17 14:41:14 +0000757 return DAG.getTruncStore(S1, dl,
758 DAG.getConstant(FuncInfo->getVarArgsOffset(),
759 MVT::i64),
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000760 SA2, MachinePointerInfo(),
761 MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000762 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000763 case ISD::RETURNADDR:
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000764 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc(), MVT::i64);
Andrew Lenharthac5a5452007-02-08 17:37:41 +0000765 //FIXME: implement
Nate Begemanbcc5f362007-01-29 22:58:52 +0000766 case ISD::FRAMEADDR: break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000767 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000768
Dan Gohman475871a2008-07-27 21:46:04 +0000769 return SDValue();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000770}
Nate Begeman0aed7842006-01-28 03:14:31 +0000771
Duncan Sands1607f052008-12-01 11:39:25 +0000772void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
773 SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000774 SelectionDAG &DAG) const {
Dale Johannesen33c960f2009-02-04 20:06:27 +0000775 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +0000776 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sands126d9072008-07-04 11:47:58 +0000777 N->getOpcode() == ISD::VAARG &&
Nate Begeman0aed7842006-01-28 03:14:31 +0000778 "Unknown node to custom promote!");
Duncan Sands126d9072008-07-04 11:47:58 +0000779
Dan Gohman475871a2008-07-27 21:46:04 +0000780 SDValue Chain, DataPtr;
Duncan Sands126d9072008-07-04 11:47:58 +0000781 LowerVAARG(N, Chain, DataPtr, DAG);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000782 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr,
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000783 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000784 false, false, 0);
Duncan Sands1607f052008-12-01 11:39:25 +0000785 Results.push_back(Res);
786 Results.push_back(SDValue(Res.getNode(), 1));
Nate Begeman0aed7842006-01-28 03:14:31 +0000787}
Andrew Lenharth17255992006-06-21 13:37:27 +0000788
789
790//Inline Asm
791
792/// getConstraintType - Given a constraint letter, return the type of
793/// constraint it is for this target.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000794AlphaTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +0000795AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
796 if (Constraint.size() == 1) {
797 switch (Constraint[0]) {
798 default: break;
799 case 'f':
800 case 'r':
801 return C_RegisterClass;
802 }
803 }
804 return TargetLowering::getConstraintType(Constraint);
Andrew Lenharth17255992006-06-21 13:37:27 +0000805}
806
John Thompson44ab89e2010-10-29 17:29:13 +0000807/// Examine constraint type and operand type and determine a weight value.
808/// This object must already have been set up with the operand type
809/// and the current alternative constraint selected.
810TargetLowering::ConstraintWeight
811AlphaTargetLowering::getSingleConstraintMatchWeight(
812 AsmOperandInfo &info, const char *constraint) const {
813 ConstraintWeight weight = CW_Invalid;
814 Value *CallOperandVal = info.CallOperandVal;
815 // If we don't have a value, we can't do a match,
816 // but allow it at the lowest weight.
817 if (CallOperandVal == NULL)
818 return CW_Default;
819 // Look at the constraint type.
820 switch (*constraint) {
821 default:
822 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
823 break;
824 case 'f':
825 weight = CW_Register;
826 break;
827 }
828 return weight;
829}
830
Andrew Lenharth17255992006-06-21 13:37:27 +0000831std::vector<unsigned> AlphaTargetLowering::
832getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +0000833 EVT VT) const {
Andrew Lenharth17255992006-06-21 13:37:27 +0000834 if (Constraint.size() == 1) {
835 switch (Constraint[0]) {
836 default: break; // Unknown constriant letter
Daniel Dunbara279bc32009-09-20 02:20:51 +0000837 case 'f':
Andrew Lenharth17255992006-06-21 13:37:27 +0000838 return make_vector<unsigned>(Alpha::F0 , Alpha::F1 , Alpha::F2 ,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000839 Alpha::F3 , Alpha::F4 , Alpha::F5 ,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000840 Alpha::F6 , Alpha::F7 , Alpha::F8 ,
841 Alpha::F9 , Alpha::F10, Alpha::F11,
842 Alpha::F12, Alpha::F13, Alpha::F14,
843 Alpha::F15, Alpha::F16, Alpha::F17,
844 Alpha::F18, Alpha::F19, Alpha::F20,
845 Alpha::F21, Alpha::F22, Alpha::F23,
846 Alpha::F24, Alpha::F25, Alpha::F26,
847 Alpha::F27, Alpha::F28, Alpha::F29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000848 Alpha::F30, Alpha::F31, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000849 case 'r':
850 return make_vector<unsigned>(Alpha::R0 , Alpha::R1 , Alpha::R2 ,
851 Alpha::R3 , Alpha::R4 , Alpha::R5 ,
852 Alpha::R6 , Alpha::R7 , Alpha::R8 ,
853 Alpha::R9 , Alpha::R10, Alpha::R11,
854 Alpha::R12, Alpha::R13, Alpha::R14,
855 Alpha::R15, Alpha::R16, Alpha::R17,
856 Alpha::R18, Alpha::R19, Alpha::R20,
857 Alpha::R21, Alpha::R22, Alpha::R23,
858 Alpha::R24, Alpha::R25, Alpha::R26,
859 Alpha::R27, Alpha::R28, Alpha::R29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000860 Alpha::R30, Alpha::R31, 0);
Andrew Lenharth17255992006-06-21 13:37:27 +0000861 }
862 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000863
Andrew Lenharth17255992006-06-21 13:37:27 +0000864 return std::vector<unsigned>();
865}
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000866//===----------------------------------------------------------------------===//
867// Other Lowering Code
868//===----------------------------------------------------------------------===//
869
870MachineBasicBlock *
871AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000872 MachineBasicBlock *BB) const {
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000873 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
874 assert((MI->getOpcode() == Alpha::CAS32 ||
875 MI->getOpcode() == Alpha::CAS64 ||
876 MI->getOpcode() == Alpha::LAS32 ||
877 MI->getOpcode() == Alpha::LAS64 ||
878 MI->getOpcode() == Alpha::SWAP32 ||
879 MI->getOpcode() == Alpha::SWAP64) &&
880 "Unexpected instr type to insert");
881
Daniel Dunbara279bc32009-09-20 02:20:51 +0000882 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000883 MI->getOpcode() == Alpha::LAS32 ||
884 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000885
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000886 //Load locked store conditional for atomic ops take on the same form
887 //start:
888 //ll
889 //do stuff (maybe branch to exit)
890 //sc
891 //test sc and maybe branck to start
892 //exit:
893 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen01b36e62009-02-13 02:30:42 +0000894 DebugLoc dl = MI->getDebugLoc();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000895 MachineFunction::iterator It = BB;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000896 ++It;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000897
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000898 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000899 MachineFunction *F = BB->getParent();
900 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
901 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000902
Dan Gohman14152b42010-07-06 20:24:04 +0000903 sinkMBB->splice(sinkMBB->begin(), thisMBB,
904 llvm::next(MachineBasicBlock::iterator(MI)),
905 thisMBB->end());
906 sinkMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000907
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000908 F->insert(It, llscMBB);
909 F->insert(It, sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000910
Dale Johannesen01b36e62009-02-13 02:30:42 +0000911 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000912
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000913 unsigned reg_res = MI->getOperand(0).getReg(),
914 reg_ptr = MI->getOperand(1).getReg(),
915 reg_v2 = MI->getOperand(2).getReg(),
916 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
917
Daniel Dunbara279bc32009-09-20 02:20:51 +0000918 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000919 reg_res).addImm(0).addReg(reg_ptr);
920 switch (MI->getOpcode()) {
921 case Alpha::CAS32:
922 case Alpha::CAS64: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000923 unsigned reg_cmp
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000924 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000925 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000926 .addReg(reg_v2).addReg(reg_res);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000927 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000928 .addImm(0).addReg(reg_cmp).addMBB(sinkMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000929 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000930 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
931 break;
932 }
933 case Alpha::LAS32:
934 case Alpha::LAS64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000935 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000936 .addReg(reg_res).addReg(reg_v2);
937 break;
938 }
939 case Alpha::SWAP32:
940 case Alpha::SWAP64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000941 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000942 .addReg(reg_v2).addReg(reg_v2);
943 break;
944 }
945 }
Dale Johannesen01b36e62009-02-13 02:30:42 +0000946 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000947 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000948 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000949 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000950 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000951
952 thisMBB->addSuccessor(llscMBB);
953 llscMBB->addSuccessor(llscMBB);
954 llscMBB->addSuccessor(sinkMBB);
Dan Gohman14152b42010-07-06 20:24:04 +0000955 MI->eraseFromParent(); // The pseudo instruction is gone now.
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000956
957 return sinkMBB;
958}
Dan Gohman6520e202008-10-18 02:06:02 +0000959
960bool
961AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
962 // The Alpha target isn't yet aware of offsets.
963 return false;
964}
Evan Chengeb2f9692009-10-27 19:56:55 +0000965
Evan Chenga1eaa3c2009-10-28 01:43:28 +0000966bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
967 if (VT != MVT::f32 && VT != MVT::f64)
968 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +0000969 // +0.0 F31
970 // +0.0f F31
971 // -0.0 -F31
972 // -0.0f -F31
973 return Imm.isZero() || Imm.isNegZero();
974}