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