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