blob: ea78bf3742006b36f876e6d6be4ab42e0d67982d [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,
Dan Gohmanc9403652010-07-07 15:54:55 +0000227 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000228 const SmallVectorImpl<ISD::InputArg> &Ins,
229 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000230 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000231 // Alpha target does not yet support tail call optimization.
232 isTailCall = false;
Eli Friedman796492d2009-07-19 01:11:32 +0000233
234 // Analyze operands of the call, assigning locations to each operand.
235 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000236 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
237 ArgLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000238
Dan Gohman98ca4f22009-08-05 01:29:28 +0000239 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000240
241 // Get a count of how many bytes are to be pushed on the stack.
242 unsigned NumBytes = CCInfo.getNextStackOffset();
243
244 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
245 getPointerTy(), true));
246
247 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
248 SmallVector<SDValue, 12> MemOpChains;
249 SDValue StackPtr;
250
251 // Walk the register/memloc assignments, inserting copies/loads.
252 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
253 CCValAssign &VA = ArgLocs[i];
254
Dan Gohmanc9403652010-07-07 15:54:55 +0000255 SDValue Arg = OutVals[i];
Eli Friedman796492d2009-07-19 01:11:32 +0000256
257 // Promote the value if needed.
258 switch (VA.getLocInfo()) {
259 default: assert(0 && "Unknown loc info!");
260 case CCValAssign::Full: break;
261 case CCValAssign::SExt:
262 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
263 break;
264 case CCValAssign::ZExt:
265 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
266 break;
267 case CCValAssign::AExt:
268 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
269 break;
270 }
271
272 // Arguments that can be passed on register must be kept at RegsToPass
273 // vector
274 if (VA.isRegLoc()) {
275 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
276 } else {
277 assert(VA.isMemLoc());
278
279 if (StackPtr.getNode() == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +0000280 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedman796492d2009-07-19 01:11:32 +0000281
282 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
283 StackPtr,
284 DAG.getIntPtrConstant(VA.getLocMemOffset()));
285
286 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
David Greene0e2236c2010-02-15 16:55:07 +0000287 PseudoSourceValue::getStack(), 0,
288 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);
David Greene0e2236c2010-02-15 16:55:07 +0000434 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, NULL, 0,
435 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);
David Greene0e2236c2010-02-15 16:55:07 +0000451 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0,
452 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);
David Greene0e2236c2010-02-15 16:55:07 +0000459 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0,
460 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
David Greene0e2236c2010-02-15 16:55:07 +0000540 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP, VAListS, 0,
541 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000542 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
543 DAG.getConstant(8, MVT::i64));
Evan Chengbcc80172010-07-07 22:15:37 +0000544 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Base.getValue(1),
David Greene0e2236c2010-02-15 16:55:07 +0000545 Tmp, NULL, 0, MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000546 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sands126d9072008-07-04 11:47:58 +0000547 if (N->getValueType(0).isFloatingPoint())
548 {
549 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson825b72b2009-08-11 20:47:22 +0000550 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
551 DAG.getConstant(8*6, MVT::i64));
552 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
553 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
554 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sands126d9072008-07-04 11:47:58 +0000555 }
556
Owen Anderson825b72b2009-08-11 20:47:22 +0000557 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
558 DAG.getConstant(8, MVT::i64));
Dale Johannesenf5d97892009-02-04 01:48:28 +0000559 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp, NULL, 0,
David Greene0e2236c2010-02-15 16:55:07 +0000560 MVT::i32, false, false, 0);
Duncan Sands126d9072008-07-04 11:47:58 +0000561}
562
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000563/// LowerOperation - Provide custom lowering hooks for some operations.
564///
Dan Gohmand858e902010-04-17 15:26:15 +0000565SDValue AlphaTargetLowering::LowerOperation(SDValue Op,
566 SelectionDAG &DAG) const {
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000567 DebugLoc dl = Op.getDebugLoc();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000568 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000569 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000570 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
571
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000572 case ISD::INTRINSIC_WO_CHAIN: {
573 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
574 switch (IntNo) {
575 default: break; // Don't custom lower most intrinsics.
576 case Intrinsic::alpha_umulh:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000577 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesende064702009-02-06 21:50:26 +0000578 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000579 }
580 }
581
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000582 case ISD::SRL_PARTS: {
583 SDValue ShOpLo = Op.getOperand(0);
584 SDValue ShOpHi = Op.getOperand(1);
585 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000586 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
587 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson825b72b2009-08-11 20:47:22 +0000588 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
589 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000590 // if 64 - shAmt <= 0
Owen Anderson825b72b2009-08-11 20:47:22 +0000591 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
592 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000593 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000595 // else
Owen Anderson825b72b2009-08-11 20:47:22 +0000596 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
597 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
598 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
599 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000600 // Merge
Owen Anderson825b72b2009-08-11 20:47:22 +0000601 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
602 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000603 SDValue Ops[2] = { Lo, Hi };
604 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000605 }
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000606 // case ISD::SRA_PARTS:
607
608 // case ISD::SHL_PARTS:
609
610
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000611 case ISD::SINT_TO_FP: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000612 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000613 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman475871a2008-07-27 21:46:04 +0000614 SDValue LD;
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 bool isDouble = Op.getValueType() == MVT::f64;
616 LD = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +0000617 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000618 isDouble?MVT::f64:MVT::f32, LD);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000619 return FP;
620 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000621 case ISD::FP_TO_SINT: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000622 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman475871a2008-07-27 21:46:04 +0000623 SDValue src = Op.getOperand(0);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000624
625 if (!isDouble) //Promote
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000627
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000629
Owen Anderson825b72b2009-08-11 20:47:22 +0000630 return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i64, src);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000631 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000632 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000633 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000634 const Constant *C = CP->getConstVal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000635 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesende064702009-02-06 21:50:26 +0000636 // FIXME there isn't really any debug info here
Daniel Dunbara279bc32009-09-20 02:20:51 +0000637
Owen Anderson825b72b2009-08-11 20:47:22 +0000638 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
639 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
640 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000641 return Lo;
642 }
Lauro Ramos Venancio75ce0102007-07-11 17:19:51 +0000643 case ISD::GlobalTLSAddress:
Torok Edwinc23197a2009-07-14 16:55:14 +0000644 llvm_unreachable("TLS not implemented for Alpha.");
Andrew Lenharth4e629512005-12-24 05:36:33 +0000645 case ISD::GlobalAddress: {
646 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000647 const GlobalValue *GV = GSDN->getGlobal();
Devang Patel0d881da2010-07-06 22:08:15 +0000648 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i64,
649 GSDN->getOffset());
Dale Johannesende064702009-02-06 21:50:26 +0000650 // FIXME there isn't really any debug info here
Andrew Lenharth4e629512005-12-24 05:36:33 +0000651
Devang Patel0d881da2010-07-06 22:08:15 +0000652 // if (!GV->hasWeakLinkage() && !GV->isDeclaration()
653 // && !GV->hasLinkOnceLinkage()) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000654 if (GV->hasLocalLinkage()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000655 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
656 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
657 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000658 return Lo;
659 } else
Daniel Dunbara279bc32009-09-20 02:20:51 +0000660 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson825b72b2009-08-11 20:47:22 +0000661 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000662 }
Bill Wendling056292f2008-09-16 21:48:12 +0000663 case ISD::ExternalSymbol: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000664 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendling056292f2008-09-16 21:48:12 +0000665 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson825b72b2009-08-11 20:47:22 +0000666 ->getSymbol(), MVT::i64),
667 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth53d89702005-12-25 01:34:27 +0000668 }
Bill Wendling056292f2008-09-16 21:48:12 +0000669
Andrew Lenharth53d89702005-12-25 01:34:27 +0000670 case ISD::UREM:
671 case ISD::SREM:
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000672 //Expand only on constant case
673 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersone50ed302009-08-10 22:56:29 +0000674 EVT VT = Op.getNode()->getValueType(0);
Gabor Greifba36cb52008-08-28 21:40:38 +0000675 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
676 BuildUDIV(Op.getNode(), DAG, NULL) :
677 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesende064702009-02-06 21:50:26 +0000678 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
679 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000680 return Tmp1;
681 }
682 //fall through
683 case ISD::SDIV:
684 case ISD::UDIV:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000685 if (Op.getValueType().isInteger()) {
Andrew Lenharth253b9e72006-04-06 21:26:32 +0000686 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbara279bc32009-09-20 02:20:51 +0000687 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greifba36cb52008-08-28 21:40:38 +0000688 : BuildUDIV(Op.getNode(), DAG, NULL);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000689 const char* opstr = 0;
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000690 switch (Op.getOpcode()) {
Andrew Lenharth53d89702005-12-25 01:34:27 +0000691 case ISD::UREM: opstr = "__remqu"; break;
692 case ISD::SREM: opstr = "__remq"; break;
693 case ISD::UDIV: opstr = "__divqu"; break;
694 case ISD::SDIV: opstr = "__divq"; break;
695 }
Dan Gohman475871a2008-07-27 21:46:04 +0000696 SDValue Tmp1 = Op.getOperand(0),
Andrew Lenharth53d89702005-12-25 01:34:27 +0000697 Tmp2 = Op.getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +0000698 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
699 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000700 }
701 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000702
Nate Begemanacc398c2006-01-25 18:21:52 +0000703 case ISD::VAARG: {
Dan Gohman475871a2008-07-27 21:46:04 +0000704 SDValue Chain, DataPtr;
Gabor Greifba36cb52008-08-28 21:40:38 +0000705 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Andrew Lenharth66e49582006-01-23 21:51:33 +0000706
Dan Gohman475871a2008-07-27 21:46:04 +0000707 SDValue Result;
Owen Anderson825b72b2009-08-11 20:47:22 +0000708 if (Op.getValueType() == MVT::i32)
Evan Chengbcc80172010-07-07 22:15:37 +0000709 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Chain, DataPtr,
David Greene0e2236c2010-02-15 16:55:07 +0000710 NULL, 0, MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000711 else
David Greene0e2236c2010-02-15 16:55:07 +0000712 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr, NULL, 0,
713 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000714 return Result;
715 }
716 case ISD::VACOPY: {
Dan Gohman475871a2008-07-27 21:46:04 +0000717 SDValue Chain = Op.getOperand(0);
718 SDValue DestP = Op.getOperand(1);
719 SDValue SrcP = Op.getOperand(2);
Dan Gohman69de1932008-02-06 22:27:42 +0000720 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
721 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000722
David Greene0e2236c2010-02-15 16:55:07 +0000723 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP, SrcS, 0,
724 false, false, 0);
725 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP, DestS, 0,
726 false, false, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000727 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson825b72b2009-08-11 20:47:22 +0000728 DAG.getConstant(8, MVT::i64));
Evan Chengbcc80172010-07-07 22:15:37 +0000729 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, dl, Result,
David Greene0e2236c2010-02-15 16:55:07 +0000730 NP, NULL,0, MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000731 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
732 DAG.getConstant(8, MVT::i64));
David Greene0e2236c2010-02-15 16:55:07 +0000733 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD, NULL, 0, MVT::i32,
734 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000735 }
736 case ISD::VASTART: {
Dan Gohman1e93df62010-04-17 14:41:14 +0000737 MachineFunction &MF = DAG.getMachineFunction();
738 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
739
Dan Gohman475871a2008-07-27 21:46:04 +0000740 SDValue Chain = Op.getOperand(0);
741 SDValue VAListP = Op.getOperand(1);
Dan Gohman69de1932008-02-06 22:27:42 +0000742 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000743
Nate Begemanacc398c2006-01-25 18:21:52 +0000744 // vastart stores the address of the VarArgsBase and VarArgsOffset
Dan Gohman1e93df62010-04-17 14:41:14 +0000745 SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsBase(), MVT::i64);
David Greene0e2236c2010-02-15 16:55:07 +0000746 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP, VAListS, 0,
747 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000748 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
749 DAG.getConstant(8, MVT::i64));
Dan Gohman1e93df62010-04-17 14:41:14 +0000750 return DAG.getTruncStore(S1, dl,
751 DAG.getConstant(FuncInfo->getVarArgsOffset(),
752 MVT::i64),
David Greene0e2236c2010-02-15 16:55:07 +0000753 SA2, NULL, 0, MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000754 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000755 case ISD::RETURNADDR:
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000756 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc(), MVT::i64);
Andrew Lenharthac5a5452007-02-08 17:37:41 +0000757 //FIXME: implement
Nate Begemanbcc5f362007-01-29 22:58:52 +0000758 case ISD::FRAMEADDR: break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000759 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000760
Dan Gohman475871a2008-07-27 21:46:04 +0000761 return SDValue();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000762}
Nate Begeman0aed7842006-01-28 03:14:31 +0000763
Duncan Sands1607f052008-12-01 11:39:25 +0000764void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
765 SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000766 SelectionDAG &DAG) const {
Dale Johannesen33c960f2009-02-04 20:06:27 +0000767 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +0000768 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sands126d9072008-07-04 11:47:58 +0000769 N->getOpcode() == ISD::VAARG &&
Nate Begeman0aed7842006-01-28 03:14:31 +0000770 "Unknown node to custom promote!");
Duncan Sands126d9072008-07-04 11:47:58 +0000771
Dan Gohman475871a2008-07-27 21:46:04 +0000772 SDValue Chain, DataPtr;
Duncan Sands126d9072008-07-04 11:47:58 +0000773 LowerVAARG(N, Chain, DataPtr, DAG);
David Greene0e2236c2010-02-15 16:55:07 +0000774 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr, NULL, 0,
775 false, false, 0);
Duncan Sands1607f052008-12-01 11:39:25 +0000776 Results.push_back(Res);
777 Results.push_back(SDValue(Res.getNode(), 1));
Nate Begeman0aed7842006-01-28 03:14:31 +0000778}
Andrew Lenharth17255992006-06-21 13:37:27 +0000779
780
781//Inline Asm
782
783/// getConstraintType - Given a constraint letter, return the type of
784/// constraint it is for this target.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000785AlphaTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +0000786AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
787 if (Constraint.size() == 1) {
788 switch (Constraint[0]) {
789 default: break;
790 case 'f':
791 case 'r':
792 return C_RegisterClass;
793 }
794 }
795 return TargetLowering::getConstraintType(Constraint);
Andrew Lenharth17255992006-06-21 13:37:27 +0000796}
797
798std::vector<unsigned> AlphaTargetLowering::
799getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +0000800 EVT VT) const {
Andrew Lenharth17255992006-06-21 13:37:27 +0000801 if (Constraint.size() == 1) {
802 switch (Constraint[0]) {
803 default: break; // Unknown constriant letter
Daniel Dunbara279bc32009-09-20 02:20:51 +0000804 case 'f':
Andrew Lenharth17255992006-06-21 13:37:27 +0000805 return make_vector<unsigned>(Alpha::F0 , Alpha::F1 , Alpha::F2 ,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000806 Alpha::F3 , Alpha::F4 , Alpha::F5 ,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000807 Alpha::F6 , Alpha::F7 , Alpha::F8 ,
808 Alpha::F9 , Alpha::F10, Alpha::F11,
809 Alpha::F12, Alpha::F13, Alpha::F14,
810 Alpha::F15, Alpha::F16, Alpha::F17,
811 Alpha::F18, Alpha::F19, Alpha::F20,
812 Alpha::F21, Alpha::F22, Alpha::F23,
813 Alpha::F24, Alpha::F25, Alpha::F26,
814 Alpha::F27, Alpha::F28, Alpha::F29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000815 Alpha::F30, Alpha::F31, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000816 case 'r':
817 return make_vector<unsigned>(Alpha::R0 , Alpha::R1 , Alpha::R2 ,
818 Alpha::R3 , Alpha::R4 , Alpha::R5 ,
819 Alpha::R6 , Alpha::R7 , Alpha::R8 ,
820 Alpha::R9 , Alpha::R10, Alpha::R11,
821 Alpha::R12, Alpha::R13, Alpha::R14,
822 Alpha::R15, Alpha::R16, Alpha::R17,
823 Alpha::R18, Alpha::R19, Alpha::R20,
824 Alpha::R21, Alpha::R22, Alpha::R23,
825 Alpha::R24, Alpha::R25, Alpha::R26,
826 Alpha::R27, Alpha::R28, Alpha::R29,
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000827 Alpha::R30, Alpha::R31, 0);
Andrew Lenharth17255992006-06-21 13:37:27 +0000828 }
829 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000830
Andrew Lenharth17255992006-06-21 13:37:27 +0000831 return std::vector<unsigned>();
832}
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000833//===----------------------------------------------------------------------===//
834// Other Lowering Code
835//===----------------------------------------------------------------------===//
836
837MachineBasicBlock *
838AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000839 MachineBasicBlock *BB) const {
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000840 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
841 assert((MI->getOpcode() == Alpha::CAS32 ||
842 MI->getOpcode() == Alpha::CAS64 ||
843 MI->getOpcode() == Alpha::LAS32 ||
844 MI->getOpcode() == Alpha::LAS64 ||
845 MI->getOpcode() == Alpha::SWAP32 ||
846 MI->getOpcode() == Alpha::SWAP64) &&
847 "Unexpected instr type to insert");
848
Daniel Dunbara279bc32009-09-20 02:20:51 +0000849 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000850 MI->getOpcode() == Alpha::LAS32 ||
851 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000852
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000853 //Load locked store conditional for atomic ops take on the same form
854 //start:
855 //ll
856 //do stuff (maybe branch to exit)
857 //sc
858 //test sc and maybe branck to start
859 //exit:
860 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen01b36e62009-02-13 02:30:42 +0000861 DebugLoc dl = MI->getDebugLoc();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000862 MachineFunction::iterator It = BB;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000863 ++It;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000864
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000865 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000866 MachineFunction *F = BB->getParent();
867 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
868 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000869
Dan Gohman14152b42010-07-06 20:24:04 +0000870 sinkMBB->splice(sinkMBB->begin(), thisMBB,
871 llvm::next(MachineBasicBlock::iterator(MI)),
872 thisMBB->end());
873 sinkMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000874
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000875 F->insert(It, llscMBB);
876 F->insert(It, sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000877
Dale Johannesen01b36e62009-02-13 02:30:42 +0000878 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000879
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000880 unsigned reg_res = MI->getOperand(0).getReg(),
881 reg_ptr = MI->getOperand(1).getReg(),
882 reg_v2 = MI->getOperand(2).getReg(),
883 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
884
Daniel Dunbara279bc32009-09-20 02:20:51 +0000885 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000886 reg_res).addImm(0).addReg(reg_ptr);
887 switch (MI->getOpcode()) {
888 case Alpha::CAS32:
889 case Alpha::CAS64: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000890 unsigned reg_cmp
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000891 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000892 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000893 .addReg(reg_v2).addReg(reg_res);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000894 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000895 .addImm(0).addReg(reg_cmp).addMBB(sinkMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000896 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000897 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
898 break;
899 }
900 case Alpha::LAS32:
901 case Alpha::LAS64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000902 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000903 .addReg(reg_res).addReg(reg_v2);
904 break;
905 }
906 case Alpha::SWAP32:
907 case Alpha::SWAP64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000908 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000909 .addReg(reg_v2).addReg(reg_v2);
910 break;
911 }
912 }
Dale Johannesen01b36e62009-02-13 02:30:42 +0000913 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000914 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000915 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000916 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000917 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000918
919 thisMBB->addSuccessor(llscMBB);
920 llscMBB->addSuccessor(llscMBB);
921 llscMBB->addSuccessor(sinkMBB);
Dan Gohman14152b42010-07-06 20:24:04 +0000922 MI->eraseFromParent(); // The pseudo instruction is gone now.
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000923
924 return sinkMBB;
925}
Dan Gohman6520e202008-10-18 02:06:02 +0000926
927bool
928AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
929 // The Alpha target isn't yet aware of offsets.
930 return false;
931}
Evan Chengeb2f9692009-10-27 19:56:55 +0000932
Evan Chenga1eaa3c2009-10-28 01:43:28 +0000933bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
934 if (VT != MVT::f32 && VT != MVT::f64)
935 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +0000936 // +0.0 F31
937 // +0.0f F31
938 // -0.0 -F31
939 // -0.0f -F31
940 return Imm.isZero() || Imm.isNegZero();
941}