LLVM 24.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#define GET_CALLING_CONV_IMPL
227#include "SparcGenCallingConv.inc"
228
229// The calling conventions in SparcCallingConv.td are described in terms of the
230// callee's register window. This function translates registers to the
231// corresponding caller window %o register.
232static unsigned toCallerWindow(unsigned Reg) {
233 static_assert(SP::I0 + 7 == SP::I7 && SP::O0 + 7 == SP::O7,
234 "Unexpected enum");
235 if (Reg >= SP::I0 && Reg <= SP::I7)
236 return Reg - SP::I0 + SP::O0;
237 return Reg;
238}
239
241 CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
242 const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
243 const Type *RetTy) const {
245 CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
246 return CCInfo.CheckReturn(Outs, Subtarget->is64Bit() ? RetCC_Sparc64
247 : RetCC_Sparc32);
248}
249
252 bool IsVarArg,
254 const SmallVectorImpl<SDValue> &OutVals,
255 const SDLoc &DL, SelectionDAG &DAG) const {
256 if (Subtarget->is64Bit())
257 return LowerReturn_64(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
258 return LowerReturn_32(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
259}
260
263 bool IsVarArg,
265 const SmallVectorImpl<SDValue> &OutVals,
266 const SDLoc &DL, SelectionDAG &DAG) const {
268
269 // CCValAssign - represent the assignment of the return value to locations.
271
272 // CCState - Info about the registers and stack slot.
273 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
274 *DAG.getContext());
275
276 // Analyze return values.
277 CCInfo.AnalyzeReturn(Outs, RetCC_Sparc32);
278
279 SDValue Glue;
280 SmallVector<SDValue, 4> RetOps(1, Chain);
281 // Make room for the return address offset.
282 RetOps.push_back(SDValue());
283
284 // Copy the result values into the output registers.
285 for (unsigned i = 0, realRVLocIdx = 0;
286 i != RVLocs.size();
287 ++i, ++realRVLocIdx) {
288 CCValAssign &VA = RVLocs[i];
289 assert(VA.isRegLoc() && "Can only return in registers!");
290
291 SDValue Arg = OutVals[realRVLocIdx];
292
293 if (VA.needsCustom()) {
294 assert(VA.getLocVT() == MVT::v2i32);
295 // Legalize ret v2i32 -> ret 2 x i32 (Basically: do what would
296 // happen by default if this wasn't a legal type)
297
298 SDValue Part0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32,
299 Arg,
301 SDValue Part1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32,
302 Arg,
304
305 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part0, Glue);
306 Glue = Chain.getValue(1);
307 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
308 VA = RVLocs[++i]; // skip ahead to next loc
309 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part1,
310 Glue);
311 } else
312 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Arg, Glue);
313
314 // Guarantee that all emitted copies are stuck together with flags.
315 Glue = Chain.getValue(1);
316 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
317 }
318
319 unsigned RetAddrOffset = 8; // Call Inst + Delay Slot
320 // If the function returns a struct, copy the SRetReturnReg to I0. This
321 // covers both an explicit sret parameter and a return value that was
322 // demoted to sret because it does not fit in the return registers.
324 if (Register Reg = SFI->getSRetReturnReg()) {
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
331 // A zero-sized return value, e.g. an empty struct or union, is returned
332 // without an unimp instruction after the call, so there is nothing for the
333 // return to skip over.
334 const Function &F = MF.getFunction();
335 Type *RetType =
336 F.hasStructRetAttr() ? F.getParamStructRetType(0) : F.getReturnType();
337 if (!RetType->isEmptyTy())
338 RetAddrOffset = 12; // CallInst + Delay Slot + Unimp
339 }
340
341 RetOps[0] = Chain; // Update chain.
342 RetOps[1] = DAG.getConstant(RetAddrOffset, DL, MVT::i32);
343
344 // Add the glue if we have it.
345 if (Glue.getNode())
346 RetOps.push_back(Glue);
347
348 return DAG.getNode(SPISD::RET_GLUE, DL, MVT::Other, RetOps);
349}
350
351// Lower return values for the 64-bit ABI.
352// Return values are passed the exactly the same way as function arguments.
355 bool IsVarArg,
357 const SmallVectorImpl<SDValue> &OutVals,
358 const SDLoc &DL, SelectionDAG &DAG) const {
359 // CCValAssign - represent the assignment of the return value to locations.
361
362 // CCState - Info about the registers and stack slot.
363 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
364 *DAG.getContext());
365
366 // Analyze return values.
367 CCInfo.AnalyzeReturn(Outs, RetCC_Sparc64);
368
369 SDValue Glue;
370 SmallVector<SDValue, 4> RetOps(1, Chain);
371
372 // The second operand on the return instruction is the return address offset.
373 // The return address is always %i7+8 with the 64-bit ABI.
374 RetOps.push_back(DAG.getConstant(8, DL, MVT::i32));
375
376 // Copy the result values into the output registers.
377 for (unsigned i = 0; i != RVLocs.size(); ++i) {
378 CCValAssign &VA = RVLocs[i];
379 assert(VA.isRegLoc() && "Can only return in registers!");
380 SDValue OutVal = OutVals[i];
381
382 // Integer return values must be sign or zero extended by the callee.
383 switch (VA.getLocInfo()) {
384 case CCValAssign::Full: break;
386 OutVal = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), OutVal);
387 break;
389 OutVal = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), OutVal);
390 break;
392 OutVal = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), OutVal);
393 break;
394 default:
395 llvm_unreachable("Unknown loc info!");
396 }
397
398 // The custom bit on an i32 return value indicates that it should be passed
399 // in the high bits of the register.
400 if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
401 OutVal = DAG.getNode(ISD::SHL, DL, MVT::i64, OutVal,
402 DAG.getConstant(32, DL, MVT::i32));
403
404 // The next value may go in the low bits of the same register.
405 // Handle both at once.
406 if (i+1 < RVLocs.size() && RVLocs[i+1].getLocReg() == VA.getLocReg()) {
407 SDValue NV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, OutVals[i+1]);
408 OutVal = DAG.getNode(ISD::OR, DL, MVT::i64, OutVal, NV);
409 // Skip the next value, it's already done.
410 ++i;
411 }
412 }
413
414 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), OutVal, Glue);
415
416 // Guarantee that all emitted copies are stuck together with flags.
417 Glue = Chain.getValue(1);
418 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
419 }
420
421 RetOps[0] = Chain; // Update chain.
422
423 // Add the flag if we have it.
424 if (Glue.getNode())
425 RetOps.push_back(Glue);
426
427 return DAG.getNode(SPISD::RET_GLUE, DL, MVT::Other, RetOps);
428}
429
431 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
432 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
433 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
434 if (Subtarget->is64Bit())
435 return LowerFormalArguments_64(Chain, CallConv, IsVarArg, Ins,
436 DL, DAG, InVals);
437 return LowerFormalArguments_32(Chain, CallConv, IsVarArg, Ins,
438 DL, DAG, InVals);
439}
440
441/// LowerFormalArguments32 - V8 uses a very simple ABI, where all values are
442/// passed in either one or two GPRs, including FP values. TODO: we should
443/// pass FP values in FP registers for fastcc functions.
445 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
446 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
447 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
449 MachineRegisterInfo &RegInfo = MF.getRegInfo();
451 EVT PtrVT = getPointerTy(DAG.getDataLayout());
452
453 // Assign locations to all of the incoming arguments.
455 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
456 *DAG.getContext());
457 CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc32);
458
459 const unsigned StackOffset = 92;
460 bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
461
462 unsigned InIdx = 0;
463 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i, ++InIdx) {
464 CCValAssign &VA = ArgLocs[i];
465 EVT LocVT = VA.getLocVT();
466
467 if (Ins[InIdx].Flags.isSRet()) {
468 if (InIdx != 0)
469 report_fatal_error("sparc only supports sret on the first parameter");
470 // Get SRet from [%fp+64].
471 int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, 64, true);
472 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
473 SDValue Arg =
474 DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
475 InVals.push_back(Arg);
476 continue;
477 }
478
479 SDValue Arg;
480 if (VA.isRegLoc()) {
481 if (VA.needsCustom()) {
482 assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
483
484 Register VRegHi = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
485 MF.getRegInfo().addLiveIn(VA.getLocReg(), VRegHi);
486 SDValue HiVal = DAG.getCopyFromReg(Chain, dl, VRegHi, MVT::i32);
487
488 assert(i+1 < e);
489 CCValAssign &NextVA = ArgLocs[++i];
490
491 SDValue LoVal;
492 if (NextVA.isMemLoc()) {
493 int FrameIdx = MF.getFrameInfo().
494 CreateFixedObject(4, StackOffset+NextVA.getLocMemOffset(),true);
495 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
496 LoVal = DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
497 } else {
498 Register loReg = MF.addLiveIn(NextVA.getLocReg(),
499 &SP::IntRegsRegClass);
500 LoVal = DAG.getCopyFromReg(Chain, dl, loReg, MVT::i32);
501 }
502
503 if (IsLittleEndian)
504 std::swap(LoVal, HiVal);
505
506 SDValue WholeValue =
507 DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
508 WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), WholeValue);
509 InVals.push_back(WholeValue);
510 continue;
511 }
512 Register VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
513 MF.getRegInfo().addLiveIn(VA.getLocReg(), VReg);
514 Arg = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32);
515 if (VA.getLocInfo() != CCValAssign::Indirect) {
516 if (VA.getLocVT() == MVT::f32)
517 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Arg);
518 else if (VA.getLocVT() != MVT::i32) {
519 Arg = DAG.getNode(ISD::AssertSext, dl, MVT::i32, Arg,
520 DAG.getValueType(VA.getLocVT()));
521 Arg = DAG.getNode(ISD::TRUNCATE, dl, VA.getLocVT(), Arg);
522 }
523 InVals.push_back(Arg);
524 continue;
525 }
526 } else {
527 assert(VA.isMemLoc());
528
529 unsigned Offset = VA.getLocMemOffset() + StackOffset;
530
531 if (VA.needsCustom()) {
532 assert(VA.getValVT() == MVT::f64 || VA.getValVT() == MVT::v2i32);
533 // If it is double-word aligned, just load.
534 if (Offset % 8 == 0) {
535 int FI = MF.getFrameInfo().CreateFixedObject(8, Offset, true);
536 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
537 SDValue Load = DAG.getLoad(VA.getValVT(), dl, Chain, FIPtr,
539 InVals.push_back(Load);
540 continue;
541 }
542
543 int FI = MF.getFrameInfo().CreateFixedObject(4, Offset, true);
544 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
545 SDValue HiVal =
546 DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
547 int FI2 = MF.getFrameInfo().CreateFixedObject(4, Offset + 4, true);
548 SDValue FIPtr2 = DAG.getFrameIndex(FI2, PtrVT);
549
550 SDValue LoVal =
551 DAG.getLoad(MVT::i32, dl, Chain, FIPtr2, MachinePointerInfo());
552
553 if (IsLittleEndian)
554 std::swap(LoVal, HiVal);
555
556 SDValue WholeValue =
557 DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
558 WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), WholeValue);
559 InVals.push_back(WholeValue);
560 continue;
561 }
562
563 int FI = MF.getFrameInfo().CreateFixedObject(LocVT.getSizeInBits() / 8,
564 Offset, true);
565 SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
566 SDValue Load = DAG.getLoad(LocVT, dl, Chain, FIPtr,
568 if (VA.getLocInfo() != CCValAssign::Indirect) {
569 InVals.push_back(Load);
570 continue;
571 }
572 Arg = Load;
573 }
574
576
577 SDValue ArgValue =
578 DAG.getLoad(VA.getValVT(), dl, Chain, Arg, MachinePointerInfo());
579 InVals.push_back(ArgValue);
580
581 unsigned ArgIndex = Ins[InIdx].OrigArgIndex;
582 assert(Ins[InIdx].PartOffset == 0);
583 while (i + 1 != e && Ins[InIdx + 1].OrigArgIndex == ArgIndex) {
584 CCValAssign &PartVA = ArgLocs[i + 1];
585 unsigned PartOffset = Ins[InIdx + 1].PartOffset;
587 ArgValue, TypeSize::getFixed(PartOffset), dl);
588 InVals.push_back(DAG.getLoad(PartVA.getValVT(), dl, Chain, Address,
590 ++i;
591 ++InIdx;
592 }
593 }
594
595 // Ins[0] is an sret argument both for an explicit sret parameter and for a
596 // return value that was demoted to sret.
597 if (!Ins.empty() && Ins[0].Flags.isSRet()) {
598 // Copy the SRet Argument to SRetReturnReg.
600 Register Reg = SFI->getSRetReturnReg();
601 if (!Reg) {
602 Reg = MF.getRegInfo().createVirtualRegister(&SP::IntRegsRegClass);
603 SFI->setSRetReturnReg(Reg);
604 }
605 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]);
606 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
607 }
608
609 // Store remaining ArgRegs to the stack if this is a varargs function.
610 if (isVarArg) {
611 static const MCPhysReg ArgRegs[] = {
612 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
613 };
614 unsigned NumAllocated = CCInfo.getFirstUnallocated(ArgRegs);
615 const MCPhysReg *CurArgReg = ArgRegs+NumAllocated, *ArgRegEnd = ArgRegs+6;
616 unsigned ArgOffset = CCInfo.getStackSize();
617 if (NumAllocated == 6)
618 ArgOffset += StackOffset;
619 else {
620 assert(!ArgOffset);
621 ArgOffset = 68+4*NumAllocated;
622 }
623
624 // Remember the vararg offset for the va_start implementation.
625 FuncInfo->setVarArgsFrameOffset(ArgOffset);
626
627 std::vector<SDValue> OutChains;
628
629 for (; CurArgReg != ArgRegEnd; ++CurArgReg) {
630 Register VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
631 MF.getRegInfo().addLiveIn(*CurArgReg, VReg);
632 SDValue Arg = DAG.getCopyFromReg(DAG.getRoot(), dl, VReg, MVT::i32);
633
634 int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, ArgOffset,
635 true);
636 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
637
638 OutChains.push_back(
639 DAG.getStore(DAG.getRoot(), dl, Arg, FIPtr, MachinePointerInfo()));
640 ArgOffset += 4;
641 }
642
643 if (!OutChains.empty()) {
644 OutChains.push_back(Chain);
645 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
646 }
647 }
648
649 return Chain;
650}
651
652// Lower formal arguments for the 64 bit ABI.
654 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
655 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
656 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
658
659 // Analyze arguments according to CC_Sparc64.
661 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
662 *DAG.getContext());
663 CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc64);
664
665 // The argument array begins at %fp+BIAS+128, after the register save area.
666 const unsigned ArgArea = 128;
667
668 for (const CCValAssign &VA : ArgLocs) {
669 if (VA.isRegLoc()) {
670 // This argument is passed in a register.
671 // All integer register arguments are promoted by the caller to i64.
672
673 // Create a virtual register for the promoted live-in value.
674 Register VReg = MF.addLiveIn(VA.getLocReg(),
675 getRegClassFor(VA.getLocVT()));
676 SDValue Arg = DAG.getCopyFromReg(Chain, DL, VReg, VA.getLocVT());
677
678 // Get the high bits for i32 struct elements.
679 if (VA.getValVT() == MVT::i32 && VA.needsCustom())
680 Arg = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), Arg,
681 DAG.getConstant(32, DL, MVT::i32));
682
683 // The caller promoted the argument, so insert an Assert?ext SDNode so we
684 // won't promote the value again in this function.
685 switch (VA.getLocInfo()) {
687 Arg = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), Arg,
688 DAG.getValueType(VA.getValVT()));
689 break;
691 Arg = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), Arg,
692 DAG.getValueType(VA.getValVT()));
693 break;
694 default:
695 break;
696 }
697
698 // Truncate the register down to the argument type.
699 if (VA.isExtInLoc())
700 Arg = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Arg);
701
702 InVals.push_back(Arg);
703 continue;
704 }
705
706 // The registers are exhausted. This argument was passed on the stack.
707 assert(VA.isMemLoc());
708 // The CC_Sparc64_Full/Half functions compute stack offsets relative to the
709 // beginning of the arguments area at %fp+BIAS+128.
710 unsigned Offset = VA.getLocMemOffset() + ArgArea;
711 unsigned ValSize = VA.getValVT().getSizeInBits() / 8;
712 // Adjust offset for extended arguments, SPARC is big-endian.
713 // The caller will have written the full slot with extended bytes, but we
714 // prefer our own extending loads.
715 if (VA.isExtInLoc())
716 Offset += 8 - ValSize;
717 int FI = MF.getFrameInfo().CreateFixedObject(ValSize, Offset, true);
718 InVals.push_back(
719 DAG.getLoad(VA.getValVT(), DL, Chain,
722 }
723
724 if (!IsVarArg)
725 return Chain;
726
727 // This function takes variable arguments, some of which may have been passed
728 // in registers %i0-%i5. Variable floating point arguments are never passed
729 // in floating point registers. They go on %i0-%i5 or on the stack like
730 // integer arguments.
731 //
732 // The va_start intrinsic needs to know the offset to the first variable
733 // argument.
734 unsigned ArgOffset = CCInfo.getStackSize();
736 // Skip the 128 bytes of register save area.
737 FuncInfo->setVarArgsFrameOffset(ArgOffset + ArgArea +
738 Subtarget->getStackPointerBias());
739
740 // Save the variable arguments that were passed in registers.
741 // The caller is required to reserve stack space for 6 arguments regardless
742 // of how many arguments were actually passed.
743 SmallVector<SDValue, 8> OutChains;
744 for (; ArgOffset < 6*8; ArgOffset += 8) {
745 Register VReg = MF.addLiveIn(SP::I0 + ArgOffset/8, &SP::I64RegsRegClass);
746 SDValue VArg = DAG.getCopyFromReg(Chain, DL, VReg, MVT::i64);
747 int FI = MF.getFrameInfo().CreateFixedObject(8, ArgOffset + ArgArea, true);
748 auto PtrVT = getPointerTy(MF.getDataLayout());
749 OutChains.push_back(
750 DAG.getStore(Chain, DL, VArg, DAG.getFrameIndex(FI, PtrVT),
752 }
753
754 if (!OutChains.empty())
755 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
756
757 return Chain;
758}
759
760// Check whether any of the argument registers are reserved
762 const MachineFunction &MF) {
763 // The register window design means that outgoing parameters at O*
764 // will appear in the callee as I*.
765 // Be conservative and check both sides of the register names.
766 bool Outgoing =
767 llvm::any_of(SP::GPROutgoingArgRegClass, [TRI, &MF](MCPhysReg r) {
768 return TRI->isReservedReg(MF, r);
769 });
770 bool Incoming =
771 llvm::any_of(SP::GPRIncomingArgRegClass, [TRI, &MF](MCPhysReg r) {
772 return TRI->isReservedReg(MF, r);
773 });
774 return Outgoing || Incoming;
775}
776
778 const Function &F = MF.getFunction();
779 F.getContext().diagnose(DiagnosticInfoUnsupported{
780 F, ("SPARC doesn't support"
781 " function calls if any of the argument registers is reserved.")});
782}
783
786 SmallVectorImpl<SDValue> &InVals) const {
787 if (Subtarget->is64Bit())
788 return LowerCall_64(CLI, InVals);
789 return LowerCall_32(CLI, InVals);
790}
791
792static bool hasReturnsTwiceAttr(SelectionDAG &DAG, SDValue Callee,
793 const CallBase *Call) {
794 if (Call)
795 return Call->hasFnAttr(Attribute::ReturnsTwice);
796
797 const Function *CalleeFn = nullptr;
799 CalleeFn = dyn_cast<Function>(G->getGlobal());
800 } else if (ExternalSymbolSDNode *E =
802 const Function &Fn = DAG.getMachineFunction().getFunction();
803 const Module *M = Fn.getParent();
804 const char *CalleeName = E->getSymbol();
805 CalleeFn = M->getFunction(CalleeName);
806 }
807
808 if (!CalleeFn)
809 return false;
810 return CalleeFn->hasFnAttribute(Attribute::ReturnsTwice);
811}
812
813/// IsEligibleForTailCallOptimization - Check whether the call is eligible
814/// for tail call optimization.
816 CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF) const {
817
818 auto &Outs = CLI.Outs;
819 auto &Caller = MF.getFunction();
820
821 // Do not tail call opt functions with "disable-tail-calls" attribute.
822 if (Caller.getFnAttribute("disable-tail-calls").getValueAsString() == "true")
823 return false;
824
825 // Do not tail call opt if the stack is used to pass parameters.
826 // 64-bit targets have a slightly higher limit since the ABI requires
827 // to allocate some space even when all the parameters fit inside registers.
828 unsigned StackSizeLimit = Subtarget->is64Bit() ? 48 : 0;
829 if (CCInfo.getStackSize() > StackSizeLimit)
830 return false;
831
832 // Do not tail call opt if either the callee or caller returns
833 // a struct and the other does not. On 32-bit SPARC the caller's
834 // return value may have been demoted to sret, in which case it has
835 // an SRetReturnReg but no sret attribute.
837 bool CallerSRet = Caller.hasStructRetAttr() || SFI->getSRetReturnReg();
838 bool CalleeSRet = !Outs.empty() && Outs[0].Flags.isSRet();
839 if (CallerSRet != CalleeSRet)
840 return false;
841
842 // Byval parameters hand the function a pointer directly into the stack area
843 // we want to reuse during a tail call.
844 for (auto &Arg : Outs)
845 if (Arg.Flags.isByVal())
846 return false;
847
848 return true;
849}
850
851// Lower a call for the 32-bit ABI.
854 SmallVectorImpl<SDValue> &InVals) const {
855 SelectionDAG &DAG = CLI.DAG;
856 SDLoc &dl = CLI.DL;
858 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
860 SDValue Chain = CLI.Chain;
861 SDValue Callee = CLI.Callee;
862 bool &isTailCall = CLI.IsTailCall;
863 CallingConv::ID CallConv = CLI.CallConv;
864 bool isVarArg = CLI.IsVarArg;
866 LLVMContext &Ctx = *DAG.getContext();
867 EVT PtrVT = getPointerTy(MF.getDataLayout());
868
869 // Analyze operands of the call, assigning locations to each operand.
871 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
872 *DAG.getContext());
873 CCInfo.AnalyzeCallOperands(Outs, CC_Sparc32);
874
875 isTailCall = isTailCall && IsEligibleForTailCallOptimization(
876 CCInfo, CLI, DAG.getMachineFunction());
877 if (!isTailCall && CLI.CB && CLI.CB->isMustTailCall())
878 reportFatalInternalError("failed to perform tail call elimination on a "
879 "call site marked musttail");
880
881 // Get the size of the outgoing arguments stack space requirement.
882 unsigned ArgsSize = CCInfo.getStackSize();
883
884 // Keep stack frames 8-byte aligned.
885 ArgsSize = (ArgsSize+7) & ~7;
886
888
889 // Create local copies for byval args.
890 SmallVector<SDValue, 8> ByValArgs;
891 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
892 ISD::ArgFlagsTy Flags = Outs[i].Flags;
893 if (!Flags.isByVal())
894 continue;
895
896 SDValue Arg = OutVals[i];
897 unsigned Size = Flags.getByValSize();
898 Align Alignment = Flags.getNonZeroByValAlign();
899
900 if (Size > 0U) {
901 int FI = MFI.CreateStackObject(Size, Alignment, false);
902 SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
903 SDValue SizeNode = DAG.getConstant(Size, dl, MVT::i32);
904
905 Chain =
906 DAG.getMemcpy(Chain, dl, FIPtr, Arg, SizeNode, Alignment, Alignment,
907 false, // isVolatile,
908 (Size <= 32), // AlwaysInline if size <= 32,
909 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(),
911 ByValArgs.push_back(FIPtr);
912 }
913 else {
914 SDValue nullVal;
915 ByValArgs.push_back(nullVal);
916 }
917 }
918
919 assert(!isTailCall || ArgsSize == 0);
920
921 if (!isTailCall)
922 Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, dl);
923
925 SmallVector<SDValue, 8> MemOpChains;
926
927 const unsigned StackOffset = 92;
928 bool hasStructRetAttr = false;
929 unsigned SRetArgSize = 0;
930 // Walk the register/memloc assignments, inserting copies/loads.
931 for (unsigned i = 0, realArgIdx = 0, byvalArgIdx = 0, e = ArgLocs.size();
932 i != e;
933 ++i, ++realArgIdx) {
934 CCValAssign &VA = ArgLocs[i];
935 SDValue Arg = OutVals[realArgIdx];
936
937 ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
938
939 // Use local copy if it is a byval arg.
940 if (Flags.isByVal()) {
941 Arg = ByValArgs[byvalArgIdx++];
942 if (!Arg) {
943 continue;
944 }
945 }
946
947 // Promote the value if needed.
948 switch (VA.getLocInfo()) {
949 default: llvm_unreachable("Unknown loc info!");
952 break;
954 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
955 break;
957 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
958 break;
960 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
961 break;
963 Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg);
964 break;
965 }
966
967 if (Flags.isSRet()) {
968 assert(VA.needsCustom());
969
970 if (isTailCall)
971 continue;
972
973 // store SRet argument in %sp+64
974 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
975 SDValue PtrOff = DAG.getIntPtrConstant(64, dl);
976 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
977 MemOpChains.push_back(
978 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
979 hasStructRetAttr = true;
980 // sret only allowed on first argument
981 assert(Outs[realArgIdx].OrigArgIndex == 0);
982 SRetArgSize =
983 DAG.getDataLayout().getTypeAllocSize(CLI.getArgs()[0].IndirectType);
984 continue;
985 }
986
987 if (VA.needsCustom()) {
988 assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
989
990 if (VA.isMemLoc()) {
991 unsigned Offset = VA.getLocMemOffset() + StackOffset;
992 // if it is double-word aligned, just store.
993 if (Offset % 8 == 0) {
994 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
995 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
996 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
997 MemOpChains.push_back(
998 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
999 continue;
1000 }
1001 }
1002
1003 if (VA.getLocVT() == MVT::f64) {
1004 // Move from the float value from float registers into the
1005 // integer registers.
1007 Arg = bitcastConstantFPToInt(C, dl, DAG);
1008 else
1009 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, Arg);
1010 }
1011
1012 SDValue Part0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32,
1013 Arg,
1014 DAG.getConstant(0, dl, getVectorIdxTy(DAG.getDataLayout())));
1015 SDValue Part1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32,
1016 Arg,
1017 DAG.getConstant(1, dl, getVectorIdxTy(DAG.getDataLayout())));
1018
1019 if (VA.isRegLoc()) {
1020 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Part0));
1021 assert(i+1 != e);
1022 CCValAssign &NextVA = ArgLocs[++i];
1023 if (NextVA.isRegLoc()) {
1024 RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), Part1));
1025 } else {
1026 // Store the second part in stack.
1027 unsigned Offset = NextVA.getLocMemOffset() + StackOffset;
1028 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1029 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
1030 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1031 MemOpChains.push_back(
1032 DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
1033 }
1034 } else {
1035 unsigned Offset = VA.getLocMemOffset() + StackOffset;
1036 // Store the first part.
1037 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1038 SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
1039 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1040 MemOpChains.push_back(
1041 DAG.getStore(Chain, dl, Part0, PtrOff, MachinePointerInfo()));
1042 // Store the second part.
1043 PtrOff = DAG.getIntPtrConstant(Offset + 4, dl);
1044 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1045 MemOpChains.push_back(
1046 DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
1047 }
1048 continue;
1049 }
1050
1051 if (VA.getLocInfo() == CCValAssign::Indirect) {
1052 // Store the argument in a stack slot and pass its address.
1053 unsigned ArgIndex = Outs[realArgIdx].OrigArgIndex;
1054 assert(Outs[realArgIdx].PartOffset == 0);
1055
1056 EVT SlotVT;
1057 if (i + 1 != e && Outs[realArgIdx + 1].OrigArgIndex == ArgIndex) {
1058 Type *OrigArgType = CLI.Args[ArgIndex].Ty;
1059 EVT OrigArgVT = getValueType(MF.getDataLayout(), OrigArgType);
1060 MVT PartVT =
1061 getRegisterTypeForCallingConv(Ctx, CLI.CallConv, OrigArgVT);
1062 unsigned N =
1063 getNumRegistersForCallingConv(Ctx, CLI.CallConv, OrigArgVT);
1064 SlotVT = EVT::getIntegerVT(Ctx, PartVT.getSizeInBits() * N);
1065 } else {
1066 SlotVT = Outs[realArgIdx].VT;
1067 }
1068
1069 SDValue SpillSlot = DAG.CreateStackTemporary(SlotVT);
1070 int FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
1071 MemOpChains.push_back(
1072 DAG.getStore(Chain, dl, Arg, SpillSlot,
1074 // If the original argument was split (e.g. f128), we need
1075 // to store all parts of it here (and pass just one address).
1076 while (i + 1 != e && Outs[realArgIdx + 1].OrigArgIndex == ArgIndex) {
1077 SDValue PartValue = OutVals[realArgIdx + 1];
1078 unsigned PartOffset = Outs[realArgIdx + 1].PartOffset;
1080 DAG.getFrameIndex(FI, PtrVT), TypeSize::getFixed(PartOffset), dl);
1081 MemOpChains.push_back(
1082 DAG.getStore(Chain, dl, PartValue, Address,
1084 assert((PartOffset + PartValue.getValueType().getStoreSize() <=
1085 SlotVT.getStoreSize()) &&
1086 "Not enough space for argument part!");
1087 ++i;
1088 ++realArgIdx;
1089 }
1090
1091 Arg = SpillSlot;
1092 }
1093
1094 // Arguments that can be passed on register must be kept at
1095 // RegsToPass vector
1096 if (VA.isRegLoc()) {
1097 if (VA.getLocVT() != MVT::f32) {
1098 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
1099 continue;
1100 }
1101 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg);
1102 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
1103 continue;
1104 }
1105
1106 assert(VA.isMemLoc());
1107
1108 // Create a store off the stack pointer for this argument.
1109 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
1111 dl);
1112 PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
1113 MemOpChains.push_back(
1114 DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
1115 }
1116
1117
1118 // Emit all stores, make sure the occur before any copies into physregs.
1119 if (!MemOpChains.empty())
1120 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
1121
1122 // Build a sequence of copy-to-reg nodes chained together with token
1123 // chain and flag operands which copy the outgoing args into registers.
1124 // The InGlue in necessary since all emitted instructions must be
1125 // stuck together.
1126 SDValue InGlue;
1127 for (const auto &[OrigReg, N] : RegsToPass) {
1128 Register Reg = isTailCall ? OrigReg : toCallerWindow(OrigReg);
1129 Chain = DAG.getCopyToReg(Chain, dl, Reg, N, InGlue);
1130 InGlue = Chain.getValue(1);
1131 }
1132
1133 bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CB);
1134
1135 // If the callee is a GlobalAddress node (quite common, every direct call is)
1136 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
1137 // Likewise ExternalSymbol -> TargetExternalSymbol.
1139 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32, 0);
1141 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
1142
1143 // Returns a chain & a flag for retval copy to use
1144 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1146 Ops.push_back(Chain);
1147 Ops.push_back(Callee);
1148 if (hasStructRetAttr)
1149 Ops.push_back(DAG.getTargetConstant(SRetArgSize, dl, MVT::i32));
1150 for (const auto &[OrigReg, N] : RegsToPass) {
1151 Register Reg = isTailCall ? OrigReg : toCallerWindow(OrigReg);
1152 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
1153 }
1154
1155 // Add a register mask operand representing the call-preserved registers.
1156 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1157 const uint32_t *Mask =
1158 ((hasReturnsTwice)
1159 ? TRI->getRTCallPreservedMask(CallConv)
1160 : TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv));
1161
1162 if (isAnyArgRegReserved(TRI, MF))
1164
1165 assert(Mask && "Missing call preserved mask for calling convention");
1166 Ops.push_back(DAG.getRegisterMask(Mask));
1167
1168 if (InGlue.getNode())
1169 Ops.push_back(InGlue);
1170
1171 if (isTailCall) {
1173 return DAG.getNode(SPISD::TAIL_CALL, dl, MVT::Other, Ops);
1174 }
1175
1176 Chain = DAG.getNode(SPISD::CALL, dl, NodeTys, Ops);
1177 InGlue = Chain.getValue(1);
1178
1179 Chain = DAG.getCALLSEQ_END(Chain, ArgsSize, 0, InGlue, dl);
1180 InGlue = Chain.getValue(1);
1181
1182 // Assign locations to each value returned by this call.
1184 CCState RVInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
1185 *DAG.getContext());
1186
1187 RVInfo.AnalyzeCallResult(Ins, RetCC_Sparc32);
1188
1189 // Copy all of the result registers out of their specified physreg.
1190 for (unsigned i = 0; i != RVLocs.size(); ++i) {
1191 assert(RVLocs[i].isRegLoc() && "Can only return in registers!");
1192 if (RVLocs[i].getLocVT() == MVT::v2i32) {
1193 SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2i32);
1195 Chain, dl, toCallerWindow(RVLocs[i++].getLocReg()), MVT::i32, InGlue);
1196 Chain = Lo.getValue(1);
1197 InGlue = Lo.getValue(2);
1198 Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Lo,
1199 DAG.getConstant(0, dl, MVT::i32));
1201 Chain, dl, toCallerWindow(RVLocs[i].getLocReg()), MVT::i32, InGlue);
1202 Chain = Hi.getValue(1);
1203 InGlue = Hi.getValue(2);
1204 Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Hi,
1205 DAG.getConstant(1, dl, MVT::i32));
1206 InVals.push_back(Vec);
1207 } else {
1208 Chain =
1209 DAG.getCopyFromReg(Chain, dl, toCallerWindow(RVLocs[i].getLocReg()),
1210 RVLocs[i].getValVT(), InGlue)
1211 .getValue(1);
1212 InGlue = Chain.getValue(2);
1213 InVals.push_back(Chain.getValue(0));
1214 }
1215 }
1216
1217 return Chain;
1218}
1219
1220// FIXME? Maybe this could be a TableGen attribute on some registers and
1221// this table could be generated automatically from RegInfo.
1223 const MachineFunction &MF) const {
1224 StringRef Name(RegName);
1225 Name.consume_front("%");
1227 .Cases({"r24", "i0"}, SP::I0)
1228 .Cases({"r25", "i1"}, SP::I1)
1229 .Cases({"r26", "i2"}, SP::I2)
1230 .Cases({"r27", "i3"}, SP::I3)
1231 .Cases({"r28", "i4"}, SP::I4)
1232 .Cases({"r29", "i5"}, SP::I5)
1233 .Cases({"r30", "i6", "fp"}, SP::I6)
1234 .Cases({"r31", "i7"}, SP::I7)
1235 .Cases({"r8", "o0"}, SP::O0)
1236 .Cases({"r9", "o1"}, SP::O1)
1237 .Cases({"r10", "o2"}, SP::O2)
1238 .Cases({"r11", "o3"}, SP::O3)
1239 .Cases({"r12", "o4"}, SP::O4)
1240 .Cases({"r13", "o5"}, SP::O5)
1241 .Cases({"r14", "o6", "sp"}, SP::O6)
1242 .Cases({"r15", "o7"}, SP::O7)
1243 .Cases({"r16", "l0"}, SP::L0)
1244 .Cases({"r17", "l1"}, SP::L1)
1245 .Cases({"r18", "l2"}, SP::L2)
1246 .Cases({"r19", "l3"}, SP::L3)
1247 .Cases({"r20", "l4"}, SP::L4)
1248 .Cases({"r21", "l5"}, SP::L5)
1249 .Cases({"r22", "l6"}, SP::L6)
1250 .Cases({"r23", "l7"}, SP::L7)
1251 .Cases({"r0", "g0"}, SP::G0)
1252 .Cases({"r1", "g1"}, SP::G1)
1253 .Cases({"r2", "g2"}, SP::G2)
1254 .Cases({"r3", "g3"}, SP::G3)
1255 .Cases({"r4", "g4"}, SP::G4)
1256 .Cases({"r5", "g5"}, SP::G5)
1257 .Cases({"r6", "g6"}, SP::G6)
1258 .Cases({"r7", "g7"}, SP::G7)
1259 .Default(0);
1260
1261 // If we're directly referencing register names
1262 // (e.g in GCC C extension `register int r asm("g1");`),
1263 // make sure that said register is in the reserve list.
1264 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1265 if (!TRI->isReservedReg(MF, Reg))
1266 Reg = Register();
1267
1268 return Reg;
1269}
1270
1271// Fixup floating point arguments in the ... part of a varargs call.
1272//
1273// The SPARC v9 ABI requires that floating point arguments are treated the same
1274// as integers when calling a varargs function. This does not apply to the
1275// fixed arguments that are part of the function's prototype.
1276//
1277// This function post-processes a CCValAssign array created by
1278// AnalyzeCallOperands().
1281 for (CCValAssign &VA : ArgLocs) {
1282 MVT ValTy = VA.getLocVT();
1283 // FIXME: What about f32 arguments? C promotes them to f64 when calling
1284 // varargs functions.
1285 if (!VA.isRegLoc() || (ValTy != MVT::f64 && ValTy != MVT::f128))
1286 continue;
1287 // The fixed arguments to a varargs function still go in FP registers.
1288 if (!Outs[VA.getValNo()].Flags.isVarArg())
1289 continue;
1290
1291 // This floating point argument should be reassigned.
1292 // Determine the offset into the argument array.
1293 Register firstReg = (ValTy == MVT::f64) ? SP::D0 : SP::Q0;
1294 unsigned argSize = (ValTy == MVT::f64) ? 8 : 16;
1295 unsigned Offset = argSize * (VA.getLocReg() - firstReg);
1296 assert(Offset < 16*8 && "Offset out of range, bad register enum?");
1297
1298 if (Offset < 6*8) {
1299 // This argument should go in %i0-%i5.
1300 unsigned IReg = SP::I0 + Offset/8;
1301 if (ValTy == MVT::f64)
1302 // Full register, just bitconvert into i64.
1303 VA = CCValAssign::getReg(VA.getValNo(), VA.getValVT(), IReg, MVT::i64,
1305 else {
1306 assert(ValTy == MVT::f128 && "Unexpected type!");
1307 // Full register, just bitconvert into i128 -- We will lower this into
1308 // two i64s in LowerCall_64.
1309 VA = CCValAssign::getCustomReg(VA.getValNo(), VA.getValVT(), IReg,
1310 MVT::i128, CCValAssign::BCvt);
1311 }
1312 } else {
1313 // This needs to go to memory, we're out of integer registers.
1314 VA = CCValAssign::getMem(VA.getValNo(), VA.getValVT(), Offset,
1315 VA.getLocVT(), VA.getLocInfo());
1316 }
1317 }
1318}
1319
1320// Lower a call for the 64-bit ABI.
1321SDValue
1323 SmallVectorImpl<SDValue> &InVals) const {
1324 SelectionDAG &DAG = CLI.DAG;
1325 SDLoc DL = CLI.DL;
1326 SDValue Chain = CLI.Chain;
1327 auto PtrVT = getPointerTy(DAG.getDataLayout());
1329
1330 // Analyze operands of the call, assigning locations to each operand.
1332 CCState CCInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), ArgLocs,
1333 *DAG.getContext());
1334 CCInfo.AnalyzeCallOperands(CLI.Outs, CC_Sparc64);
1335
1337 CCInfo, CLI, DAG.getMachineFunction());
1338 if (!CLI.IsTailCall && CLI.CB && CLI.CB->isMustTailCall())
1339 reportFatalInternalError("failed to perform tail call elimination on a "
1340 "call site marked musttail");
1341
1342 // Get the size of the outgoing arguments stack space requirement.
1343 // The stack offset computed by CC_Sparc64 includes all arguments.
1344 // Called functions expect 6 argument words to exist in the stack frame, used
1345 // or not.
1346 unsigned StackReserved = 6 * 8u;
1347 unsigned ArgsSize = std::max<unsigned>(StackReserved, CCInfo.getStackSize());
1348
1349 // Keep stack frames 16-byte aligned.
1350 ArgsSize = alignTo(ArgsSize, 16);
1351
1352 // Varargs calls require special treatment.
1353 if (CLI.IsVarArg)
1354 fixupVariableFloatArgs(ArgLocs, CLI.Outs);
1355
1356 assert(!CLI.IsTailCall || ArgsSize == StackReserved);
1357
1358 // Adjust the stack pointer to make room for the arguments.
1359 // FIXME: Use hasReservedCallFrame to avoid %sp adjustments around all calls
1360 // with more than 6 arguments.
1361 if (!CLI.IsTailCall)
1362 Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, DL);
1363
1364 // Collect the set of registers to pass to the function and their values.
1365 // This will be emitted as a sequence of CopyToReg nodes glued to the call
1366 // instruction.
1368
1369 // Collect chains from all the memory opeations that copy arguments to the
1370 // stack. They must follow the stack pointer adjustment above and precede the
1371 // call instruction itself.
1372 SmallVector<SDValue, 8> MemOpChains;
1373
1374 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1375 const CCValAssign &VA = ArgLocs[i];
1376 SDValue Arg = CLI.OutVals[i];
1377
1378 // Promote the value if needed.
1379 switch (VA.getLocInfo()) {
1380 default:
1381 llvm_unreachable("Unknown location info!");
1382 case CCValAssign::Full:
1383 break;
1384 case CCValAssign::SExt:
1385 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Arg);
1386 break;
1387 case CCValAssign::ZExt:
1388 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Arg);
1389 break;
1390 case CCValAssign::AExt:
1391 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Arg);
1392 break;
1393 case CCValAssign::BCvt:
1394 // fixupVariableFloatArgs() may create bitcasts from f128 to i128. But
1395 // SPARC does not support i128 natively. Lower it into two i64, see below.
1396 if (!VA.needsCustom() || VA.getValVT() != MVT::f128
1397 || VA.getLocVT() != MVT::i128)
1398 Arg = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Arg);
1399 break;
1400 }
1401
1402 if (VA.isRegLoc()) {
1403 if (VA.needsCustom() && VA.getValVT() == MVT::f128
1404 && VA.getLocVT() == MVT::i128) {
1405 // Store and reload into the integer register reg and reg+1.
1406 unsigned Offset = 8 * (VA.getLocReg() - SP::I0);
1407 unsigned StackOffset = Offset + Subtarget->getStackPointerBias() + 128;
1408 SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1409 SDValue HiPtrOff = DAG.getIntPtrConstant(StackOffset, DL);
1410 HiPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, HiPtrOff);
1411 SDValue LoPtrOff = DAG.getIntPtrConstant(StackOffset + 8, DL);
1412 LoPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, LoPtrOff);
1413
1414 // Store to %sp+BIAS+128+Offset
1415 SDValue Store =
1416 DAG.getStore(Chain, DL, Arg, HiPtrOff, MachinePointerInfo());
1417 // Load into Reg and Reg+1
1418 SDValue Hi64 =
1419 DAG.getLoad(MVT::i64, DL, Store, HiPtrOff, MachinePointerInfo());
1420 SDValue Lo64 =
1421 DAG.getLoad(MVT::i64, DL, Store, LoPtrOff, MachinePointerInfo());
1422
1423 Register HiReg = VA.getLocReg();
1424 Register LoReg = VA.getLocReg() + 1;
1425 if (!CLI.IsTailCall) {
1426 HiReg = toCallerWindow(HiReg);
1427 LoReg = toCallerWindow(LoReg);
1428 }
1429
1430 RegsToPass.push_back(std::make_pair(HiReg, Hi64));
1431 RegsToPass.push_back(std::make_pair(LoReg, Lo64));
1432 continue;
1433 }
1434
1435 // The custom bit on an i32 return value indicates that it should be
1436 // passed in the high bits of the register.
1437 if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
1438 Arg = DAG.getNode(ISD::SHL, DL, MVT::i64, Arg,
1439 DAG.getConstant(32, DL, MVT::i32));
1440
1441 // The next value may go in the low bits of the same register.
1442 // Handle both at once.
1443 if (i+1 < ArgLocs.size() && ArgLocs[i+1].isRegLoc() &&
1444 ArgLocs[i+1].getLocReg() == VA.getLocReg()) {
1445 SDValue NV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64,
1446 CLI.OutVals[i+1]);
1447 Arg = DAG.getNode(ISD::OR, DL, MVT::i64, Arg, NV);
1448 // Skip the next value, it's already done.
1449 ++i;
1450 }
1451 }
1452
1453 Register Reg = VA.getLocReg();
1454 if (!CLI.IsTailCall)
1455 Reg = toCallerWindow(Reg);
1456 RegsToPass.push_back(std::make_pair(Reg, Arg));
1457 continue;
1458 }
1459
1460 assert(VA.isMemLoc());
1461
1462 // Create a store off the stack pointer for this argument.
1463 SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1464 // The argument area starts at %fp+BIAS+128 in the callee frame,
1465 // %sp+BIAS+128 in ours.
1466 SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset() +
1467 Subtarget->getStackPointerBias() +
1468 128, DL);
1469 PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
1470 MemOpChains.push_back(
1471 DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo()));
1472 }
1473
1474 // Emit all stores, make sure they occur before the call.
1475 if (!MemOpChains.empty())
1476 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
1477
1478 // Build a sequence of CopyToReg nodes glued together with token chain and
1479 // glue operands which copy the outgoing args into registers. The InGlue is
1480 // necessary since all emitted instructions must be stuck together in order
1481 // to pass the live physical registers.
1482 SDValue InGlue;
1483 for (const auto &[Reg, N] : RegsToPass) {
1484 Chain = DAG.getCopyToReg(Chain, DL, Reg, N, InGlue);
1485 InGlue = Chain.getValue(1);
1486 }
1487
1488 // If the callee is a GlobalAddress node (quite common, every direct call is)
1489 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
1490 // Likewise ExternalSymbol -> TargetExternalSymbol.
1491 SDValue Callee = CLI.Callee;
1492 bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CB);
1494 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, PtrVT, 0);
1496 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT);
1497
1498 // Build the operands for the call instruction itself.
1500 Ops.push_back(Chain);
1501 Ops.push_back(Callee);
1502 for (const auto &[Reg, N] : RegsToPass)
1503 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
1504
1505 // Add a register mask operand representing the call-preserved registers.
1506 const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1507 const uint32_t *Mask =
1508 ((hasReturnsTwice) ? TRI->getRTCallPreservedMask(CLI.CallConv)
1509 : TRI->getCallPreservedMask(DAG.getMachineFunction(),
1510 CLI.CallConv));
1511
1512 if (isAnyArgRegReserved(TRI, MF))
1514
1515 assert(Mask && "Missing call preserved mask for calling convention");
1516 Ops.push_back(DAG.getRegisterMask(Mask));
1517
1518 // Make sure the CopyToReg nodes are glued to the call instruction which
1519 // consumes the registers.
1520 if (InGlue.getNode())
1521 Ops.push_back(InGlue);
1522
1523 // Now the call itself.
1524 if (CLI.IsTailCall) {
1526 return DAG.getNode(SPISD::TAIL_CALL, DL, MVT::Other, Ops);
1527 }
1528 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1529 Chain = DAG.getNode(SPISD::CALL, DL, NodeTys, Ops);
1530 InGlue = Chain.getValue(1);
1531
1532 // Revert the stack pointer immediately after the call.
1533 Chain = DAG.getCALLSEQ_END(Chain, ArgsSize, 0, InGlue, DL);
1534 InGlue = Chain.getValue(1);
1535
1536 // Now extract the return values. This is more or less the same as
1537 // LowerFormalArguments_64.
1538
1539 // Assign locations to each value returned by this call.
1541 CCState RVInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), RVLocs,
1542 *DAG.getContext());
1543
1544 // Set inreg flag manually for codegen generated library calls that
1545 // return float.
1546 if (CLI.Ins.size() == 1 && CLI.Ins[0].VT == MVT::f32 && !CLI.CB)
1547 CLI.Ins[0].Flags.setInReg();
1548
1549 RVInfo.AnalyzeCallResult(CLI.Ins, RetCC_Sparc64);
1550
1551 // Copy all of the result registers out of their specified physreg.
1552 for (unsigned i = 0; i != RVLocs.size(); ++i) {
1553 CCValAssign &VA = RVLocs[i];
1554 assert(VA.isRegLoc() && "Can only return in registers!");
1555 unsigned Reg = toCallerWindow(VA.getLocReg());
1556
1557 // When returning 'inreg {i32, i32 }', two consecutive i32 arguments can
1558 // reside in the same register in the high and low bits. Reuse the
1559 // CopyFromReg previous node to avoid duplicate copies.
1560 SDValue RV;
1561 if (RegisterSDNode *SrcReg = dyn_cast<RegisterSDNode>(Chain.getOperand(1)))
1562 if (SrcReg->getReg() == Reg && Chain->getOpcode() == ISD::CopyFromReg)
1563 RV = Chain.getValue(0);
1564
1565 // But usually we'll create a new CopyFromReg for a different register.
1566 if (!RV.getNode()) {
1567 RV = DAG.getCopyFromReg(Chain, DL, Reg, RVLocs[i].getLocVT(), InGlue);
1568 Chain = RV.getValue(1);
1569 InGlue = Chain.getValue(2);
1570 }
1571
1572 // Get the high bits for i32 struct elements.
1573 if (VA.getValVT() == MVT::i32 && VA.needsCustom())
1574 RV = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), RV,
1575 DAG.getConstant(32, DL, MVT::i32));
1576
1577 // The callee promoted the return value, so insert an Assert?ext SDNode so
1578 // we won't promote the value again in this function.
1579 switch (VA.getLocInfo()) {
1580 case CCValAssign::SExt:
1581 RV = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), RV,
1582 DAG.getValueType(VA.getValVT()));
1583 break;
1584 case CCValAssign::ZExt:
1585 RV = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), RV,
1586 DAG.getValueType(VA.getValVT()));
1587 break;
1588 default:
1589 break;
1590 }
1591
1592 // Truncate the register down to the return value type.
1593 if (VA.isExtInLoc())
1594 RV = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), RV);
1595
1596 InVals.push_back(RV);
1597 }
1598
1599 return Chain;
1600}
1601
1602//===----------------------------------------------------------------------===//
1603// TargetLowering Implementation
1604//===----------------------------------------------------------------------===//
1605
1608 if (AI->getOperation() == AtomicRMWInst::Xchg &&
1609 AI->getType()->getPrimitiveSizeInBits() == 32)
1610 return AtomicExpansionKind::None; // Uses xchg instruction
1611
1613}
1614
1615/// intCondCCodeToRcond - Convert a DAG integer condition code to a SPARC
1616/// rcond condition.
1618 switch (CC) {
1619 default:
1620 llvm_unreachable("Unknown/unsigned integer condition code!");
1621 case ISD::SETEQ:
1622 return SPCC::REG_Z;
1623 case ISD::SETNE:
1624 return SPCC::REG_NZ;
1625 case ISD::SETLT:
1626 return SPCC::REG_LZ;
1627 case ISD::SETGT:
1628 return SPCC::REG_GZ;
1629 case ISD::SETLE:
1630 return SPCC::REG_LEZ;
1631 case ISD::SETGE:
1632 return SPCC::REG_GEZ;
1633 }
1634}
1635
1636/// IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC
1637/// condition.
1639 switch (CC) {
1640 default: llvm_unreachable("Unknown integer condition code!");
1641 case ISD::SETEQ: return SPCC::ICC_E;
1642 case ISD::SETNE: return SPCC::ICC_NE;
1643 case ISD::SETLT: return SPCC::ICC_L;
1644 case ISD::SETGT: return SPCC::ICC_G;
1645 case ISD::SETLE: return SPCC::ICC_LE;
1646 case ISD::SETGE: return SPCC::ICC_GE;
1647 case ISD::SETULT: return SPCC::ICC_CS;
1648 case ISD::SETULE: return SPCC::ICC_LEU;
1649 case ISD::SETUGT: return SPCC::ICC_GU;
1650 case ISD::SETUGE: return SPCC::ICC_CC;
1651 }
1652}
1653
1654/// FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC
1655/// FCC condition.
1657 switch (CC) {
1658 default: llvm_unreachable("Unknown fp condition code!");
1659 case ISD::SETEQ:
1660 case ISD::SETOEQ: return SPCC::FCC_E;
1661 case ISD::SETNE:
1662 case ISD::SETUNE: return SPCC::FCC_NE;
1663 case ISD::SETLT:
1664 case ISD::SETOLT: return SPCC::FCC_L;
1665 case ISD::SETGT:
1666 case ISD::SETOGT: return SPCC::FCC_G;
1667 case ISD::SETLE:
1668 case ISD::SETOLE: return SPCC::FCC_LE;
1669 case ISD::SETGE:
1670 case ISD::SETOGE: return SPCC::FCC_GE;
1671 case ISD::SETULT: return SPCC::FCC_UL;
1672 case ISD::SETULE: return SPCC::FCC_ULE;
1673 case ISD::SETUGT: return SPCC::FCC_UG;
1674 case ISD::SETUGE: return SPCC::FCC_UGE;
1675 case ISD::SETUO: return SPCC::FCC_U;
1676 case ISD::SETO: return SPCC::FCC_O;
1677 case ISD::SETONE: return SPCC::FCC_LG;
1678 case ISD::SETUEQ: return SPCC::FCC_UE;
1679 }
1680}
1681
1683 const SparcSubtarget &STI)
1684 : TargetLowering(TM, STI), Subtarget(&STI) {
1685 MVT PtrVT = Subtarget->is64Bit() ? MVT::i64 : MVT::i32;
1686
1687 // Instructions which use registers as conditionals examine all the
1688 // bits (as does the pseudo SELECT_CC expansion). I don't think it
1689 // matters much whether it's ZeroOrOneBooleanContent, or
1690 // ZeroOrNegativeOneBooleanContent, so, arbitrarily choose the
1691 // former.
1694
1695 // Set up the register classes.
1696 addRegisterClass(MVT::i32, &SP::IntRegsRegClass);
1697 if (!Subtarget->useSoftFloat()) {
1698 addRegisterClass(MVT::f32, &SP::FPRegsRegClass);
1699 addRegisterClass(MVT::f64, &SP::DFPRegsRegClass);
1700 addRegisterClass(MVT::f128, &SP::QFPRegsRegClass);
1701 }
1702 if (Subtarget->is64Bit()) {
1703 addRegisterClass(MVT::i64, &SP::I64RegsRegClass);
1704 } else {
1705 // On 32bit sparc, we define a double-register 32bit register
1706 // class, as well. This is modeled in LLVM as a 2-vector of i32.
1707 addRegisterClass(MVT::v2i32, &SP::IntPairRegClass);
1708
1709 // ...but almost all operations must be expanded, so set that as
1710 // the default.
1711 for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op) {
1712 setOperationAction(Op, MVT::v2i32, Expand);
1713 }
1714 // Truncating/extending stores/loads are also not supported.
1716 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::v2i32, Expand);
1717 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::v2i32, Expand);
1718 setLoadExtAction(ISD::EXTLOAD, VT, MVT::v2i32, Expand);
1719
1720 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i32, VT, Expand);
1721 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i32, VT, Expand);
1722 setLoadExtAction(ISD::EXTLOAD, MVT::v2i32, VT, Expand);
1723
1724 setTruncStoreAction(VT, MVT::v2i32, Expand);
1725 setTruncStoreAction(MVT::v2i32, VT, Expand);
1726 }
1727 // However, load and store *are* legal.
1728 setOperationAction(ISD::LOAD, MVT::v2i32, Legal);
1729 setOperationAction(ISD::STORE, MVT::v2i32, Legal);
1733
1734 // And we need to promote i64 loads/stores into vector load/store
1737
1738 // Sadly, this doesn't work:
1739 // AddPromotedToType(ISD::LOAD, MVT::i64, MVT::v2i32);
1740 // AddPromotedToType(ISD::STORE, MVT::i64, MVT::v2i32);
1741 }
1742
1743 // Turn FP extload into load/fpextend
1744 for (MVT VT : MVT::fp_valuetypes()) {
1745 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand);
1746 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand);
1747 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f64, Expand);
1748 }
1749
1750 // Sparc doesn't have i1 sign extending load
1751 for (MVT VT : MVT::integer_valuetypes())
1752 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote);
1753
1754 // Turn FP truncstore into trunc + store.
1755 setTruncStoreAction(MVT::f32, MVT::f16, Expand);
1756 setTruncStoreAction(MVT::f64, MVT::f16, Expand);
1757 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
1758 setTruncStoreAction(MVT::f128, MVT::f16, Expand);
1759 setTruncStoreAction(MVT::f128, MVT::f32, Expand);
1760 setTruncStoreAction(MVT::f128, MVT::f64, Expand);
1761
1762 // Custom legalize GlobalAddress nodes into LO/HI parts.
1767
1768 // Sparc doesn't have sext_inreg, replace them with shl/sra
1772
1773 // Sparc has no REM or DIVREM operations.
1778
1779 // ... nor does SparcV9.
1780 if (Subtarget->is64Bit()) {
1785 }
1786
1787 // Custom expand fp<->sint
1792
1793 // Custom Expand fp<->uint
1798
1799 // Lower f16 conversion operations into library calls
1806
1808 Subtarget->isVIS3() ? Legal : Expand);
1810 Subtarget->isVIS3() ? Legal : Expand);
1811
1812 // Sparc has no select or setcc: expand to SELECT_CC.
1817
1822
1823 // Sparc doesn't have BRCOND either, it has BR_CC.
1825 setOperationAction(ISD::BRIND, MVT::Other, Expand);
1826 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
1831
1836
1841
1842 if (Subtarget->isVIS3()) {
1845 }
1846
1847 if (Subtarget->is64Bit()) {
1849 Subtarget->isVIS3() ? Legal : Expand);
1851 Subtarget->isVIS3() ? Legal : Expand);
1856
1858 Subtarget->usePopc() ? Legal : Expand);
1860 setOperationAction(ISD::ROTL , MVT::i64, Expand);
1861 setOperationAction(ISD::ROTR , MVT::i64, Expand);
1863 }
1864
1865 // ATOMICs.
1866 // Atomics are supported on SparcV9. 32-bit atomics are also
1867 // supported by some Leon SparcV8 variants. Otherwise, atomics
1868 // are unsupported.
1869 //
1870 // 32-bit V9 code can only use 64-bit atomics under the V8+ ABI, which
1871 // guarantees that the upper halves of the %g and %o registers are preserved.
1872 if (Subtarget->isV9()) {
1873 if (Subtarget->is64Bit() || Subtarget->isV8Plus())
1875 else
1877 } else if (Subtarget->hasLeonCasa())
1879 else
1881
1883
1885
1887
1888 // Custom Lower Atomic LOAD/STORE
1891
1892 if (Subtarget->is64Bit()) {
1897 } else if (Subtarget->isV9() && Subtarget->isV8Plus()) {
1898 // As in GCC, 64-bit atomic loads and stores use ldd/std, and 64-bit
1899 // compare-and-swap uses casx on values packed into %g/%o registers.
1900 // Everything else is expanded to a compare-and-swap loop.
1904 }
1905
1906 if (!Subtarget->isV9()) {
1907 // SparcV8 does not have FNEGD and FABSD.
1910 }
1911
1912 setOperationAction(ISD::FSIN , MVT::f128, Expand);
1913 setOperationAction(ISD::FCOS , MVT::f128, Expand);
1916 setOperationAction(ISD::FMA , MVT::f128, Expand);
1917 setOperationAction(ISD::FSIN , MVT::f64, Expand);
1918 setOperationAction(ISD::FCOS , MVT::f64, Expand);
1921 setOperationAction(ISD::FMA, MVT::f64,
1922 Subtarget->isUA2007() ? Legal : Expand);
1923 setOperationAction(ISD::FSIN , MVT::f32, Expand);
1924 setOperationAction(ISD::FCOS , MVT::f32, Expand);
1927 setOperationAction(ISD::FMA, MVT::f32,
1928 Subtarget->isUA2007() ? Legal : Expand);
1929 setOperationAction(ISD::ROTL , MVT::i32, Expand);
1930 setOperationAction(ISD::ROTR , MVT::i32, Expand);
1931 setOperationAction(ISD::BSWAP, MVT::i32, Subtarget->isV9() ? Custom : Expand);
1935 setOperationAction(ISD::FPOW , MVT::f128, Expand);
1936 setOperationAction(ISD::FPOW , MVT::f64, Expand);
1937 setOperationAction(ISD::FPOW , MVT::f32, Expand);
1938
1942
1943 // Expands to [SU]MUL_LOHI.
1947
1948 if (Subtarget->useSoftMulDiv()) {
1949 // .umul works for both signed and unsigned
1954 }
1955
1956 if (Subtarget->is64Bit()) {
1960 Subtarget->isVIS3() ? Legal : Expand);
1962 Subtarget->isVIS3() ? Legal : Expand);
1963
1967 }
1968
1969 // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
1970 setOperationAction(ISD::VASTART , MVT::Other, Custom);
1971 // VAARG needs to be lowered to not do unaligned accesses for doubles.
1972 setOperationAction(ISD::VAARG , MVT::Other, Custom);
1973
1974 setOperationAction(ISD::TRAP , MVT::Other, Legal);
1976
1977 // Use the default implementation.
1978 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
1979 setOperationAction(ISD::VAEND , MVT::Other, Expand);
1984
1986
1988 Subtarget->usePopc() ? Legal : Expand);
1989
1990 if (Subtarget->isV9() && Subtarget->hasHardQuad()) {
1991 setOperationAction(ISD::LOAD, MVT::f128, Legal);
1992 setOperationAction(ISD::STORE, MVT::f128, Legal);
1993 } else {
1994 setOperationAction(ISD::LOAD, MVT::f128, Custom);
1996 }
1997
1998 if (Subtarget->hasHardQuad()) {
1999 setOperationAction(ISD::FADD, MVT::f128, Legal);
2000 setOperationAction(ISD::FSUB, MVT::f128, Legal);
2001 setOperationAction(ISD::FMUL, MVT::f128, Legal);
2002 setOperationAction(ISD::FDIV, MVT::f128, Legal);
2003 setOperationAction(ISD::FSQRT, MVT::f128, Legal);
2006 if (Subtarget->isV9()) {
2007 setOperationAction(ISD::FNEG, MVT::f128, Legal);
2008 setOperationAction(ISD::FABS, MVT::f128, Legal);
2009 } else {
2010 setOperationAction(ISD::FNEG, MVT::f128, Custom);
2011 setOperationAction(ISD::FABS, MVT::f128, Custom);
2012 }
2013 } else {
2014 // Custom legalize f128 operations.
2015
2016 setOperationAction(ISD::FADD, MVT::f128, Custom);
2017 setOperationAction(ISD::FSUB, MVT::f128, Custom);
2018 setOperationAction(ISD::FMUL, MVT::f128, Custom);
2019 setOperationAction(ISD::FDIV, MVT::f128, Custom);
2021 setOperationAction(ISD::FNEG, MVT::f128, Custom);
2022 setOperationAction(ISD::FABS, MVT::f128, Custom);
2023
2027 }
2028
2029 if (Subtarget->hasNoFMULS()) {
2031 }
2032
2033 // Constrained (strict) floating-point support. With soft-float all FP
2034 // operations become libcalls during type legalization instead.
2035 IsStrictFPEnabled = true;
2036 if (!Subtarget->useSoftFloat()) {
2037 for (MVT VT : {MVT::f32, MVT::f64}) {
2040 VT, Legal);
2042 Subtarget->isUA2007() ? Legal : Expand);
2043 }
2046
2047 for (MVT VT : {MVT::f32, MVT::f64, MVT::f128})
2049
2050 for (MVT VT : {MVT::i32, MVT::i64})
2053 VT, Custom);
2054
2055 if (Subtarget->hasHardQuad()) {
2059 MVT::f128, Legal);
2061 } else {
2065 MVT::f128, Custom);
2068 }
2069
2070 if (Subtarget->hasNoFMULS())
2072 }
2073
2074 // Custom combine bitcast between f64 and v2i32
2075 if (!Subtarget->is64Bit())
2077
2078 if (Subtarget->isV9())
2080
2081 if (Subtarget->hasLeonCycleCounter())
2083 MVT::i64, Custom);
2084
2085 if (Subtarget->isVIS3()) {
2090
2091 setOperationAction(ISD::CTTZ, MVT::i32,
2092 Subtarget->is64Bit() ? Promote : Expand);
2095 Subtarget->is64Bit() ? Promote : Expand);
2097 } else if (Subtarget->usePopc()) {
2102
2107 } else {
2111 Subtarget->is64Bit() ? Promote : LibCall);
2113
2114 // FIXME here we don't have any ISA extensions that could help us, so to
2115 // prevent large expansions those should be made into LibCalls.
2120 }
2121
2123
2124 // Some processors have no branch predictor and have pipelines longer than
2125 // what can be covered by the delay slot. This results in a stall, so mark
2126 // branches to be expensive on those processors.
2127 setJumpIsExpensive(Subtarget->hasNoPredictor());
2128 // The high cost of branching means that using conditional moves will
2129 // still be profitable even if the condition is predictable.
2131
2133
2134 computeRegisterProperties(Subtarget->getRegisterInfo());
2135}
2136
2138 return Subtarget->useSoftFloat();
2139}
2140
2142 EVT VT) const {
2143 if (!VT.isVector())
2144 return MVT::i32;
2146}
2147
2148/// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
2149/// be zero. Op is expected to be a target specific node. Used by DAG
2150/// combiner.
2152 (const SDValue Op,
2154 const APInt &DemandedElts,
2155 const SelectionDAG &DAG,
2156 unsigned Depth) const {
2157 KnownBits Known2;
2158 Known.resetAll();
2159
2160 switch (Op.getOpcode()) {
2161 default: break;
2162 case SPISD::SELECT_ICC:
2163 case SPISD::SELECT_XCC:
2164 case SPISD::SELECT_FCC:
2165 Known = DAG.computeKnownBits(Op.getOperand(1), Depth + 1);
2166 Known2 = DAG.computeKnownBits(Op.getOperand(0), Depth + 1);
2167
2168 // Only known if known in both the LHS and RHS.
2169 Known = Known.intersectWith(Known2);
2170 break;
2171 }
2172}
2173
2174// Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so
2175// set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
2177 ISD::CondCode CC, unsigned &SPCC) {
2178 if (isNullConstant(RHS) && CC == ISD::SETNE &&
2179 (((LHS.getOpcode() == SPISD::SELECT_ICC ||
2180 LHS.getOpcode() == SPISD::SELECT_XCC) &&
2181 LHS.getOperand(3).getOpcode() == SPISD::CMPICC) ||
2182 (LHS.getOpcode() == SPISD::SELECT_FCC &&
2183 (LHS.getOperand(3).getOpcode() == SPISD::CMPFCC ||
2184 LHS.getOperand(3).getOpcode() == SPISD::CMPFCC_V9))) &&
2185 isOneConstant(LHS.getOperand(0)) && isNullConstant(LHS.getOperand(1))) {
2186 SDValue CMPCC = LHS.getOperand(3);
2187 SPCC = LHS.getConstantOperandVal(2);
2188 LHS = CMPCC.getOperand(0);
2189 RHS = CMPCC.getOperand(1);
2190 }
2191}
2192
2193// Convert to a target node and set target flags.
2195 SelectionDAG &DAG) const {
2197 return DAG.getTargetGlobalAddress(GA->getGlobal(),
2198 SDLoc(GA),
2199 GA->getValueType(0),
2200 GA->getOffset(), TF);
2201
2203 return DAG.getTargetConstantPool(CP->getConstVal(), CP->getValueType(0),
2204 CP->getAlign(), CP->getOffset(), TF);
2205
2207 return DAG.getTargetBlockAddress(BA->getBlockAddress(),
2208 Op.getValueType(),
2209 0,
2210 TF);
2211
2213 return DAG.getTargetExternalSymbol(ES->getSymbol(),
2214 ES->getValueType(0), TF);
2215
2216 llvm_unreachable("Unhandled address SDNode");
2217}
2218
2219// Split Op into high and low parts according to HiTF and LoTF.
2220// Return an ADD node combining the parts.
2222 unsigned HiTF, unsigned LoTF,
2223 SelectionDAG &DAG) const {
2224 SDLoc DL(Op);
2225 EVT VT = Op.getValueType();
2226 SDValue Hi = DAG.getNode(SPISD::Hi, DL, VT, withTargetFlags(Op, HiTF, DAG));
2227 SDValue Lo = DAG.getNode(SPISD::Lo, DL, VT, withTargetFlags(Op, LoTF, DAG));
2228 return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
2229}
2230
2231// Build SDNodes for producing an address from a GlobalAddress, ConstantPool,
2232// or ExternalSymbol SDNode.
2234 SDLoc DL(Op);
2235 EVT VT = getPointerTy(DAG.getDataLayout());
2236
2237 // Handle PIC mode first.
2238 if (isPositionIndependent()) {
2239 const Module *M = DAG.getMachineFunction().getFunction().getParent();
2240 PICLevel::Level picLevel = M->getPICLevel();
2241
2242 SDValue GlobalBase = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, VT);
2243 // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
2244 // function has calls.
2246 MFI.setHasCalls(true);
2247
2248 if (picLevel == PICLevel::SmallPIC) {
2249 // This is the pic13 code model, the GOT is known to be smaller than 8KiB.
2250 // There is no 13-bit form of the GOTDATA_OP relocations, so always load
2251 // the address from the GOT.
2252 SDValue Idx = DAG.getNode(SPISD::Lo, DL, Op.getValueType(),
2253 withTargetFlags(Op, ELF::R_SPARC_GOT13, DAG));
2254 SDValue AbsAddr = DAG.getNode(ISD::ADD, DL, VT, GlobalBase, Idx);
2255 return DAG.getLoad(VT, DL, DAG.getEntryNode(), AbsAddr,
2257 }
2258
2259 // This is the pic32 code model, the GOT is known to be smaller than 4GB.
2260 // Use the GOTDATA_OP sequence:
2261 //
2262 // sethi %gdop_hix22(sym), %r1
2263 // xor %r1, %gdop_lox10(sym), %r1
2264 // ld[x] [%gotbase + %r1], %r2, %gdop(sym)
2265 //
2266 // The three relocations tell the linker this is a GOT load of sym's
2267 // address. If sym binds locally, the linker rewrites the sethi/xor to
2268 // produce sym's offset from the GOT and turns the load into an add, so
2269 // nothing is read from the GOT at run time. This matches GCC and matters
2270 // for code that runs before dynamic relocations are applied, such as the
2271 // dynamic linker's own startup code.
2272 SDValue Hi =
2273 DAG.getNode(SPISD::Hi, DL, VT,
2274 withTargetFlags(Op, ELF::R_SPARC_GOTDATA_OP_HIX22, DAG));
2275 SDValue Lo =
2276 DAG.getNode(SPISD::Lo, DL, VT,
2277 withTargetFlags(Op, ELF::R_SPARC_GOTDATA_OP_LOX10, DAG));
2278 SDValue Idx = DAG.getNode(ISD::XOR, DL, VT, Hi, Lo);
2279 SDValue AbsAddr = DAG.getNode(ISD::ADD, DL, VT, GlobalBase, Idx);
2280 // Attach a GOT memory operand, as for the plain GOT load above, so that
2281 // the load is still known to be invariant and can be hoisted, CSE'd and
2282 // rematerialized.
2283 SDValue Ops[] = {DAG.getEntryNode(), AbsAddr,
2284 withTargetFlags(Op, ELF::R_SPARC_GOTDATA_OP, DAG)};
2285 return DAG.getMemIntrinsicNode(
2286 SPISD::LOAD_GDOP, DL, DAG.getVTList(VT, MVT::Other), Ops, VT,
2288 /*Alignment=*/std::nullopt, MachineMemOperand::MOLoad);
2289 }
2290
2291 // This is one of the absolute code models.
2292 switch(getTargetMachine().getCodeModel()) {
2293 default:
2294 llvm_unreachable("Unsupported absolute code model");
2295 case CodeModel::Small:
2296 // abs32.
2297 return makeHiLoPair(Op, ELF::R_SPARC_HI22, ELF::R_SPARC_LO10, DAG);
2298 case CodeModel::Medium: {
2299 // abs44.
2300 SDValue H44 = makeHiLoPair(Op, ELF::R_SPARC_H44, ELF::R_SPARC_M44, DAG);
2301 H44 = DAG.getNode(ISD::SHL, DL, VT, H44, DAG.getConstant(12, DL, MVT::i32));
2302 SDValue L44 = withTargetFlags(Op, ELF::R_SPARC_L44, DAG);
2303 L44 = DAG.getNode(SPISD::Lo, DL, VT, L44);
2304 return DAG.getNode(ISD::ADD, DL, VT, H44, L44);
2305 }
2306 case CodeModel::Large: {
2307 // abs64.
2308 SDValue Hi = makeHiLoPair(Op, ELF::R_SPARC_HH22, ELF::R_SPARC_HM10, DAG);
2309 Hi = DAG.getNode(ISD::SHL, DL, VT, Hi, DAG.getConstant(32, DL, MVT::i32));
2310 SDValue Lo = makeHiLoPair(Op, ELF::R_SPARC_HI22, ELF::R_SPARC_LO10, DAG);
2311 return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
2312 }
2313 }
2314}
2315
2320
2325
2330
2332 SelectionDAG &DAG) const {
2333
2335 if (DAG.getTarget().useEmulatedTLS())
2336 return LowerToTLSEmulatedModel(GA, DAG);
2337
2338 SDLoc DL(GA);
2339 const GlobalValue *GV = GA->getGlobal();
2340 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2341
2343
2344 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) {
2345 unsigned HiTF =
2346 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_HI22
2347 : ELF::R_SPARC_TLS_LDM_HI22);
2348 unsigned LoTF =
2349 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_LO10
2350 : ELF::R_SPARC_TLS_LDM_LO10);
2351 unsigned addTF =
2352 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_ADD
2353 : ELF::R_SPARC_TLS_LDM_ADD);
2354 unsigned callTF =
2355 ((model == TLSModel::GeneralDynamic) ? ELF::R_SPARC_TLS_GD_CALL
2356 : ELF::R_SPARC_TLS_LDM_CALL);
2357
2358 SDValue HiLo = makeHiLoPair(Op, HiTF, LoTF, DAG);
2359 SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2360 SDValue Argument = DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Base, HiLo,
2361 withTargetFlags(Op, addTF, DAG));
2362
2363 SDValue Chain = DAG.getEntryNode();
2364 SDValue InGlue;
2365
2366 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, DL);
2367 Chain = DAG.getCopyToReg(Chain, DL, SP::O0, Argument, InGlue);
2368 InGlue = Chain.getValue(1);
2369 SDValue Callee = DAG.getTargetExternalSymbol("__tls_get_addr", PtrVT);
2370 SDValue Symbol = withTargetFlags(Op, callTF, DAG);
2371
2372 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
2373 const uint32_t *Mask = Subtarget->getRegisterInfo()->getCallPreservedMask(
2375 assert(Mask && "Missing call preserved mask for calling convention");
2376 SDValue Ops[] = {Chain,
2377 Callee,
2378 Symbol,
2379 DAG.getRegister(SP::O0, PtrVT),
2380 DAG.getRegisterMask(Mask),
2381 InGlue};
2382 Chain = DAG.getNode(SPISD::TLS_CALL, DL, NodeTys, Ops);
2383 InGlue = Chain.getValue(1);
2384 Chain = DAG.getCALLSEQ_END(Chain, 0, 0, InGlue, DL);
2385 InGlue = Chain.getValue(1);
2386 SDValue Ret = DAG.getCopyFromReg(Chain, DL, SP::O0, PtrVT, InGlue);
2387
2388 if (model != TLSModel::LocalDynamic)
2389 return Ret;
2390
2391 SDValue Hi =
2392 DAG.getNode(SPISD::Hi, DL, PtrVT,
2393 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_HIX22, DAG));
2394 SDValue Lo =
2395 DAG.getNode(SPISD::Lo, DL, PtrVT,
2396 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_LOX10, DAG));
2397 HiLo = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2398 return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Ret, HiLo,
2399 withTargetFlags(Op, ELF::R_SPARC_TLS_LDO_ADD, DAG));
2400 }
2401
2402 if (model == TLSModel::InitialExec) {
2403 unsigned ldTF = ((PtrVT == MVT::i64) ? ELF::R_SPARC_TLS_IE_LDX
2404 : ELF::R_SPARC_TLS_IE_LD);
2405
2406 SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2407
2408 // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
2409 // function has calls.
2411 MFI.setHasCalls(true);
2412
2413 SDValue TGA = makeHiLoPair(Op, ELF::R_SPARC_TLS_IE_HI22,
2414 ELF::R_SPARC_TLS_IE_LO10, DAG);
2415 SDValue Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Base, TGA);
2416 SDValue Ops[] = {DAG.getEntryNode(), Ptr, withTargetFlags(Op, ldTF, DAG)};
2418 SPISD::TLS_LD, DL, DAG.getVTList(PtrVT, MVT::Other), Ops, PtrVT,
2420 /*Alignment=*/std::nullopt, MachineMemOperand::MOLoad);
2421 return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT,
2422 DAG.getRegister(SP::G7, PtrVT), Offset,
2423 withTargetFlags(Op, ELF::R_SPARC_TLS_IE_ADD, DAG));
2424 }
2425
2426 assert(model == TLSModel::LocalExec);
2427 SDValue Hi = DAG.getNode(SPISD::Hi, DL, PtrVT,
2428 withTargetFlags(Op, ELF::R_SPARC_TLS_LE_HIX22, DAG));
2429 SDValue Lo = DAG.getNode(SPISD::Lo, DL, PtrVT,
2430 withTargetFlags(Op, ELF::R_SPARC_TLS_LE_LOX10, DAG));
2431 SDValue Offset = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2432
2433 return DAG.getNode(ISD::ADD, DL, PtrVT,
2434 DAG.getRegister(SP::G7, PtrVT), Offset);
2435}
2436
2438 ArgListTy &Args, SDValue Arg,
2439 const SDLoc &DL,
2440 SelectionDAG &DAG) const {
2442 EVT ArgVT = Arg.getValueType();
2443 Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
2444
2445 if (ArgTy->isFP128Ty()) {
2446 // Create a stack object and pass the pointer to the library function.
2447 int FI = MFI.CreateStackObject(16, Align(8), false);
2448 SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
2449 Chain = DAG.getStore(Chain, DL, Arg, FIPtr, MachinePointerInfo(), Align(8));
2450 Args.emplace_back(FIPtr, PointerType::getUnqual(ArgTy->getContext()));
2451 } else {
2452 Args.emplace_back(Arg, ArgTy);
2453 }
2454 return Chain;
2455}
2456
2458 RTLIB::Libcall LibFunc,
2459 unsigned numArgs) const {
2460 RTLIB::LibcallImpl LibFuncImpl = DAG.getLibcalls().getLibcallImpl(LibFunc);
2461 if (LibFuncImpl == RTLIB::Unsupported)
2462 return SDValue();
2463
2464 ArgListTy Args;
2465
2467 auto PtrVT = getPointerTy(DAG.getDataLayout());
2468
2469 SDValue Callee = DAG.getExternalSymbol(LibFuncImpl, PtrVT);
2470 Type *RetTy = Op.getValueType().getTypeForEVT(*DAG.getContext());
2471 Type *RetTyABI = RetTy;
2472 // Constrained operations carry their chain as operand 0 and must produce
2473 // an output chain, so the libcall is ordered with respect to other
2474 // FP-environment accesses.
2475 bool IsStrict = Op->isStrictFPOpcode();
2476 SDValue Chain = IsStrict ? Op.getOperand(0) : DAG.getEntryNode();
2477 unsigned FirstArg = IsStrict ? 1 : 0;
2478 SDLoc DL(Op);
2479 SDValue RetPtr;
2480
2481 if (RetTy->isFP128Ty()) {
2482 // Create a Stack Object to receive the return value of type f128.
2483 int RetFI = MFI.CreateStackObject(16, Align(8), false);
2484 RetPtr = DAG.getFrameIndex(RetFI, PtrVT);
2485 ArgListEntry Entry(RetPtr, PointerType::getUnqual(RetTy->getContext()));
2486 if (!Subtarget->is64Bit()) {
2487 Entry.IsSRet = true;
2488 Entry.IndirectType = RetTy;
2489 }
2490 Entry.IsReturned = false;
2491 Args.push_back(Entry);
2492 RetTyABI = Type::getVoidTy(*DAG.getContext());
2493 }
2494
2495 assert(Op->getNumOperands() >= numArgs + FirstArg && "Not enough operands!");
2496 for (unsigned i = 0, e = numArgs; i != e; ++i) {
2497 Chain =
2498 LowerF128_LibCallArg(Chain, Args, Op.getOperand(i + FirstArg), DL, DAG);
2499 }
2500
2503 CLI.setDebugLoc(DL).setChain(Chain).setCallee(CC, RetTyABI, Callee,
2504 std::move(Args));
2505
2506 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2507
2508 // chain is in second result.
2509 if (RetTyABI == RetTy) {
2510 if (IsStrict)
2511 return DAG.getMergeValues({CallInfo.first, CallInfo.second}, DL);
2512 return CallInfo.first;
2513 }
2514
2515 assert (RetTy->isFP128Ty() && "Unexpected return type!");
2516
2517 Chain = CallInfo.second;
2518
2519 // Load RetPtr to get the return value.
2520 SDValue Result = DAG.getLoad(Op.getValueType(), DL, Chain, RetPtr,
2522 if (IsStrict)
2523 return DAG.getMergeValues({Result, Result.getValue(1)}, DL);
2524 return Result;
2525}
2526
2527// Return the f128 compare helper for SPCC, or nullptr if there is none. This
2528// is the same choice GCC makes: _Q_feq, _Q_fne, _Q_flt, _Q_fle, _Q_fgt and
2529// _Q_fge (or their _Qp_ forms) for the predicates they implement. An ult, ule,
2530// ugt or uge, as produced by inverting a branch, is the inverse of an oge, ogt,
2531// ole or olt, so it uses that helper with Invert set. Signaling is set to the
2532// helper's exception behaviour: _Q_feq and _Q_fne are quiet like fcmp, and the
2533// ordered relational helpers are signaling like fcmpe.
2534static const char *getF128PredicateLibCall(unsigned SPCC, bool Is64Bit,
2535 bool &Invert, bool &Signaling) {
2536 Invert = false;
2537 Signaling = true;
2538 switch (SPCC) {
2539 case SPCC::FCC_E:
2540 Signaling = false;
2541 return Is64Bit ? "_Qp_feq" : "_Q_feq";
2542 case SPCC::FCC_NE:
2543 Signaling = false;
2544 return Is64Bit ? "_Qp_fne" : "_Q_fne";
2545 case SPCC::FCC_UGE:
2546 Invert = true;
2547 [[fallthrough]];
2548 case SPCC::FCC_L:
2549 return Is64Bit ? "_Qp_flt" : "_Q_flt";
2550 case SPCC::FCC_UG:
2551 Invert = true;
2552 [[fallthrough]];
2553 case SPCC::FCC_LE:
2554 return Is64Bit ? "_Qp_fle" : "_Q_fle";
2555 case SPCC::FCC_ULE:
2556 Invert = true;
2557 [[fallthrough]];
2558 case SPCC::FCC_G:
2559 return Is64Bit ? "_Qp_fgt" : "_Q_fgt";
2560 case SPCC::FCC_UL:
2561 Invert = true;
2562 [[fallthrough]];
2563 case SPCC::FCC_GE:
2564 return Is64Bit ? "_Qp_fge" : "_Q_fge";
2565 default:
2566 return nullptr;
2567 }
2568}
2569
2571 unsigned &SPCC, const SDLoc &DL,
2572 SelectionDAG &DAG) const {
2573
2574 bool is64Bit = Subtarget->is64Bit();
2575 bool Invert, Signaling;
2576 const char *LibCall =
2577 getF128PredicateLibCall(SPCC, is64Bit, Invert, Signaling);
2578 bool IsPredicateCall = LibCall != nullptr;
2579 if (!IsPredicateCall)
2580 LibCall = is64Bit ? "_Qp_cmp" : "_Q_cmp";
2581
2582 auto PtrVT = getPointerTy(DAG.getDataLayout());
2583 SDValue Callee = DAG.getExternalSymbol(LibCall, PtrVT);
2584 Type *RetTy = Type::getInt32Ty(*DAG.getContext());
2585 ArgListTy Args;
2586 SDValue Chain = DAG.getEntryNode();
2587 Chain = LowerF128_LibCallArg(Chain, Args, LHS, DL, DAG);
2588 Chain = LowerF128_LibCallArg(Chain, Args, RHS, DL, DAG);
2589
2591 CLI.setDebugLoc(DL).setChain(Chain)
2592 .setCallee(CallingConv::C, RetTy, Callee, std::move(Args));
2593
2594 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2595
2596 // result is in first, and chain is in second result.
2597 SDValue Result = CallInfo.first;
2598
2599 // The predicate helpers return nonzero if the predicate holds.
2600 if (IsPredicateCall) {
2601 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2602 SPCC = Invert ? SPCC::ICC_E : SPCC::ICC_NE;
2603 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2604 }
2605
2606 switch (SPCC) {
2607 default:
2608 llvm_unreachable("Unhandled conditional code!");
2609 case SPCC::FCC_U : {
2610 SDValue RHS = DAG.getConstant(3, DL, Result.getValueType());
2611 SPCC = SPCC::ICC_E;
2612 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2613 }
2614 case SPCC::FCC_O : {
2615 SDValue RHS = DAG.getConstant(3, DL, Result.getValueType());
2617 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2618 }
2619 case SPCC::FCC_LG : {
2620 SDValue One = DAG.getConstant(1, DL, Result.getValueType());
2621 SDValue Two = DAG.getConstant(2, DL, Result.getValueType());
2622 Result = DAG.getNode(ISD::ADD, DL, Result.getValueType(), Result, One);
2623 Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Two);
2624 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2626 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2627 }
2628 case SPCC::FCC_UE : {
2629 SDValue One = DAG.getConstant(1, DL, Result.getValueType());
2630 SDValue Two = DAG.getConstant(2, DL, Result.getValueType());
2631 Result = DAG.getNode(ISD::ADD, DL, Result.getValueType(), Result, One);
2632 Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Two);
2633 SDValue RHS = DAG.getConstant(0, DL, Result.getValueType());
2634 SPCC = SPCC::ICC_E;
2635 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2636 }
2637 }
2638}
2639
2640// Lower a constrained f128 compare to a libcall. Use the predicate-specific
2641// helper when its exception behaviour matches, as GCC does. Otherwise call
2642// _Q_cmp/_Qp_cmp (quiet) or _Q_cmpe/_Qp_cmpe (signaling), which let us pick
2643// the exception behaviour independently of the predicate, and decode the
2644// result into an integer compare.
2646 SDValue RHS, unsigned &SPCC,
2647 bool IsSignaling,
2648 const SDLoc &DL,
2649 SelectionDAG &DAG) const {
2650 bool is64Bit = Subtarget->is64Bit();
2651 auto PtrVT = getPointerTy(DAG.getDataLayout());
2652 Type *RetTy = Type::getInt32Ty(*DAG.getContext());
2653
2654 auto EmitCall = [&](const char *LibCall) {
2655 SDValue Callee = DAG.getExternalSymbol(LibCall, PtrVT);
2656 ArgListTy Args;
2657 Chain = LowerF128_LibCallArg(Chain, Args, LHS, DL, DAG);
2658 Chain = LowerF128_LibCallArg(Chain, Args, RHS, DL, DAG);
2659
2661 CLI.setDebugLoc(DL).setChain(Chain).setCallee(CallingConv::C, RetTy, Callee,
2662 std::move(Args));
2663
2664 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2665 Chain = CallInfo.second;
2666 return CallInfo.first;
2667 };
2668
2669 auto Compare = [&](SDValue V, uint64_t C, unsigned NewSPCC) {
2670 SPCC = NewSPCC;
2671 return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, V,
2672 DAG.getConstant(C, DL, V.getValueType()));
2673 };
2674
2675 // There is no signaling equality helper. Like GCC does for iseqsig, test
2676 // a >= b && a <= b with _Q_fge and _Q_fle, which are both signaling.
2677 if (IsSignaling && (SPCC == SPCC::FCC_E || SPCC == SPCC::FCC_NE)) {
2678 bool Invert = SPCC == SPCC::FCC_NE;
2679 SDValue GE = EmitCall(is64Bit ? "_Qp_fge" : "_Q_fge");
2680 SDValue LE = EmitCall(is64Bit ? "_Qp_fle" : "_Q_fle");
2681 EVT ResVT = GE.getValueType();
2682 SDValue Zero = DAG.getConstant(0, DL, ResVT);
2683 SDValue Both = DAG.getNode(ISD::AND, DL, ResVT,
2684 DAG.getSetCC(DL, ResVT, GE, Zero, ISD::SETNE),
2685 DAG.getSetCC(DL, ResVT, LE, Zero, ISD::SETNE));
2686 return Compare(Both, 0, Invert ? SPCC::ICC_E : SPCC::ICC_NE);
2687 }
2688
2689 bool Invert, Signaling;
2690 const char *LibCall =
2691 getF128PredicateLibCall(SPCC, is64Bit, Invert, Signaling);
2692 // The predicate helpers return nonzero if the predicate holds.
2693 if (LibCall && Signaling == IsSignaling)
2694 return Compare(EmitCall(LibCall), 0, Invert ? SPCC::ICC_E : SPCC::ICC_NE);
2695
2696 if (IsSignaling)
2697 LibCall = is64Bit ? "_Qp_cmpe" : "_Q_cmpe";
2698 else
2699 LibCall = is64Bit ? "_Qp_cmp" : "_Q_cmp";
2700 SDValue Result = EmitCall(LibCall);
2701 EVT ResVT = Result.getValueType();
2702
2703 auto And = [&](SDValue V, uint64_t C) {
2704 return DAG.getNode(ISD::AND, DL, ResVT, V, DAG.getConstant(C, DL, ResVT));
2705 };
2706 auto Add = [&](SDValue V, int64_t C) {
2707 return DAG.getNode(ISD::ADD, DL, ResVT, V,
2708 DAG.getSignedConstant(C, DL, ResVT));
2709 };
2710
2711 switch (SPCC) {
2712 default:
2713 llvm_unreachable("Unhandled conditional code!");
2714 case SPCC::FCC_L: // 1
2715 return Compare(Result, 1, SPCC::ICC_E);
2716 case SPCC::FCC_G: // 2
2717 return Compare(Result, 2, SPCC::ICC_E);
2718 case SPCC::FCC_LE: // 0, 1
2719 return Compare(Result, 2, SPCC::ICC_CS);
2720 case SPCC::FCC_GE: // 0, 2
2721 return Compare(And(Result, 1), 0, SPCC::ICC_E);
2722 case SPCC::FCC_UL: // 1, 3
2723 return Compare(And(Result, 1), 0, SPCC::ICC_NE);
2724 case SPCC::FCC_ULE: // 0, 1, 3
2725 return Compare(Result, 2, SPCC::ICC_NE);
2726 case SPCC::FCC_UG: // 2, 3
2727 return Compare(Result, 1, SPCC::ICC_GU);
2728 case SPCC::FCC_UGE: // 0, 2, 3
2729 return Compare(Result, 1, SPCC::ICC_NE);
2730 case SPCC::FCC_U: // 3
2731 return Compare(Result, 3, SPCC::ICC_E);
2732 case SPCC::FCC_O: // 0, 1, 2
2733 return Compare(Result, 3, SPCC::ICC_NE);
2734 case SPCC::FCC_LG: // 1, 2
2735 return Compare(Add(Result, -1), 2, SPCC::ICC_CS);
2736 case SPCC::FCC_UE: // 0, 3
2737 return Compare(And(Add(Result, 1), 2), 0, SPCC::ICC_E);
2738 }
2739}
2740
2741static SDValue
2743 const SparcTargetLowering &TLI) {
2744 EVT SrcVT = Op.getOperand(Op->isStrictFPOpcode() ? 1 : 0).getValueType();
2745
2746 if (SrcVT == MVT::f64)
2747 return TLI.LowerF128Op(Op, DAG, RTLIB::FPEXT_F64_F128, 1);
2748
2749 if (SrcVT == MVT::f32)
2750 return TLI.LowerF128Op(Op, DAG, RTLIB::FPEXT_F32_F128, 1);
2751
2752 llvm_unreachable("fpextend with non-float operand!");
2753 return SDValue();
2754}
2755
2756static SDValue
2758 const SparcTargetLowering &TLI) {
2759 // FP_ROUND on f64 and f32 are legal.
2760 if (Op.getOperand(Op->isStrictFPOpcode() ? 1 : 0).getValueType() != MVT::f128)
2761 return Op;
2762
2763 if (Op.getValueType() == MVT::f64)
2764 return TLI.LowerF128Op(Op, DAG, RTLIB::FPROUND_F128_F64, 1);
2765 if (Op.getValueType() == MVT::f32)
2766 return TLI.LowerF128Op(Op, DAG, RTLIB::FPROUND_F128_F32, 1);
2767
2768 llvm_unreachable("fpround to non-float!");
2769 return SDValue();
2770}
2771
2773 const SparcTargetLowering &TLI,
2774 bool hasHardQuad) {
2775 SDLoc dl(Op);
2776 EVT VT = Op.getValueType();
2777 assert(VT == MVT::i32 || VT == MVT::i64);
2778 bool IsStrict = Op->isStrictFPOpcode();
2779 SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
2780
2781 // Expand f128 operations to fp128 abi calls.
2782 if (Src.getValueType() == MVT::f128 &&
2783 (!hasHardQuad || !TLI.isTypeLegal(VT))) {
2784 RTLIB::Libcall LibFunc =
2785 VT == MVT::i32 ? RTLIB::FPTOSINT_F128_I32 : RTLIB::FPTOSINT_F128_I64;
2786 return TLI.LowerF128Op(Op, DAG, LibFunc, 1);
2787 }
2788
2789 // Expand if the resulting type is illegal.
2790 if (!TLI.isTypeLegal(VT))
2791 return SDValue();
2792
2793 // Otherwise, Convert the fp value to integer in an FP register.
2794 MVT FloatVT = VT == MVT::i32 ? MVT::f32 : MVT::f64;
2795 if (IsStrict) {
2796 unsigned Opc = VT == MVT::i32 ? SPISD::STRICT_FTOI : SPISD::STRICT_FTOX;
2797 SDValue Conv =
2798 DAG.getNode(Opc, dl, {FloatVT, MVT::Other}, {Op.getOperand(0), Src});
2799 SDValue Res = DAG.getNode(ISD::BITCAST, dl, VT, Conv);
2800 return DAG.getMergeValues({Res, Conv.getValue(1)}, dl);
2801 }
2802
2803 unsigned Opc = VT == MVT::i32 ? SPISD::FTOI : SPISD::FTOX;
2804 Op = DAG.getNode(Opc, dl, FloatVT, Src);
2805 return DAG.getNode(ISD::BITCAST, dl, VT, Op);
2806}
2807
2809 const SparcTargetLowering &TLI,
2810 bool hasHardQuad) {
2811 SDLoc dl(Op);
2812 bool IsStrict = Op->isStrictFPOpcode();
2813 SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
2814 EVT OpVT = Src.getValueType();
2815 assert(OpVT == MVT::i32 || (OpVT == MVT::i64));
2816
2817 EVT floatVT = (OpVT == MVT::i32) ? MVT::f32 : MVT::f64;
2818
2819 // Expand f128 operations to fp128 ABI calls.
2820 if (Op.getValueType() == MVT::f128
2821 && (!hasHardQuad || !TLI.isTypeLegal(OpVT))) {
2822 RTLIB::Libcall LibFunc =
2823 OpVT == MVT::i32 ? RTLIB::SINTTOFP_I32_F128 : RTLIB::SINTTOFP_I64_F128;
2824 return TLI.LowerF128Op(Op, DAG, LibFunc, 1);
2825 }
2826
2827 // Expand if the operand type is illegal.
2828 if (!TLI.isTypeLegal(OpVT))
2829 return SDValue();
2830
2831 // Otherwise, Convert the int value to FP in an FP register.
2832 SDValue Tmp;
2833 auto *LD = dyn_cast<LoadSDNode>(Src);
2834 if (LD && Src.hasOneUse() && ISD::isNormalLoad(LD) && LD->isSimple()) {
2835 // Load the integer directly into an FP register instead of moving it
2836 // there from an integer register through the stack.
2837 LD->getMemOperand()->clearRanges();
2838 Tmp = DAG.getLoad(floatVT, dl, LD->getChain(), LD->getBasePtr(),
2839 LD->getMemOperand());
2840 DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), Tmp.getValue(1));
2841 } else {
2842 Tmp = DAG.getNode(ISD::BITCAST, dl, floatVT, Src);
2843 }
2844 if (IsStrict) {
2845 unsigned Opc = OpVT == MVT::i32 ? SPISD::STRICT_ITOF : SPISD::STRICT_XTOF;
2846 return DAG.getNode(Opc, dl, {Op.getValueType(), MVT::Other},
2847 {Op.getOperand(0), Tmp});
2848 }
2849 unsigned opcode = (OpVT == MVT::i32)? SPISD::ITOF : SPISD::XTOF;
2850 return DAG.getNode(opcode, dl, Op.getValueType(), Tmp);
2851}
2852
2854 const SparcTargetLowering &TLI,
2855 bool hasHardQuad) {
2856 EVT VT = Op.getValueType();
2857 SDValue Src = Op.getOperand(Op->isStrictFPOpcode() ? 1 : 0);
2858
2859 // Expand if it does not involve f128 or the target has support for
2860 // quad floating point instructions and the resulting type is legal.
2861 if (Src.getValueType() != MVT::f128 || (hasHardQuad && TLI.isTypeLegal(VT)))
2862 return SDValue();
2863
2864 assert(VT == MVT::i32 || VT == MVT::i64);
2865
2866 return TLI.LowerF128Op(
2867 Op, DAG,
2868 VT == MVT::i32 ? RTLIB::FPTOUINT_F128_I32 : RTLIB::FPTOUINT_F128_I64, 1);
2869}
2870
2872 const SparcTargetLowering &TLI,
2873 bool hasHardQuad) {
2874 SDLoc dl(Op);
2875 EVT VT = Op.getValueType();
2876 bool IsStrict = Op->isStrictFPOpcode();
2877 SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
2878 EVT OpVT = Src.getValueType();
2879 assert(OpVT == MVT::i32 || OpVT == MVT::i64);
2880
2881 // Expand f128 operations to fp128 ABI calls if there is no hardware quad
2882 // support or the operand type is illegal.
2883 if (VT == MVT::f128 && (!hasHardQuad || !TLI.isTypeLegal(OpVT)))
2884 return TLI.LowerF128Op(Op, DAG,
2885 OpVT == MVT::i32 ? RTLIB::UINTTOFP_I32_F128
2886 : RTLIB::UINTTOFP_I64_F128,
2887 1);
2888
2889 // When i64 is legal, zero-extend an i32 operand and use the signed 64-bit
2890 // conversion (fxtos/fxtod/fxtoq). The generic i32 expansion builds the
2891 // double 0x43300000:x and subtracts 2^52, which yields -0.0 for an input of
2892 // 0 when rounding toward negative infinity.
2893 if (OpVT == MVT::i32 && TLI.isTypeLegal(MVT::i64)) {
2894 SDValue Ext = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, Src);
2895 if (IsStrict)
2896 return DAG.getNode(ISD::STRICT_SINT_TO_FP, dl, {VT, MVT::Other},
2897 {Op.getOperand(0), Ext});
2898 return DAG.getNode(ISD::SINT_TO_FP, dl, VT, Ext);
2899 }
2900
2901 // For i64 to f64, the generic non-strict expansion splits the operand into
2902 // 2^84 and 2^52 biased halves, which also yields -0.0 for an input of 0 when
2903 // rounding toward negative infinity. Use the same sequence as the strict
2904 // expansion instead: if the sign bit is set, halve the operand keeping the
2905 // low bit sticky, convert with fxtod and double the result. This is correct
2906 // in all rounding modes and avoids the constant pool load.
2907 if (!IsStrict && OpVT == MVT::i64 && VT == MVT::f64 &&
2908 TLI.isTypeLegal(MVT::i64)) {
2909 if (Op->getFlags().hasNonNeg())
2910 return DAG.getNode(ISD::SINT_TO_FP, dl, VT, Src);
2911
2912 EVT SetCCVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
2913 MVT::i64);
2914 SDValue SignBitTest = DAG.getSetCC(
2915 dl, SetCCVT, Src, DAG.getConstant(0, dl, MVT::i64), ISD::SETLT);
2916 SDValue Shr = DAG.getNode(ISD::SRL, dl, MVT::i64, Src,
2917 DAG.getShiftAmountConstant(1, MVT::i64, dl));
2918 SDValue And = DAG.getNode(ISD::AND, dl, MVT::i64, Src,
2919 DAG.getConstant(1, dl, MVT::i64));
2920 SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i64, And, Shr);
2921 SDValue InCvt = DAG.getSelect(dl, MVT::i64, SignBitTest, Or, Src);
2922 SDValue Cvt = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64, InCvt);
2923 SDValue Dbl = DAG.getNode(ISD::FADD, dl, MVT::f64, Cvt, Cvt);
2924 return DAG.getSelect(dl, MVT::f64, SignBitTest, Dbl, Cvt);
2925 }
2926
2927 // Otherwise, use the generic expansion.
2928 return SDValue();
2929}
2930
2931// Lower a constrained FP compare. The quiet form uses fcmp and the signaling
2932// form uses fcmpe (or the corresponding f128 libcall), and the result is
2933// materialized with a conditional select.
2935 const SparcTargetLowering &TLI,
2936 bool hasHardQuad, bool isV9) {
2937 SDLoc dl(Op);
2938 bool IsSignaling = Op.getOpcode() == ISD::STRICT_FSETCCS;
2939 SDValue Chain = Op.getOperand(0);
2940 SDValue LHS = Op.getOperand(1);
2941 SDValue RHS = Op.getOperand(2);
2942 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(3))->get();
2943 EVT VT = Op.getValueType();
2944 unsigned SPCC = FPCondCCodeToFCC(CC);
2945
2946 SDValue CompareFlag;
2947 unsigned SelectOpc;
2948 if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
2949 CompareFlag =
2950 TLI.LowerF128StrictCompare(Chain, LHS, RHS, SPCC, IsSignaling, dl, DAG);
2951 SelectOpc = SPISD::SELECT_ICC;
2952 } else {
2953 unsigned CmpOpc;
2954 if (isV9)
2955 CmpOpc = IsSignaling ? SPISD::STRICT_CMPFCCS_V9 : SPISD::STRICT_CMPFCC_V9;
2956 else
2957 CmpOpc = IsSignaling ? SPISD::STRICT_CMPFCCS : SPISD::STRICT_CMPFCC;
2958 SDValue Cmp =
2959 DAG.getNode(CmpOpc, dl, {MVT::Other, MVT::Glue}, {Chain, LHS, RHS});
2960 Chain = Cmp.getValue(0);
2961 CompareFlag = Cmp.getValue(1);
2962 SelectOpc = SPISD::SELECT_FCC;
2963 }
2964
2965 SDValue Res = DAG.getNode(SelectOpc, dl, VT, DAG.getConstant(1, dl, VT),
2966 DAG.getConstant(0, dl, VT),
2967 DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
2968 return DAG.getMergeValues({Res, Chain}, dl);
2969}
2970
2971// If this is a br_cc on the result of a constrained FP compare that was
2972// lowered into a STRICT_CMPFCC*/SELECT_FCC pair, set Chain and Glue so that
2973// the branch can test the FP condition codes directly instead of
2974// materializing the result and comparing it against zero.
2975//
2976// The compare is glued to the branch, so nothing may be scheduled between
2977// them, and the branch's chain must come straight from the compare. That is
2978// the case if the compare's output chain feeds only the branch. If it instead
2979// reaches the branch through a token factor used only by the branch, emit a
2980// new compare chained after the token factor's other operands and branch on
2981// that. Those operands were not ordered with respect to the compare, and the
2982// original compare and its select become dead.
2984 ISD::CondCode CC, unsigned &SPCC,
2985 SDValue &Glue, const SDLoc &DL,
2986 SelectionDAG &DAG) {
2987 if (CC != ISD::SETNE || !isNullConstant(RHS) ||
2988 LHS.getOpcode() != SPISD::SELECT_FCC || !LHS.hasOneUse() ||
2989 !isOneConstant(LHS.getOperand(0)) || !isNullConstant(LHS.getOperand(1)))
2990 return false;
2991
2992 SDNode *Cmp = LHS.getOperand(3).getNode();
2993 switch (Cmp->getOpcode()) {
2994 case SPISD::STRICT_CMPFCC:
2995 case SPISD::STRICT_CMPFCCS:
2996 case SPISD::STRICT_CMPFCC_V9:
2997 case SPISD::STRICT_CMPFCCS_V9:
2998 break;
2999 default:
3000 return false;
3001 }
3002
3003 SDValue CmpChain(Cmp, 0);
3004 if (!CmpChain.hasOneUse())
3005 return false;
3006
3007 if (Chain == CmpChain) {
3008 Glue = SDValue(Cmp, 1);
3009 } else if (Chain.getOpcode() == ISD::TokenFactor && Chain.hasOneUse() &&
3010 is_contained(Chain->op_values(), CmpChain)) {
3012 for (SDValue Op : Chain->op_values())
3013 if (Op != CmpChain)
3014 Ops.push_back(Op);
3015 Ops.push_back(Cmp->getOperand(0));
3016 SDValue InChain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Ops);
3017 SDValue NewCmp =
3018 DAG.getNode(Cmp->getOpcode(), DL, Cmp->getVTList(),
3019 {InChain, Cmp->getOperand(1), Cmp->getOperand(2)});
3020 Chain = NewCmp.getValue(0);
3021 Glue = NewCmp.getValue(1);
3022 } else {
3023 return false;
3024 }
3025
3026 SPCC = LHS.getConstantOperandVal(2);
3027 return true;
3028}
3029
3031 const SparcTargetLowering &TLI, bool hasHardQuad,
3032 bool isV9, bool is64Bit) {
3033 SDValue Chain = Op.getOperand(0);
3034 ISD::CondCode CC = Op.getOperandCondCode(1);
3035 SDValue LHS = Op.getOperand(2);
3036 SDValue RHS = Op.getOperand(3);
3037 SDValue Dest = Op.getOperand(4);
3038 SDLoc dl(Op);
3039 unsigned Opc, SPCC = ~0U;
3040
3041 // A brcond on the result of a lowered setcc is expanded into
3042 // br_cc (and X, 1), 0, setne. When X is a SELECT_[IF]CC of 1 and 0 the and
3043 // is a no-op, so look through it.
3044 if (CC == ISD::SETNE && isNullConstant(RHS) && LHS.getOpcode() == ISD::AND &&
3045 isOneConstant(LHS.getOperand(1)) && LHS.hasOneUse()) {
3046 SDValue Sel = LHS.getOperand(0);
3047 if ((Sel.getOpcode() == SPISD::SELECT_ICC ||
3048 Sel.getOpcode() == SPISD::SELECT_XCC ||
3049 Sel.getOpcode() == SPISD::SELECT_FCC) &&
3051 LHS = Sel;
3052 }
3053
3054 // If this is a br_cc of a "setcc", and if the setcc got lowered into
3055 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
3057 assert(LHS.getValueType() == RHS.getValueType());
3058
3059 // Likewise for a constrained FP compare, branch on the FP condition codes.
3060 SDValue StrictCmpFlag;
3061 if (LookThroughStrictSetCC(Chain, LHS, RHS, CC, SPCC, StrictCmpFlag, dl, DAG))
3062 return DAG.getNode(isV9 ? SPISD::BRFCC_V9 : SPISD::BRFCC, dl, MVT::Other,
3063 Chain, Dest, DAG.getConstant(SPCC, dl, MVT::i32),
3064 StrictCmpFlag);
3065
3066 // Get the condition flag.
3067 SDValue CompareFlag;
3068 if (LHS.getValueType().isInteger()) {
3069 // On V9 processors running in 64-bit mode, if CC compares two `i64`s
3070 // and the RHS is zero we might be able to use a specialized branch.
3071 if (is64Bit && isV9 && LHS.getValueType() == MVT::i64 &&
3073 return DAG.getNode(SPISD::BR_REG, dl, MVT::Other, Chain, Dest,
3074 DAG.getConstant(intCondCCodeToRcond(CC), dl, MVT::i32),
3075 LHS);
3076
3077 CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
3078 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
3079 if (isV9)
3080 // 32-bit compares use the icc flags, 64-bit uses the xcc flags.
3081 Opc = LHS.getValueType() == MVT::i32 ? SPISD::BPICC : SPISD::BPXCC;
3082 else
3083 // Non-v9 targets don't have xcc.
3084 Opc = SPISD::BRICC;
3085 } else {
3086 if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
3087 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
3088 CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
3089 Opc = isV9 ? SPISD::BPICC : SPISD::BRICC;
3090 } else {
3091 unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
3092 CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
3093 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
3094 Opc = isV9 ? SPISD::BRFCC_V9 : SPISD::BRFCC;
3095 }
3096 }
3097 return DAG.getNode(Opc, dl, MVT::Other, Chain, Dest,
3098 DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
3099}
3100
3102 const SparcTargetLowering &TLI, bool hasHardQuad,
3103 bool isV9, bool is64Bit) {
3104 SDValue LHS = Op.getOperand(0);
3105 SDValue RHS = Op.getOperand(1);
3106 ISD::CondCode CC = Op.getOperandCondCode(4);
3107 SDValue TrueVal = Op.getOperand(2);
3108 SDValue FalseVal = Op.getOperand(3);
3109 SDLoc dl(Op);
3110 unsigned Opc, SPCC = ~0U;
3111
3112 // If this is a select_cc of a "setcc", and if the setcc got lowered into
3113 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
3115 assert(LHS.getValueType() == RHS.getValueType());
3116
3117 SDValue CompareFlag;
3118 if (LHS.getValueType().isInteger()) {
3119 // On V9 processors running in 64-bit mode, if CC compares two `i64`s
3120 // and the RHS is zero we might be able to use a specialized select.
3121 // All SELECT_CC between any two scalar integer types are eligible for
3122 // lowering to specialized instructions. Additionally, f32 and f64 types
3123 // are also eligible, but for f128 we can only use the specialized
3124 // instruction when we have hardquad.
3125 EVT ValType = TrueVal.getValueType();
3126 bool IsEligibleType = ValType.isScalarInteger() || ValType == MVT::f32 ||
3127 ValType == MVT::f64 ||
3128 (ValType == MVT::f128 && hasHardQuad);
3129 if (is64Bit && isV9 && LHS.getValueType() == MVT::i64 &&
3130 isNullConstant(RHS) && !ISD::isUnsignedIntSetCC(CC) && IsEligibleType)
3131 return DAG.getNode(
3132 SPISD::SELECT_REG, dl, TrueVal.getValueType(), TrueVal, FalseVal,
3133 DAG.getConstant(intCondCCodeToRcond(CC), dl, MVT::i32), LHS);
3134
3135 CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
3136 Opc = LHS.getValueType() == MVT::i32 ?
3137 SPISD::SELECT_ICC : SPISD::SELECT_XCC;
3138 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
3139 } else {
3140 if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
3141 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
3142 CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
3143 Opc = SPISD::SELECT_ICC;
3144 } else {
3145 unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
3146 CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
3147 Opc = SPISD::SELECT_FCC;
3148 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
3149 }
3150 }
3151 return DAG.getNode(Opc, dl, TrueVal.getValueType(), TrueVal, FalseVal,
3152 DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
3153}
3154
3156 const SparcTargetLowering &TLI) {
3159 auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
3160
3161 // Need frame address to find the address of VarArgsFrameIndex.
3163
3164 // vastart just stores the address of the VarArgsFrameIndex slot into the
3165 // memory location argument.
3166 SDLoc DL(Op);
3167 SDValue Offset =
3168 DAG.getNode(ISD::ADD, DL, PtrVT, DAG.getRegister(SP::I6, PtrVT),
3169 DAG.getIntPtrConstant(FuncInfo->getVarArgsFrameOffset(), DL));
3170 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
3171 return DAG.getStore(Op.getOperand(0), DL, Offset, Op.getOperand(1),
3172 MachinePointerInfo(SV));
3173}
3174
3176 SDNode *Node = Op.getNode();
3177 EVT VT = Node->getValueType(0);
3178 SDValue InChain = Node->getOperand(0);
3179 SDValue VAListPtr = Node->getOperand(1);
3180 EVT PtrVT = VAListPtr.getValueType();
3181 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
3182 SDLoc DL(Node);
3183 SDValue VAList =
3184 DAG.getLoad(PtrVT, DL, InChain, VAListPtr, MachinePointerInfo(SV));
3185 // Increment the pointer, VAList, to the next vaarg.
3186 SDValue NextPtr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
3188 DL));
3189 // Store the incremented VAList to the legalized pointer.
3190 InChain = DAG.getStore(VAList.getValue(1), DL, NextPtr, VAListPtr,
3191 MachinePointerInfo(SV));
3192 // Load the actual argument out of the pointer VAList.
3193 // We can't count on greater alignment than the word size.
3194 return DAG.getLoad(
3195 VT, DL, InChain, VAList, MachinePointerInfo(),
3196 Align(std::min(PtrVT.getFixedSizeInBits(), VT.getFixedSizeInBits()) / 8));
3197}
3198
3200 const SparcSubtarget &Subtarget) {
3201 SDValue Chain = Op.getOperand(0);
3202 EVT VT = Op->getValueType(0);
3203 SDLoc DL(Op);
3204
3205 MCRegister SPReg = SP::O6;
3206 SDValue SP = DAG.getCopyFromReg(Chain, DL, SPReg, VT);
3207
3208 // Unbias the stack pointer register.
3209 unsigned OffsetToStackStart = Subtarget.getStackPointerBias();
3210 // Move past the register save area: 8 in registers + 8 local registers.
3211 OffsetToStackStart += 16 * (Subtarget.is64Bit() ? 8 : 4);
3212 // Move past the struct return address slot (4 bytes) on SPARC 32-bit.
3213 if (!Subtarget.is64Bit())
3214 OffsetToStackStart += 4;
3215
3216 SDValue StackAddr = DAG.getNode(ISD::ADD, DL, VT, SP,
3217 DAG.getConstant(OffsetToStackStart, DL, VT));
3218 return DAG.getMergeValues({StackAddr, Chain}, DL);
3219}
3220
3222 const SparcSubtarget *Subtarget) {
3223 SDValue Chain = Op.getOperand(0);
3224 SDValue Size = Op.getOperand(1);
3225 SDValue Alignment = Op.getOperand(2);
3226 MaybeAlign MaybeAlignment =
3227 cast<ConstantSDNode>(Alignment)->getMaybeAlignValue();
3228 EVT VT = Size->getValueType(0);
3229 SDLoc dl(Op);
3230
3231 unsigned SPReg = SP::O6;
3232 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
3233
3234 // The resultant pointer needs to be above the register spill area
3235 // at the bottom of the stack.
3236 unsigned regSpillArea;
3237 if (Subtarget->is64Bit()) {
3238 regSpillArea = 128;
3239 } else {
3240 // On Sparc32, the size of the spill area is 92. Unfortunately,
3241 // that's only 4-byte aligned, not 8-byte aligned (the stack
3242 // pointer is 8-byte aligned). So, if the user asked for an 8-byte
3243 // aligned dynamic allocation, we actually need to add 96 to the
3244 // bottom of the stack, instead of 92, to ensure 8-byte alignment.
3245
3246 // That also means adding 4 to the size of the allocation --
3247 // before applying the 8-byte rounding. Unfortunately, we the
3248 // value we get here has already had rounding applied. So, we need
3249 // to add 8, instead, wasting a bit more memory.
3250
3251 // Further, this only actually needs to be done if the required
3252 // alignment is > 4, but, we've lost that info by this point, too,
3253 // so we always apply it.
3254
3255 // (An alternative approach would be to always reserve 96 bytes
3256 // instead of the required 92, but then we'd waste 4 extra bytes
3257 // in every frame, not just those with dynamic stack allocations)
3258
3259 // TODO: modify code in SelectionDAGBuilder to make this less sad.
3260
3261 Size = DAG.getNode(ISD::ADD, dl, VT, Size,
3262 DAG.getConstant(8, dl, VT));
3263 regSpillArea = 96;
3264 }
3265
3266 int64_t Bias = Subtarget->getStackPointerBias();
3267
3268 // Debias and increment SP past the reserved spill area.
3269 // We need the SP to point to the first usable region before calculating
3270 // anything to prevent any of the pointers from becoming out of alignment when
3271 // we rebias the SP later on.
3272 SDValue StartOfUsableStack = DAG.getNode(
3273 ISD::ADD, dl, VT, SP, DAG.getConstant(regSpillArea + Bias, dl, VT));
3274 SDValue AllocatedPtr =
3275 DAG.getNode(ISD::SUB, dl, VT, StartOfUsableStack, Size);
3276
3277 bool IsOveraligned = MaybeAlignment.has_value();
3278 SDValue AlignedPtr =
3279 IsOveraligned
3280 ? DAG.getNode(ISD::AND, dl, VT, AllocatedPtr,
3281 DAG.getSignedConstant(-MaybeAlignment->value(), dl, VT))
3282 : AllocatedPtr;
3283
3284 // Now that we are done, restore the bias and reserved spill area.
3285 SDValue NewSP = DAG.getNode(ISD::SUB, dl, VT, AlignedPtr,
3286 DAG.getConstant(regSpillArea + Bias, dl, VT));
3287 Chain = DAG.getCopyToReg(SP.getValue(1), dl, SPReg, NewSP);
3288 SDValue Ops[2] = {AlignedPtr, Chain};
3289 return DAG.getMergeValues(Ops, dl);
3290}
3291
3292
3294 SDLoc dl(Op);
3295 SDValue Chain = DAG.getNode(SPISD::FLUSHW,
3296 dl, MVT::Other, DAG.getEntryNode());
3297 return Chain;
3298}
3299
3302 bool AlwaysFlush = false) {
3304 MFI.setFrameAddressIsTaken(true);
3305
3306 EVT VT = Op.getValueType();
3307 SDLoc dl(Op);
3308 unsigned FrameReg = SP::I6;
3309 unsigned stackBias = Subtarget->getStackPointerBias();
3310
3311 SDValue FrameAddr;
3312 SDValue Chain;
3313
3314 // flush first to make sure the windowed registers' values are in stack
3315 Chain = (depth || AlwaysFlush) ? getFLUSHW(Op, DAG) : DAG.getEntryNode();
3316
3317 FrameAddr = DAG.getCopyFromReg(Chain, dl, FrameReg, VT);
3318
3319 unsigned Offset = (Subtarget->is64Bit()) ? (stackBias + 112) : 56;
3320
3321 while (depth--) {
3322 SDValue Ptr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
3323 DAG.getIntPtrConstant(Offset, dl));
3324 FrameAddr = DAG.getLoad(VT, dl, Chain, Ptr, MachinePointerInfo());
3325 }
3326 if (Subtarget->is64Bit())
3327 FrameAddr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
3328 DAG.getIntPtrConstant(stackBias, dl));
3329 return FrameAddr;
3330}
3331
3332
3334 const SparcSubtarget *Subtarget) {
3335
3336 uint64_t depth = Op.getConstantOperandVal(0);
3337
3338 return getFRAMEADDR(depth, Op, DAG, Subtarget);
3339
3340}
3341
3343 const SparcTargetLowering &TLI,
3344 const SparcSubtarget *Subtarget) {
3346 MachineFrameInfo &MFI = MF.getFrameInfo();
3347 MFI.setReturnAddressIsTaken(true);
3348
3349 EVT VT = Op.getValueType();
3350 SDLoc dl(Op);
3351 uint64_t depth = Op.getConstantOperandVal(0);
3352
3353 SDValue RetAddr;
3354 if (depth == 0) {
3355 auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
3356 Register RetReg = MF.addLiveIn(SP::I7, TLI.getRegClassFor(PtrVT));
3357 RetAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, RetReg, VT);
3358 return RetAddr;
3359 }
3360
3361 // Need frame address to find return address of the caller.
3362 SDValue FrameAddr = getFRAMEADDR(depth - 1, Op, DAG, Subtarget, true);
3363
3364 unsigned Offset = (Subtarget->is64Bit()) ? 120 : 60;
3365 SDValue Ptr = DAG.getNode(ISD::ADD,
3366 dl, VT,
3367 FrameAddr,
3368 DAG.getIntPtrConstant(Offset, dl));
3369 RetAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), Ptr, MachinePointerInfo());
3370
3371 return RetAddr;
3372}
3373
3374static SDValue LowerF64Op(SDValue SrcReg64, const SDLoc &dl, SelectionDAG &DAG,
3375 unsigned opcode) {
3376 assert(SrcReg64.getValueType() == MVT::f64 && "LowerF64Op called on non-double!");
3377 assert(opcode == ISD::FNEG || opcode == ISD::FABS);
3378
3379 // Lower fneg/fabs on f64 to fneg/fabs on f32.
3380 // fneg f64 => fneg f32:sub_even, fmov f32:sub_odd.
3381 // fabs f64 => fabs f32:sub_even, fmov f32:sub_odd.
3382
3383 // Note: in little-endian, the floating-point value is stored in the
3384 // registers are in the opposite order, so the subreg with the sign
3385 // bit is the highest-numbered (odd), rather than the
3386 // lowest-numbered (even).
3387
3388 SDValue Hi32 = DAG.getTargetExtractSubreg(SP::sub_even, dl, MVT::f32,
3389 SrcReg64);
3390 SDValue Lo32 = DAG.getTargetExtractSubreg(SP::sub_odd, dl, MVT::f32,
3391 SrcReg64);
3392
3393 if (DAG.getDataLayout().isLittleEndian())
3394 Lo32 = DAG.getNode(opcode, dl, MVT::f32, Lo32);
3395 else
3396 Hi32 = DAG.getNode(opcode, dl, MVT::f32, Hi32);
3397
3398 SDValue DstReg64 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
3399 dl, MVT::f64), 0);
3400 DstReg64 = DAG.getTargetInsertSubreg(SP::sub_even, dl, MVT::f64,
3401 DstReg64, Hi32);
3402 DstReg64 = DAG.getTargetInsertSubreg(SP::sub_odd, dl, MVT::f64,
3403 DstReg64, Lo32);
3404 return DstReg64;
3405}
3406
3407// Lower a f128 load into two f64 loads.
3409{
3410 SDLoc dl(Op);
3411 LoadSDNode *LdNode = cast<LoadSDNode>(Op.getNode());
3412 assert(LdNode->getOffset().isUndef() && "Unexpected node type");
3413
3414 Align Alignment = commonAlignment(LdNode->getBaseAlign(), 8);
3415
3416 SDValue Hi64 =
3417 DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LdNode->getBasePtr(),
3418 LdNode->getPointerInfo(), Alignment);
3419 EVT addrVT = LdNode->getBasePtr().getValueType();
3420 SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
3421 LdNode->getBasePtr(),
3422 DAG.getConstant(8, dl, addrVT));
3423 SDValue Lo64 = DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LoPtr,
3424 LdNode->getPointerInfo().getWithOffset(8),
3425 Alignment);
3426
3427 SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
3428 SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
3429
3430 SDNode *InFP128 = DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
3431 dl, MVT::f128);
3432 InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
3433 MVT::f128,
3434 SDValue(InFP128, 0),
3435 Hi64,
3436 SubRegEven);
3437 InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
3438 MVT::f128,
3439 SDValue(InFP128, 0),
3440 Lo64,
3441 SubRegOdd);
3442 SDValue OutChains[2] = { SDValue(Hi64.getNode(), 1),
3443 SDValue(Lo64.getNode(), 1) };
3444 SDValue OutChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
3445 SDValue Ops[2] = {SDValue(InFP128,0), OutChain};
3446 return DAG.getMergeValues(Ops, dl);
3447}
3448
3450 // We don't have an in-register bswap, so expand bswap(x) into
3451 // load(store-swapped(x)). The reason the swap is done during the store is
3452 // that on some implementations (mainly older ones) ASI-tagged memory
3453 // operations are not pipelined, and generally stores finish faster than
3454 // loads.
3455
3457 MachineFrameInfo &MFI = MF.getFrameInfo();
3458 MVT PtrVT = getPointerTy(DAG.getDataLayout());
3459 SDValue Chain = DAG.getEntryNode();
3460 bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
3461 SDLoc DL(Op);
3462
3463 SDValue BSwapOp = Op.getOperand(0);
3464 EVT VT = BSwapOp.getValueType();
3465 Type *Ty = VT.getTypeForEVT(*DAG.getContext());
3466 Align Al = DAG.getDataLayout().getPrefTypeAlign(Ty);
3467
3468 // Create a stack object to serve as temporary storage.
3469 int TmpFI = MFI.CreateStackObject(VT.getStoreSize(), Al, false);
3470 SDValue TmpPtr = DAG.getFrameIndex(TmpFI, PtrVT);
3471
3472 // Store-swap the value, then load it back.
3473 SDValue Ops[] = {Chain, BSwapOp, TmpPtr, DAG.getValueType(VT)};
3475 IsLittleEndian ? SPISD::STORE_BIG : SPISD::STORE_LITTLE, DL,
3476 DAG.getVTList(MVT::Other), Ops, VT,
3477 MachinePointerInfo::getFixedStack(MF, TmpFI), std::nullopt,
3479 return DAG.getLoad(VT, DL, ST, TmpPtr,
3481}
3482
3484{
3485 LoadSDNode *LdNode = cast<LoadSDNode>(Op.getNode());
3486
3487 EVT MemVT = LdNode->getMemoryVT();
3488 if (MemVT == MVT::f128)
3489 return LowerF128Load(Op, DAG);
3490
3491 return Op;
3492}
3493
3494// Lower a f128 store into two f64 stores.
3496 SDLoc dl(Op);
3497 StoreSDNode *StNode = cast<StoreSDNode>(Op.getNode());
3498 assert(StNode->getOffset().isUndef() && "Unexpected node type");
3499
3500 SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
3501 SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
3502
3503 SDNode *Hi64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3504 dl,
3505 MVT::f64,
3506 StNode->getValue(),
3507 SubRegEven);
3508 SDNode *Lo64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3509 dl,
3510 MVT::f64,
3511 StNode->getValue(),
3512 SubRegOdd);
3513
3514 Align Alignment = commonAlignment(StNode->getBaseAlign(), 8);
3515
3516 SDValue OutChains[2];
3517 OutChains[0] =
3518 DAG.getStore(StNode->getChain(), dl, SDValue(Hi64, 0),
3519 StNode->getBasePtr(), StNode->getPointerInfo(),
3520 Alignment);
3521 EVT addrVT = StNode->getBasePtr().getValueType();
3522 SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
3523 StNode->getBasePtr(),
3524 DAG.getConstant(8, dl, addrVT));
3525 OutChains[1] = DAG.getStore(StNode->getChain(), dl, SDValue(Lo64, 0), LoPtr,
3526 StNode->getPointerInfo().getWithOffset(8),
3527 Alignment);
3528 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
3529}
3530
3532{
3533 SDLoc dl(Op);
3534 StoreSDNode *St = cast<StoreSDNode>(Op.getNode());
3535
3536 EVT MemVT = St->getMemoryVT();
3537 if (MemVT == MVT::f128)
3538 return LowerF128Store(Op, DAG);
3539
3540 if (MemVT == MVT::i64 && St->getAlign() >= Align(8)) {
3541 // Custom handling for aligned i64 stores: turn it into a bitcast and a
3542 // v2i32 store.
3543 SDValue Val = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, St->getValue());
3544 SDValue Chain = DAG.getStore(
3545 St->getChain(), dl, Val, St->getBasePtr(), St->getPointerInfo(),
3546 St->getBaseAlign(), St->getMemOperand()->getFlags(), St->getAAInfo());
3547 return Chain;
3548 }
3549
3550 return SDValue();
3551}
3552
3554 assert((Op.getOpcode() == ISD::FNEG || Op.getOpcode() == ISD::FABS)
3555 && "invalid opcode");
3556
3557 SDLoc dl(Op);
3558
3559 if (Op.getValueType() == MVT::f64)
3560 return LowerF64Op(Op.getOperand(0), dl, DAG, Op.getOpcode());
3561 if (Op.getValueType() != MVT::f128)
3562 return Op;
3563
3564 // Lower fabs/fneg on f128 to fabs/fneg on f64
3565 // fabs/fneg f128 => fabs/fneg f64:sub_even64, fmov f64:sub_odd64
3566 // (As with LowerF64Op, on little-endian, we need to negate the odd
3567 // subreg)
3568
3569 SDValue SrcReg128 = Op.getOperand(0);
3570 SDValue Hi64 = DAG.getTargetExtractSubreg(SP::sub_even64, dl, MVT::f64,
3571 SrcReg128);
3572 SDValue Lo64 = DAG.getTargetExtractSubreg(SP::sub_odd64, dl, MVT::f64,
3573 SrcReg128);
3574
3575 if (DAG.getDataLayout().isLittleEndian()) {
3576 if (isV9)
3577 Lo64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Lo64);
3578 else
3579 Lo64 = LowerF64Op(Lo64, dl, DAG, Op.getOpcode());
3580 } else {
3581 if (isV9)
3582 Hi64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Hi64);
3583 else
3584 Hi64 = LowerF64Op(Hi64, dl, DAG, Op.getOpcode());
3585 }
3586
3587 SDValue DstReg128 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
3588 dl, MVT::f128), 0);
3589 DstReg128 = DAG.getTargetInsertSubreg(SP::sub_even64, dl, MVT::f128,
3590 DstReg128, Hi64);
3591 DstReg128 = DAG.getTargetInsertSubreg(SP::sub_odd64, dl, MVT::f128,
3592 DstReg128, Lo64);
3593 return DstReg128;
3594}
3595
3597 auto *AN = cast<AtomicSDNode>(Op);
3598
3599 // 64-bit atomic store in 32-bit V8+ code: like GCC's atomic_storedi_1, use
3600 // std, which is atomic for doubleword-aligned addresses. The load side is
3601 // handled in ReplaceNodeResults.
3602 if (Op.getOpcode() == ISD::ATOMIC_STORE &&
3603 Op.getOperand(1).getValueType() == MVT::i64 &&
3604 !DAG.getSubtarget<SparcSubtarget>().is64Bit()) {
3605 SDLoc DL(Op);
3606 SDValue Val = DAG.getNode(ISD::BITCAST, DL, MVT::v2i32, Op.getOperand(1));
3607 return DAG.getStore(AN->getChain(), DL, Val, AN->getBasePtr(),
3608 AN->getMemOperand());
3609 }
3610
3611 if (isStrongerThanMonotonic(AN->getSuccessOrdering())) {
3612 // Expand with a fence.
3613 return SDValue();
3614 }
3615
3616 // Monotonic load/stores are legal.
3617 return Op;
3618}
3619
3621 SDLoc DL(Op);
3622 SDValue Vec = Op.getOperand(0);
3623 SDValue Idx = Op.getOperand(1);
3624 assert(Vec.getSimpleValueType() == MVT::v2i32 && "Unexpected vector type");
3625
3626 // Constant indices are handled by the TableGen patterns.
3627 if (isa<ConstantSDNode>(Idx))
3628 return Op;
3629
3630 EVT VT = Op.getValueType();
3631 EVT IdxVT = Idx.getValueType();
3632 SDValue Elt0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Vec,
3633 DAG.getConstant(0, DL, IdxVT));
3634 SDValue Elt1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Vec,
3635 DAG.getConstant(1, DL, IdxVT));
3636 return DAG.getSelectCC(DL, Idx, DAG.getConstant(0, DL, IdxVT), Elt0, Elt1,
3637 ISD::SETEQ);
3638}
3639
3641 SelectionDAG &DAG) const {
3642 unsigned IntNo = Op.getConstantOperandVal(0);
3643 switch (IntNo) {
3644 default: return SDValue(); // Don't custom lower most intrinsics.
3645 case Intrinsic::thread_pointer: {
3646 EVT PtrVT = getPointerTy(DAG.getDataLayout());
3647 return DAG.getRegister(SP::G7, PtrVT);
3648 }
3649 }
3650}
3651
3654
3655 bool hasHardQuad = Subtarget->hasHardQuad();
3656 bool isV9 = Subtarget->isV9();
3657 bool is64Bit = Subtarget->is64Bit();
3658
3659 switch (Op.getOpcode()) {
3660 default: llvm_unreachable("Should not custom lower this!");
3661
3662 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG, *this,
3663 Subtarget);
3664 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG,
3665 Subtarget);
3667 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
3668 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
3669 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
3670 case ISD::FP_TO_SINT:
3672 return LowerFP_TO_SINT(Op, DAG, *this, hasHardQuad);
3673 case ISD::SINT_TO_FP:
3675 return LowerSINT_TO_FP(Op, DAG, *this, hasHardQuad);
3676 case ISD::FP_TO_UINT:
3678 return LowerFP_TO_UINT(Op, DAG, *this, hasHardQuad);
3679 case ISD::UINT_TO_FP:
3681 return LowerUINT_TO_FP(Op, DAG, *this, hasHardQuad);
3682 case ISD::STRICT_FSETCC:
3684 return LowerSTRICT_FSETCC(Op, DAG, *this, hasHardQuad, isV9);
3685 case ISD::BR_CC:
3686 return LowerBR_CC(Op, DAG, *this, hasHardQuad, isV9, is64Bit);
3687 case ISD::SELECT_CC:
3688 return LowerSELECT_CC(Op, DAG, *this, hasHardQuad, isV9, is64Bit);
3689 case ISD::VASTART: return LowerVASTART(Op, DAG, *this);
3690 case ISD::VAARG: return LowerVAARG(Op, DAG);
3692 Subtarget);
3693 case ISD::STACKADDRESS:
3694 return LowerSTACKADDRESS(Op, DAG, *Subtarget);
3695
3696 case ISD::BSWAP:
3697 return LowerBSWAP(Op, DAG);
3698
3699 case ISD::LOAD: return LowerLOAD(Op, DAG);
3700 case ISD::STORE: return LowerSTORE(Op, DAG);
3701 case ISD::FADD:
3702 case ISD::STRICT_FADD:
3703 return LowerF128Op(Op, DAG, RTLIB::ADD_F128, 2);
3704 case ISD::FSUB:
3705 case ISD::STRICT_FSUB:
3706 return LowerF128Op(Op, DAG, RTLIB::SUB_F128, 2);
3707 case ISD::FMUL:
3708 case ISD::STRICT_FMUL:
3709 return LowerF128Op(Op, DAG, RTLIB::MUL_F128, 2);
3710 case ISD::FDIV:
3711 case ISD::STRICT_FDIV:
3712 return LowerF128Op(Op, DAG, RTLIB::DIV_F128, 2);
3713 case ISD::FSQRT:
3714 case ISD::STRICT_FSQRT:
3715 return LowerF128Op(Op, DAG, RTLIB::SQRT_F128, 1);
3716 case ISD::FABS:
3717 case ISD::FNEG: return LowerFNEGorFABS(Op, DAG, isV9);
3718 case ISD::FP_EXTEND:
3720 return LowerF128_FPEXTEND(Op, DAG, *this);
3721 case ISD::FP_ROUND:
3723 return LowerF128_FPROUND(Op, DAG, *this);
3724 case ISD::ATOMIC_LOAD:
3725 case ISD::ATOMIC_STORE: return LowerATOMIC_LOAD_STORE(Op, DAG);
3727 return LowerEXTRACT_VECTOR_ELT(Op, DAG);
3729 }
3730}
3731
3733 const SDLoc &DL,
3734 SelectionDAG &DAG) const {
3735 APInt V = C->getValueAPF().bitcastToAPInt();
3736 SDValue Lo = DAG.getConstant(V.zextOrTrunc(32), DL, MVT::i32);
3737 SDValue Hi = DAG.getConstant(V.lshr(32).zextOrTrunc(32), DL, MVT::i32);
3738 if (DAG.getDataLayout().isLittleEndian())
3739 std::swap(Lo, Hi);
3740 return DAG.getBuildVector(MVT::v2i32, DL, {Hi, Lo});
3741}
3742
3744 DAGCombinerInfo &DCI) const {
3745 SDLoc dl(N);
3746 SDValue Src = N->getOperand(0);
3747
3748 if (isa<ConstantFPSDNode>(Src) && N->getSimpleValueType(0) == MVT::v2i32 &&
3749 Src.getSimpleValueType() == MVT::f64)
3751
3752 return SDValue();
3753}
3754
3756 DAGCombinerInfo &DCI) const {
3757 SDLoc DL(N);
3758 SelectionDAG &DAG = DCI.DAG;
3759 SDValue Op = N->getOperand(0);
3760 EVT VT = N->getValueType(0);
3761 auto *LN = dyn_cast<LoadSDNode>(Op.getNode());
3762
3763 bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
3764 bool IsAlignedLoad = LN && ISD::isNormalLoad(Op.getNode()) &&
3765 LN->getAlign() >= VT.getScalarStoreSize();
3766
3767 // Turn BSWAP (aligned-LOAD) -> ld*a #ASI_P(_L) on V9.
3768 if (Subtarget->isV9() && IsAlignedLoad && Op.getNode()->hasOneUse() &&
3769 (VT == MVT::i16 || VT == MVT::i32 ||
3770 (Subtarget->is64Bit() && VT == MVT::i64))) {
3771 SDValue Load = Op;
3772 auto *LD = cast<LoadSDNode>(Load);
3773
3774 // Create the byte-swapping load.
3775 SDValue Ops[] = {LD->getChain(), LD->getBasePtr(), DAG.getValueType(VT)};
3776
3777 SDValue BSLoad = DAG.getMemIntrinsicNode(
3778 IsLittleEndian ? SPISD::LOAD_BIG : SPISD::LOAD_LITTLE, DL,
3779 DAG.getVTList(VT == MVT::i64 ? MVT::i64 : MVT::i32, MVT::Other), Ops,
3780 LD->getMemoryVT(), LD->getMemOperand());
3781
3782 // If this is an i16 load, insert the truncate.
3783 SDValue ResVal = BSLoad;
3784 if (VT == MVT::i16)
3785 ResVal = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, BSLoad);
3786
3787 return DCI.CombineTo(N, ResVal);
3788 }
3789
3790 return SDValue();
3791}
3792
3794 DAGCombinerInfo &DCI) const {
3795 SDLoc DL(N);
3796 SelectionDAG &DAG = DCI.DAG;
3797 SDValue Op = N->getOperand(1);
3798 EVT VT = Op.getValueType();
3799 EVT MemVT = cast<StoreSDNode>(N)->getMemoryVT();
3800 unsigned Opcode = Op.getOpcode();
3801 auto *SN = dyn_cast<StoreSDNode>(N);
3802
3803 bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
3804 bool IsAlignedStore = SN && SN->getAlign() >= MemVT.getScalarStoreSize();
3805
3806 // Turn aligned-STORE (BSWAP) -> st*a #ASI_P(_L) on V9.
3807 if (Subtarget->isV9() && Opcode == ISD::BSWAP && Op.getNode()->hasOneUse() &&
3808 IsAlignedStore &&
3809 (VT == MVT::i16 || VT == MVT::i32 ||
3810 (Subtarget->is64Bit() && VT == MVT::i64))) {
3811
3812 // st*a can only handle simple types and it makes no sense to store less
3813 // than two bytes in byte-reversed order.
3814 if (MemVT.getSizeInBits() < 16)
3815 return SDValue();
3816
3817 SDValue BSwapOp = Op.getOperand(0);
3818 // Do an any-extend to 32-bits if this is a half-word input.
3819 if (BSwapOp.getValueType() == MVT::i16)
3820 BSwapOp = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, BSwapOp);
3821
3822 // If the type of BSWAP operand is wider than stored memory width
3823 // it needs to be shifted to the right side before st*a.
3824 if (VT.bitsGT(MemVT)) {
3825 unsigned Shift = VT.getSizeInBits() - MemVT.getSizeInBits();
3826 BSwapOp = DAG.getNode(ISD::SRL, DL, VT, BSwapOp,
3827 DAG.getShiftAmountConstant(Shift, VT, DL));
3828 }
3829
3830 SDValue Ops[] = {N->getOperand(0), BSwapOp, N->getOperand(2),
3831 DAG.getValueType(MemVT)};
3832 return DAG.getMemIntrinsicNode(
3833 IsLittleEndian ? SPISD::STORE_BIG : SPISD::STORE_LITTLE, DL,
3834 DAG.getVTList(MVT::Other), Ops, cast<StoreSDNode>(N)->getMemoryVT(),
3835 cast<StoreSDNode>(N)->getMemOperand());
3836 }
3837
3838 return SDValue();
3839}
3840
3842 DAGCombinerInfo &DCI) const {
3843 switch (N->getOpcode()) {
3844 default:
3845 break;
3846 case ISD::BITCAST:
3847 return PerformBITCASTCombine(N, DCI);
3848 case ISD::BSWAP:
3849 return PerformBSWAPCombine(N, DCI);
3850 case ISD::STORE:
3851 return PerformSTORECombine(N, DCI);
3852 }
3853 return SDValue();
3854}
3855
3857 MachineBasicBlock *BB) {
3858 MachineFunction &MF = *BB->getParent();
3859 const BasicBlock *LLVMBB = BB->getBasicBlock();
3861 MachineBasicBlock *LoopMBB = MF.CreateMachineBasicBlock(LLVMBB);
3862 MachineBasicBlock *DoneMBB = MF.CreateMachineBasicBlock(LLVMBB);
3863 MF.insert(It, LoopMBB);
3864 MF.insert(It, DoneMBB);
3865
3866 DoneMBB->splice(DoneMBB->begin(), BB,
3867 std::next(MachineBasicBlock::iterator(MI)), BB->end());
3869 BB->addSuccessor(LoopMBB);
3870 LoopMBB->addSuccessor(LoopMBB);
3871 LoopMBB->addSuccessor(DoneMBB);
3872
3875 Register Lo = MI.getOperand(0).getReg();
3876 Register Hi = MI.getOperand(1).getReg();
3877 Register HiAgain = MRI.createVirtualRegister(&SP::IntRegsRegClass);
3878 DebugLoc DL = MI.getDebugLoc();
3879
3880 BuildMI(LoopMBB, DL, TII.get(SP::RDASR), Hi).addReg(SP::ASR22);
3881 BuildMI(LoopMBB, DL, TII.get(SP::RDASR), Lo).addReg(SP::ASR23);
3882 BuildMI(LoopMBB, DL, TII.get(SP::RDASR), HiAgain).addReg(SP::ASR22);
3883 BuildMI(LoopMBB, DL, TII.get(SP::SUBCCrr), SP::G0).addReg(Hi).addReg(HiAgain);
3884 BuildMI(LoopMBB, DL, TII.get(SP::BCOND)).addMBB(LoopMBB).addImm(SPCC::ICC_NE);
3885
3886 MI.eraseFromParent();
3887 return DoneMBB;
3888}
3889
3892 MachineBasicBlock *BB) const {
3893 switch (MI.getOpcode()) {
3894 default:
3895 llvm_unreachable("Unknown custom-inserter instruction");
3896 case SP::ReadCycleCounter:
3897 return emitReadCycleCounter(MI, BB);
3898 case SP::SELECT_CC_Int_ICC:
3899 case SP::SELECT_CC_FP_ICC:
3900 case SP::SELECT_CC_DFP_ICC:
3901 case SP::SELECT_CC_QFP_ICC:
3902 if (Subtarget->isV9())
3903 return expandSelectCC(MI, BB, SP::BPICC);
3904 return expandSelectCC(MI, BB, SP::BCOND);
3905 case SP::SELECT_CC_Int_XCC:
3906 case SP::SELECT_CC_FP_XCC:
3907 case SP::SELECT_CC_DFP_XCC:
3908 case SP::SELECT_CC_QFP_XCC:
3909 return expandSelectCC(MI, BB, SP::BPXCC);
3910 case SP::SELECT_CC_Int_FCC:
3911 case SP::SELECT_CC_FP_FCC:
3912 case SP::SELECT_CC_DFP_FCC:
3913 case SP::SELECT_CC_QFP_FCC:
3914 if (Subtarget->isV9())
3915 return expandSelectCC(MI, BB, SP::FBCOND_V9);
3916 return expandSelectCC(MI, BB, SP::FBCOND);
3917 }
3918}
3919
3922 unsigned BROpcode) const {
3923 const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
3924 DebugLoc dl = MI.getDebugLoc();
3925 unsigned CC = (SPCC::CondCodes)MI.getOperand(3).getImm();
3926
3927 // To "insert" a SELECT_CC instruction, we actually have to insert the
3928 // triangle control-flow pattern. The incoming instruction knows the
3929 // destination vreg to set, the condition code register to branch on, the
3930 // true/false values to select between, and the condition code for the branch.
3931 //
3932 // We produce the following control flow:
3933 // ThisMBB
3934 // | \
3935 // | IfFalseMBB
3936 // | /
3937 // SinkMBB
3938 const BasicBlock *LLVM_BB = BB->getBasicBlock();
3940
3941 MachineBasicBlock *ThisMBB = BB;
3942 MachineFunction *F = BB->getParent();
3943 MachineBasicBlock *IfFalseMBB = F->CreateMachineBasicBlock(LLVM_BB);
3944 MachineBasicBlock *SinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
3945 F->insert(It, IfFalseMBB);
3946 F->insert(It, SinkMBB);
3947
3948 // Transfer the remainder of ThisMBB and its successor edges to SinkMBB.
3949 SinkMBB->splice(SinkMBB->begin(), ThisMBB,
3950 std::next(MachineBasicBlock::iterator(MI)), ThisMBB->end());
3951 SinkMBB->transferSuccessorsAndUpdatePHIs(ThisMBB);
3952
3953 // Set the new successors for ThisMBB.
3954 ThisMBB->addSuccessor(IfFalseMBB);
3955 ThisMBB->addSuccessor(SinkMBB);
3956
3957 BuildMI(ThisMBB, dl, TII.get(BROpcode))
3958 .addMBB(SinkMBB)
3959 .addImm(CC);
3960
3961 // IfFalseMBB just falls through to SinkMBB.
3962 IfFalseMBB->addSuccessor(SinkMBB);
3963
3964 // %Result = phi [ %TrueValue, ThisMBB ], [ %FalseValue, IfFalseMBB ]
3965 BuildMI(*SinkMBB, SinkMBB->begin(), dl, TII.get(SP::PHI),
3966 MI.getOperand(0).getReg())
3967 .addReg(MI.getOperand(1).getReg())
3968 .addMBB(ThisMBB)
3969 .addReg(MI.getOperand(2).getReg())
3970 .addMBB(IfFalseMBB);
3971
3972 MI.eraseFromParent(); // The pseudo instruction is gone now.
3973 return SinkMBB;
3974}
3975
3976//===----------------------------------------------------------------------===//
3977// Sparc Inline Assembly Support
3978//===----------------------------------------------------------------------===//
3979
3980/// getConstraintType - Given a constraint letter, return the type of
3981/// constraint it is for this target.
3984 if (Constraint.size() == 1) {
3985 switch (Constraint[0]) {
3986 default: break;
3987 case 'r':
3988 case 'f':
3989 case 'e':
3990 return C_RegisterClass;
3991 case 'I': // SIMM13
3992 case 'J': // Zero
3993 case 'K': // 32-bit constant with the low 10 bits clear (sethi)
3994 case 'L': // SIMM11
3995 case 'M': // SIMM10
3996 case 'N': // Unsigned 32-bit constant with the low 10 bits clear (sethi)
3997 case 'O': // The constant 4096
3998 return C_Immediate;
3999 }
4000 }
4001
4002 return TargetLowering::getConstraintType(Constraint);
4003}
4004
4005/// isValidImmForConstraint - Return true if constraint is satisfied
4006static bool isValidImmForConstraint(char Constraint, int64_t Val) {
4007 switch (Constraint) {
4008 case 'I':
4009 return isInt<13>(Val);
4010 case 'J':
4011 return Val == 0;
4012 case 'K':
4013 return (isInt<32>(Val) || isUInt<32>(Val)) && (Val & 0x3ff) == 0;
4014 case 'L':
4015 return isInt<11>(Val);
4016 case 'M':
4017 return isInt<10>(Val);
4018 case 'N':
4019 return isUInt<32>(Val) && (Val & 0x3ff) == 0;
4020 case 'O':
4021 return Val == 4096;
4022 default:
4023 return false;
4024 }
4025}
4026
4029 const char *constraint) const {
4031 Value *CallOperandVal = info.CallOperandVal;
4032 // If we don't have a value, we can't do a match,
4033 // but allow it at the lowest weight.
4034 if (!CallOperandVal)
4035 return CW_Default;
4036
4037 // Look at the constraint type.
4038 switch (*constraint) {
4039 default:
4041 break;
4042 case 'I': // SIMM13
4043 case 'J':
4044 case 'K':
4045 case 'L':
4046 case 'M':
4047 case 'N':
4048 case 'O':
4049 if (ConstantInt *C = dyn_cast<ConstantInt>(info.CallOperandVal)) {
4050 if (isValidImmForConstraint(*constraint, C->getSExtValue()))
4052 }
4053 break;
4054 }
4055 return weight;
4056}
4057
4058/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
4059/// vector. If it is invalid, don't add anything to Ops.
4061 SDValue Op, StringRef Constraint, std::vector<SDValue> &Ops,
4062 SelectionDAG &DAG) const {
4063 SDValue Result;
4064
4065 // Only support length 1 constraints for now.
4066 if (Constraint.size() > 1)
4067 return;
4068
4069 char ConstraintLetter = Constraint[0];
4070 switch (ConstraintLetter) {
4071 default: break;
4072 case 'I':
4073 case 'J':
4074 case 'K':
4075 case 'L':
4076 case 'M':
4077 case 'N':
4078 case 'O':
4080 if (isValidImmForConstraint(ConstraintLetter, C->getSExtValue())) {
4081 Result = DAG.getSignedTargetConstant(C->getSExtValue(), SDLoc(Op),
4082 Op.getValueType());
4083 break;
4084 }
4085 return;
4086 }
4087 }
4088
4089 if (Result.getNode()) {
4090 Ops.push_back(Result);
4091 return;
4092 }
4094}
4095
4096std::pair<unsigned, const TargetRegisterClass *>
4098 StringRef Constraint,
4099 MVT VT) const {
4100 if (Constraint.empty())
4101 return std::make_pair(0U, nullptr);
4102
4103 if (Constraint.size() == 1) {
4104 switch (Constraint[0]) {
4105 case 'r':
4106 if (VT == MVT::v2i32)
4107 return std::make_pair(0U, &SP::IntPairRegClass);
4108 else if (Subtarget->is64Bit())
4109 return std::make_pair(0U, &SP::I64RegsRegClass);
4110 else
4111 return std::make_pair(0U, &SP::IntRegsRegClass);
4112 case 'f':
4113 if (VT == MVT::f32 || VT == MVT::i32)
4114 return std::make_pair(0U, &SP::FPRegsRegClass);
4115 else if (VT == MVT::f64 || VT == MVT::i64)
4116 return std::make_pair(0U, &SP::LowDFPRegsRegClass);
4117 else if (VT == MVT::f128)
4118 return std::make_pair(0U, &SP::LowQFPRegsRegClass);
4119 // This will generate an error message
4120 return std::make_pair(0U, nullptr);
4121 case 'e':
4122 if (VT == MVT::f32 || VT == MVT::i32)
4123 return std::make_pair(0U, &SP::FPRegsRegClass);
4124 else if (VT == MVT::f64 || VT == MVT::i64 )
4125 return std::make_pair(0U, &SP::DFPRegsRegClass);
4126 else if (VT == MVT::f128)
4127 return std::make_pair(0U, &SP::QFPRegsRegClass);
4128 // This will generate an error message
4129 return std::make_pair(0U, nullptr);
4130 }
4131 }
4132
4133 if (Constraint.front() != '{')
4134 return std::make_pair(0U, nullptr);
4135
4136 assert(Constraint.back() == '}' && "Not a brace enclosed constraint?");
4137 StringRef RegName(Constraint.data() + 1, Constraint.size() - 2);
4138 if (RegName.empty())
4139 return std::make_pair(0U, nullptr);
4140
4141 unsigned CCReg = StringSwitch<unsigned>(RegName)
4142 .Cases({"cc", "icc"}, SP::ICC)
4143 .Case("fcc0", SP::FCC0)
4144 .Case("fcc1", SP::FCC1)
4145 .Case("fcc2", SP::FCC2)
4146 .Case("fcc3", SP::FCC3)
4147 .Default(0);
4148 if (CCReg == SP::ICC)
4149 return std::make_pair(CCReg, &SP::ICCRegsRegClass);
4150 if (CCReg)
4151 return std::make_pair(CCReg, &SP::FCCRegsRegClass);
4152
4153 unsigned long long RegNo;
4154 // Handle numbered register aliases.
4155 if (RegName[0] == 'r' &&
4156 getAsUnsignedInteger(RegName.begin() + 1, 10, RegNo)) {
4157 // r0-r7 -> g0-g7
4158 // r8-r15 -> o0-o7
4159 // r16-r23 -> l0-l7
4160 // r24-r31 -> i0-i7
4161 if (RegNo > 31)
4162 return std::make_pair(0U, nullptr);
4163 const char RegTypes[] = {'g', 'o', 'l', 'i'};
4164 char RegType = RegTypes[RegNo / 8];
4165 char RegIndex = '0' + (RegNo % 8);
4166 char Tmp[] = {'{', RegType, RegIndex, '}', 0};
4167 return getRegForInlineAsmConstraint(TRI, Tmp, VT);
4168 }
4169
4170 // Rewrite the fN constraint according to the value type if needed.
4171 if (VT != MVT::f32 && VT != MVT::Other && RegName[0] == 'f' &&
4172 getAsUnsignedInteger(RegName.begin() + 1, 10, RegNo)) {
4173 if (VT == MVT::f64 && (RegNo % 2 == 0)) {
4175 TRI, StringRef("{d" + utostr(RegNo / 2) + "}"), VT);
4176 } else if (VT == MVT::f128 && (RegNo % 4 == 0)) {
4178 TRI, StringRef("{q" + utostr(RegNo / 4) + "}"), VT);
4179 } else {
4180 return std::make_pair(0U, nullptr);
4181 }
4182 }
4183
4184 auto ResultPair =
4186 if (!ResultPair.second)
4187 return std::make_pair(0U, nullptr);
4188
4189 // Force the use of I64Regs over IntRegs for 64-bit values.
4190 if (Subtarget->is64Bit() && VT == MVT::i64) {
4191 assert(ResultPair.second == &SP::IntRegsRegClass &&
4192 "Unexpected register class");
4193 return std::make_pair(ResultPair.first, &SP::I64RegsRegClass);
4194 }
4195
4196 return ResultPair;
4197}
4198
4199bool
4201 // The Sparc target isn't yet aware of offsets.
4202 return false;
4203}
4204
4207 SelectionDAG &DAG) const {
4208
4209 SDLoc dl(N);
4210
4211 RTLIB::Libcall libCall = RTLIB::UNKNOWN_LIBCALL;
4212
4213 switch (N->getOpcode()) {
4214 default:
4215 llvm_unreachable("Do not know how to custom type legalize this operation!");
4216
4217 case ISD::FP_TO_SINT:
4218 case ISD::FP_TO_UINT:
4221 bool IsStrict = N->isStrictFPOpcode();
4222 // Custom lower only if it involves f128 or i64.
4223 if (N->getOperand(IsStrict ? 1 : 0).getValueType() != MVT::f128 ||
4224 N->getValueType(0) != MVT::i64)
4225 return;
4226 libCall = ((N->getOpcode() == ISD::FP_TO_SINT ||
4227 N->getOpcode() == ISD::STRICT_FP_TO_SINT)
4228 ? RTLIB::FPTOSINT_F128_I64
4229 : RTLIB::FPTOUINT_F128_I64);
4230
4231 SDValue Res = LowerF128Op(SDValue(N, 0), DAG, libCall, 1);
4232 Results.push_back(Res);
4233 if (IsStrict)
4234 Results.push_back(Res.getValue(1));
4235 return;
4236 }
4239 assert(Subtarget->hasLeonCycleCounter());
4240 SDVTList VTs = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other);
4241 SDValue Counter =
4242 DAG.getNode(SPISD::READ_CYCLE_COUNTER, dl, VTs, N->getOperand(0));
4243 Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Counter,
4244 Counter.getValue(1)));
4245 Results.push_back(Counter.getValue(2));
4246 return;
4247 }
4248 case ISD::SINT_TO_FP:
4249 case ISD::UINT_TO_FP:
4252 bool IsStrict = N->isStrictFPOpcode();
4253 // Custom lower only if it involves f128 or i64.
4254 if (N->getValueType(0) != MVT::f128 ||
4255 N->getOperand(IsStrict ? 1 : 0).getValueType() != MVT::i64)
4256 return;
4257
4258 libCall = ((N->getOpcode() == ISD::SINT_TO_FP ||
4259 N->getOpcode() == ISD::STRICT_SINT_TO_FP)
4260 ? RTLIB::SINTTOFP_I64_F128
4261 : RTLIB::UINTTOFP_I64_F128);
4262
4263 SDValue Res = LowerF128Op(SDValue(N, 0), DAG, libCall, 1);
4264 Results.push_back(Res);
4265 if (IsStrict)
4266 Results.push_back(Res.getValue(1));
4267 return;
4268 }
4269 case ISD::LOAD: {
4271 // Custom handling only for aligned i64 loads: turn i64 load into a v2i32
4272 // load, and a bitcast.
4273 if (Ld->getValueType(0) != MVT::i64 || Ld->getMemoryVT() != MVT::i64 ||
4274 Ld->getAlign() < Align(8))
4275 return;
4276
4277 SDLoc dl(N);
4278 SDValue LoadRes = DAG.getExtLoad(
4279 Ld->getExtensionType(), dl, MVT::v2i32, Ld->getChain(),
4280 Ld->getBasePtr(), Ld->getPointerInfo(), MVT::v2i32, Ld->getBaseAlign(),
4281 Ld->getMemOperand()->getFlags(), Ld->getAAInfo());
4282
4283 SDValue Res = DAG.getNode(ISD::BITCAST, dl, MVT::i64, LoadRes);
4284 Results.push_back(Res);
4285 Results.push_back(LoadRes.getValue(1));
4286 return;
4287 }
4288 case ISD::ATOMIC_LOAD: {
4289 // 64-bit atomic load in 32-bit V8+ code: like GCC's atomic_loaddi_1, use
4290 // ldd, which is atomic for doubleword-aligned addresses. Ordering is
4291 // handled by the fences AtomicExpand inserted around it.
4292 auto *AN = cast<AtomicSDNode>(N);
4293 assert(AN->getMemoryVT() == MVT::i64 && !Subtarget->is64Bit());
4294 SDValue LoadRes = DAG.getLoad(MVT::v2i32, dl, AN->getChain(),
4295 AN->getBasePtr(), AN->getMemOperand());
4296 Results.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i64, LoadRes));
4297 Results.push_back(LoadRes.getValue(1));
4298 return;
4299 }
4300 case ISD::ATOMIC_CMP_SWAP: {
4301 // 64-bit compare-and-swap in 32-bit V8+ code. See CASX_V8PLUS.
4302 auto *AN = cast<AtomicSDNode>(N);
4303 assert(AN->getMemoryVT() == MVT::i64 && !Subtarget->is64Bit());
4304 auto [CmpLo, CmpHi] =
4305 DAG.SplitScalar(N->getOperand(2), dl, MVT::i32, MVT::i32);
4306 auto [NewLo, NewHi] =
4307 DAG.SplitScalar(N->getOperand(3), dl, MVT::i32, MVT::i32);
4308 SDValue Ops[] = {N->getOperand(1), CmpHi, CmpLo, NewHi, NewLo,
4309 N->getOperand(0)};
4310 MachineSDNode *CAS = DAG.getMachineNode(
4311 SP::CASX_V8PLUS, dl,
4312 DAG.getVTList(MVT::i32, MVT::i32, MVT::i32, MVT::Other), Ops);
4313 DAG.setNodeMemRefs(CAS, {AN->getMemOperand()});
4314 DAG.getMachineFunction()
4316 ->setUsesV8PlusRegs();
4317 SDValue Hi(CAS, 0), Lo(CAS, 1);
4318 Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi));
4319 Results.push_back(SDValue(CAS, 3));
4320 return;
4321 }
4322 }
4323}
4324
4325// Override to enable LOAD_STACK_GUARD lowering on Linux.
4327 if (!Subtarget->getTargetTriple().isOSLinux())
4329 return true;
4330}
4331
4333 if (Subtarget->isVIS3())
4334 return VT == MVT::f32 || VT == MVT::f64;
4335 return false;
4336}
4337
4340 bool ForCodeSize) const {
4341 if (VT != MVT::f32 && VT != MVT::f64)
4343 if (Subtarget->isVIS() && Imm.isZero())
4344 return FPImmAction::Legal;
4345 // Check for +/-0.5.
4346 if (Subtarget->isVIS3() && Imm.getExactLog2Abs() == -1)
4347 return FPImmAction::Legal;
4349}
4350
4351bool SparcTargetLowering::isCtlzFast() const { return Subtarget->isVIS3(); }
4352
4354 // We lack native cttz, however,
4355 // On 64-bit targets it is cheap to implement it in terms of popc.
4356 if (Subtarget->is64Bit() && Subtarget->usePopc())
4357 return true;
4358 // Otherwise, implementing cttz in terms of ctlz is still cheap.
4359 return isCheapToSpeculateCtlz(Ty);
4360}
4361
4363 EVT VT) const {
4364 return Subtarget->isUA2007() && !Subtarget->useSoftFloat();
4365}
4366
4368 SDNode *Node) const {
4369 assert(MI.getOpcode() == SP::SUBCCrr || MI.getOpcode() == SP::SUBCCri);
4370 // If the result is dead, replace it with %g0.
4371 if (!Node->hasAnyUseOfValue(0))
4372 MI.getOperand(0).setReg(SP::G0);
4373}
4374
4376 Instruction *Inst,
4377 AtomicOrdering Ord) const {
4378 bool HasStoreSemantics =
4380 if (HasStoreSemantics && isReleaseOrStronger(Ord))
4381 return Builder.CreateFence(AtomicOrdering::Release);
4382 return nullptr;
4383}
4384
4386 Instruction *Inst,
4387 AtomicOrdering Ord) const {
4388 // V8 loads already come with implicit acquire barrier so there's no need to
4389 // emit it again.
4390 bool HasLoadSemantics = isa<AtomicCmpXchgInst, AtomicRMWInst, LoadInst>(Inst);
4391 if (Subtarget->isV9() && HasLoadSemantics && isAcquireOrStronger(Ord))
4392 return Builder.CreateFence(AtomicOrdering::Acquire);
4393
4394 // SC plain stores would need a trailing full barrier.
4396 return Builder.CreateFence(Ord);
4397 return nullptr;
4398}
return SDValue()
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
uint64_t Imm
static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG)
static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG, const ARMSubtarget *ST)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
hexagon merge activate weight
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
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
MachineInstr *& Lo
static void EmitCall(MCStreamer &OutStreamer, MCOperand &Callee, const MCSubtargetInfo &STI)
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 LowerSTRICT_FSETCC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad, bool isV9)
static SDValue getFRAMEADDR(uint64_t depth, SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget, bool AlwaysFlush=false)
static unsigned toCallerWindow(unsigned Reg)
static bool isValidImmForConstraint(char Constraint, int64_t Val)
isValidImmForConstraint - Return true if constraint is satisfied
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 const char * getF128PredicateLibCall(unsigned SPCC, bool Is64Bit, bool &Invert, bool &Signaling)
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 bool LookThroughStrictSetCC(SDValue &Chain, SDValue LHS, SDValue RHS, ISD::CondCode CC, unsigned &SPCC, SDValue &Glue, const SDLoc &DL, SelectionDAG &DAG)
static MachineBasicBlock * emitReadCycleCounter(MachineInstr &MI, MachineBasicBlock *BB)
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...
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
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:220
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
LLVM_ABI Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
A debug info location.
Definition DebugLoc.h:127
Diagnostic information for unsupported feature in backend.
const Function & getFunction() const
Definition Function.h:167
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
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:111
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
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
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 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)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
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.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
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.
An SDNode that represents everything that will be needed to construct a MachineInstr.
Align getBaseAlign() const
Returns alignment and volatility of the memory access.
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:68
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
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.
iterator_range< value_op_iterator > op_values() const
SDNodeFlags getFlags() const
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
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node, in exactly one operand.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
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.
const TargetSubtargetInfo & getSubtarget() const
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 SDValue getShiftAmountConstant(uint64_t Val, EVT VT, const SDLoc &DL)
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 getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=LocationSize::precise(0), const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
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)
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
LLVM_ABI void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Helper function to build ISD::STORE nodes.
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 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 MMOMetadata &Metadata=MMOMetadata())
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.
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
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)
LLVM_ABI void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
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.
LLVM_ABI std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
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.
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
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 PerformSTORECombine(SDNode *N, DAGCombinerInfo &DCI) const
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 LowerF128StrictCompare(SDValue &Chain, SDValue LHS, SDValue RHS, unsigned &SPCC, bool IsSignaling, const SDLoc &DL, SelectionDAG &DAG) const
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.
FPImmAction getFPImmAction(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns how the legalizer should materialize the specified FP immediate.
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)
SDValue LowerBSWAP(SDValue Op, SelectionDAG &DAG) const
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 PerformBSWAPCombine(SDNode *N, DAGCombinerInfo &DCI) const
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:31
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)
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, 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.
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...
FPImmAction
How the legalizer should materialize a floating-point immediate.
@ ConstantPool
Load the immediate from the constant pool.
@ Legal
The target can instruction select the immediate natively.
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...
virtual const TargetInstrInfo * getInstrInfo() const
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:352
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
Definition Type.cpp:170
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:294
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:267
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:187
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:257
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:851
@ 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.
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition ISDOpcodes.h:516
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:277
@ STACKADDRESS
STACKADDRESS - Represents the llvm.stackaddress intrinsic.
Definition ISDOpcodes.h:129
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:811
@ 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:296
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:266
@ 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:885
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:523
@ GlobalAddress
Definition ISDOpcodes.h:90
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:912
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:420
@ 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:282
@ 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...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition ISDOpcodes.h:256
@ STRICT_FSQRT
Constrained versions of libm-equivalent floating point intrinsics.
Definition ISDOpcodes.h:441
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
@ GlobalTLSAddress
Definition ISDOpcodes.h:91
@ CTLZ_ZERO_POISON
Definition ISDOpcodes.h:820
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:876
@ STRICT_UINT_TO_FP
Definition ISDOpcodes.h:490
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
@ 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:828
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ UNDEF
UNDEF - An undefined node.
Definition ISDOpcodes.h:235
@ 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:232
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:720
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:793
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:581
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:882
@ 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:843
@ 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:920
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
Definition ISDOpcodes.h:489
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition ISDOpcodes.h:112
@ STRICT_FP_TO_UINT
Definition ISDOpcodes.h:483
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
Definition ISDOpcodes.h:505
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:482
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:958
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition ISDOpcodes.h:510
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:763
@ TRAP
TRAP - Trapping instruction.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition ISDOpcodes.h:207
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:306
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition ISDOpcodes.h:430
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition ISDOpcodes.h:570
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:55
@ 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:819
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition ISDOpcodes.h:991
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:888
@ 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:865
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:64
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:539
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:561
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...
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
@ FCC_ULE
Definition Sparc.h:103
@ FCC_UG
Definition Sparc.h:93
@ ICC_G
Definition Sparc.h:75
@ REG_LEZ
Definition Sparc.h:126
@ ICC_L
Definition Sparc.h:78
@ FCC_NE
Definition Sparc.h:97
@ ICC_CS
Definition Sparc.h:82
@ FCC_LG
Definition Sparc.h:96
@ ICC_LEU
Definition Sparc.h:80
@ ICC_LE
Definition Sparc.h:76
@ FCC_U
Definition Sparc.h:91
@ ICC_GE
Definition Sparc.h:77
@ FCC_E
Definition Sparc.h:98
@ FCC_L
Definition Sparc.h:94
@ ICC_GU
Definition Sparc.h:79
@ ICC_NE
Definition Sparc.h:73
@ FCC_UE
Definition Sparc.h:99
@ ICC_E
Definition Sparc.h:74
@ FCC_UGE
Definition Sparc.h:101
@ ICC_CC
Definition Sparc.h:81
@ REG_GEZ
Definition Sparc.h:130
@ FCC_G
Definition Sparc.h:92
@ FCC_UL
Definition Sparc.h:95
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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:1685
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:166
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
@ Known
Known to have no common set bits.
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)
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
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:1762
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:149
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
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.
@ And
Bitwise or logical AND of integers.
@ Add
Sum of integers.
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.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:206
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:881
#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:433
uint64_t getScalarStoreSize() const
Definition ValueTypes.h:440
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
Definition ValueTypes.h:322
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
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:419
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:191
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Matching combinators.
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:111
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={})
LLVM_ABI SDValue CombineTo(SDNode *N, ArrayRef< SDValue > To, bool AddTo=true)