blob: 68ae71530acac10f571c7d032dbe61f06a64b7c3 [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);
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
Cameron Zwarich33390842011-07-08 21:39:21 +0000125 setOperationAction(ISD::FMA, MVT::f64, Expand);
126 setOperationAction(ISD::FMA, MVT::f32, Expand);
127
Owen Anderson825b72b2009-08-11 20:47:22 +0000128 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000129
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000130 setOperationAction(ISD::BITCAST, MVT::f32, Promote);
Andrew Lenharth3553d862007-01-24 21:09:16 +0000131
Owen Anderson825b72b2009-08-11 20:47:22 +0000132 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000133
134 // Not implemented yet.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000135 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
Owen Anderson825b72b2009-08-11 20:47:22 +0000136 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
137 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Andrew Lenharth739027e2006-01-16 21:22:38 +0000138
Bill Wendling056292f2008-09-16 21:48:12 +0000139 // We want to legalize GlobalAddress and ConstantPool and
140 // ExternalSymbols nodes into the appropriate instructions to
141 // materialize the address.
Owen Anderson825b72b2009-08-11 20:47:22 +0000142 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
143 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
144 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
145 setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000146
Owen Anderson825b72b2009-08-11 20:47:22 +0000147 setOperationAction(ISD::VASTART, MVT::Other, Custom);
148 setOperationAction(ISD::VAEND, MVT::Other, Expand);
149 setOperationAction(ISD::VACOPY, MVT::Other, Custom);
150 setOperationAction(ISD::VAARG, MVT::Other, Custom);
151 setOperationAction(ISD::VAARG, MVT::i32, Custom);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000152
Owen Anderson825b72b2009-08-11 20:47:22 +0000153 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
154 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000155
Eli Friedman4db5aca2011-08-29 18:23:02 +0000156 setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand);
157 setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand);
158
Andrew Lenharth739027e2006-01-16 21:22:38 +0000159 setStackPointerRegisterToSaveRestore(Alpha::R30);
160
Andrew Lenharth89c0b4a2006-09-05 00:22:25 +0000161 setJumpBufSize(272);
162 setJumpBufAlignment(16);
163
Eli Friedmanfc5d3052011-05-06 20:34:06 +0000164 setMinFunctionAlignment(4);
165
Eli Friedman26689ac2011-08-03 21:06:02 +0000166 setInsertFencesForAtomic(true);
167
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000168 computeRegisterProperties();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000169}
170
Owen Anderson825b72b2009-08-11 20:47:22 +0000171MVT::SimpleValueType AlphaTargetLowering::getSetCCResultType(EVT VT) const {
172 return MVT::i64;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000173}
174
Andrew Lenharth84a06052006-01-16 19:53:25 +0000175const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
176 switch (Opcode) {
177 default: return 0;
Andrew Lenharth84a06052006-01-16 19:53:25 +0000178 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
179 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
180 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
181 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
182 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
183 case AlphaISD::RelLit: return "Alpha::RelLit";
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000184 case AlphaISD::GlobalRetAddr: return "Alpha::GlobalRetAddr";
Chris Lattner2d90bd52006-01-27 23:39:00 +0000185 case AlphaISD::CALL: return "Alpha::CALL";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000186 case AlphaISD::DivCall: return "Alpha::DivCall";
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000187 case AlphaISD::RET_FLAG: return "Alpha::RET_FLAG";
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000188 case AlphaISD::COND_BRANCH_I: return "Alpha::COND_BRANCH_I";
189 case AlphaISD::COND_BRANCH_F: return "Alpha::COND_BRANCH_F";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000190 }
191}
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000192
Dan Gohman475871a2008-07-27 21:46:04 +0000193static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
Owen Andersone50ed302009-08-10 22:56:29 +0000194 EVT PtrVT = Op.getValueType();
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000195 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Dan Gohman475871a2008-07-27 21:46:04 +0000196 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
Dale Johannesende064702009-02-06 21:50:26 +0000197 // FIXME there isn't really any debug info here
198 DebugLoc dl = Op.getDebugLoc();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000199
Owen Anderson825b72b2009-08-11 20:47:22 +0000200 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, JTI,
201 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
202 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, JTI, Hi);
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000203 return Lo;
204}
205
Chris Lattnere21492b2006-08-11 17:19:54 +0000206//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/
207//AA-PY8AC-TET1_html/callCH3.html#BLOCK21
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000208
209//For now, just use variable size stack frame format
210
211//In a standard call, the first six items are passed in registers $16
212//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
213//of argument-to-register correspondence.) The remaining items are
214//collected in a memory argument list that is a naturally aligned
215//array of quadwords. In a standard call, this list, if present, must
216//be passed at 0(SP).
217//7 ... n 0(SP) ... (n-7)*8(SP)
218
219// //#define FP $15
220// //#define RA $26
221// //#define PV $27
222// //#define GP $29
223// //#define SP $30
224
Eli Friedman796492d2009-07-19 01:11:32 +0000225#include "AlphaGenCallingConv.inc"
226
Dan Gohman98ca4f22009-08-05 01:29:28 +0000227SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000228AlphaTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000229 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000230 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000231 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000232 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000233 const SmallVectorImpl<ISD::InputArg> &Ins,
234 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000235 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000236 // Alpha target does not yet support tail call optimization.
237 isTailCall = false;
Eli Friedman796492d2009-07-19 01:11:32 +0000238
239 // Analyze operands of the call, assigning locations to each operand.
240 SmallVector<CCValAssign, 16> ArgLocs;
Eric Christopher471e4222011-06-08 23:55:35 +0000241 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(),
242 getTargetMachine(), ArgLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000243
Dan Gohman98ca4f22009-08-05 01:29:28 +0000244 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000245
246 // Get a count of how many bytes are to be pushed on the stack.
247 unsigned NumBytes = CCInfo.getNextStackOffset();
248
249 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
250 getPointerTy(), true));
251
252 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
253 SmallVector<SDValue, 12> MemOpChains;
254 SDValue StackPtr;
255
256 // Walk the register/memloc assignments, inserting copies/loads.
257 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
258 CCValAssign &VA = ArgLocs[i];
259
Dan Gohmanc9403652010-07-07 15:54:55 +0000260 SDValue Arg = OutVals[i];
Eli Friedman796492d2009-07-19 01:11:32 +0000261
262 // Promote the value if needed.
263 switch (VA.getLocInfo()) {
264 default: assert(0 && "Unknown loc info!");
265 case CCValAssign::Full: break;
266 case CCValAssign::SExt:
267 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
268 break;
269 case CCValAssign::ZExt:
270 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
271 break;
272 case CCValAssign::AExt:
273 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
274 break;
275 }
276
277 // Arguments that can be passed on register must be kept at RegsToPass
278 // vector
279 if (VA.isRegLoc()) {
280 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
281 } else {
282 assert(VA.isMemLoc());
283
284 if (StackPtr.getNode() == 0)
Owen Anderson825b72b2009-08-11 20:47:22 +0000285 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedman796492d2009-07-19 01:11:32 +0000286
287 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
288 StackPtr,
289 DAG.getIntPtrConstant(VA.getLocMemOffset()));
290
291 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000292 MachinePointerInfo(),false, false, 0));
Eli Friedman796492d2009-07-19 01:11:32 +0000293 }
294 }
295
296 // Transform all store nodes into one single node because all store nodes are
297 // independent of each other.
298 if (!MemOpChains.empty())
Owen Anderson825b72b2009-08-11 20:47:22 +0000299 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Eli Friedman796492d2009-07-19 01:11:32 +0000300 &MemOpChains[0], MemOpChains.size());
301
302 // Build a sequence of copy-to-reg nodes chained together with token chain and
303 // flag operands which copy the outgoing args into registers. The InFlag in
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000304 // necessary since all emitted instructions must be stuck together.
Eli Friedman796492d2009-07-19 01:11:32 +0000305 SDValue InFlag;
306 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
307 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
308 RegsToPass[i].second, InFlag);
309 InFlag = Chain.getValue(1);
310 }
311
312 // Returns a chain & a flag for retval copy to use.
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000313 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
Eli Friedman796492d2009-07-19 01:11:32 +0000314 SmallVector<SDValue, 8> Ops;
315 Ops.push_back(Chain);
316 Ops.push_back(Callee);
317
318 // Add argument registers to the end of the list so that they are
319 // known live into the call.
320 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
321 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
322 RegsToPass[i].second.getValueType()));
323
324 if (InFlag.getNode())
325 Ops.push_back(InFlag);
326
327 Chain = DAG.getNode(AlphaISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
328 InFlag = Chain.getValue(1);
329
330 // Create the CALLSEQ_END node.
331 Chain = DAG.getCALLSEQ_END(Chain,
332 DAG.getConstant(NumBytes, getPointerTy(), true),
333 DAG.getConstant(0, getPointerTy(), true),
334 InFlag);
335 InFlag = Chain.getValue(1);
336
337 // Handle result values, copying them out of physregs into vregs that we
338 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000339 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
340 Ins, dl, DAG, InVals);
Eli Friedman796492d2009-07-19 01:11:32 +0000341}
342
Dan Gohman98ca4f22009-08-05 01:29:28 +0000343/// LowerCallResult - Lower the result values of a call into the
344/// appropriate copies out of appropriate physical registers.
345///
346SDValue
Eli Friedman796492d2009-07-19 01:11:32 +0000347AlphaTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000348 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000349 const SmallVectorImpl<ISD::InputArg> &Ins,
350 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000351 SmallVectorImpl<SDValue> &InVals) const {
Eli Friedman796492d2009-07-19 01:11:32 +0000352
353 // Assign locations to each value returned by this call.
354 SmallVector<CCValAssign, 16> RVLocs;
Eric Christopher471e4222011-06-08 23:55:35 +0000355 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(),
356 getTargetMachine(), RVLocs, *DAG.getContext());
Eli Friedman796492d2009-07-19 01:11:32 +0000357
Dan Gohman98ca4f22009-08-05 01:29:28 +0000358 CCInfo.AnalyzeCallResult(Ins, RetCC_Alpha);
Eli Friedman796492d2009-07-19 01:11:32 +0000359
360 // Copy all of the result registers out of their specified physreg.
361 for (unsigned i = 0; i != RVLocs.size(); ++i) {
362 CCValAssign &VA = RVLocs[i];
363
364 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
365 VA.getLocVT(), InFlag).getValue(1);
366 SDValue RetValue = Chain.getValue(0);
367 InFlag = Chain.getValue(2);
368
369 // If this is an 8/16/32-bit value, it is really passed promoted to 64
370 // bits. Insert an assert[sz]ext to capture this, then truncate to the
371 // right size.
372 if (VA.getLocInfo() == CCValAssign::SExt)
373 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
374 DAG.getValueType(VA.getValVT()));
375 else if (VA.getLocInfo() == CCValAssign::ZExt)
376 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
377 DAG.getValueType(VA.getValVT()));
378
379 if (VA.getLocInfo() != CCValAssign::Full)
380 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
381
Dan Gohman98ca4f22009-08-05 01:29:28 +0000382 InVals.push_back(RetValue);
Eli Friedman796492d2009-07-19 01:11:32 +0000383 }
384
Dan Gohman98ca4f22009-08-05 01:29:28 +0000385 return Chain;
Eli Friedman796492d2009-07-19 01:11:32 +0000386}
387
Dan Gohman98ca4f22009-08-05 01:29:28 +0000388SDValue
389AlphaTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000390 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000391 const SmallVectorImpl<ISD::InputArg>
392 &Ins,
393 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000394 SmallVectorImpl<SDValue> &InVals)
395 const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000396
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000397 MachineFunction &MF = DAG.getMachineFunction();
398 MachineFrameInfo *MFI = MF.getFrameInfo();
Dan Gohman1e93df62010-04-17 14:41:14 +0000399 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000400
Andrew Lenharthf71df332005-09-04 06:12:19 +0000401 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000402 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000403 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000404 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Daniel Dunbara279bc32009-09-20 02:20:51 +0000405
Dan Gohman98ca4f22009-08-05 01:29:28 +0000406 for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
Dan Gohman475871a2008-07-27 21:46:04 +0000407 SDValue argt;
Owen Andersone50ed302009-08-10 22:56:29 +0000408 EVT ObjectVT = Ins[ArgNo].VT;
Dan Gohman475871a2008-07-27 21:46:04 +0000409 SDValue ArgVal;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000410
411 if (ArgNo < 6) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000412 switch (ObjectVT.getSimpleVT().SimpleTy) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000413 default:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000414 assert(false && "Invalid value type!");
Owen Anderson825b72b2009-08-11 20:47:22 +0000415 case MVT::f64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000416 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000417 &Alpha::F8RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000418 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000419 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000420 case MVT::f32:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000421 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000422 &Alpha::F4RCRegClass);
Dan Gohman98ca4f22009-08-05 01:29:28 +0000423 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Andrew Lenharthd1aab352006-06-21 01:00:43 +0000424 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000425 case MVT::i64:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000426 args_int[ArgNo] = AddLiveIn(MF, args_int[ArgNo],
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000427 &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000428 ArgVal = DAG.getCopyFromReg(Chain, dl, args_int[ArgNo], MVT::i64);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000429 break;
430 }
431 } else { //more args
432 // Create the frame index object for this incoming parameter...
Evan Chenged2ae132010-07-03 00:40:23 +0000433 int FI = MFI->CreateFixedObject(8, 8 * (ArgNo - 6), true);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000434
435 // Create the SelectionDAG nodes corresponding to a load
436 //from this parameter
Owen Anderson825b72b2009-08-11 20:47:22 +0000437 SDValue FIN = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000438 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000439 false, false, 0);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000440 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000441 InVals.push_back(ArgVal);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000442 }
443
444 // If the functions takes variable number of arguments, copy all regs to stack
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000445 if (isVarArg) {
Dan Gohman1e93df62010-04-17 14:41:14 +0000446 FuncInfo->setVarArgsOffset(Ins.size() * 8);
Dan Gohman475871a2008-07-27 21:46:04 +0000447 std::vector<SDValue> LS;
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000448 for (int i = 0; i < 6; ++i) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000449 if (TargetRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000450 args_int[i] = AddLiveIn(MF, args_int[i], &Alpha::GPRCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000451 SDValue argt = DAG.getCopyFromReg(Chain, dl, args_int[i], MVT::i64);
Evan Chenged2ae132010-07-03 00:40:23 +0000452 int FI = MFI->CreateFixedObject(8, -8 * (6 - i), true);
Dan Gohman1e93df62010-04-17 14:41:14 +0000453 if (i == 0) FuncInfo->setVarArgsBase(FI);
Owen Anderson825b72b2009-08-11 20:47:22 +0000454 SDValue SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000455 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000456 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000457
Dan Gohman6f0d0242008-02-10 18:45:23 +0000458 if (TargetRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000459 args_float[i] = AddLiveIn(MF, args_float[i], &Alpha::F8RCRegClass);
Owen Anderson825b72b2009-08-11 20:47:22 +0000460 argt = DAG.getCopyFromReg(Chain, dl, args_float[i], MVT::f64);
Evan Chenged2ae132010-07-03 00:40:23 +0000461 FI = MFI->CreateFixedObject(8, - 8 * (12 - i), true);
Owen Anderson825b72b2009-08-11 20:47:22 +0000462 SDFI = DAG.getFrameIndex(FI, MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000463 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000464 false, false, 0));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000465 }
466
467 //Set up a token factor with all the stack traffic
Owen Anderson825b72b2009-08-11 20:47:22 +0000468 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LS[0], LS.size());
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000469 }
470
Dan Gohman98ca4f22009-08-05 01:29:28 +0000471 return Chain;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000472}
473
Dan Gohman98ca4f22009-08-05 01:29:28 +0000474SDValue
475AlphaTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000476 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000477 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000478 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +0000479 DebugLoc dl, SelectionDAG &DAG) const {
Dan Gohman98ca4f22009-08-05 01:29:28 +0000480
481 SDValue Copy = DAG.getCopyToReg(Chain, dl, Alpha::R26,
482 DAG.getNode(AlphaISD::GlobalRetAddr,
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000483 DebugLoc(), MVT::i64),
Dan Gohman98ca4f22009-08-05 01:29:28 +0000484 SDValue());
485 switch (Outs.size()) {
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000486 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000487 llvm_unreachable("Do not know how to return this many arguments!");
Dan Gohman98ca4f22009-08-05 01:29:28 +0000488 case 0:
Andrew Lenharth0e4dd012006-06-13 18:27:39 +0000489 break;
Dan Gohman475871a2008-07-27 21:46:04 +0000490 //return SDValue(); // ret void is legal
Dan Gohman98ca4f22009-08-05 01:29:28 +0000491 case 1: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000492 EVT ArgVT = Outs[0].VT;
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000493 unsigned ArgReg;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000494 if (ArgVT.isInteger())
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000495 ArgReg = Alpha::R0;
496 else {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000497 assert(ArgVT.isFloatingPoint());
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000498 ArgReg = Alpha::F0;
499 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000500 Copy = DAG.getCopyToReg(Copy, dl, ArgReg,
Dan Gohmanc9403652010-07-07 15:54:55 +0000501 OutVals[0], Copy.getValue(1));
Chris Lattner84bc5422007-12-31 04:13:23 +0000502 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
503 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000504 break;
505 }
Dan Gohman98ca4f22009-08-05 01:29:28 +0000506 case 2: {
Dan Gohmanc9403652010-07-07 15:54:55 +0000507 EVT ArgVT = Outs[0].VT;
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000508 unsigned ArgReg1, ArgReg2;
509 if (ArgVT.isInteger()) {
510 ArgReg1 = Alpha::R0;
511 ArgReg2 = Alpha::R1;
512 } else {
513 assert(ArgVT.isFloatingPoint());
514 ArgReg1 = Alpha::F0;
515 ArgReg2 = Alpha::F1;
516 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000517 Copy = DAG.getCopyToReg(Copy, dl, ArgReg1,
Dan Gohmanc9403652010-07-07 15:54:55 +0000518 OutVals[0], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000519 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000520 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg1)
521 == DAG.getMachineFunction().getRegInfo().liveout_end())
522 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg1);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000523 Copy = DAG.getCopyToReg(Copy, dl, ArgReg2,
Dan Gohmanc9403652010-07-07 15:54:55 +0000524 OutVals[1], Copy.getValue(1));
Daniel Dunbara279bc32009-09-20 02:20:51 +0000525 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000526 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg2)
527 == DAG.getMachineFunction().getRegInfo().liveout_end())
528 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg2);
529 break;
530 }
Andrew Lenharthf2b806a2006-06-12 18:09:24 +0000531 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000532 return DAG.getNode(AlphaISD::RET_FLAG, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000533 MVT::Other, Copy, Copy.getValue(1));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000534}
535
Dan Gohman475871a2008-07-27 21:46:04 +0000536void AlphaTargetLowering::LowerVAARG(SDNode *N, SDValue &Chain,
Dan Gohmand858e902010-04-17 15:26:15 +0000537 SDValue &DataPtr,
538 SelectionDAG &DAG) const {
Duncan Sands126d9072008-07-04 11:47:58 +0000539 Chain = N->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000540 SDValue VAListP = N->getOperand(1);
Duncan Sands126d9072008-07-04 11:47:58 +0000541 const Value *VAListS = cast<SrcValueSDNode>(N->getOperand(2))->getValue();
Dale Johannesenf5d97892009-02-04 01:48:28 +0000542 DebugLoc dl = N->getDebugLoc();
Duncan Sands126d9072008-07-04 11:47:58 +0000543
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000544 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP,
545 MachinePointerInfo(VAListS),
David Greene0e2236c2010-02-15 16:55:07 +0000546 false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000547 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
548 DAG.getConstant(8, MVT::i64));
Stuart Hastingsa9011292011-02-16 16:23:55 +0000549 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Base.getValue(1),
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000550 Tmp, MachinePointerInfo(),
551 MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000552 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sands126d9072008-07-04 11:47:58 +0000553 if (N->getValueType(0).isFloatingPoint())
554 {
555 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson825b72b2009-08-11 20:47:22 +0000556 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
557 DAG.getConstant(8*6, MVT::i64));
558 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
559 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
560 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sands126d9072008-07-04 11:47:58 +0000561 }
562
Owen Anderson825b72b2009-08-11 20:47:22 +0000563 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
564 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000565 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp,
566 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000567 MVT::i32, false, false, 0);
Duncan Sands126d9072008-07-04 11:47:58 +0000568}
569
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000570/// LowerOperation - Provide custom lowering hooks for some operations.
571///
Dan Gohmand858e902010-04-17 15:26:15 +0000572SDValue AlphaTargetLowering::LowerOperation(SDValue Op,
573 SelectionDAG &DAG) const {
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000574 DebugLoc dl = Op.getDebugLoc();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000575 switch (Op.getOpcode()) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000576 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Andrew Lenharthea4f9d52006-09-18 18:01:03 +0000577 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
578
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000579 case ISD::INTRINSIC_WO_CHAIN: {
580 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
581 switch (IntNo) {
582 default: break; // Don't custom lower most intrinsics.
583 case Intrinsic::alpha_umulh:
Daniel Dunbara279bc32009-09-20 02:20:51 +0000584 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesende064702009-02-06 21:50:26 +0000585 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharth1b19ef02008-10-07 02:10:26 +0000586 }
587 }
588
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000589 case ISD::SRL_PARTS: {
590 SDValue ShOpLo = Op.getOperand(0);
591 SDValue ShOpHi = Op.getOperand(1);
592 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000593 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
594 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson825b72b2009-08-11 20:47:22 +0000595 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
596 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000597 // if 64 - shAmt <= 0
Owen Anderson825b72b2009-08-11 20:47:22 +0000598 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
599 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbara279bc32009-09-20 02:20:51 +0000600 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson825b72b2009-08-11 20:47:22 +0000601 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000602 // else
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
604 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
605 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
606 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000607 // Merge
Owen Anderson825b72b2009-08-11 20:47:22 +0000608 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
609 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000610 SDValue Ops[2] = { Lo, Hi };
611 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000612 }
Andrew Lenharth7116b7b2009-08-07 22:37:20 +0000613 // case ISD::SRA_PARTS:
614
615 // case ISD::SHL_PARTS:
616
617
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000618 case ISD::SINT_TO_FP: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000619 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000620 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue LD;
Owen Anderson825b72b2009-08-11 20:47:22 +0000622 bool isDouble = Op.getValueType() == MVT::f64;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000623 LD = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op.getOperand(0));
Dale Johannesende064702009-02-06 21:50:26 +0000624 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 isDouble?MVT::f64:MVT::f32, LD);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000626 return FP;
627 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000628 case ISD::FP_TO_SINT: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000629 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman475871a2008-07-27 21:46:04 +0000630 SDValue src = Op.getOperand(0);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000631
632 if (!isDouble) //Promote
Owen Anderson825b72b2009-08-11 20:47:22 +0000633 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000634
Owen Anderson825b72b2009-08-11 20:47:22 +0000635 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Andrew Lenharthcd804962005-11-30 16:10:29 +0000636
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000637 return DAG.getNode(ISD::BITCAST, dl, MVT::i64, src);
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000638 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000639 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000640 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000641 const Constant *C = CP->getConstVal();
Owen Anderson825b72b2009-08-11 20:47:22 +0000642 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesende064702009-02-06 21:50:26 +0000643 // FIXME there isn't really any debug info here
Daniel Dunbara279bc32009-09-20 02:20:51 +0000644
Owen Anderson825b72b2009-08-11 20:47:22 +0000645 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
646 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
647 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000648 return Lo;
649 }
Lauro Ramos Venancio75ce0102007-07-11 17:19:51 +0000650 case ISD::GlobalTLSAddress:
Torok Edwinc23197a2009-07-14 16:55:14 +0000651 llvm_unreachable("TLS not implemented for Alpha.");
Andrew Lenharth4e629512005-12-24 05:36:33 +0000652 case ISD::GlobalAddress: {
653 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000654 const GlobalValue *GV = GSDN->getGlobal();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000655 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i64,
Devang Patel0d881da2010-07-06 22:08:15 +0000656 GSDN->getOffset());
Dale Johannesende064702009-02-06 21:50:26 +0000657 // FIXME there isn't really any debug info here
Andrew Lenharth4e629512005-12-24 05:36:33 +0000658
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000659 // if (!GV->hasWeakLinkage() && !GV->isDeclaration()
Devang Patel0d881da2010-07-06 22:08:15 +0000660 // && !GV->hasLinkOnceLinkage()) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000661 if (GV->hasLocalLinkage()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000662 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
663 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
664 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000665 return Lo;
666 } else
Daniel Dunbara279bc32009-09-20 02:20:51 +0000667 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson825b72b2009-08-11 20:47:22 +0000668 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000669 }
Bill Wendling056292f2008-09-16 21:48:12 +0000670 case ISD::ExternalSymbol: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000671 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendling056292f2008-09-16 21:48:12 +0000672 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson825b72b2009-08-11 20:47:22 +0000673 ->getSymbol(), MVT::i64),
674 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Andrew Lenharth53d89702005-12-25 01:34:27 +0000675 }
Bill Wendling056292f2008-09-16 21:48:12 +0000676
Andrew Lenharth53d89702005-12-25 01:34:27 +0000677 case ISD::UREM:
678 case ISD::SREM:
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000679 //Expand only on constant case
680 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersone50ed302009-08-10 22:56:29 +0000681 EVT VT = Op.getNode()->getValueType(0);
Gabor Greifba36cb52008-08-28 21:40:38 +0000682 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
683 BuildUDIV(Op.getNode(), DAG, NULL) :
684 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesende064702009-02-06 21:50:26 +0000685 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
686 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Andrew Lenharthccd9f982006-04-02 21:08:39 +0000687 return Tmp1;
688 }
689 //fall through
690 case ISD::SDIV:
691 case ISD::UDIV:
Duncan Sands83ec4b62008-06-06 12:08:01 +0000692 if (Op.getValueType().isInteger()) {
Andrew Lenharth253b9e72006-04-06 21:26:32 +0000693 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbara279bc32009-09-20 02:20:51 +0000694 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greifba36cb52008-08-28 21:40:38 +0000695 : BuildUDIV(Op.getNode(), DAG, NULL);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000696 const char* opstr = 0;
Anton Korobeynikovbed29462007-04-16 18:10:23 +0000697 switch (Op.getOpcode()) {
Andrew Lenharth53d89702005-12-25 01:34:27 +0000698 case ISD::UREM: opstr = "__remqu"; break;
699 case ISD::SREM: opstr = "__remq"; break;
700 case ISD::UDIV: opstr = "__divqu"; break;
701 case ISD::SDIV: opstr = "__divq"; break;
702 }
Dan Gohman475871a2008-07-27 21:46:04 +0000703 SDValue Tmp1 = Op.getOperand(0),
Andrew Lenharth53d89702005-12-25 01:34:27 +0000704 Tmp2 = Op.getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +0000705 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
706 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Andrew Lenharth53d89702005-12-25 01:34:27 +0000707 }
708 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000709
Nate Begemanacc398c2006-01-25 18:21:52 +0000710 case ISD::VAARG: {
Dan Gohman475871a2008-07-27 21:46:04 +0000711 SDValue Chain, DataPtr;
Gabor Greifba36cb52008-08-28 21:40:38 +0000712 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Andrew Lenharth66e49582006-01-23 21:51:33 +0000713
Dan Gohman475871a2008-07-27 21:46:04 +0000714 SDValue Result;
Owen Anderson825b72b2009-08-11 20:47:22 +0000715 if (Op.getValueType() == MVT::i32)
Stuart Hastingsa9011292011-02-16 16:23:55 +0000716 Result = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Chain, DataPtr,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000717 MachinePointerInfo(), MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000718 else
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000719 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr,
720 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000721 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000722 return Result;
723 }
724 case ISD::VACOPY: {
Dan Gohman475871a2008-07-27 21:46:04 +0000725 SDValue Chain = Op.getOperand(0);
726 SDValue DestP = Op.getOperand(1);
727 SDValue SrcP = Op.getOperand(2);
Dan Gohman69de1932008-02-06 22:27:42 +0000728 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
729 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000730
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000731 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP,
732 MachinePointerInfo(SrcS),
David Greene0e2236c2010-02-15 16:55:07 +0000733 false, false, 0);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000734 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP,
Chris Lattner6229d0a2010-09-21 18:41:36 +0000735 MachinePointerInfo(DestS),
David Greene0e2236c2010-02-15 16:55:07 +0000736 false, false, 0);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000737 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson825b72b2009-08-11 20:47:22 +0000738 DAG.getConstant(8, MVT::i64));
Stuart Hastingsa9011292011-02-16 16:23:55 +0000739 Val = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Result,
Chris Lattner3d6ccfb2010-09-21 17:04:51 +0000740 NP, MachinePointerInfo(), MVT::i32, false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000741 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
742 DAG.getConstant(8, MVT::i64));
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000743 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD,
744 MachinePointerInfo(), MVT::i32,
David Greene0e2236c2010-02-15 16:55:07 +0000745 false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000746 }
747 case ISD::VASTART: {
Dan Gohman1e93df62010-04-17 14:41:14 +0000748 MachineFunction &MF = DAG.getMachineFunction();
749 AlphaMachineFunctionInfo *FuncInfo = MF.getInfo<AlphaMachineFunctionInfo>();
750
Dan Gohman475871a2008-07-27 21:46:04 +0000751 SDValue Chain = Op.getOperand(0);
752 SDValue VAListP = Op.getOperand(1);
Dan Gohman69de1932008-02-06 22:27:42 +0000753 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbara279bc32009-09-20 02:20:51 +0000754
Nate Begemanacc398c2006-01-25 18:21:52 +0000755 // vastart stores the address of the VarArgsBase and VarArgsOffset
Dan Gohman1e93df62010-04-17 14:41:14 +0000756 SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsBase(), MVT::i64);
Chris Lattner6229d0a2010-09-21 18:41:36 +0000757 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP,
758 MachinePointerInfo(VAListS), false, false, 0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000759 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
760 DAG.getConstant(8, MVT::i64));
Dan Gohman1e93df62010-04-17 14:41:14 +0000761 return DAG.getTruncStore(S1, dl,
762 DAG.getConstant(FuncInfo->getVarArgsOffset(),
763 MVT::i64),
Chris Lattnerda2d8e12010-09-21 17:42:31 +0000764 SA2, MachinePointerInfo(),
765 MVT::i32, false, false, 0);
Nate Begemanacc398c2006-01-25 18:21:52 +0000766 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000767 case ISD::RETURNADDR:
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000768 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc(), MVT::i64);
Andrew Lenharthac5a5452007-02-08 17:37:41 +0000769 //FIXME: implement
Nate Begemanbcc5f362007-01-29 22:58:52 +0000770 case ISD::FRAMEADDR: break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000771 }
Daniel Dunbara279bc32009-09-20 02:20:51 +0000772
Dan Gohman475871a2008-07-27 21:46:04 +0000773 return SDValue();
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000774}
Nate Begeman0aed7842006-01-28 03:14:31 +0000775
Duncan Sands1607f052008-12-01 11:39:25 +0000776void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
777 SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000778 SelectionDAG &DAG) const {
Dale Johannesen33c960f2009-02-04 20:06:27 +0000779 DebugLoc dl = N->getDebugLoc();
Owen Anderson825b72b2009-08-11 20:47:22 +0000780 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sands126d9072008-07-04 11:47:58 +0000781 N->getOpcode() == ISD::VAARG &&
Nate Begeman0aed7842006-01-28 03:14:31 +0000782 "Unknown node to custom promote!");
Duncan Sands126d9072008-07-04 11:47:58 +0000783
Dan Gohman475871a2008-07-27 21:46:04 +0000784 SDValue Chain, DataPtr;
Duncan Sands126d9072008-07-04 11:47:58 +0000785 LowerVAARG(N, Chain, DataPtr, DAG);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000786 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr,
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000787 MachinePointerInfo(),
David Greene0e2236c2010-02-15 16:55:07 +0000788 false, false, 0);
Duncan Sands1607f052008-12-01 11:39:25 +0000789 Results.push_back(Res);
790 Results.push_back(SDValue(Res.getNode(), 1));
Nate Begeman0aed7842006-01-28 03:14:31 +0000791}
Andrew Lenharth17255992006-06-21 13:37:27 +0000792
793
794//Inline Asm
795
796/// getConstraintType - Given a constraint letter, return the type of
797/// constraint it is for this target.
Daniel Dunbara279bc32009-09-20 02:20:51 +0000798AlphaTargetLowering::ConstraintType
Chris Lattner4234f572007-03-25 02:14:49 +0000799AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
800 if (Constraint.size() == 1) {
801 switch (Constraint[0]) {
802 default: break;
803 case 'f':
804 case 'r':
805 return C_RegisterClass;
806 }
807 }
808 return TargetLowering::getConstraintType(Constraint);
Andrew Lenharth17255992006-06-21 13:37:27 +0000809}
810
John Thompson44ab89e2010-10-29 17:29:13 +0000811/// Examine constraint type and operand type and determine a weight value.
812/// This object must already have been set up with the operand type
813/// and the current alternative constraint selected.
814TargetLowering::ConstraintWeight
815AlphaTargetLowering::getSingleConstraintMatchWeight(
816 AsmOperandInfo &info, const char *constraint) const {
817 ConstraintWeight weight = CW_Invalid;
818 Value *CallOperandVal = info.CallOperandVal;
819 // If we don't have a value, we can't do a match,
820 // but allow it at the lowest weight.
821 if (CallOperandVal == NULL)
822 return CW_Default;
823 // Look at the constraint type.
824 switch (*constraint) {
825 default:
826 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
827 break;
828 case 'f':
829 weight = CW_Register;
830 break;
831 }
832 return weight;
833}
834
Eric Christopher46b65f72011-06-29 19:40:01 +0000835/// Given a register class constraint, like 'r', if this corresponds directly
836/// to an LLVM register class, return a register of 0 and the register class
837/// pointer.
838std::pair<unsigned, const TargetRegisterClass*> AlphaTargetLowering::
839getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const
840{
Andrew Lenharth17255992006-06-21 13:37:27 +0000841 if (Constraint.size() == 1) {
842 switch (Constraint[0]) {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000843 case 'r':
Eric Christopher46b65f72011-06-29 19:40:01 +0000844 return std::make_pair(0U, Alpha::GPRCRegisterClass);
845 case 'f':
Eric Christopher0a1509e2011-06-30 01:05:46 +0000846 return VT == MVT::f64 ? std::make_pair(0U, Alpha::F8RCRegisterClass) :
847 std::make_pair(0U, Alpha::F4RCRegisterClass);
Andrew Lenharth17255992006-06-21 13:37:27 +0000848 }
849 }
Eric Christopher46b65f72011-06-29 19:40:01 +0000850 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
Andrew Lenharth17255992006-06-21 13:37:27 +0000851}
Eric Christopher46b65f72011-06-29 19:40:01 +0000852
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000853//===----------------------------------------------------------------------===//
854// Other Lowering Code
855//===----------------------------------------------------------------------===//
856
857MachineBasicBlock *
858AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000859 MachineBasicBlock *BB) const {
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000860 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
861 assert((MI->getOpcode() == Alpha::CAS32 ||
862 MI->getOpcode() == Alpha::CAS64 ||
863 MI->getOpcode() == Alpha::LAS32 ||
864 MI->getOpcode() == Alpha::LAS64 ||
865 MI->getOpcode() == Alpha::SWAP32 ||
866 MI->getOpcode() == Alpha::SWAP64) &&
867 "Unexpected instr type to insert");
868
Daniel Dunbara279bc32009-09-20 02:20:51 +0000869 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000870 MI->getOpcode() == Alpha::LAS32 ||
871 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000872
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000873 //Load locked store conditional for atomic ops take on the same form
874 //start:
875 //ll
876 //do stuff (maybe branch to exit)
877 //sc
878 //test sc and maybe branck to start
879 //exit:
880 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen01b36e62009-02-13 02:30:42 +0000881 DebugLoc dl = MI->getDebugLoc();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000882 MachineFunction::iterator It = BB;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000883 ++It;
Daniel Dunbara279bc32009-09-20 02:20:51 +0000884
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000885 MachineBasicBlock *thisMBB = BB;
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000886 MachineFunction *F = BB->getParent();
887 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
888 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000889
Dan Gohman14152b42010-07-06 20:24:04 +0000890 sinkMBB->splice(sinkMBB->begin(), thisMBB,
891 llvm::next(MachineBasicBlock::iterator(MI)),
892 thisMBB->end());
893 sinkMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000894
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000895 F->insert(It, llscMBB);
896 F->insert(It, sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000897
Dale Johannesen01b36e62009-02-13 02:30:42 +0000898 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbara279bc32009-09-20 02:20:51 +0000899
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000900 unsigned reg_res = MI->getOperand(0).getReg(),
901 reg_ptr = MI->getOperand(1).getReg(),
902 reg_v2 = MI->getOperand(2).getReg(),
903 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
904
Daniel Dunbara279bc32009-09-20 02:20:51 +0000905 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000906 reg_res).addImm(0).addReg(reg_ptr);
907 switch (MI->getOpcode()) {
908 case Alpha::CAS32:
909 case Alpha::CAS64: {
Daniel Dunbara279bc32009-09-20 02:20:51 +0000910 unsigned reg_cmp
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000911 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000912 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000913 .addReg(reg_v2).addReg(reg_res);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000914 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000915 .addImm(0).addReg(reg_cmp).addMBB(sinkMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000916 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000917 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
918 break;
919 }
920 case Alpha::LAS32:
921 case Alpha::LAS64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000922 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000923 .addReg(reg_res).addReg(reg_v2);
924 break;
925 }
926 case Alpha::SWAP32:
927 case Alpha::SWAP64: {
Dale Johannesen01b36e62009-02-13 02:30:42 +0000928 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000929 .addReg(reg_v2).addReg(reg_v2);
930 break;
931 }
932 }
Dale Johannesen01b36e62009-02-13 02:30:42 +0000933 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000934 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000935 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000936 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen01b36e62009-02-13 02:30:42 +0000937 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000938
939 thisMBB->addSuccessor(llscMBB);
940 llscMBB->addSuccessor(llscMBB);
941 llscMBB->addSuccessor(sinkMBB);
Dan Gohman14152b42010-07-06 20:24:04 +0000942 MI->eraseFromParent(); // The pseudo instruction is gone now.
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000943
944 return sinkMBB;
945}
Dan Gohman6520e202008-10-18 02:06:02 +0000946
947bool
948AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
949 // The Alpha target isn't yet aware of offsets.
950 return false;
951}
Evan Chengeb2f9692009-10-27 19:56:55 +0000952
Evan Chenga1eaa3c2009-10-28 01:43:28 +0000953bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
954 if (VT != MVT::f32 && VT != MVT::f64)
955 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +0000956 // +0.0 F31
957 // +0.0f F31
958 // -0.0 -F31
959 // -0.0f -F31
960 return Imm.isZero() || Imm.isNegZero();
961}