blob: 90084a79a38f2e8ea35582db471b850ef26cfddb [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"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000030#include "llvm/Support/CommandLine.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000031#include "llvm/Support/ErrorHandling.h"
Torok Edwindac237e2009-07-08 20:53:28 +000032#include "llvm/Support/raw_ostream.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000033using namespace llvm;
34
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000035/// AddLiveIn - This helper function adds the specified physical register to the
36/// MachineFunction as a live in value. It also creates a corresponding virtual
37/// register for it.
38static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
39 TargetRegisterClass *RC) {
40 assert(RC->contains(PReg) && "Not the correct regclass!");
Chris Lattner84bc5422007-12-31 04:13:23 +000041 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
42 MF.getRegInfo().addLiveIn(PReg, VReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000043 return VReg;
44}
45
Chris Lattnerf0144122009-07-28 03:13:23 +000046AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM)
Andrew Lenharth7f285c82009-08-05 18:13:04 +000047 : TargetLowering(TM, new TargetLoweringObjectFileELF()) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000048 // Set up the TargetLowering object.
Dan Gohmana119de82009-06-14 23:30:43 +000049 //I am having problems with shr n i8 1
Owen Anderson825b72b2009-08-11 20:47:22 +000050 setShiftAmountType(MVT::i64);
Duncan Sands03228082008-11-23 15:47:28 +000051 setBooleanContents(ZeroOrOneBooleanContent);
Daniel Dunbara279bc32009-09-20 02:20:51 +000052
Owen Anderson825b72b2009-08-11 20:47:22 +000053 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
54 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
55 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000056
57 // We want to custom lower some of our intrinsics.
Owen Anderson825b72b2009-08-11 20:47:22 +000058 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000059
Owen Anderson825b72b2009-08-11 20:47:22 +000060 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
61 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000062
Owen Anderson825b72b2009-08-11 20:47:22 +000063 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
64 setLoadExtAction(ISD::ZEXTLOAD, MVT::i32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000065
Owen Anderson825b72b2009-08-11 20:47:22 +000066 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
67 setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand);
68 setLoadExtAction(ISD::SEXTLOAD, MVT::i16, Expand);
Evan Cheng8b2794a2006-10-13 21:14:26 +000069
Owen Anderson825b72b2009-08-11 20:47:22 +000070 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Eli Friedman18d643a2009-07-17 05:23:03 +000071
Owen Anderson825b72b2009-08-11 20:47:22 +000072 // setOperationAction(ISD::BRIND, MVT::Other, Expand);
73 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
74 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000075 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
Andrew Lenharthf3fb71b2005-10-06 16:54:29 +000076
Owen Anderson825b72b2009-08-11 20:47:22 +000077 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Andrew Lenharth7794bd32006-06-27 23:19:14 +000078
Owen Anderson825b72b2009-08-11 20:47:22 +000079 setOperationAction(ISD::FREM, MVT::f32, Expand);
80 setOperationAction(ISD::FREM, MVT::f64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000081
Owen Anderson825b72b2009-08-11 20:47:22 +000082 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
83 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
84 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
85 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
Andrew Lenharthcd804962005-11-30 16:10:29 +000086
Andrew Lenharth120ab482005-09-29 22:54:56 +000087 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Owen Anderson825b72b2009-08-11 20:47:22 +000088 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
89 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
90 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000091 }
Owen Anderson825b72b2009-08-11 20:47:22 +000092 setOperationAction(ISD::BSWAP , MVT::i64, Expand);
93 setOperationAction(ISD::ROTL , MVT::i64, Expand);
94 setOperationAction(ISD::ROTR , MVT::i64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000095
Owen Anderson825b72b2009-08-11 20:47:22 +000096 setOperationAction(ISD::SREM , MVT::i64, Custom);
97 setOperationAction(ISD::UREM , MVT::i64, Custom);
98 setOperationAction(ISD::SDIV , MVT::i64, Custom);
99 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthafe3f492006-04-03 03:18:59 +0000100
Owen Anderson825b72b2009-08-11 20:47:22 +0000101 setOperationAction(ISD::ADDC , MVT::i64, Expand);
102 setOperationAction(ISD::ADDE , MVT::i64, Expand);
103 setOperationAction(ISD::SUBC , MVT::i64, Expand);
104 setOperationAction(ISD::SUBE , MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000105
Owen Anderson825b72b2009-08-11 20:47:22 +0000106 setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
107 setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
Chris Lattnerd2a27ee2008-10-09 04:50:56 +0000108
Owen Anderson825b72b2009-08-11 20:47:22 +0000109 setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom);
110 setOperationAction(ISD::SRA_PARTS, MVT::i64, Expand);
111 setOperationAction(ISD::SHL_PARTS, MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000112
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000113 // We don't support sin/cos/sqrt/pow
Owen Anderson825b72b2009-08-11 20:47:22 +0000114 setOperationAction(ISD::FSIN , MVT::f64, Expand);
115 setOperationAction(ISD::FCOS , MVT::f64, Expand);
116 setOperationAction(ISD::FSIN , MVT::f32, Expand);
117 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Andrew Lenharth39424472006-01-19 21:10:38 +0000118
Owen Anderson825b72b2009-08-11 20:47:22 +0000119 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
120 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000121
Owen Anderson825b72b2009-08-11 20:47:22 +0000122 setOperationAction(ISD::FPOW , MVT::f32, Expand);
123 setOperationAction(ISD::FPOW , MVT::f64, Expand);
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000124
Owen Anderson825b72b2009-08-11 20:47:22 +0000125 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000126
Owen Anderson825b72b2009-08-11 20:47:22 +0000127 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Promote);
Andrew Lenharth3553d862007-01-24 21:09:16 +0000128
Owen Anderson825b72b2009-08-11 20:47:22 +0000129 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000130
131 // Not implemented yet.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000132 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
Owen Anderson825b72b2009-08-11 20:47:22 +0000133 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
134 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Andrew Lenharth739027e2006-01-16 21:22:38 +0000135
Bill Wendling056292f2008-09-16 21:48:12 +0000136 // We want to legalize GlobalAddress and ConstantPool and
137 // ExternalSymbols nodes into the appropriate instructions to
138 // materialize the address.
Owen Anderson825b72b2009-08-11 20:47:22 +0000139 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
140 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
141 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
142 setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000143
Owen Anderson825b72b2009-08-11 20:47:22 +0000144 setOperationAction(ISD::VASTART, MVT::Other, Custom);
145 setOperationAction(ISD::VAEND, MVT::Other, Expand);
146 setOperationAction(ISD::VACOPY, MVT::Other, Custom);
147 setOperationAction(ISD::VAARG, MVT::Other, Custom);
148 setOperationAction(ISD::VAARG, MVT::i32, Custom);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000149
Owen Anderson825b72b2009-08-11 20:47:22 +0000150 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
151 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000152
Andrew Lenharth739027e2006-01-16 21:22:38 +0000153 setStackPointerRegisterToSaveRestore(Alpha::R30);
154
Andrew Lenharth89c0b4a2006-09-05 00:22:25 +0000155 setJumpBufSize(272);
156 setJumpBufAlignment(16);
157
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000158 computeRegisterProperties();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000159}
160
Owen Anderson825b72b2009-08-11 20:47:22 +0000161MVT::SimpleValueType AlphaTargetLowering::getSetCCResultType(EVT VT) const {
162 return MVT::i64;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000163}
164
Andrew Lenharth84a06052006-01-16 19:53:25 +0000165const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
166 switch (Opcode) {
167 default: return 0;
Andrew Lenharth84a06052006-01-16 19:53:25 +0000168 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
169 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
170 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
171 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
172 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
173 case AlphaISD::RelLit: return "Alpha::RelLit";
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000174 case AlphaISD::GlobalRetAddr: return "Alpha::GlobalRetAddr";
Chris Lattner2d90bd52006-01-27 23:39:00 +0000175 case AlphaISD::CALL: return "Alpha::CALL";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000176 case AlphaISD::DivCall: return "Alpha::DivCall";
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000177 case AlphaISD::RET_FLAG: return "Alpha::RET_FLAG";
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000178 case AlphaISD::COND_BRANCH_I: return "Alpha::COND_BRANCH_I";
179 case AlphaISD::COND_BRANCH_F: return "Alpha::COND_BRANCH_F";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000180 }
181}
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000182
Bill Wendlingb4202b82009-07-01 18:50:55 +0000183/// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling20c568f2009-06-30 22:38:32 +0000184unsigned AlphaTargetLowering::getFunctionAlignment(const Function *F) const {
185 return 4;
186}
187
Dan Gohman475871a2008-07-27 21:46:04 +0000188static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +0000189 EVT PtrVT = Op.getValueType();
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000190 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Dan Gohman475871a2008-07-27 21:46:04 +0000191 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
Dale Johannesende064702009-02-06 21:50:26 +0000192 // FIXME there isn't really any debug info here
193 DebugLoc dl = Op.getDebugLoc();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000194
Owen Anderson825b72b2009-08-11 20:47:22 +0000195 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, JTI,
196 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
197 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, JTI, Hi);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000198 return Lo;
199}
200
Chris Lattnere21492b2006-08-11 17:19:54 +0000201//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/
202//AA-PY8AC-TET1_html/callCH3.html#BLOCK21
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000203
204//For now, just use variable size stack frame format
205
206//In a standard call, the first six items are passed in registers $16
207//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
208//of argument-to-register correspondence.) The remaining items are
209//collected in a memory argument list that is a naturally aligned
210//array of quadwords. In a standard call, this list, if present, must
211//be passed at 0(SP).
212//7 ... n 0(SP) ... (n-7)*8(SP)
213
214// //#define FP $15
215// //#define RA $26
216// //#define PV $27
217// //#define GP $29
218// //#define SP $30
219
Eli Friedman796492d2009-07-19 01:11:32 +0000220#include "AlphaGenCallingConv.inc"
221
Dan Gohman98ca4f22009-08-05 01:29:28 +0000222SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000223AlphaTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000224 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000225 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000226 const SmallVectorImpl<ISD::OutputArg> &Outs,
227 const SmallVectorImpl<ISD::InputArg> &Ins,
228 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000229 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000230 // Alpha target does not yet support tail call optimization.
231 isTailCall = false;
Eli Friedman796492d2009-07-19 01:11:32 +0000232
233 // Analyze operands of the call, assigning locations to each operand.
234 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000235 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
236 ArgLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000237
Dan Gohman98ca4f22009-08-05 01:29:28 +0000238 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000239
240 // Get a count of how many bytes are to be pushed on the stack.
241 unsigned NumBytes = CCInfo.getNextStackOffset();
242
243 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
244 getPointerTy(), true));
245
246 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
247 SmallVector<SDValue, 12> MemOpChains;
248 SDValue StackPtr;
249
250 // Walk the register/memloc assignments, inserting copies/loads.
251 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
252 CCValAssign &VA = ArgLocs[i];
253
Dan Gohman98ca4f22009-08-05 01:29:28 +0000254 SDValue Arg = Outs[i].Val;
Eli Friedman796492d2009-07-19 01:11:32 +0000255
256 // Promote the value if needed.
257 switch (VA.getLocInfo()) {
258 default: assert(0 && "Unknown loc info!");
259 case CCValAssign::Full: break;
260 case CCValAssign::SExt:
261 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
262 break;
263 case CCValAssign::ZExt:
264 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
265 break;
266 case CCValAssign::AExt:
267 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
268 break;
269 }
270
271 // Arguments that can be passed on register must be kept at RegsToPass
272 // vector
273 if (VA.isRegLoc()) {
274 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
275 } else {
276 assert(VA.isMemLoc());
277
278 if (StackPtr.getNode() == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +0000279 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedman796492d2009-07-19 01:11:32 +0000280
281 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
282 StackPtr,
283 DAG.getIntPtrConstant(VA.getLocMemOffset()));
284
285 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
David Greene0e2236c2010-02-15 16:55:07 +0000286 PseudoSourceValue::getStack(), 0,
287 false, false, 0));
Eli Friedman796492d2009-07-19 01:11:32 +0000288 }
289 }
290
291 // Transform all store nodes into one single node because all store nodes are
292 // independent of each other.
293 if (!MemOpChains.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +0000294 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Eli Friedman796492d2009-07-19 01:11:32 +0000295 &MemOpChains[0], MemOpChains.size());
296
297 // Build a sequence of copy-to-reg nodes chained together with token chain and
298 // flag operands which copy the outgoing args into registers. The InFlag in
299 // necessary since all emited instructions must be stuck together.
300 SDValue InFlag;
301 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
302 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
303 RegsToPass[i].second, InFlag);
304 InFlag = Chain.getValue(1);
305 }
306
307 // Returns a chain & a flag for retval copy to use.
Owen Anderson825b72b2009-08-11 20:47:22 +0000308 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
Eli Friedman796492d2009-07-19 01:11:32 +0000309 SmallVector<SDValue, 8> Ops;
310 Ops.push_back(Chain);
311 Ops.push_back(Callee);
312
313 // Add argument registers to the end of the list so that they are
314 // known live into the call.
315 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
316 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
317 RegsToPass[i].second.getValueType()));
318
319 if (InFlag.getNode())
320 Ops.push_back(InFlag);
321
322 Chain = DAG.getNode(AlphaISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
323 InFlag = Chain.getValue(1);
324
325 // Create the CALLSEQ_END node.
326 Chain = DAG.getCALLSEQ_END(Chain,
327 DAG.getConstant(NumBytes, getPointerTy(), true),
328 DAG.getConstant(0, getPointerTy(), true),
329 InFlag);
330 InFlag = Chain.getValue(1);
331
332 // Handle result values, copying them out of physregs into vregs that we
333 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000334 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
335 Ins, dl, DAG, InVals);
Eli Friedman796492d2009-07-19 01:11:32 +0000336}
337
Dan Gohman98ca4f22009-08-05 01:29:28 +0000338/// LowerCallResult - Lower the result values of a call into the
339/// appropriate copies out of appropriate physical registers.
340///
341SDValue
Eli Friedman796492d2009-07-19 01:11:32 +0000342AlphaTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000343 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000344 const SmallVectorImpl<ISD::InputArg> &Ins,
345 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000346 SmallVectorImpl<SDValue> &InVals) const {
Eli Friedman796492d2009-07-19 01:11:32 +0000347
348 // Assign locations to each value returned by this call.
349 SmallVector<CCValAssign, 16> RVLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000350 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs,
Owen Andersone922c022009-07-22 00:24:57 +0000351 *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000352
Dan Gohman98ca4f22009-08-05 01:29:28 +0000353 CCInfo.AnalyzeCallResult(Ins, RetCC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000354
355 // Copy all of the result registers out of their specified physreg.
356 for (unsigned i = 0; i != RVLocs.size(); ++i) {
357 CCValAssign &VA = RVLocs[i];
358
359 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
360 VA.getLocVT(), InFlag).getValue(1);
361 SDValue RetValue = Chain.getValue(0);
362 InFlag = Chain.getValue(2);
363
364 // If this is an 8/16/32-bit value, it is really passed promoted to 64
365 // bits. Insert an assert[sz]ext to capture this, then truncate to the
366 // right size.
367 if (VA.getLocInfo() == CCValAssign::SExt)
368 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
369 DAG.getValueType(VA.getValVT()));
370 else if (VA.getLocInfo() == CCValAssign::ZExt)
371 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
372 DAG.getValueType(VA.getValVT()));
373
374 if (VA.getLocInfo() != CCValAssign::Full)
375 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
376
Dan Gohman98ca4f22009-08-05 01:29:28 +0000377 InVals.push_back(RetValue);
Eli Friedman796492d2009-07-19 01:11:32 +0000378 }
379
Dan Gohman98ca4f22009-08-05 01:29:28 +0000380 return Chain;
Eli Friedman796492d2009-07-19 01:11:32 +0000381}
382
Dan Gohman98ca4f22009-08-05 01:29:28 +0000383SDValue
384AlphaTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000385 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000386 const SmallVectorImpl<ISD::InputArg>
387 &Ins,
388 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000389 SmallVectorImpl<SDValue> &InVals)
390 const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000391
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000392 MachineFunction &MF = DAG.getMachineFunction();
393 MachineFrameInfo *MFI = MF.getFrameInfo();
Dan Gohman1e93df62010-04-17 14:41:14 +0000394 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000395
Andrew Lenharthf71df332005-09-04 06:12:19 +0000396 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000397 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000398 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000399 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Daniel Dunbara279bc32009-09-20 02:20:51 +0000400
Dan Gohman98ca4f22009-08-05 01:29:28 +0000401 for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
Dan Gohman475871a2008-07-27 21:46:04 +0000402 SDValue argt;
Owen Andersone50ed302009-08-10 22:56:29 +0000403 EVT ObjectVT = Ins[ArgNo].VT;
Dan Gohman475871a2008-07-27 21:46:04 +0000404 SDValue ArgVal;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000405
406 if (ArgNo < 6) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000407 switch (ObjectVT.getSimpleVT().SimpleTy) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000408 default:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000409 assert(false && "Invalid value type!");
Owen Anderson825b72b2009-08-11 20:47:22 +0000410 case MVT::f64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000411 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000412 &Alpha::F8RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000413 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000414 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000415 case MVT::f32:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000416 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000417 &Alpha::F4RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000418 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthd1aab352006-06-21 01:00:43 +0000419 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000420 case MVT::i64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000421 args_int[ArgNo] = AddLiveIn(MF, args_int[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000422 &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000423 ArgVal = DAG.getCopyFromReg(Chain, dl, args_int[ArgNo], MVT::i64);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000424 break;
425 }
426 } else { //more args
427 // Create the frame index object for this incoming parameter...
Evan Chenged2ae132010-07-03 00:40:23 +0000428 int FI = MFI->CreateFixedObject(8, 8 * (ArgNo - 6), true);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000429
430 // Create the SelectionDAG nodes corresponding to a load
431 //from this parameter
Owen Anderson825b72b2009-08-11 20:47:22 +0000432 SDValue FIN = DAG.getFrameIndex(FI, MVT::i64);
David Greene0e2236c2010-02-15 16:55:07 +0000433 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, NULL, 0,
434 false, false, 0);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000435 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000436 InVals.push_back(ArgVal);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000437 }
438
439 // If the functions takes variable number of arguments, copy all regs to stack
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000440 if (isVarArg) {
Dan Gohman1e93df62010-04-17 14:41:14 +0000441 FuncInfo->setVarArgsOffset(Ins.size() * 8);
Dan Gohman475871a2008-07-27 21:46:04 +0000442 std::vector<SDValue> LS;
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000443 for (int i = 0; i < 6; ++i) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000444 if (TargetRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000445 args_int[i] = AddLiveIn(MF, args_int[i], &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000446 SDValue argt = DAG.getCopyFromReg(Chain, dl, args_int[i], MVT::i64);
Evan Chenged2ae132010-07-03 00:40:23 +0000447 int FI = MFI->CreateFixedObject(8, -8 * (6 - i), true);
Dan Gohman1e93df62010-04-17 14:41:14 +0000448 if (i == 0) FuncInfo->setVarArgsBase(FI);
Owen Anderson825b72b2009-08-11 20:47:22 +0000449 SDValue SDFI = DAG.getFrameIndex(FI, MVT::i64);
David Greene0e2236c2010-02-15 16:55:07 +0000450 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0,
451 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000452
Dan Gohman6f0d0242008-02-10 18:45:23 +0000453 if (TargetRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000454 args_float[i] = AddLiveIn(MF, args_float[i], &Alpha::F8RCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000455 argt = DAG.getCopyFromReg(Chain, dl, args_float[i], MVT::f64);
Evan Chenged2ae132010-07-03 00:40:23 +0000456 FI = MFI->CreateFixedObject(8, - 8 * (12 - i), true);
Owen Anderson825b72b2009-08-11 20:47:22 +0000457 SDFI = DAG.getFrameIndex(FI, MVT::i64);
David Greene0e2236c2010-02-15 16:55:07 +0000458 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0,
459 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000460 }
461
462 //Set up a token factor with all the stack traffic
Owen Anderson825b72b2009-08-11 20:47:22 +0000463 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LS[0], LS.size());
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000464 }
465
Dan Gohman98ca4f22009-08-05 01:29:28 +0000466 return Chain;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000467}
468
Dan Gohman98ca4f22009-08-05 01:29:28 +0000469SDValue
470AlphaTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000471 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000472 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmand858e902010-04-17 15:26:15 +0000473 DebugLoc dl, SelectionDAG &DAG) const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000474
475 SDValue Copy = DAG.getCopyToReg(Chain, dl, Alpha::R26,
476 DAG.getNode(AlphaISD::GlobalRetAddr,
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000477 DebugLoc(), MVT::i64),
Dan Gohman98ca4f22009-08-05 01:29:28 +0000478 SDValue());
479 switch (Outs.size()) {
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000480 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000481 llvm_unreachable("Do not know how to return this many arguments!");
Dan Gohman98ca4f22009-08-05 01:29:28 +0000482 case 0:
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000483 break;
Dan Gohman475871a2008-07-27 21:46:04 +0000484 //return SDValue(); // ret void is legal
Dan Gohman98ca4f22009-08-05 01:29:28 +0000485 case 1: {
Owen Andersone50ed302009-08-10 22:56:29 +0000486 EVT ArgVT = Outs[0].Val.getValueType();
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000487 unsigned ArgReg;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000488 if (ArgVT.isInteger())
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000489 ArgReg = Alpha::R0;
490 else {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000491 assert(ArgVT.isFloatingPoint());
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000492 ArgReg = Alpha::F0;
493 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000494 Copy = DAG.getCopyToReg(Copy, dl, ArgReg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000495 Outs[0].Val, Copy.getValue(1));
Chris Lattner84bc5422007-12-31 04:13:23 +0000496 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
497 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000498 break;
499 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000500 case 2: {
Owen Andersone50ed302009-08-10 22:56:29 +0000501 EVT ArgVT = Outs[0].Val.getValueType();
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000502 unsigned ArgReg1, ArgReg2;
503 if (ArgVT.isInteger()) {
504 ArgReg1 = Alpha::R0;
505 ArgReg2 = Alpha::R1;
506 } else {
507 assert(ArgVT.isFloatingPoint());
508 ArgReg1 = Alpha::F0;
509 ArgReg2 = Alpha::F1;
510 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000511 Copy = DAG.getCopyToReg(Copy, dl, ArgReg1,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000512 Outs[0].Val, Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000513 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000514 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg1)
515 == DAG.getMachineFunction().getRegInfo().liveout_end())
516 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg1);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000517 Copy = DAG.getCopyToReg(Copy, dl, ArgReg2,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000518 Outs[1].Val, Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000519 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000520 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg2)
521 == DAG.getMachineFunction().getRegInfo().liveout_end())
522 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg2);
523 break;
524 }
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000525 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000526 return DAG.getNode(AlphaISD::RET_FLAG, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000527 MVT::Other, Copy, Copy.getValue(1));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000528}
529
Dan Gohman475871a2008-07-27 21:46:04 +0000530void AlphaTargetLowering::LowerVAARG(SDNode *N, SDValue &Chain,
Dan Gohmand858e902010-04-17 15:26:15 +0000531 SDValue &DataPtr,
532 SelectionDAG &DAG) const {
Duncan Sands126d9072008-07-04 11:47:58 +0000533 Chain = N->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000534 SDValue VAListP = N->getOperand(1);
Duncan Sands126d9072008-07-04 11:47:58 +0000535 const Value *VAListS = cast<SrcValueSDNode>(N->getOperand(2))->getValue();
Dale Johannesenf5d97892009-02-04 01:48:28 +0000536 DebugLoc dl = N->getDebugLoc();
Duncan Sands126d9072008-07-04 11:47:58 +0000537
David Greene0e2236c2010-02-15 16:55:07 +0000538 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP, VAListS, 0,
539 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000540 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
541 DAG.getConstant(8, MVT::i64));
542 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Base.getValue(1),
David Greene0e2236c2010-02-15 16:55:07 +0000543 Tmp, NULL, 0, MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000544 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sands126d9072008-07-04 11:47:58 +0000545 if (N->getValueType(0).isFloatingPoint())
546 {
547 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson825b72b2009-08-11 20:47:22 +0000548 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
549 DAG.getConstant(8*6, MVT::i64));
550 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
551 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
552 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sands126d9072008-07-04 11:47:58 +0000553 }
554
Owen Anderson825b72b2009-08-11 20:47:22 +0000555 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
556 DAG.getConstant(8, MVT::i64));
Dale Johannesenf5d97892009-02-04 01:48:28 +0000557 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp, NULL, 0,
David Greene0e2236c2010-02-15 16:55:07 +0000558 MVT::i32, false, false, 0);
Duncan Sands126d9072008-07-04 11:47:58 +0000559}
560
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000561/// LowerOperation - Provide custom lowering hooks for some operations.
562///
Dan Gohmand858e902010-04-17 15:26:15 +0000563SDValue AlphaTargetLowering::LowerOperation(SDValue Op,
564 SelectionDAG &DAG) const {
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000565 DebugLoc dl = Op.getDebugLoc();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000566 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000567 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000568 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
569
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000570 case ISD::INTRINSIC_WO_CHAIN: {
571 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
572 switch (IntNo) {
573 default: break; // Don't custom lower most intrinsics.
574 case Intrinsic::alpha_umulh:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000575 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesende064702009-02-06 21:50:26 +0000576 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000577 }
578 }
579
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000580 case ISD::SRL_PARTS: {
581 SDValue ShOpLo = Op.getOperand(0);
582 SDValue ShOpHi = Op.getOperand(1);
583 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000584 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
585 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson825b72b2009-08-11 20:47:22 +0000586 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
587 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000588 // if 64 - shAmt <= 0
Owen Anderson825b72b2009-08-11 20:47:22 +0000589 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
590 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000591 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson825b72b2009-08-11 20:47:22 +0000592 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000593 // else
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
595 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
596 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
597 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000598 // Merge
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
600 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000601 SDValue Ops[2] = { Lo, Hi };
602 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000603 }
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000604 // case ISD::SRA_PARTS:
605
606 // case ISD::SHL_PARTS:
607
608
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000609 case ISD::SINT_TO_FP: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000611 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman475871a2008-07-27 21:46:04 +0000612 SDValue LD;
Owen Anderson825b72b2009-08-11 20:47:22 +0000613 bool isDouble = Op.getValueType() == MVT::f64;
614 LD = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +0000615 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 isDouble?MVT::f64:MVT::f32, LD);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000617 return FP;
618 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000619 case ISD::FP_TO_SINT: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000620 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue src = Op.getOperand(0);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000622
623 if (!isDouble) //Promote
Owen Anderson825b72b2009-08-11 20:47:22 +0000624 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000625
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000627
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i64, src);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000629 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000630 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000631 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000632 const Constant *C = CP->getConstVal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000633 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesende064702009-02-06 21:50:26 +0000634 // FIXME there isn't really any debug info here
Daniel Dunbara279bc32009-09-20 02:20:51 +0000635
Owen Anderson825b72b2009-08-11 20:47:22 +0000636 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
637 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
638 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000639 return Lo;
640 }
Lauro Ramos Venancio75ce0102007-07-11 17:19:51 +0000641 case ISD::GlobalTLSAddress:
Torok Edwinc23197a2009-07-14 16:55:14 +0000642 llvm_unreachable("TLS not implemented for Alpha.");
Andrew Lenharth4e629512005-12-24 05:36:33 +0000643 case ISD::GlobalAddress: {
644 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000645 const GlobalValue *GV = GSDN->getGlobal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000646 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
Dale Johannesende064702009-02-06 21:50:26 +0000647 // FIXME there isn't really any debug info here
Andrew Lenharth4e629512005-12-24 05:36:33 +0000648
Reid Spencer5cbf9852007-01-30 20:08:39 +0000649 // if (!GV->hasWeakLinkage() && !GV->isDeclaration() && !GV->hasLinkOnceLinkage()) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000650 if (GV->hasLocalLinkage()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000651 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
652 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
653 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000654 return Lo;
655 } else
Daniel Dunbara279bc32009-09-20 02:20:51 +0000656 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson825b72b2009-08-11 20:47:22 +0000657 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000658 }
Bill Wendling056292f2008-09-16 21:48:12 +0000659 case ISD::ExternalSymbol: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000660 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendling056292f2008-09-16 21:48:12 +0000661 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson825b72b2009-08-11 20:47:22 +0000662 ->getSymbol(), MVT::i64),
663 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth53d89702005-12-25 01:34:27 +0000664 }
Bill Wendling056292f2008-09-16 21:48:12 +0000665
Andrew Lenharth53d89702005-12-25 01:34:27 +0000666 case ISD::UREM:
667 case ISD::SREM:
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000668 //Expand only on constant case
669 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersone50ed302009-08-10 22:56:29 +0000670 EVT VT = Op.getNode()->getValueType(0);
Gabor Greifba36cb52008-08-28 21:40:38 +0000671 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
672 BuildUDIV(Op.getNode(), DAG, NULL) :
673 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesende064702009-02-06 21:50:26 +0000674 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
675 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000676 return Tmp1;
677 }
678 //fall through
679 case ISD::SDIV:
680 case ISD::UDIV:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000681 if (Op.getValueType().isInteger()) {
Andrew Lenharth253b9e72006-04-06 21:26:32 +0000682 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbara279bc32009-09-20 02:20:51 +0000683 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greifba36cb52008-08-28 21:40:38 +0000684 : BuildUDIV(Op.getNode(), DAG, NULL);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000685 const char* opstr = 0;
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000686 switch (Op.getOpcode()) {
Andrew Lenharth53d89702005-12-25 01:34:27 +0000687 case ISD::UREM: opstr = "__remqu"; break;
688 case ISD::SREM: opstr = "__remq"; break;
689 case ISD::UDIV: opstr = "__divqu"; break;
690 case ISD::SDIV: opstr = "__divq"; break;
691 }
Dan Gohman475871a2008-07-27 21:46:04 +0000692 SDValue Tmp1 = Op.getOperand(0),
Andrew Lenharth53d89702005-12-25 01:34:27 +0000693 Tmp2 = Op.getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +0000694 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
695 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000696 }
697 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000698
Nate Begemanacc398c2006-01-25 18:21:52 +0000699 case ISD::VAARG: {
Dan Gohman475871a2008-07-27 21:46:04 +0000700 SDValue Chain, DataPtr;
Gabor Greifba36cb52008-08-28 21:40:38 +0000701 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Andrew Lenharth66e49582006-01-23 21:51:33 +0000702
Dan Gohman475871a2008-07-27 21:46:04 +0000703 SDValue Result;
Owen Anderson825b72b2009-08-11 20:47:22 +0000704 if (Op.getValueType() == MVT::i32)
705 Result = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Chain, DataPtr,
David Greene0e2236c2010-02-15 16:55:07 +0000706 NULL, 0, MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000707 else
David Greene0e2236c2010-02-15 16:55:07 +0000708 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr, NULL, 0,
709 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000710 return Result;
711 }
712 case ISD::VACOPY: {
Dan Gohman475871a2008-07-27 21:46:04 +0000713 SDValue Chain = Op.getOperand(0);
714 SDValue DestP = Op.getOperand(1);
715 SDValue SrcP = Op.getOperand(2);
Dan Gohman69de1932008-02-06 22:27:42 +0000716 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
717 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000718
David Greene0e2236c2010-02-15 16:55:07 +0000719 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP, SrcS, 0,
720 false, false, 0);
721 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP, DestS, 0,
722 false, false, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000723 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson825b72b2009-08-11 20:47:22 +0000724 DAG.getConstant(8, MVT::i64));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000725 Val = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Result,
David Greene0e2236c2010-02-15 16:55:07 +0000726 NP, NULL,0, MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000727 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
728 DAG.getConstant(8, MVT::i64));
David Greene0e2236c2010-02-15 16:55:07 +0000729 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD, NULL, 0, MVT::i32,
730 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000731 }
732 case ISD::VASTART: {
Dan Gohman1e93df62010-04-17 14:41:14 +0000733 MachineFunction &MF = DAG.getMachineFunction();
734 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
735
Dan Gohman475871a2008-07-27 21:46:04 +0000736 SDValue Chain = Op.getOperand(0);
737 SDValue VAListP = Op.getOperand(1);
Dan Gohman69de1932008-02-06 22:27:42 +0000738 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000739
Nate Begemanacc398c2006-01-25 18:21:52 +0000740 // vastart stores the address of the VarArgsBase and VarArgsOffset
Dan Gohman1e93df62010-04-17 14:41:14 +0000741 SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsBase(), MVT::i64);
David Greene0e2236c2010-02-15 16:55:07 +0000742 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP, VAListS, 0,
743 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000744 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
745 DAG.getConstant(8, MVT::i64));
Dan Gohman1e93df62010-04-17 14:41:14 +0000746 return DAG.getTruncStore(S1, dl,
747 DAG.getConstant(FuncInfo->getVarArgsOffset(),
748 MVT::i64),
David Greene0e2236c2010-02-15 16:55:07 +0000749 SA2, NULL, 0, MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000750 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000751 case ISD::RETURNADDR:
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000752 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc(), MVT::i64);
Andrew Lenharthac5a5452007-02-08 17:37:41 +0000753 //FIXME: implement
Nate Begemanbcc5f362007-01-29 22:58:52 +0000754 case ISD::FRAMEADDR: break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000755 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000756
Dan Gohman475871a2008-07-27 21:46:04 +0000757 return SDValue();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000758}
Nate Begeman0aed7842006-01-28 03:14:31 +0000759
Duncan Sands1607f052008-12-01 11:39:25 +0000760void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
761 SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000762 SelectionDAG &DAG) const {
Dale Johannesen33c960f2009-02-04 20:06:27 +0000763 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +0000764 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sands126d9072008-07-04 11:47:58 +0000765 N->getOpcode() == ISD::VAARG &&
Nate Begeman0aed7842006-01-28 03:14:31 +0000766 "Unknown node to custom promote!");
Duncan Sands126d9072008-07-04 11:47:58 +0000767
Dan Gohman475871a2008-07-27 21:46:04 +0000768 SDValue Chain, DataPtr;
Duncan Sands126d9072008-07-04 11:47:58 +0000769 LowerVAARG(N, Chain, DataPtr, DAG);
David Greene0e2236c2010-02-15 16:55:07 +0000770 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr, NULL, 0,
771 false, false, 0);
Duncan Sands1607f052008-12-01 11:39:25 +0000772 Results.push_back(Res);
773 Results.push_back(SDValue(Res.getNode(), 1));
Nate Begeman0aed7842006-01-28 03:14:31 +0000774}
Andrew Lenharth17255992006-06-21 13:37:27 +0000775
776
777//Inline Asm
778
779/// getConstraintType - Given a constraint letter, return the type of
780/// constraint it is for this target.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000781AlphaTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +0000782AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
783 if (Constraint.size() == 1) {
784 switch (Constraint[0]) {
785 default: break;
786 case 'f':
787 case 'r':
788 return C_RegisterClass;
789 }
790 }
791 return TargetLowering::getConstraintType(Constraint);
Andrew Lenharth17255992006-06-21 13:37:27 +0000792}
793
794std::vector<unsigned> AlphaTargetLowering::
795getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +0000796 EVT VT) const {
Andrew Lenharth17255992006-06-21 13:37:27 +0000797 if (Constraint.size() == 1) {
798 switch (Constraint[0]) {
799 default: break; // Unknown constriant letter
Daniel Dunbara279bc32009-09-20 02:20:51 +0000800 case 'f':
Andrew Lenharth17255992006-06-21 13:37:27 +0000801 return make_vector<unsigned>(Alpha::F0 , Alpha::F1 , Alpha::F2 ,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000802 Alpha::F3 , Alpha::F4 , Alpha::F5 ,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000803 Alpha::F6 , Alpha::F7 , Alpha::F8 ,
804 Alpha::F9 , Alpha::F10, Alpha::F11,
805 Alpha::F12, Alpha::F13, Alpha::F14,
806 Alpha::F15, Alpha::F16, Alpha::F17,
807 Alpha::F18, Alpha::F19, Alpha::F20,
808 Alpha::F21, Alpha::F22, Alpha::F23,
809 Alpha::F24, Alpha::F25, Alpha::F26,
810 Alpha::F27, Alpha::F28, Alpha::F29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000811 Alpha::F30, Alpha::F31, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000812 case 'r':
813 return make_vector<unsigned>(Alpha::R0 , Alpha::R1 , Alpha::R2 ,
814 Alpha::R3 , Alpha::R4 , Alpha::R5 ,
815 Alpha::R6 , Alpha::R7 , Alpha::R8 ,
816 Alpha::R9 , Alpha::R10, Alpha::R11,
817 Alpha::R12, Alpha::R13, Alpha::R14,
818 Alpha::R15, Alpha::R16, Alpha::R17,
819 Alpha::R18, Alpha::R19, Alpha::R20,
820 Alpha::R21, Alpha::R22, Alpha::R23,
821 Alpha::R24, Alpha::R25, Alpha::R26,
822 Alpha::R27, Alpha::R28, Alpha::R29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000823 Alpha::R30, Alpha::R31, 0);
Andrew Lenharth17255992006-06-21 13:37:27 +0000824 }
825 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000826
Andrew Lenharth17255992006-06-21 13:37:27 +0000827 return std::vector<unsigned>();
828}
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000829//===----------------------------------------------------------------------===//
830// Other Lowering Code
831//===----------------------------------------------------------------------===//
832
833MachineBasicBlock *
834AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000835 MachineBasicBlock *BB) const {
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000836 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
837 assert((MI->getOpcode() == Alpha::CAS32 ||
838 MI->getOpcode() == Alpha::CAS64 ||
839 MI->getOpcode() == Alpha::LAS32 ||
840 MI->getOpcode() == Alpha::LAS64 ||
841 MI->getOpcode() == Alpha::SWAP32 ||
842 MI->getOpcode() == Alpha::SWAP64) &&
843 "Unexpected instr type to insert");
844
Daniel Dunbara279bc32009-09-20 02:20:51 +0000845 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000846 MI->getOpcode() == Alpha::LAS32 ||
847 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000848
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000849 //Load locked store conditional for atomic ops take on the same form
850 //start:
851 //ll
852 //do stuff (maybe branch to exit)
853 //sc
854 //test sc and maybe branck to start
855 //exit:
856 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen01b36e62009-02-13 02:30:42 +0000857 DebugLoc dl = MI->getDebugLoc();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000858 MachineFunction::iterator It = BB;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000859 ++It;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000860
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000861 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000862 MachineFunction *F = BB->getParent();
863 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
864 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000865
Dan Gohman258c58c2010-07-06 15:49:48 +0000866 sinkMBB->transferSuccessors(thisMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000867
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000868 F->insert(It, llscMBB);
869 F->insert(It, sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000870
Dale Johannesen01b36e62009-02-13 02:30:42 +0000871 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000872
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000873 unsigned reg_res = MI->getOperand(0).getReg(),
874 reg_ptr = MI->getOperand(1).getReg(),
875 reg_v2 = MI->getOperand(2).getReg(),
876 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
877
Daniel Dunbara279bc32009-09-20 02:20:51 +0000878 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000879 reg_res).addImm(0).addReg(reg_ptr);
880 switch (MI->getOpcode()) {
881 case Alpha::CAS32:
882 case Alpha::CAS64: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000883 unsigned reg_cmp
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000884 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000885 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000886 .addReg(reg_v2).addReg(reg_res);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000887 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000888 .addImm(0).addReg(reg_cmp).addMBB(sinkMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000889 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000890 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
891 break;
892 }
893 case Alpha::LAS32:
894 case Alpha::LAS64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000895 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000896 .addReg(reg_res).addReg(reg_v2);
897 break;
898 }
899 case Alpha::SWAP32:
900 case Alpha::SWAP64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000901 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000902 .addReg(reg_v2).addReg(reg_v2);
903 break;
904 }
905 }
Dale Johannesen01b36e62009-02-13 02:30:42 +0000906 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000907 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000908 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000909 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000910 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000911
912 thisMBB->addSuccessor(llscMBB);
913 llscMBB->addSuccessor(llscMBB);
914 llscMBB->addSuccessor(sinkMBB);
Dan Gohman258c58c2010-07-06 15:49:48 +0000915 F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000916
917 return sinkMBB;
918}
Dan Gohman6520e202008-10-18 02:06:02 +0000919
920bool
921AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
922 // The Alpha target isn't yet aware of offsets.
923 return false;
924}
Evan Chengeb2f9692009-10-27 19:56:55 +0000925
Evan Chenga1eaa3c2009-10-28 01:43:28 +0000926bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
927 if (VT != MVT::f32 && VT != MVT::f64)
928 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +0000929 // +0.0 F31
930 // +0.0f F31
931 // -0.0 -F31
932 // -0.0f -F31
933 return Imm.isZero() || Imm.isNegZero();
934}