blob: 3daa16b517234dab0c5949ac6e347cbec7ada22d [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- AlphaISelLowering.cpp - Alpha DAG Lowering Implementation ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AlphaISelLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AlphaISelLowering.h"
15#include "AlphaTargetMachine.h"
Eli Friedmanc52e5592009-07-19 01:11:32 +000016#include "llvm/CodeGen/CallingConvLower.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "llvm/CodeGen/MachineFrameInfo.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner1b989192007-12-31 04:13:23 +000020#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021#include "llvm/CodeGen/SelectionDAG.h"
Chris Lattner1b989192007-12-31 04:13:23 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Eli Friedmanc52e5592009-07-19 01:11:32 +000023#include "llvm/CodeGen/PseudoSourceValue.h"
Chris Lattnerc4c40a92009-07-28 03:13:23 +000024#include "llvm/Target/TargetLoweringObjectFile.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025#include "llvm/Constants.h"
26#include "llvm/Function.h"
27#include "llvm/Module.h"
Andrew Lenharthc69be952008-10-07 02:10:26 +000028#include "llvm/Intrinsics.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029#include "llvm/Support/CommandLine.h"
Edwin Török2b331342009-07-08 19:04:27 +000030#include "llvm/Support/ErrorHandling.h"
Edwin Török4d9756a2009-07-08 20:53:28 +000031#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032using namespace llvm;
33
34/// AddLiveIn - This helper function adds the specified physical register to the
35/// MachineFunction as a live in value. It also creates a corresponding virtual
36/// register for it.
37static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
38 TargetRegisterClass *RC) {
39 assert(RC->contains(PReg) && "Not the correct regclass!");
Chris Lattner1b989192007-12-31 04:13:23 +000040 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
41 MF.getRegInfo().addLiveIn(PReg, VReg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 return VReg;
43}
44
Chris Lattnerc4c40a92009-07-28 03:13:23 +000045AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM)
Andrew Lenharth6d2fba12009-08-05 18:13:04 +000046 : TargetLowering(TM, new TargetLoweringObjectFileELF()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 // Set up the TargetLowering object.
Dan Gohman9e1657f2009-06-14 23:30:43 +000048 //I am having problems with shr n i8 1
Owen Anderson36e3a6e2009-08-11 20:47:22 +000049 setShiftAmountType(MVT::i64);
Duncan Sands8cf4a822008-11-23 15:47:28 +000050 setBooleanContents(ZeroOrOneBooleanContent);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000051
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 setUsesGlobalOffsetTable(true);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000053
Owen Anderson36e3a6e2009-08-11 20:47:22 +000054 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
55 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
56 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharthc69be952008-10-07 02:10:26 +000057
58 // We want to custom lower some of our intrinsics.
Owen Anderson36e3a6e2009-08-11 20:47:22 +000059 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
Andrew Lenharthc69be952008-10-07 02:10:26 +000060
Owen Anderson36e3a6e2009-08-11 20:47:22 +000061 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
62 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000063
Owen Anderson36e3a6e2009-08-11 20:47:22 +000064 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
65 setLoadExtAction(ISD::ZEXTLOAD, MVT::i32, Expand);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000066
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070
Owen Anderson36e3a6e2009-08-11 20:47:22 +000071 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Eli Friedman07d8ebd2009-07-17 05:23:03 +000072
Owen Anderson36e3a6e2009-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 Dunbar3be44e62009-09-20 02:20:51 +000076 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077
Owen Anderson36e3a6e2009-08-11 20:47:22 +000078 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079
Owen Anderson36e3a6e2009-08-11 20:47:22 +000080 setOperationAction(ISD::FREM, MVT::f32, Expand);
81 setOperationAction(ISD::FREM, MVT::f64, Expand);
Daniel Dunbar3be44e62009-09-20 02:20:51 +000082
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087
88 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 }
Owen Anderson36e3a6e2009-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 Dunbar3be44e62009-09-20 02:20:51 +000096
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101
Owen Anderson36e3a6e2009-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 Lenharthc69be952008-10-07 02:10:26 +0000106
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000107 setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
108 setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
Chris Lattner418b09b2008-10-09 04:50:56 +0000109
Owen Anderson36e3a6e2009-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 Lenharthc69be952008-10-07 02:10:26 +0000113
Dan Gohman2f7b1982007-10-11 23:21:31 +0000114 // We don't support sin/cos/sqrt/pow
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000120 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
121 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Dan Gohman2f7b1982007-10-11 23:21:31 +0000122
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000123 setOperationAction(ISD::FPOW , MVT::f32, Expand);
124 setOperationAction(ISD::FPOW , MVT::f64, Expand);
Dale Johannesen92b33082008-09-04 00:47:13 +0000125
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000126 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000128 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Promote);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129
130 // We don't have line number support yet.
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000131 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
132 setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand);
133 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134
135 // Not implemented yet.
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000136 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000137 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
138 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139
Bill Wendlingfef06052008-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 Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000147
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000154 setOperationAction(ISD::JumpTable, MVT::i64, Custom);
155 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156
157 setStackPointerRegisterToSaveRestore(Alpha::R30);
158
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159 setJumpBufSize(272);
160 setJumpBufAlignment(16);
161
162 computeRegisterProperties();
163}
164
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000165MVT::SimpleValueType AlphaTargetLowering::getSetCCResultType(EVT VT) const {
166 return MVT::i64;
Scott Michel502151f2008-03-10 15:42:14 +0000167}
168
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
170 switch (Opcode) {
171 default: return 0;
172 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
173 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
174 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
175 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
176 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
177 case AlphaISD::RelLit: return "Alpha::RelLit";
178 case AlphaISD::GlobalRetAddr: return "Alpha::GlobalRetAddr";
179 case AlphaISD::CALL: return "Alpha::CALL";
180 case AlphaISD::DivCall: return "Alpha::DivCall";
181 case AlphaISD::RET_FLAG: return "Alpha::RET_FLAG";
182 case AlphaISD::COND_BRANCH_I: return "Alpha::COND_BRANCH_I";
183 case AlphaISD::COND_BRANCH_F: return "Alpha::COND_BRANCH_F";
184 }
185}
186
Bill Wendling045f2632009-07-01 18:50:55 +0000187/// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling25a8ae32009-06-30 22:38:32 +0000188unsigned AlphaTargetLowering::getFunctionAlignment(const Function *F) const {
189 return 4;
190}
191
Dan Gohman8181bd12008-07-27 21:46:04 +0000192static SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
Owen Andersonac9de032009-08-10 22:56:29 +0000193 EVT PtrVT = Op.getValueType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Dan Gohman8181bd12008-07-27 21:46:04 +0000195 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
196 SDValue Zero = DAG.getConstant(0, PtrVT);
Dale Johannesen175fdef2009-02-06 21:50:26 +0000197 // FIXME there isn't really any debug info here
198 DebugLoc dl = Op.getDebugLoc();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000199
Owen Anderson36e3a6e2009-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);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 return Lo;
204}
205
206//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/
207//AA-PY8AC-TET1_html/callCH3.html#BLOCK21
208
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 Friedmanc52e5592009-07-19 01:11:32 +0000225#include "AlphaGenCallingConv.inc"
226
Dan Gohman9178de12009-08-05 01:29:28 +0000227SDValue
228AlphaTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel5838baa2009-09-02 08:44:58 +0000229 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman9178de12009-08-05 01:29:28 +0000230 bool isTailCall,
231 const SmallVectorImpl<ISD::OutputArg> &Outs,
232 const SmallVectorImpl<ISD::InputArg> &Ins,
233 DebugLoc dl, SelectionDAG &DAG,
234 SmallVectorImpl<SDValue> &InVals) {
Eli Friedmanc52e5592009-07-19 01:11:32 +0000235
236 // Analyze operands of the call, assigning locations to each operand.
237 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman9178de12009-08-05 01:29:28 +0000238 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
239 ArgLocs, *DAG.getContext());
Eli Friedmanc52e5592009-07-19 01:11:32 +0000240
Dan Gohman9178de12009-08-05 01:29:28 +0000241 CCInfo.AnalyzeCallOperands(Outs, CC_Alpha);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000242
243 // Get a count of how many bytes are to be pushed on the stack.
244 unsigned NumBytes = CCInfo.getNextStackOffset();
245
246 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(NumBytes,
247 getPointerTy(), true));
248
249 SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
250 SmallVector<SDValue, 12> MemOpChains;
251 SDValue StackPtr;
252
253 // Walk the register/memloc assignments, inserting copies/loads.
254 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
255 CCValAssign &VA = ArgLocs[i];
256
Dan Gohman9178de12009-08-05 01:29:28 +0000257 SDValue Arg = Outs[i].Val;
Eli Friedmanc52e5592009-07-19 01:11:32 +0000258
259 // Promote the value if needed.
260 switch (VA.getLocInfo()) {
261 default: assert(0 && "Unknown loc info!");
262 case CCValAssign::Full: break;
263 case CCValAssign::SExt:
264 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
265 break;
266 case CCValAssign::ZExt:
267 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
268 break;
269 case CCValAssign::AExt:
270 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
271 break;
272 }
273
274 // Arguments that can be passed on register must be kept at RegsToPass
275 // vector
276 if (VA.isRegLoc()) {
277 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
278 } else {
279 assert(VA.isMemLoc());
280
281 if (StackPtr.getNode() == 0)
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000282 StackPtr = DAG.getCopyFromReg(Chain, dl, Alpha::R30, MVT::i64);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000283
284 SDValue PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(),
285 StackPtr,
286 DAG.getIntPtrConstant(VA.getLocMemOffset()));
287
288 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
289 PseudoSourceValue::getStack(), 0));
290 }
291 }
292
293 // Transform all store nodes into one single node because all store nodes are
294 // independent of each other.
295 if (!MemOpChains.empty())
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000296 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Eli Friedmanc52e5592009-07-19 01:11:32 +0000297 &MemOpChains[0], MemOpChains.size());
298
299 // Build a sequence of copy-to-reg nodes chained together with token chain and
300 // flag operands which copy the outgoing args into registers. The InFlag in
301 // necessary since all emited instructions must be stuck together.
302 SDValue InFlag;
303 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
304 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
305 RegsToPass[i].second, InFlag);
306 InFlag = Chain.getValue(1);
307 }
308
309 // Returns a chain & a flag for retval copy to use.
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000310 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000311 SmallVector<SDValue, 8> Ops;
312 Ops.push_back(Chain);
313 Ops.push_back(Callee);
314
315 // Add argument registers to the end of the list so that they are
316 // known live into the call.
317 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
318 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
319 RegsToPass[i].second.getValueType()));
320
321 if (InFlag.getNode())
322 Ops.push_back(InFlag);
323
324 Chain = DAG.getNode(AlphaISD::CALL, dl, NodeTys, &Ops[0], Ops.size());
325 InFlag = Chain.getValue(1);
326
327 // Create the CALLSEQ_END node.
328 Chain = DAG.getCALLSEQ_END(Chain,
329 DAG.getConstant(NumBytes, getPointerTy(), true),
330 DAG.getConstant(0, getPointerTy(), true),
331 InFlag);
332 InFlag = Chain.getValue(1);
333
334 // Handle result values, copying them out of physregs into vregs that we
335 // return.
Dan Gohman9178de12009-08-05 01:29:28 +0000336 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
337 Ins, dl, DAG, InVals);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000338}
339
Dan Gohman9178de12009-08-05 01:29:28 +0000340/// LowerCallResult - Lower the result values of a call into the
341/// appropriate copies out of appropriate physical registers.
342///
343SDValue
Eli Friedmanc52e5592009-07-19 01:11:32 +0000344AlphaTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel5838baa2009-09-02 08:44:58 +0000345 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman9178de12009-08-05 01:29:28 +0000346 const SmallVectorImpl<ISD::InputArg> &Ins,
347 DebugLoc dl, SelectionDAG &DAG,
348 SmallVectorImpl<SDValue> &InVals) {
Eli Friedmanc52e5592009-07-19 01:11:32 +0000349
350 // Assign locations to each value returned by this call.
351 SmallVector<CCValAssign, 16> RVLocs;
Dan Gohman9178de12009-08-05 01:29:28 +0000352 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), RVLocs,
Owen Anderson175b6542009-07-22 00:24:57 +0000353 *DAG.getContext());
Eli Friedmanc52e5592009-07-19 01:11:32 +0000354
Dan Gohman9178de12009-08-05 01:29:28 +0000355 CCInfo.AnalyzeCallResult(Ins, RetCC_Alpha);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000356
357 // Copy all of the result registers out of their specified physreg.
358 for (unsigned i = 0; i != RVLocs.size(); ++i) {
359 CCValAssign &VA = RVLocs[i];
360
361 Chain = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(),
362 VA.getLocVT(), InFlag).getValue(1);
363 SDValue RetValue = Chain.getValue(0);
364 InFlag = Chain.getValue(2);
365
366 // If this is an 8/16/32-bit value, it is really passed promoted to 64
367 // bits. Insert an assert[sz]ext to capture this, then truncate to the
368 // right size.
369 if (VA.getLocInfo() == CCValAssign::SExt)
370 RetValue = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), RetValue,
371 DAG.getValueType(VA.getValVT()));
372 else if (VA.getLocInfo() == CCValAssign::ZExt)
373 RetValue = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), RetValue,
374 DAG.getValueType(VA.getValVT()));
375
376 if (VA.getLocInfo() != CCValAssign::Full)
377 RetValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), RetValue);
378
Dan Gohman9178de12009-08-05 01:29:28 +0000379 InVals.push_back(RetValue);
Eli Friedmanc52e5592009-07-19 01:11:32 +0000380 }
381
Dan Gohman9178de12009-08-05 01:29:28 +0000382 return Chain;
Eli Friedmanc52e5592009-07-19 01:11:32 +0000383}
384
Dan Gohman9178de12009-08-05 01:29:28 +0000385SDValue
386AlphaTargetLowering::LowerFormalArguments(SDValue Chain,
Sandeep Patel5838baa2009-09-02 08:44:58 +0000387 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman9178de12009-08-05 01:29:28 +0000388 const SmallVectorImpl<ISD::InputArg>
389 &Ins,
390 DebugLoc dl, SelectionDAG &DAG,
391 SmallVectorImpl<SDValue> &InVals) {
392
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 MachineFunction &MF = DAG.getMachineFunction();
394 MachineFrameInfo *MFI = MF.getFrameInfo();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396 unsigned args_int[] = {
397 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
398 unsigned args_float[] = {
399 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000400
Dan Gohman9178de12009-08-05 01:29:28 +0000401 for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
Dan Gohman8181bd12008-07-27 21:46:04 +0000402 SDValue argt;
Owen Andersonac9de032009-08-10 22:56:29 +0000403 EVT ObjectVT = Ins[ArgNo].VT;
Dan Gohman8181bd12008-07-27 21:46:04 +0000404 SDValue ArgVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405
406 if (ArgNo < 6) {
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000407 switch (ObjectVT.getSimpleVT().SimpleTy) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408 default:
Duncan Sands92c43912008-06-06 12:08:01 +0000409 assert(false && "Invalid value type!");
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000410 case MVT::f64:
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000411 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000412 &Alpha::F8RCRegClass);
Dan Gohman9178de12009-08-05 01:29:28 +0000413 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414 break;
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000415 case MVT::f32:
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000416 args_float[ArgNo] = AddLiveIn(MF, args_float[ArgNo],
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417 &Alpha::F4RCRegClass);
Dan Gohman9178de12009-08-05 01:29:28 +0000418 ArgVal = DAG.getCopyFromReg(Chain, dl, args_float[ArgNo], ObjectVT);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419 break;
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000420 case MVT::i64:
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000421 args_int[ArgNo] = AddLiveIn(MF, args_int[ArgNo],
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422 &Alpha::GPRCRegClass);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000423 ArgVal = DAG.getCopyFromReg(Chain, dl, args_int[ArgNo], MVT::i64);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000424 break;
425 }
426 } else { //more args
427 // Create the frame index object for this incoming parameter...
David Greene6424ab92009-11-12 20:49:22 +0000428 int FI = MFI->CreateFixedObject(8, 8 * (ArgNo - 6), true, false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429
430 // Create the SelectionDAG nodes corresponding to a load
431 //from this parameter
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000432 SDValue FIN = DAG.getFrameIndex(FI, MVT::i64);
Dan Gohman9178de12009-08-05 01:29:28 +0000433 ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, NULL, 0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 }
Dan Gohman9178de12009-08-05 01:29:28 +0000435 InVals.push_back(ArgVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436 }
437
438 // If the functions takes variable number of arguments, copy all regs to stack
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 if (isVarArg) {
Dan Gohman9178de12009-08-05 01:29:28 +0000440 VarArgsOffset = Ins.size() * 8;
Dan Gohman8181bd12008-07-27 21:46:04 +0000441 std::vector<SDValue> LS;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442 for (int i = 0; i < 6; ++i) {
Dan Gohman1e57df32008-02-10 18:45:23 +0000443 if (TargetRegisterInfo::isPhysicalRegister(args_int[i]))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 args_int[i] = AddLiveIn(MF, args_int[i], &Alpha::GPRCRegClass);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000445 SDValue argt = DAG.getCopyFromReg(Chain, dl, args_int[i], MVT::i64);
David Greene6424ab92009-11-12 20:49:22 +0000446 int FI = MFI->CreateFixedObject(8, -8 * (6 - i), true, false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 if (i == 0) VarArgsBase = FI;
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000448 SDValue SDFI = DAG.getFrameIndex(FI, MVT::i64);
Dan Gohman9178de12009-08-05 01:29:28 +0000449 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450
Dan Gohman1e57df32008-02-10 18:45:23 +0000451 if (TargetRegisterInfo::isPhysicalRegister(args_float[i]))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452 args_float[i] = AddLiveIn(MF, args_float[i], &Alpha::F8RCRegClass);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000453 argt = DAG.getCopyFromReg(Chain, dl, args_float[i], MVT::f64);
David Greene6424ab92009-11-12 20:49:22 +0000454 FI = MFI->CreateFixedObject(8, - 8 * (12 - i), true, false);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000455 SDFI = DAG.getFrameIndex(FI, MVT::i64);
Dan Gohman9178de12009-08-05 01:29:28 +0000456 LS.push_back(DAG.getStore(Chain, dl, argt, SDFI, NULL, 0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457 }
458
459 //Set up a token factor with all the stack traffic
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000460 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &LS[0], LS.size());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461 }
462
Dan Gohman9178de12009-08-05 01:29:28 +0000463 return Chain;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464}
465
Dan Gohman9178de12009-08-05 01:29:28 +0000466SDValue
467AlphaTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel5838baa2009-09-02 08:44:58 +0000468 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman9178de12009-08-05 01:29:28 +0000469 const SmallVectorImpl<ISD::OutputArg> &Outs,
470 DebugLoc dl, SelectionDAG &DAG) {
471
472 SDValue Copy = DAG.getCopyToReg(Chain, dl, Alpha::R26,
473 DAG.getNode(AlphaISD::GlobalRetAddr,
474 DebugLoc::getUnknownLoc(),
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000475 MVT::i64),
Dan Gohman9178de12009-08-05 01:29:28 +0000476 SDValue());
477 switch (Outs.size()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478 default:
Edwin Törökbd448e32009-07-14 16:55:14 +0000479 llvm_unreachable("Do not know how to return this many arguments!");
Dan Gohman9178de12009-08-05 01:29:28 +0000480 case 0:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481 break;
Dan Gohman8181bd12008-07-27 21:46:04 +0000482 //return SDValue(); // ret void is legal
Dan Gohman9178de12009-08-05 01:29:28 +0000483 case 1: {
Owen Andersonac9de032009-08-10 22:56:29 +0000484 EVT ArgVT = Outs[0].Val.getValueType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485 unsigned ArgReg;
Duncan Sands92c43912008-06-06 12:08:01 +0000486 if (ArgVT.isInteger())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 ArgReg = Alpha::R0;
488 else {
Duncan Sands92c43912008-06-06 12:08:01 +0000489 assert(ArgVT.isFloatingPoint());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490 ArgReg = Alpha::F0;
491 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000492 Copy = DAG.getCopyToReg(Copy, dl, ArgReg,
Dan Gohman9178de12009-08-05 01:29:28 +0000493 Outs[0].Val, Copy.getValue(1));
Chris Lattner1b989192007-12-31 04:13:23 +0000494 if (DAG.getMachineFunction().getRegInfo().liveout_empty())
495 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 break;
497 }
Dan Gohman9178de12009-08-05 01:29:28 +0000498 case 2: {
Owen Andersonac9de032009-08-10 22:56:29 +0000499 EVT ArgVT = Outs[0].Val.getValueType();
Andrew Lenharthc69be952008-10-07 02:10:26 +0000500 unsigned ArgReg1, ArgReg2;
501 if (ArgVT.isInteger()) {
502 ArgReg1 = Alpha::R0;
503 ArgReg2 = Alpha::R1;
504 } else {
505 assert(ArgVT.isFloatingPoint());
506 ArgReg1 = Alpha::F0;
507 ArgReg2 = Alpha::F1;
508 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000509 Copy = DAG.getCopyToReg(Copy, dl, ArgReg1,
Dan Gohman9178de12009-08-05 01:29:28 +0000510 Outs[0].Val, Copy.getValue(1));
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000511 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharthc69be952008-10-07 02:10:26 +0000512 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg1)
513 == DAG.getMachineFunction().getRegInfo().liveout_end())
514 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg1);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000515 Copy = DAG.getCopyToReg(Copy, dl, ArgReg2,
Dan Gohman9178de12009-08-05 01:29:28 +0000516 Outs[1].Val, Copy.getValue(1));
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000517 if (std::find(DAG.getMachineFunction().getRegInfo().liveout_begin(),
Andrew Lenharthc69be952008-10-07 02:10:26 +0000518 DAG.getMachineFunction().getRegInfo().liveout_end(), ArgReg2)
519 == DAG.getMachineFunction().getRegInfo().liveout_end())
520 DAG.getMachineFunction().getRegInfo().addLiveOut(ArgReg2);
521 break;
522 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000524 return DAG.getNode(AlphaISD::RET_FLAG, dl,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000525 MVT::Other, Copy, Copy.getValue(1));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526}
527
Dan Gohman8181bd12008-07-27 21:46:04 +0000528void AlphaTargetLowering::LowerVAARG(SDNode *N, SDValue &Chain,
529 SDValue &DataPtr, SelectionDAG &DAG) {
Duncan Sandsac496a12008-07-04 11:47:58 +0000530 Chain = N->getOperand(0);
Dan Gohman8181bd12008-07-27 21:46:04 +0000531 SDValue VAListP = N->getOperand(1);
Duncan Sandsac496a12008-07-04 11:47:58 +0000532 const Value *VAListS = cast<SrcValueSDNode>(N->getOperand(2))->getValue();
Dale Johannesen85fc0932009-02-04 01:48:28 +0000533 DebugLoc dl = N->getDebugLoc();
Duncan Sandsac496a12008-07-04 11:47:58 +0000534
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000535 SDValue Base = DAG.getLoad(MVT::i64, dl, Chain, VAListP, VAListS, 0);
536 SDValue Tmp = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
537 DAG.getConstant(8, MVT::i64));
538 SDValue Offset = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Base.getValue(1),
539 Tmp, NULL, 0, MVT::i32);
540 DataPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Base, Offset);
Duncan Sandsac496a12008-07-04 11:47:58 +0000541 if (N->getValueType(0).isFloatingPoint())
542 {
543 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000544 SDValue FPDataPtr = DAG.getNode(ISD::SUB, dl, MVT::i64, DataPtr,
545 DAG.getConstant(8*6, MVT::i64));
546 SDValue CC = DAG.getSetCC(dl, MVT::i64, Offset,
547 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
548 DataPtr = DAG.getNode(ISD::SELECT, dl, MVT::i64, CC, FPDataPtr, DataPtr);
Duncan Sandsac496a12008-07-04 11:47:58 +0000549 }
550
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000551 SDValue NewOffset = DAG.getNode(ISD::ADD, dl, MVT::i64, Offset,
552 DAG.getConstant(8, MVT::i64));
Dale Johannesen85fc0932009-02-04 01:48:28 +0000553 Chain = DAG.getTruncStore(Offset.getValue(1), dl, NewOffset, Tmp, NULL, 0,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000554 MVT::i32);
Duncan Sandsac496a12008-07-04 11:47:58 +0000555}
556
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557/// LowerOperation - Provide custom lowering hooks for some operations.
558///
Dan Gohman8181bd12008-07-27 21:46:04 +0000559SDValue AlphaTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
Dale Johannesen2dbdb0e2009-02-07 19:59:05 +0000560 DebugLoc dl = Op.getDebugLoc();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561 switch (Op.getOpcode()) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000562 default: llvm_unreachable("Wasn't expecting to be able to lower this!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
564
Andrew Lenharthc69be952008-10-07 02:10:26 +0000565 case ISD::INTRINSIC_WO_CHAIN: {
566 unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
567 switch (IntNo) {
568 default: break; // Don't custom lower most intrinsics.
569 case Intrinsic::alpha_umulh:
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000570 return DAG.getNode(ISD::MULHU, dl, MVT::i64,
Dale Johannesen175fdef2009-02-06 21:50:26 +0000571 Op.getOperand(1), Op.getOperand(2));
Andrew Lenharthc69be952008-10-07 02:10:26 +0000572 }
573 }
574
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000575 case ISD::SRL_PARTS: {
576 SDValue ShOpLo = Op.getOperand(0);
577 SDValue ShOpHi = Op.getOperand(1);
578 SDValue ShAmt = Op.getOperand(2);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000579 SDValue bm = DAG.getNode(ISD::SUB, dl, MVT::i64,
580 DAG.getConstant(64, MVT::i64), ShAmt);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000581 SDValue BMCC = DAG.getSetCC(dl, MVT::i64, bm,
582 DAG.getConstant(0, MVT::i64), ISD::SETLE);
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000583 // if 64 - shAmt <= 0
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000584 SDValue Hi_Neg = DAG.getConstant(0, MVT::i64);
585 SDValue ShAmt_Neg = DAG.getNode(ISD::SUB, dl, MVT::i64,
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000586 DAG.getConstant(0, MVT::i64), bm);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000587 SDValue Lo_Neg = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt_Neg);
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000588 // else
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000589 SDValue carries = DAG.getNode(ISD::SHL, dl, MVT::i64, ShOpHi, bm);
590 SDValue Hi_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpHi, ShAmt);
591 SDValue Lo_Pos = DAG.getNode(ISD::SRL, dl, MVT::i64, ShOpLo, ShAmt);
592 Lo_Pos = DAG.getNode(ISD::OR, dl, MVT::i64, Lo_Pos, carries);
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000593 // Merge
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000594 SDValue Hi = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Hi_Neg, Hi_Pos);
595 SDValue Lo = DAG.getNode(ISD::SELECT, dl, MVT::i64, BMCC, Lo_Neg, Lo_Pos);
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000596 SDValue Ops[2] = { Lo, Hi };
597 return DAG.getMergeValues(Ops, 2, dl);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000598 }
Andrew Lenharth35f9cde2009-08-07 22:37:20 +0000599 // case ISD::SRA_PARTS:
600
601 // case ISD::SHL_PARTS:
602
603
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604 case ISD::SINT_TO_FP: {
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000605 assert(Op.getOperand(0).getValueType() == MVT::i64 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606 "Unhandled SINT_TO_FP type in custom expander!");
Dan Gohman8181bd12008-07-27 21:46:04 +0000607 SDValue LD;
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000608 bool isDouble = Op.getValueType() == MVT::f64;
609 LD = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f64, Op.getOperand(0));
Dale Johannesen175fdef2009-02-06 21:50:26 +0000610 SDValue FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, dl,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000611 isDouble?MVT::f64:MVT::f32, LD);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 return FP;
613 }
614 case ISD::FP_TO_SINT: {
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000615 bool isDouble = Op.getOperand(0).getValueType() == MVT::f64;
Dan Gohman8181bd12008-07-27 21:46:04 +0000616 SDValue src = Op.getOperand(0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618 if (!isDouble) //Promote
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000619 src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, src);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000620
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000621 src = DAG.getNode(AlphaISD::CVTTQ_, dl, MVT::f64, src);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000623 return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i64, src);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 }
625 case ISD::ConstantPool: {
626 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
627 Constant *C = CP->getConstVal();
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000628 SDValue CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Dale Johannesen175fdef2009-02-06 21:50:26 +0000629 // FIXME there isn't really any debug info here
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000630
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000631 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, CPI,
632 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
633 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, CPI, Hi);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634 return Lo;
635 }
636 case ISD::GlobalTLSAddress:
Edwin Törökbd448e32009-07-14 16:55:14 +0000637 llvm_unreachable("TLS not implemented for Alpha.");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638 case ISD::GlobalAddress: {
639 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
640 GlobalValue *GV = GSDN->getGlobal();
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000641 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
Dale Johannesen175fdef2009-02-06 21:50:26 +0000642 // FIXME there isn't really any debug info here
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643
644 // if (!GV->hasWeakLinkage() && !GV->isDeclaration() && !GV->hasLinkOnceLinkage()) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000645 if (GV->hasLocalLinkage()) {
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000646 SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, dl, MVT::i64, GA,
647 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
648 SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, dl, MVT::i64, GA, Hi);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649 return Lo;
650 } else
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000651 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64, GA,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000652 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 }
Bill Wendlingfef06052008-09-16 21:48:12 +0000654 case ISD::ExternalSymbol: {
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000655 return DAG.getNode(AlphaISD::RelLit, dl, MVT::i64,
Bill Wendlingfef06052008-09-16 21:48:12 +0000656 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000657 ->getSymbol(), MVT::i64),
658 DAG.getGLOBAL_OFFSET_TABLE(MVT::i64));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659 }
Bill Wendlingfef06052008-09-16 21:48:12 +0000660
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661 case ISD::UREM:
662 case ISD::SREM:
663 //Expand only on constant case
664 if (Op.getOperand(1).getOpcode() == ISD::Constant) {
Owen Andersonac9de032009-08-10 22:56:29 +0000665 EVT VT = Op.getNode()->getValueType(0);
Gabor Greif1c80d112008-08-28 21:40:38 +0000666 SDValue Tmp1 = Op.getNode()->getOpcode() == ISD::UREM ?
667 BuildUDIV(Op.getNode(), DAG, NULL) :
668 BuildSDIV(Op.getNode(), DAG, NULL);
Dale Johannesen175fdef2009-02-06 21:50:26 +0000669 Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Op.getOperand(1));
670 Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Op.getOperand(0), Tmp1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000671 return Tmp1;
672 }
673 //fall through
674 case ISD::SDIV:
675 case ISD::UDIV:
Duncan Sands92c43912008-06-06 12:08:01 +0000676 if (Op.getValueType().isInteger()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 if (Op.getOperand(1).getOpcode() == ISD::Constant)
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000678 return Op.getOpcode() == ISD::SDIV ? BuildSDIV(Op.getNode(), DAG, NULL)
Gabor Greif1c80d112008-08-28 21:40:38 +0000679 : BuildUDIV(Op.getNode(), DAG, NULL);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 const char* opstr = 0;
681 switch (Op.getOpcode()) {
682 case ISD::UREM: opstr = "__remqu"; break;
683 case ISD::SREM: opstr = "__remq"; break;
684 case ISD::UDIV: opstr = "__divqu"; break;
685 case ISD::SDIV: opstr = "__divq"; break;
686 }
Dan Gohman8181bd12008-07-27 21:46:04 +0000687 SDValue Tmp1 = Op.getOperand(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 Tmp2 = Op.getOperand(1),
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000689 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
690 return DAG.getNode(AlphaISD::DivCall, dl, MVT::i64, Addr, Tmp1, Tmp2);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691 }
692 break;
693
694 case ISD::VAARG: {
Dan Gohman8181bd12008-07-27 21:46:04 +0000695 SDValue Chain, DataPtr;
Gabor Greif1c80d112008-08-28 21:40:38 +0000696 LowerVAARG(Op.getNode(), Chain, DataPtr, DAG);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697
Dan Gohman8181bd12008-07-27 21:46:04 +0000698 SDValue Result;
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000699 if (Op.getValueType() == MVT::i32)
700 Result = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Chain, DataPtr,
701 NULL, 0, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 else
Dale Johannesen3c4fb222009-02-04 02:34:38 +0000703 Result = DAG.getLoad(Op.getValueType(), dl, Chain, DataPtr, NULL, 0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 return Result;
705 }
706 case ISD::VACOPY: {
Dan Gohman8181bd12008-07-27 21:46:04 +0000707 SDValue Chain = Op.getOperand(0);
708 SDValue DestP = Op.getOperand(1);
709 SDValue SrcP = Op.getOperand(2);
Dan Gohman12a9c082008-02-06 22:27:42 +0000710 const Value *DestS = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
711 const Value *SrcS = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000712
Dale Johannesen3c4fb222009-02-04 02:34:38 +0000713 SDValue Val = DAG.getLoad(getPointerTy(), dl, Chain, SrcP, SrcS, 0);
714 SDValue Result = DAG.getStore(Val.getValue(1), dl, Val, DestP, DestS, 0);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000715 SDValue NP = DAG.getNode(ISD::ADD, dl, MVT::i64, SrcP,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000716 DAG.getConstant(8, MVT::i64));
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000717 Val = DAG.getExtLoad(ISD::SEXTLOAD, dl, MVT::i64, Result,
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000718 NP, NULL,0, MVT::i32);
719 SDValue NPD = DAG.getNode(ISD::ADD, dl, MVT::i64, DestP,
720 DAG.getConstant(8, MVT::i64));
721 return DAG.getTruncStore(Val.getValue(1), dl, Val, NPD, NULL, 0, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 }
723 case ISD::VASTART: {
Dan Gohman8181bd12008-07-27 21:46:04 +0000724 SDValue Chain = Op.getOperand(0);
725 SDValue VAListP = Op.getOperand(1);
Dan Gohman12a9c082008-02-06 22:27:42 +0000726 const Value *VAListS = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000727
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 // vastart stores the address of the VarArgsBase and VarArgsOffset
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000729 SDValue FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
Dale Johannesen3c4fb222009-02-04 02:34:38 +0000730 SDValue S1 = DAG.getStore(Chain, dl, FR, VAListP, VAListS, 0);
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000731 SDValue SA2 = DAG.getNode(ISD::ADD, dl, MVT::i64, VAListP,
732 DAG.getConstant(8, MVT::i64));
733 return DAG.getTruncStore(S1, dl, DAG.getConstant(VarArgsOffset, MVT::i64),
734 SA2, NULL, 0, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000735 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000736 case ISD::RETURNADDR:
Dale Johannesen24dd9a52009-02-07 00:55:49 +0000737 return DAG.getNode(AlphaISD::GlobalRetAddr, DebugLoc::getUnknownLoc(),
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000738 MVT::i64);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 //FIXME: implement
740 case ISD::FRAMEADDR: break;
741 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000742
Dan Gohman8181bd12008-07-27 21:46:04 +0000743 return SDValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744}
745
Duncan Sands7d9834b2008-12-01 11:39:25 +0000746void AlphaTargetLowering::ReplaceNodeResults(SDNode *N,
747 SmallVectorImpl<SDValue>&Results,
748 SelectionDAG &DAG) {
Dale Johannesenea996922009-02-04 20:06:27 +0000749 DebugLoc dl = N->getDebugLoc();
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000750 assert(N->getValueType(0) == MVT::i32 &&
Duncan Sandsac496a12008-07-04 11:47:58 +0000751 N->getOpcode() == ISD::VAARG &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752 "Unknown node to custom promote!");
Duncan Sandsac496a12008-07-04 11:47:58 +0000753
Dan Gohman8181bd12008-07-27 21:46:04 +0000754 SDValue Chain, DataPtr;
Duncan Sandsac496a12008-07-04 11:47:58 +0000755 LowerVAARG(N, Chain, DataPtr, DAG);
Dale Johannesenea996922009-02-04 20:06:27 +0000756 SDValue Res = DAG.getLoad(N->getValueType(0), dl, Chain, DataPtr, NULL, 0);
Duncan Sands7d9834b2008-12-01 11:39:25 +0000757 Results.push_back(Res);
758 Results.push_back(SDValue(Res.getNode(), 1));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000759}
760
761
762//Inline Asm
763
764/// getConstraintType - Given a constraint letter, return the type of
765/// constraint it is for this target.
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000766AlphaTargetLowering::ConstraintType
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767AlphaTargetLowering::getConstraintType(const std::string &Constraint) const {
768 if (Constraint.size() == 1) {
769 switch (Constraint[0]) {
770 default: break;
771 case 'f':
772 case 'r':
773 return C_RegisterClass;
774 }
775 }
776 return TargetLowering::getConstraintType(Constraint);
777}
778
779std::vector<unsigned> AlphaTargetLowering::
780getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersonac9de032009-08-10 22:56:29 +0000781 EVT VT) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 if (Constraint.size() == 1) {
783 switch (Constraint[0]) {
784 default: break; // Unknown constriant letter
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000785 case 'f':
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000786 return make_vector<unsigned>(Alpha::F0 , Alpha::F1 , Alpha::F2 ,
787 Alpha::F3 , Alpha::F4 , Alpha::F5 ,
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000788 Alpha::F6 , Alpha::F7 , Alpha::F8 ,
789 Alpha::F9 , Alpha::F10, Alpha::F11,
790 Alpha::F12, Alpha::F13, Alpha::F14,
791 Alpha::F15, Alpha::F16, Alpha::F17,
792 Alpha::F18, Alpha::F19, Alpha::F20,
793 Alpha::F21, Alpha::F22, Alpha::F23,
794 Alpha::F24, Alpha::F25, Alpha::F26,
795 Alpha::F27, Alpha::F28, Alpha::F29,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 Alpha::F30, Alpha::F31, 0);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000797 case 'r':
798 return make_vector<unsigned>(Alpha::R0 , Alpha::R1 , Alpha::R2 ,
799 Alpha::R3 , Alpha::R4 , Alpha::R5 ,
800 Alpha::R6 , Alpha::R7 , Alpha::R8 ,
801 Alpha::R9 , Alpha::R10, Alpha::R11,
802 Alpha::R12, Alpha::R13, Alpha::R14,
803 Alpha::R15, Alpha::R16, Alpha::R17,
804 Alpha::R18, Alpha::R19, Alpha::R20,
805 Alpha::R21, Alpha::R22, Alpha::R23,
806 Alpha::R24, Alpha::R25, Alpha::R26,
807 Alpha::R27, Alpha::R28, Alpha::R29,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 Alpha::R30, Alpha::R31, 0);
809 }
810 }
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000811
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812 return std::vector<unsigned>();
813}
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000814//===----------------------------------------------------------------------===//
815// Other Lowering Code
816//===----------------------------------------------------------------------===//
817
818MachineBasicBlock *
819AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Evan Chengd7dc9832009-09-18 21:02:19 +0000820 MachineBasicBlock *BB,
821 DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) const {
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000822 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
823 assert((MI->getOpcode() == Alpha::CAS32 ||
824 MI->getOpcode() == Alpha::CAS64 ||
825 MI->getOpcode() == Alpha::LAS32 ||
826 MI->getOpcode() == Alpha::LAS64 ||
827 MI->getOpcode() == Alpha::SWAP32 ||
828 MI->getOpcode() == Alpha::SWAP64) &&
829 "Unexpected instr type to insert");
830
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000831 bool is32 = MI->getOpcode() == Alpha::CAS32 ||
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000832 MI->getOpcode() == Alpha::LAS32 ||
833 MI->getOpcode() == Alpha::SWAP32;
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000834
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000835 //Load locked store conditional for atomic ops take on the same form
836 //start:
837 //ll
838 //do stuff (maybe branch to exit)
839 //sc
840 //test sc and maybe branck to start
841 //exit:
842 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dale Johannesen238c69d2009-02-13 02:30:42 +0000843 DebugLoc dl = MI->getDebugLoc();
Dan Gohman221a4372008-07-07 23:14:23 +0000844 MachineFunction::iterator It = BB;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000845 ++It;
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000846
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000847 MachineBasicBlock *thisMBB = BB;
Dan Gohman221a4372008-07-07 23:14:23 +0000848 MachineFunction *F = BB->getParent();
849 MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
850 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000851
Evan Cheng5f3a5402009-09-19 09:51:03 +0000852 // Inform sdisel of the edge changes.
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000853 for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
Evan Cheng5f3a5402009-09-19 09:51:03 +0000854 E = BB->succ_end(); I != E; ++I)
855 EM->insert(std::make_pair(*I, sinkMBB));
856
Dan Gohmanafc94df2008-06-21 20:21:19 +0000857 sinkMBB->transferSuccessors(thisMBB);
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000858
Dan Gohman221a4372008-07-07 23:14:23 +0000859 F->insert(It, llscMBB);
860 F->insert(It, sinkMBB);
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000861
Dale Johannesen238c69d2009-02-13 02:30:42 +0000862 BuildMI(thisMBB, dl, TII->get(Alpha::BR)).addMBB(llscMBB);
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000863
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000864 unsigned reg_res = MI->getOperand(0).getReg(),
865 reg_ptr = MI->getOperand(1).getReg(),
866 reg_v2 = MI->getOperand(2).getReg(),
867 reg_store = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
868
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000869 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::LDL_L : Alpha::LDQ_L),
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000870 reg_res).addImm(0).addReg(reg_ptr);
871 switch (MI->getOpcode()) {
872 case Alpha::CAS32:
873 case Alpha::CAS64: {
Daniel Dunbar3be44e62009-09-20 02:20:51 +0000874 unsigned reg_cmp
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000875 = F->getRegInfo().createVirtualRegister(&Alpha::GPRCRegClass);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000876 BuildMI(llscMBB, dl, TII->get(Alpha::CMPEQ), reg_cmp)
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000877 .addReg(reg_v2).addReg(reg_res);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000878 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000879 .addImm(0).addReg(reg_cmp).addMBB(sinkMBB);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000880 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000881 .addReg(Alpha::R31).addReg(MI->getOperand(3).getReg());
882 break;
883 }
884 case Alpha::LAS32:
885 case Alpha::LAS64: {
Dale Johannesen238c69d2009-02-13 02:30:42 +0000886 BuildMI(llscMBB, dl,TII->get(is32 ? Alpha::ADDLr : Alpha::ADDQr), reg_store)
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000887 .addReg(reg_res).addReg(reg_v2);
888 break;
889 }
890 case Alpha::SWAP32:
891 case Alpha::SWAP64: {
Dale Johannesen238c69d2009-02-13 02:30:42 +0000892 BuildMI(llscMBB, dl, TII->get(Alpha::BISr), reg_store)
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000893 .addReg(reg_v2).addReg(reg_v2);
894 break;
895 }
896 }
Dale Johannesen238c69d2009-02-13 02:30:42 +0000897 BuildMI(llscMBB, dl, TII->get(is32 ? Alpha::STL_C : Alpha::STQ_C), reg_store)
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000898 .addReg(reg_store).addImm(0).addReg(reg_ptr);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000899 BuildMI(llscMBB, dl, TII->get(Alpha::BEQ))
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000900 .addImm(0).addReg(reg_store).addMBB(llscMBB);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000901 BuildMI(llscMBB, dl, TII->get(Alpha::BR)).addMBB(sinkMBB);
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000902
903 thisMBB->addSuccessor(llscMBB);
904 llscMBB->addSuccessor(llscMBB);
905 llscMBB->addSuccessor(sinkMBB);
Dan Gohman221a4372008-07-07 23:14:23 +0000906 F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000907
908 return sinkMBB;
909}
Dan Gohman36322c72008-10-18 02:06:02 +0000910
911bool
912AlphaTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
913 // The Alpha target isn't yet aware of offsets.
914 return false;
915}
Evan Cheng6337b552009-10-27 19:56:55 +0000916
Evan Chenga0e67782009-10-28 01:43:28 +0000917bool AlphaTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
918 if (VT != MVT::f32 && VT != MVT::f64)
919 return false;
Evan Cheng6337b552009-10-27 19:56:55 +0000920 // +0.0 F31
921 // +0.0f F31
922 // -0.0 -F31
923 // -0.0f -F31
924 return Imm.isZero() || Imm.isNegZero();
925}