LLVM  5.0.0
SparcISelLowering.cpp
Go to the documentation of this file.
1 //===-- SparcISelLowering.cpp - Sparc DAG Lowering Implementation ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the interfaces that Sparc uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "SparcISelLowering.h"
18 #include "SparcRegisterInfo.h"
19 #include "SparcTargetMachine.h"
20 #include "SparcTargetObjectFile.h"
21 #include "llvm/ADT/StringSwitch.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/Module.h"
33 #include "llvm/Support/KnownBits.h"
34 using namespace llvm;
35 
36 
37 //===----------------------------------------------------------------------===//
38 // Calling Convention Implementation
39 //===----------------------------------------------------------------------===//
40 
41 static bool CC_Sparc_Assign_SRet(unsigned &ValNo, MVT &ValVT,
42  MVT &LocVT, CCValAssign::LocInfo &LocInfo,
43  ISD::ArgFlagsTy &ArgFlags, CCState &State)
44 {
45  assert (ArgFlags.isSRet());
46 
47  // Assign SRet argument.
48  State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
49  0,
50  LocVT, LocInfo));
51  return true;
52 }
53 
54 static bool CC_Sparc_Assign_Split_64(unsigned &ValNo, MVT &ValVT,
55  MVT &LocVT, CCValAssign::LocInfo &LocInfo,
56  ISD::ArgFlagsTy &ArgFlags, CCState &State)
57 {
58  static const MCPhysReg RegList[] = {
59  SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
60  };
61  // Try to get first reg.
62  if (unsigned Reg = State.AllocateReg(RegList)) {
63  State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
64  } else {
65  // Assign whole thing in stack.
66  State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
67  State.AllocateStack(8,4),
68  LocVT, LocInfo));
69  return true;
70  }
71 
72  // Try to get second reg.
73  if (unsigned Reg = State.AllocateReg(RegList))
74  State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
75  else
76  State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT,
77  State.AllocateStack(4,4),
78  LocVT, LocInfo));
79  return true;
80 }
81 
82 static bool CC_Sparc_Assign_Ret_Split_64(unsigned &ValNo, MVT &ValVT,
83  MVT &LocVT, CCValAssign::LocInfo &LocInfo,
84  ISD::ArgFlagsTy &ArgFlags, CCState &State)
85 {
86  static const MCPhysReg RegList[] = {
87  SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
88  };
89 
90  // Try to get first reg.
91  if (unsigned Reg = State.AllocateReg(RegList))
92  State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
93  else
94  return false;
95 
96  // Try to get second reg.
97  if (unsigned Reg = State.AllocateReg(RegList))
98  State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
99  else
100  return false;
101 
102  return true;
103 }
104 
105 // Allocate a full-sized argument for the 64-bit ABI.
106 static bool CC_Sparc64_Full(unsigned &ValNo, MVT &ValVT,
107  MVT &LocVT, CCValAssign::LocInfo &LocInfo,
108  ISD::ArgFlagsTy &ArgFlags, CCState &State) {
109  assert((LocVT == MVT::f32 || LocVT == MVT::f128
110  || LocVT.getSizeInBits() == 64) &&
111  "Can't handle non-64 bits locations");
112 
113  // Stack space is allocated for all arguments starting from [%fp+BIAS+128].
114  unsigned size = (LocVT == MVT::f128) ? 16 : 8;
115  unsigned alignment = (LocVT == MVT::f128) ? 16 : 8;
116  unsigned Offset = State.AllocateStack(size, alignment);
117  unsigned Reg = 0;
118 
119  if (LocVT == MVT::i64 && Offset < 6*8)
120  // Promote integers to %i0-%i5.
121  Reg = SP::I0 + Offset/8;
122  else if (LocVT == MVT::f64 && Offset < 16*8)
123  // Promote doubles to %d0-%d30. (Which LLVM calls D0-D15).
124  Reg = SP::D0 + Offset/8;
125  else if (LocVT == MVT::f32 && Offset < 16*8)
126  // Promote floats to %f1, %f3, ...
127  Reg = SP::F1 + Offset/4;
128  else if (LocVT == MVT::f128 && Offset < 16*8)
129  // Promote long doubles to %q0-%q28. (Which LLVM calls Q0-Q7).
130  Reg = SP::Q0 + Offset/16;
131 
132  // Promote to register when possible, otherwise use the stack slot.
133  if (Reg) {
134  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
135  return true;
136  }
137 
138  // This argument goes on the stack in an 8-byte slot.
139  // When passing floats, LocVT is smaller than 8 bytes. Adjust the offset to
140  // the right-aligned float. The first 4 bytes of the stack slot are undefined.
141  if (LocVT == MVT::f32)
142  Offset += 4;
143 
144  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
145  return true;
146 }
147 
148 // Allocate a half-sized argument for the 64-bit ABI.
149 //
150 // This is used when passing { float, int } structs by value in registers.
151 static bool CC_Sparc64_Half(unsigned &ValNo, MVT &ValVT,
152  MVT &LocVT, CCValAssign::LocInfo &LocInfo,
153  ISD::ArgFlagsTy &ArgFlags, CCState &State) {
154  assert(LocVT.getSizeInBits() == 32 && "Can't handle non-32 bits locations");
155  unsigned Offset = State.AllocateStack(4, 4);
156 
157  if (LocVT == MVT::f32 && Offset < 16*8) {
158  // Promote floats to %f0-%f31.
159  State.addLoc(CCValAssign::getReg(ValNo, ValVT, SP::F0 + Offset/4,
160  LocVT, LocInfo));
161  return true;
162  }
163 
164  if (LocVT == MVT::i32 && Offset < 6*8) {
165  // Promote integers to %i0-%i5, using half the register.
166  unsigned Reg = SP::I0 + Offset/8;
167  LocVT = MVT::i64;
168  LocInfo = CCValAssign::AExt;
169 
170  // Set the Custom bit if this i32 goes in the high bits of a register.
171  if (Offset % 8 == 0)
172  State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg,
173  LocVT, LocInfo));
174  else
175  State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
176  return true;
177  }
178 
179  State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
180  return true;
181 }
182 
183 #include "SparcGenCallingConv.inc"
184 
185 // The calling conventions in SparcCallingConv.td are described in terms of the
186 // callee's register window. This function translates registers to the
187 // corresponding caller window %o register.
188 static unsigned toCallerWindow(unsigned Reg) {
189  static_assert(SP::I0 + 7 == SP::I7 && SP::O0 + 7 == SP::O7,
190  "Unexpected enum");
191  if (Reg >= SP::I0 && Reg <= SP::I7)
192  return Reg - SP::I0 + SP::O0;
193  return Reg;
194 }
195 
196 SDValue
198  bool IsVarArg,
200  const SmallVectorImpl<SDValue> &OutVals,
201  const SDLoc &DL, SelectionDAG &DAG) const {
202  if (Subtarget->is64Bit())
203  return LowerReturn_64(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
204  return LowerReturn_32(Chain, CallConv, IsVarArg, Outs, OutVals, DL, DAG);
205 }
206 
207 SDValue
209  bool IsVarArg,
211  const SmallVectorImpl<SDValue> &OutVals,
212  const SDLoc &DL, SelectionDAG &DAG) const {
214 
215  // CCValAssign - represent the assignment of the return value to locations.
217 
218  // CCState - Info about the registers and stack slot.
219  CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
220  *DAG.getContext());
221 
222  // Analyze return values.
223  CCInfo.AnalyzeReturn(Outs, RetCC_Sparc32);
224 
225  SDValue Flag;
226  SmallVector<SDValue, 4> RetOps(1, Chain);
227  // Make room for the return address offset.
228  RetOps.push_back(SDValue());
229 
230  // Copy the result values into the output registers.
231  for (unsigned i = 0, realRVLocIdx = 0;
232  i != RVLocs.size();
233  ++i, ++realRVLocIdx) {
234  CCValAssign &VA = RVLocs[i];
235  assert(VA.isRegLoc() && "Can only return in registers!");
236 
237  SDValue Arg = OutVals[realRVLocIdx];
238 
239  if (VA.needsCustom()) {
240  assert(VA.getLocVT() == MVT::v2i32);
241  // Legalize ret v2i32 -> ret 2 x i32 (Basically: do what would
242  // happen by default if this wasn't a legal type)
243 
245  Arg,
246  DAG.getConstant(0, DL, getVectorIdxTy(DAG.getDataLayout())));
248  Arg,
249  DAG.getConstant(1, DL, getVectorIdxTy(DAG.getDataLayout())));
250 
251  Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part0, Flag);
252  Flag = Chain.getValue(1);
253  RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
254  VA = RVLocs[++i]; // skip ahead to next loc
255  Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Part1,
256  Flag);
257  } else
258  Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Arg, Flag);
259 
260  // Guarantee that all emitted copies are stuck together with flags.
261  Flag = Chain.getValue(1);
262  RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
263  }
264 
265  unsigned RetAddrOffset = 8; // Call Inst + Delay Slot
266  // If the function returns a struct, copy the SRetReturnReg to I0
267  if (MF.getFunction()->hasStructRetAttr()) {
269  unsigned Reg = SFI->getSRetReturnReg();
270  if (!Reg)
271  llvm_unreachable("sret virtual register not created in the entry block");
272  auto PtrVT = getPointerTy(DAG.getDataLayout());
273  SDValue Val = DAG.getCopyFromReg(Chain, DL, Reg, PtrVT);
274  Chain = DAG.getCopyToReg(Chain, DL, SP::I0, Val, Flag);
275  Flag = Chain.getValue(1);
276  RetOps.push_back(DAG.getRegister(SP::I0, PtrVT));
277  RetAddrOffset = 12; // CallInst + Delay Slot + Unimp
278  }
279 
280  RetOps[0] = Chain; // Update chain.
281  RetOps[1] = DAG.getConstant(RetAddrOffset, DL, MVT::i32);
282 
283  // Add the flag if we have it.
284  if (Flag.getNode())
285  RetOps.push_back(Flag);
286 
287  return DAG.getNode(SPISD::RET_FLAG, DL, MVT::Other, RetOps);
288 }
289 
290 // Lower return values for the 64-bit ABI.
291 // Return values are passed the exactly the same way as function arguments.
292 SDValue
294  bool IsVarArg,
296  const SmallVectorImpl<SDValue> &OutVals,
297  const SDLoc &DL, SelectionDAG &DAG) const {
298  // CCValAssign - represent the assignment of the return value to locations.
300 
301  // CCState - Info about the registers and stack slot.
302  CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
303  *DAG.getContext());
304 
305  // Analyze return values.
306  CCInfo.AnalyzeReturn(Outs, RetCC_Sparc64);
307 
308  SDValue Flag;
309  SmallVector<SDValue, 4> RetOps(1, Chain);
310 
311  // The second operand on the return instruction is the return address offset.
312  // The return address is always %i7+8 with the 64-bit ABI.
313  RetOps.push_back(DAG.getConstant(8, DL, MVT::i32));
314 
315  // Copy the result values into the output registers.
316  for (unsigned i = 0; i != RVLocs.size(); ++i) {
317  CCValAssign &VA = RVLocs[i];
318  assert(VA.isRegLoc() && "Can only return in registers!");
319  SDValue OutVal = OutVals[i];
320 
321  // Integer return values must be sign or zero extended by the callee.
322  switch (VA.getLocInfo()) {
323  case CCValAssign::Full: break;
324  case CCValAssign::SExt:
325  OutVal = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), OutVal);
326  break;
327  case CCValAssign::ZExt:
328  OutVal = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), OutVal);
329  break;
330  case CCValAssign::AExt:
331  OutVal = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), OutVal);
332  break;
333  default:
334  llvm_unreachable("Unknown loc info!");
335  }
336 
337  // The custom bit on an i32 return value indicates that it should be passed
338  // in the high bits of the register.
339  if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
340  OutVal = DAG.getNode(ISD::SHL, DL, MVT::i64, OutVal,
341  DAG.getConstant(32, DL, MVT::i32));
342 
343  // The next value may go in the low bits of the same register.
344  // Handle both at once.
345  if (i+1 < RVLocs.size() && RVLocs[i+1].getLocReg() == VA.getLocReg()) {
346  SDValue NV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, OutVals[i+1]);
347  OutVal = DAG.getNode(ISD::OR, DL, MVT::i64, OutVal, NV);
348  // Skip the next value, it's already done.
349  ++i;
350  }
351  }
352 
353  Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), OutVal, Flag);
354 
355  // Guarantee that all emitted copies are stuck together with flags.
356  Flag = Chain.getValue(1);
357  RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
358  }
359 
360  RetOps[0] = Chain; // Update chain.
361 
362  // Add the flag if we have it.
363  if (Flag.getNode())
364  RetOps.push_back(Flag);
365 
366  return DAG.getNode(SPISD::RET_FLAG, DL, MVT::Other, RetOps);
367 }
368 
370  SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
372  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
373  if (Subtarget->is64Bit())
374  return LowerFormalArguments_64(Chain, CallConv, IsVarArg, Ins,
375  DL, DAG, InVals);
376  return LowerFormalArguments_32(Chain, CallConv, IsVarArg, Ins,
377  DL, DAG, InVals);
378 }
379 
380 /// LowerFormalArguments32 - V8 uses a very simple ABI, where all values are
381 /// passed in either one or two GPRs, including FP values. TODO: we should
382 /// pass FP values in FP registers for fastcc functions.
384  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
385  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
386  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
388  MachineRegisterInfo &RegInfo = MF.getRegInfo();
390 
391  // Assign locations to all of the incoming arguments.
393  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
394  *DAG.getContext());
395  CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc32);
396 
397  const unsigned StackOffset = 92;
398  bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
399 
400  unsigned InIdx = 0;
401  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i, ++InIdx) {
402  CCValAssign &VA = ArgLocs[i];
403 
404  if (Ins[InIdx].Flags.isSRet()) {
405  if (InIdx != 0)
406  report_fatal_error("sparc only supports sret on the first parameter");
407  // Get SRet from [%fp+64].
408  int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, 64, true);
409  SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
410  SDValue Arg =
411  DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
412  InVals.push_back(Arg);
413  continue;
414  }
415 
416  if (VA.isRegLoc()) {
417  if (VA.needsCustom()) {
418  assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
419 
420  unsigned VRegHi = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
421  MF.getRegInfo().addLiveIn(VA.getLocReg(), VRegHi);
422  SDValue HiVal = DAG.getCopyFromReg(Chain, dl, VRegHi, MVT::i32);
423 
424  assert(i+1 < e);
425  CCValAssign &NextVA = ArgLocs[++i];
426 
427  SDValue LoVal;
428  if (NextVA.isMemLoc()) {
429  int FrameIdx = MF.getFrameInfo().
430  CreateFixedObject(4, StackOffset+NextVA.getLocMemOffset(),true);
431  SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
432  LoVal = DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
433  } else {
434  unsigned loReg = MF.addLiveIn(NextVA.getLocReg(),
435  &SP::IntRegsRegClass);
436  LoVal = DAG.getCopyFromReg(Chain, dl, loReg, MVT::i32);
437  }
438 
439  if (IsLittleEndian)
440  std::swap(LoVal, HiVal);
441 
442  SDValue WholeValue =
443  DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
444  WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), WholeValue);
445  InVals.push_back(WholeValue);
446  continue;
447  }
448  unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
449  MF.getRegInfo().addLiveIn(VA.getLocReg(), VReg);
450  SDValue Arg = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32);
451  if (VA.getLocVT() == MVT::f32)
452  Arg = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Arg);
453  else if (VA.getLocVT() != MVT::i32) {
454  Arg = DAG.getNode(ISD::AssertSext, dl, MVT::i32, Arg,
455  DAG.getValueType(VA.getLocVT()));
456  Arg = DAG.getNode(ISD::TRUNCATE, dl, VA.getLocVT(), Arg);
457  }
458  InVals.push_back(Arg);
459  continue;
460  }
461 
462  assert(VA.isMemLoc());
463 
464  unsigned Offset = VA.getLocMemOffset()+StackOffset;
465  auto PtrVT = getPointerTy(DAG.getDataLayout());
466 
467  if (VA.needsCustom()) {
468  assert(VA.getValVT() == MVT::f64 || VA.getValVT() == MVT::v2i32);
469  // If it is double-word aligned, just load.
470  if (Offset % 8 == 0) {
471  int FI = MF.getFrameInfo().CreateFixedObject(8,
472  Offset,
473  true);
474  SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
475  SDValue Load =
476  DAG.getLoad(VA.getValVT(), dl, Chain, FIPtr, MachinePointerInfo());
477  InVals.push_back(Load);
478  continue;
479  }
480 
481  int FI = MF.getFrameInfo().CreateFixedObject(4,
482  Offset,
483  true);
484  SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
485  SDValue HiVal =
486  DAG.getLoad(MVT::i32, dl, Chain, FIPtr, MachinePointerInfo());
487  int FI2 = MF.getFrameInfo().CreateFixedObject(4,
488  Offset+4,
489  true);
490  SDValue FIPtr2 = DAG.getFrameIndex(FI2, PtrVT);
491 
492  SDValue LoVal =
493  DAG.getLoad(MVT::i32, dl, Chain, FIPtr2, MachinePointerInfo());
494 
495  if (IsLittleEndian)
496  std::swap(LoVal, HiVal);
497 
498  SDValue WholeValue =
499  DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, LoVal, HiVal);
500  WholeValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), WholeValue);
501  InVals.push_back(WholeValue);
502  continue;
503  }
504 
505  int FI = MF.getFrameInfo().CreateFixedObject(4,
506  Offset,
507  true);
508  SDValue FIPtr = DAG.getFrameIndex(FI, PtrVT);
509  SDValue Load ;
510  if (VA.getValVT() == MVT::i32 || VA.getValVT() == MVT::f32) {
511  Load = DAG.getLoad(VA.getValVT(), dl, Chain, FIPtr, MachinePointerInfo());
512  } else if (VA.getValVT() == MVT::f128) {
513  report_fatal_error("SPARCv8 does not handle f128 in calls; "
514  "pass indirectly");
515  } else {
516  // We shouldn't see any other value types here.
517  llvm_unreachable("Unexpected ValVT encountered in frame lowering.");
518  }
519  InVals.push_back(Load);
520  }
521 
522  if (MF.getFunction()->hasStructRetAttr()) {
523  // Copy the SRet Argument to SRetReturnReg.
525  unsigned Reg = SFI->getSRetReturnReg();
526  if (!Reg) {
527  Reg = MF.getRegInfo().createVirtualRegister(&SP::IntRegsRegClass);
528  SFI->setSRetReturnReg(Reg);
529  }
530  SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]);
531  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
532  }
533 
534  // Store remaining ArgRegs to the stack if this is a varargs function.
535  if (isVarArg) {
536  static const MCPhysReg ArgRegs[] = {
537  SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
538  };
539  unsigned NumAllocated = CCInfo.getFirstUnallocated(ArgRegs);
540  const MCPhysReg *CurArgReg = ArgRegs+NumAllocated, *ArgRegEnd = ArgRegs+6;
541  unsigned ArgOffset = CCInfo.getNextStackOffset();
542  if (NumAllocated == 6)
543  ArgOffset += StackOffset;
544  else {
545  assert(!ArgOffset);
546  ArgOffset = 68+4*NumAllocated;
547  }
548 
549  // Remember the vararg offset for the va_start implementation.
550  FuncInfo->setVarArgsFrameOffset(ArgOffset);
551 
552  std::vector<SDValue> OutChains;
553 
554  for (; CurArgReg != ArgRegEnd; ++CurArgReg) {
555  unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
556  MF.getRegInfo().addLiveIn(*CurArgReg, VReg);
557  SDValue Arg = DAG.getCopyFromReg(DAG.getRoot(), dl, VReg, MVT::i32);
558 
559  int FrameIdx = MF.getFrameInfo().CreateFixedObject(4, ArgOffset,
560  true);
561  SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
562 
563  OutChains.push_back(
564  DAG.getStore(DAG.getRoot(), dl, Arg, FIPtr, MachinePointerInfo()));
565  ArgOffset += 4;
566  }
567 
568  if (!OutChains.empty()) {
569  OutChains.push_back(Chain);
570  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
571  }
572  }
573 
574  return Chain;
575 }
576 
577 // Lower formal arguments for the 64 bit ABI.
579  SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
581  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
583 
584  // Analyze arguments according to CC_Sparc64.
586  CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
587  *DAG.getContext());
588  CCInfo.AnalyzeFormalArguments(Ins, CC_Sparc64);
589 
590  // The argument array begins at %fp+BIAS+128, after the register save area.
591  const unsigned ArgArea = 128;
592 
593  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
594  CCValAssign &VA = ArgLocs[i];
595  if (VA.isRegLoc()) {
596  // This argument is passed in a register.
597  // All integer register arguments are promoted by the caller to i64.
598 
599  // Create a virtual register for the promoted live-in value.
600  unsigned VReg = MF.addLiveIn(VA.getLocReg(),
601  getRegClassFor(VA.getLocVT()));
602  SDValue Arg = DAG.getCopyFromReg(Chain, DL, VReg, VA.getLocVT());
603 
604  // Get the high bits for i32 struct elements.
605  if (VA.getValVT() == MVT::i32 && VA.needsCustom())
606  Arg = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), Arg,
607  DAG.getConstant(32, DL, MVT::i32));
608 
609  // The caller promoted the argument, so insert an Assert?ext SDNode so we
610  // won't promote the value again in this function.
611  switch (VA.getLocInfo()) {
612  case CCValAssign::SExt:
613  Arg = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), Arg,
614  DAG.getValueType(VA.getValVT()));
615  break;
616  case CCValAssign::ZExt:
617  Arg = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), Arg,
618  DAG.getValueType(VA.getValVT()));
619  break;
620  default:
621  break;
622  }
623 
624  // Truncate the register down to the argument type.
625  if (VA.isExtInLoc())
626  Arg = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Arg);
627 
628  InVals.push_back(Arg);
629  continue;
630  }
631 
632  // The registers are exhausted. This argument was passed on the stack.
633  assert(VA.isMemLoc());
634  // The CC_Sparc64_Full/Half functions compute stack offsets relative to the
635  // beginning of the arguments area at %fp+BIAS+128.
636  unsigned Offset = VA.getLocMemOffset() + ArgArea;
637  unsigned ValSize = VA.getValVT().getSizeInBits() / 8;
638  // Adjust offset for extended arguments, SPARC is big-endian.
639  // The caller will have written the full slot with extended bytes, but we
640  // prefer our own extending loads.
641  if (VA.isExtInLoc())
642  Offset += 8 - ValSize;
643  int FI = MF.getFrameInfo().CreateFixedObject(ValSize, Offset, true);
644  InVals.push_back(
645  DAG.getLoad(VA.getValVT(), DL, Chain,
648  }
649 
650  if (!IsVarArg)
651  return Chain;
652 
653  // This function takes variable arguments, some of which may have been passed
654  // in registers %i0-%i5. Variable floating point arguments are never passed
655  // in floating point registers. They go on %i0-%i5 or on the stack like
656  // integer arguments.
657  //
658  // The va_start intrinsic needs to know the offset to the first variable
659  // argument.
660  unsigned ArgOffset = CCInfo.getNextStackOffset();
662  // Skip the 128 bytes of register save area.
663  FuncInfo->setVarArgsFrameOffset(ArgOffset + ArgArea +
664  Subtarget->getStackPointerBias());
665 
666  // Save the variable arguments that were passed in registers.
667  // The caller is required to reserve stack space for 6 arguments regardless
668  // of how many arguments were actually passed.
669  SmallVector<SDValue, 8> OutChains;
670  for (; ArgOffset < 6*8; ArgOffset += 8) {
671  unsigned VReg = MF.addLiveIn(SP::I0 + ArgOffset/8, &SP::I64RegsRegClass);
672  SDValue VArg = DAG.getCopyFromReg(Chain, DL, VReg, MVT::i64);
673  int FI = MF.getFrameInfo().CreateFixedObject(8, ArgOffset + ArgArea, true);
674  auto PtrVT = getPointerTy(MF.getDataLayout());
675  OutChains.push_back(
676  DAG.getStore(Chain, DL, VArg, DAG.getFrameIndex(FI, PtrVT),
678  }
679 
680  if (!OutChains.empty())
681  Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
682 
683  return Chain;
684 }
685 
686 SDValue
688  SmallVectorImpl<SDValue> &InVals) const {
689  if (Subtarget->is64Bit())
690  return LowerCall_64(CLI, InVals);
691  return LowerCall_32(CLI, InVals);
692 }
693 
694 static bool hasReturnsTwiceAttr(SelectionDAG &DAG, SDValue Callee,
695  ImmutableCallSite *CS) {
696  if (CS)
697  return CS->hasFnAttr(Attribute::ReturnsTwice);
698 
699  const Function *CalleeFn = nullptr;
700  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
701  CalleeFn = dyn_cast<Function>(G->getGlobal());
702  } else if (ExternalSymbolSDNode *E =
703  dyn_cast<ExternalSymbolSDNode>(Callee)) {
704  const Function *Fn = DAG.getMachineFunction().getFunction();
705  const Module *M = Fn->getParent();
706  const char *CalleeName = E->getSymbol();
707  CalleeFn = M->getFunction(CalleeName);
708  }
709 
710  if (!CalleeFn)
711  return false;
712  return CalleeFn->hasFnAttribute(Attribute::ReturnsTwice);
713 }
714 
715 // Lower a call for the 32-bit ABI.
716 SDValue
718  SmallVectorImpl<SDValue> &InVals) const {
719  SelectionDAG &DAG = CLI.DAG;
720  SDLoc &dl = CLI.DL;
722  SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
724  SDValue Chain = CLI.Chain;
725  SDValue Callee = CLI.Callee;
726  bool &isTailCall = CLI.IsTailCall;
727  CallingConv::ID CallConv = CLI.CallConv;
728  bool isVarArg = CLI.IsVarArg;
729 
730  // Sparc target does not yet support tail call optimization.
731  isTailCall = false;
732 
733  // Analyze operands of the call, assigning locations to each operand.
735  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
736  *DAG.getContext());
737  CCInfo.AnalyzeCallOperands(Outs, CC_Sparc32);
738 
739  // Get the size of the outgoing arguments stack space requirement.
740  unsigned ArgsSize = CCInfo.getNextStackOffset();
741 
742  // Keep stack frames 8-byte aligned.
743  ArgsSize = (ArgsSize+7) & ~7;
744 
746 
747  // Create local copies for byval args.
748  SmallVector<SDValue, 8> ByValArgs;
749  for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
750  ISD::ArgFlagsTy Flags = Outs[i].Flags;
751  if (!Flags.isByVal())
752  continue;
753 
754  SDValue Arg = OutVals[i];
755  unsigned Size = Flags.getByValSize();
756  unsigned Align = Flags.getByValAlign();
757 
758  if (Size > 0U) {
759  int FI = MFI.CreateStackObject(Size, Align, false);
760  SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
761  SDValue SizeNode = DAG.getConstant(Size, dl, MVT::i32);
762 
763  Chain = DAG.getMemcpy(Chain, dl, FIPtr, Arg, SizeNode, Align,
764  false, // isVolatile,
765  (Size <= 32), // AlwaysInline if size <= 32,
766  false, // isTailCall
768  ByValArgs.push_back(FIPtr);
769  }
770  else {
771  SDValue nullVal;
772  ByValArgs.push_back(nullVal);
773  }
774  }
775 
776  Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, dl);
777 
779  SmallVector<SDValue, 8> MemOpChains;
780 
781  const unsigned StackOffset = 92;
782  bool hasStructRetAttr = false;
783  // Walk the register/memloc assignments, inserting copies/loads.
784  for (unsigned i = 0, realArgIdx = 0, byvalArgIdx = 0, e = ArgLocs.size();
785  i != e;
786  ++i, ++realArgIdx) {
787  CCValAssign &VA = ArgLocs[i];
788  SDValue Arg = OutVals[realArgIdx];
789 
790  ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
791 
792  // Use local copy if it is a byval arg.
793  if (Flags.isByVal()) {
794  Arg = ByValArgs[byvalArgIdx++];
795  if (!Arg) {
796  continue;
797  }
798  }
799 
800  // Promote the value if needed.
801  switch (VA.getLocInfo()) {
802  default: llvm_unreachable("Unknown loc info!");
803  case CCValAssign::Full: break;
804  case CCValAssign::SExt:
805  Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
806  break;
807  case CCValAssign::ZExt:
808  Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
809  break;
810  case CCValAssign::AExt:
811  Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
812  break;
813  case CCValAssign::BCvt:
814  Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg);
815  break;
816  }
817 
818  if (Flags.isSRet()) {
819  assert(VA.needsCustom());
820  // store SRet argument in %sp+64
821  SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
822  SDValue PtrOff = DAG.getIntPtrConstant(64, dl);
823  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
824  MemOpChains.push_back(
825  DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
826  hasStructRetAttr = true;
827  continue;
828  }
829 
830  if (VA.needsCustom()) {
831  assert(VA.getLocVT() == MVT::f64 || VA.getLocVT() == MVT::v2i32);
832 
833  if (VA.isMemLoc()) {
834  unsigned Offset = VA.getLocMemOffset() + StackOffset;
835  // if it is double-word aligned, just store.
836  if (Offset % 8 == 0) {
837  SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
838  SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
839  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
840  MemOpChains.push_back(
841  DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
842  continue;
843  }
844  }
845 
846  if (VA.getLocVT() == MVT::f64) {
847  // Move from the float value from float registers into the
848  // integer registers.
849 
850  // TODO: The f64 -> v2i32 conversion is super-inefficient for
851  // constants: it sticks them in the constant pool, then loads
852  // to a fp register, then stores to temp memory, then loads to
853  // integer registers.
854  Arg = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, Arg);
855  }
856 
858  Arg,
859  DAG.getConstant(0, dl, getVectorIdxTy(DAG.getDataLayout())));
861  Arg,
862  DAG.getConstant(1, dl, getVectorIdxTy(DAG.getDataLayout())));
863 
864  if (VA.isRegLoc()) {
865  RegsToPass.push_back(std::make_pair(VA.getLocReg(), Part0));
866  assert(i+1 != e);
867  CCValAssign &NextVA = ArgLocs[++i];
868  if (NextVA.isRegLoc()) {
869  RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), Part1));
870  } else {
871  // Store the second part in stack.
872  unsigned Offset = NextVA.getLocMemOffset() + StackOffset;
873  SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
874  SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
875  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
876  MemOpChains.push_back(
877  DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
878  }
879  } else {
880  unsigned Offset = VA.getLocMemOffset() + StackOffset;
881  // Store the first part.
882  SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
883  SDValue PtrOff = DAG.getIntPtrConstant(Offset, dl);
884  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
885  MemOpChains.push_back(
886  DAG.getStore(Chain, dl, Part0, PtrOff, MachinePointerInfo()));
887  // Store the second part.
888  PtrOff = DAG.getIntPtrConstant(Offset + 4, dl);
889  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
890  MemOpChains.push_back(
891  DAG.getStore(Chain, dl, Part1, PtrOff, MachinePointerInfo()));
892  }
893  continue;
894  }
895 
896  // Arguments that can be passed on register must be kept at
897  // RegsToPass vector
898  if (VA.isRegLoc()) {
899  if (VA.getLocVT() != MVT::f32) {
900  RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
901  continue;
902  }
903  Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg);
904  RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
905  continue;
906  }
907 
908  assert(VA.isMemLoc());
909 
910  // Create a store off the stack pointer for this argument.
911  SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
912  SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset() + StackOffset,
913  dl);
914  PtrOff = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, PtrOff);
915  MemOpChains.push_back(
916  DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()));
917  }
918 
919 
920  // Emit all stores, make sure the occur before any copies into physregs.
921  if (!MemOpChains.empty())
922  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
923 
924  // Build a sequence of copy-to-reg nodes chained together with token
925  // chain and flag operands which copy the outgoing args into registers.
926  // The InFlag in necessary since all emitted instructions must be
927  // stuck together.
928  SDValue InFlag;
929  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
930  unsigned Reg = toCallerWindow(RegsToPass[i].first);
931  Chain = DAG.getCopyToReg(Chain, dl, Reg, RegsToPass[i].second, InFlag);
932  InFlag = Chain.getValue(1);
933  }
934 
935  unsigned SRetArgSize = (hasStructRetAttr)? getSRetArgSize(DAG, Callee):0;
936  bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CS);
937 
938  // If the callee is a GlobalAddress node (quite common, every direct call is)
939  // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
940  // Likewise ExternalSymbol -> TargetExternalSymbol.
942  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
943  Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32, 0, TF);
944  else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
945  Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32, TF);
946 
947  // Returns a chain & a flag for retval copy to use
948  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
950  Ops.push_back(Chain);
951  Ops.push_back(Callee);
952  if (hasStructRetAttr)
953  Ops.push_back(DAG.getTargetConstant(SRetArgSize, dl, MVT::i32));
954  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
955  Ops.push_back(DAG.getRegister(toCallerWindow(RegsToPass[i].first),
956  RegsToPass[i].second.getValueType()));
957 
958  // Add a register mask operand representing the call-preserved registers.
959  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
960  const uint32_t *Mask =
961  ((hasReturnsTwice)
962  ? TRI->getRTCallPreservedMask(CallConv)
963  : TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv));
964  assert(Mask && "Missing call preserved mask for calling convention");
965  Ops.push_back(DAG.getRegisterMask(Mask));
966 
967  if (InFlag.getNode())
968  Ops.push_back(InFlag);
969 
970  Chain = DAG.getNode(SPISD::CALL, dl, NodeTys, Ops);
971  InFlag = Chain.getValue(1);
972 
973  Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(ArgsSize, dl, true),
974  DAG.getIntPtrConstant(0, dl, true), InFlag, dl);
975  InFlag = Chain.getValue(1);
976 
977  // Assign locations to each value returned by this call.
979  CCState RVInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
980  *DAG.getContext());
981 
982  RVInfo.AnalyzeCallResult(Ins, RetCC_Sparc32);
983 
984  // Copy all of the result registers out of their specified physreg.
985  for (unsigned i = 0; i != RVLocs.size(); ++i) {
986  if (RVLocs[i].getLocVT() == MVT::v2i32) {
987  SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2i32);
988  SDValue Lo = DAG.getCopyFromReg(
989  Chain, dl, toCallerWindow(RVLocs[i++].getLocReg()), MVT::i32, InFlag);
990  Chain = Lo.getValue(1);
991  InFlag = Lo.getValue(2);
992  Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Lo,
993  DAG.getConstant(0, dl, MVT::i32));
994  SDValue Hi = DAG.getCopyFromReg(
995  Chain, dl, toCallerWindow(RVLocs[i].getLocReg()), MVT::i32, InFlag);
996  Chain = Hi.getValue(1);
997  InFlag = Hi.getValue(2);
998  Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2i32, Vec, Hi,
999  DAG.getConstant(1, dl, MVT::i32));
1000  InVals.push_back(Vec);
1001  } else {
1002  Chain =
1003  DAG.getCopyFromReg(Chain, dl, toCallerWindow(RVLocs[i].getLocReg()),
1004  RVLocs[i].getValVT(), InFlag)
1005  .getValue(1);
1006  InFlag = Chain.getValue(2);
1007  InVals.push_back(Chain.getValue(0));
1008  }
1009  }
1010 
1011  return Chain;
1012 }
1013 
1014 // FIXME? Maybe this could be a TableGen attribute on some registers and
1015 // this table could be generated automatically from RegInfo.
1016 unsigned SparcTargetLowering::getRegisterByName(const char* RegName, EVT VT,
1017  SelectionDAG &DAG) const {
1018  unsigned Reg = StringSwitch<unsigned>(RegName)
1019  .Case("i0", SP::I0).Case("i1", SP::I1).Case("i2", SP::I2).Case("i3", SP::I3)
1020  .Case("i4", SP::I4).Case("i5", SP::I5).Case("i6", SP::I6).Case("i7", SP::I7)
1021  .Case("o0", SP::O0).Case("o1", SP::O1).Case("o2", SP::O2).Case("o3", SP::O3)
1022  .Case("o4", SP::O4).Case("o5", SP::O5).Case("o6", SP::O6).Case("o7", SP::O7)
1023  .Case("l0", SP::L0).Case("l1", SP::L1).Case("l2", SP::L2).Case("l3", SP::L3)
1024  .Case("l4", SP::L4).Case("l5", SP::L5).Case("l6", SP::L6).Case("l7", SP::L7)
1025  .Case("g0", SP::G0).Case("g1", SP::G1).Case("g2", SP::G2).Case("g3", SP::G3)
1026  .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", SP::G7)
1027  .Default(0);
1028 
1029  if (Reg)
1030  return Reg;
1031 
1032  report_fatal_error("Invalid register name global variable");
1033 }
1034 
1035 // This functions returns true if CalleeName is a ABI function that returns
1036 // a long double (fp128).
1037 static bool isFP128ABICall(const char *CalleeName)
1038 {
1039  static const char *const ABICalls[] =
1040  { "_Q_add", "_Q_sub", "_Q_mul", "_Q_div",
1041  "_Q_sqrt", "_Q_neg",
1042  "_Q_itoq", "_Q_stoq", "_Q_dtoq", "_Q_utoq",
1043  "_Q_lltoq", "_Q_ulltoq",
1044  nullptr
1045  };
1046  for (const char * const *I = ABICalls; *I != nullptr; ++I)
1047  if (strcmp(CalleeName, *I) == 0)
1048  return true;
1049  return false;
1050 }
1051 
1052 unsigned
1054 {
1055  const Function *CalleeFn = nullptr;
1056  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
1057  CalleeFn = dyn_cast<Function>(G->getGlobal());
1058  } else if (ExternalSymbolSDNode *E =
1059  dyn_cast<ExternalSymbolSDNode>(Callee)) {
1060  const Function *Fn = DAG.getMachineFunction().getFunction();
1061  const Module *M = Fn->getParent();
1062  const char *CalleeName = E->getSymbol();
1063  CalleeFn = M->getFunction(CalleeName);
1064  if (!CalleeFn && isFP128ABICall(CalleeName))
1065  return 16; // Return sizeof(fp128)
1066  }
1067 
1068  if (!CalleeFn)
1069  return 0;
1070 
1071  // It would be nice to check for the sret attribute on CalleeFn here,
1072  // but since it is not part of the function type, any check will misfire.
1073 
1074  PointerType *Ty = cast<PointerType>(CalleeFn->arg_begin()->getType());
1075  Type *ElementTy = Ty->getElementType();
1076  return DAG.getDataLayout().getTypeAllocSize(ElementTy);
1077 }
1078 
1079 
1080 // Fixup floating point arguments in the ... part of a varargs call.
1081 //
1082 // The SPARC v9 ABI requires that floating point arguments are treated the same
1083 // as integers when calling a varargs function. This does not apply to the
1084 // fixed arguments that are part of the function's prototype.
1085 //
1086 // This function post-processes a CCValAssign array created by
1087 // AnalyzeCallOperands().
1089  ArrayRef<ISD::OutputArg> Outs) {
1090  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1091  const CCValAssign &VA = ArgLocs[i];
1092  MVT ValTy = VA.getLocVT();
1093  // FIXME: What about f32 arguments? C promotes them to f64 when calling
1094  // varargs functions.
1095  if (!VA.isRegLoc() || (ValTy != MVT::f64 && ValTy != MVT::f128))
1096  continue;
1097  // The fixed arguments to a varargs function still go in FP registers.
1098  if (Outs[VA.getValNo()].IsFixed)
1099  continue;
1100 
1101  // This floating point argument should be reassigned.
1102  CCValAssign NewVA;
1103 
1104  // Determine the offset into the argument array.
1105  unsigned firstReg = (ValTy == MVT::f64) ? SP::D0 : SP::Q0;
1106  unsigned argSize = (ValTy == MVT::f64) ? 8 : 16;
1107  unsigned Offset = argSize * (VA.getLocReg() - firstReg);
1108  assert(Offset < 16*8 && "Offset out of range, bad register enum?");
1109 
1110  if (Offset < 6*8) {
1111  // This argument should go in %i0-%i5.
1112  unsigned IReg = SP::I0 + Offset/8;
1113  if (ValTy == MVT::f64)
1114  // Full register, just bitconvert into i64.
1115  NewVA = CCValAssign::getReg(VA.getValNo(), VA.getValVT(),
1116  IReg, MVT::i64, CCValAssign::BCvt);
1117  else {
1118  assert(ValTy == MVT::f128 && "Unexpected type!");
1119  // Full register, just bitconvert into i128 -- We will lower this into
1120  // two i64s in LowerCall_64.
1121  NewVA = CCValAssign::getCustomReg(VA.getValNo(), VA.getValVT(),
1122  IReg, MVT::i128, CCValAssign::BCvt);
1123  }
1124  } else {
1125  // This needs to go to memory, we're out of integer registers.
1126  NewVA = CCValAssign::getMem(VA.getValNo(), VA.getValVT(),
1127  Offset, VA.getLocVT(), VA.getLocInfo());
1128  }
1129  ArgLocs[i] = NewVA;
1130  }
1131 }
1132 
1133 // Lower a call for the 64-bit ABI.
1134 SDValue
1136  SmallVectorImpl<SDValue> &InVals) const {
1137  SelectionDAG &DAG = CLI.DAG;
1138  SDLoc DL = CLI.DL;
1139  SDValue Chain = CLI.Chain;
1140  auto PtrVT = getPointerTy(DAG.getDataLayout());
1141 
1142  // Sparc target does not yet support tail call optimization.
1143  CLI.IsTailCall = false;
1144 
1145  // Analyze operands of the call, assigning locations to each operand.
1147  CCState CCInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), ArgLocs,
1148  *DAG.getContext());
1149  CCInfo.AnalyzeCallOperands(CLI.Outs, CC_Sparc64);
1150 
1151  // Get the size of the outgoing arguments stack space requirement.
1152  // The stack offset computed by CC_Sparc64 includes all arguments.
1153  // Called functions expect 6 argument words to exist in the stack frame, used
1154  // or not.
1155  unsigned ArgsSize = std::max(6*8u, CCInfo.getNextStackOffset());
1156 
1157  // Keep stack frames 16-byte aligned.
1158  ArgsSize = alignTo(ArgsSize, 16);
1159 
1160  // Varargs calls require special treatment.
1161  if (CLI.IsVarArg)
1162  fixupVariableFloatArgs(ArgLocs, CLI.Outs);
1163 
1164  // Adjust the stack pointer to make room for the arguments.
1165  // FIXME: Use hasReservedCallFrame to avoid %sp adjustments around all calls
1166  // with more than 6 arguments.
1167  Chain = DAG.getCALLSEQ_START(Chain, ArgsSize, 0, DL);
1168 
1169  // Collect the set of registers to pass to the function and their values.
1170  // This will be emitted as a sequence of CopyToReg nodes glued to the call
1171  // instruction.
1173 
1174  // Collect chains from all the memory opeations that copy arguments to the
1175  // stack. They must follow the stack pointer adjustment above and precede the
1176  // call instruction itself.
1177  SmallVector<SDValue, 8> MemOpChains;
1178 
1179  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1180  const CCValAssign &VA = ArgLocs[i];
1181  SDValue Arg = CLI.OutVals[i];
1182 
1183  // Promote the value if needed.
1184  switch (VA.getLocInfo()) {
1185  default:
1186  llvm_unreachable("Unknown location info!");
1187  case CCValAssign::Full:
1188  break;
1189  case CCValAssign::SExt:
1190  Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Arg);
1191  break;
1192  case CCValAssign::ZExt:
1193  Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Arg);
1194  break;
1195  case CCValAssign::AExt:
1196  Arg = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Arg);
1197  break;
1198  case CCValAssign::BCvt:
1199  // fixupVariableFloatArgs() may create bitcasts from f128 to i128. But
1200  // SPARC does not support i128 natively. Lower it into two i64, see below.
1201  if (!VA.needsCustom() || VA.getValVT() != MVT::f128
1202  || VA.getLocVT() != MVT::i128)
1203  Arg = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Arg);
1204  break;
1205  }
1206 
1207  if (VA.isRegLoc()) {
1208  if (VA.needsCustom() && VA.getValVT() == MVT::f128
1209  && VA.getLocVT() == MVT::i128) {
1210  // Store and reload into the integer register reg and reg+1.
1211  unsigned Offset = 8 * (VA.getLocReg() - SP::I0);
1212  unsigned StackOffset = Offset + Subtarget->getStackPointerBias() + 128;
1213  SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1214  SDValue HiPtrOff = DAG.getIntPtrConstant(StackOffset, DL);
1215  HiPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, HiPtrOff);
1216  SDValue LoPtrOff = DAG.getIntPtrConstant(StackOffset + 8, DL);
1217  LoPtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, LoPtrOff);
1218 
1219  // Store to %sp+BIAS+128+Offset
1220  SDValue Store =
1221  DAG.getStore(Chain, DL, Arg, HiPtrOff, MachinePointerInfo());
1222  // Load into Reg and Reg+1
1223  SDValue Hi64 =
1224  DAG.getLoad(MVT::i64, DL, Store, HiPtrOff, MachinePointerInfo());
1225  SDValue Lo64 =
1226  DAG.getLoad(MVT::i64, DL, Store, LoPtrOff, MachinePointerInfo());
1227  RegsToPass.push_back(std::make_pair(toCallerWindow(VA.getLocReg()),
1228  Hi64));
1229  RegsToPass.push_back(std::make_pair(toCallerWindow(VA.getLocReg()+1),
1230  Lo64));
1231  continue;
1232  }
1233 
1234  // The custom bit on an i32 return value indicates that it should be
1235  // passed in the high bits of the register.
1236  if (VA.getValVT() == MVT::i32 && VA.needsCustom()) {
1237  Arg = DAG.getNode(ISD::SHL, DL, MVT::i64, Arg,
1238  DAG.getConstant(32, DL, MVT::i32));
1239 
1240  // The next value may go in the low bits of the same register.
1241  // Handle both at once.
1242  if (i+1 < ArgLocs.size() && ArgLocs[i+1].isRegLoc() &&
1243  ArgLocs[i+1].getLocReg() == VA.getLocReg()) {
1245  CLI.OutVals[i+1]);
1246  Arg = DAG.getNode(ISD::OR, DL, MVT::i64, Arg, NV);
1247  // Skip the next value, it's already done.
1248  ++i;
1249  }
1250  }
1251  RegsToPass.push_back(std::make_pair(toCallerWindow(VA.getLocReg()), Arg));
1252  continue;
1253  }
1254 
1255  assert(VA.isMemLoc());
1256 
1257  // Create a store off the stack pointer for this argument.
1258  SDValue StackPtr = DAG.getRegister(SP::O6, PtrVT);
1259  // The argument area starts at %fp+BIAS+128 in the callee frame,
1260  // %sp+BIAS+128 in ours.
1261  SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset() +
1262  Subtarget->getStackPointerBias() +
1263  128, DL);
1264  PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
1265  MemOpChains.push_back(
1266  DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo()));
1267  }
1268 
1269  // Emit all stores, make sure they occur before the call.
1270  if (!MemOpChains.empty())
1271  Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
1272 
1273  // Build a sequence of CopyToReg nodes glued together with token chain and
1274  // glue operands which copy the outgoing args into registers. The InGlue is
1275  // necessary since all emitted instructions must be stuck together in order
1276  // to pass the live physical registers.
1277  SDValue InGlue;
1278  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
1279  Chain = DAG.getCopyToReg(Chain, DL,
1280  RegsToPass[i].first, RegsToPass[i].second, InGlue);
1281  InGlue = Chain.getValue(1);
1282  }
1283 
1284  // If the callee is a GlobalAddress node (quite common, every direct call is)
1285  // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
1286  // Likewise ExternalSymbol -> TargetExternalSymbol.
1287  SDValue Callee = CLI.Callee;
1288  bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CS);
1290  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1291  Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, PtrVT, 0, TF);
1292  else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
1293  Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT, TF);
1294 
1295  // Build the operands for the call instruction itself.
1297  Ops.push_back(Chain);
1298  Ops.push_back(Callee);
1299  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
1300  Ops.push_back(DAG.getRegister(RegsToPass[i].first,
1301  RegsToPass[i].second.getValueType()));
1302 
1303  // Add a register mask operand representing the call-preserved registers.
1304  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
1305  const uint32_t *Mask =
1306  ((hasReturnsTwice) ? TRI->getRTCallPreservedMask(CLI.CallConv)
1308  CLI.CallConv));
1309  assert(Mask && "Missing call preserved mask for calling convention");
1310  Ops.push_back(DAG.getRegisterMask(Mask));
1311 
1312  // Make sure the CopyToReg nodes are glued to the call instruction which
1313  // consumes the registers.
1314  if (InGlue.getNode())
1315  Ops.push_back(InGlue);
1316 
1317  // Now the call itself.
1318  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1319  Chain = DAG.getNode(SPISD::CALL, DL, NodeTys, Ops);
1320  InGlue = Chain.getValue(1);
1321 
1322  // Revert the stack pointer immediately after the call.
1323  Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(ArgsSize, DL, true),
1324  DAG.getIntPtrConstant(0, DL, true), InGlue, DL);
1325  InGlue = Chain.getValue(1);
1326 
1327  // Now extract the return values. This is more or less the same as
1328  // LowerFormalArguments_64.
1329 
1330  // Assign locations to each value returned by this call.
1332  CCState RVInfo(CLI.CallConv, CLI.IsVarArg, DAG.getMachineFunction(), RVLocs,
1333  *DAG.getContext());
1334 
1335  // Set inreg flag manually for codegen generated library calls that
1336  // return float.
1337  if (CLI.Ins.size() == 1 && CLI.Ins[0].VT == MVT::f32 && CLI.CS == nullptr)
1338  CLI.Ins[0].Flags.setInReg();
1339 
1340  RVInfo.AnalyzeCallResult(CLI.Ins, RetCC_Sparc64);
1341 
1342  // Copy all of the result registers out of their specified physreg.
1343  for (unsigned i = 0; i != RVLocs.size(); ++i) {
1344  CCValAssign &VA = RVLocs[i];
1345  unsigned Reg = toCallerWindow(VA.getLocReg());
1346 
1347  // When returning 'inreg {i32, i32 }', two consecutive i32 arguments can
1348  // reside in the same register in the high and low bits. Reuse the
1349  // CopyFromReg previous node to avoid duplicate copies.
1350  SDValue RV;
1351  if (RegisterSDNode *SrcReg = dyn_cast<RegisterSDNode>(Chain.getOperand(1)))
1352  if (SrcReg->getReg() == Reg && Chain->getOpcode() == ISD::CopyFromReg)
1353  RV = Chain.getValue(0);
1354 
1355  // But usually we'll create a new CopyFromReg for a different register.
1356  if (!RV.getNode()) {
1357  RV = DAG.getCopyFromReg(Chain, DL, Reg, RVLocs[i].getLocVT(), InGlue);
1358  Chain = RV.getValue(1);
1359  InGlue = Chain.getValue(2);
1360  }
1361 
1362  // Get the high bits for i32 struct elements.
1363  if (VA.getValVT() == MVT::i32 && VA.needsCustom())
1364  RV = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), RV,
1365  DAG.getConstant(32, DL, MVT::i32));
1366 
1367  // The callee promoted the return value, so insert an Assert?ext SDNode so
1368  // we won't promote the value again in this function.
1369  switch (VA.getLocInfo()) {
1370  case CCValAssign::SExt:
1371  RV = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), RV,
1372  DAG.getValueType(VA.getValVT()));
1373  break;
1374  case CCValAssign::ZExt:
1375  RV = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), RV,
1376  DAG.getValueType(VA.getValVT()));
1377  break;
1378  default:
1379  break;
1380  }
1381 
1382  // Truncate the register down to the return value type.
1383  if (VA.isExtInLoc())
1384  RV = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), RV);
1385 
1386  InVals.push_back(RV);
1387  }
1388 
1389  return Chain;
1390 }
1391 
1392 //===----------------------------------------------------------------------===//
1393 // TargetLowering Implementation
1394 //===----------------------------------------------------------------------===//
1395 
1397  if (AI->getOperation() == AtomicRMWInst::Xchg &&
1398  AI->getType()->getPrimitiveSizeInBits() == 32)
1399  return AtomicExpansionKind::None; // Uses xchg instruction
1400 
1402 }
1403 
1404 /// IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC
1405 /// condition.
1407  switch (CC) {
1408  default: llvm_unreachable("Unknown integer condition code!");
1409  case ISD::SETEQ: return SPCC::ICC_E;
1410  case ISD::SETNE: return SPCC::ICC_NE;
1411  case ISD::SETLT: return SPCC::ICC_L;
1412  case ISD::SETGT: return SPCC::ICC_G;
1413  case ISD::SETLE: return SPCC::ICC_LE;
1414  case ISD::SETGE: return SPCC::ICC_GE;
1415  case ISD::SETULT: return SPCC::ICC_CS;
1416  case ISD::SETULE: return SPCC::ICC_LEU;
1417  case ISD::SETUGT: return SPCC::ICC_GU;
1418  case ISD::SETUGE: return SPCC::ICC_CC;
1419  }
1420 }
1421 
1422 /// FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC
1423 /// FCC condition.
1425  switch (CC) {
1426  default: llvm_unreachable("Unknown fp condition code!");
1427  case ISD::SETEQ:
1428  case ISD::SETOEQ: return SPCC::FCC_E;
1429  case ISD::SETNE:
1430  case ISD::SETUNE: return SPCC::FCC_NE;
1431  case ISD::SETLT:
1432  case ISD::SETOLT: return SPCC::FCC_L;
1433  case ISD::SETGT:
1434  case ISD::SETOGT: return SPCC::FCC_G;
1435  case ISD::SETLE:
1436  case ISD::SETOLE: return SPCC::FCC_LE;
1437  case ISD::SETGE:
1438  case ISD::SETOGE: return SPCC::FCC_GE;
1439  case ISD::SETULT: return SPCC::FCC_UL;
1440  case ISD::SETULE: return SPCC::FCC_ULE;
1441  case ISD::SETUGT: return SPCC::FCC_UG;
1442  case ISD::SETUGE: return SPCC::FCC_UGE;
1443  case ISD::SETUO: return SPCC::FCC_U;
1444  case ISD::SETO: return SPCC::FCC_O;
1445  case ISD::SETONE: return SPCC::FCC_LG;
1446  case ISD::SETUEQ: return SPCC::FCC_UE;
1447  }
1448 }
1449 
1451  const SparcSubtarget &STI)
1452  : TargetLowering(TM), Subtarget(&STI) {
1453  MVT PtrVT = MVT::getIntegerVT(8 * TM.getPointerSize());
1454 
1455  // Instructions which use registers as conditionals examine all the
1456  // bits (as does the pseudo SELECT_CC expansion). I don't think it
1457  // matters much whether it's ZeroOrOneBooleanContent, or
1458  // ZeroOrNegativeOneBooleanContent, so, arbitrarily choose the
1459  // former.
1462 
1463  // Set up the register classes.
1464  addRegisterClass(MVT::i32, &SP::IntRegsRegClass);
1465  if (!Subtarget->useSoftFloat()) {
1466  addRegisterClass(MVT::f32, &SP::FPRegsRegClass);
1467  addRegisterClass(MVT::f64, &SP::DFPRegsRegClass);
1468  addRegisterClass(MVT::f128, &SP::QFPRegsRegClass);
1469  }
1470  if (Subtarget->is64Bit()) {
1471  addRegisterClass(MVT::i64, &SP::I64RegsRegClass);
1472  } else {
1473  // On 32bit sparc, we define a double-register 32bit register
1474  // class, as well. This is modeled in LLVM as a 2-vector of i32.
1475  addRegisterClass(MVT::v2i32, &SP::IntPairRegClass);
1476 
1477  // ...but almost all operations must be expanded, so set that as
1478  // the default.
1479  for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op) {
1481  }
1482  // Truncating/extending stores/loads are also not supported.
1483  for (MVT VT : MVT::integer_vector_valuetypes()) {
1487 
1491 
1494  }
1495  // However, load and store *are* legal.
1500 
1501  // And we need to promote i64 loads/stores into vector load/store
1504 
1505  // Sadly, this doesn't work:
1506  // AddPromotedToType(ISD::LOAD, MVT::i64, MVT::v2i32);
1507  // AddPromotedToType(ISD::STORE, MVT::i64, MVT::v2i32);
1508  }
1509 
1510  // Turn FP extload into load/fpextend
1511  for (MVT VT : MVT::fp_valuetypes()) {
1514  }
1515 
1516  // Sparc doesn't have i1 sign extending load
1517  for (MVT VT : MVT::integer_valuetypes())
1519 
1520  // Turn FP truncstore into trunc + store.
1524 
1525  // Custom legalize GlobalAddress nodes into LO/HI parts.
1530 
1531  // Sparc doesn't have sext_inreg, replace them with shl/sra
1535 
1536  // Sparc has no REM or DIVREM operations.
1541 
1542  // ... nor does SparcV9.
1543  if (Subtarget->is64Bit()) {
1548  }
1549 
1550  // Custom expand fp<->sint
1555 
1556  // Custom Expand fp<->uint
1561 
1564 
1565  // Sparc has no select or setcc: expand to SELECT_CC.
1570 
1575 
1576  // Sparc doesn't have BRCOND either, it has BR_CC.
1584 
1589 
1592 
1593  if (Subtarget->is64Bit()) {
1604 
1606  Subtarget->usePopc() ? Legal : Expand);
1613  }
1614 
1615  // ATOMICs.
1616  // Atomics are supported on SparcV9. 32-bit atomics are also
1617  // supported by some Leon SparcV8 variants. Otherwise, atomics
1618  // are unsupported.
1619  if (Subtarget->isV9())
1621  else if (Subtarget->hasLeonCasa())
1623  else
1625 
1627 
1629 
1631 
1632  // Custom Lower Atomic LOAD/STORE
1635 
1636  if (Subtarget->is64Bit()) {
1641  }
1642 
1643  if (!Subtarget->is64Bit()) {
1644  // These libcalls are not available in 32-bit.
1645  setLibcallName(RTLIB::SHL_I128, nullptr);
1646  setLibcallName(RTLIB::SRL_I128, nullptr);
1647  setLibcallName(RTLIB::SRA_I128, nullptr);
1648  }
1649 
1650  if (!Subtarget->isV9()) {
1651  // SparcV8 does not have FNEGD and FABSD.
1654  }
1655 
1682 
1686 
1687  // Expands to [SU]MUL_LOHI.
1691 
1692  if (Subtarget->useSoftMulDiv()) {
1693  // .umul works for both signed and unsigned
1696  setLibcallName(RTLIB::MUL_I32, ".umul");
1697 
1700 
1702  setLibcallName(RTLIB::UDIV_I32, ".udiv");
1703  }
1704 
1705  if (Subtarget->is64Bit()) {
1710 
1713 
1717  }
1718 
1719  // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
1721  // VAARG needs to be lowered to not do unaligned accesses for doubles.
1723 
1725 
1726  // Use the default implementation.
1732 
1734 
1736  Subtarget->usePopc() ? Legal : Expand);
1737 
1738  if (Subtarget->isV9() && Subtarget->hasHardQuad()) {
1741  } else {
1744  }
1745 
1746  if (Subtarget->hasHardQuad()) {
1754  if (Subtarget->isV9()) {
1757  } else {
1760  }
1761 
1762  if (!Subtarget->is64Bit()) {
1767  }
1768 
1769  } else {
1770  // Custom legalize f128 operations.
1771 
1779 
1783 
1784  // Setup Runtime library names.
1785  if (Subtarget->is64Bit() && !Subtarget->useSoftFloat()) {
1786  setLibcallName(RTLIB::ADD_F128, "_Qp_add");
1787  setLibcallName(RTLIB::SUB_F128, "_Qp_sub");
1788  setLibcallName(RTLIB::MUL_F128, "_Qp_mul");
1789  setLibcallName(RTLIB::DIV_F128, "_Qp_div");
1790  setLibcallName(RTLIB::SQRT_F128, "_Qp_sqrt");
1803  } else if (!Subtarget->useSoftFloat()) {
1804  setLibcallName(RTLIB::ADD_F128, "_Q_add");
1805  setLibcallName(RTLIB::SUB_F128, "_Q_sub");
1806  setLibcallName(RTLIB::MUL_F128, "_Q_mul");
1807  setLibcallName(RTLIB::DIV_F128, "_Q_div");
1808  setLibcallName(RTLIB::SQRT_F128, "_Q_sqrt");
1821  }
1822  }
1823 
1824  if (Subtarget->fixAllFDIVSQRT()) {
1825  // Promote FDIVS and FSQRTS to FDIVD and FSQRTD instructions instead as
1826  // the former instructions generate errata on LEON processors.
1829  }
1830 
1831  if (Subtarget->replaceFMULS()) {
1832  // Promote FMULS to FMULD instructions instead as
1833  // the former instructions generate errata on LEON processors.
1835  }
1836 
1838 
1840 
1842 }
1843 
1845  return Subtarget->useSoftFloat();
1846 }
1847 
1848 const char *SparcTargetLowering::getTargetNodeName(unsigned Opcode) const {
1849  switch ((SPISD::NodeType)Opcode) {
1850  case SPISD::FIRST_NUMBER: break;
1851  case SPISD::CMPICC: return "SPISD::CMPICC";
1852  case SPISD::CMPFCC: return "SPISD::CMPFCC";
1853  case SPISD::BRICC: return "SPISD::BRICC";
1854  case SPISD::BRXCC: return "SPISD::BRXCC";
1855  case SPISD::BRFCC: return "SPISD::BRFCC";
1856  case SPISD::SELECT_ICC: return "SPISD::SELECT_ICC";
1857  case SPISD::SELECT_XCC: return "SPISD::SELECT_XCC";
1858  case SPISD::SELECT_FCC: return "SPISD::SELECT_FCC";
1859  case SPISD::EH_SJLJ_SETJMP: return "SPISD::EH_SJLJ_SETJMP";
1860  case SPISD::EH_SJLJ_LONGJMP: return "SPISD::EH_SJLJ_LONGJMP";
1861  case SPISD::Hi: return "SPISD::Hi";
1862  case SPISD::Lo: return "SPISD::Lo";
1863  case SPISD::FTOI: return "SPISD::FTOI";
1864  case SPISD::ITOF: return "SPISD::ITOF";
1865  case SPISD::FTOX: return "SPISD::FTOX";
1866  case SPISD::XTOF: return "SPISD::XTOF";
1867  case SPISD::CALL: return "SPISD::CALL";
1868  case SPISD::RET_FLAG: return "SPISD::RET_FLAG";
1869  case SPISD::GLOBAL_BASE_REG: return "SPISD::GLOBAL_BASE_REG";
1870  case SPISD::FLUSHW: return "SPISD::FLUSHW";
1871  case SPISD::TLS_ADD: return "SPISD::TLS_ADD";
1872  case SPISD::TLS_LD: return "SPISD::TLS_LD";
1873  case SPISD::TLS_CALL: return "SPISD::TLS_CALL";
1874  }
1875  return nullptr;
1876 }
1877 
1879  EVT VT) const {
1880  if (!VT.isVector())
1881  return MVT::i32;
1883 }
1884 
1885 /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
1886 /// be zero. Op is expected to be a target specific node. Used by DAG
1887 /// combiner.
1889  (const SDValue Op,
1890  KnownBits &Known,
1891  const APInt &DemandedElts,
1892  const SelectionDAG &DAG,
1893  unsigned Depth) const {
1894  KnownBits Known2;
1895  Known.resetAll();
1896 
1897  switch (Op.getOpcode()) {
1898  default: break;
1899  case SPISD::SELECT_ICC:
1900  case SPISD::SELECT_XCC:
1901  case SPISD::SELECT_FCC:
1902  DAG.computeKnownBits(Op.getOperand(1), Known, Depth+1);
1903  DAG.computeKnownBits(Op.getOperand(0), Known2, Depth+1);
1904 
1905  // Only known if known in both the LHS and RHS.
1906  Known.One &= Known2.One;
1907  Known.Zero &= Known2.Zero;
1908  break;
1909  }
1910 }
1911 
1912 // Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so
1913 // set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
1914 static void LookThroughSetCC(SDValue &LHS, SDValue &RHS,
1915  ISD::CondCode CC, unsigned &SPCC) {
1916  if (isNullConstant(RHS) &&
1917  CC == ISD::SETNE &&
1918  (((LHS.getOpcode() == SPISD::SELECT_ICC ||
1919  LHS.getOpcode() == SPISD::SELECT_XCC) &&
1920  LHS.getOperand(3).getOpcode() == SPISD::CMPICC) ||
1921  (LHS.getOpcode() == SPISD::SELECT_FCC &&
1922  LHS.getOperand(3).getOpcode() == SPISD::CMPFCC)) &&
1923  isOneConstant(LHS.getOperand(0)) &&
1924  isNullConstant(LHS.getOperand(1))) {
1925  SDValue CMPCC = LHS.getOperand(3);
1926  SPCC = cast<ConstantSDNode>(LHS.getOperand(2))->getZExtValue();
1927  LHS = CMPCC.getOperand(0);
1928  RHS = CMPCC.getOperand(1);
1929  }
1930 }
1931 
1932 // Convert to a target node and set target flags.
1934  SelectionDAG &DAG) const {
1935  if (const GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Op))
1936  return DAG.getTargetGlobalAddress(GA->getGlobal(),
1937  SDLoc(GA),
1938  GA->getValueType(0),
1939  GA->getOffset(), TF);
1940 
1941  if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op))
1942  return DAG.getTargetConstantPool(CP->getConstVal(),
1943  CP->getValueType(0),
1944  CP->getAlignment(),
1945  CP->getOffset(), TF);
1946 
1947  if (const BlockAddressSDNode *BA = dyn_cast<BlockAddressSDNode>(Op))
1948  return DAG.getTargetBlockAddress(BA->getBlockAddress(),
1949  Op.getValueType(),
1950  0,
1951  TF);
1952 
1953  if (const ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op))
1954  return DAG.getTargetExternalSymbol(ES->getSymbol(),
1955  ES->getValueType(0), TF);
1956 
1957  llvm_unreachable("Unhandled address SDNode");
1958 }
1959 
1960 // Split Op into high and low parts according to HiTF and LoTF.
1961 // Return an ADD node combining the parts.
1963  unsigned HiTF, unsigned LoTF,
1964  SelectionDAG &DAG) const {
1965  SDLoc DL(Op);
1966  EVT VT = Op.getValueType();
1967  SDValue Hi = DAG.getNode(SPISD::Hi, DL, VT, withTargetFlags(Op, HiTF, DAG));
1968  SDValue Lo = DAG.getNode(SPISD::Lo, DL, VT, withTargetFlags(Op, LoTF, DAG));
1969  return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
1970 }
1971 
1972 // Build SDNodes for producing an address from a GlobalAddress, ConstantPool,
1973 // or ExternalSymbol SDNode.
1975  SDLoc DL(Op);
1976  EVT VT = getPointerTy(DAG.getDataLayout());
1977 
1978  // Handle PIC mode first. SPARC needs a got load for every variable!
1979  if (isPositionIndependent()) {
1980  // This is the pic32 code model, the GOT is known to be smaller than 4GB.
1983  SDValue GlobalBase = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, VT);
1984  SDValue AbsAddr = DAG.getNode(ISD::ADD, DL, VT, GlobalBase, HiLo);
1985  // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
1986  // function has calls.
1988  MFI.setHasCalls(true);
1989  return DAG.getLoad(VT, DL, DAG.getEntryNode(), AbsAddr,
1991  }
1992 
1993  // This is one of the absolute code models.
1994  switch(getTargetMachine().getCodeModel()) {
1995  default:
1996  llvm_unreachable("Unsupported absolute code model");
1997  case CodeModel::Small:
1998  // abs32.
2001  case CodeModel::Medium: {
2002  // abs44.
2005  H44 = DAG.getNode(ISD::SHL, DL, VT, H44, DAG.getConstant(12, DL, MVT::i32));
2007  L44 = DAG.getNode(SPISD::Lo, DL, VT, L44);
2008  return DAG.getNode(ISD::ADD, DL, VT, H44, L44);
2009  }
2010  case CodeModel::Large: {
2011  // abs64.
2014  Hi = DAG.getNode(ISD::SHL, DL, VT, Hi, DAG.getConstant(32, DL, MVT::i32));
2017  return DAG.getNode(ISD::ADD, DL, VT, Hi, Lo);
2018  }
2019  }
2020 }
2021 
2023  SelectionDAG &DAG) const {
2024  return makeAddress(Op, DAG);
2025 }
2026 
2028  SelectionDAG &DAG) const {
2029  return makeAddress(Op, DAG);
2030 }
2031 
2033  SelectionDAG &DAG) const {
2034  return makeAddress(Op, DAG);
2035 }
2036 
2038  SelectionDAG &DAG) const {
2039 
2040  GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
2041  if (DAG.getTarget().Options.EmulatedTLS)
2042  return LowerToTLSEmulatedModel(GA, DAG);
2043 
2044  SDLoc DL(GA);
2045  const GlobalValue *GV = GA->getGlobal();
2046  EVT PtrVT = getPointerTy(DAG.getDataLayout());
2047 
2049 
2050  if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) {
2051  unsigned HiTF = ((model == TLSModel::GeneralDynamic)
2054  unsigned LoTF = ((model == TLSModel::GeneralDynamic)
2057  unsigned addTF = ((model == TLSModel::GeneralDynamic)
2060  unsigned callTF = ((model == TLSModel::GeneralDynamic)
2063 
2064  SDValue HiLo = makeHiLoPair(Op, HiTF, LoTF, DAG);
2065  SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2066  SDValue Argument = DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Base, HiLo,
2067  withTargetFlags(Op, addTF, DAG));
2068 
2069  SDValue Chain = DAG.getEntryNode();
2070  SDValue InFlag;
2071 
2072  Chain = DAG.getCALLSEQ_START(Chain, 1, 0, DL);
2073  Chain = DAG.getCopyToReg(Chain, DL, SP::O0, Argument, InFlag);
2074  InFlag = Chain.getValue(1);
2075  SDValue Callee = DAG.getTargetExternalSymbol("__tls_get_addr", PtrVT);
2076  SDValue Symbol = withTargetFlags(Op, callTF, DAG);
2077 
2078  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
2079  const uint32_t *Mask = Subtarget->getRegisterInfo()->getCallPreservedMask(
2081  assert(Mask && "Missing call preserved mask for calling convention");
2082  SDValue Ops[] = {Chain,
2083  Callee,
2084  Symbol,
2085  DAG.getRegister(SP::O0, PtrVT),
2086  DAG.getRegisterMask(Mask),
2087  InFlag};
2088  Chain = DAG.getNode(SPISD::TLS_CALL, DL, NodeTys, Ops);
2089  InFlag = Chain.getValue(1);
2090  Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(1, DL, true),
2091  DAG.getIntPtrConstant(0, DL, true), InFlag, DL);
2092  InFlag = Chain.getValue(1);
2093  SDValue Ret = DAG.getCopyFromReg(Chain, DL, SP::O0, PtrVT, InFlag);
2094 
2095  if (model != TLSModel::LocalDynamic)
2096  return Ret;
2097 
2098  SDValue Hi = DAG.getNode(SPISD::Hi, DL, PtrVT,
2100  SDValue Lo = DAG.getNode(SPISD::Lo, DL, PtrVT,
2102  HiLo = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2103  return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT, Ret, HiLo,
2105  }
2106 
2107  if (model == TLSModel::InitialExec) {
2108  unsigned ldTF = ((PtrVT == MVT::i64)? SparcMCExpr::VK_Sparc_TLS_IE_LDX
2110 
2111  SDValue Base = DAG.getNode(SPISD::GLOBAL_BASE_REG, DL, PtrVT);
2112 
2113  // GLOBAL_BASE_REG codegen'ed with call. Inform MFI that this
2114  // function has calls.
2116  MFI.setHasCalls(true);
2117 
2118  SDValue TGA = makeHiLoPair(Op,
2121  SDValue Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Base, TGA);
2123  DL, PtrVT, Ptr,
2124  withTargetFlags(Op, ldTF, DAG));
2125  return DAG.getNode(SPISD::TLS_ADD, DL, PtrVT,
2126  DAG.getRegister(SP::G7, PtrVT), Offset,
2127  withTargetFlags(Op,
2129  }
2130 
2131  assert(model == TLSModel::LocalExec);
2132  SDValue Hi = DAG.getNode(SPISD::Hi, DL, PtrVT,
2134  SDValue Lo = DAG.getNode(SPISD::Lo, DL, PtrVT,
2136  SDValue Offset = DAG.getNode(ISD::XOR, DL, PtrVT, Hi, Lo);
2137 
2138  return DAG.getNode(ISD::ADD, DL, PtrVT,
2139  DAG.getRegister(SP::G7, PtrVT), Offset);
2140 }
2141 
2143  ArgListTy &Args, SDValue Arg,
2144  const SDLoc &DL,
2145  SelectionDAG &DAG) const {
2147  EVT ArgVT = Arg.getValueType();
2148  Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
2149 
2150  ArgListEntry Entry;
2151  Entry.Node = Arg;
2152  Entry.Ty = ArgTy;
2153 
2154  if (ArgTy->isFP128Ty()) {
2155  // Create a stack object and pass the pointer to the library function.
2156  int FI = MFI.CreateStackObject(16, 8, false);
2157  SDValue FIPtr = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
2158  Chain = DAG.getStore(Chain, DL, Entry.Node, FIPtr, MachinePointerInfo(),
2159  /* Alignment = */ 8);
2160 
2161  Entry.Node = FIPtr;
2162  Entry.Ty = PointerType::getUnqual(ArgTy);
2163  }
2164  Args.push_back(Entry);
2165  return Chain;
2166 }
2167 
2168 SDValue
2170  const char *LibFuncName,
2171  unsigned numArgs) const {
2172 
2173  ArgListTy Args;
2174 
2176  auto PtrVT = getPointerTy(DAG.getDataLayout());
2177 
2178  SDValue Callee = DAG.getExternalSymbol(LibFuncName, PtrVT);
2179  Type *RetTy = Op.getValueType().getTypeForEVT(*DAG.getContext());
2180  Type *RetTyABI = RetTy;
2181  SDValue Chain = DAG.getEntryNode();
2182  SDValue RetPtr;
2183 
2184  if (RetTy->isFP128Ty()) {
2185  // Create a Stack Object to receive the return value of type f128.
2186  ArgListEntry Entry;
2187  int RetFI = MFI.CreateStackObject(16, 8, false);
2188  RetPtr = DAG.getFrameIndex(RetFI, PtrVT);
2189  Entry.Node = RetPtr;
2190  Entry.Ty = PointerType::getUnqual(RetTy);
2191  if (!Subtarget->is64Bit())
2192  Entry.IsSRet = true;
2193  Entry.IsReturned = false;
2194  Args.push_back(Entry);
2195  RetTyABI = Type::getVoidTy(*DAG.getContext());
2196  }
2197 
2198  assert(Op->getNumOperands() >= numArgs && "Not enough operands!");
2199  for (unsigned i = 0, e = numArgs; i != e; ++i) {
2200  Chain = LowerF128_LibCallArg(Chain, Args, Op.getOperand(i), SDLoc(Op), DAG);
2201  }
2203  CLI.setDebugLoc(SDLoc(Op)).setChain(Chain)
2204  .setCallee(CallingConv::C, RetTyABI, Callee, std::move(Args));
2205 
2206  std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2207 
2208  // chain is in second result.
2209  if (RetTyABI == RetTy)
2210  return CallInfo.first;
2211 
2212  assert (RetTy->isFP128Ty() && "Unexpected return type!");
2213 
2214  Chain = CallInfo.second;
2215 
2216  // Load RetPtr to get the return value.
2217  return DAG.getLoad(Op.getValueType(), SDLoc(Op), Chain, RetPtr,
2218  MachinePointerInfo(), /* Alignment = */ 8);
2219 }
2220 
2222  unsigned &SPCC, const SDLoc &DL,
2223  SelectionDAG &DAG) const {
2224 
2225  const char *LibCall = nullptr;
2226  bool is64Bit = Subtarget->is64Bit();
2227  switch(SPCC) {
2228  default: llvm_unreachable("Unhandled conditional code!");
2229  case SPCC::FCC_E : LibCall = is64Bit? "_Qp_feq" : "_Q_feq"; break;
2230  case SPCC::FCC_NE : LibCall = is64Bit? "_Qp_fne" : "_Q_fne"; break;
2231  case SPCC::FCC_L : LibCall = is64Bit? "_Qp_flt" : "_Q_flt"; break;
2232  case SPCC::FCC_G : LibCall = is64Bit? "_Qp_fgt" : "_Q_fgt"; break;
2233  case SPCC::FCC_LE : LibCall = is64Bit? "_Qp_fle" : "_Q_fle"; break;
2234  case SPCC::FCC_GE : LibCall = is64Bit? "_Qp_fge" : "_Q_fge"; break;
2235  case SPCC::FCC_UL :
2236  case SPCC::FCC_ULE:
2237  case SPCC::FCC_UG :
2238  case SPCC::FCC_UGE:
2239  case SPCC::FCC_U :
2240  case SPCC::FCC_O :
2241  case SPCC::FCC_LG :
2242  case SPCC::FCC_UE : LibCall = is64Bit? "_Qp_cmp" : "_Q_cmp"; break;
2243  }
2244 
2245  auto PtrVT = getPointerTy(DAG.getDataLayout());
2246  SDValue Callee = DAG.getExternalSymbol(LibCall, PtrVT);
2247  Type *RetTy = Type::getInt32Ty(*DAG.getContext());
2248  ArgListTy Args;
2249  SDValue Chain = DAG.getEntryNode();
2250  Chain = LowerF128_LibCallArg(Chain, Args, LHS, DL, DAG);
2251  Chain = LowerF128_LibCallArg(Chain, Args, RHS, DL, DAG);
2252 
2254  CLI.setDebugLoc(DL).setChain(Chain)
2255  .setCallee(CallingConv::C, RetTy, Callee, std::move(Args));
2256 
2257  std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
2258 
2259  // result is in first, and chain is in second result.
2260  SDValue Result = CallInfo.first;
2261 
2262  switch(SPCC) {
2263  default: {
2264  SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
2265  SPCC = SPCC::ICC_NE;
2266  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2267  }
2268  case SPCC::FCC_UL : {
2269  SDValue Mask = DAG.getTargetConstant(1, DL, Result.getValueType());
2270  Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2271  SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
2272  SPCC = SPCC::ICC_NE;
2273  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2274  }
2275  case SPCC::FCC_ULE: {
2276  SDValue RHS = DAG.getTargetConstant(2, DL, Result.getValueType());
2277  SPCC = SPCC::ICC_NE;
2278  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2279  }
2280  case SPCC::FCC_UG : {
2281  SDValue RHS = DAG.getTargetConstant(1, DL, Result.getValueType());
2282  SPCC = SPCC::ICC_G;
2283  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2284  }
2285  case SPCC::FCC_UGE: {
2286  SDValue RHS = DAG.getTargetConstant(1, DL, Result.getValueType());
2287  SPCC = SPCC::ICC_NE;
2288  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2289  }
2290 
2291  case SPCC::FCC_U : {
2292  SDValue RHS = DAG.getTargetConstant(3, DL, Result.getValueType());
2293  SPCC = SPCC::ICC_E;
2294  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2295  }
2296  case SPCC::FCC_O : {
2297  SDValue RHS = DAG.getTargetConstant(3, DL, Result.getValueType());
2298  SPCC = SPCC::ICC_NE;
2299  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2300  }
2301  case SPCC::FCC_LG : {
2302  SDValue Mask = DAG.getTargetConstant(3, DL, Result.getValueType());
2303  Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2304  SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
2305  SPCC = SPCC::ICC_NE;
2306  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2307  }
2308  case SPCC::FCC_UE : {
2309  SDValue Mask = DAG.getTargetConstant(3, DL, Result.getValueType());
2310  Result = DAG.getNode(ISD::AND, DL, Result.getValueType(), Result, Mask);
2311  SDValue RHS = DAG.getTargetConstant(0, DL, Result.getValueType());
2312  SPCC = SPCC::ICC_E;
2313  return DAG.getNode(SPISD::CMPICC, DL, MVT::Glue, Result, RHS);
2314  }
2315  }
2316 }
2317 
2318 static SDValue
2320  const SparcTargetLowering &TLI) {
2321 
2322  if (Op.getOperand(0).getValueType() == MVT::f64)
2323  return TLI.LowerF128Op(Op, DAG,
2325 
2326  if (Op.getOperand(0).getValueType() == MVT::f32)
2327  return TLI.LowerF128Op(Op, DAG,
2329 
2330  llvm_unreachable("fpextend with non-float operand!");
2331  return SDValue();
2332 }
2333 
2334 static SDValue
2336  const SparcTargetLowering &TLI) {
2337  // FP_ROUND on f64 and f32 are legal.
2338  if (Op.getOperand(0).getValueType() != MVT::f128)
2339  return Op;
2340 
2341  if (Op.getValueType() == MVT::f64)
2342  return TLI.LowerF128Op(Op, DAG,
2344  if (Op.getValueType() == MVT::f32)
2345  return TLI.LowerF128Op(Op, DAG,
2347 
2348  llvm_unreachable("fpround to non-float!");
2349  return SDValue();
2350 }
2351 
2353  const SparcTargetLowering &TLI,
2354  bool hasHardQuad) {
2355  SDLoc dl(Op);
2356  EVT VT = Op.getValueType();
2357  assert(VT == MVT::i32 || VT == MVT::i64);
2358 
2359  // Expand f128 operations to fp128 abi calls.
2360  if (Op.getOperand(0).getValueType() == MVT::f128
2361  && (!hasHardQuad || !TLI.isTypeLegal(VT))) {
2362  const char *libName = TLI.getLibcallName(VT == MVT::i32
2365  return TLI.LowerF128Op(Op, DAG, libName, 1);
2366  }
2367 
2368  // Expand if the resulting type is illegal.
2369  if (!TLI.isTypeLegal(VT))
2370  return SDValue();
2371 
2372  // Otherwise, Convert the fp value to integer in an FP register.
2373  if (VT == MVT::i32)
2374  Op = DAG.getNode(SPISD::FTOI, dl, MVT::f32, Op.getOperand(0));
2375  else
2376  Op = DAG.getNode(SPISD::FTOX, dl, MVT::f64, Op.getOperand(0));
2377 
2378  return DAG.getNode(ISD::BITCAST, dl, VT, Op);
2379 }
2380 
2382  const SparcTargetLowering &TLI,
2383  bool hasHardQuad) {
2384  SDLoc dl(Op);
2385  EVT OpVT = Op.getOperand(0).getValueType();
2386  assert(OpVT == MVT::i32 || (OpVT == MVT::i64));
2387 
2388  EVT floatVT = (OpVT == MVT::i32) ? MVT::f32 : MVT::f64;
2389 
2390  // Expand f128 operations to fp128 ABI calls.
2391  if (Op.getValueType() == MVT::f128
2392  && (!hasHardQuad || !TLI.isTypeLegal(OpVT))) {
2393  const char *libName = TLI.getLibcallName(OpVT == MVT::i32
2396  return TLI.LowerF128Op(Op, DAG, libName, 1);
2397  }
2398 
2399  // Expand if the operand type is illegal.
2400  if (!TLI.isTypeLegal(OpVT))
2401  return SDValue();
2402 
2403  // Otherwise, Convert the int value to FP in an FP register.
2404  SDValue Tmp = DAG.getNode(ISD::BITCAST, dl, floatVT, Op.getOperand(0));
2405  unsigned opcode = (OpVT == MVT::i32)? SPISD::ITOF : SPISD::XTOF;
2406  return DAG.getNode(opcode, dl, Op.getValueType(), Tmp);
2407 }
2408 
2410  const SparcTargetLowering &TLI,
2411  bool hasHardQuad) {
2412  SDLoc dl(Op);
2413  EVT VT = Op.getValueType();
2414 
2415  // Expand if it does not involve f128 or the target has support for
2416  // quad floating point instructions and the resulting type is legal.
2417  if (Op.getOperand(0).getValueType() != MVT::f128 ||
2418  (hasHardQuad && TLI.isTypeLegal(VT)))
2419  return SDValue();
2420 
2421  assert(VT == MVT::i32 || VT == MVT::i64);
2422 
2423  return TLI.LowerF128Op(Op, DAG,
2424  TLI.getLibcallName(VT == MVT::i32
2427  1);
2428 }
2429 
2431  const SparcTargetLowering &TLI,
2432  bool hasHardQuad) {
2433  SDLoc dl(Op);
2434  EVT OpVT = Op.getOperand(0).getValueType();
2435  assert(OpVT == MVT::i32 || OpVT == MVT::i64);
2436 
2437  // Expand if it does not involve f128 or the target has support for
2438  // quad floating point instructions and the operand type is legal.
2439  if (Op.getValueType() != MVT::f128 || (hasHardQuad && TLI.isTypeLegal(OpVT)))
2440  return SDValue();
2441 
2442  return TLI.LowerF128Op(Op, DAG,
2443  TLI.getLibcallName(OpVT == MVT::i32
2446  1);
2447 }
2448 
2450  const SparcTargetLowering &TLI,
2451  bool hasHardQuad) {
2452  SDValue Chain = Op.getOperand(0);
2453  ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
2454  SDValue LHS = Op.getOperand(2);
2455  SDValue RHS = Op.getOperand(3);
2456  SDValue Dest = Op.getOperand(4);
2457  SDLoc dl(Op);
2458  unsigned Opc, SPCC = ~0U;
2459 
2460  // If this is a br_cc of a "setcc", and if the setcc got lowered into
2461  // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
2462  LookThroughSetCC(LHS, RHS, CC, SPCC);
2463 
2464  // Get the condition flag.
2465  SDValue CompareFlag;
2466  if (LHS.getValueType().isInteger()) {
2467  CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
2468  if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
2469  // 32-bit compares use the icc flags, 64-bit uses the xcc flags.
2470  Opc = LHS.getValueType() == MVT::i32 ? SPISD::BRICC : SPISD::BRXCC;
2471  } else {
2472  if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
2473  if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2474  CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
2475  Opc = SPISD::BRICC;
2476  } else {
2477  CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Glue, LHS, RHS);
2478  if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2479  Opc = SPISD::BRFCC;
2480  }
2481  }
2482  return DAG.getNode(Opc, dl, MVT::Other, Chain, Dest,
2483  DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
2484 }
2485 
2487  const SparcTargetLowering &TLI,
2488  bool hasHardQuad) {
2489  SDValue LHS = Op.getOperand(0);
2490  SDValue RHS = Op.getOperand(1);
2491  ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
2492  SDValue TrueVal = Op.getOperand(2);
2493  SDValue FalseVal = Op.getOperand(3);
2494  SDLoc dl(Op);
2495  unsigned Opc, SPCC = ~0U;
2496 
2497  // If this is a select_cc of a "setcc", and if the setcc got lowered into
2498  // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
2499  LookThroughSetCC(LHS, RHS, CC, SPCC);
2500 
2501  SDValue CompareFlag;
2502  if (LHS.getValueType().isInteger()) {
2503  CompareFlag = DAG.getNode(SPISD::CMPICC, dl, MVT::Glue, LHS, RHS);
2504  Opc = LHS.getValueType() == MVT::i32 ?
2506  if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
2507  } else {
2508  if (!hasHardQuad && LHS.getValueType() == MVT::f128) {
2509  if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2510  CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
2511  Opc = SPISD::SELECT_ICC;
2512  } else {
2513  CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Glue, LHS, RHS);
2514  Opc = SPISD::SELECT_FCC;
2515  if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2516  }
2517  }
2518  return DAG.getNode(Opc, dl, TrueVal.getValueType(), TrueVal, FalseVal,
2519  DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
2520 }
2521 
2523  const SparcTargetLowering &TLI) const {
2524  SDLoc DL(Op);
2525  return DAG.getNode(SPISD::EH_SJLJ_SETJMP, DL,
2526  DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), Op.getOperand(1));
2527 
2528 }
2529 
2531  const SparcTargetLowering &TLI) const {
2532  SDLoc DL(Op);
2533  return DAG.getNode(SPISD::EH_SJLJ_LONGJMP, DL, MVT::Other, Op.getOperand(0), Op.getOperand(1));
2534 }
2535 
2537  const SparcTargetLowering &TLI) {
2538  MachineFunction &MF = DAG.getMachineFunction();
2540  auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
2541 
2542  // Need frame address to find the address of VarArgsFrameIndex.
2544 
2545  // vastart just stores the address of the VarArgsFrameIndex slot into the
2546  // memory location argument.
2547  SDLoc DL(Op);
2548  SDValue Offset =
2549  DAG.getNode(ISD::ADD, DL, PtrVT, DAG.getRegister(SP::I6, PtrVT),
2550  DAG.getIntPtrConstant(FuncInfo->getVarArgsFrameOffset(), DL));
2551  const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
2552  return DAG.getStore(Op.getOperand(0), DL, Offset, Op.getOperand(1),
2553  MachinePointerInfo(SV));
2554 }
2555 
2557  SDNode *Node = Op.getNode();
2558  EVT VT = Node->getValueType(0);
2559  SDValue InChain = Node->getOperand(0);
2560  SDValue VAListPtr = Node->getOperand(1);
2561  EVT PtrVT = VAListPtr.getValueType();
2562  const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
2563  SDLoc DL(Node);
2564  SDValue VAList =
2565  DAG.getLoad(PtrVT, DL, InChain, VAListPtr, MachinePointerInfo(SV));
2566  // Increment the pointer, VAList, to the next vaarg.
2567  SDValue NextPtr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
2568  DAG.getIntPtrConstant(VT.getSizeInBits()/8,
2569  DL));
2570  // Store the incremented VAList to the legalized pointer.
2571  InChain = DAG.getStore(VAList.getValue(1), DL, NextPtr, VAListPtr,
2572  MachinePointerInfo(SV));
2573  // Load the actual argument out of the pointer VAList.
2574  // We can't count on greater alignment than the word size.
2575  return DAG.getLoad(VT, DL, InChain, VAList, MachinePointerInfo(),
2576  std::min(PtrVT.getSizeInBits(), VT.getSizeInBits()) / 8);
2577 }
2578 
2580  const SparcSubtarget *Subtarget) {
2581  SDValue Chain = Op.getOperand(0); // Legalize the chain.
2582  SDValue Size = Op.getOperand(1); // Legalize the size.
2583  unsigned Align = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue();
2584  unsigned StackAlign = Subtarget->getFrameLowering()->getStackAlignment();
2585  EVT VT = Size->getValueType(0);
2586  SDLoc dl(Op);
2587 
2588  // TODO: implement over-aligned alloca. (Note: also implies
2589  // supporting support for overaligned function frames + dynamic
2590  // allocations, at all, which currently isn't supported)
2591  if (Align > StackAlign) {
2592  const MachineFunction &MF = DAG.getMachineFunction();
2593  report_fatal_error("Function \"" + Twine(MF.getName()) + "\": "
2594  "over-aligned dynamic alloca not supported.");
2595  }
2596 
2597  // The resultant pointer needs to be above the register spill area
2598  // at the bottom of the stack.
2599  unsigned regSpillArea;
2600  if (Subtarget->is64Bit()) {
2601  regSpillArea = 128;
2602  } else {
2603  // On Sparc32, the size of the spill area is 92. Unfortunately,
2604  // that's only 4-byte aligned, not 8-byte aligned (the stack
2605  // pointer is 8-byte aligned). So, if the user asked for an 8-byte
2606  // aligned dynamic allocation, we actually need to add 96 to the
2607  // bottom of the stack, instead of 92, to ensure 8-byte alignment.
2608 
2609  // That also means adding 4 to the size of the allocation --
2610  // before applying the 8-byte rounding. Unfortunately, we the
2611  // value we get here has already had rounding applied. So, we need
2612  // to add 8, instead, wasting a bit more memory.
2613 
2614  // Further, this only actually needs to be done if the required
2615  // alignment is > 4, but, we've lost that info by this point, too,
2616  // so we always apply it.
2617 
2618  // (An alternative approach would be to always reserve 96 bytes
2619  // instead of the required 92, but then we'd waste 4 extra bytes
2620  // in every frame, not just those with dynamic stack allocations)
2621 
2622  // TODO: modify code in SelectionDAGBuilder to make this less sad.
2623 
2624  Size = DAG.getNode(ISD::ADD, dl, VT, Size,
2625  DAG.getConstant(8, dl, VT));
2626  regSpillArea = 96;
2627  }
2628 
2629  unsigned SPReg = SP::O6;
2630  SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
2631  SDValue NewSP = DAG.getNode(ISD::SUB, dl, VT, SP, Size); // Value
2632  Chain = DAG.getCopyToReg(SP.getValue(1), dl, SPReg, NewSP); // Output chain
2633 
2634  regSpillArea += Subtarget->getStackPointerBias();
2635 
2636  SDValue NewVal = DAG.getNode(ISD::ADD, dl, VT, NewSP,
2637  DAG.getConstant(regSpillArea, dl, VT));
2638  SDValue Ops[2] = { NewVal, Chain };
2639  return DAG.getMergeValues(Ops, dl);
2640 }
2641 
2642 
2644  SDLoc dl(Op);
2645  SDValue Chain = DAG.getNode(SPISD::FLUSHW,
2646  dl, MVT::Other, DAG.getEntryNode());
2647  return Chain;
2648 }
2649 
2650 static SDValue getFRAMEADDR(uint64_t depth, SDValue Op, SelectionDAG &DAG,
2651  const SparcSubtarget *Subtarget) {
2653  MFI.setFrameAddressIsTaken(true);
2654 
2655  EVT VT = Op.getValueType();
2656  SDLoc dl(Op);
2657  unsigned FrameReg = SP::I6;
2658  unsigned stackBias = Subtarget->getStackPointerBias();
2659 
2660  SDValue FrameAddr;
2661 
2662  if (depth == 0) {
2663  FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT);
2664  if (Subtarget->is64Bit())
2665  FrameAddr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
2666  DAG.getIntPtrConstant(stackBias, dl));
2667  return FrameAddr;
2668  }
2669 
2670  // flush first to make sure the windowed registers' values are in stack
2671  SDValue Chain = getFLUSHW(Op, DAG);
2672  FrameAddr = DAG.getCopyFromReg(Chain, dl, FrameReg, VT);
2673 
2674  unsigned Offset = (Subtarget->is64Bit()) ? (stackBias + 112) : 56;
2675 
2676  while (depth--) {
2677  SDValue Ptr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
2678  DAG.getIntPtrConstant(Offset, dl));
2679  FrameAddr = DAG.getLoad(VT, dl, Chain, Ptr, MachinePointerInfo());
2680  }
2681  if (Subtarget->is64Bit())
2682  FrameAddr = DAG.getNode(ISD::ADD, dl, VT, FrameAddr,
2683  DAG.getIntPtrConstant(stackBias, dl));
2684  return FrameAddr;
2685 }
2686 
2687 
2689  const SparcSubtarget *Subtarget) {
2690 
2691  uint64_t depth = Op.getConstantOperandVal(0);
2692 
2693  return getFRAMEADDR(depth, Op, DAG, Subtarget);
2694 
2695 }
2696 
2698  const SparcTargetLowering &TLI,
2699  const SparcSubtarget *Subtarget) {
2700  MachineFunction &MF = DAG.getMachineFunction();
2701  MachineFrameInfo &MFI = MF.getFrameInfo();
2702  MFI.setReturnAddressIsTaken(true);
2703 
2704  if (TLI.verifyReturnAddressArgumentIsConstant(Op, DAG))
2705  return SDValue();
2706 
2707  EVT VT = Op.getValueType();
2708  SDLoc dl(Op);
2709  uint64_t depth = Op.getConstantOperandVal(0);
2710 
2711  SDValue RetAddr;
2712  if (depth == 0) {
2713  auto PtrVT = TLI.getPointerTy(DAG.getDataLayout());
2714  unsigned RetReg = MF.addLiveIn(SP::I7, TLI.getRegClassFor(PtrVT));
2715  RetAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, RetReg, VT);
2716  return RetAddr;
2717  }
2718 
2719  // Need frame address to find return address of the caller.
2720  SDValue FrameAddr = getFRAMEADDR(depth - 1, Op, DAG, Subtarget);
2721 
2722  unsigned Offset = (Subtarget->is64Bit()) ? 120 : 60;
2723  SDValue Ptr = DAG.getNode(ISD::ADD,
2724  dl, VT,
2725  FrameAddr,
2726  DAG.getIntPtrConstant(Offset, dl));
2727  RetAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), Ptr, MachinePointerInfo());
2728 
2729  return RetAddr;
2730 }
2731 
2732 static SDValue LowerF64Op(SDValue SrcReg64, const SDLoc &dl, SelectionDAG &DAG,
2733  unsigned opcode) {
2734  assert(SrcReg64.getValueType() == MVT::f64 && "LowerF64Op called on non-double!");
2735  assert(opcode == ISD::FNEG || opcode == ISD::FABS);
2736 
2737  // Lower fneg/fabs on f64 to fneg/fabs on f32.
2738  // fneg f64 => fneg f32:sub_even, fmov f32:sub_odd.
2739  // fabs f64 => fabs f32:sub_even, fmov f32:sub_odd.
2740 
2741  // Note: in little-endian, the floating-point value is stored in the
2742  // registers are in the opposite order, so the subreg with the sign
2743  // bit is the highest-numbered (odd), rather than the
2744  // lowest-numbered (even).
2745 
2746  SDValue Hi32 = DAG.getTargetExtractSubreg(SP::sub_even, dl, MVT::f32,
2747  SrcReg64);
2748  SDValue Lo32 = DAG.getTargetExtractSubreg(SP::sub_odd, dl, MVT::f32,
2749  SrcReg64);
2750 
2751  if (DAG.getDataLayout().isLittleEndian())
2752  Lo32 = DAG.getNode(opcode, dl, MVT::f32, Lo32);
2753  else
2754  Hi32 = DAG.getNode(opcode, dl, MVT::f32, Hi32);
2755 
2756  SDValue DstReg64 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
2757  dl, MVT::f64), 0);
2758  DstReg64 = DAG.getTargetInsertSubreg(SP::sub_even, dl, MVT::f64,
2759  DstReg64, Hi32);
2760  DstReg64 = DAG.getTargetInsertSubreg(SP::sub_odd, dl, MVT::f64,
2761  DstReg64, Lo32);
2762  return DstReg64;
2763 }
2764 
2765 // Lower a f128 load into two f64 loads.
2767 {
2768  SDLoc dl(Op);
2769  LoadSDNode *LdNode = dyn_cast<LoadSDNode>(Op.getNode());
2770  assert(LdNode && LdNode->getOffset().isUndef()
2771  && "Unexpected node type");
2772 
2773  unsigned alignment = LdNode->getAlignment();
2774  if (alignment > 8)
2775  alignment = 8;
2776 
2777  SDValue Hi64 =
2778  DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LdNode->getBasePtr(),
2779  LdNode->getPointerInfo(), alignment);
2780  EVT addrVT = LdNode->getBasePtr().getValueType();
2781  SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
2782  LdNode->getBasePtr(),
2783  DAG.getConstant(8, dl, addrVT));
2784  SDValue Lo64 = DAG.getLoad(MVT::f64, dl, LdNode->getChain(), LoPtr,
2785  LdNode->getPointerInfo(), alignment);
2786 
2787  SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
2788  SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
2789 
2790  SDNode *InFP128 = DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
2791  dl, MVT::f128);
2792  InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
2793  MVT::f128,
2794  SDValue(InFP128, 0),
2795  Hi64,
2796  SubRegEven);
2797  InFP128 = DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
2798  MVT::f128,
2799  SDValue(InFP128, 0),
2800  Lo64,
2801  SubRegOdd);
2802  SDValue OutChains[2] = { SDValue(Hi64.getNode(), 1),
2803  SDValue(Lo64.getNode(), 1) };
2804  SDValue OutChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
2805  SDValue Ops[2] = {SDValue(InFP128,0), OutChain};
2806  return DAG.getMergeValues(Ops, dl);
2807 }
2808 
2810 {
2811  LoadSDNode *LdNode = cast<LoadSDNode>(Op.getNode());
2812 
2813  EVT MemVT = LdNode->getMemoryVT();
2814  if (MemVT == MVT::f128)
2815  return LowerF128Load(Op, DAG);
2816 
2817  return Op;
2818 }
2819 
2820 // Lower a f128 store into two f64 stores.
2822  SDLoc dl(Op);
2823  StoreSDNode *StNode = dyn_cast<StoreSDNode>(Op.getNode());
2824  assert(StNode && StNode->getOffset().isUndef()
2825  && "Unexpected node type");
2826  SDValue SubRegEven = DAG.getTargetConstant(SP::sub_even64, dl, MVT::i32);
2827  SDValue SubRegOdd = DAG.getTargetConstant(SP::sub_odd64, dl, MVT::i32);
2828 
2829  SDNode *Hi64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2830  dl,
2831  MVT::f64,
2832  StNode->getValue(),
2833  SubRegEven);
2834  SDNode *Lo64 = DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG,
2835  dl,
2836  MVT::f64,
2837  StNode->getValue(),
2838  SubRegOdd);
2839 
2840  unsigned alignment = StNode->getAlignment();
2841  if (alignment > 8)
2842  alignment = 8;
2843 
2844  SDValue OutChains[2];
2845  OutChains[0] =
2846  DAG.getStore(StNode->getChain(), dl, SDValue(Hi64, 0),
2847  StNode->getBasePtr(), MachinePointerInfo(), alignment);
2848  EVT addrVT = StNode->getBasePtr().getValueType();
2849  SDValue LoPtr = DAG.getNode(ISD::ADD, dl, addrVT,
2850  StNode->getBasePtr(),
2851  DAG.getConstant(8, dl, addrVT));
2852  OutChains[1] = DAG.getStore(StNode->getChain(), dl, SDValue(Lo64, 0), LoPtr,
2853  MachinePointerInfo(), alignment);
2854  return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
2855 }
2856 
2858 {
2859  SDLoc dl(Op);
2860  StoreSDNode *St = cast<StoreSDNode>(Op.getNode());
2861 
2862  EVT MemVT = St->getMemoryVT();
2863  if (MemVT == MVT::f128)
2864  return LowerF128Store(Op, DAG);
2865 
2866  if (MemVT == MVT::i64) {
2867  // Custom handling for i64 stores: turn it into a bitcast and a
2868  // v2i32 store.
2869  SDValue Val = DAG.getNode(ISD::BITCAST, dl, MVT::v2i32, St->getValue());
2870  SDValue Chain = DAG.getStore(
2871  St->getChain(), dl, Val, St->getBasePtr(), St->getPointerInfo(),
2872  St->getAlignment(), St->getMemOperand()->getFlags(), St->getAAInfo());
2873  return Chain;
2874  }
2875 
2876  return SDValue();
2877 }
2878 
2879 static SDValue LowerFNEGorFABS(SDValue Op, SelectionDAG &DAG, bool isV9) {
2880  assert((Op.getOpcode() == ISD::FNEG || Op.getOpcode() == ISD::FABS)
2881  && "invalid opcode");
2882 
2883  SDLoc dl(Op);
2884 
2885  if (Op.getValueType() == MVT::f64)
2886  return LowerF64Op(Op.getOperand(0), dl, DAG, Op.getOpcode());
2887  if (Op.getValueType() != MVT::f128)
2888  return Op;
2889 
2890  // Lower fabs/fneg on f128 to fabs/fneg on f64
2891  // fabs/fneg f128 => fabs/fneg f64:sub_even64, fmov f64:sub_odd64
2892  // (As with LowerF64Op, on little-endian, we need to negate the odd
2893  // subreg)
2894 
2895  SDValue SrcReg128 = Op.getOperand(0);
2896  SDValue Hi64 = DAG.getTargetExtractSubreg(SP::sub_even64, dl, MVT::f64,
2897  SrcReg128);
2898  SDValue Lo64 = DAG.getTargetExtractSubreg(SP::sub_odd64, dl, MVT::f64,
2899  SrcReg128);
2900 
2901  if (DAG.getDataLayout().isLittleEndian()) {
2902  if (isV9)
2903  Lo64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Lo64);
2904  else
2905  Lo64 = LowerF64Op(Lo64, dl, DAG, Op.getOpcode());
2906  } else {
2907  if (isV9)
2908  Hi64 = DAG.getNode(Op.getOpcode(), dl, MVT::f64, Hi64);
2909  else
2910  Hi64 = LowerF64Op(Hi64, dl, DAG, Op.getOpcode());
2911  }
2912 
2913  SDValue DstReg128 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
2914  dl, MVT::f128), 0);
2915  DstReg128 = DAG.getTargetInsertSubreg(SP::sub_even64, dl, MVT::f128,
2916  DstReg128, Hi64);
2917  DstReg128 = DAG.getTargetInsertSubreg(SP::sub_odd64, dl, MVT::f128,
2918  DstReg128, Lo64);
2919  return DstReg128;
2920 }
2921 
2923 
2924  if (Op.getValueType() != MVT::i64)
2925  return Op;
2926 
2927  SDLoc dl(Op);
2928  SDValue Src1 = Op.getOperand(0);
2929  SDValue Src1Lo = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src1);
2930  SDValue Src1Hi = DAG.getNode(ISD::SRL, dl, MVT::i64, Src1,
2931  DAG.getConstant(32, dl, MVT::i64));
2932  Src1Hi = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src1Hi);
2933 
2934  SDValue Src2 = Op.getOperand(1);
2935  SDValue Src2Lo = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src2);
2936  SDValue Src2Hi = DAG.getNode(ISD::SRL, dl, MVT::i64, Src2,
2937  DAG.getConstant(32, dl, MVT::i64));
2938  Src2Hi = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src2Hi);
2939 
2940 
2941  bool hasChain = false;
2942  unsigned hiOpc = Op.getOpcode();
2943  switch (Op.getOpcode()) {
2944  default: llvm_unreachable("Invalid opcode");
2945  case ISD::ADDC: hiOpc = ISD::ADDE; break;
2946  case ISD::ADDE: hasChain = true; break;
2947  case ISD::SUBC: hiOpc = ISD::SUBE; break;
2948  case ISD::SUBE: hasChain = true; break;
2949  }
2950  SDValue Lo;
2951  SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Glue);
2952  if (hasChain) {
2953  Lo = DAG.getNode(Op.getOpcode(), dl, VTs, Src1Lo, Src2Lo,
2954  Op.getOperand(2));
2955  } else {
2956  Lo = DAG.getNode(Op.getOpcode(), dl, VTs, Src1Lo, Src2Lo);
2957  }
2958  SDValue Hi = DAG.getNode(hiOpc, dl, VTs, Src1Hi, Src2Hi, Lo.getValue(1));
2959  SDValue Carry = Hi.getValue(1);
2960 
2961  Lo = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, Lo);
2962  Hi = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, Hi);
2963  Hi = DAG.getNode(ISD::SHL, dl, MVT::i64, Hi,
2964  DAG.getConstant(32, dl, MVT::i64));
2965 
2966  SDValue Dst = DAG.getNode(ISD::OR, dl, MVT::i64, Hi, Lo);
2967  SDValue Ops[2] = { Dst, Carry };
2968  return DAG.getMergeValues(Ops, dl);
2969 }
2970 
2971 // Custom lower UMULO/SMULO for SPARC. This code is similar to ExpandNode()
2972 // in LegalizeDAG.cpp except the order of arguments to the library function.
2974  const SparcTargetLowering &TLI)
2975 {
2976  unsigned opcode = Op.getOpcode();
2977  assert((opcode == ISD::UMULO || opcode == ISD::SMULO) && "Invalid Opcode.");
2978 
2979  bool isSigned = (opcode == ISD::SMULO);
2980  EVT VT = MVT::i64;
2981  EVT WideVT = MVT::i128;
2982  SDLoc dl(Op);
2983  SDValue LHS = Op.getOperand(0);
2984 
2985  if (LHS.getValueType() != VT)
2986  return Op;
2987 
2988  SDValue ShiftAmt = DAG.getConstant(63, dl, VT);
2989 
2990  SDValue RHS = Op.getOperand(1);
2991  SDValue HiLHS = DAG.getNode(ISD::SRA, dl, VT, LHS, ShiftAmt);
2992  SDValue HiRHS = DAG.getNode(ISD::SRA, dl, MVT::i64, RHS, ShiftAmt);
2993  SDValue Args[] = { HiLHS, LHS, HiRHS, RHS };
2994 
2995  SDValue MulResult = TLI.makeLibCall(DAG,
2996  RTLIB::MUL_I128, WideVT,
2997  Args, isSigned, dl).first;
2998  SDValue BottomHalf = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, VT,
2999  MulResult, DAG.getIntPtrConstant(0, dl));
3000  SDValue TopHalf = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, VT,
3001  MulResult, DAG.getIntPtrConstant(1, dl));
3002  if (isSigned) {
3003  SDValue Tmp1 = DAG.getNode(ISD::SRA, dl, VT, BottomHalf, ShiftAmt);
3004  TopHalf = DAG.getSetCC(dl, MVT::i32, TopHalf, Tmp1, ISD::SETNE);
3005  } else {
3006  TopHalf = DAG.getSetCC(dl, MVT::i32, TopHalf, DAG.getConstant(0, dl, VT),
3007  ISD::SETNE);
3008  }
3009  // MulResult is a node with an illegal type. Because such things are not
3010  // generally permitted during this phase of legalization, ensure that
3011  // nothing is left using the node. The above EXTRACT_ELEMENT nodes should have
3012  // been folded.
3013  assert(MulResult->use_empty() && "Illegally typed node still in use!");
3014 
3015  SDValue Ops[2] = { BottomHalf, TopHalf } ;
3016  return DAG.getMergeValues(Ops, dl);
3017 }
3018 
3020  if (isStrongerThanMonotonic(cast<AtomicSDNode>(Op)->getOrdering()))
3021  // Expand with a fence.
3022  return SDValue();
3023 
3024  // Monotonic load/stores are legal.
3025  return Op;
3026 }
3027 
3029  SelectionDAG &DAG) const {
3030  unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
3031  SDLoc dl(Op);
3032  switch (IntNo) {
3033  default: return SDValue(); // Don't custom lower most intrinsics.
3034  case Intrinsic::thread_pointer: {
3035  EVT PtrVT = getPointerTy(DAG.getDataLayout());
3036  return DAG.getRegister(SP::G7, PtrVT);
3037  }
3038  }
3039 }
3040 
3043 
3044  bool hasHardQuad = Subtarget->hasHardQuad();
3045  bool isV9 = Subtarget->isV9();
3046 
3047  switch (Op.getOpcode()) {
3048  default: llvm_unreachable("Should not custom lower this!");
3049 
3050  case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG, *this,
3051  Subtarget);
3052  case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG,
3053  Subtarget);
3054  case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
3055  case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
3056  case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
3057  case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
3058  case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG, *this,
3059  hasHardQuad);
3060  case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG, *this,
3061  hasHardQuad);
3062  case ISD::FP_TO_UINT: return LowerFP_TO_UINT(Op, DAG, *this,
3063  hasHardQuad);
3064  case ISD::UINT_TO_FP: return LowerUINT_TO_FP(Op, DAG, *this,
3065  hasHardQuad);
3066  case ISD::BR_CC: return LowerBR_CC(Op, DAG, *this,
3067  hasHardQuad);
3068  case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG, *this,
3069  hasHardQuad);
3070  case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG, *this);
3071  case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG, *this);
3072  case ISD::VASTART: return LowerVASTART(Op, DAG, *this);
3073  case ISD::VAARG: return LowerVAARG(Op, DAG);
3074  case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG,
3075  Subtarget);
3076 
3077  case ISD::LOAD: return LowerLOAD(Op, DAG);
3078  case ISD::STORE: return LowerSTORE(Op, DAG);
3079  case ISD::FADD: return LowerF128Op(Op, DAG,
3081  case ISD::FSUB: return LowerF128Op(Op, DAG,
3083  case ISD::FMUL: return LowerF128Op(Op, DAG,
3085  case ISD::FDIV: return LowerF128Op(Op, DAG,
3087  case ISD::FSQRT: return LowerF128Op(Op, DAG,
3089  case ISD::FABS:
3090  case ISD::FNEG: return LowerFNEGorFABS(Op, DAG, isV9);
3091  case ISD::FP_EXTEND: return LowerF128_FPEXTEND(Op, DAG, *this);
3092  case ISD::FP_ROUND: return LowerF128_FPROUND(Op, DAG, *this);
3093  case ISD::ADDC:
3094  case ISD::ADDE:
3095  case ISD::SUBC:
3096  case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG);
3097  case ISD::UMULO:
3098  case ISD::SMULO: return LowerUMULO_SMULO(Op, DAG, *this);
3099  case ISD::ATOMIC_LOAD:
3100  case ISD::ATOMIC_STORE: return LowerATOMIC_LOAD_STORE(Op, DAG);
3101  case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
3102  }
3103 }
3104 
3107  MachineBasicBlock *BB) const {
3108  switch (MI.getOpcode()) {
3109  default: llvm_unreachable("Unknown SELECT_CC!");
3110  case SP::SELECT_CC_Int_ICC:
3111  case SP::SELECT_CC_FP_ICC:
3112  case SP::SELECT_CC_DFP_ICC:
3113  case SP::SELECT_CC_QFP_ICC:
3114  return expandSelectCC(MI, BB, SP::BCOND);
3115  case SP::SELECT_CC_Int_FCC:
3116  case SP::SELECT_CC_FP_FCC:
3117  case SP::SELECT_CC_DFP_FCC:
3118  case SP::SELECT_CC_QFP_FCC:
3119  return expandSelectCC(MI, BB, SP::FBCOND);
3120  case SP::EH_SJLJ_SETJMP32ri:
3121  case SP::EH_SJLJ_SETJMP32rr:
3122  return emitEHSjLjSetJmp(MI, BB);
3123  case SP::EH_SJLJ_LONGJMP32rr:
3124  case SP::EH_SJLJ_LONGJMP32ri:
3125  return emitEHSjLjLongJmp(MI, BB);
3126 
3127  }
3128 }
3129 
3132  unsigned BROpcode) const {
3133  const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
3134  DebugLoc dl = MI.getDebugLoc();
3135  unsigned CC = (SPCC::CondCodes)MI.getOperand(3).getImm();
3136 
3137  // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
3138  // control-flow pattern. The incoming instruction knows the destination vreg
3139  // to set, the condition code register to branch on, the true/false values to
3140  // select between, and a branch opcode to use.
3141  const BasicBlock *LLVM_BB = BB->getBasicBlock();
3143 
3144  // thisMBB:
3145  // ...
3146  // TrueVal = ...
3147  // [f]bCC copy1MBB
3148  // fallthrough --> copy0MBB
3149  MachineBasicBlock *thisMBB = BB;
3150  MachineFunction *F = BB->getParent();
3151  MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
3152  MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
3153  F->insert(It, copy0MBB);
3154  F->insert(It, sinkMBB);
3155 
3156  // Transfer the remainder of BB and its successor edges to sinkMBB.
3157  sinkMBB->splice(sinkMBB->begin(), BB,
3158  std::next(MachineBasicBlock::iterator(MI)),
3159  BB->end());
3160  sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
3161 
3162  // Add the true and fallthrough blocks as its successors.
3163  BB->addSuccessor(copy0MBB);
3164  BB->addSuccessor(sinkMBB);
3165 
3166  BuildMI(BB, dl, TII.get(BROpcode)).addMBB(sinkMBB).addImm(CC);
3167 
3168  // copy0MBB:
3169  // %FalseValue = ...
3170  // # fallthrough to sinkMBB
3171  BB = copy0MBB;
3172 
3173  // Update machine-CFG edges
3174  BB->addSuccessor(sinkMBB);
3175 
3176  // sinkMBB:
3177  // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
3178  // ...
3179  BB = sinkMBB;
3180  BuildMI(*BB, BB->begin(), dl, TII.get(SP::PHI), MI.getOperand(0).getReg())
3181  .addReg(MI.getOperand(2).getReg())
3182  .addMBB(copy0MBB)
3183  .addReg(MI.getOperand(1).getReg())
3184  .addMBB(thisMBB);
3185 
3186  MI.eraseFromParent(); // The pseudo instruction is gone now.
3187  return BB;
3188 }
3189 
3192  MachineBasicBlock *MBB) const {
3193  DebugLoc DL = MI.getDebugLoc();
3194  const TargetInstrInfo *TII = Subtarget->getInstrInfo();
3195 
3196  MachineFunction *MF = MBB->getParent();
3198  MachineInstrBuilder MIB;
3199 
3200  MVT PVT = getPointerTy(MF->getDataLayout());
3201  unsigned RegSize = PVT.getStoreSize();
3202  assert(PVT == MVT::i32 && "Invalid Pointer Size!");
3203 
3204  unsigned Buf = MI.getOperand(0).getReg();
3205  unsigned JmpLoc = MRI.createVirtualRegister(&SP::IntRegsRegClass);
3206 
3207  // TO DO: If we do 64-bit handling, this perhaps should be FLUSHW, not TA 3
3208  MIB = BuildMI(*MBB, MI, DL, TII->get(SP::TRAPri), SP::G0).addImm(3).addImm(SPCC::ICC_A);
3209 
3210  // Instruction to restore FP
3211  const unsigned FP = SP::I6;
3212  MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))
3213  .addReg(FP)
3214  .addReg(Buf)
3215  .addImm(0);
3216 
3217  // Instruction to load jmp location
3218  MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))
3219  .addReg(JmpLoc, RegState::Define)
3220  .addReg(Buf)
3221  .addImm(RegSize);
3222 
3223  // Instruction to restore SP
3224  const unsigned SP = SP::O6;
3225  MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))
3226  .addReg(SP)
3227  .addReg(Buf)
3228  .addImm(2 * RegSize);
3229 
3230  // Instruction to restore I7
3231  MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))
3232  .addReg(SP::I7)
3233  .addReg(Buf, RegState::Kill)
3234  .addImm(3 * RegSize);
3235 
3236  // Jump to JmpLoc
3237  BuildMI(*MBB, MI, DL, TII->get(SP::JMPLrr)).addReg(SP::G0).addReg(JmpLoc, RegState::Kill).addReg(SP::G0);
3238 
3239  MI.eraseFromParent();
3240  return MBB;
3241 }
3242 
3245  MachineBasicBlock *MBB) const {
3246  DebugLoc DL = MI.getDebugLoc();
3247  const TargetInstrInfo *TII = Subtarget->getInstrInfo();
3248  const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
3249 
3250  MachineFunction *MF = MBB->getParent();
3252  MachineInstrBuilder MIB;
3253 
3254  MVT PVT = getPointerTy(MF->getDataLayout());
3255  unsigned RegSize = PVT.getStoreSize();
3256  assert(PVT == MVT::i32 && "Invalid Pointer Size!");
3257 
3258  unsigned DstReg = MI.getOperand(0).getReg();
3259  const TargetRegisterClass *RC = MRI.getRegClass(DstReg);
3260  assert(TRI->isTypeLegalForClass(*RC, MVT::i32) && "Invalid destination!");
3261  (void)TRI;
3262  unsigned mainDstReg = MRI.createVirtualRegister(RC);
3263  unsigned restoreDstReg = MRI.createVirtualRegister(RC);
3264 
3265  // For v = setjmp(buf), we generate
3266  //
3267  // thisMBB:
3268  // buf[0] = FP
3269  // buf[RegSize] = restoreMBB <-- takes address of restoreMBB
3270  // buf[RegSize * 2] = O6
3271  // buf[RegSize * 3] = I7
3272  // Ensure restoreMBB remains in the relocations list (done using a bn instruction)
3273  // b mainMBB
3274  //
3275  // mainMBB:
3276  // v_main = 0
3277  // b sinkMBB
3278  //
3279  // restoreMBB:
3280  // v_restore = 1
3281  // --fall through--
3282  //
3283  // sinkMBB:
3284  // v = phi(main, restore)
3285 
3286  const BasicBlock *BB = MBB->getBasicBlock();
3287  MachineFunction::iterator It = ++MBB->getIterator();
3288  MachineBasicBlock *thisMBB = MBB;
3289  MachineBasicBlock *mainMBB = MF->CreateMachineBasicBlock(BB);
3290  MachineBasicBlock *restoreMBB = MF->CreateMachineBasicBlock(BB);
3291  MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(BB);
3292 
3293  MF->insert(It, mainMBB);
3294  MF->insert(It, restoreMBB);
3295  MF->insert(It, sinkMBB);
3296  restoreMBB->setHasAddressTaken();
3297 
3298  // Transfer the remainder of BB and its successor edges to sinkMBB.
3299  sinkMBB->splice(sinkMBB->begin(), MBB,
3300  std::next(MachineBasicBlock::iterator(MI)),
3301  MBB->end());
3302  sinkMBB->transferSuccessorsAndUpdatePHIs(MBB);
3303 
3304  unsigned LabelReg = MRI.createVirtualRegister(&SP::IntRegsRegClass);
3305  unsigned LabelReg2 = MRI.createVirtualRegister(&SP::IntRegsRegClass);
3306  unsigned BufReg = MI.getOperand(1).getReg();
3307 
3308  // Instruction to store FP
3309  const unsigned FP = SP::I6;
3310  MIB = BuildMI(thisMBB, DL, TII->get(SP::STri))
3311  .addReg(BufReg)
3312  .addImm(0)
3313  .addReg(FP);
3314 
3315  // Instructions to store jmp location
3316  MIB = BuildMI(thisMBB, DL, TII->get(SP::SETHIi))
3317  .addReg(LabelReg, RegState::Define)
3318  .addMBB(restoreMBB, SparcMCExpr::VK_Sparc_HI);
3319 
3320  MIB = BuildMI(thisMBB, DL, TII->get(SP::ORri))
3321  .addReg(LabelReg2, RegState::Define)
3322  .addReg(LabelReg, RegState::Kill)
3323  .addMBB(restoreMBB, SparcMCExpr::VK_Sparc_LO);
3324 
3325  MIB = BuildMI(thisMBB, DL, TII->get(SP::STri))
3326  .addReg(BufReg)
3327  .addImm(RegSize)
3328  .addReg(LabelReg2, RegState::Kill);
3329 
3330  // Instruction to store SP
3331  const unsigned SP = SP::O6;
3332  MIB = BuildMI(thisMBB, DL, TII->get(SP::STri))
3333  .addReg(BufReg)
3334  .addImm(2 * RegSize)
3335  .addReg(SP);
3336 
3337  // Instruction to store I7
3338  MIB = BuildMI(thisMBB, DL, TII->get(SP::STri))
3339  .addReg(BufReg)
3340  .addImm(3 * RegSize)
3341  .addReg(SP::I7);
3342 
3343 
3344  // FIX ME: This next instruction ensures that the restoreMBB block address remains
3345  // valid through optimization passes and serves no other purpose. The ICC_N ensures
3346  // that the branch is never taken. This commented-out code here was an alternative
3347  // attempt to achieve this which brought myriad problems.
3348  //MIB = BuildMI(thisMBB, DL, TII->get(SP::EH_SjLj_Setup)).addMBB(restoreMBB, SparcMCExpr::VK_Sparc_None);
3349  MIB = BuildMI(thisMBB, DL, TII->get(SP::BCOND))
3350  .addMBB(restoreMBB)
3351  .addImm(SPCC::ICC_N);
3352 
3353  MIB = BuildMI(thisMBB, DL, TII->get(SP::BCOND))
3354  .addMBB(mainMBB)
3355  .addImm(SPCC::ICC_A);
3356 
3357  thisMBB->addSuccessor(mainMBB);
3358  thisMBB->addSuccessor(restoreMBB);
3359 
3360 
3361  // mainMBB:
3362  MIB = BuildMI(mainMBB, DL, TII->get(SP::ORrr))
3363  .addReg(mainDstReg, RegState::Define)
3364  .addReg(SP::G0)
3365  .addReg(SP::G0);
3366  MIB = BuildMI(mainMBB, DL, TII->get(SP::BCOND)).addMBB(sinkMBB).addImm(SPCC::ICC_A);
3367 
3368  mainMBB->addSuccessor(sinkMBB);
3369 
3370 
3371  // restoreMBB:
3372  MIB = BuildMI(restoreMBB, DL, TII->get(SP::ORri))
3373  .addReg(restoreDstReg, RegState::Define)
3374  .addReg(SP::G0)
3375  .addImm(1);
3376  //MIB = BuildMI(restoreMBB, DL, TII->get(SP::BCOND)).addMBB(sinkMBB).addImm(SPCC::ICC_A);
3377  restoreMBB->addSuccessor(sinkMBB);
3378 
3379  // sinkMBB:
3380  MIB = BuildMI(*sinkMBB, sinkMBB->begin(), DL,
3381  TII->get(SP::PHI), DstReg)
3382  .addReg(mainDstReg).addMBB(mainMBB)
3383  .addReg(restoreDstReg).addMBB(restoreMBB);
3384 
3385  MI.eraseFromParent();
3386  return sinkMBB;
3387 }
3388 
3389 //===----------------------------------------------------------------------===//
3390 // Sparc Inline Assembly Support
3391 //===----------------------------------------------------------------------===//
3392 
3393 /// getConstraintType - Given a constraint letter, return the type of
3394 /// constraint it is for this target.
3397  if (Constraint.size() == 1) {
3398  switch (Constraint[0]) {
3399  default: break;
3400  case 'r':
3401  case 'f':
3402  case 'e':
3403  return C_RegisterClass;
3404  case 'I': // SIMM13
3405  return C_Other;
3406  }
3407  }
3408 
3409  return TargetLowering::getConstraintType(Constraint);
3410 }
3411 
3414  const char *constraint) const {
3415  ConstraintWeight weight = CW_Invalid;
3416  Value *CallOperandVal = info.CallOperandVal;
3417  // If we don't have a value, we can't do a match,
3418  // but allow it at the lowest weight.
3419  if (!CallOperandVal)
3420  return CW_Default;
3421 
3422  // Look at the constraint type.
3423  switch (*constraint) {
3424  default:
3425  weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
3426  break;
3427  case 'I': // SIMM13
3428  if (ConstantInt *C = dyn_cast<ConstantInt>(info.CallOperandVal)) {
3429  if (isInt<13>(C->getSExtValue()))
3430  weight = CW_Constant;
3431  }
3432  break;
3433  }
3434  return weight;
3435 }
3436 
3437 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
3438 /// vector. If it is invalid, don't add anything to Ops.
3441  std::string &Constraint,
3442  std::vector<SDValue> &Ops,
3443  SelectionDAG &DAG) const {
3444  SDValue Result(nullptr, 0);
3445 
3446  // Only support length 1 constraints for now.
3447  if (Constraint.length() > 1)
3448  return;
3449 
3450  char ConstraintLetter = Constraint[0];
3451  switch (ConstraintLetter) {
3452  default: break;
3453  case 'I':
3454  if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
3455  if (isInt<13>(C->getSExtValue())) {
3456  Result = DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op),
3457  Op.getValueType());
3458  break;
3459  }
3460  return;
3461  }
3462  }
3463 
3464  if (Result.getNode()) {
3465  Ops.push_back(Result);
3466  return;
3467  }
3468  TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
3469 }
3470 
3471 std::pair<unsigned, const TargetRegisterClass *>
3473  StringRef Constraint,
3474  MVT VT) const {
3475  if (Constraint.size() == 1) {
3476  switch (Constraint[0]) {
3477  case 'r':
3478  if (VT == MVT::v2i32)
3479  return std::make_pair(0U, &SP::IntPairRegClass);
3480  else
3481  return std::make_pair(0U, &SP::IntRegsRegClass);
3482  case 'f':
3483  if (VT == MVT::f32)
3484  return std::make_pair(0U, &SP::FPRegsRegClass);
3485  else if (VT == MVT::f64)
3486  return std::make_pair(0U, &SP::LowDFPRegsRegClass);
3487  else if (VT == MVT::f128)
3488  return std::make_pair(0U, &SP::LowQFPRegsRegClass);
3489  llvm_unreachable("Unknown ValueType for f-register-type!");
3490  break;
3491  case 'e':
3492  if (VT == MVT::f32)
3493  return std::make_pair(0U, &SP::FPRegsRegClass);
3494  else if (VT == MVT::f64)
3495  return std::make_pair(0U, &SP::DFPRegsRegClass);
3496  else if (VT == MVT::f128)
3497  return std::make_pair(0U, &SP::QFPRegsRegClass);
3498  llvm_unreachable("Unknown ValueType for e-register-type!");
3499  break;
3500  }
3501  } else if (!Constraint.empty() && Constraint.size() <= 5
3502  && Constraint[0] == '{' && *(Constraint.end()-1) == '}') {
3503  // constraint = '{r<d>}'
3504  // Remove the braces from around the name.
3505  StringRef name(Constraint.data()+1, Constraint.size()-2);
3506  // Handle register aliases:
3507  // r0-r7 -> g0-g7
3508  // r8-r15 -> o0-o7
3509  // r16-r23 -> l0-l7
3510  // r24-r31 -> i0-i7
3511  uint64_t intVal = 0;
3512  if (name.substr(0, 1).equals("r")
3513  && !name.substr(1).getAsInteger(10, intVal) && intVal <= 31) {
3514  const char regTypes[] = { 'g', 'o', 'l', 'i' };
3515  char regType = regTypes[intVal/8];
3516  char regIdx = '0' + (intVal % 8);
3517  char tmp[] = { '{', regType, regIdx, '}', 0 };
3518  std::string newConstraint = std::string(tmp);
3519  return TargetLowering::getRegForInlineAsmConstraint(TRI, newConstraint,
3520  VT);
3521  }
3522  }
3523 
3524  return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
3525 }
3526 
3527 bool
3529  // The Sparc target isn't yet aware of offsets.
3530  return false;
3531 }
3532 
3535  SelectionDAG &DAG) const {
3536 
3537  SDLoc dl(N);
3538 
3540 
3541  switch (N->getOpcode()) {
3542  default:
3543  llvm_unreachable("Do not know how to custom type legalize this operation!");
3544 
3545  case ISD::FP_TO_SINT:
3546  case ISD::FP_TO_UINT:
3547  // Custom lower only if it involves f128 or i64.
3548  if (N->getOperand(0).getValueType() != MVT::f128
3549  || N->getValueType(0) != MVT::i64)
3550  return;
3551  libCall = ((N->getOpcode() == ISD::FP_TO_SINT)
3554 
3555  Results.push_back(LowerF128Op(SDValue(N, 0),
3556  DAG,
3557  getLibcallName(libCall),
3558  1));
3559  return;
3560 
3561  case ISD::SINT_TO_FP:
3562  case ISD::UINT_TO_FP:
3563  // Custom lower only if it involves f128 or i64.
3564  if (N->getValueType(0) != MVT::f128
3565  || N->getOperand(0).getValueType() != MVT::i64)
3566  return;
3567 
3568  libCall = ((N->getOpcode() == ISD::SINT_TO_FP)
3571 
3572  Results.push_back(LowerF128Op(SDValue(N, 0),
3573  DAG,
3574  getLibcallName(libCall),
3575  1));
3576  return;
3577  case ISD::LOAD: {
3578  LoadSDNode *Ld = cast<LoadSDNode>(N);
3579  // Custom handling only for i64: turn i64 load into a v2i32 load,
3580  // and a bitcast.
3581  if (Ld->getValueType(0) != MVT::i64 || Ld->getMemoryVT() != MVT::i64)
3582  return;
3583 
3584  SDLoc dl(N);
3585  SDValue LoadRes = DAG.getExtLoad(
3586  Ld->getExtensionType(), dl, MVT::v2i32, Ld->getChain(),
3587  Ld->getBasePtr(), Ld->getPointerInfo(), MVT::v2i32, Ld->getAlignment(),
3588  Ld->getMemOperand()->getFlags(), Ld->getAAInfo());
3589 
3590  SDValue Res = DAG.getNode(ISD::BITCAST, dl, MVT::i64, LoadRes);
3591  Results.push_back(Res);
3592  Results.push_back(LoadRes.getValue(1));
3593  return;
3594  }
3595  }
3596 }
3597 
3598 // Override to enable LOAD_STACK_GUARD lowering on Linux.
3600  if (!Subtarget->isTargetLinux())
3602  return true;
3603 }
3604 
3605 // Override to disable global variable loading on Linux.
3607  if (!Subtarget->isTargetLinux())
3609 }
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
void setFrameAddressIsTaken(bool T)
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
static SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:544
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:511
bool use_empty() const
Return true if there are no uses of this node.
static MVT getIntegerVT(unsigned BitWidth)
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:827
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
SDValue getValue(unsigned R) const
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...
MVT getValVT() const
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant, which is required to be operand #1) half of the integer or float value specified as operand #0.
Definition: ISDOpcodes.h:184
Flags getFlags() const
Return the raw flags of the source value,.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVMContext * getContext() const
Definition: SelectionDAG.h:381
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
DiagnosticInfoOptimizationBase::Argument NV
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
Definition: SelectionDAG.h:884
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
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)...
Definition: SelectionDAG.h:800
static SPCC::CondCodes IntCondCCodeToICC(ISD::CondCode CC)
IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC condition.
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:616
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
LocInfo getLocInfo() const
unsigned getSRetArgSize(SelectionDAG &DAG, SDValue Callee) const
static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF, SelectionDAG &DAG) const
static SDValue LowerATOMIC_LOAD_STORE(SDValue Op, SelectionDAG &DAG)
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
const TargetMachine & getTargetMachine() const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
SDValue LowerF128Compare(SDValue LHS, SDValue RHS, unsigned &SPCC, const SDLoc &DL, SelectionDAG &DAG) const
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
MachineBasicBlock * emitEHSjLjLongJmp(MachineInstr &MI, MachineBasicBlock *MBB) const
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:222
const TargetMachine & getTarget() const
Definition: SelectionDAG.h:377
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
DataLayout DL
MachineBasicBlock * emitEHSjLjSetJmp(MachineInstr &MI, MachineBasicBlock *MBB) const
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain...
Definition: ISDOpcodes.h:659
bool fixAllFDIVSQRT() const
const GlobalValue * getGlobal() const
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const
Function Alias Analysis Results
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:205
unsigned getSizeInBits() const
unsigned getByValSize() const
unsigned second
unsigned getNumOperands() const
Return the number of values used by this operation.
static bool CC_Sparc64_Full(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
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...
A debug info location.
Definition: DebugLoc.h:34
const SDValue & getOperand(unsigned Num) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:677
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned char TargetFlags=0)
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
Type * getElementType() const
Definition: DerivedTypes.h:486
Value * CallOperandVal
If this is the result output operand or a clobber, this is null, otherwise it is the incoming operand...
const SparcInstrInfo * getInstrInfo() const override
unsigned getValNo() const
const SDValue & getBasePtr() const
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
Definition: ISDOpcodes.h:741
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:403
AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all...
bool useSoftFloat() const override
bool isRegLoc() const
SDValue getExternalSymbol(const char *Sym, EVT VT)
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const override
Examine constraint string and operand type and determine a weight value.
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
static bool CC_Sparc_Assign_SRet(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
OUTCHAIN = EH_SJLJ_LONGJMP(INCHAIN, buffer) This corresponds to the eh.sjlj.longjmp intrinsic...
Definition: ISDOpcodes.h:114
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:209
bool replaceFMULS() const
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
Definition: ISDOpcodes.h:432
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const
static SDValue LowerF128_FPROUND(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
static SDValue LowerFNEGorFABS(SDValue Op, SelectionDAG &DAG, bool isV9)
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI) const
const uint32_t * getRTCallPreservedMask(CallingConv::ID CC) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static SDValue LowerF128_FPEXTEND(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
const HexagonInstrInfo * TII
static void fixupVariableFloatArgs(SmallVectorImpl< CCValAssign > &ArgLocs, ArrayRef< ISD::OutputArg > Outs)
Shift and rotation operations.
Definition: ISDOpcodes.h:378
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
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), MachineInstr opcode, and operands.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:375
CallLoweringInfo & setChain(SDValue InChain)
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition: ISDOpcodes.h:190
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
void addLoc(const CCValAssign &V)
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
Reg
All possible values of the reg field in the ModR/M byte.
static SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, const SparcSubtarget *Subtarget)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt) For double-word atomic operations: ValLo, ValHi, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amtLo, amtHi) ValLo, ValHi, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amtLo, amtHi) These correspond to the atomicrmw instruction.
Definition: ISDOpcodes.h:770
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...
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
bool isPositionIndependent() const
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
Definition: ISDOpcodes.h:73
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:141
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
SmallVector< ISD::InputArg, 32 > Ins
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:655
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
virtual 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...
static void LookThroughSetCC(SDValue &LHS, SDValue &RHS, ISD::CondCode CC, unsigned &SPCC)
static bool CC_Sparc_Assign_Split_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
unsigned getLocReg() const
#define F(x, y, z)
Definition: MD5.cpp:55
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:454
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
SDValue getRegisterMask(const uint32_t *RegMask)
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:503
static SDValue LowerUMULO_SMULO(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI)
SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID CC) const override
This contains information for each constraint that we are lowering.
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
SmallVector< ISD::OutputArg, 32 > Outs
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:216
const SDValue & getBasePtr() const
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
static mvt_range integer_vector_valuetypes()
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:909
EVT getMemoryVT() const
Return the type of the in-memory value.
int64_t getImm() const
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:546
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
bool useLoadStackGuardNode() const override
Override to support customized stack guard loading.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:151
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:376
SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
Class to represent pointers.
Definition: DerivedTypes.h:467
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
UNDEF - An undefined node.
Definition: ISDOpcodes.h:178
This class is used to represent ISD::STORE nodes.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:497
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static CCValAssign getReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:301
TargetInstrInfo - Interface to description of machine instruction set.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
SDNode * getNode() const
get the SDNode which holds the desired result
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
static SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG)
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
unsigned const MachineRegisterInfo * MRI
CodeModel::Model getCodeModel() const
Returns the code model.
Machine Value Type.
static bool CC_Sparc64_Half(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
const SDValue & getOperand(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
Simple binary floating point operators.
Definition: ISDOpcodes.h:259
bool isExtInLoc() const
MVT getLocVT() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void resetAll()
Resets the known state of all bits.
Definition: KnownBits.h:66
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
Definition: ISDOpcodes.h:688
static bool is64Bit(const char *name)
void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
LowerAsmOperandForConstraint - Lower the specified operand into the Ops vector.
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
Definition: ISDOpcodes.h:306
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:231
static bool hasReturnsTwiceAttr(SelectionDAG &DAG, SDValue Callee, ImmutableCallSite *CS)
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 ...
Definition: SelectionDAG.h:788
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
static mvt_range fp_valuetypes()
static SDValue LowerF128Store(SDValue Op, SelectionDAG &DAG)
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
static SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getOpcode() const
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:727
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Definition: CallSite.h:359
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:57
virtual bool useLoadStackGuardNode() const
If this function returns true, SelectionDAGBuilder emits a LOAD_STACK_GUARD node when it is lowering ...
arg_iterator arg_begin()
Definition: Function.h:595
static SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
MachineBasicBlock * expandSelectCC(MachineInstr &MI, MachineBasicBlock *BB, unsigned BROpcode) const
self_iterator getIterator()
Definition: ilist_node.h:82
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...
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:679
static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
const SDValue & getValue() const
lazy value info
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
Definition: ISDOpcodes.h:756
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:529
std::vector< ArgListEntry > ArgListTy
Extended Value Type.
Definition: ValueTypes.h:34
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:156
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This structure contains all information that is necessary for lowering calls.
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, ArrayRef< SDValue > Ops, bool isSigned, const SDLoc &dl, bool doesNotReturn=false, bool isReturnValueUsed=true) const
Returns a pair of (return value, chain).
This class contains a discriminated union of information about pointers in memory operands...
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...
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:431
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, 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...
bool needsCustom() const
const SparcRegisterInfo * getRegisterInfo() const override
unsigned first
const MachinePointerInfo & getPointerInfo() const
const TargetFrameLowering * getFrameLowering() const override
unsigned getByValAlign() const
const SDValue & getOffset() 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 ...
SDValue getTargetConstantPool(const Constant *C, EVT VT, unsigned Align=0, int Offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:605
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:50
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target...
bool hasHardQuad() const
Iterator for intrusive lists based on ilist_node.
bool usePopc() const
CCState - This class holds information needed while lowering arguments and return values...
#define E
Definition: LargeTest.cpp:27
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:482
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
static bool isFP128ABICall(const char *CalleeName)
SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args, SDValue Arg, const SDLoc &DL, SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
getSetCCResultType - Return the ISD::SETCC ValueType
static bool isStrongerThanMonotonic(AtomicOrdering ao)
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:313
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:405
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
CallLoweringInfo & setCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
bool isTargetLinux() const
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
CCValAssign - Represent assignment of one arg/retval to a location.
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, unsigned Align, bool isVol, bool AlwaysInline, bool isTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo)
BRCOND - Conditional branch.
Definition: ISDOpcodes.h:610
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
const SDValue & getChain() const
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 ...
bool hasLeonCasa() const
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:381
const size_t N
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
SDValue LowerFormalArguments_64(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
const char * getTargetNodeName(unsigned Opcode) const override
This method returns the name of a target specific DAG node.
BinOp getOperation() const
Definition: Instructions.h:730
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:643
static SDValue getFLUSHW(SDValue Op, SelectionDAG &DAG)
SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const
static mvt_range integer_valuetypes()
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:35
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Class for arbitrary precision integers.
Definition: APInt.h:69
SparcTargetLowering(const TargetMachine &TM, const SparcSubtarget &STI)
static SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG)
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:388
void setMinFunctionAlignment(unsigned Align)
Set the target's minimum function alignment (in log2(bytes))
unsigned EmulatedTLS
EmulatedTLS - This flag enables emulated TLS model, using emutls function in the runtime library...
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:444
static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC)
FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC FCC condition.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
bool isMemLoc() const
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...
void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:447
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:257
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:286
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...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:604
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
Representation of each machine instruction.
Definition: MachineInstr.h:59
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the source.
Definition: ISDOpcodes.h:684
SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI) const
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:637
uint64_t getConstantOperandVal(unsigned i) const
SmallVector< SDValue, 32 > OutVals
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:254
CondCodes
Definition: Sparc.h:42
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 '...
bool isUndef() const
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:669
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:205
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:462
#define C
Definition: LargeTest.cpp:25
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
TargetOptions Options
Definition: TargetMachine.h:95
Establish a view to a call site for examination.
Definition: CallSite.h:687
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:292
#define I(x, y, z)
Definition: MD5.cpp:58
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_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void setStackPointerRegisterToSaveRestore(unsigned R)
If set to a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save and restore.
const SDValue & getOffset() const
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
Same for multiplication.
Definition: ISDOpcodes.h:256
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:574
RESULT, OUTCHAIN = EH_SJLJ_SETJMP(INCHAIN, buffer) This corresponds to the eh.sjlj.setjmp intrinsic.
Definition: ISDOpcodes.h:108
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition: ISDOpcodes.h:175
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
unsigned getPointerSize() const
Get the pointer size for this target.
unsigned getReg() const
getReg - Returns the register number.
bool useSoftMulDiv() const
void insertSSPDeclarations(Module &M) const override
Inserts necessary declarations for SSP (stack protection) purpose.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
void insert(iterator MBBI, MachineBasicBlock *MBB)
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
void setReturnAddressIsTaken(bool s)
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...
static MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
LLVM Value Representation.
Definition: Value.h:73
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:276
SDValue getRegister(unsigned Reg, EVT VT)
static bool CC_Sparc_Assign_Ret_Split_64(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static const char * name
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
static SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG)
SDValue getValueType(EVT)
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
static SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG, const SparcTargetLowering &TLI, bool hasHardQuad)
bool isV9() const
iterator end() const
Definition: StringRef.h:108
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
bool is64Bit() const
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static SDValue getFRAMEADDR(uint64_t depth, SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:411
virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA, SelectionDAG &DAG) const
Lower TLS global address SDNode for target independent emulated TLS model.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
int64_t getStackPointerBias() const
The 64-bit ABI uses biased stack and frame pointers, so the stack frame of the current function is th...
unsigned getLocMemOffset() const
Conversion operators.
Definition: ISDOpcodes.h:441
int * Ptr
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:434
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:749
static SDValue LowerF64Op(SDValue SrcReg64, const SDLoc &dl, SelectionDAG &DAG, unsigned opcode)
SDValue getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand, SDValue Subreg)
A convenience function for creating TargetInstrInfo::INSERT_SUBREG nodes.
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:450
unsigned getAlignment() const
unsigned AllocateReg(unsigned Reg)
AllocateReg - Attempt to allocate one register.
virtual ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const
Examine constraint string and operand type and determine a weight value.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
Definition: ISDOpcodes.h:560
SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG, const char *LibFuncName, unsigned numArgs) const
unsigned AllocateStack(unsigned Size, unsigned Align)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:745
static unsigned toCallerWindow(unsigned Reg)
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:96
static SDValue LowerF128Load(SDValue Op, SelectionDAG &DAG)
bool useSoftFloat() const
unsigned getRegisterByName(const char *RegName, EVT VT, SelectionDAG &DAG) const override
Return the register ID of the name passed in.
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned char TargetFlags=0)
Definition: SelectionDAG.h:588
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
static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG)
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:354
BRIND - Indirect branch.
Definition: ISDOpcodes.h:600
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...
Definition: ISDOpcodes.h:589