LLVM 23.0.0git
SparcISelLowering.cpp
Go to the documentation of this file.
1//===-- SparcISelLowering.cpp - Sparc DAG Lowering Implementation ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the interfaces that Sparc uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SparcISelLowering.h"
17#include "SparcRegisterInfo.h"
19#include "SparcTargetMachine.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/IRBuilder.h"
37#include "llvm/IR/Module.h"
40using namespace llvm;
41
42
43//===----------------------------------------------------------------------===//
44// Calling Convention Implementation
45//===----------------------------------------------------------------------===//
46
47static bool CC_Sparc_Assign_SRet(unsigned &ValNo, MVT &ValVT,
48 MVT &LocVT, CCValAssign::LocInfo &LocInfo,
49 ISD::ArgFlagsTy &ArgFlags, CCState &State)
50{
51 assert (ArgFlags.isSRet());
52
53 // Assign SRet argument.
54 State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
55 0,
56 LocVT, LocInfo));
57 return true;
58}
59
60static bool CC_Sparc_Assign_Split_64(unsigned &ValNo, MVT &ValVT,
61 MVT &LocVT, CCValAssign::LocInfo &LocInfo,
62 ISD::ArgFlagsTy &ArgFlags, CCState &State)
63{
64 static const MCPhysReg RegList[] = {
65 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
66 };
67 // Try to get first reg.
68 if (Register Reg = State.AllocateReg(RegList)) {
69 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
70 } else {
71 // Assign whole thing in stack.
72 State.addLoc(CCValAssign::getCustomMem(
73 ValNo, ValVT, State.AllocateStack(8, Align(4)), LocVT, LocInfo));
74 return true;
75 }
76
77 // Try to get second reg.
78 if (Register Reg = State.AllocateReg(RegList))
79 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
80 else
81 State.addLoc(CCValAssign::getCustomMem(
82 ValNo, ValVT, State.AllocateStack(4, Align(4)), LocVT, LocInfo));
83 return true;
84}
85
86static bool CC_Sparc_Assign_Ret_Split_64(unsigned &ValNo, MVT &ValVT,
87 MVT &LocVT, CCValAssign::LocInfo &LocInfo,
88 ISD::ArgFlagsTy &ArgFlags, CCState &State)
89{
90 static const MCPhysReg RegList[] = {
91 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
92 };
93
94 // Try to get first reg.
95 if (Register Reg = State.AllocateReg(RegList))
96 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
97 else
98 return false;
99
100 // Try to get second reg.
101 if (Register Reg = State.AllocateReg(RegList))
102 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
103 else
104 return false;
105
106 return true;
107}
108
109// Allocate a full-sized argument for the 64-bit ABI.
110static bool Analyze_CC_Sparc64_Full(bool IsReturn, unsigned &ValNo, MVT &ValVT,
111 MVT &LocVT, CCValAssign::LocInfo &LocInfo,
112 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
113 assert((LocVT == MVT::f32 || LocVT == MVT::f128
114 || LocVT.getSizeInBits() == 64) &&
115 "Can't handle non-64 bits locations");
116
117 // Stack space is allocated for all arguments starting from [%fp+BIAS+128].
118 unsigned size = (LocVT == MVT::f128) ? 16 : 8;
119 Align alignment =
120 (LocVT == MVT::f128 || ArgFlags.isSplit()) ? Align(16) : Align(8);
121 unsigned Offset = State.AllocateStack(size, alignment);
122 unsigned Reg = 0;
123
124 if (LocVT == MVT::i64 && Offset < 6*8)
125 // Promote integers to %i0-%i5.
126 Reg = SP::I0 + Offset/8;
127 else if (LocVT == MVT::f64 && Offset < 16*8)
128 // Promote doubles to %d0-%d30. (Which LLVM calls D0-D15).
129 Reg = SP::D0 + Offset/8;
130 else if (LocVT == MVT::f32 && Offset < 16*8)
131 // Promote floats to %f1, %f3, ...
132 Reg = SP::F1 + Offset/4;
133 else if (LocVT == MVT::f128 && Offset < 16*8)
134 // Promote long doubles to %q0-%q28. (Which LLVM calls Q0-Q7).
135 Reg = SP::Q0 + Offset/16;
136
137 // Promote to register when possible, otherwise use the stack slot.
138 if (Reg) {
139 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
140 return true;
141 }
142
143 // Bail out if this is a return CC and we run out of registers to place
144 // values into.
145 if (IsReturn)
146 return false;
147
148 // This argument goes on the stack in an 8-byte slot.
149 // When passing floats, LocVT is smaller than 8 bytes. Adjust the offset to
150 // the right-aligned float. The first 4 bytes of the stack slot are undefined.
151 if (LocVT == MVT::f32)
152 Offset += 4;
153
154 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
155 return true;
156}
157
158// Allocate a half-sized argument for the 64-bit ABI.
159//
160// This is used when passing { float, int } structs by value in registers.
161static bool Analyze_CC_Sparc64_Half(bool IsReturn, unsigned &ValNo, MVT &ValVT,
162 MVT &LocVT, CCValAssign::LocInfo &LocInfo,
163 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
164 assert(LocVT.getSizeInBits() == 32 && "Can't handle non-32 bits locations");
165 unsigned Offset = State.AllocateStack(4, Align(4));
166
167 if (LocVT == MVT::f32 && Offset < 16*8) {
168 // Promote floats to %f0-%f31.
169 State.addLoc(CCValAssign::getReg(ValNo, ValVT, SP::F0 + Offset/4,
170 LocVT, LocInfo));
171 return true;
172 }
173
174 if (LocVT == MVT::i32 && Offset < 6*8) {
175 // Promote integers to %i0-%i5, using half the register.
176 unsigned Reg = SP::I0 + Offset/8;
177 LocVT = MVT::i64;
178 LocInfo = CCValAssign::AExt;
179
180 // Set the Custom bit if this i32 goes in the high bits of a register.
181 if (Offset % 8 == 0)
182 State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg,
183 LocVT, LocInfo));
184 else
185 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
186 return true;
187 }
188
189 // Bail out if this is a return CC and we run out of registers to place
190 // values into.
191 if (IsReturn)
192 return false;
193
194 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
195 return true;
196}
197
198static bool CC_Sparc64_Full(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
199 CCValAssign::LocInfo &LocInfo,
200 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
201 return Analyze_CC_Sparc64_Full(false, ValNo, ValVT, LocVT, LocInfo, ArgFlags,
202 State);
203}
204
205static bool CC_Sparc64_Half(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
206 CCValAssign::LocInfo &LocInfo,
207 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
208 return Analyze_CC_Sparc64_Half(false, ValNo, ValVT, LocVT, LocInfo, ArgFlags,
209 State);
210}
211
212static bool RetCC_Sparc64_Full(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
213 CCValAssign::LocInfo &LocInfo,
214 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
215 return Analyze_CC_Sparc64_Full(true, ValNo, ValVT, LocVT, LocInfo, ArgFlags,
216 State);
217}
218
219static bool RetCC_Sparc64_Half(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
220 CCValAssign::LocInfo &LocInfo,
221 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
222 return Analyze_CC_Sparc64_Half(true, ValNo, ValVT, LocVT, LocInfo, ArgFlags,
223 State);
224}
225
226#include "SparcGenCallingConv.inc"
227
228// The calling conventions in SparcCallingConv.td are described in terms of the
229// callee's register window. This function translates registers to the
230// corresponding caller window %o register.
231static unsigned toCallerWindow(unsigned Reg) {
232 static_assert(SP::I0 + 7 == SP::I7 && SP::O0 + 7 == SP::O7,
233 "Unexpected enum");
234 if (Reg >= SP::I0 && Reg <= SP::I7)
235 return Reg - SP::I0 + SP::O0;
236 return Reg;
237}
238
240 CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
241 const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
242 const Type *RetTy) const {
244 CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
245 return CCInfo.CheckReturn(Outs, Subtarget->is64Bit() ? RetCC_Sparc64
246 : RetCC_Sparc32);
247}
248
251 bool IsVarArg,
253 const SmallVectorImpl<SDValue> &OutVals,
254 const SDLoc &DL, SelectionDAG &DAG) const {
255 if (Subtarget->is64Bit())
256 return LowerReturn_64(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
257 return LowerReturn_32(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
258}
259
262 bool IsVarArg,
264 const SmallVectorImpl<SDValue> &OutVals,
265 const SDLoc &DL, SelectionDAG &DAG) const {
267
268 // CCValAssign - represent the assignment of the return value to locations.
270
271 // CCState - Info about the registers and stack slot.
272 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
273 *DAG.getContext());
274
275 // Analyze return values.
276 CCInfo.AnalyzeReturn(Outs, RetCC_Sparc32);
277
278 SDValue Glue;
279 SmallVector<SDValue, 4> RetOps(1, Chain);
280 // Make room for the return address offset.
281 RetOps.push_back(SDValue());
282
283 // Copy the result values into the output registers.
284 for (unsigned i = 0, realRVLocIdx = 0;
285 i != RVLocs.size();
286 ++i, ++realRVLocIdx) {
287 CCValAssign &VA = RVLocs[i];
288 assert(VA.isRegLoc() && "Can only return in registers!");
289
290 SDValue Arg = OutVals[realRVLocIdx];
291
292 if (VA.needsCustom()) {
293 assert(VA.getLocVT() == MVT::v2i32);
294 // Legalize ret v2i32 -> ret 2 x i32 (Basically: do what would
295 // happen by default if this wasn't a legal type)
296
297 SDValue Part0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32,
298 Arg,
300 SDValue Part1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32,
301 Arg,
303
304 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part0, Glue);
305 Glue = Chain.getValue(1);
306 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
307 VA = RVLocs[++i]; // skip ahead to next loc
308 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part1,
309 Glue);
310 } else
311 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Arg, Glue);
312
313 // Guarantee that all emitted copies are stuck together with flags.
314 Glue = Chain.getValue(1);
315 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
316 }
317
318 unsigned RetAddrOffset = 8; // Call Inst + Delay Slot
319 // If the function returns a struct, copy the SRetReturnReg to I0
320 if (MF.getFunction().hasStructRetAttr()) {
322 Register Reg = SFI->getSRetReturnReg();
323 if (!Reg)
324 llvm_unreachable("sret virtual register not created in the entry block");
325 auto PtrVT = getPointerTy(DAG.getDataLayout());
326 SDValue Val = DAG.getCopyFromReg(Chain, DL, Reg, PtrVT);
327 Chain = DAG.getCopyToReg(Chain, DL, SP::I0, Val, Glue);
328 Glue = Chain.getValue(1);
329 RetOps.push_back(DAG.getRegister(SP::I0, PtrVT));
330 RetAddrOffset = 12; // CallInst + Delay Slot + Unimp
331 }
332
333 RetOps[0] = Chain; // Update chain.
334 RetOps[1] = DAG.getConstant(RetAddrOffset, DL, MVT::i32);
335
336 // Add the glue if we have it.
337 if (Glue.getNode())
338 RetOps.push_back(Glue);
339
340 return DAG.getNode(SPISD::RET_GLUE, DL, MVT::Other, RetOps);
341}
342
343// Lower return values for the 64-bit ABI.
344// Return values are passed the exactly the same way as function arguments.
347 bool IsVarArg,
349 const SmallVectorImpl<SDValue> &OutVals,
350 const SDLoc &DL, SelectionDAG &DAG) const {
351 // CCValAssign - represent the assignment of the return value to locations.
353
354 // CCState - Info about the registers and stack slot.
355 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
356 *DAG.getContext());
357
358 // Analyze return values.
359 CCInfo.AnalyzeReturn(Outs, RetCC_Sparc64);
360
361 SDValue Glue;
362 SmallVector<SDValue, 4> RetOps(1, Chain);
363
364 // The second operand on the return instruction is the return address offset.
365 // The return address is always %i7+8 with the 64-bit ABI.
366 RetOps.push_back(DAG.getConstant(8, DL, MVT::i32));
367
368 // Copy the result values into the output registers.
369 for (unsigned i = 0; i != RVLocs.size(); ++i) {
370 CCValAssign &VA = RVLocs[i];
371 assert(VA.isRegLoc() && "Can only return in registers!");
372 SDValue OutVal = OutVals[i];
373
374 // Integer return values must be sign or zero extended by the callee.
375 switch (VA.getLocInfo()) {
376 case CCValAssign::Full: break;
378 OutVal = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), OutVal);
379 break;
381 OutVal = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), OutVal);
382 break;
384 OutVal = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), OutVal);
385 break;
386 default:
387 llvm_unreachable("Unknown loc info!");
388 }
389
390 // The custom bit on an i32 return value indicates that it should be passed
391 // in the high bits of the register.
392 if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
393 OutVal = DAG.getNode(ISD::SHL, DL, MVT::i64, OutVal,
394 DAG.getConstant(32, DL, MVT::i32));
395
396 // The next value may go in the low bits of the same register.
397 // Handle both at once.
398 if (i+1 < RVLocs.size() && RVLocs[i+1].getLocReg() == VA.getLocReg()) {
399 SDValue NV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, OutVals[i+1]);
400 OutVal = DAG.getNode(ISD::OR, DL, MVT::i64, OutVal, NV);
401 // Skip the next value, it's already done.
402 ++i;
403 }
404 }
405
406 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), OutVal, Glue);
407
408 // Guarantee that all emitted copies are stuck together with flags.
409 Glue = Chain.getValue(1);
410 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
411 }
412
413 RetOps[0] = Chain; // Update chain.
414
415 // Add the flag if we have it.
416 if (Glue.getNode())
417 RetOps.push_back(Glue);
418
419 return DAG.getNode(SPISD::RET_GLUE, DL, MVT::Other, RetOps);
420}
421
423 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
424 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
425 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
426 if (Subtarget->is64Bit())
427 return LowerFormalArguments_64(Chain, CallConv, IsVarArg, Ins,
428 DL, DAG, InVals);
429 return LowerFormalArguments_32(Chain, CallConv, IsVarArg, Ins,
430 DL, DAG, InVals);
431}
432
433/// LowerFormalArguments32 - V8 uses a very simple ABI, where all values are
434/// passed in either one or two GPRs, including FP values. TODO: we should
435/// pass FP values in FP registers for fastcc functions.
437 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
438 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
439 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
441 MachineRegisterInfo &RegInfo = MF.getRegInfo();
443 EVT PtrVT = getPointerTy(DAG.getDataLayout());
444
445 // Assign locations to all of the incoming arguments.
447 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
448 *DAG.getContext());
449 CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc32);
450
451 const unsigned StackOffset = 92;
452 bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
453
454 unsigned InIdx = 0;
455 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i, ++InIdx) {
456 CCValAssign &VA = ArgLocs[i];
457 EVT LocVT = VA.getLocVT();
458
459 if (Ins[InIdx].Flags.isSRet()) {
460 if (InIdx != 0)
461 report_fatal_error("sparc only supports sret on the first parameter");
462 // Get SRet from [%fp+64].
463 int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, 64, true);
464 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
465 SDValue Arg =
466 DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
467 InVals.push_back(Arg);
468 continue;
469 }
470
471 SDValue Arg;
472 if (VA.isRegLoc()) {
473 if (VA.needsCustom()) {
474 assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
475
476 Register VRegHi = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
477 MF.getRegInfo().addLiveIn(VA.getLocReg(), VRegHi);
478 SDValue HiVal = DAG.getCopyFromReg(Chain, dl, VRegHi, MVT::i32);
479
480 assert(i+1 < e);
481 CCValAssign &NextVA = ArgLocs[++i];
482
483 SDValue LoVal;
484 if (NextVA.isMemLoc()) {
485 int FrameIdx = MF.getFrameInfo().
486 CreateFixedObject(4, StackOffset+NextVA.getLocMemOffset(),true);
487 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
488 LoVal = DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
489 } else {
490 Register loReg = MF.addLiveIn(NextVA.getLocReg(),
491 &SP::IntRegsRegClass);
492 LoVal = DAG.getCopyFromReg(Chain, dl, loReg, MVT::i32);
493 }
494
495 if (IsLittleEndian)
496 std::swap(LoVal, HiVal);
497
498 SDValue WholeValue =
499 DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
500 WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), WholeValue);
501 InVals.push_back(WholeValue);
502 continue;
503 }
504 Register VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
505 MF.getRegInfo().addLiveIn(VA.getLocReg(), VReg);
506 Arg = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32);
507 if (VA.getLocInfo() != CCValAssign::Indirect) {
508 if (VA.getLocVT() == MVT::f32)
509 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Arg);
510 else if (VA.getLocVT() != MVT::i32) {
511 Arg = DAG.getNode(ISD::AssertSext, dl, MVT::i32, Arg,
512 DAG.getValueType(VA.getLocVT()));
513 Arg = DAG.getNode(ISD::TRUNCATE, dl, VA.getLocVT(), Arg);
514 }
515 InVals.push_back(Arg);
516 continue;
517 }
518 } else {
519 assert(VA.isMemLoc());
520
521 unsigned Offset = VA.getLocMemOffset() + StackOffset;
522
523 if (VA.needsCustom()) {
524 assert(VA.getValVT() == MVT::f64 || VA.getValVT() == MVT::v2i32);
525 // If it is double-word aligned, just load.
526 if (Offset % 8 == 0) {
527 int FI = MF.getFrameInfo().CreateFixedObject(8, Offset, true);
528 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
529 SDValue Load = DAG.getLoad(VA.getValVT(), dl, Chain, FIPtr,
531 InVals.push_back(Load);
532 continue;
533 }
534
535 int FI = MF.getFrameInfo().CreateFixedObject(4, Offset, true);
536 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
537 SDValue HiVal =
538 DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
539 int FI2 = MF.getFrameInfo().CreateFixedObject(4, Offset + 4, true);
540 SDValue FIPtr2 = DAG.getFrameIndex(FI2, PtrVT);
541
542 SDValue LoVal =
543 DAG.getLoad(MVT::i32, dl, Chain, FIPtr2, MachinePointerInfo());
544
545 if (IsLittleEndian)
546 std::swap(LoVal, HiVal);
547
548 SDValue WholeValue =
549 DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
550 WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), WholeValue);
551 InVals.push_back(WholeValue);
552 continue;
553 }
554
555 int FI = MF.getFrameInfo().CreateFixedObject(LocVT.getSizeInBits() / 8,
556 Offset, true);
557 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
558 SDValue Load = DAG.getLoad(LocVT, dl, Chain, FIPtr,
560 if (VA.getLocInfo() != CCValAssign::Indirect) {
561 InVals.push_back(Load);
562 continue;
563 }
564 Arg = Load;
565 }
566
568
569 SDValue ArgValue =
570 DAG.getLoad(VA.getValVT(), dl, Chain, Arg, MachinePointerInfo());
571 InVals.push_back(ArgValue);
572
573 unsigned ArgIndex = Ins[InIdx].OrigArgIndex;
574 assert(Ins[InIdx].PartOffset == 0);
575 while (i + 1 != e && Ins[InIdx + 1].OrigArgIndex == ArgIndex) {
576 CCValAssign &PartVA = ArgLocs[i + 1];
577 unsigned PartOffset = Ins[InIdx + 1].PartOffset;
579 ArgValue, TypeSize::getFixed(PartOffset), dl);
580 InVals.push_back(DAG.getLoad(PartVA.getValVT(), dl, Chain, Address,
582 ++i;
583 ++InIdx;
584 }
585 }
586
587 if (MF.getFunction().hasStructRetAttr()) {
588 // Copy the SRet Argument to SRetReturnReg.
590 Register Reg = SFI->getSRetReturnReg();
591 if (!Reg) {
592 Reg = MF.getRegInfo().createVirtualRegister(&SP::IntRegsRegClass);
593 SFI->setSRetReturnReg(Reg);
594 }
595 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]);
596 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
597 }
598
599 // Store remaining ArgRegs to the stack if this is a varargs function.
600 if (isVarArg) {
601 static const MCPhysReg ArgRegs[] = {
602 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
603 };
604 unsigned NumAllocated = CCInfo.getFirstUnallocated(ArgRegs);
605 const MCPhysReg *CurArgReg = ArgRegs+NumAllocated, *ArgRegEnd = ArgRegs+6;
606 unsigned ArgOffset = CCInfo.getStackSize();
607 if (NumAllocated == 6)
608 ArgOffset += StackOffset;
609 else {
610 assert(!ArgOffset);
611 ArgOffset = 68+4*NumAllocated;
612 }
613
614 // Remember the vararg offset for the va_start implementation.
615 FuncInfo->setVarArgsFrameOffset(ArgOffset);
616
617 std::vector<SDValue> OutChains;
618
619 for (; CurArgReg != ArgRegEnd; ++CurArgReg) {
620 Register VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
621 MF.getRegInfo().addLiveIn(*CurArgReg, VReg);
622 SDValue Arg = DAG.getCopyFromReg(DAG.getRoot(), dl, VReg, MVT::i32);
623
624 int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, ArgOffset,
625 true);
626 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
627
628 OutChains.push_back(
629 DAG.getStore(DAG.getRoot(), dl, Arg, FIPtr, MachinePointerInfo()));
630 ArgOffset += 4;
631 }
632
633 if (!OutChains.empty()) {
634 OutChains.push_back(Chain);
635 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
636 }
637 }
638
639 return Chain;
640}
641
642// Lower formal arguments for the 64 bit ABI.
644 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
645 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
646 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
648
649 // Analyze arguments according to CC_Sparc64.
651 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
652 *DAG.getContext());
653 CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc64);
654
655 // The argument array begins at %fp+BIAS+128, after the register save area.
656 const unsigned ArgArea = 128;
657
658 for (const CCValAssign &VA : ArgLocs) {
659 if (VA.isRegLoc()) {
660 // This argument is passed in a register.
661 // All integer register arguments are promoted by the caller to i64.
662
663 // Create a virtual register for the promoted live-in value.
664 Register VReg = MF.addLiveIn(VA.getLocReg(),
665 getRegClassFor(VA.getLocVT()));
666 SDValue Arg = DAG.getCopyFromReg(Chain, DL, VReg, VA.getLocVT());
667
668 // Get the high bits for i32 struct elements.
669 if (VA.getValVT() == MVT::i32 && VA.needsCustom())
670 Arg = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), Arg,
671 DAG.getConstant(32, DL, MVT::i32));
672
673 // The caller promoted the argument, so insert an Assert?ext SDNode so we
674 // won't promote the value again in this function.
675 switch (VA.getLocInfo()) {
677 Arg = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), Arg,
678 DAG.getValueType(VA.getValVT()));
679 break;
681 Arg = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), Arg,
682 DAG.getValueType(VA.getValVT()));
683 break;
684 default:
685 break;
686 }
687
688 // Truncate the register down to the argument type.
689 if (VA.isExtInLoc())
690 Arg = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Arg);
691
692 InVals.push_back(Arg);
693 continue;
694 }
695
696 // The registers are exhausted. This argument was passed on the stack.
697 assert(VA.isMemLoc());
698 // The CC_Sparc64_Full/Half functions compute stack offsets relative to the
699 // beginning of the arguments area at %fp+BIAS+128.
700 unsigned Offset = VA.getLocMemOffset() + ArgArea;
701 unsigned ValSize = VA.getValVT().getSizeInBits() / 8;
702 // Adjust offset for extended arguments, SPARC is big-endian.
703 // The caller will have written the full slot with extended bytes, but we
704 // prefer our own extending loads.
705 if (VA.isExtInLoc())
706 Offset += 8 - ValSize;
707 int FI = MF.getFrameInfo().CreateFixedObject(ValSize, Offset, true);
708 InVals.push_back(
709 DAG.getLoad(VA.getValVT(), DL, Chain,
712 }
713
714 if (!IsVarArg)
715 return Chain;
716
717 // This function takes variable arguments, some of which may have been passed
718 // in registers %i0-%i5. Variable floating point arguments are never passed
719 // in floating point registers. They go on %i0-%i5 or on the stack like
720 // integer arguments.
721 //
722 // The va_start intrinsic needs to know the offset to the first variable
723 // argument.
724 unsigned ArgOffset = CCInfo.getStackSize();
726 // Skip the 128 bytes of register save area.
727 FuncInfo->setVarArgsFrameOffset(ArgOffset + ArgArea +
728 Subtarget->getStackPointerBias());
729
730 // Save the variable arguments that were passed in registers.
731 // The caller is required to reserve stack space for 6 arguments regardless
732 // of how many arguments were actually passed.
733 SmallVector<SDValue, 8> OutChains;
734 for (; ArgOffset < 6*8; ArgOffset += 8) {
735 Register VReg = MF.addLiveIn(SP::I0 + ArgOffset/8, &SP::I64RegsRegClass);
736 SDValue VArg = DAG.getCopyFromReg(Chain, DL, VReg, MVT::i64);
737 int FI = MF.getFrameInfo().CreateFixedObject(8, ArgOffset + ArgArea, true);
738 auto PtrVT = getPointerTy(MF.getDataLayout());
739 OutChains.push_back(
740 DAG.getStore(Chain, DL, VArg, DAG.getFrameIndex(FI, PtrVT),
742 }
743
744 if (!OutChains.empty())
745 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
746
747 return Chain;
748}
749
750// Check whether any of the argument registers are reserved
752 const MachineFunction &MF) {
753 // The register window design means that outgoing parameters at O*
754 // will appear in the callee as I*.
755 // Be conservative and check both sides of the register names.
756 bool Outgoing =
757 llvm::any_of(SP::GPROutgoingArgRegClass, [TRI, &MF](MCPhysReg r) {
758 return TRI->isReservedReg(MF, r);
759 });
760 bool Incoming =
761 llvm::any_of(SP::GPRIncomingArgRegClass, [TRI, &MF](MCPhysReg r) {
762 return TRI->isReservedReg(MF, r);
763 });
764 return Outgoing || Incoming;
765}
766
768 const Function &F = MF.getFunction();
769 F.getContext().diagnose(DiagnosticInfoUnsupported{
770 F, ("SPARC doesn't support"
771 " function calls if any of the argument registers is reserved.")});
772}
773
776 SmallVectorImpl<SDValue> &InVals) const {
777 if (Subtarget->is64Bit())
778 return LowerCall_64(CLI, InVals);
779 return LowerCall_32(CLI, InVals);
780}
781
782static bool hasReturnsTwiceAttr(SelectionDAG &DAG, SDValue Callee,
783 const CallBase *Call) {
784 if (Call)
785 return Call->hasFnAttr(Attribute::ReturnsTwice);
786
787 const Function *CalleeFn = nullptr;
789 CalleeFn = dyn_cast<Function>(G->getGlobal());
790 } else if (ExternalSymbolSDNode *E =
792 const Function &Fn = DAG.getMachineFunction().getFunction();
793 const Module *M = Fn.getParent();
794 const char *CalleeName = E->getSymbol();
795 CalleeFn = M->getFunction(CalleeName);
796 }
797
798 if (!CalleeFn)
799 return false;
800 return CalleeFn->hasFnAttribute(Attribute::ReturnsTwice);
801}
802
803/// IsEligibleForTailCallOptimization - Check whether the call is eligible
804/// for tail call optimization.
806 CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF) const {
807
808 auto &Outs = CLI.Outs;
809 auto &Caller = MF.getFunction();
810
811 // Do not tail call opt functions with "disable-tail-calls" attribute.
812 if (Caller.getFnAttribute("disable-tail-calls").getValueAsString() == "true")
813 return false;
814
815 // Do not tail call opt if the stack is used to pass parameters.
816 // 64-bit targets have a slightly higher limit since the ABI requires
817 // to allocate some space even when all the parameters fit inside registers.
818 unsigned StackSizeLimit = Subtarget->is64Bit() ? 48 : 0;
819 if (CCInfo.getStackSize() > StackSizeLimit)
820 return false;
821
822 // Do not tail call opt if either the callee or caller returns
823 // a struct and the other does not.
824 if (!Outs.empty() && Caller.hasStructRetAttr() != Outs[0].Flags.isSRet())
825 return false;
826
827 // Byval parameters hand the function a pointer directly into the stack area
828 // we want to reuse during a tail call.
829 for (auto &Arg : Outs)
830 if (Arg.Flags.isByVal())
831 return false;
832
833 return true;
834}
835
836// Lower a call for the 32-bit ABI.
839 SmallVectorImpl<SDValue> &InVals) const {
840 SelectionDAG &DAG = CLI.DAG;
841 SDLoc &dl = CLI.DL;
843 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
845 SDValue Chain = CLI.Chain;
846 SDValue Callee = CLI.Callee;
847 bool &isTailCall = CLI.IsTailCall;
848 CallingConv::ID CallConv = CLI.CallConv;
849 bool isVarArg = CLI.IsVarArg;
851 LLVMContext &Ctx = *DAG.getContext();
852 EVT PtrVT = getPointerTy(MF.getDataLayout());
853
854 // Analyze operands of the call, assigning locations to each operand.
856 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
857 *DAG.getContext());
858 CCInfo.AnalyzeCallOperands(Outs, CC_Sparc32);
859
860 isTailCall = isTailCall && IsEligibleForTailCallOptimization(
861 CCInfo, CLI, DAG.getMachineFunction());
862
863 // Get the size of the outgoing arguments stack space requirement.
864 unsigned ArgsSize = CCInfo.getStackSize();
865
866 // Keep stack frames 8-byte aligned.
867 ArgsSize = (ArgsSize+7) & ~7;
868
870
871 // Create local copies for byval args.
872 SmallVector<SDValue, 8> ByValArgs;
873 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
874 ISD::ArgFlagsTy Flags = Outs[i].Flags;
875 if (!Flags.isByVal())
876 continue;
877
878 SDValue Arg = OutVals[i];
879 unsigned Size = Flags.getByValSize();
880 Align Alignment = Flags.getNonZeroByValAlign();
881
882 if (Size > 0U) {
883 int FI = MFI.CreateStackObject(Size, Alignment, false);
884 SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
885 SDValue SizeNode = DAG.getConstant(Size, dl, MVT::i32);
886
887 Chain =
888 DAG.getMemcpy(Chain, dl, FIPtr, Arg, SizeNode, Alignment, Alignment,
889 false, // isVolatile,
890 (Size <= 32), // AlwaysInline if size <= 32,
891 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(),
893 ByValArgs.push_back(FIPtr);
894 }
895 else {
896 SDValue nullVal;
897 ByValArgs.push_back(nullVal);
898 }
899 }
900
901 assert(!isTailCall || ArgsSize == 0);
902
903 if (!isTailCall)
904 Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, dl);
905
907 SmallVector<SDValue, 8> MemOpChains;
908
909 const unsigned StackOffset = 92;
910 bool hasStructRetAttr = false;
911 unsigned SRetArgSize = 0;
912 // Walk the register/memloc assignments, inserting copies/loads.
913 for (unsigned i = 0, realArgIdx = 0, byvalArgIdx = 0, e = ArgLocs.size();
914 i != e;
915 ++i, ++realArgIdx) {
916 CCValAssign &VA = ArgLocs[i];
917 SDValue Arg = OutVals[realArgIdx];
918
919 ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
920
921 // Use local copy if it is a byval arg.
922 if (Flags.isByVal()) {
923 Arg = ByValArgs[byvalArgIdx++];
924 if (!Arg) {
925 continue;
926 }
927 }
928
929 // Promote the value if needed.
930 switch (VA.getLocInfo()) {
931 default: llvm_unreachable("Unknown loc info!");
934 break;
936 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
937 break;
939 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
940 break;
942 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
943 break;
945 Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg);
946 break;
947 }
948
949 if (Flags.isSRet()) {
950 assert(VA.needsCustom());
951
952 if (isTailCall)
953 continue;
954
955 // store SRet argument in %sp+64
956 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
957 SDValue PtrOff = DAG.getIntPtrConstant(64, dl);
958 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
959 MemOpChains.push_back(
960 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
961 hasStructRetAttr = true;
962 // sret only allowed on first argument
963 assert(Outs[realArgIdx].OrigArgIndex == 0);
964 SRetArgSize =
965 DAG.getDataLayout().getTypeAllocSize(CLI.getArgs()[0].IndirectType);
966 continue;
967 }
968
969 if (VA.needsCustom()) {
970 assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
971
972 if (VA.isMemLoc()) {
973 unsigned Offset = VA.getLocMemOffset() + StackOffset;
974 // if it is double-word aligned, just store.
975 if (Offset % 8 == 0) {
976 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
977 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
978 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
979 MemOpChains.push_back(
980 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
981 continue;
982 }
983 }
984
985 if (VA.getLocVT() == MVT::f64) {
986 // Move from the float value from float registers into the
987 // integer registers.
989 Arg = bitcastConstantFPToInt(C, dl, DAG);
990 else
991 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, Arg);
992 }
993
994 SDValue Part0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32,
995 Arg,
996 DAG.getConstant(0, dl, getVectorIdxTy(DAG.getDataLayout())));
997 SDValue Part1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32,
998 Arg,
999 DAG.getConstant(1, dl, getVectorIdxTy(DAG.getDataLayout())));
1000
1001 if (VA.isRegLoc()) {
1002 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Part0));
1003 assert(i+1 != e);
1004 CCValAssign &NextVA = ArgLocs[++i];
1005 if (NextVA.isRegLoc()) {
1006 RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), Part1));
1007 } else {
1008 // Store the second part in stack.
1009 unsigned Offset = NextVA.getLocMemOffset() + StackOffset;
1010 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1011 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
1012 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1013 MemOpChains.push_back(
1014 DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
1015 }
1016 } else {
1017 unsigned Offset = VA.getLocMemOffset() + StackOffset;
1018 // Store the first part.
1019 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1020 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
1021 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1022 MemOpChains.push_back(
1023 DAG.getStore(Chain, dl, Part0, PtrOff, MachinePointerInfo()));
1024 // Store the second part.
1025 PtrOff = DAG.getIntPtrConstant(Offset + 4, dl);
1026 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1027 MemOpChains.push_back(
1028 DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
1029 }
1030 continue;
1031 }
1032
1033 if (VA.getLocInfo() == CCValAssign::Indirect) {
1034 // Store the argument in a stack slot and pass its address.
1035 unsigned ArgIndex = Outs[realArgIdx].OrigArgIndex;
1036 assert(Outs[realArgIdx].PartOffset == 0);
1037
1038 EVT SlotVT;
1039 if (i + 1 != e && Outs[realArgIdx + 1].OrigArgIndex == ArgIndex) {
1040 Type *OrigArgType = CLI.Args[ArgIndex].Ty;
1041 EVT OrigArgVT = getValueType(MF.getDataLayout(), OrigArgType);
1042 MVT PartVT =
1043 getRegisterTypeForCallingConv(Ctx, CLI.CallConv, OrigArgVT);
1044 unsigned N =
1045 getNumRegistersForCallingConv(Ctx, CLI.CallConv, OrigArgVT);
1046 SlotVT = EVT::getIntegerVT(Ctx, PartVT.getSizeInBits() * N);
1047 } else {
1048 SlotVT = Outs[realArgIdx].VT;
1049 }
1050
1051 SDValue SpillSlot = DAG.CreateStackTemporary(SlotVT);
1052 int FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
1053 MemOpChains.push_back(
1054 DAG.getStore(Chain, dl, Arg, SpillSlot,
1056 // If the original argument was split (e.g. f128), we need
1057 // to store all parts of it here (and pass just one address).
1058 while (i + 1 != e && Outs[realArgIdx + 1].OrigArgIndex == ArgIndex) {
1059 SDValue PartValue = OutVals[realArgIdx + 1];
1060 unsigned PartOffset = Outs[realArgIdx + 1].PartOffset;
1062 DAG.getFrameIndex(FI, PtrVT), TypeSize::getFixed(PartOffset), dl);
1063 MemOpChains.push_back(
1064 DAG.getStore(Chain, dl, PartValue, Address,
1066 assert((PartOffset + PartValue.getValueType().getStoreSize() <=
1067 SlotVT.getStoreSize()) &&
1068 "Not enough space for argument part!");
1069 ++i;
1070 ++realArgIdx;
1071 }
1072
1073 Arg = SpillSlot;
1074 }
1075
1076 // Arguments that can be passed on register must be kept at
1077 // RegsToPass vector
1078 if (VA.isRegLoc()) {
1079 if (VA.getLocVT() != MVT::f32) {
1080 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
1081 continue;
1082 }
1083 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg);
1084 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
1085 continue;
1086 }
1087
1088 assert(VA.isMemLoc());
1089
1090 // Create a store off the stack pointer for this argument.
1091 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1093 dl);
1094 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1095 MemOpChains.push_back(
1096 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
1097 }
1098
1099
1100 // Emit all stores, make sure the occur before any copies into physregs.
1101 if (!MemOpChains.empty())
1102 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
1103
1104 // Build a sequence of copy-to-reg nodes chained together with token
1105 // chain and flag operands which copy the outgoing args into registers.
1106 // The InGlue in necessary since all emitted instructions must be
1107 // stuck together.
1108 SDValue InGlue;
1109 for (const auto &[OrigReg, N] : RegsToPass) {
1110 Register Reg = isTailCall ? OrigReg : toCallerWindow(OrigReg);
1111 Chain = DAG.getCopyToReg(Chain, dl, Reg, N, InGlue);
1112 InGlue = Chain.getValue(1);
1113 }
1114
1115 bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CB);
1116
1117 // If the callee is a GlobalAddress node (quite common, every direct call is)
1118 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
1119 // Likewise ExternalSymbol -> TargetExternalSymbol.
1121 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32, 0);
1123 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
1124
1125 // Returns a chain & a flag for retval copy to use
1126 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1128 Ops.push_back(Chain);
1129 Ops.push_back(Callee);
1130 if (hasStructRetAttr)
1131 Ops.push_back(DAG.getTargetConstant(SRetArgSize, dl, MVT::i32));
1132 for (const auto &[OrigReg, N] : RegsToPass) {
1133 Register Reg = isTailCall ? OrigReg : toCallerWindow(OrigReg);
1134 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
1135 }
1136
1137 // Add a register mask operand representing the call-preserved registers.
1138 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1139 const uint32_t *Mask =
1140 ((hasReturnsTwice)
1141 ? TRI->getRTCallPreservedMask(CallConv)
1142 : TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv));
1143
1144 if (isAnyArgRegReserved(TRI, MF))
1146
1147 assert(Mask && "Missing call preserved mask for calling convention");
1148 Ops.push_back(DAG.getRegisterMask(Mask));
1149
1150 if (InGlue.getNode())
1151 Ops.push_back(InGlue);
1152
1153 if (isTailCall) {
1155 return DAG.getNode(SPISD::TAIL_CALL, dl, MVT::Other, Ops);
1156 }
1157
1158 Chain = DAG.getNode(SPISD::CALL, dl, NodeTys, Ops);
1159 InGlue = Chain.getValue(1);
1160
1161 Chain = DAG.getCALLSEQ_END(Chain, ArgsSize, 0, InGlue, dl);
1162 InGlue = Chain.getValue(1);
1163
1164 // Assign locations to each value returned by this call.
1166 CCState RVInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
1167 *DAG.getContext());
1168
1169 RVInfo.AnalyzeCallResult(Ins, RetCC_Sparc32);
1170
1171 // Copy all of the result registers out of their specified physreg.
1172 for (unsigned i = 0; i != RVLocs.size(); ++i) {
1173 assert(RVLocs[i].isRegLoc() && "Can only return in registers!");
1174 if (RVLocs[i].getLocVT() == MVT::v2i32) {
1175 SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2i32);
1177 Chain, dl, toCallerWindow(RVLocs[i++].getLocReg()), MVT::i32, InGlue);
1178 Chain = Lo.getValue(1);
1179 InGlue = Lo.getValue(2);
1180 Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Lo,
1181 DAG.getConstant(0, dl, MVT::i32));
1183 Chain, dl, toCallerWindow(RVLocs[i].getLocReg()), MVT::i32, InGlue);
1184 Chain = Hi.getValue(1);
1185 InGlue = Hi.getValue(2);
1186 Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Hi,
1187 DAG.getConstant(1, dl, MVT::i32));
1188 InVals.push_back(Vec);
1189 } else {
1190 Chain =
1191 DAG.getCopyFromReg(Chain, dl, toCallerWindow(RVLocs[i].getLocReg()),
1192 RVLocs[i].getValVT(), InGlue)
1193 .getValue(1);
1194 InGlue = Chain.getValue(2);
1195 InVals.push_back(Chain.getValue(0));
1196 }
1197 }
1198
1199 return Chain;
1200}
1201
1202// FIXME? Maybe this could be a TableGen attribute on some registers and
1203// this table could be generated automatically from RegInfo.
1205 const MachineFunction &MF) const {
1207 .Case("i0", SP::I0).Case("i1", SP::I1).Case("i2", SP::I2).Case("i3", SP::I3)
1208 .Case("i4", SP::I4).Case("i5", SP::I5).Case("i6", SP::I6).Case("i7", SP::I7)
1209 .Case("o0", SP::O0).Case("o1", SP::O1).Case("o2", SP::O2).Case("o3", SP::O3)
1210 .Case("o4", SP::O4).Case("o5", SP::O5).Case("o6", SP::O6).Case("o7", SP::O7)
1211 .Case("l0", SP::L0).Case("l1", SP::L1).Case("l2", SP::L2).Case("l3", SP::L3)
1212 .Case("l4", SP::L4).Case("l5", SP::L5).Case("l6", SP::L6).Case("l7", SP::L7)
1213 .Case("g0", SP::G0).Case("g1", SP::G1).Case("g2", SP::G2).Case("g3", SP::G3)
1214 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", SP::G7)
1215 .Default(0);
1216
1217 // If we're directly referencing register names
1218 // (e.g in GCC C extension `register int r asm("g1");`),
1219 // make sure that said register is in the reserve list.
1220 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1221 if (!TRI->isReservedReg(MF, Reg))
1222 Reg = Register();
1223
1224 return Reg;
1225}
1226
1227// Fixup floating point arguments in the ... part of a varargs call.
1228//
1229// The SPARC v9 ABI requires that floating point arguments are treated the same
1230// as integers when calling a varargs function. This does not apply to the
1231// fixed arguments that are part of the function's prototype.
1232//
1233// This function post-processes a CCValAssign array created by
1234// AnalyzeCallOperands().
1237 for (CCValAssign &VA : ArgLocs) {
1238 MVT ValTy = VA.getLocVT();
1239 // FIXME: What about f32 arguments? C promotes them to f64 when calling
1240 // varargs functions.
1241 if (!VA.isRegLoc() || (ValTy != MVT::f64 && ValTy != MVT::f128))
1242 continue;
1243 // The fixed arguments to a varargs function still go in FP registers.
1244 if (!Outs[VA.getValNo()].Flags.isVarArg())
1245 continue;
1246
1247 // This floating point argument should be reassigned.
1248 // Determine the offset into the argument array.
1249 Register firstReg = (ValTy == MVT::f64) ? SP::D0 : SP::Q0;
1250 unsigned argSize = (ValTy == MVT::f64) ? 8 : 16;
1251 unsigned Offset = argSize * (VA.getLocReg() - firstReg);
1252 assert(Offset < 16*8 && "Offset out of range, bad register enum?");
1253
1254 if (Offset < 6*8) {
1255 // This argument should go in %i0-%i5.
1256 unsigned IReg = SP::I0 + Offset/8;
1257 if (ValTy == MVT::f64)
1258 // Full register, just bitconvert into i64.
1259 VA = CCValAssign::getReg(VA.getValNo(), VA.getValVT(), IReg, MVT::i64,
1261 else {
1262 assert(ValTy == MVT::f128 && "Unexpected type!");
1263 // Full register, just bitconvert into i128 -- We will lower this into
1264 // two i64s in LowerCall_64.
1265 VA = CCValAssign::getCustomReg(VA.getValNo(), VA.getValVT(), IReg,
1266 MVT::i128, CCValAssign::BCvt);
1267 }
1268 } else {
1269 // This needs to go to memory, we're out of integer registers.
1270 VA = CCValAssign::getMem(VA.getValNo(), VA.getValVT(), Offset,
1271 VA.getLocVT(), VA.getLocInfo());
1272 }
1273 }
1274}
1275
1276// Lower a call for the 64-bit ABI.
1277SDValue
1279 SmallVectorImpl<SDValue> &InVals) const {
1280 SelectionDAG &DAG = CLI.DAG;
1281 SDLoc DL = CLI.DL;
1282 SDValue Chain = CLI.Chain;
1283 auto PtrVT = getPointerTy(DAG.getDataLayout());
1285
1286 // Analyze operands of the call, assigning locations to each operand.
1288 CCState CCInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), ArgLocs,
1289 *DAG.getContext());
1290 CCInfo.AnalyzeCallOperands(CLI.Outs, CC_Sparc64);
1291
1293 CCInfo, CLI, DAG.getMachineFunction());
1294
1295 // Get the size of the outgoing arguments stack space requirement.
1296 // The stack offset computed by CC_Sparc64 includes all arguments.
1297 // Called functions expect 6 argument words to exist in the stack frame, used
1298 // or not.
1299 unsigned StackReserved = 6 * 8u;
1300 unsigned ArgsSize = std::max<unsigned>(StackReserved, CCInfo.getStackSize());
1301
1302 // Keep stack frames 16-byte aligned.
1303 ArgsSize = alignTo(ArgsSize, 16);
1304
1305 // Varargs calls require special treatment.
1306 if (CLI.IsVarArg)
1307 fixupVariableFloatArgs(ArgLocs, CLI.Outs);
1308
1309 assert(!CLI.IsTailCall || ArgsSize == StackReserved);
1310
1311 // Adjust the stack pointer to make room for the arguments.
1312 // FIXME: Use hasReservedCallFrame to avoid %sp adjustments around all calls
1313 // with more than 6 arguments.
1314 if (!CLI.IsTailCall)
1315 Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, DL);
1316
1317 // Collect the set of registers to pass to the function and their values.
1318 // This will be emitted as a sequence of CopyToReg nodes glued to the call
1319 // instruction.
1321
1322 // Collect chains from all the memory opeations that copy arguments to the
1323 // stack. They must follow the stack pointer adjustment above and precede the
1324 // call instruction itself.
1325 SmallVector<SDValue, 8> MemOpChains;
1326
1327 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1328 const CCValAssign &VA = ArgLocs[i];
1329 SDValue Arg = CLI.OutVals[i];
1330
1331 // Promote the value if needed.
1332 switch (VA.getLocInfo()) {
1333 default:
1334 llvm_unreachable("Unknown location info!");
1335 case CCValAssign::Full:
1336 break;
1337 case CCValAssign::SExt:
1338 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Arg);
1339 break;
1340 case CCValAssign::ZExt:
1341 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Arg);
1342 break;
1343 case CCValAssign::AExt:
1344 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Arg);
1345 break;
1346 case CCValAssign::BCvt:
1347 // fixupVariableFloatArgs() may create bitcasts from f128 to i128. But
1348 // SPARC does not support i128 natively. Lower it into two i64, see below.
1349 if (!VA.needsCustom() || VA.getValVT() != MVT::f128
1350 || VA.getLocVT() != MVT::i128)
1351 Arg = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Arg);
1352 break;
1353 }
1354
1355 if (VA.isRegLoc()) {
1356 if (VA.needsCustom() && VA.getValVT() == MVT::f128
1357 && VA.getLocVT() == MVT::i128) {
1358 // Store and reload into the integer register reg and reg+1.
1359 unsigned Offset = 8 * (VA.getLocReg() - SP::I0);
1360 unsigned StackOffset = Offset + Subtarget->getStackPointerBias() + 128;
1361 SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1362 SDValue HiPtrOff = DAG.getIntPtrConstant(StackOffset, DL);
1363 HiPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, HiPtrOff);
1364 SDValue LoPtrOff = DAG.getIntPtrConstant(StackOffset + 8, DL);
1365 LoPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, LoPtrOff);
1366
1367 // Store to %sp+BIAS+128+Offset
1368 SDValue Store =
1369 DAG.getStore(Chain, DL, Arg, HiPtrOff, MachinePointerInfo());
1370 // Load into Reg and Reg+1
1371 SDValue Hi64 =
1372 DAG.getLoad(MVT::i64, DL, Store, HiPtrOff, MachinePointerInfo());
1373 SDValue Lo64 =
1374 DAG.getLoad(MVT::i64, DL, Store, LoPtrOff, MachinePointerInfo());
1375
1376 Register HiReg = VA.getLocReg();
1377 Register LoReg = VA.getLocReg() + 1;
1378 if (!CLI.IsTailCall) {
1379 HiReg = toCallerWindow(HiReg);
1380 LoReg = toCallerWindow(LoReg);
1381 }
1382
1383 RegsToPass.push_back(std::make_pair(HiReg, Hi64));
1384 RegsToPass.push_back(std::make_pair(LoReg, Lo64));
1385 continue;
1386 }
1387
1388 // The custom bit on an i32 return value indicates that it should be
1389 // passed in the high bits of the register.
1390 if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
1391 Arg = DAG.getNode(ISD::SHL, DL, MVT::i64, Arg,
1392 DAG.getConstant(32, DL, MVT::i32));
1393
1394 // The next value may go in the low bits of the same register.
1395 // Handle both at once.
1396 if (i+1 < ArgLocs.size() && ArgLocs[i+1].isRegLoc() &&
1397 ArgLocs[i+1].getLocReg() == VA.getLocReg()) {
1398 SDValue NV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64,
1399 CLI.OutVals[i+1]);
1400 Arg = DAG.getNode(ISD::OR, DL, MVT::i64, Arg, NV);
1401 // Skip the next value, it's already done.
1402 ++i;
1403 }
1404 }
1405
1406 Register Reg = VA.getLocReg();
1407 if (!CLI.IsTailCall)
1408 Reg = toCallerWindow(Reg);
1409 RegsToPass.push_back(std::make_pair(Reg, Arg));
1410 continue;
1411 }
1412
1413 assert(VA.isMemLoc());
1414
1415 // Create a store off the stack pointer for this argument.
1416 SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1417 // The argument area starts at %fp+BIAS+128 in the callee frame,
1418 // %sp+BIAS+128 in ours.
1419 SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset() +
1420 Subtarget->getStackPointerBias() +
1421 128, DL);
1422 PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
1423 MemOpChains.push_back(
1424 DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo()));
1425 }
1426
1427 // Emit all stores, make sure they occur before the call.
1428 if (!MemOpChains.empty())
1429 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
1430
1431 // Build a sequence of CopyToReg nodes glued together with token chain and
1432 // glue operands which copy the outgoing args into registers. The InGlue is
1433 // necessary since all emitted instructions must be stuck together in order
1434 // to pass the live physical registers.
1435 SDValue InGlue;
1436 for (const auto &[Reg, N] : RegsToPass) {
1437 Chain = DAG.getCopyToReg(Chain, DL, Reg, N, InGlue);
1438 InGlue = Chain.getValue(1);
1439 }
1440
1441 // If the callee is a GlobalAddress node (quite common, every direct call is)
1442 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
1443 // Likewise ExternalSymbol -> TargetExternalSymbol.
1444 SDValue Callee = CLI.Callee;
1445 bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CB);
1447 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, PtrVT, 0);
1449 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT);
1450
1451 // Build the operands for the call instruction itself.
1453 Ops.push_back(Chain);
1454 Ops.push_back(Callee);
1455 for (const auto &[Reg, N] : RegsToPass)
1456 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
1457
1458 // Add a register mask operand representing the call-preserved registers.
1459 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1460 const uint32_t *Mask =
1461 ((hasReturnsTwice) ? TRI->getRTCallPreservedMask(CLI.CallConv)
1462 : TRI->getCallPreservedMask(DAG.getMachineFunction(),
1463 CLI.CallConv));
1464
1465 if (isAnyArgRegReserved(TRI, MF))
1467
1468 assert(Mask && "Missing call preserved mask for calling convention");
1469 Ops.push_back(DAG.getRegisterMask(Mask));
1470
1471 // Make sure the CopyToReg nodes are glued to the call instruction which
1472 // consumes the registers.
1473 if (InGlue.getNode())
1474 Ops.push_back(InGlue);
1475
1476 // Now the call itself.
1477 if (CLI.IsTailCall) {
1479 return DAG.getNode(SPISD::TAIL_CALL, DL, MVT::Other, Ops);
1480 }
1481 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1482 Chain = DAG.getNode(SPISD::CALL, DL, NodeTys, Ops);
1483 InGlue = Chain.getValue(1);
1484
1485 // Revert the stack pointer immediately after the call.
1486 Chain = DAG.getCALLSEQ_END(Chain, ArgsSize, 0, InGlue, DL);
1487 InGlue = Chain.getValue(1);
1488
1489 // Now extract the return values. This is more or less the same as
1490 // LowerFormalArguments_64.
1491
1492 // Assign locations to each value returned by this call.
1494 CCState RVInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), RVLocs,
1495 *DAG.getContext());
1496
1497 // Set inreg flag manually for codegen generated library calls that
1498 // return float.
1499 if (CLI.Ins.size() == 1 && CLI.Ins[0].VT == MVT::f32 && !CLI.CB)
1500 CLI.Ins[0].Flags.setInReg();
1501
1502 RVInfo.AnalyzeCallResult(CLI.Ins, RetCC_Sparc64);
1503
1504 // Copy all of the result registers out of their specified physreg.
1505 for (unsigned i = 0; i != RVLocs.size(); ++i) {
1506 CCValAssign &VA = RVLocs[i];
1507 assert(VA.isRegLoc() && "Can only return in registers!");
1508 unsigned Reg = toCallerWindow(VA.getLocReg());
1509
1510 // When returning 'inreg {i32, i32 }', two consecutive i32 arguments can
1511 // reside in the same register in the high and low bits. Reuse the
1512 // CopyFromReg previous node to avoid duplicate copies.
1513 SDValue RV;
1514 if (RegisterSDNode *SrcReg = dyn_cast<RegisterSDNode>(Chain.getOperand(1)))
1515 if (SrcReg->getReg() == Reg && Chain->getOpcode() == ISD::CopyFromReg)
1516 RV = Chain.getValue(0);
1517
1518 // But usually we'll create a new CopyFromReg for a different register.
1519 if (!RV.getNode()) {
1520 RV = DAG.getCopyFromReg(Chain, DL, Reg, RVLocs[i].getLocVT(), InGlue);
1521 Chain = RV.getValue(1);
1522 InGlue = Chain.getValue(2);
1523 }
1524
1525 // Get the high bits for i32 struct elements.
1526 if (VA.getValVT() == MVT::i32 && VA.needsCustom())
1527 RV = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), RV,
1528 DAG.getConstant(32, DL, MVT::i32));
1529
1530 // The callee promoted the return value, so insert an Assert?ext SDNode so
1531 // we won't promote the value again in this function.
1532 switch (VA.getLocInfo()) {
1533 case CCValAssign::SExt:
1534 RV = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), RV,
1535 DAG.getValueType(VA.getValVT()));
1536 break;
1537 case CCValAssign::ZExt:
1538 RV = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), RV,
1539 DAG.getValueType(VA.getValVT()));
1540 break;
1541 default:
1542 break;
1543 }
1544
1545 // Truncate the register down to the return value type.
1546 if (VA.isExtInLoc())
1547 RV = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), RV);
1548
1549 InVals.push_back(RV);
1550 }
1551
1552 return Chain;
1553}
1554
1555//===----------------------------------------------------------------------===//
1556// TargetLowering Implementation
1557//===----------------------------------------------------------------------===//
1558
1561 if (AI->getOperation() == AtomicRMWInst::Xchg &&
1562 AI->getType()->getPrimitiveSizeInBits() == 32)
1563 return AtomicExpansionKind::None; // Uses xchg instruction
1564
1566}
1567
1568/// intCondCCodeToRcond - Convert a DAG integer condition code to a SPARC
1569/// rcond condition.
1571 switch (CC) {
1572 default:
1573 llvm_unreachable("Unknown/unsigned integer condition code!");
1574 case ISD::SETEQ:
1575 return SPCC::REG_Z;
1576 case ISD::SETNE:
1577 return SPCC::REG_NZ;
1578 case ISD::SETLT:
1579 return SPCC::REG_LZ;
1580 case ISD::SETGT:
1581 return SPCC::REG_GZ;
1582 case ISD::SETLE:
1583 return SPCC::REG_LEZ;
1584 case ISD::SETGE:
1585 return SPCC::REG_GEZ;
1586 }
1587}
1588
1589/// IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC
1590/// condition.
1592 switch (CC) {
1593 default: llvm_unreachable("Unknown integer condition code!");
1594 case ISD::SETEQ: return SPCC::ICC_E;
1595 case ISD::SETNE: return SPCC::ICC_NE;
1596 case ISD::SETLT: return SPCC::ICC_L;
1597 case ISD::SETGT: return SPCC::ICC_G;
1598 case ISD::SETLE: return SPCC::ICC_LE;
1599 case ISD::SETGE: return SPCC::ICC_GE;
1600 case ISD::SETULT: return SPCC::ICC_CS;
1601 case ISD::SETULE: return SPCC::ICC_LEU;
1602 case ISD::SETUGT: return SPCC::ICC_GU;
1603 case ISD::SETUGE: return SPCC::ICC_CC;
1604 }
1605}
1606
1607/// FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC
1608/// FCC condition.
1610 switch (CC) {
1611 default: llvm_unreachable("Unknown fp condition code!");
1612 case ISD::SETEQ:
1613 case ISD::SETOEQ: return SPCC::FCC_E;
1614 case ISD::SETNE:
1615 case ISD::SETUNE: return SPCC::FCC_NE;
1616 case ISD::SETLT:
1617 case ISD::SETOLT: return SPCC::FCC_L;
1618 case ISD::SETGT:
1619 case ISD::SETOGT: return SPCC::FCC_G;
1620 case ISD::SETLE:
1621 case ISD::SETOLE: return SPCC::FCC_LE;
1622 case ISD::SETGE:
1623 case ISD::SETOGE: return SPCC::FCC_GE;
1624 case ISD::SETULT: return SPCC::FCC_UL;
1625 case ISD::SETULE: return SPCC::FCC_ULE;
1626 case ISD::SETUGT: return SPCC::FCC_UG;
1627 case ISD::SETUGE: return SPCC::FCC_UGE;
1628 case ISD::SETUO: return SPCC::FCC_U;
1629 case ISD::SETO: return SPCC::FCC_O;
1630 case ISD::SETONE: return SPCC::FCC_LG;
1631 case ISD::SETUEQ: return SPCC::FCC_UE;
1632 }
1633}
1634
1636 const SparcSubtarget &STI)
1637 : TargetLowering(TM, STI), Subtarget(&STI) {
1638 MVT PtrVT = MVT::getIntegerVT(TM.getPointerSizeInBits(0));
1639
1640 // Instructions which use registers as conditionals examine all the
1641 // bits (as does the pseudo SELECT_CC expansion). I don't think it
1642 // matters much whether it's ZeroOrOneBooleanContent, or
1643 // ZeroOrNegativeOneBooleanContent, so, arbitrarily choose the
1644 // former.
1647
1648 // Set up the register classes.
1649 addRegisterClass(MVT::i32, &SP::IntRegsRegClass);
1650 if (!Subtarget->useSoftFloat()) {
1651 addRegisterClass(MVT::f32, &SP::FPRegsRegClass);
1652 addRegisterClass(MVT::f64, &SP::DFPRegsRegClass);
1653 addRegisterClass(MVT::f128, &SP::QFPRegsRegClass);
1654 }
1655 if (Subtarget->is64Bit()) {
1656 addRegisterClass(MVT::i64, &SP::I64RegsRegClass);
1657 } else {
1658 // On 32bit sparc, we define a double-register 32bit register
1659 // class, as well. This is modeled in LLVM as a 2-vector of i32.
1660 addRegisterClass(MVT::v2i32, &SP::IntPairRegClass);
1661
1662 // ...but almost all operations must be expanded, so set that as
1663 // the default.
1664 for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op) {
1665 setOperationAction(Op, MVT::v2i32, Expand);
1666 }
1667 // Truncating/extending stores/loads are also not supported.
1669 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::v2i32, Expand);
1670 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::v2i32, Expand);
1671 setLoadExtAction(ISD::EXTLOAD, VT, MVT::v2i32, Expand);
1672
1673 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i32, VT, Expand);
1674 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i32, VT, Expand);
1675 setLoadExtAction(ISD::EXTLOAD, MVT::v2i32, VT, Expand);
1676
1677 setTruncStoreAction(VT, MVT::v2i32, Expand);
1678 setTruncStoreAction(MVT::v2i32, VT, Expand);
1679 }
1680 // However, load and store *are* legal.
1681 setOperationAction(ISD::LOAD, MVT::v2i32, Legal);
1682 setOperationAction(ISD::STORE, MVT::v2i32, Legal);
1685
1686 // And we need to promote i64 loads/stores into vector load/store
1689
1690 // Sadly, this doesn't work:
1691 // AddPromotedToType(ISD::LOAD, MVT::i64, MVT::v2i32);
1692 // AddPromotedToType(ISD::STORE, MVT::i64, MVT::v2i32);
1693 }
1694
1695 // Turn FP extload into load/fpextend
1696 for (MVT VT : MVT::fp_valuetypes()) {
1697 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand);
1698 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand);
1699 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f64, Expand);
1700 }
1701
1702 // Sparc doesn't have i1 sign extending load
1703 for (MVT VT : MVT::integer_valuetypes())
1704 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote);
1705
1706 // Turn FP truncstore into trunc + store.
1707 setTruncStoreAction(MVT::f32, MVT::f16, Expand);
1708 setTruncStoreAction(MVT::f64, MVT::f16, Expand);
1709 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
1710 setTruncStoreAction(MVT::f128, MVT::f16, Expand);
1711 setTruncStoreAction(MVT::f128, MVT::f32, Expand);
1712 setTruncStoreAction(MVT::f128, MVT::f64, Expand);
1713
1714 // Custom legalize GlobalAddress nodes into LO/HI parts.
1719
1720 // Sparc doesn't have sext_inreg, replace them with shl/sra
1724
1725 // Sparc has no REM or DIVREM operations.
1730
1731 // ... nor does SparcV9.
1732 if (Subtarget->is64Bit()) {
1737 }
1738
1739 // Custom expand fp<->sint
1744
1745 // Custom Expand fp<->uint
1750
1751 // Lower f16 conversion operations into library calls
1758
1760 Subtarget->isVIS3() ? Legal : Expand);
1762 Subtarget->isVIS3() ? Legal : Expand);
1763
1764 // Sparc has no select or setcc: expand to SELECT_CC.
1769
1774
1775 // Sparc doesn't have BRCOND either, it has BR_CC.
1777 setOperationAction(ISD::BRIND, MVT::Other, Expand);
1778 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
1783
1788
1793
1794 if (Subtarget->isVIS3()) {
1797 }
1798
1799 if (Subtarget->is64Bit()) {
1801 Subtarget->isVIS3() ? Legal : Expand);
1803 Subtarget->isVIS3() ? Legal : Expand);
1808
1810 Subtarget->usePopc() ? Legal : Expand);
1812 setOperationAction(ISD::ROTL , MVT::i64, Expand);
1813 setOperationAction(ISD::ROTR , MVT::i64, Expand);
1815 }
1816
1817 // ATOMICs.
1818 // Atomics are supported on SparcV9. 32-bit atomics are also
1819 // supported by some Leon SparcV8 variants. Otherwise, atomics
1820 // are unsupported.
1821 if (Subtarget->isV9()) {
1822 // TODO: we _ought_ to be able to support 64-bit atomics on 32-bit sparcv9,
1823 // but it hasn't been implemented in the backend yet.
1824 if (Subtarget->is64Bit())
1826 else
1828 } else if (Subtarget->hasLeonCasa())
1830 else
1832
1834
1836
1838
1839 // Custom Lower Atomic LOAD/STORE
1842
1843 if (Subtarget->is64Bit()) {
1848 }
1849
1850 if (!Subtarget->isV9()) {
1851 // SparcV8 does not have FNEGD and FABSD.
1854 }
1855
1856 setOperationAction(ISD::FSIN , MVT::f128, Expand);
1857 setOperationAction(ISD::FCOS , MVT::f128, Expand);
1860 setOperationAction(ISD::FMA , MVT::f128, Expand);
1861 setOperationAction(ISD::FSIN , MVT::f64, Expand);
1862 setOperationAction(ISD::FCOS , MVT::f64, Expand);
1865 setOperationAction(ISD::FMA, MVT::f64,
1866 Subtarget->isUA2007() ? Legal : Expand);
1867 setOperationAction(ISD::FSIN , MVT::f32, Expand);
1868 setOperationAction(ISD::FCOS , MVT::f32, Expand);
1871 setOperationAction(ISD::FMA, MVT::f32,
1872 Subtarget->isUA2007() ? Legal : Expand);
1873 setOperationAction(ISD::ROTL , MVT::i32, Expand);
1874 setOperationAction(ISD::ROTR , MVT::i32, Expand);
1879 setOperationAction(ISD::FPOW , MVT::f128, Expand);
1880 setOperationAction(ISD::FPOW , MVT::f64, Expand);
1881 setOperationAction(ISD::FPOW , MVT::f32, Expand);
1882
1886
1887 // Expands to [SU]MUL_LOHI.
1891
1892 if (Subtarget->useSoftMulDiv()) {
1893 // .umul works for both signed and unsigned
1898 }
1899
1900 if (Subtarget->is64Bit()) {
1904 Subtarget->isVIS3() ? Legal : Expand);
1906 Subtarget->isVIS3() ? Legal : Expand);
1907
1911 }
1912
1913 // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
1914 setOperationAction(ISD::VASTART , MVT::Other, Custom);
1915 // VAARG needs to be lowered to not do unaligned accesses for doubles.
1916 setOperationAction(ISD::VAARG , MVT::Other, Custom);
1917
1918 setOperationAction(ISD::TRAP , MVT::Other, Legal);
1920
1921 // Use the default implementation.
1922 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
1923 setOperationAction(ISD::VAEND , MVT::Other, Expand);
1928
1930
1932 Subtarget->usePopc() ? Legal : Expand);
1933
1934 if (Subtarget->isV9() && Subtarget->hasHardQuad()) {
1935 setOperationAction(ISD::LOAD, MVT::f128, Legal);
1936 setOperationAction(ISD::STORE, MVT::f128, Legal);
1937 } else {
1938 setOperationAction(ISD::LOAD, MVT::f128, Custom);
1940 }
1941
1942 if (Subtarget->hasHardQuad()) {
1943 setOperationAction(ISD::FADD, MVT::f128, Legal);
1944 setOperationAction(ISD::FSUB, MVT::f128, Legal);
1945 setOperationAction(ISD::FMUL, MVT::f128, Legal);
1946 setOperationAction(ISD::FDIV, MVT::f128, Legal);
1947 setOperationAction(ISD::FSQRT, MVT::f128, Legal);
1950 if (Subtarget->isV9()) {
1951 setOperationAction(ISD::FNEG, MVT::f128, Legal);
1952 setOperationAction(ISD::FABS, MVT::f128, Legal);
1953 } else {
1954 setOperationAction(ISD::FNEG, MVT::f128, Custom);
1955 setOperationAction(ISD::FABS, MVT::f128, Custom);
1956 }
1957 } else {
1958 // Custom legalize f128 operations.
1959
1960 setOperationAction(ISD::FADD, MVT::f128, Custom);
1961 setOperationAction(ISD::FSUB, MVT::f128, Custom);
1962 setOperationAction(ISD::FMUL, MVT::f128, Custom);
1963 setOperationAction(ISD::FDIV, MVT::f128, Custom);
1965 setOperationAction(ISD::FNEG, MVT::f128, Custom);
1966 setOperationAction(ISD::FABS, MVT::f128, Custom);
1967
1971 }
1972
1973 if (Subtarget->fixAllFDIVSQRT()) {
1974 // Promote FDIVS and FSQRTS to FDIVD and FSQRTD instructions instead as
1975 // the former instructions generate errata on LEON processors.
1978 }
1979
1980 if (Subtarget->hasNoFMULS()) {
1982 }
1983
1984 // Custom combine bitcast between f64 and v2i32
1985 if (!Subtarget->is64Bit())
1987
1988 if (Subtarget->hasLeonCycleCounter())
1990
1991 if (Subtarget->isVIS3()) {
1996
1997 setOperationAction(ISD::CTTZ, MVT::i32,
1998 Subtarget->is64Bit() ? Promote : Expand);
2001 Subtarget->is64Bit() ? Promote : Expand);
2003 } else if (Subtarget->usePopc()) {
2008
2013 } else {
2017 Subtarget->is64Bit() ? Promote : LibCall);
2019
2020 // FIXME here we don't have any ISA extensions that could help us, so to
2021 // prevent large expansions those should be made into LibCalls.
2026 }
2027
2029
2030 // Some processors have no branch predictor and have pipelines longer than
2031 // what can be covered by the delay slot. This results in a stall, so mark
2032 // branches to be expensive on those processors.
2033 setJumpIsExpensive(Subtarget->hasNoPredictor());
2034 // The high cost of branching means that using conditional moves will
2035 // still be profitable even if the condition is predictable.
2037
2039
2040 computeRegisterProperties(Subtarget->getRegisterInfo());
2041}
2042
2044 return Subtarget->useSoftFloat();
2045}
2046
2048 EVT VT) const {
2049 if (!VT.isVector())
2050 return MVT::i32;
2052}
2053
2054/// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
2055/// be zero. Op is expected to be a target specific node. Used by DAG
2056/// combiner.
2058 (const SDValue Op,
2059 KnownBits &Known,
2060 const APInt &DemandedElts,
2061 const SelectionDAG &DAG,
2062 unsigned Depth) const {
2063 KnownBits Known2;
2064 Known.resetAll();
2065
2066 switch (Op.getOpcode()) {
2067 default: break;
2068 case SPISD::SELECT_ICC:
2069 case SPISD::SELECT_XCC:
2070 case SPISD::SELECT_FCC:
2071 Known = DAG.computeKnownBits(Op.getOperand(1), Depth + 1);
2072 Known2 = DAG.computeKnownBits(Op.getOperand(0), Depth + 1);
2073
2074 // Only known if known in both the LHS and RHS.
2075 Known = Known.intersectWith(Known2);
2076 break;
2077 }
2078}
2079
2080// Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so
2081// set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
2083 ISD::CondCode CC, unsigned &SPCC) {
2084 if (isNullConstant(RHS) && CC == ISD::SETNE &&
2085 (((LHS.getOpcode() == SPISD::SELECT_ICC ||
2086 LHS.getOpcode() == SPISD::SELECT_XCC) &&
2087 LHS.getOperand(3).getOpcode() == SPISD::CMPICC) ||
2088 (LHS.getOpcode() == SPISD::SELECT_FCC &&
2089 (LHS.getOperand(3).getOpcode() == SPISD::CMPFCC ||
2090 LHS.getOperand(3).getOpcode() == SPISD::CMPFCC_V9))) &&
2091 isOneConstant(LHS.getOperand(0)) && isNullConstant(LHS.getOperand(1))) {
2092 SDValue CMPCC = LHS.getOperand(3);
2093 SPCC = LHS.getConstantOperandVal(2);
2094 LHS = CMPCC.getOperand(0);
2095 RHS = CMPCC.getOperand(1);
2096 }
2097}
2098
2099// Convert to a target node and set target flags.
2101 SelectionDAG &DAG) const {
2103 return DAG.getTargetGlobalAddress(GA->getGlobal(),
2104 SDLoc(GA),
2105 GA->getValueType(0),
2106 GA->getOffset(), TF);
2107
2109 return DAG.getTargetConstantPool(CP->getConstVal(), CP->getValueType(0),
2110 CP->getAlign(), CP->getOffset(), TF);
2111
2113 return DAG.getTargetBlockAddress(BA->getBlockAddress(),
2114 Op.getValueType(),
2115 0,
2116 TF);
2117
2119 return DAG.getTargetExternalSymbol(ES->getSymbol(),
2120 ES->getValueType(0), TF);
2121
2122 llvm_unreachable("Unhandled address SDNode");
2123}
2124
2125// Split Op into high and low parts according to HiTF and LoTF.
2126// Return an ADD node combining the parts.
2128 unsigned HiTF, unsigned LoTF,
2129 SelectionDAG &DAG) const {
2130 SDLoc DL(Op);
2131 EVT VT = Op.getValueType();
2132 SDValue Hi = DAG.getNode(SPISD::Hi, DL, VT, withTargetFlags(Op, HiTF, DAG));
2133 SDValue Lo = DAG.getNode(SPISD::Lo, DL, VT, withTargetFlags(Op, LoTF, DAG));
2134 return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
2135}
2136
2137// Build SDNodes for producing an address from a GlobalAddress, ConstantPool,
2138// or ExternalSymbol SDNode.
2140 SDLoc DL(Op);
2141 EVT VT = getPointerTy(DAG.getDataLayout());
2142
2143 // Handle PIC mode first. SPARC needs a got load for every variable!
2144 if (isPositionIndependent()) {
2145 const Module *M = DAG.getMachineFunction().getFunction().getParent();
2146 PICLevel::Level picLevel = M->getPICLevel();
2147 SDValue Idx;
2148
2149 if (picLevel == PICLevel::SmallPIC) {
2150 // This is the pic13 code model, the GOT is known to be smaller than 8KiB.
2151 Idx = DAG.getNode(SPISD::Lo, DL, Op.getValueType(),
2152 withTargetFlags(Op, ELF::R_SPARC_GOT13, DAG));
2153 } else {
2154 // This is the pic32 code model, the GOT is known to be smaller than 4GB.
2155 Idx = makeHiLoPair(Op, ELF::R_SPARC_GOT22, ELF::R_SPARC_GOT10, DAG);
2156 }
2157
2158 SDValue GlobalBase = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, VT);
2159 SDValue AbsAddr = DAG.getNode(ISD::ADD, DL, VT, GlobalBase, Idx);
2160 // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
2161 // function has calls.
2163 MFI.setHasCalls(true);
2164 return DAG.getLoad(VT, DL, DAG.getEntryNode(), AbsAddr,
2166 }
2167
2168 // This is one of the absolute code models.
2169 switch(getTargetMachine().getCodeModel()) {
2170 default:
2171 llvm_unreachable("Unsupported absolute code model");
2172 case CodeModel::Small:
2173 // abs32.
2174 return makeHiLoPair(Op, ELF::R_SPARC_HI22, ELF::R_SPARC_LO10, DAG);
2175 case CodeModel::Medium: {
2176 // abs44.
2177 SDValue H44 = makeHiLoPair(Op, ELF::R_SPARC_H44, ELF::R_SPARC_M44, DAG);
2178 H44 = DAG.getNode(ISD::SHL, DL, VT, H44, DAG.getConstant(12, DL, MVT::i32));
2179 SDValue L44 = withTargetFlags(Op, ELF::R_SPARC_L44, DAG);
2180 L44 = DAG.getNode(SPISD::Lo, DL, VT, L44);
2181 return DAG.getNode(ISD::ADD, DL, VT, H44, L44);
2182 }
2183 case CodeModel::Large: {
2184 // abs64.
2185 SDValue Hi = makeHiLoPair(Op, ELF::R_SPARC_HH22, ELF::R_SPARC_HM10, DAG);
2186 Hi = DAG.getNode(ISD::SHL, DL, VT, Hi, DAG.getConstant(32, DL, MVT::i32));
2187 SDValue Lo = makeHiLoPair(Op, ELF::R_SPARC_HI22, ELF::R_SPARC_LO10, DAG);
2188 return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
2189 }
2190 }
2191}
2192
2197
2202
2207
2209 SelectionDAG &DAG) const {
2210
2212 if (DAG.getTarget().useEmulatedTLS())
2213 return LowerToTLSEmulatedModel(GA, DAG);
2214
2215 SDLoc DL(GA);
2216 const GlobalValue *GV = GA->getGlobal();
2217 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2218
2220
2221 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) {
2222 unsigned HiTF =
2223 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_HI22
2224 : ELF::R_SPARC_TLS_LDM_HI22);
2225 unsigned LoTF =
2226 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_LO10
2227 : ELF::R_SPARC_TLS_LDM_LO10);
2228 unsigned addTF =
2229 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_ADD
2230 : ELF::R_SPARC_TLS_LDM_ADD);
2231 unsigned callTF =
2232 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_CALL
2233 : ELF::R_SPARC_TLS_LDM_CALL);
2234
2235 SDValue HiLo = makeHiLoPair(Op, HiTF, LoTF, DAG);
2236 SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2237 SDValue Argument = DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Base, HiLo,
2238 withTargetFlags(Op, addTF, DAG));
2239
2240 SDValue Chain = DAG.getEntryNode();
2241 SDValue InGlue;
2242
2243 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, DL);
2244 Chain = DAG.getCopyToReg(Chain, DL, SP::O0, Argument, InGlue);
2245 InGlue = Chain.getValue(1);
2246 SDValue Callee = DAG.getTargetExternalSymbol("__tls_get_addr", PtrVT);
2247 SDValue Symbol = withTargetFlags(Op, callTF, DAG);
2248
2249 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
2250 const uint32_t *Mask = Subtarget->getRegisterInfo()->getCallPreservedMask(
2252 assert(Mask && "Missing call preserved mask for calling convention");
2253 SDValue Ops[] = {Chain,
2254 Callee,
2255 Symbol,
2256 DAG.getRegister(SP::O0, PtrVT),
2257 DAG.getRegisterMask(Mask),
2258 InGlue};
2259 Chain = DAG.getNode(SPISD::TLS_CALL, DL, NodeTys, Ops);
2260 InGlue = Chain.getValue(1);
2261 Chain = DAG.getCALLSEQ_END(Chain, 0, 0, InGlue, DL);
2262 InGlue = Chain.getValue(1);
2263 SDValue Ret = DAG.getCopyFromReg(Chain, DL, SP::O0, PtrVT, InGlue);
2264
2265 if (model != TLSModel::LocalDynamic)
2266 return Ret;
2267
2268 SDValue Hi =
2269 DAG.getNode(SPISD::Hi, DL, PtrVT,
2270 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_HIX22, DAG));
2271 SDValue Lo =
2272 DAG.getNode(SPISD::Lo, DL, PtrVT,
2273 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_LOX10, DAG));
2274 HiLo = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2275 return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Ret, HiLo,
2276 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_ADD, DAG));
2277 }
2278
2279 if (model == TLSModel::InitialExec) {
2280 unsigned ldTF = ((PtrVT == MVT::i64) ? ELF::R_SPARC_TLS_IE_LDX
2281 : ELF::R_SPARC_TLS_IE_LD);
2282
2283 SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2284
2285 // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
2286 // function has calls.
2288 MFI.setHasCalls(true);
2289
2290 SDValue TGA = makeHiLoPair(Op, ELF::R_SPARC_TLS_IE_HI22,
2291 ELF::R_SPARC_TLS_IE_LO10, DAG);
2292 SDValue Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Base, TGA);
2293 SDValue Offset = DAG.getNode(SPISD::TLS_LD,
2294 DL, PtrVT, Ptr,
2295 withTargetFlags(Op, ldTF, DAG));
2296 return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT,
2297 DAG.getRegister(SP::G7, PtrVT), Offset,
2298 withTargetFlags(Op, ELF::R_SPARC_TLS_IE_ADD, DAG));
2299 }
2300
2301 assert(model == TLSModel::LocalExec);
2302 SDValue Hi = DAG.getNode(SPISD::Hi, DL, PtrVT,
2303 withTargetFlags(Op, ELF::R_SPARC_TLS_LE_HIX22, DAG));
2304 SDValue Lo = DAG.getNode(SPISD::Lo, DL, PtrVT,
2305 withTargetFlags(Op, ELF::R_SPARC_TLS_LE_LOX10, DAG));
2306 SDValue Offset = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2307
2308 return DAG.getNode(ISD::ADD, DL, PtrVT,
2309 DAG.getRegister(SP::G7, PtrVT), Offset);
2310}
2311
2313 ArgListTy &Args, SDValue Arg,
2314 const SDLoc &DL,
2315 SelectionDAG &DAG) const {
2317 EVT ArgVT = Arg.getValueType();
2318 Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
2319
2320 if (ArgTy->isFP128Ty()) {
2321 // Create a stack object and pass the pointer to the library function.
2322 int FI = MFI.CreateStackObject(16, Align(8), false);
2323 SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
2324 Chain = DAG.getStore(Chain, DL, Arg, FIPtr, MachinePointerInfo(), Align(8));
2325 Args.emplace_back(FIPtr, PointerType::getUnqual(ArgTy->getContext()));
2326 } else {
2327 Args.emplace_back(Arg, ArgTy);
2328 }
2329 return Chain;
2330}
2331
2333 RTLIB::Libcall LibFunc,
2334 unsigned numArgs) const {
2335 RTLIB::LibcallImpl LibFuncImpl = DAG.getLibcalls().getLibcallImpl(LibFunc);
2336 if (LibFuncImpl == RTLIB::Unsupported)
2337 return SDValue();
2338
2339 ArgListTy Args;
2340
2342 auto PtrVT = getPointerTy(DAG.getDataLayout());
2343
2344 SDValue Callee = DAG.getExternalSymbol(LibFuncImpl, PtrVT);
2345 Type *RetTy = Op.getValueType().getTypeForEVT(*DAG.getContext());
2346 Type *RetTyABI = RetTy;
2347 SDValue Chain = DAG.getEntryNode();
2348 SDValue RetPtr;
2349
2350 if (RetTy->isFP128Ty()) {
2351 // Create a Stack Object to receive the return value of type f128.
2352 int RetFI = MFI.CreateStackObject(16, Align(8), false);
2353 RetPtr = DAG.getFrameIndex(RetFI, PtrVT);
2354 ArgListEntry Entry(RetPtr, PointerType::getUnqual(RetTy->getContext()));
2355 if (!Subtarget->is64Bit()) {
2356 Entry.IsSRet = true;
2357 Entry.IndirectType = RetTy;
2358 }
2359 Entry.IsReturned = false;
2360 Args.push_back(Entry);
2361 RetTyABI = Type::getVoidTy(*DAG.getContext());
2362 }
2363
2364 assert(Op->getNumOperands() >= numArgs && "Not enough operands!");
2365 for (unsigned i = 0, e = numArgs; i != e; ++i) {
2366 Chain = LowerF128_LibCallArg(Chain, Args, Op.getOperand(i), SDLoc(Op), DAG);
2367 }
2368
2371 CLI.setDebugLoc(SDLoc(Op)).setChain(Chain).setCallee(CC, RetTyABI, Callee,
2372 std::move(Args));
2373
2374 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2375
2376 // chain is in second result.
2377 if (RetTyABI == RetTy)
2378 return CallInfo.first;
2379
2380 assert (RetTy->isFP128Ty() && "Unexpected return type!");
2381
2382 Chain = CallInfo.second;
2383
2384 // Load RetPtr to get the return value.
2385 return DAG.getLoad(Op.getValueType(), SDLoc(Op), Chain, RetPtr,
2387}
2388
2390 unsigned &SPCC, const SDLoc &DL,
2391 SelectionDAG &DAG) const {
2392
2393 const char *LibCall = nullptr;
2394 bool is64Bit = Subtarget->is64Bit();
2395 switch(SPCC) {
2396 default: llvm_unreachable("Unhandled conditional code!");
2397 case SPCC::FCC_E : LibCall = is64Bit? "_Qp_feq" : "_Q_feq"; break;
2398 case SPCC::FCC_NE : LibCall = is64Bit? "_Qp_fne" : "_Q_fne"; break;
2399 case SPCC::FCC_L : LibCall = is64Bit? "_Qp_flt" : "_Q_flt"; break;
2400 case SPCC::FCC_G : LibCall = is64Bit? "_Qp_fgt" : "_Q_fgt"; break;
2401 case SPCC::FCC_LE : LibCall = is64Bit? "_Qp_fle" : "_Q_fle"; break;
2402 case SPCC::FCC_GE : LibCall = is64Bit? "_Qp_fge" : "_Q_fge"; break;
2403 case SPCC::FCC_UL :
2404 case SPCC::FCC_ULE:
2405 case SPCC::FCC_UG :
2406 case SPCC::FCC_UGE:
2407 case SPCC::FCC_U :
2408 case SPCC::FCC_O :
2409 case SPCC::FCC_LG :
2410 case SPCC::FCC_UE : LibCall = is64Bit? "_Qp_cmp" : "_Q_cmp"; break;
2411 }
2412
2413 auto PtrVT = getPointerTy(DAG.getDataLayout());
2414 SDValue Callee = DAG.getExternalSymbol(LibCall, PtrVT);
2415 Type *RetTy = Type::getInt32Ty(*DAG.getContext());
2416 ArgListTy Args;
2417 SDValue Chain = DAG.getEntryNode();
2418 Chain = LowerF128_LibCallArg(Chain, Args, LHS, DL, DAG);
2419 Chain = LowerF128_LibCallArg(Chain, Args, RHS, DL, DAG);
2420
2422 CLI.setDebugLoc(DL).setChain(Chain)
2423 .setCallee(CallingConv::C, RetTy, Callee, std::move(Args));
2424
2425 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2426
2427 // result is in first, and chain is in second result.
2428 SDValue Result = CallInfo.first;
2429
2430 switch(SPCC) {
2431 default: {
2432 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2434 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2435 }
2436 case SPCC::FCC_UL : {
2437 SDValue Mask = DAG.getConstant(1, DL, Result.getValueType());
2438 Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2439 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2441 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2442 }
2443 case SPCC::FCC_ULE: {
2444 SDValue RHS = DAG.getConstant(2, DL, Result.getValueType());
2446 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2447 }
2448 case SPCC::FCC_UG : {
2449 SDValue RHS = DAG.getConstant(1, DL, Result.getValueType());
2450 SPCC = SPCC::ICC_G;
2451 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2452 }
2453 case SPCC::FCC_UGE: {
2454 SDValue RHS = DAG.getConstant(1, DL, Result.getValueType());
2456 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2457 }
2458
2459 case SPCC::FCC_U : {
2460 SDValue RHS = DAG.getConstant(3, DL, Result.getValueType());
2461 SPCC = SPCC::ICC_E;
2462 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2463 }
2464 case SPCC::FCC_O : {
2465 SDValue RHS = DAG.getConstant(3, DL, Result.getValueType());
2467 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2468 }
2469 case SPCC::FCC_LG : {
2470 SDValue Mask = DAG.getConstant(3, DL, Result.getValueType());
2471 Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2472 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2474 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2475 }
2476 case SPCC::FCC_UE : {
2477 SDValue Mask = DAG.getConstant(3, DL, Result.getValueType());
2478 Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2479 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2480 SPCC = SPCC::ICC_E;
2481 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2482 }
2483 }
2484}
2485
2486static SDValue
2488 const SparcTargetLowering &TLI) {
2489
2490 if (Op.getOperand(0).getValueType() == MVT::f64)
2491 return TLI.LowerF128Op(Op, DAG, RTLIB::FPEXT_F64_F128, 1);
2492
2493 if (Op.getOperand(0).getValueType() == MVT::f32)
2494 return TLI.LowerF128Op(Op, DAG, RTLIB::FPEXT_F32_F128, 1);
2495
2496 llvm_unreachable("fpextend with non-float operand!");
2497 return SDValue();
2498}
2499
2500static SDValue
2502 const SparcTargetLowering &TLI) {
2503 // FP_ROUND on f64 and f32 are legal.
2504 if (Op.getOperand(0).getValueType() != MVT::f128)
2505 return Op;
2506
2507 if (Op.getValueType() == MVT::f64)
2508 return TLI.LowerF128Op(Op, DAG, RTLIB::FPROUND_F128_F64, 1);
2509 if (Op.getValueType() == MVT::f32)
2510 return TLI.LowerF128Op(Op, DAG, RTLIB::FPROUND_F128_F32, 1);
2511
2512 llvm_unreachable("fpround to non-float!");
2513 return SDValue();
2514}
2515
2517 const SparcTargetLowering &TLI,
2518 bool hasHardQuad) {
2519 SDLoc dl(Op);
2520 EVT VT = Op.getValueType();
2521 assert(VT == MVT::i32 || VT == MVT::i64);
2522
2523 // Expand f128 operations to fp128 abi calls.
2524 if (Op.getOperand(0).getValueType() == MVT::f128
2525 && (!hasHardQuad || !TLI.isTypeLegal(VT))) {
2526 RTLIB::Libcall LibFunc =
2527 VT == MVT::i32 ? RTLIB::FPTOSINT_F128_I32 : RTLIB::FPTOSINT_F128_I64;
2528 return TLI.LowerF128Op(Op, DAG, LibFunc, 1);
2529 }
2530
2531 // Expand if the resulting type is illegal.
2532 if (!TLI.isTypeLegal(VT))
2533 return SDValue();
2534
2535 // Otherwise, Convert the fp value to integer in an FP register.
2536 if (VT == MVT::i32)
2537 Op = DAG.getNode(SPISD::FTOI, dl, MVT::f32, Op.getOperand(0));
2538 else
2539 Op = DAG.getNode(SPISD::FTOX, dl, MVT::f64, Op.getOperand(0));
2540
2541 return DAG.getNode(ISD::BITCAST, dl, VT, Op);
2542}
2543
2545 const SparcTargetLowering &TLI,
2546 bool hasHardQuad) {
2547 SDLoc dl(Op);
2548 EVT OpVT = Op.getOperand(0).getValueType();
2549 assert(OpVT == MVT::i32 || (OpVT == MVT::i64));
2550
2551 EVT floatVT = (OpVT == MVT::i32) ? MVT::f32 : MVT::f64;
2552
2553 // Expand f128 operations to fp128 ABI calls.
2554 if (Op.getValueType() == MVT::f128
2555 && (!hasHardQuad || !TLI.isTypeLegal(OpVT))) {
2556 RTLIB::Libcall LibFunc =
2557 OpVT == MVT::i32 ? RTLIB::SINTTOFP_I32_F128 : RTLIB::SINTTOFP_I64_F128;
2558 return TLI.LowerF128Op(Op, DAG, LibFunc, 1);
2559 }
2560
2561 // Expand if the operand type is illegal.
2562 if (!TLI.isTypeLegal(OpVT))
2563 return SDValue();
2564
2565 // Otherwise, Convert the int value to FP in an FP register.
2566 SDValue Tmp = DAG.getNode(ISD::BITCAST, dl, floatVT, Op.getOperand(0));
2567 unsigned opcode = (OpVT == MVT::i32)? SPISD::ITOF : SPISD::XTOF;
2568 return DAG.getNode(opcode, dl, Op.getValueType(), Tmp);
2569}
2570
2572 const SparcTargetLowering &TLI,
2573 bool hasHardQuad) {
2574 EVT VT = Op.getValueType();
2575
2576 // Expand if it does not involve f128 or the target has support for
2577 // quad floating point instructions and the resulting type is legal.
2578 if (Op.getOperand(0).getValueType() != MVT::f128 ||
2579 (hasHardQuad && TLI.isTypeLegal(VT)))
2580 return SDValue();
2581
2582 assert(VT == MVT::i32 || VT == MVT::i64);
2583
2584 return TLI.LowerF128Op(
2585 Op, DAG,
2586 VT == MVT::i32 ? RTLIB::FPTOUINT_F128_I32 : RTLIB::FPTOUINT_F128_I64, 1);
2587}
2588
2590 const SparcTargetLowering &TLI,
2591 bool hasHardQuad) {
2592 EVT OpVT = Op.getOperand(0).getValueType();
2593 assert(OpVT == MVT::i32 || OpVT == MVT::i64);
2594
2595 // Expand if it does not involve f128 or the target has support for
2596 // quad floating point instructions and the operand type is legal.
2597 if (Op.getValueType() != MVT::f128 || (hasHardQuad && TLI.isTypeLegal(OpVT)))
2598 return SDValue();
2599
2600 return TLI.LowerF128Op(Op, DAG,
2601 OpVT == MVT::i32 ? RTLIB::UINTTOFP_I32_F128
2602 : RTLIB::UINTTOFP_I64_F128,
2603 1);
2604}
2605
2607 const SparcTargetLowering &TLI, bool hasHardQuad,
2608 bool isV9, bool is64Bit) {
2609 SDValue Chain = Op.getOperand(0);
2610 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
2611 SDValue LHS = Op.getOperand(2);
2612 SDValue RHS = Op.getOperand(3);
2613 SDValue Dest = Op.getOperand(4);
2614 SDLoc dl(Op);
2615 unsigned Opc, SPCC = ~0U;
2616
2617 // If this is a br_cc of a "setcc", and if the setcc got lowered into
2618 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
2620 assert(LHS.getValueType() == RHS.getValueType());
2621
2622 // Get the condition flag.
2623 SDValue CompareFlag;
2624 if (LHS.getValueType().isInteger()) {
2625 // On V9 processors running in 64-bit mode, if CC compares two `i64`s
2626 // and the RHS is zero we might be able to use a specialized branch.
2627 if (is64Bit && isV9 && LHS.getValueType() == MVT::i64 &&
2629 return DAG.getNode(SPISD::BR_REG, dl, MVT::Other, Chain, Dest,
2630 DAG.getConstant(intCondCCodeToRcond(CC), dl, MVT::i32),
2631 LHS);
2632
2633 CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
2634 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
2635 if (isV9)
2636 // 32-bit compares use the icc flags, 64-bit uses the xcc flags.
2637 Opc = LHS.getValueType() == MVT::i32 ? SPISD::BPICC : SPISD::BPXCC;
2638 else
2639 // Non-v9 targets don't have xcc.
2640 Opc = SPISD::BRICC;
2641 } else {
2642 if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
2643 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2644 CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
2645 Opc = isV9 ? SPISD::BPICC : SPISD::BRICC;
2646 } else {
2647 unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
2648 CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
2649 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2650 Opc = isV9 ? SPISD::BRFCC_V9 : SPISD::BRFCC;
2651 }
2652 }
2653 return DAG.getNode(Opc, dl, MVT::Other, Chain, Dest,
2654 DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
2655}
2656
2658 const SparcTargetLowering &TLI, bool hasHardQuad,
2659 bool isV9, bool is64Bit) {
2660 SDValue LHS = Op.getOperand(0);
2661 SDValue RHS = Op.getOperand(1);
2662 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
2663 SDValue TrueVal = Op.getOperand(2);
2664 SDValue FalseVal = Op.getOperand(3);
2665 SDLoc dl(Op);
2666 unsigned Opc, SPCC = ~0U;
2667
2668 // If this is a select_cc of a "setcc", and if the setcc got lowered into
2669 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
2671 assert(LHS.getValueType() == RHS.getValueType());
2672
2673 SDValue CompareFlag;
2674 if (LHS.getValueType().isInteger()) {
2675 // On V9 processors running in 64-bit mode, if CC compares two `i64`s
2676 // and the RHS is zero we might be able to use a specialized select.
2677 // All SELECT_CC between any two scalar integer types are eligible for
2678 // lowering to specialized instructions. Additionally, f32 and f64 types
2679 // are also eligible, but for f128 we can only use the specialized
2680 // instruction when we have hardquad.
2681 EVT ValType = TrueVal.getValueType();
2682 bool IsEligibleType = ValType.isScalarInteger() || ValType == MVT::f32 ||
2683 ValType == MVT::f64 ||
2684 (ValType == MVT::f128 && hasHardQuad);
2685 if (is64Bit && isV9 && LHS.getValueType() == MVT::i64 &&
2686 isNullConstant(RHS) && !ISD::isUnsignedIntSetCC(CC) && IsEligibleType)
2687 return DAG.getNode(
2688 SPISD::SELECT_REG, dl, TrueVal.getValueType(), TrueVal, FalseVal,
2689 DAG.getConstant(intCondCCodeToRcond(CC), dl, MVT::i32), LHS);
2690
2691 CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
2692 Opc = LHS.getValueType() == MVT::i32 ?
2693 SPISD::SELECT_ICC : SPISD::SELECT_XCC;
2694 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
2695 } else {
2696 if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
2697 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2698 CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
2699 Opc = SPISD::SELECT_ICC;
2700 } else {
2701 unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
2702 CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
2703 Opc = SPISD::SELECT_FCC;
2704 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2705 }
2706 }
2707 return DAG.getNode(Opc, dl, TrueVal.getValueType(), TrueVal, FalseVal,
2708 DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
2709}
2710
2712 const SparcTargetLowering &TLI) {
2715 auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
2716
2717 // Need frame address to find the address of VarArgsFrameIndex.
2719
2720 // vastart just stores the address of the VarArgsFrameIndex slot into the
2721 // memory location argument.
2722 SDLoc DL(Op);
2723 SDValue Offset =
2724 DAG.getNode(ISD::ADD, DL, PtrVT, DAG.getRegister(SP::I6, PtrVT),
2725 DAG.getIntPtrConstant(FuncInfo->getVarArgsFrameOffset(), DL));
2726 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
2727 return DAG.getStore(Op.getOperand(0), DL, Offset, Op.getOperand(1),
2728 MachinePointerInfo(SV));
2729}
2730
2732 SDNode *Node = Op.getNode();
2733 EVT VT = Node->getValueType(0);
2734 SDValue InChain = Node->getOperand(0);
2735 SDValue VAListPtr = Node->getOperand(1);
2736 EVT PtrVT = VAListPtr.getValueType();
2737 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
2738 SDLoc DL(Node);
2739 SDValue VAList =
2740 DAG.getLoad(PtrVT, DL, InChain, VAListPtr, MachinePointerInfo(SV));
2741 // Increment the pointer, VAList, to the next vaarg.
2742 SDValue NextPtr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
2744 DL));
2745 // Store the incremented VAList to the legalized pointer.
2746 InChain = DAG.getStore(VAList.getValue(1), DL, NextPtr, VAListPtr,
2747 MachinePointerInfo(SV));
2748 // Load the actual argument out of the pointer VAList.
2749 // We can't count on greater alignment than the word size.
2750 return DAG.getLoad(
2751 VT, DL, InChain, VAList, MachinePointerInfo(),
2752 Align(std::min(PtrVT.getFixedSizeInBits(), VT.getFixedSizeInBits()) / 8));
2753}
2754
2756 const SparcSubtarget &Subtarget) {
2757 SDValue Chain = Op.getOperand(0);
2758 EVT VT = Op->getValueType(0);
2759 SDLoc DL(Op);
2760
2761 MCRegister SPReg = SP::O6;
2762 SDValue SP = DAG.getCopyFromReg(Chain, DL, SPReg, VT);
2763
2764 // Unbias the stack pointer register.
2765 unsigned OffsetToStackStart = Subtarget.getStackPointerBias();
2766 // Move past the register save area: 8 in registers + 8 local registers.
2767 OffsetToStackStart += 16 * (Subtarget.is64Bit() ? 8 : 4);
2768 // Move past the struct return address slot (4 bytes) on SPARC 32-bit.
2769 if (!Subtarget.is64Bit())
2770 OffsetToStackStart += 4;
2771
2772 SDValue StackAddr = DAG.getNode(ISD::ADD, DL, VT, SP,
2773 DAG.getConstant(OffsetToStackStart, DL, VT));
2774 return DAG.getMergeValues({StackAddr, Chain}, DL);
2775}
2776
2778 const SparcSubtarget *Subtarget) {
2779 SDValue Chain = Op.getOperand(0);
2780 SDValue Size = Op.getOperand(1);
2781 SDValue Alignment = Op.getOperand(2);
2782 MaybeAlign MaybeAlignment =
2783 cast<ConstantSDNode>(Alignment)->getMaybeAlignValue();
2784 EVT VT = Size->getValueType(0);
2785 SDLoc dl(Op);
2786
2787 unsigned SPReg = SP::O6;
2788 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
2789
2790 // The resultant pointer needs to be above the register spill area
2791 // at the bottom of the stack.
2792 unsigned regSpillArea;
2793 if (Subtarget->is64Bit()) {
2794 regSpillArea = 128;
2795 } else {
2796 // On Sparc32, the size of the spill area is 92. Unfortunately,
2797 // that's only 4-byte aligned, not 8-byte aligned (the stack
2798 // pointer is 8-byte aligned). So, if the user asked for an 8-byte
2799 // aligned dynamic allocation, we actually need to add 96 to the
2800 // bottom of the stack, instead of 92, to ensure 8-byte alignment.
2801
2802 // That also means adding 4 to the size of the allocation --
2803 // before applying the 8-byte rounding. Unfortunately, we the
2804 // value we get here has already had rounding applied. So, we need
2805 // to add 8, instead, wasting a bit more memory.
2806
2807 // Further, this only actually needs to be done if the required
2808 // alignment is > 4, but, we've lost that info by this point, too,
2809 // so we always apply it.
2810
2811 // (An alternative approach would be to always reserve 96 bytes
2812 // instead of the required 92, but then we'd waste 4 extra bytes
2813 // in every frame, not just those with dynamic stack allocations)
2814
2815 // TODO: modify code in SelectionDAGBuilder to make this less sad.
2816
2817 Size = DAG.getNode(ISD::ADD, dl, VT, Size,
2818 DAG.getConstant(8, dl, VT));
2819 regSpillArea = 96;
2820 }
2821
2822 int64_t Bias = Subtarget->getStackPointerBias();
2823
2824 // Debias and increment SP past the reserved spill area.
2825 // We need the SP to point to the first usable region before calculating
2826 // anything to prevent any of the pointers from becoming out of alignment when
2827 // we rebias the SP later on.
2828 SDValue StartOfUsableStack = DAG.getNode(
2829 ISD::ADD, dl, VT, SP, DAG.getConstant(regSpillArea + Bias, dl, VT));
2830 SDValue AllocatedPtr =
2831 DAG.getNode(ISD::SUB, dl, VT, StartOfUsableStack, Size);
2832
2833 bool IsOveraligned = MaybeAlignment.has_value();
2834 SDValue AlignedPtr =
2835 IsOveraligned
2836 ? DAG.getNode(ISD::AND, dl, VT, AllocatedPtr,
2837 DAG.getSignedConstant(-MaybeAlignment->value(), dl, VT))
2838 : AllocatedPtr;
2839
2840 // Now that we are done, restore the bias and reserved spill area.
2841 SDValue NewSP = DAG.getNode(ISD::SUB, dl, VT, AlignedPtr,
2842 DAG.getConstant(regSpillArea + Bias, dl, VT));
2843 Chain = DAG.getCopyToReg(SP.getValue(1), dl, SPReg, NewSP);
2844 SDValue Ops[2] = {AlignedPtr, Chain};
2845 return DAG.getMergeValues(Ops, dl);
2846}
2847
2848
2850 SDLoc dl(Op);
2851 SDValue Chain = DAG.getNode(SPISD::FLUSHW,
2852 dl, MVT::Other, DAG.getEntryNode());
2853 return Chain;
2854}
2855
2857 const SparcSubtarget *Subtarget,
2858 bool AlwaysFlush = false) {
2860 MFI.setFrameAddressIsTaken(true);
2861
2862 EVT VT = Op.getValueType();
2863 SDLoc dl(Op);
2864 unsigned FrameReg = SP::I6;
2865 unsigned stackBias = Subtarget->getStackPointerBias();
2866
2867 SDValue FrameAddr;
2868 SDValue Chain;
2869
2870 // flush first to make sure the windowed registers' values are in stack
2871 Chain = (depth || AlwaysFlush) ? getFLUSHW(Op, DAG) : DAG.getEntryNode();
2872
2873 FrameAddr = DAG.getCopyFromReg(Chain, dl, FrameReg, VT);
2874
2875 unsigned Offset = (Subtarget->is64Bit()) ? (stackBias + 112) : 56;
2876
2877 while (depth--) {
2878 SDValue Ptr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
2879 DAG.getIntPtrConstant(Offset, dl));
2880 FrameAddr = DAG.getLoad(VT, dl, Chain, Ptr, MachinePointerInfo());
2881 }
2882 if (Subtarget->is64Bit())
2883 FrameAddr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
2884 DAG.getIntPtrConstant(stackBias, dl));
2885 return FrameAddr;
2886}
2887
2888
2890 const SparcSubtarget *Subtarget) {
2891
2892 uint64_t depth = Op.getConstantOperandVal(0);
2893
2894 return getFRAMEADDR(depth, Op, DAG, Subtarget);
2895
2896}
2897
2899 const SparcTargetLowering &TLI,
2900 const SparcSubtarget *Subtarget) {
2902 MachineFrameInfo &MFI = MF.getFrameInfo();
2903 MFI.setReturnAddressIsTaken(true);
2904
2905 EVT VT = Op.getValueType();
2906 SDLoc dl(Op);
2907 uint64_t depth = Op.getConstantOperandVal(0);
2908
2909 SDValue RetAddr;
2910 if (depth == 0) {
2911 auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
2912 Register RetReg = MF.addLiveIn(SP::I7, TLI.getRegClassFor(PtrVT));
2913 RetAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, RetReg, VT);
2914 return RetAddr;
2915 }
2916
2917 // Need frame address to find return address of the caller.
2918 SDValue FrameAddr = getFRAMEADDR(depth - 1, Op, DAG, Subtarget, true);
2919
2920 unsigned Offset = (Subtarget->is64Bit()) ? 120 : 60;
2921 SDValue Ptr = DAG.getNode(ISD::ADD,
2922 dl, VT,
2923 FrameAddr,
2924 DAG.getIntPtrConstant(Offset, dl));
2925 RetAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), Ptr, MachinePointerInfo());
2926
2927 return RetAddr;
2928}
2929
2930static SDValue LowerF64Op(SDValue SrcReg64, const SDLoc &dl, SelectionDAG &DAG,
2931 unsigned opcode) {
2932 assert(SrcReg64.getValueType() == MVT::f64 && "LowerF64Op called on non-double!");
2933 assert(opcode == ISD::FNEG || opcode == ISD::FABS);
2934
2935 // Lower fneg/fabs on f64 to fneg/fabs on f32.
2936 // fneg f64 => fneg f32:sub_even, fmov f32:sub_odd.
2937 // fabs f64 => fabs f32:sub_even, fmov f32:sub_odd.
2938
2939 // Note: in little-endian, the floating-point value is stored in the
2940 // registers are in the opposite order, so the subreg with the sign
2941 // bit is the highest-numbered (odd), rather than the
2942 // lowest-numbered (even).
2943
2944 SDValue Hi32 = DAG.getTargetExtractSubreg(SP::sub_even, dl, MVT::f32,
2945 SrcReg64);
2946 SDValue Lo32 = DAG.getTargetExtractSubreg(SP::sub_odd, dl, MVT::f32,
2947 SrcReg64);
2948
2949 if (DAG.getDataLayout().isLittleEndian())
2950 Lo32 = DAG.getNode(opcode, dl, MVT::f32, Lo32);
2951 else
2952 Hi32 = DAG.getNode(opcode, dl, MVT::f32, Hi32);
2953
2954 SDValue DstReg64 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
2955 dl, MVT::f64), 0);
2956 DstReg64 = DAG.getTargetInsertSubreg(SP::sub_even, dl, MVT::f64,
2957 DstReg64, Hi32);
2958 DstReg64 = DAG.getTargetInsertSubreg(SP::sub_odd, dl, MVT::f64,
2959 DstReg64, Lo32);
2960 return DstReg64;
2961}
2962
2963// Lower a f128 load into two f64 loads.
2965{
2966 SDLoc dl(Op);
2967 LoadSDNode *LdNode = cast<LoadSDNode>(Op.getNode());
2968 assert(LdNode->getOffset().isUndef() && "Unexpected node type");
2969
2970 Align Alignment = commonAlignment(LdNode->getBaseAlign(), 8);
2971
2972 SDValue Hi64 =
2973 DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LdNode->getBasePtr(),
2974 LdNode->getPointerInfo(), Alignment);
2975 EVT addrVT = LdNode->getBasePtr().getValueType();
2976 SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
2977 LdNode->getBasePtr(),
2978 DAG.getConstant(8, dl, addrVT));
2979 SDValue Lo64 = DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LoPtr,
2980 LdNode->getPointerInfo().getWithOffset(8),
2981 Alignment);
2982
2983 SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
2984 SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
2985
2986 SDNode *InFP128 = DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
2987 dl, MVT::f128);
2988 InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
2989 MVT::f128,
2990 SDValue(InFP128, 0),
2991 Hi64,
2992 SubRegEven);
2993 InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
2994 MVT::f128,
2995 SDValue(InFP128, 0),
2996 Lo64,
2997 SubRegOdd);
2998 SDValue OutChains[2] = { SDValue(Hi64.getNode(), 1),
2999 SDValue(Lo64.getNode(), 1) };
3000 SDValue OutChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
3001 SDValue Ops[2] = {SDValue(InFP128,0), OutChain};
3002 return DAG.getMergeValues(Ops, dl);
3003}
3004
3006{
3007 LoadSDNode *LdNode = cast<LoadSDNode>(Op.getNode());
3008
3009 EVT MemVT = LdNode->getMemoryVT();
3010 if (MemVT == MVT::f128)
3011 return LowerF128Load(Op, DAG);
3012
3013 return Op;
3014}
3015
3016// Lower a f128 store into two f64 stores.
3018 SDLoc dl(Op);
3019 StoreSDNode *StNode = cast<StoreSDNode>(Op.getNode());
3020 assert(StNode->getOffset().isUndef() && "Unexpected node type");
3021
3022 SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
3023 SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
3024
3025 SDNode *Hi64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3026 dl,
3027 MVT::f64,
3028 StNode->getValue(),
3029 SubRegEven);
3030 SDNode *Lo64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3031 dl,
3032 MVT::f64,
3033 StNode->getValue(),
3034 SubRegOdd);
3035
3036 Align Alignment = commonAlignment(StNode->getBaseAlign(), 8);
3037
3038 SDValue OutChains[2];
3039 OutChains[0] =
3040 DAG.getStore(StNode->getChain(), dl, SDValue(Hi64, 0),
3041 StNode->getBasePtr(), StNode->getPointerInfo(),
3042 Alignment);
3043 EVT addrVT = StNode->getBasePtr().getValueType();
3044 SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
3045 StNode->getBasePtr(),
3046 DAG.getConstant(8, dl, addrVT));
3047 OutChains[1] = DAG.getStore(StNode->getChain(), dl, SDValue(Lo64, 0), LoPtr,
3048 StNode->getPointerInfo().getWithOffset(8),
3049 Alignment);
3050 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
3051}
3052
3054{
3055 SDLoc dl(Op);
3056 StoreSDNode *St = cast<StoreSDNode>(Op.getNode());
3057
3058 EVT MemVT = St->getMemoryVT();
3059 if (MemVT == MVT::f128)
3060 return LowerF128Store(Op, DAG);
3061
3062 if (MemVT == MVT::i64) {
3063 // Custom handling for i64 stores: turn it into a bitcast and a
3064 // v2i32 store.
3065 SDValue Val = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, St->getValue());
3066 SDValue Chain = DAG.getStore(
3067 St->getChain(), dl, Val, St->getBasePtr(), St->getPointerInfo(),
3068 St->getBaseAlign(), St->getMemOperand()->getFlags(), St->getAAInfo());
3069 return Chain;
3070 }
3071
3072 return SDValue();
3073}
3074
3076 assert((Op.getOpcode() == ISD::FNEG || Op.getOpcode() == ISD::FABS)
3077 && "invalid opcode");
3078
3079 SDLoc dl(Op);
3080
3081 if (Op.getValueType() == MVT::f64)
3082 return LowerF64Op(Op.getOperand(0), dl, DAG, Op.getOpcode());
3083 if (Op.getValueType() != MVT::f128)
3084 return Op;
3085
3086 // Lower fabs/fneg on f128 to fabs/fneg on f64
3087 // fabs/fneg f128 => fabs/fneg f64:sub_even64, fmov f64:sub_odd64
3088 // (As with LowerF64Op, on little-endian, we need to negate the odd
3089 // subreg)
3090
3091 SDValue SrcReg128 = Op.getOperand(0);
3092 SDValue Hi64 = DAG.getTargetExtractSubreg(SP::sub_even64, dl, MVT::f64,
3093 SrcReg128);
3094 SDValue Lo64 = DAG.getTargetExtractSubreg(SP::sub_odd64, dl, MVT::f64,
3095 SrcReg128);
3096
3097 if (DAG.getDataLayout().isLittleEndian()) {
3098 if (isV9)
3099 Lo64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Lo64);
3100 else
3101 Lo64 = LowerF64Op(Lo64, dl, DAG, Op.getOpcode());
3102 } else {
3103 if (isV9)
3104 Hi64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Hi64);
3105 else
3106 Hi64 = LowerF64Op(Hi64, dl, DAG, Op.getOpcode());
3107 }
3108
3109 SDValue DstReg128 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
3110 dl, MVT::f128), 0);
3111 DstReg128 = DAG.getTargetInsertSubreg(SP::sub_even64, dl, MVT::f128,
3112 DstReg128, Hi64);
3113 DstReg128 = DAG.getTargetInsertSubreg(SP::sub_odd64, dl, MVT::f128,
3114 DstReg128, Lo64);
3115 return DstReg128;
3116}
3117
3119 if (isStrongerThanMonotonic(cast<AtomicSDNode>(Op)->getSuccessOrdering())) {
3120 // Expand with a fence.
3121 return SDValue();
3122 }
3123
3124 // Monotonic load/stores are legal.
3125 return Op;
3126}
3127
3129 SelectionDAG &DAG) const {
3130 unsigned IntNo = Op.getConstantOperandVal(0);
3131 switch (IntNo) {
3132 default: return SDValue(); // Don't custom lower most intrinsics.
3133 case Intrinsic::thread_pointer: {
3134 EVT PtrVT = getPointerTy(DAG.getDataLayout());
3135 return DAG.getRegister(SP::G7, PtrVT);
3136 }
3137 }
3138}
3139
3142
3143 bool hasHardQuad = Subtarget->hasHardQuad();
3144 bool isV9 = Subtarget->isV9();
3145 bool is64Bit = Subtarget->is64Bit();
3146
3147 switch (Op.getOpcode()) {
3148 default: llvm_unreachable("Should not custom lower this!");
3149
3150 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG, *this,
3151 Subtarget);
3152 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG,
3153 Subtarget);
3155 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
3156 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
3157 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
3158 case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG, *this,
3159 hasHardQuad);
3160 case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG, *this,
3161 hasHardQuad);
3162 case ISD::FP_TO_UINT: return LowerFP_TO_UINT(Op, DAG, *this,
3163 hasHardQuad);
3164 case ISD::UINT_TO_FP: return LowerUINT_TO_FP(Op, DAG, *this,
3165 hasHardQuad);
3166 case ISD::BR_CC:
3167 return LowerBR_CC(Op, DAG, *this, hasHardQuad, isV9, is64Bit);
3168 case ISD::SELECT_CC:
3169 return LowerSELECT_CC(Op, DAG, *this, hasHardQuad, isV9, is64Bit);
3170 case ISD::VASTART: return LowerVASTART(Op, DAG, *this);
3171 case ISD::VAARG: return LowerVAARG(Op, DAG);
3173 Subtarget);
3174 case ISD::STACKADDRESS:
3175 return LowerSTACKADDRESS(Op, DAG, *Subtarget);
3176
3177 case ISD::LOAD: return LowerLOAD(Op, DAG);
3178 case ISD::STORE: return LowerSTORE(Op, DAG);
3179 case ISD::FADD:
3180 return LowerF128Op(Op, DAG, RTLIB::ADD_F128, 2);
3181 case ISD::FSUB:
3182 return LowerF128Op(Op, DAG, RTLIB::SUB_F128, 2);
3183 case ISD::FMUL:
3184 return LowerF128Op(Op, DAG, RTLIB::MUL_F128, 2);
3185 case ISD::FDIV:
3186 return LowerF128Op(Op, DAG, RTLIB::DIV_F128, 2);
3187 case ISD::FSQRT:
3188 return LowerF128Op(Op, DAG, RTLIB::SQRT_F128, 1);
3189 case ISD::FABS:
3190 case ISD::FNEG: return LowerFNEGorFABS(Op, DAG, isV9);
3191 case ISD::FP_EXTEND: return LowerF128_FPEXTEND(Op, DAG, *this);
3192 case ISD::FP_ROUND: return LowerF128_FPROUND(Op, DAG, *this);
3193 case ISD::ATOMIC_LOAD:
3194 case ISD::ATOMIC_STORE: return LowerATOMIC_LOAD_STORE(Op, DAG);
3196 }
3197}
3198
3200 const SDLoc &DL,
3201 SelectionDAG &DAG) const {
3202 APInt V = C->getValueAPF().bitcastToAPInt();
3203 SDValue Lo = DAG.getConstant(V.zextOrTrunc(32), DL, MVT::i32);
3204 SDValue Hi = DAG.getConstant(V.lshr(32).zextOrTrunc(32), DL, MVT::i32);
3205 if (DAG.getDataLayout().isLittleEndian())
3206 std::swap(Lo, Hi);
3207 return DAG.getBuildVector(MVT::v2i32, DL, {Hi, Lo});
3208}
3209
3211 DAGCombinerInfo &DCI) const {
3212 SDLoc dl(N);
3213 SDValue Src = N->getOperand(0);
3214
3215 if (isa<ConstantFPSDNode>(Src) && N->getSimpleValueType(0) == MVT::v2i32 &&
3216 Src.getSimpleValueType() == MVT::f64)
3218
3219 return SDValue();
3220}
3221
3223 DAGCombinerInfo &DCI) const {
3224 switch (N->getOpcode()) {
3225 default:
3226 break;
3227 case ISD::BITCAST:
3228 return PerformBITCASTCombine(N, DCI);
3229 }
3230 return SDValue();
3231}
3232
3235 MachineBasicBlock *BB) const {
3236 switch (MI.getOpcode()) {
3237 default: llvm_unreachable("Unknown SELECT_CC!");
3238 case SP::SELECT_CC_Int_ICC:
3239 case SP::SELECT_CC_FP_ICC:
3240 case SP::SELECT_CC_DFP_ICC:
3241 case SP::SELECT_CC_QFP_ICC:
3242 if (Subtarget->isV9())
3243 return expandSelectCC(MI, BB, SP::BPICC);
3244 return expandSelectCC(MI, BB, SP::BCOND);
3245 case SP::SELECT_CC_Int_XCC:
3246 case SP::SELECT_CC_FP_XCC:
3247 case SP::SELECT_CC_DFP_XCC:
3248 case SP::SELECT_CC_QFP_XCC:
3249 return expandSelectCC(MI, BB, SP::BPXCC);
3250 case SP::SELECT_CC_Int_FCC:
3251 case SP::SELECT_CC_FP_FCC:
3252 case SP::SELECT_CC_DFP_FCC:
3253 case SP::SELECT_CC_QFP_FCC:
3254 if (Subtarget->isV9())
3255 return expandSelectCC(MI, BB, SP::FBCOND_V9);
3256 return expandSelectCC(MI, BB, SP::FBCOND);
3257 }
3258}
3259
3262 unsigned BROpcode) const {
3263 const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
3264 DebugLoc dl = MI.getDebugLoc();
3265 unsigned CC = (SPCC::CondCodes)MI.getOperand(3).getImm();
3266
3267 // To "insert" a SELECT_CC instruction, we actually have to insert the
3268 // triangle control-flow pattern. The incoming instruction knows the
3269 // destination vreg to set, the condition code register to branch on, the
3270 // true/false values to select between, and the condition code for the branch.
3271 //
3272 // We produce the following control flow:
3273 // ThisMBB
3274 // | \
3275 // | IfFalseMBB
3276 // | /
3277 // SinkMBB
3278 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3280
3281 MachineBasicBlock *ThisMBB = BB;
3282 MachineFunction *F = BB->getParent();
3283 MachineBasicBlock *IfFalseMBB = F->CreateMachineBasicBlock(LLVM_BB);
3284 MachineBasicBlock *SinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
3285 F->insert(It, IfFalseMBB);
3286 F->insert(It, SinkMBB);
3287
3288 // Transfer the remainder of ThisMBB and its successor edges to SinkMBB.
3289 SinkMBB->splice(SinkMBB->begin(), ThisMBB,
3290 std::next(MachineBasicBlock::iterator(MI)), ThisMBB->end());
3291 SinkMBB->transferSuccessorsAndUpdatePHIs(ThisMBB);
3292
3293 // Set the new successors for ThisMBB.
3294 ThisMBB->addSuccessor(IfFalseMBB);
3295 ThisMBB->addSuccessor(SinkMBB);
3296
3297 BuildMI(ThisMBB, dl, TII.get(BROpcode))
3298 .addMBB(SinkMBB)
3299 .addImm(CC);
3300
3301 // IfFalseMBB just falls through to SinkMBB.
3302 IfFalseMBB->addSuccessor(SinkMBB);
3303
3304 // %Result = phi [ %TrueValue, ThisMBB ], [ %FalseValue, IfFalseMBB ]
3305 BuildMI(*SinkMBB, SinkMBB->begin(), dl, TII.get(SP::PHI),
3306 MI.getOperand(0).getReg())
3307 .addReg(MI.getOperand(1).getReg())
3308 .addMBB(ThisMBB)
3309 .addReg(MI.getOperand(2).getReg())
3310 .addMBB(IfFalseMBB);
3311
3312 MI.eraseFromParent(); // The pseudo instruction is gone now.
3313 return SinkMBB;
3314}
3315
3316//===----------------------------------------------------------------------===//
3317// Sparc Inline Assembly Support
3318//===----------------------------------------------------------------------===//
3319
3320/// getConstraintType - Given a constraint letter, return the type of
3321/// constraint it is for this target.
3324 if (Constraint.size() == 1) {
3325 switch (Constraint[0]) {
3326 default: break;
3327 case 'r':
3328 case 'f':
3329 case 'e':
3330 return C_RegisterClass;
3331 case 'I': // SIMM13
3332 return C_Immediate;
3333 }
3334 }
3335
3336 return TargetLowering::getConstraintType(Constraint);
3337}
3338
3341 const char *constraint) const {
3343 Value *CallOperandVal = info.CallOperandVal;
3344 // If we don't have a value, we can't do a match,
3345 // but allow it at the lowest weight.
3346 if (!CallOperandVal)
3347 return CW_Default;
3348
3349 // Look at the constraint type.
3350 switch (*constraint) {
3351 default:
3353 break;
3354 case 'I': // SIMM13
3355 if (ConstantInt *C = dyn_cast<ConstantInt>(info.CallOperandVal)) {
3356 if (isInt<13>(C->getSExtValue()))
3357 weight = CW_Constant;
3358 }
3359 break;
3360 }
3361 return weight;
3362}
3363
3364/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
3365/// vector. If it is invalid, don't add anything to Ops.
3367 SDValue Op, StringRef Constraint, std::vector<SDValue> &Ops,
3368 SelectionDAG &DAG) const {
3369 SDValue Result;
3370
3371 // Only support length 1 constraints for now.
3372 if (Constraint.size() > 1)
3373 return;
3374
3375 char ConstraintLetter = Constraint[0];
3376 switch (ConstraintLetter) {
3377 default: break;
3378 case 'I':
3380 if (isInt<13>(C->getSExtValue())) {
3381 Result = DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op),
3382 Op.getValueType());
3383 break;
3384 }
3385 return;
3386 }
3387 }
3388
3389 if (Result.getNode()) {
3390 Ops.push_back(Result);
3391 return;
3392 }
3394}
3395
3396std::pair<unsigned, const TargetRegisterClass *>
3398 StringRef Constraint,
3399 MVT VT) const {
3400 if (Constraint.empty())
3401 return std::make_pair(0U, nullptr);
3402
3403 if (Constraint.size() == 1) {
3404 switch (Constraint[0]) {
3405 case 'r':
3406 if (VT == MVT::v2i32)
3407 return std::make_pair(0U, &SP::IntPairRegClass);
3408 else if (Subtarget->is64Bit())
3409 return std::make_pair(0U, &SP::I64RegsRegClass);
3410 else
3411 return std::make_pair(0U, &SP::IntRegsRegClass);
3412 case 'f':
3413 if (VT == MVT::f32 || VT == MVT::i32)
3414 return std::make_pair(0U, &SP::FPRegsRegClass);
3415 else if (VT == MVT::f64 || VT == MVT::i64)
3416 return std::make_pair(0U, &SP::LowDFPRegsRegClass);
3417 else if (VT == MVT::f128)
3418 return std::make_pair(0U, &SP::LowQFPRegsRegClass);
3419 // This will generate an error message
3420 return std::make_pair(0U, nullptr);
3421 case 'e':
3422 if (VT == MVT::f32 || VT == MVT::i32)
3423 return std::make_pair(0U, &SP::FPRegsRegClass);
3424 else if (VT == MVT::f64 || VT == MVT::i64 )
3425 return std::make_pair(0U, &SP::DFPRegsRegClass);
3426 else if (VT == MVT::f128)
3427 return std::make_pair(0U, &SP::QFPRegsRegClass);
3428 // This will generate an error message
3429 return std::make_pair(0U, nullptr);
3430 }
3431 }
3432
3433 if (Constraint.front() != '{')
3434 return std::make_pair(0U, nullptr);
3435
3436 assert(Constraint.back() == '}' && "Not a brace enclosed constraint?");
3437 StringRef RegName(Constraint.data() + 1, Constraint.size() - 2);
3438 if (RegName.empty())
3439 return std::make_pair(0U, nullptr);
3440
3441 unsigned long long RegNo;
3442 // Handle numbered register aliases.
3443 if (RegName[0] == 'r' &&
3444 getAsUnsignedInteger(RegName.begin() + 1, 10, RegNo)) {
3445 // r0-r7 -> g0-g7
3446 // r8-r15 -> o0-o7
3447 // r16-r23 -> l0-l7
3448 // r24-r31 -> i0-i7
3449 if (RegNo > 31)
3450 return std::make_pair(0U, nullptr);
3451 const char RegTypes[] = {'g', 'o', 'l', 'i'};
3452 char RegType = RegTypes[RegNo / 8];
3453 char RegIndex = '0' + (RegNo % 8);
3454 char Tmp[] = {'{', RegType, RegIndex, '}', 0};
3455 return getRegForInlineAsmConstraint(TRI, Tmp, VT);
3456 }
3457
3458 // Rewrite the fN constraint according to the value type if needed.
3459 if (VT != MVT::f32 && VT != MVT::Other && RegName[0] == 'f' &&
3460 getAsUnsignedInteger(RegName.begin() + 1, 10, RegNo)) {
3461 if (VT == MVT::f64 && (RegNo % 2 == 0)) {
3463 TRI, StringRef("{d" + utostr(RegNo / 2) + "}"), VT);
3464 } else if (VT == MVT::f128 && (RegNo % 4 == 0)) {
3466 TRI, StringRef("{q" + utostr(RegNo / 4) + "}"), VT);
3467 } else {
3468 return std::make_pair(0U, nullptr);
3469 }
3470 }
3471
3472 auto ResultPair =
3474 if (!ResultPair.second)
3475 return std::make_pair(0U, nullptr);
3476
3477 // Force the use of I64Regs over IntRegs for 64-bit values.
3478 if (Subtarget->is64Bit() && VT == MVT::i64) {
3479 assert(ResultPair.second == &SP::IntRegsRegClass &&
3480 "Unexpected register class");
3481 return std::make_pair(ResultPair.first, &SP::I64RegsRegClass);
3482 }
3483
3484 return ResultPair;
3485}
3486
3487bool
3489 // The Sparc target isn't yet aware of offsets.
3490 return false;
3491}
3492
3495 SelectionDAG &DAG) const {
3496
3497 SDLoc dl(N);
3498
3499 RTLIB::Libcall libCall = RTLIB::UNKNOWN_LIBCALL;
3500
3501 switch (N->getOpcode()) {
3502 default:
3503 llvm_unreachable("Do not know how to custom type legalize this operation!");
3504
3505 case ISD::FP_TO_SINT:
3506 case ISD::FP_TO_UINT:
3507 // Custom lower only if it involves f128 or i64.
3508 if (N->getOperand(0).getValueType() != MVT::f128
3509 || N->getValueType(0) != MVT::i64)
3510 return;
3511 libCall = ((N->getOpcode() == ISD::FP_TO_SINT)
3512 ? RTLIB::FPTOSINT_F128_I64
3513 : RTLIB::FPTOUINT_F128_I64);
3514
3515 Results.push_back(LowerF128Op(SDValue(N, 0), DAG, libCall, 1));
3516 return;
3517 case ISD::READCYCLECOUNTER: {
3518 assert(Subtarget->hasLeonCycleCounter());
3519 SDValue Lo = DAG.getCopyFromReg(N->getOperand(0), dl, SP::ASR23, MVT::i32);
3520 SDValue Hi = DAG.getCopyFromReg(Lo, dl, SP::G0, MVT::i32);
3521 SDValue Ops[] = { Lo, Hi };
3522 SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Ops);
3523 Results.push_back(Pair);
3524 Results.push_back(N->getOperand(0));
3525 return;
3526 }
3527 case ISD::SINT_TO_FP:
3528 case ISD::UINT_TO_FP:
3529 // Custom lower only if it involves f128 or i64.
3530 if (N->getValueType(0) != MVT::f128
3531 || N->getOperand(0).getValueType() != MVT::i64)
3532 return;
3533
3534 libCall = ((N->getOpcode() == ISD::SINT_TO_FP)
3535 ? RTLIB::SINTTOFP_I64_F128
3536 : RTLIB::UINTTOFP_I64_F128);
3537
3538 Results.push_back(LowerF128Op(SDValue(N, 0), DAG, libCall, 1));
3539 return;
3540 case ISD::LOAD: {
3542 // Custom handling only for i64: turn i64 load into a v2i32 load,
3543 // and a bitcast.
3544 if (Ld->getValueType(0) != MVT::i64 || Ld->getMemoryVT() != MVT::i64)
3545 return;
3546
3547 SDLoc dl(N);
3548 SDValue LoadRes = DAG.getExtLoad(
3549 Ld->getExtensionType(), dl, MVT::v2i32, Ld->getChain(),
3550 Ld->getBasePtr(), Ld->getPointerInfo(), MVT::v2i32, Ld->getBaseAlign(),
3551 Ld->getMemOperand()->getFlags(), Ld->getAAInfo());
3552
3553 SDValue Res = DAG.getNode(ISD::BITCAST, dl, MVT::i64, LoadRes);
3554 Results.push_back(Res);
3555 Results.push_back(LoadRes.getValue(1));
3556 return;
3557 }
3558 }
3559}
3560
3561// Override to enable LOAD_STACK_GUARD lowering on Linux.
3563 if (!Subtarget->getTargetTriple().isOSLinux())
3565 return true;
3566}
3567
3569 if (Subtarget->isVIS3())
3570 return VT == MVT::f32 || VT == MVT::f64;
3571 return false;
3572}
3573
3575 bool ForCodeSize) const {
3576 if (VT != MVT::f32 && VT != MVT::f64)
3577 return false;
3578 if (Subtarget->isVIS() && Imm.isZero())
3579 return true;
3580 if (Subtarget->isVIS3())
3581 return Imm.isExactlyValue(+0.5) || Imm.isExactlyValue(-0.5) ||
3582 Imm.getExactLog2Abs() == -1;
3583 return false;
3584}
3585
3586bool SparcTargetLowering::isCtlzFast() const { return Subtarget->isVIS3(); }
3587
3589 // We lack native cttz, however,
3590 // On 64-bit targets it is cheap to implement it in terms of popc.
3591 if (Subtarget->is64Bit() && Subtarget->usePopc())
3592 return true;
3593 // Otherwise, implementing cttz in terms of ctlz is still cheap.
3594 return isCheapToSpeculateCtlz(Ty);
3595}
3596
3598 EVT VT) const {
3599 return Subtarget->isUA2007() && !Subtarget->useSoftFloat();
3600}
3601
3603 SDNode *Node) const {
3604 assert(MI.getOpcode() == SP::SUBCCrr || MI.getOpcode() == SP::SUBCCri);
3605 // If the result is dead, replace it with %g0.
3606 if (!Node->hasAnyUseOfValue(0))
3607 MI.getOperand(0).setReg(SP::G0);
3608}
3609
3611 Instruction *Inst,
3612 AtomicOrdering Ord) const {
3613 bool HasStoreSemantics =
3615 if (HasStoreSemantics && isReleaseOrStronger(Ord))
3616 return Builder.CreateFence(AtomicOrdering::Release);
3617 return nullptr;
3618}
3619
3621 Instruction *Inst,
3622 AtomicOrdering Ord) const {
3623 // V8 loads already come with implicit acquire barrier so there's no need to
3624 // emit it again.
3625 bool HasLoadSemantics = isa<AtomicCmpXchgInst, AtomicRMWInst, LoadInst>(Inst);
3626 if (Subtarget->isV9() && HasLoadSemantics && isAcquireOrStronger(Ord))
3627 return Builder.CreateFence(AtomicOrdering::Acquire);
3628
3629 // SC plain stores would need a trailing full barrier.
3631 return Builder.CreateFence(Ord);
3632 return nullptr;
3633}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define RegName(no)
static LPCC::CondCode IntCondCCodeToICC(SDValue CC, const SDLoc &DL, SDValue &RHS, SelectionDAG &DAG)
lazy value info
#define F(x, y, z)
Definition MD5.cpp:54
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
static constexpr MCPhysReg SPReg
static SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
static bool CC_Sparc_Assign_Ret_Split_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
static bool CC_Sparc_Assign_Split_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue getFRAMEADDR(uint64_t depth, SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget, bool AlwaysFlush=false)
static unsigned toCallerWindow(unsigned Reg)
static SDValue LowerSTACKADDRESS(SDValue Op, SelectionDAG &DAG, const SparcSubtarget &Subtarget)
static SDValue LowerF128Store(SDValue Op, SelectionDAG &DAG)
static SPCC::CondCodes intCondCCodeToRcond(ISD::CondCode CC)
intCondCCodeToRcond - Convert a DAG integer condition code to a SPARC rcond condition.
static SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG)
static void fixupVariableFloatArgs(SmallVectorImpl< CCValAssign > &ArgLocs, ArrayRef< ISD::OutputArg > Outs)
static SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC)
FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC FCC condition.
static bool isAnyArgRegReserved(const SparcRegisterInfo *TRI, const MachineFunction &MF)
static SDValue getFLUSHW(SDValue Op, SelectionDAG &DAG)
static bool hasReturnsTwiceAttr(SelectionDAG &DAG, SDValue Callee, const CallBase *Call)
static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
static SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
static SDValue LowerF128_FPROUND(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
static SDValue LowerF64Op(SDValue SrcReg64, const SDLoc &dl, SelectionDAG &DAG, unsigned opcode)
static bool RetCC_Sparc64_Full(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad, bool isV9, bool is64Bit)
static void emitReservedArgRegCallError(const MachineFunction &MF)
static SDValue LowerATOMIC_LOAD_STORE(SDValue Op, SelectionDAG &DAG)
static bool RetCC_Sparc64_Half(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad, bool isV9, bool is64Bit)
static SDValue LowerF128_FPEXTEND(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
static SDValue LowerFNEGorFABS(SDValue Op, SelectionDAG &DAG, bool isV9)
static SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG)
static bool CC_Sparc64_Half(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static bool CC_Sparc64_Full(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static bool CC_Sparc_Assign_SRet(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static bool Analyze_CC_Sparc64_Half(bool IsReturn, unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue LowerF128Load(SDValue Op, SelectionDAG &DAG)
static SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, const SparcSubtarget *Subtarget)
static SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG)
static void LookThroughSetCC(SDValue &LHS, SDValue &RHS, ISD::CondCode CC, unsigned &SPCC)
static bool Analyze_CC_Sparc64_Full(bool IsReturn, unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
This file contains some functions that are useful when dealing with strings.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This file describes how to lower LLVM code to machine code.
static bool is64Bit(const char *name)
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
an instruction that atomically reads a memory location, combines it with another value,...
BinOp getOperation() const
LLVM Basic Block Representation.
Definition BasicBlock.h:62
CCState - This class holds information needed while lowering arguments and return values.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
LLVM_ABI void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
LLVM_ABI bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
LLVM_ABI void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
LLVM_ABI void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
LocInfo getLocInfo() const
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP)
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
bool needsCustom() const
bool isExtInLoc() const
int64_t getLocMemOffset() const
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
bool isLittleEndian() const
Layout endianness...
Definition DataLayout.h:217
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
A debug info location.
Definition DebugLoc.h:124
Diagnostic information for unsupported feature in backend.
const Function & getFunction() const
Definition Function.h:166
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition Function.h:695
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:724
const GlobalValue * getGlobal() const
Module * getParent()
Get the module that this global value is contained inside of...
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall.
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Return the lowering's selection of implementation call for Call.
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
static auto integer_fixedlen_vector_valuetypes()
static auto integer_valuetypes()
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static MVT getIntegerVT(unsigned BitWidth)
static auto fp_valuetypes()
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
void setFrameAddressIsTaken(bool T)
void setHasTailCall(bool V=true)
void setReturnAddressIsTaken(bool s)
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
Flags getFlags() const
Return the raw flags of the source value,.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Align getBaseAlign() const
Returns alignment and volatility of the memory access.
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
bool isUndef() const
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align DstAlign, Align SrcAlign, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
LLVM_ABI SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
const TargetMachine & getTarget() const
const LibcallLoweringInfo & getLibcalls() const
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
MachineFunction & getMachineFunction() const
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVM_ABI KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask)
LLVMContext * getContext() const
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
LLVM_ABI SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment)
Create a stack temporary based on the size in bytes and the alignment.
SDValue getTargetConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
LLVM_ABI SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand, SDValue Subreg)
A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
int64_t getStackPointerBias() const
The 64-bit ABI uses biased stack and frame pointers, so the stack frame of the current function is th...
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context, const Type *RetTy) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
bool useSoftFloat() const override
SDValue bitcastConstantFPToInt(ConstantFPSDNode *C, const SDLoc &DL, SelectionDAG &DAG) const
MachineBasicBlock * expandSelectCC(MachineInstr &MI, MachineBasicBlock *BB, unsigned BROpcode) const
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns true if the target can instruction select the specified FP immediate natively.
ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const override
Examine constraint string and operand type and determine a weight value.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
bool isCtlzFast() const override
Return true if ctlz instruction is fast.
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target.
SDValue LowerFormalArguments_32(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const
LowerFormalArguments32 - V8 uses a very simple ABI, where all values are passed in either one or two ...
bool isCheapToSpeculateCtlz(Type *Ty) const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
bool isCheapToSpeculateCttz(Type *Ty) const override
Return true if it is cheap to speculate a call to intrinsic cttz.
bool IsEligibleForTailCallOptimization(CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF) const
IsEligibleForTailCallOptimization - Check whether the call is eligible for tail call optimization.
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
bool isFNegFree(EVT VT) const override
Return true if an fneg operation is free to the point where it is never worthwhile to replace it with...
SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args, SDValue Arg, const SDLoc &DL, SelectionDAG &DAG) const
SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF, SelectionDAG &DAG) const
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
Inserts in the IR a target-specific intrinsic specifying a fence.
void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const override
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag.
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
computeKnownBitsForTargetNode - Determine which of the bits specified in Mask are known to be either ...
SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const
bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT VT) const override
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
SDValue LowerReturn_32(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
SDValue PerformBITCASTCombine(SDNode *N, DAGCombinerInfo &DCI) const
SDValue LowerReturn_64(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const
SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG, RTLIB::Libcall LibFunc, unsigned numArgs) const
SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
getSetCCResultType - Return the ISD::SETCC ValueType
SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const
bool useLoadStackGuardNode(const Module &M) const override
Override to support customized stack guard loading.
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFormalArguments_64(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const
SparcTargetLowering(const TargetMachine &TM, const SparcSubtarget &STI)
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
LowerAsmOperandForConstraint - Lower the specified operand into the Ops vector.
Register getRegisterByName(const char *RegName, LLT VT, const MachineFunction &MF) const override
Return the register ID of the name passed in.
SDValue LowerF128Compare(SDValue LHS, SDValue RHS, unsigned &SPCC, const SDLoc &DL, SelectionDAG &DAG) const
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
This class is used to represent ISD::STORE nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
const SDValue & getValue() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
char back() const
Get the last character in the string.
Definition StringRef.h:153
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
char front() const
Get the first character in the string.
Definition StringRef.h:147
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
TargetInstrInfo - Interface to description of machine instruction set.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
bool PredictableSelectIsExpensive
Tells the code generator that select is more expensive than a branch if the branch is usually predict...
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
const TargetMachine & getTargetMachine() const
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
bool isJumpExpensive() const
Return true if Flow Control is an expensive operation that should be avoided.
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
void setMinFunctionAlignment(Align Alignment)
Set the target's minimum function alignment.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
Sets the minimum cmpxchg or ll/sc size supported by the backend.
void setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
std::vector< ArgListEntry > ArgListTy
void setJumpIsExpensive(bool isExpensive=true)
Tells the code generator not to expand logic operations on comparison predicates into separate sequen...
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA, SelectionDAG &DAG) const
Lower TLS global address SDNode for target independent emulated TLS model.
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
bool isPositionIndependent() const
virtual ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const
Examine constraint string and operand type and determine a weight value.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
TargetLowering(const TargetLowering &)=delete
virtual bool useLoadStackGuardNode(const Module &M) const
If this function returns true, SelectionDAGBuilder emits a LOAD_STACK_GUARD node when it is lowering ...
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
Primary interface to the complete machine description for the target machine.
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:309
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:282
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition Type.h:164
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:197
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
self_iterator getIterator()
Definition ilist_node.h:123
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:823
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:275
@ STACKADDRESS
STACKADDRESS - Represents the llvm.stackaddress intrinsic.
Definition ISDOpcodes.h:127
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:783
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:294
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:264
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:857
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:518
@ GlobalAddress
Definition ISDOpcodes.h:88
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:884
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:417
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:280
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition ISDOpcodes.h:997
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition ISDOpcodes.h:254
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ GlobalTLSAddress
Definition ISDOpcodes.h:89
@ CTLZ_ZERO_POISON
Definition ISDOpcodes.h:792
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:848
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ BR_CC
BR_CC - Conditional branch.
@ BRIND
BRIND - Indirect branch.
@ BR_JT
BR_JT - Jumptable branch.
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:800
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ UNDEF
UNDEF - An undefined node.
Definition ISDOpcodes.h:233
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition ISDOpcodes.h:230
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:704
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:769
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:576
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:854
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:815
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition ISDOpcodes.h:892
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition ISDOpcodes.h:982
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition ISDOpcodes.h:110
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:930
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:739
@ TRAP
TRAP - Trapping instruction.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition ISDOpcodes.h:205
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:304
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition ISDOpcodes.h:565
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:53
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
@ CTTZ_ZERO_POISON
Bit counting operators with a poisoned result for zero inputs.
Definition ISDOpcodes.h:791
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition ISDOpcodes.h:963
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:860
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
@ BRCOND
BRCOND - Conditional branch.
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition ISDOpcodes.h:837
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:62
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:534
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:556
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
bool isUnsignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs an unsigned comparison when used with intege...
@ FCC_ULE
Definition Sparc.h:74
@ FCC_UG
Definition Sparc.h:64
@ ICC_G
Definition Sparc.h:46
@ REG_LEZ
Definition Sparc.h:97
@ ICC_L
Definition Sparc.h:49
@ FCC_NE
Definition Sparc.h:68
@ ICC_CS
Definition Sparc.h:53
@ FCC_LG
Definition Sparc.h:67
@ ICC_LEU
Definition Sparc.h:51
@ FCC_LE
Definition Sparc.h:73
@ ICC_LE
Definition Sparc.h:47
@ FCC_U
Definition Sparc.h:62
@ ICC_GE
Definition Sparc.h:48
@ FCC_E
Definition Sparc.h:69
@ REG_LZ
Definition Sparc.h:98
@ FCC_L
Definition Sparc.h:65
@ ICC_GU
Definition Sparc.h:50
@ FCC_O
Definition Sparc.h:75
@ ICC_NE
Definition Sparc.h:44
@ FCC_UE
Definition Sparc.h:70
@ REG_NZ
Definition Sparc.h:99
@ ICC_E
Definition Sparc.h:45
@ FCC_GE
Definition Sparc.h:71
@ FCC_UGE
Definition Sparc.h:72
@ REG_Z
Definition Sparc.h:96
@ ICC_CC
Definition Sparc.h:52
@ REG_GEZ
Definition Sparc.h:101
@ FCC_G
Definition Sparc.h:63
@ FCC_UL
Definition Sparc.h:66
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1668
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isStrongerThanMonotonic(AtomicOrdering AO)
std::string utostr(uint64_t X, bool isNeg=false)
bool isReleaseOrStronger(AtomicOrdering AO)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1745
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
AtomicOrdering
Atomic ordering for LLVM's memory model.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
bool isAcquireOrStronger(AtomicOrdering AO)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:862
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition ValueTypes.h:90
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition ValueTypes.h:418
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:396
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition ValueTypes.h:61
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition ValueTypes.h:404
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:176
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
void resetAll()
Resets the known state of all bits.
Definition KnownBits.h:72
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition KnownBits.h:325
This class contains a discriminated union of information about pointers in memory operands,...
MachinePointerInfo getWithOffset(int64_t O) const
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This contains information for each constraint that we are lowering.
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
SmallVector< ISD::OutputArg, 32 > Outs
CallLoweringInfo & setChain(SDValue InChain)
CallLoweringInfo & setCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList, AttributeSet ResultAttrs={})