blob: 3057eb8c57fbe37a142547420e96a2b85a8642fc [file] [log] [blame]
Andrew Lenharthaa38ce42005-09-02 18:46:02 +00001//===-- AlphaISelLowering.cpp - Alpha DAG Lowering Implementation ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Andrew Lenharthaa38ce42005-09-02 18:46:02 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AlphaISelLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AlphaISelLowering.h"
15#include "AlphaTargetMachine.h"
Dan Gohman1e93df62010-04-17 14:41:14 +000016#include "AlphaMachineFunctionInfo.h"
Eli Friedman796492d2009-07-19 01:11:32 +000017#include "llvm/CodeGen/CallingConvLower.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000018#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000022#include "llvm/CodeGen/SelectionDAG.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Eli Friedman796492d2009-07-19 01:11:32 +000024#include "llvm/CodeGen/PseudoSourceValue.h"
Anton Korobeynikov362dd0b2010-02-15 22:37:53 +000025#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000026#include "llvm/Constants.h"
27#include "llvm/Function.h"
Andrew Lenharth167bc6e2006-01-23 20:59:50 +000028#include "llvm/Module.h"
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000029#include "llvm/Intrinsics.h"
John Thompson44ab89e2010-10-29 17:29:13 +000030#include "llvm/Type.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000031#include "llvm/Support/CommandLine.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000032#include "llvm/Support/ErrorHandling.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/raw_ostream.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000034using namespace llvm;
35
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000036/// AddLiveIn - This helper function adds the specified physical register to the
37/// MachineFunction as a live in value. It also creates a corresponding virtual
38/// register for it.
39static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
40 TargetRegisterClass *RC) {
41 assert(RC->contains(PReg) && "Not the correct regclass!");
Chris Lattner84bc5422007-12-31 04:13:23 +000042 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
43 MF.getRegInfo().addLiveIn(PReg, VReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000044 return VReg;
45}
46
Chris Lattnerf0144122009-07-28 03:13:23 +000047AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM)
Andrew Lenharth7f285c82009-08-05 18:13:04 +000048 : TargetLowering(TM, new TargetLoweringObjectFileELF()) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000049 // Set up the TargetLowering object.
Dan Gohmana119de82009-06-14 23:30:43 +000050 //I am having problems with shr n i8 1
Duncan Sands03228082008-11-23 15:47:28 +000051 setBooleanContents(ZeroOrOneBooleanContent);
Duncan Sands28b77e92011-09-06 19:07:46 +000052 setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct?
Daniel Dunbara279bc32009-09-20 02:20:51 +000053
Owen Anderson825b72b2009-08-11 20:47:22 +000054 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
55 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
56 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000057
58 // We want to custom lower some of our intrinsics.
Owen Anderson825b72b2009-08-11 20:47:22 +000059 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +000060
Owen Anderson825b72b2009-08-11 20:47:22 +000061 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
62 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000063
Owen Anderson825b72b2009-08-11 20:47:22 +000064 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
65 setLoadExtAction(ISD::ZEXTLOAD, MVT::i32, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000066
Owen Anderson825b72b2009-08-11 20:47:22 +000067 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
68 setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand);
69 setLoadExtAction(ISD::SEXTLOAD, MVT::i16, Expand);
Evan Cheng8b2794a2006-10-13 21:14:26 +000070
Owen Anderson825b72b2009-08-11 20:47:22 +000071 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Eli Friedman18d643a2009-07-17 05:23:03 +000072
Owen Anderson825b72b2009-08-11 20:47:22 +000073 // setOperationAction(ISD::BRIND, MVT::Other, Expand);
74 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
75 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000076 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
Andrew Lenharthf3fb71b2005-10-06 16:54:29 +000077
Owen Anderson825b72b2009-08-11 20:47:22 +000078 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Andrew Lenharth7794bd32006-06-27 23:19:14 +000079
Owen Anderson825b72b2009-08-11 20:47:22 +000080 setOperationAction(ISD::FREM, MVT::f32, Expand);
81 setOperationAction(ISD::FREM, MVT::f64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000082
Owen Anderson825b72b2009-08-11 20:47:22 +000083 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
84 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
85 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
86 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
Andrew Lenharthcd804962005-11-30 16:10:29 +000087
Andrew Lenharth120ab482005-09-29 22:54:56 +000088 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Owen Anderson825b72b2009-08-11 20:47:22 +000089 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
90 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
91 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000092 }
Owen Anderson825b72b2009-08-11 20:47:22 +000093 setOperationAction(ISD::BSWAP , MVT::i64, Expand);
94 setOperationAction(ISD::ROTL , MVT::i64, Expand);
95 setOperationAction(ISD::ROTR , MVT::i64, Expand);
Daniel Dunbara279bc32009-09-20 02:20:51 +000096
Owen Anderson825b72b2009-08-11 20:47:22 +000097 setOperationAction(ISD::SREM , MVT::i64, Custom);
98 setOperationAction(ISD::UREM , MVT::i64, Custom);
99 setOperationAction(ISD::SDIV , MVT::i64, Custom);
100 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthafe3f492006-04-03 03:18:59 +0000101
Owen Anderson825b72b2009-08-11 20:47:22 +0000102 setOperationAction(ISD::ADDC , MVT::i64, Expand);
103 setOperationAction(ISD::ADDE , MVT::i64, Expand);
104 setOperationAction(ISD::SUBC , MVT::i64, Expand);
105 setOperationAction(ISD::SUBE , MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000106
Owen Anderson825b72b2009-08-11 20:47:22 +0000107 setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
108 setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
Chris Lattnerd2a27ee2008-10-09 04:50:56 +0000109
Owen Anderson825b72b2009-08-11 20:47:22 +0000110 setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom);
111 setOperationAction(ISD::SRA_PARTS, MVT::i64, Expand);
112 setOperationAction(ISD::SHL_PARTS, MVT::i64, Expand);
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000113
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000114 // We don't support sin/cos/sqrt/pow
Owen Anderson825b72b2009-08-11 20:47:22 +0000115 setOperationAction(ISD::FSIN , MVT::f64, Expand);
116 setOperationAction(ISD::FCOS , MVT::f64, Expand);
117 setOperationAction(ISD::FSIN , MVT::f32, Expand);
118 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Andrew Lenharth39424472006-01-19 21:10:38 +0000119
Owen Anderson825b72b2009-08-11 20:47:22 +0000120 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
121 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Dan Gohmanf96e4de2007-10-11 23:21:31 +0000122
Owen Anderson825b72b2009-08-11 20:47:22 +0000123 setOperationAction(ISD::FPOW , MVT::f32, Expand);
124 setOperationAction(ISD::FPOW , MVT::f64, Expand);
Dale Johannesen7794f2a2008-09-04 00:47:13 +0000125
Cameron Zwarich33390842011-07-08 21:39:21 +0000126 setOperationAction(ISD::FMA, MVT::f64, Expand);
127 setOperationAction(ISD::FMA, MVT::f32, Expand);
128
Owen Anderson825b72b2009-08-11 20:47:22 +0000129 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000130
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000131 setOperationAction(ISD::BITCAST, MVT::f32, Promote);
Andrew Lenharth3553d862007-01-24 21:09:16 +0000132
Owen Anderson825b72b2009-08-11 20:47:22 +0000133 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000134
135 // Not implemented yet.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000136 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
Owen Anderson825b72b2009-08-11 20:47:22 +0000137 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
138 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Andrew Lenharth739027e2006-01-16 21:22:38 +0000139
Bill Wendling056292f2008-09-16 21:48:12 +0000140 // We want to legalize GlobalAddress and ConstantPool and
141 // ExternalSymbols nodes into the appropriate instructions to
142 // materialize the address.
Owen Anderson825b72b2009-08-11 20:47:22 +0000143 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
144 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
145 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
146 setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000147
Owen Anderson825b72b2009-08-11 20:47:22 +0000148 setOperationAction(ISD::VASTART, MVT::Other, Custom);
149 setOperationAction(ISD::VAEND, MVT::Other, Expand);
150 setOperationAction(ISD::VACOPY, MVT::Other, Custom);
151 setOperationAction(ISD::VAARG, MVT::Other, Custom);
152 setOperationAction(ISD::VAARG, MVT::i32, Custom);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000153
Owen Anderson825b72b2009-08-11 20:47:22 +0000154 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
155 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000156
Eli Friedman4db5aca2011-08-29 18:23:02 +0000157 setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand);
158 setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand);
159
Andrew Lenharth739027e2006-01-16 21:22:38 +0000160 setStackPointerRegisterToSaveRestore(Alpha::R30);
161
Andrew Lenharth89c0b4a2006-09-05 00:22:25 +0000162 setJumpBufSize(272);
163 setJumpBufAlignment(16);
164
Eli Friedmanfc5d3052011-05-06 20:34:06 +0000165 setMinFunctionAlignment(4);
166
Eli Friedman26689ac2011-08-03 21:06:02 +0000167 setInsertFencesForAtomic(true);
168
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000169 computeRegisterProperties();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000170}
171
Duncan Sands28b77e92011-09-06 19:07:46 +0000172EVT AlphaTargetLowering::getSetCCResultType(EVT VT) const {
Owen Anderson825b72b2009-08-11 20:47:22 +0000173 return MVT::i64;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000174}
175
Andrew Lenharth84a06052006-01-16 19:53:25 +0000176const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
177 switch (Opcode) {
178 default: return 0;
Andrew Lenharth84a06052006-01-16 19:53:25 +0000179 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
180 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
181 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
182 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
183 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
184 case AlphaISD::RelLit: return "Alpha::RelLit";
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000185 case AlphaISD::GlobalRetAddr: return "Alpha::GlobalRetAddr";
Chris Lattner2d90bd52006-01-27 23:39:00 +0000186 case AlphaISD::CALL: return "Alpha::CALL";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000187 case AlphaISD::DivCall: return "Alpha::DivCall";
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000188 case AlphaISD::RET_FLAG: return "Alpha::RET_FLAG";
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000189 case AlphaISD::COND_BRANCH_I: return "Alpha::COND_BRANCH_I";
190 case AlphaISD::COND_BRANCH_F: return "Alpha::COND_BRANCH_F";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000191 }
192}
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000193
Dan Gohman475871a2008-07-27 21:46:04 +0000194static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +0000195 EVT PtrVT = Op.getValueType();
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000196 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Dan Gohman475871a2008-07-27 21:46:04 +0000197 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
Dale Johannesende064702009-02-06 21:50:26 +0000198 // FIXME there isn't really any debug info here
199 DebugLoc dl = Op.getDebugLoc();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000200
Owen Anderson825b72b2009-08-11 20:47:22 +0000201 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, JTI,
202 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
203 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, JTI, Hi);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000204 return Lo;
205}
206
Chris Lattnere21492b2006-08-11 17:19:54 +0000207//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/
208//AA-PY8AC-TET1_html/callCH3.html#BLOCK21
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000209
210//For now, just use variable size stack frame format
211
212//In a standard call, the first six items are passed in registers $16
213//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
214//of argument-to-register correspondence.) The remaining items are
215//collected in a memory argument list that is a naturally aligned
216//array of quadwords. In a standard call, this list, if present, must
217//be passed at 0(SP).
218//7 ... n 0(SP) ... (n-7)*8(SP)
219
220// //#define FP $15
221// //#define RA $26
222// //#define PV $27
223// //#define GP $29
224// //#define SP $30
225
Eli Friedman796492d2009-07-19 01:11:32 +0000226#include "AlphaGenCallingConv.inc"
227
Dan Gohman98ca4f22009-08-05 01:29:28 +0000228SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000229AlphaTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000230 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000231 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000232 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000233 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000234 const SmallVectorImpl<ISD::InputArg> &Ins,
235 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000236 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000237 // Alpha target does not yet support tail call optimization.
238 isTailCall = false;
Eli Friedman796492d2009-07-19 01:11:32 +0000239
240 // Analyze operands of the call, assigning locations to each operand.
241 SmallVector<CCValAssign, 16> ArgLocs;
Eric Christopher471e4222011-06-08 23:55:35 +0000242 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(),
243 getTargetMachine(), ArgLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000244
Dan Gohman98ca4f22009-08-05 01:29:28 +0000245 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000246
247 // Get a count of how many bytes are to be pushed on the stack.
248 unsigned NumBytes = CCInfo.getNextStackOffset();
249
250 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
251 getPointerTy(), true));
252
253 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
254 SmallVector<SDValue, 12> MemOpChains;
255 SDValue StackPtr;
256
257 // Walk the register/memloc assignments, inserting copies/loads.
258 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
259 CCValAssign &VA = ArgLocs[i];
260
Dan Gohmanc9403652010-07-07 15:54:55 +0000261 SDValue Arg = OutVals[i];
Eli Friedman796492d2009-07-19 01:11:32 +0000262
263 // Promote the value if needed.
264 switch (VA.getLocInfo()) {
265 default: assert(0 && "Unknown loc info!");
266 case CCValAssign::Full: break;
267 case CCValAssign::SExt:
268 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
269 break;
270 case CCValAssign::ZExt:
271 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
272 break;
273 case CCValAssign::AExt:
274 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
275 break;
276 }
277
278 // Arguments that can be passed on register must be kept at RegsToPass
279 // vector
280 if (VA.isRegLoc()) {
281 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
282 } else {
283 assert(VA.isMemLoc());
284
285 if (StackPtr.getNode() == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +0000286 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedman796492d2009-07-19 01:11:32 +0000287
288 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
289 StackPtr,
290 DAG.getIntPtrConstant(VA.getLocMemOffset()));
291
292 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000293 MachinePointerInfo(),false, false, 0));
Eli Friedman796492d2009-07-19 01:11:32 +0000294 }
295 }
296
297 // Transform all store nodes into one single node because all store nodes are
298 // independent of each other.
299 if (!MemOpChains.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +0000300 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Eli Friedman796492d2009-07-19 01:11:32 +0000301 &MemOpChains[0], MemOpChains.size());
302
303 // Build a sequence of copy-to-reg nodes chained together with token chain and
304 // flag operands which copy the outgoing args into registers. The InFlag in
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000305 // necessary since all emitted instructions must be stuck together.
Eli Friedman796492d2009-07-19 01:11:32 +0000306 SDValue InFlag;
307 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
308 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
309 RegsToPass[i].second, InFlag);
310 InFlag = Chain.getValue(1);
311 }
312
313 // Returns a chain & a flag for retval copy to use.
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000314 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
Eli Friedman796492d2009-07-19 01:11:32 +0000315 SmallVector<SDValue, 8> Ops;
316 Ops.push_back(Chain);
317 Ops.push_back(Callee);
318
319 // Add argument registers to the end of the list so that they are
320 // known live into the call.
321 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
322 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
323 RegsToPass[i].second.getValueType()));
324
325 if (InFlag.getNode())
326 Ops.push_back(InFlag);
327
328 Chain = DAG.getNode(AlphaISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
329 InFlag = Chain.getValue(1);
330
331 // Create the CALLSEQ_END node.
332 Chain = DAG.getCALLSEQ_END(Chain,
333 DAG.getConstant(NumBytes, getPointerTy(), true),
334 DAG.getConstant(0, getPointerTy(), true),
335 InFlag);
336 InFlag = Chain.getValue(1);
337
338 // Handle result values, copying them out of physregs into vregs that we
339 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000340 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
341 Ins, dl, DAG, InVals);
Eli Friedman796492d2009-07-19 01:11:32 +0000342}
343
Dan Gohman98ca4f22009-08-05 01:29:28 +0000344/// LowerCallResult - Lower the result values of a call into the
345/// appropriate copies out of appropriate physical registers.
346///
347SDValue
Eli Friedman796492d2009-07-19 01:11:32 +0000348AlphaTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000349 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000350 const SmallVectorImpl<ISD::InputArg> &Ins,
351 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000352 SmallVectorImpl<SDValue> &InVals) const {
Eli Friedman796492d2009-07-19 01:11:32 +0000353
354 // Assign locations to each value returned by this call.
355 SmallVector<CCValAssign, 16> RVLocs;
Eric Christopher471e4222011-06-08 23:55:35 +0000356 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(),
357 getTargetMachine(), RVLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000358
Dan Gohman98ca4f22009-08-05 01:29:28 +0000359 CCInfo.AnalyzeCallResult(Ins, RetCC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000360
361 // Copy all of the result registers out of their specified physreg.
362 for (unsigned i = 0; i != RVLocs.size(); ++i) {
363 CCValAssign &VA = RVLocs[i];
364
365 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
366 VA.getLocVT(), InFlag).getValue(1);
367 SDValue RetValue = Chain.getValue(0);
368 InFlag = Chain.getValue(2);
369
370 // If this is an 8/16/32-bit value, it is really passed promoted to 64
371 // bits. Insert an assert[sz]ext to capture this, then truncate to the
372 // right size.
373 if (VA.getLocInfo() == CCValAssign::SExt)
374 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
375 DAG.getValueType(VA.getValVT()));
376 else if (VA.getLocInfo() == CCValAssign::ZExt)
377 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
378 DAG.getValueType(VA.getValVT()));
379
380 if (VA.getLocInfo() != CCValAssign::Full)
381 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
382
Dan Gohman98ca4f22009-08-05 01:29:28 +0000383 InVals.push_back(RetValue);
Eli Friedman796492d2009-07-19 01:11:32 +0000384 }
385
Dan Gohman98ca4f22009-08-05 01:29:28 +0000386 return Chain;
Eli Friedman796492d2009-07-19 01:11:32 +0000387}
388
Dan Gohman98ca4f22009-08-05 01:29:28 +0000389SDValue
390AlphaTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000391 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000392 const SmallVectorImpl<ISD::InputArg>
393 &Ins,
394 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000395 SmallVectorImpl<SDValue> &InVals)
396 const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000397
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000398 MachineFunction &MF = DAG.getMachineFunction();
399 MachineFrameInfo *MFI = MF.getFrameInfo();
Dan Gohman1e93df62010-04-17 14:41:14 +0000400 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000401
Andrew Lenharthf71df332005-09-04 06:12:19 +0000402 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000403 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000404 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000405 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Daniel Dunbara279bc32009-09-20 02:20:51 +0000406
Dan Gohman98ca4f22009-08-05 01:29:28 +0000407 for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
Dan Gohman475871a2008-07-27 21:46:04 +0000408 SDValue argt;
Owen Andersone50ed302009-08-10 22:56:29 +0000409 EVT ObjectVT = Ins[ArgNo].VT;
Dan Gohman475871a2008-07-27 21:46:04 +0000410 SDValue ArgVal;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000411
412 if (ArgNo < 6) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000413 switch (ObjectVT.getSimpleVT().SimpleTy) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000414 default:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000415 assert(false && "Invalid value type!");
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 case MVT::f64:
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::F8RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000419 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000420 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000421 case MVT::f32:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000422 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000423 &Alpha::F4RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000424 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthd1aab352006-06-21 01:00:43 +0000425 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000426 case MVT::i64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000427 args_int[ArgNo] = AddLiveIn(MF, args_int[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000428 &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000429 ArgVal = DAG.getCopyFromReg(Chain, dl, args_int[ArgNo], MVT::i64);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000430 break;
431 }
432 } else { //more args
433 // Create the frame index object for this incoming parameter...
Evan Chenged2ae132010-07-03 00:40:23 +0000434 int FI = MFI->CreateFixedObject(8, 8 * (ArgNo - 6), true);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000435
436 // Create the SelectionDAG nodes corresponding to a load
437 //from this parameter
Owen Anderson825b72b2009-08-11 20:47:22 +0000438 SDValue FIN = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000439 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000440 false, false, 0);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000441 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000442 InVals.push_back(ArgVal);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000443 }
444
445 // If the functions takes variable number of arguments, copy all regs to stack
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000446 if (isVarArg) {
Dan Gohman1e93df62010-04-17 14:41:14 +0000447 FuncInfo->setVarArgsOffset(Ins.size() * 8);
Dan Gohman475871a2008-07-27 21:46:04 +0000448 std::vector<SDValue> LS;
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000449 for (int i = 0; i < 6; ++i) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000450 if (TargetRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000451 args_int[i] = AddLiveIn(MF, args_int[i], &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000452 SDValue argt = DAG.getCopyFromReg(Chain, dl, args_int[i], MVT::i64);
Evan Chenged2ae132010-07-03 00:40:23 +0000453 int FI = MFI->CreateFixedObject(8, -8 * (6 - i), true);
Dan Gohman1e93df62010-04-17 14:41:14 +0000454 if (i == 0) FuncInfo->setVarArgsBase(FI);
Owen Anderson825b72b2009-08-11 20:47:22 +0000455 SDValue SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000456 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000457 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000458
Dan Gohman6f0d0242008-02-10 18:45:23 +0000459 if (TargetRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000460 args_float[i] = AddLiveIn(MF, args_float[i], &Alpha::F8RCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000461 argt = DAG.getCopyFromReg(Chain, dl, args_float[i], MVT::f64);
Evan Chenged2ae132010-07-03 00:40:23 +0000462 FI = MFI->CreateFixedObject(8, - 8 * (12 - i), true);
Owen Anderson825b72b2009-08-11 20:47:22 +0000463 SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000464 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000465 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000466 }
467
468 //Set up a token factor with all the stack traffic
Owen Anderson825b72b2009-08-11 20:47:22 +0000469 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LS[0], LS.size());
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000470 }
471
Dan Gohman98ca4f22009-08-05 01:29:28 +0000472 return Chain;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000473}
474
Dan Gohman98ca4f22009-08-05 01:29:28 +0000475SDValue
476AlphaTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000477 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000478 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000479 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +0000480 DebugLoc dl, SelectionDAG &DAG) const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000481
482 SDValue Copy = DAG.getCopyToReg(Chain, dl, Alpha::R26,
483 DAG.getNode(AlphaISD::GlobalRetAddr,
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000484 DebugLoc(), MVT::i64),
Dan Gohman98ca4f22009-08-05 01:29:28 +0000485 SDValue());
486 switch (Outs.size()) {
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000487 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000488 llvm_unreachable("Do not know how to return this many arguments!");
Dan Gohman98ca4f22009-08-05 01:29:28 +0000489 case 0:
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000490 break;
Dan Gohman475871a2008-07-27 21:46:04 +0000491 //return SDValue(); // ret void is legal
Dan Gohman98ca4f22009-08-05 01:29:28 +0000492 case 1: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000493 EVT ArgVT = Outs[0].VT;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000494 unsigned ArgReg;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000495 if (ArgVT.isInteger())
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000496 ArgReg = Alpha::R0;
497 else {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000498 assert(ArgVT.isFloatingPoint());
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000499 ArgReg = Alpha::F0;
500 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000501 Copy = DAG.getCopyToReg(Copy, dl, ArgReg,
Dan Gohmanc9403652010-07-07 15:54:55 +0000502 OutVals[0], Copy.getValue(1));
Chris Lattner84bc5422007-12-31 04:13:23 +0000503 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
504 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000505 break;
506 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000507 case 2: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000508 EVT ArgVT = Outs[0].VT;
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000509 unsigned ArgReg1, ArgReg2;
510 if (ArgVT.isInteger()) {
511 ArgReg1 = Alpha::R0;
512 ArgReg2 = Alpha::R1;
513 } else {
514 assert(ArgVT.isFloatingPoint());
515 ArgReg1 = Alpha::F0;
516 ArgReg2 = Alpha::F1;
517 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000518 Copy = DAG.getCopyToReg(Copy, dl, ArgReg1,
Dan Gohmanc9403652010-07-07 15:54:55 +0000519 OutVals[0], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000520 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000521 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg1)
522 == DAG.getMachineFunction().getRegInfo().liveout_end())
523 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg1);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000524 Copy = DAG.getCopyToReg(Copy, dl, ArgReg2,
Dan Gohmanc9403652010-07-07 15:54:55 +0000525 OutVals[1], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000526 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000527 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg2)
528 == DAG.getMachineFunction().getRegInfo().liveout_end())
529 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg2);
530 break;
531 }
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000532 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000533 return DAG.getNode(AlphaISD::RET_FLAG, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000534 MVT::Other, Copy, Copy.getValue(1));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000535}
536
Dan Gohman475871a2008-07-27 21:46:04 +0000537void AlphaTargetLowering::LowerVAARG(SDNode *N, SDValue &Chain,
Dan Gohmand858e902010-04-17 15:26:15 +0000538 SDValue &DataPtr,
539 SelectionDAG &DAG) const {
Duncan Sands126d9072008-07-04 11:47:58 +0000540 Chain = N->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000541 SDValue VAListP = N->getOperand(1);
Duncan Sands126d9072008-07-04 11:47:58 +0000542 const Value *VAListS = cast<SrcValueSDNode>(N->getOperand(2))->getValue();
Dale Johannesenf5d97892009-02-04 01:48:28 +0000543 DebugLoc dl = N->getDebugLoc();
Duncan Sands126d9072008-07-04 11:47:58 +0000544
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000545 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP,
546 MachinePointerInfo(VAListS),
David Greene0e2236c2010-02-15 16:55:07 +0000547 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000548 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
549 DAG.getConstant(8, MVT::i64));
Stuart Hastingsa9011292011-02-16 16:23:55 +0000550 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Base.getValue(1),
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000551 Tmp, MachinePointerInfo(),
552 MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000553 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sands126d9072008-07-04 11:47:58 +0000554 if (N->getValueType(0).isFloatingPoint())
555 {
556 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson825b72b2009-08-11 20:47:22 +0000557 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
558 DAG.getConstant(8*6, MVT::i64));
559 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
560 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
561 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sands126d9072008-07-04 11:47:58 +0000562 }
563
Owen Anderson825b72b2009-08-11 20:47:22 +0000564 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
565 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000566 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp,
567 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000568 MVT::i32, false, false, 0);
Duncan Sands126d9072008-07-04 11:47:58 +0000569}
570
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000571/// LowerOperation - Provide custom lowering hooks for some operations.
572///
Dan Gohmand858e902010-04-17 15:26:15 +0000573SDValue AlphaTargetLowering::LowerOperation(SDValue Op,
574 SelectionDAG &DAG) const {
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000575 DebugLoc dl = Op.getDebugLoc();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000576 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000577 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000578 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
579
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000580 case ISD::INTRINSIC_WO_CHAIN: {
581 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
582 switch (IntNo) {
583 default: break; // Don't custom lower most intrinsics.
584 case Intrinsic::alpha_umulh:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000585 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesende064702009-02-06 21:50:26 +0000586 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000587 }
588 }
589
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000590 case ISD::SRL_PARTS: {
591 SDValue ShOpLo = Op.getOperand(0);
592 SDValue ShOpHi = Op.getOperand(1);
593 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000594 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
595 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson825b72b2009-08-11 20:47:22 +0000596 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
597 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000598 // if 64 - shAmt <= 0
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
600 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000601 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson825b72b2009-08-11 20:47:22 +0000602 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000603 // else
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
605 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
606 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
607 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000608 // Merge
Owen Anderson825b72b2009-08-11 20:47:22 +0000609 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
610 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000611 SDValue Ops[2] = { Lo, Hi };
612 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000613 }
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000614 // case ISD::SRA_PARTS:
615
616 // case ISD::SHL_PARTS:
617
618
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000619 case ISD::SINT_TO_FP: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000620 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000621 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman475871a2008-07-27 21:46:04 +0000622 SDValue LD;
Owen Anderson825b72b2009-08-11 20:47:22 +0000623 bool isDouble = Op.getValueType() == MVT::f64;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000624 LD = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +0000625 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 isDouble?MVT::f64:MVT::f32, LD);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000627 return FP;
628 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000629 case ISD::FP_TO_SINT: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000630 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman475871a2008-07-27 21:46:04 +0000631 SDValue src = Op.getOperand(0);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000632
633 if (!isDouble) //Promote
Owen Anderson825b72b2009-08-11 20:47:22 +0000634 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000635
Owen Anderson825b72b2009-08-11 20:47:22 +0000636 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000637
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000638 return DAG.getNode(ISD::BITCAST, dl, MVT::i64, src);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000639 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000640 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000641 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000642 const Constant *C = CP->getConstVal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000643 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesende064702009-02-06 21:50:26 +0000644 // FIXME there isn't really any debug info here
Daniel Dunbara279bc32009-09-20 02:20:51 +0000645
Owen Anderson825b72b2009-08-11 20:47:22 +0000646 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
647 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
648 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000649 return Lo;
650 }
Lauro Ramos Venancio75ce0102007-07-11 17:19:51 +0000651 case ISD::GlobalTLSAddress:
Torok Edwinc23197a2009-07-14 16:55:14 +0000652 llvm_unreachable("TLS not implemented for Alpha.");
Andrew Lenharth4e629512005-12-24 05:36:33 +0000653 case ISD::GlobalAddress: {
654 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000655 const GlobalValue *GV = GSDN->getGlobal();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000656 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i64,
Devang Patel0d881da2010-07-06 22:08:15 +0000657 GSDN->getOffset());
Dale Johannesende064702009-02-06 21:50:26 +0000658 // FIXME there isn't really any debug info here
Andrew Lenharth4e629512005-12-24 05:36:33 +0000659
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000660 // if (!GV->hasWeakLinkage() && !GV->isDeclaration()
Devang Patel0d881da2010-07-06 22:08:15 +0000661 // && !GV->hasLinkOnceLinkage()) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000662 if (GV->hasLocalLinkage()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000663 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
664 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
665 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000666 return Lo;
667 } else
Daniel Dunbara279bc32009-09-20 02:20:51 +0000668 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson825b72b2009-08-11 20:47:22 +0000669 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000670 }
Bill Wendling056292f2008-09-16 21:48:12 +0000671 case ISD::ExternalSymbol: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000672 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendling056292f2008-09-16 21:48:12 +0000673 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson825b72b2009-08-11 20:47:22 +0000674 ->getSymbol(), MVT::i64),
675 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth53d89702005-12-25 01:34:27 +0000676 }
Bill Wendling056292f2008-09-16 21:48:12 +0000677
Andrew Lenharth53d89702005-12-25 01:34:27 +0000678 case ISD::UREM:
679 case ISD::SREM:
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000680 //Expand only on constant case
681 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersone50ed302009-08-10 22:56:29 +0000682 EVT VT = Op.getNode()->getValueType(0);
Gabor Greifba36cb52008-08-28 21:40:38 +0000683 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
684 BuildUDIV(Op.getNode(), DAG, NULL) :
685 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesende064702009-02-06 21:50:26 +0000686 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
687 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000688 return Tmp1;
689 }
690 //fall through
691 case ISD::SDIV:
692 case ISD::UDIV:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000693 if (Op.getValueType().isInteger()) {
Andrew Lenharth253b9e72006-04-06 21:26:32 +0000694 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbara279bc32009-09-20 02:20:51 +0000695 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greifba36cb52008-08-28 21:40:38 +0000696 : BuildUDIV(Op.getNode(), DAG, NULL);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000697 const char* opstr = 0;
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000698 switch (Op.getOpcode()) {
Andrew Lenharth53d89702005-12-25 01:34:27 +0000699 case ISD::UREM: opstr = "__remqu"; break;
700 case ISD::SREM: opstr = "__remq"; break;
701 case ISD::UDIV: opstr = "__divqu"; break;
702 case ISD::SDIV: opstr = "__divq"; break;
703 }
Dan Gohman475871a2008-07-27 21:46:04 +0000704 SDValue Tmp1 = Op.getOperand(0),
Andrew Lenharth53d89702005-12-25 01:34:27 +0000705 Tmp2 = Op.getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +0000706 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
707 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000708 }
709 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000710
Nate Begemanacc398c2006-01-25 18:21:52 +0000711 case ISD::VAARG: {
Dan Gohman475871a2008-07-27 21:46:04 +0000712 SDValue Chain, DataPtr;
Gabor Greifba36cb52008-08-28 21:40:38 +0000713 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Andrew Lenharth66e49582006-01-23 21:51:33 +0000714
Dan Gohman475871a2008-07-27 21:46:04 +0000715 SDValue Result;
Owen Anderson825b72b2009-08-11 20:47:22 +0000716 if (Op.getValueType() == MVT::i32)
Stuart Hastingsa9011292011-02-16 16:23:55 +0000717 Result = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Chain, DataPtr,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000718 MachinePointerInfo(), MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000719 else
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000720 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr,
721 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000722 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000723 return Result;
724 }
725 case ISD::VACOPY: {
Dan Gohman475871a2008-07-27 21:46:04 +0000726 SDValue Chain = Op.getOperand(0);
727 SDValue DestP = Op.getOperand(1);
728 SDValue SrcP = Op.getOperand(2);
Dan Gohman69de1932008-02-06 22:27:42 +0000729 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
730 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000731
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000732 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP,
733 MachinePointerInfo(SrcS),
David Greene0e2236c2010-02-15 16:55:07 +0000734 false, false, 0);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000735 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000736 MachinePointerInfo(DestS),
David Greene0e2236c2010-02-15 16:55:07 +0000737 false, false, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000738 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson825b72b2009-08-11 20:47:22 +0000739 DAG.getConstant(8, MVT::i64));
Stuart Hastingsa9011292011-02-16 16:23:55 +0000740 Val = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Result,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000741 NP, MachinePointerInfo(), MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000742 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
743 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000744 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD,
745 MachinePointerInfo(), MVT::i32,
David Greene0e2236c2010-02-15 16:55:07 +0000746 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000747 }
748 case ISD::VASTART: {
Dan Gohman1e93df62010-04-17 14:41:14 +0000749 MachineFunction &MF = DAG.getMachineFunction();
750 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
751
Dan Gohman475871a2008-07-27 21:46:04 +0000752 SDValue Chain = Op.getOperand(0);
753 SDValue VAListP = Op.getOperand(1);
Dan Gohman69de1932008-02-06 22:27:42 +0000754 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000755
Nate Begemanacc398c2006-01-25 18:21:52 +0000756 // vastart stores the address of the VarArgsBase and VarArgsOffset
Dan Gohman1e93df62010-04-17 14:41:14 +0000757 SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsBase(), MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000758 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP,
759 MachinePointerInfo(VAListS), false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000760 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
761 DAG.getConstant(8, MVT::i64));
Dan Gohman1e93df62010-04-17 14:41:14 +0000762 return DAG.getTruncStore(S1, dl,
763 DAG.getConstant(FuncInfo->getVarArgsOffset(),
764 MVT::i64),
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000765 SA2, MachinePointerInfo(),
766 MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000767 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000768 case ISD::RETURNADDR:
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000769 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc(), MVT::i64);
Andrew Lenharthac5a5452007-02-08 17:37:41 +0000770 //FIXME: implement
Nate Begemanbcc5f362007-01-29 22:58:52 +0000771 case ISD::FRAMEADDR: break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000772 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000773
Dan Gohman475871a2008-07-27 21:46:04 +0000774 return SDValue();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000775}
Nate Begeman0aed7842006-01-28 03:14:31 +0000776
Duncan Sands1607f052008-12-01 11:39:25 +0000777void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
778 SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000779 SelectionDAG &DAG) const {
Dale Johannesen33c960f2009-02-04 20:06:27 +0000780 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +0000781 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sands126d9072008-07-04 11:47:58 +0000782 N->getOpcode() == ISD::VAARG &&
Nate Begeman0aed7842006-01-28 03:14:31 +0000783 "Unknown node to custom promote!");
Duncan Sands126d9072008-07-04 11:47:58 +0000784
Dan Gohman475871a2008-07-27 21:46:04 +0000785 SDValue Chain, DataPtr;
Duncan Sands126d9072008-07-04 11:47:58 +0000786 LowerVAARG(N, Chain, DataPtr, DAG);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000787 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr,
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000788 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000789 false, false, 0);
Duncan Sands1607f052008-12-01 11:39:25 +0000790 Results.push_back(Res);
791 Results.push_back(SDValue(Res.getNode(), 1));
Nate Begeman0aed7842006-01-28 03:14:31 +0000792}
Andrew Lenharth17255992006-06-21 13:37:27 +0000793
794
795//Inline Asm
796
797/// getConstraintType - Given a constraint letter, return the type of
798/// constraint it is for this target.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000799AlphaTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +0000800AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
801 if (Constraint.size() == 1) {
802 switch (Constraint[0]) {
803 default: break;
804 case 'f':
805 case 'r':
806 return C_RegisterClass;
807 }
808 }
809 return TargetLowering::getConstraintType(Constraint);
Andrew Lenharth17255992006-06-21 13:37:27 +0000810}
811
John Thompson44ab89e2010-10-29 17:29:13 +0000812/// Examine constraint type and operand type and determine a weight value.
813/// This object must already have been set up with the operand type
814/// and the current alternative constraint selected.
815TargetLowering::ConstraintWeight
816AlphaTargetLowering::getSingleConstraintMatchWeight(
817 AsmOperandInfo &info, const char *constraint) const {
818 ConstraintWeight weight = CW_Invalid;
819 Value *CallOperandVal = info.CallOperandVal;
820 // If we don't have a value, we can't do a match,
821 // but allow it at the lowest weight.
822 if (CallOperandVal == NULL)
823 return CW_Default;
824 // Look at the constraint type.
825 switch (*constraint) {
826 default:
827 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
828 break;
829 case 'f':
830 weight = CW_Register;
831 break;
832 }
833 return weight;
834}
835
Eric Christopher46b65f72011-06-29 19:40:01 +0000836/// Given a register class constraint, like 'r', if this corresponds directly
837/// to an LLVM register class, return a register of 0 and the register class
838/// pointer.
839std::pair<unsigned, const TargetRegisterClass*> AlphaTargetLowering::
840getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const
841{
Andrew Lenharth17255992006-06-21 13:37:27 +0000842 if (Constraint.size() == 1) {
843 switch (Constraint[0]) {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000844 case 'r':
Eric Christopher46b65f72011-06-29 19:40:01 +0000845 return std::make_pair(0U, Alpha::GPRCRegisterClass);
846 case 'f':
Eric Christopher0a1509e2011-06-30 01:05:46 +0000847 return VT == MVT::f64 ? std::make_pair(0U, Alpha::F8RCRegisterClass) :
848 std::make_pair(0U, Alpha::F4RCRegisterClass);
Andrew Lenharth17255992006-06-21 13:37:27 +0000849 }
850 }
Eric Christopher46b65f72011-06-29 19:40:01 +0000851 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
Andrew Lenharth17255992006-06-21 13:37:27 +0000852}
Eric Christopher46b65f72011-06-29 19:40:01 +0000853
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000854//===----------------------------------------------------------------------===//
855// Other Lowering Code
856//===----------------------------------------------------------------------===//
857
858MachineBasicBlock *
859AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000860 MachineBasicBlock *BB) const {
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000861 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
862 assert((MI->getOpcode() == Alpha::CAS32 ||
863 MI->getOpcode() == Alpha::CAS64 ||
864 MI->getOpcode() == Alpha::LAS32 ||
865 MI->getOpcode() == Alpha::LAS64 ||
866 MI->getOpcode() == Alpha::SWAP32 ||
867 MI->getOpcode() == Alpha::SWAP64) &&
868 "Unexpected instr type to insert");
869
Daniel Dunbara279bc32009-09-20 02:20:51 +0000870 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000871 MI->getOpcode() == Alpha::LAS32 ||
872 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000873
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000874 //Load locked store conditional for atomic ops take on the same form
875 //start:
876 //ll
877 //do stuff (maybe branch to exit)
878 //sc
879 //test sc and maybe branck to start
880 //exit:
881 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen01b36e62009-02-13 02:30:42 +0000882 DebugLoc dl = MI->getDebugLoc();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000883 MachineFunction::iterator It = BB;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000884 ++It;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000885
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000886 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000887 MachineFunction *F = BB->getParent();
888 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
889 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000890
Dan Gohman14152b42010-07-06 20:24:04 +0000891 sinkMBB->splice(sinkMBB->begin(), thisMBB,
892 llvm::next(MachineBasicBlock::iterator(MI)),
893 thisMBB->end());
894 sinkMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000895
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000896 F->insert(It, llscMBB);
897 F->insert(It, sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000898
Dale Johannesen01b36e62009-02-13 02:30:42 +0000899 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000900
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000901 unsigned reg_res = MI->getOperand(0).getReg(),
902 reg_ptr = MI->getOperand(1).getReg(),
903 reg_v2 = MI->getOperand(2).getReg(),
904 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
905
Daniel Dunbara279bc32009-09-20 02:20:51 +0000906 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000907 reg_res).addImm(0).addReg(reg_ptr);
908 switch (MI->getOpcode()) {
909 case Alpha::CAS32:
910 case Alpha::CAS64: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000911 unsigned reg_cmp
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000912 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000913 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000914 .addReg(reg_v2).addReg(reg_res);
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_cmp).addMBB(sinkMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000917 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000918 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
919 break;
920 }
921 case Alpha::LAS32:
922 case Alpha::LAS64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000923 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000924 .addReg(reg_res).addReg(reg_v2);
925 break;
926 }
927 case Alpha::SWAP32:
928 case Alpha::SWAP64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000929 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000930 .addReg(reg_v2).addReg(reg_v2);
931 break;
932 }
933 }
Dale Johannesen01b36e62009-02-13 02:30:42 +0000934 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000935 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000936 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000937 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000938 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000939
940 thisMBB->addSuccessor(llscMBB);
941 llscMBB->addSuccessor(llscMBB);
942 llscMBB->addSuccessor(sinkMBB);
Dan Gohman14152b42010-07-06 20:24:04 +0000943 MI->eraseFromParent(); // The pseudo instruction is gone now.
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000944
945 return sinkMBB;
946}
Dan Gohman6520e202008-10-18 02:06:02 +0000947
948bool
949AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
950 // The Alpha target isn't yet aware of offsets.
951 return false;
952}
Evan Chengeb2f9692009-10-27 19:56:55 +0000953
Evan Chenga1eaa3c2009-10-28 01:43:28 +0000954bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
955 if (VT != MVT::f32 && VT != MVT::f64)
956 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +0000957 // +0.0 F31
958 // +0.0f F31
959 // -0.0 -F31
960 // -0.0f -F31
961 return Imm.isZero() || Imm.isNegZero();
962}