LLVM  10.0.0
MSP430ISelLowering.cpp
Go to the documentation of this file.
1 //===-- MSP430ISelLowering.cpp - MSP430 DAG Lowering Implementation ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the MSP430TargetLowering class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "MSP430ISelLowering.h"
14 #include "MSP430.h"
16 #include "MSP430Subtarget.h"
17 #include "MSP430TargetMachine.h"
26 #include "llvm/IR/CallingConv.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/GlobalAlias.h"
30 #include "llvm/IR/GlobalVariable.h"
31 #include "llvm/IR/Intrinsics.h"
33 #include "llvm/Support/Debug.h"
36 using namespace llvm;
37 
38 #define DEBUG_TYPE "msp430-lower"
39 
41  "msp430-no-legal-immediate", cl::Hidden,
42  cl::desc("Enable non legal immediates (for testing purposes only)"),
43  cl::init(false));
44 
46  const MSP430Subtarget &STI)
47  : TargetLowering(TM) {
48 
49  // Set up the register classes.
50  addRegisterClass(MVT::i8, &MSP430::GR8RegClass);
51  addRegisterClass(MVT::i16, &MSP430::GR16RegClass);
52 
53  // Compute derived properties from the register classes
55 
56  // Provide all sorts of operation actions
59  setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct?
60 
61  // We have post-incremented loads / stores.
64 
65  for (MVT VT : MVT::integer_valuetypes()) {
71  }
72 
73  // We don't have any truncstores
75 
104 
111 
118 
120 
121  // FIXME: Implement efficiently multiplication by a constant
132 
145 
146  // varargs support
152 
153  // EABI Libcalls - EABI Section 6.2
154  const struct {
155  const RTLIB::Libcall Op;
156  const char * const Name;
157  const ISD::CondCode Cond;
158  } LibraryCalls[] = {
159  // Floating point conversions - EABI Table 6
160  { RTLIB::FPROUND_F64_F32, "__mspabi_cvtdf", ISD::SETCC_INVALID },
161  { RTLIB::FPEXT_F32_F64, "__mspabi_cvtfd", ISD::SETCC_INVALID },
162  // The following is NOT implemented in libgcc
163  //{ RTLIB::FPTOSINT_F64_I16, "__mspabi_fixdi", ISD::SETCC_INVALID },
164  { RTLIB::FPTOSINT_F64_I32, "__mspabi_fixdli", ISD::SETCC_INVALID },
165  { RTLIB::FPTOSINT_F64_I64, "__mspabi_fixdlli", ISD::SETCC_INVALID },
166  // The following is NOT implemented in libgcc
167  //{ RTLIB::FPTOUINT_F64_I16, "__mspabi_fixdu", ISD::SETCC_INVALID },
168  { RTLIB::FPTOUINT_F64_I32, "__mspabi_fixdul", ISD::SETCC_INVALID },
169  { RTLIB::FPTOUINT_F64_I64, "__mspabi_fixdull", ISD::SETCC_INVALID },
170  // The following is NOT implemented in libgcc
171  //{ RTLIB::FPTOSINT_F32_I16, "__mspabi_fixfi", ISD::SETCC_INVALID },
172  { RTLIB::FPTOSINT_F32_I32, "__mspabi_fixfli", ISD::SETCC_INVALID },
173  { RTLIB::FPTOSINT_F32_I64, "__mspabi_fixflli", ISD::SETCC_INVALID },
174  // The following is NOT implemented in libgcc
175  //{ RTLIB::FPTOUINT_F32_I16, "__mspabi_fixfu", ISD::SETCC_INVALID },
176  { RTLIB::FPTOUINT_F32_I32, "__mspabi_fixful", ISD::SETCC_INVALID },
177  { RTLIB::FPTOUINT_F32_I64, "__mspabi_fixfull", ISD::SETCC_INVALID },
178  // TODO The following IS implemented in libgcc
179  //{ RTLIB::SINTTOFP_I16_F64, "__mspabi_fltid", ISD::SETCC_INVALID },
180  { RTLIB::SINTTOFP_I32_F64, "__mspabi_fltlid", ISD::SETCC_INVALID },
181  // TODO The following IS implemented in libgcc but is not in the EABI
182  { RTLIB::SINTTOFP_I64_F64, "__mspabi_fltllid", ISD::SETCC_INVALID },
183  // TODO The following IS implemented in libgcc
184  //{ RTLIB::UINTTOFP_I16_F64, "__mspabi_fltud", ISD::SETCC_INVALID },
185  { RTLIB::UINTTOFP_I32_F64, "__mspabi_fltuld", ISD::SETCC_INVALID },
186  // The following IS implemented in libgcc but is not in the EABI
187  { RTLIB::UINTTOFP_I64_F64, "__mspabi_fltulld", ISD::SETCC_INVALID },
188  // TODO The following IS implemented in libgcc
189  //{ RTLIB::SINTTOFP_I16_F32, "__mspabi_fltif", ISD::SETCC_INVALID },
190  { RTLIB::SINTTOFP_I32_F32, "__mspabi_fltlif", ISD::SETCC_INVALID },
191  // TODO The following IS implemented in libgcc but is not in the EABI
192  { RTLIB::SINTTOFP_I64_F32, "__mspabi_fltllif", ISD::SETCC_INVALID },
193  // TODO The following IS implemented in libgcc
194  //{ RTLIB::UINTTOFP_I16_F32, "__mspabi_fltuf", ISD::SETCC_INVALID },
195  { RTLIB::UINTTOFP_I32_F32, "__mspabi_fltulf", ISD::SETCC_INVALID },
196  // The following IS implemented in libgcc but is not in the EABI
197  { RTLIB::UINTTOFP_I64_F32, "__mspabi_fltullf", ISD::SETCC_INVALID },
198 
199  // Floating point comparisons - EABI Table 7
200  { RTLIB::OEQ_F64, "__mspabi_cmpd", ISD::SETEQ },
201  { RTLIB::UNE_F64, "__mspabi_cmpd", ISD::SETNE },
202  { RTLIB::OGE_F64, "__mspabi_cmpd", ISD::SETGE },
203  { RTLIB::OLT_F64, "__mspabi_cmpd", ISD::SETLT },
204  { RTLIB::OLE_F64, "__mspabi_cmpd", ISD::SETLE },
205  { RTLIB::OGT_F64, "__mspabi_cmpd", ISD::SETGT },
206  { RTLIB::OEQ_F32, "__mspabi_cmpf", ISD::SETEQ },
207  { RTLIB::UNE_F32, "__mspabi_cmpf", ISD::SETNE },
208  { RTLIB::OGE_F32, "__mspabi_cmpf", ISD::SETGE },
209  { RTLIB::OLT_F32, "__mspabi_cmpf", ISD::SETLT },
210  { RTLIB::OLE_F32, "__mspabi_cmpf", ISD::SETLE },
211  { RTLIB::OGT_F32, "__mspabi_cmpf", ISD::SETGT },
212 
213  // Floating point arithmetic - EABI Table 8
214  { RTLIB::ADD_F64, "__mspabi_addd", ISD::SETCC_INVALID },
215  { RTLIB::ADD_F32, "__mspabi_addf", ISD::SETCC_INVALID },
216  { RTLIB::DIV_F64, "__mspabi_divd", ISD::SETCC_INVALID },
217  { RTLIB::DIV_F32, "__mspabi_divf", ISD::SETCC_INVALID },
218  { RTLIB::MUL_F64, "__mspabi_mpyd", ISD::SETCC_INVALID },
219  { RTLIB::MUL_F32, "__mspabi_mpyf", ISD::SETCC_INVALID },
220  { RTLIB::SUB_F64, "__mspabi_subd", ISD::SETCC_INVALID },
221  { RTLIB::SUB_F32, "__mspabi_subf", ISD::SETCC_INVALID },
222  // The following are NOT implemented in libgcc
223  // { RTLIB::NEG_F64, "__mspabi_negd", ISD::SETCC_INVALID },
224  // { RTLIB::NEG_F32, "__mspabi_negf", ISD::SETCC_INVALID },
225 
226  // Universal Integer Operations - EABI Table 9
227  { RTLIB::SDIV_I16, "__mspabi_divi", ISD::SETCC_INVALID },
228  { RTLIB::SDIV_I32, "__mspabi_divli", ISD::SETCC_INVALID },
229  { RTLIB::SDIV_I64, "__mspabi_divlli", ISD::SETCC_INVALID },
230  { RTLIB::UDIV_I16, "__mspabi_divu", ISD::SETCC_INVALID },
231  { RTLIB::UDIV_I32, "__mspabi_divul", ISD::SETCC_INVALID },
232  { RTLIB::UDIV_I64, "__mspabi_divull", ISD::SETCC_INVALID },
233  { RTLIB::SREM_I16, "__mspabi_remi", ISD::SETCC_INVALID },
234  { RTLIB::SREM_I32, "__mspabi_remli", ISD::SETCC_INVALID },
235  { RTLIB::SREM_I64, "__mspabi_remlli", ISD::SETCC_INVALID },
236  { RTLIB::UREM_I16, "__mspabi_remu", ISD::SETCC_INVALID },
237  { RTLIB::UREM_I32, "__mspabi_remul", ISD::SETCC_INVALID },
238  { RTLIB::UREM_I64, "__mspabi_remull", ISD::SETCC_INVALID },
239 
240  // Bitwise Operations - EABI Table 10
241  // TODO: __mspabi_[srli/srai/slli] ARE implemented in libgcc
242  { RTLIB::SRL_I32, "__mspabi_srll", ISD::SETCC_INVALID },
243  { RTLIB::SRA_I32, "__mspabi_sral", ISD::SETCC_INVALID },
244  { RTLIB::SHL_I32, "__mspabi_slll", ISD::SETCC_INVALID },
245  // __mspabi_[srlll/srall/sllll/rlli/rlll] are NOT implemented in libgcc
246 
247  };
248 
249  for (const auto &LC : LibraryCalls) {
250  setLibcallName(LC.Op, LC.Name);
251  if (LC.Cond != ISD::SETCC_INVALID)
252  setCmpLibcallCC(LC.Op, LC.Cond);
253  }
254 
255  if (STI.hasHWMult16()) {
256  const struct {
257  const RTLIB::Libcall Op;
258  const char * const Name;
259  } LibraryCalls[] = {
260  // Integer Multiply - EABI Table 9
261  { RTLIB::MUL_I16, "__mspabi_mpyi_hw" },
262  { RTLIB::MUL_I32, "__mspabi_mpyl_hw" },
263  { RTLIB::MUL_I64, "__mspabi_mpyll_hw" },
264  // TODO The __mspabi_mpysl*_hw functions ARE implemented in libgcc
265  // TODO The __mspabi_mpyul*_hw functions ARE implemented in libgcc
266  };
267  for (const auto &LC : LibraryCalls) {
268  setLibcallName(LC.Op, LC.Name);
269  }
270  } else if (STI.hasHWMult32()) {
271  const struct {
272  const RTLIB::Libcall Op;
273  const char * const Name;
274  } LibraryCalls[] = {
275  // Integer Multiply - EABI Table 9
276  { RTLIB::MUL_I16, "__mspabi_mpyi_hw" },
277  { RTLIB::MUL_I32, "__mspabi_mpyl_hw32" },
278  { RTLIB::MUL_I64, "__mspabi_mpyll_hw32" },
279  // TODO The __mspabi_mpysl*_hw32 functions ARE implemented in libgcc
280  // TODO The __mspabi_mpyul*_hw32 functions ARE implemented in libgcc
281  };
282  for (const auto &LC : LibraryCalls) {
283  setLibcallName(LC.Op, LC.Name);
284  }
285  } else if (STI.hasHWMultF5()) {
286  const struct {
287  const RTLIB::Libcall Op;
288  const char * const Name;
289  } LibraryCalls[] = {
290  // Integer Multiply - EABI Table 9
291  { RTLIB::MUL_I16, "__mspabi_mpyi_f5hw" },
292  { RTLIB::MUL_I32, "__mspabi_mpyl_f5hw" },
293  { RTLIB::MUL_I64, "__mspabi_mpyll_f5hw" },
294  // TODO The __mspabi_mpysl*_f5hw functions ARE implemented in libgcc
295  // TODO The __mspabi_mpyul*_f5hw functions ARE implemented in libgcc
296  };
297  for (const auto &LC : LibraryCalls) {
298  setLibcallName(LC.Op, LC.Name);
299  }
300  } else { // NoHWMult
301  const struct {
302  const RTLIB::Libcall Op;
303  const char * const Name;
304  } LibraryCalls[] = {
305  // Integer Multiply - EABI Table 9
306  { RTLIB::MUL_I16, "__mspabi_mpyi" },
307  { RTLIB::MUL_I32, "__mspabi_mpyl" },
308  { RTLIB::MUL_I64, "__mspabi_mpyll" },
309  // The __mspabi_mpysl* functions are NOT implemented in libgcc
310  // The __mspabi_mpyul* functions are NOT implemented in libgcc
311  };
312  for (const auto &LC : LibraryCalls) {
313  setLibcallName(LC.Op, LC.Name);
314  }
316  }
317 
318  // Several of the runtime library functions use a special calling conv
333  // TODO: __mspabi_srall, __mspabi_srlll, __mspabi_sllll
334 
337 }
338 
340  SelectionDAG &DAG) const {
341  switch (Op.getOpcode()) {
342  case ISD::SHL: // FALLTHROUGH
343  case ISD::SRL:
344  case ISD::SRA: return LowerShifts(Op, DAG);
345  case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
346  case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
347  case ISD::ExternalSymbol: return LowerExternalSymbol(Op, DAG);
348  case ISD::SETCC: return LowerSETCC(Op, DAG);
349  case ISD::BR_CC: return LowerBR_CC(Op, DAG);
350  case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
351  case ISD::SIGN_EXTEND: return LowerSIGN_EXTEND(Op, DAG);
352  case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
353  case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
354  case ISD::VASTART: return LowerVASTART(Op, DAG);
355  case ISD::JumpTable: return LowerJumpTable(Op, DAG);
356  default:
357  llvm_unreachable("unimplemented operand");
358  }
359 }
360 
361 // Define non profitable transforms into shifts
363  unsigned Amount) const {
364  return !(Amount == 8 || Amount == 9 || Amount<=2);
365 }
366 
367 // Implemented to verify test case assertions in
368 // tests/codegen/msp430/shift-amount-threshold-b.ll
371  return Immed >= -32 && Immed < 32;
373 }
374 
375 //===----------------------------------------------------------------------===//
376 // MSP430 Inline Assembly Support
377 //===----------------------------------------------------------------------===//
378 
379 /// getConstraintType - Given a constraint letter, return the type of
380 /// constraint it is for this target.
383  if (Constraint.size() == 1) {
384  switch (Constraint[0]) {
385  case 'r':
386  return C_RegisterClass;
387  default:
388  break;
389  }
390  }
391  return TargetLowering::getConstraintType(Constraint);
392 }
393 
394 std::pair<unsigned, const TargetRegisterClass *>
396  const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
397  if (Constraint.size() == 1) {
398  // GCC Constraint Letters
399  switch (Constraint[0]) {
400  default: break;
401  case 'r': // GENERAL_REGS
402  if (VT == MVT::i8)
403  return std::make_pair(0U, &MSP430::GR8RegClass);
404 
405  return std::make_pair(0U, &MSP430::GR16RegClass);
406  }
407  }
408 
409  return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
410 }
411 
412 //===----------------------------------------------------------------------===//
413 // Calling Convention Implementation
414 //===----------------------------------------------------------------------===//
415 
416 #include "MSP430GenCallingConv.inc"
417 
418 /// For each argument in a function store the number of pieces it is composed
419 /// of.
420 template<typename ArgT>
423  unsigned CurrentArgIndex;
424 
425  if (Args.empty())
426  return;
427 
428  CurrentArgIndex = Args[0].OrigArgIndex;
429  Out.push_back(0);
430 
431  for (auto &Arg : Args) {
432  if (CurrentArgIndex == Arg.OrigArgIndex) {
433  Out.back() += 1;
434  } else {
435  Out.push_back(1);
436  CurrentArgIndex = Arg.OrigArgIndex;
437  }
438  }
439 }
440 
441 static void AnalyzeVarArgs(CCState &State,
442  const SmallVectorImpl<ISD::OutputArg> &Outs) {
443  State.AnalyzeCallOperands(Outs, CC_MSP430_AssignStack);
444 }
445 
446 static void AnalyzeVarArgs(CCState &State,
448  State.AnalyzeFormalArguments(Ins, CC_MSP430_AssignStack);
449 }
450 
451 /// Analyze incoming and outgoing function arguments. We need custom C++ code
452 /// to handle special constraints in the ABI like reversing the order of the
453 /// pieces of splitted arguments. In addition, all pieces of a certain argument
454 /// have to be passed either using registers or the stack but never mixing both.
455 template<typename ArgT>
456 static void AnalyzeArguments(CCState &State,
458  const SmallVectorImpl<ArgT> &Args) {
459  static const MCPhysReg CRegList[] = {
460  MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15
461  };
462  static const unsigned CNbRegs = array_lengthof(CRegList);
463  static const MCPhysReg BuiltinRegList[] = {
464  MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
465  MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15
466  };
467  static const unsigned BuiltinNbRegs = array_lengthof(BuiltinRegList);
468 
469  ArrayRef<MCPhysReg> RegList;
470  unsigned NbRegs;
471 
472  bool Builtin = (State.getCallingConv() == CallingConv::MSP430_BUILTIN);
473  if (Builtin) {
474  RegList = BuiltinRegList;
475  NbRegs = BuiltinNbRegs;
476  } else {
477  RegList = CRegList;
478  NbRegs = CNbRegs;
479  }
480 
481  if (State.isVarArg()) {
482  AnalyzeVarArgs(State, Args);
483  return;
484  }
485 
486  SmallVector<unsigned, 4> ArgsParts;
487  ParseFunctionArgs(Args, ArgsParts);
488 
489  if (Builtin) {
490  assert(ArgsParts.size() == 2 &&
491  "Builtin calling convention requires two arguments");
492  }
493 
494  unsigned RegsLeft = NbRegs;
495  bool UsedStack = false;
496  unsigned ValNo = 0;
497 
498  for (unsigned i = 0, e = ArgsParts.size(); i != e; i++) {
499  MVT ArgVT = Args[ValNo].VT;
500  ISD::ArgFlagsTy ArgFlags = Args[ValNo].Flags;
501  MVT LocVT = ArgVT;
503 
504  // Promote i8 to i16
505  if (LocVT == MVT::i8) {
506  LocVT = MVT::i16;
507  if (ArgFlags.isSExt())
508  LocInfo = CCValAssign::SExt;
509  else if (ArgFlags.isZExt())
510  LocInfo = CCValAssign::ZExt;
511  else
512  LocInfo = CCValAssign::AExt;
513  }
514 
515  // Handle byval arguments
516  if (ArgFlags.isByVal()) {
517  State.HandleByVal(ValNo++, ArgVT, LocVT, LocInfo, 2, 2, ArgFlags);
518  continue;
519  }
520 
521  unsigned Parts = ArgsParts[i];
522 
523  if (Builtin) {
524  assert(Parts == 4 &&
525  "Builtin calling convention requires 64-bit arguments");
526  }
527 
528  if (!UsedStack && Parts == 2 && RegsLeft == 1) {
529  // Special case for 32-bit register split, see EABI section 3.3.3
530  unsigned Reg = State.AllocateReg(RegList);
531  State.addLoc(CCValAssign::getReg(ValNo++, ArgVT, Reg, LocVT, LocInfo));
532  RegsLeft -= 1;
533 
534  UsedStack = true;
535  CC_MSP430_AssignStack(ValNo++, ArgVT, LocVT, LocInfo, ArgFlags, State);
536  } else if (Parts <= RegsLeft) {
537  for (unsigned j = 0; j < Parts; j++) {
538  unsigned Reg = State.AllocateReg(RegList);
539  State.addLoc(CCValAssign::getReg(ValNo++, ArgVT, Reg, LocVT, LocInfo));
540  RegsLeft--;
541  }
542  } else {
543  UsedStack = true;
544  for (unsigned j = 0; j < Parts; j++)
545  CC_MSP430_AssignStack(ValNo++, ArgVT, LocVT, LocInfo, ArgFlags, State);
546  }
547  }
548 }
549 
550 static void AnalyzeRetResult(CCState &State,
552  State.AnalyzeCallResult(Ins, RetCC_MSP430);
553 }
554 
555 static void AnalyzeRetResult(CCState &State,
556  const SmallVectorImpl<ISD::OutputArg> &Outs) {
557  State.AnalyzeReturn(Outs, RetCC_MSP430);
558 }
559 
560 template<typename ArgT>
561 static void AnalyzeReturnValues(CCState &State,
563  const SmallVectorImpl<ArgT> &Args) {
564  AnalyzeRetResult(State, Args);
565 }
566 
567 SDValue MSP430TargetLowering::LowerFormalArguments(
568  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
569  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
570  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
571 
572  switch (CallConv) {
573  default:
574  report_fatal_error("Unsupported calling convention");
575  case CallingConv::C:
576  case CallingConv::Fast:
577  return LowerCCCArguments(Chain, CallConv, isVarArg, Ins, dl, DAG, InVals);
579  if (Ins.empty())
580  return Chain;
581  report_fatal_error("ISRs cannot have arguments");
582  }
583 }
584 
585 SDValue
586 MSP430TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
587  SmallVectorImpl<SDValue> &InVals) const {
588  SelectionDAG &DAG = CLI.DAG;
589  SDLoc &dl = CLI.DL;
591  SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
593  SDValue Chain = CLI.Chain;
594  SDValue Callee = CLI.Callee;
595  bool &isTailCall = CLI.IsTailCall;
596  CallingConv::ID CallConv = CLI.CallConv;
597  bool isVarArg = CLI.IsVarArg;
598 
599  // MSP430 target does not yet support tail call optimization.
600  isTailCall = false;
601 
602  switch (CallConv) {
603  default:
604  report_fatal_error("Unsupported calling convention");
606  case CallingConv::Fast:
607  case CallingConv::C:
608  return LowerCCCCallTo(Chain, Callee, CallConv, isVarArg, isTailCall,
609  Outs, OutVals, Ins, dl, DAG, InVals);
611  report_fatal_error("ISRs cannot be called directly");
612  }
613 }
614 
615 /// LowerCCCArguments - transform physical registers into virtual registers and
616 /// generate load operations for arguments places on the stack.
617 // FIXME: struct return stuff
618 SDValue MSP430TargetLowering::LowerCCCArguments(
619  SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
620  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
621  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
623  MachineFrameInfo &MFI = MF.getFrameInfo();
624  MachineRegisterInfo &RegInfo = MF.getRegInfo();
626 
627  // Assign locations to all of the incoming arguments.
629  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
630  *DAG.getContext());
631  AnalyzeArguments(CCInfo, ArgLocs, Ins);
632 
633  // Create frame index for the start of the first vararg value
634  if (isVarArg) {
635  unsigned Offset = CCInfo.getNextStackOffset();
636  FuncInfo->setVarArgsFrameIndex(MFI.CreateFixedObject(1, Offset, true));
637  }
638 
639  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
640  CCValAssign &VA = ArgLocs[i];
641  if (VA.isRegLoc()) {
642  // Arguments passed in registers
643  EVT RegVT = VA.getLocVT();
644  switch (RegVT.getSimpleVT().SimpleTy) {
645  default:
646  {
647 #ifndef NDEBUG
648  errs() << "LowerFormalArguments Unhandled argument type: "
649  << RegVT.getEVTString() << "\n";
650 #endif
651  llvm_unreachable(nullptr);
652  }
653  case MVT::i16:
654  Register VReg = RegInfo.createVirtualRegister(&MSP430::GR16RegClass);
655  RegInfo.addLiveIn(VA.getLocReg(), VReg);
656  SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, VReg, RegVT);
657 
658  // If this is an 8-bit value, it is really passed promoted to 16
659  // bits. Insert an assert[sz]ext to capture this, then truncate to the
660  // right size.
661  if (VA.getLocInfo() == CCValAssign::SExt)
662  ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
663  DAG.getValueType(VA.getValVT()));
664  else if (VA.getLocInfo() == CCValAssign::ZExt)
665  ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
666  DAG.getValueType(VA.getValVT()));
667 
668  if (VA.getLocInfo() != CCValAssign::Full)
669  ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
670 
671  InVals.push_back(ArgValue);
672  }
673  } else {
674  // Sanity check
675  assert(VA.isMemLoc());
676 
677  SDValue InVal;
678  ISD::ArgFlagsTy Flags = Ins[i].Flags;
679 
680  if (Flags.isByVal()) {
681  int FI = MFI.CreateFixedObject(Flags.getByValSize(),
682  VA.getLocMemOffset(), true);
683  InVal = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
684  } else {
685  // Load the argument to a virtual register
686  unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
687  if (ObjSize > 2) {
688  errs() << "LowerFormalArguments Unhandled argument type: "
689  << EVT(VA.getLocVT()).getEVTString()
690  << "\n";
691  }
692  // Create the frame index object for this incoming parameter...
693  int FI = MFI.CreateFixedObject(ObjSize, VA.getLocMemOffset(), true);
694 
695  // Create the SelectionDAG nodes corresponding to a load
696  //from this parameter
697  SDValue FIN = DAG.getFrameIndex(FI, MVT::i16);
698  InVal = DAG.getLoad(
699  VA.getLocVT(), dl, Chain, FIN,
701  }
702 
703  InVals.push_back(InVal);
704  }
705  }
706 
707  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
708  if (Ins[i].Flags.isSRet()) {
709  unsigned Reg = FuncInfo->getSRetReturnReg();
710  if (!Reg) {
713  FuncInfo->setSRetReturnReg(Reg);
714  }
715  SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[i]);
716  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
717  }
718  }
719 
720  return Chain;
721 }
722 
723 bool
724 MSP430TargetLowering::CanLowerReturn(CallingConv::ID CallConv,
725  MachineFunction &MF,
726  bool IsVarArg,
728  LLVMContext &Context) const {
730  CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
731  return CCInfo.CheckReturn(Outs, RetCC_MSP430);
732 }
733 
734 SDValue
735 MSP430TargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
736  bool isVarArg,
738  const SmallVectorImpl<SDValue> &OutVals,
739  const SDLoc &dl, SelectionDAG &DAG) const {
740 
742 
743  // CCValAssign - represent the assignment of the return value to a location
745 
746  // ISRs cannot return any value.
747  if (CallConv == CallingConv::MSP430_INTR && !Outs.empty())
748  report_fatal_error("ISRs cannot return any value");
749 
750  // CCState - Info about the registers and stack slot.
751  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
752  *DAG.getContext());
753 
754  // Analize return values.
755  AnalyzeReturnValues(CCInfo, RVLocs, Outs);
756 
757  SDValue Flag;
758  SmallVector<SDValue, 4> RetOps(1, Chain);
759 
760  // Copy the result values into the output registers.
761  for (unsigned i = 0; i != RVLocs.size(); ++i) {
762  CCValAssign &VA = RVLocs[i];
763  assert(VA.isRegLoc() && "Can only return in registers!");
764 
765  Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
766  OutVals[i], Flag);
767 
768  // Guarantee that all emitted copies are stuck together,
769  // avoiding something bad.
770  Flag = Chain.getValue(1);
771  RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
772  }
773 
774  if (MF.getFunction().hasStructRetAttr()) {
776  unsigned Reg = FuncInfo->getSRetReturnReg();
777 
778  if (!Reg)
779  llvm_unreachable("sret virtual register not created in entry block");
780 
781  SDValue Val =
782  DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy(DAG.getDataLayout()));
783  unsigned R12 = MSP430::R12;
784 
785  Chain = DAG.getCopyToReg(Chain, dl, R12, Val, Flag);
786  Flag = Chain.getValue(1);
787  RetOps.push_back(DAG.getRegister(R12, getPointerTy(DAG.getDataLayout())));
788  }
789 
790  unsigned Opc = (CallConv == CallingConv::MSP430_INTR ?
792 
793  RetOps[0] = Chain; // Update chain.
794 
795  // Add the flag if we have it.
796  if (Flag.getNode())
797  RetOps.push_back(Flag);
798 
799  return DAG.getNode(Opc, dl, MVT::Other, RetOps);
800 }
801 
802 /// LowerCCCCallTo - functions arguments are copied from virtual regs to
803 /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
804 SDValue MSP430TargetLowering::LowerCCCCallTo(
805  SDValue Chain, SDValue Callee, CallingConv::ID CallConv, bool isVarArg,
806  bool isTailCall, const SmallVectorImpl<ISD::OutputArg> &Outs,
807  const SmallVectorImpl<SDValue> &OutVals,
808  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
809  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
810  // Analyze operands of the call, assigning locations to each operand.
812  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
813  *DAG.getContext());
814  AnalyzeArguments(CCInfo, ArgLocs, Outs);
815 
816  // Get a count of how many bytes are to be pushed on the stack.
817  unsigned NumBytes = CCInfo.getNextStackOffset();
818  auto PtrVT = getPointerTy(DAG.getDataLayout());
819 
820  Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl);
821 
823  SmallVector<SDValue, 12> MemOpChains;
824  SDValue StackPtr;
825 
826  // Walk the register/memloc assignments, inserting copies/loads.
827  for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
828  CCValAssign &VA = ArgLocs[i];
829 
830  SDValue Arg = OutVals[i];
831 
832  // Promote the value if needed.
833  switch (VA.getLocInfo()) {
834  default: llvm_unreachable("Unknown loc info!");
835  case CCValAssign::Full: break;
836  case CCValAssign::SExt:
837  Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
838  break;
839  case CCValAssign::ZExt:
840  Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
841  break;
842  case CCValAssign::AExt:
843  Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
844  break;
845  }
846 
847  // Arguments that can be passed on register must be kept at RegsToPass
848  // vector
849  if (VA.isRegLoc()) {
850  RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
851  } else {
852  assert(VA.isMemLoc());
853 
854  if (!StackPtr.getNode())
855  StackPtr = DAG.getCopyFromReg(Chain, dl, MSP430::SP, PtrVT);
856 
857  SDValue PtrOff =
858  DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr,
859  DAG.getIntPtrConstant(VA.getLocMemOffset(), dl));
860 
861  SDValue MemOp;
862  ISD::ArgFlagsTy Flags = Outs[i].Flags;
863 
864  if (Flags.isByVal()) {
865  SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i16);
866  MemOp = DAG.getMemcpy(Chain, dl, PtrOff, Arg, SizeNode,
867  Flags.getByValAlign(),
868  /*isVolatile*/false,
869  /*AlwaysInline=*/true,
870  /*isTailCall=*/false,
873  } else {
874  MemOp = DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo());
875  }
876 
877  MemOpChains.push_back(MemOp);
878  }
879  }
880 
881  // Transform all store nodes into one single node because all store nodes are
882  // independent of each other.
883  if (!MemOpChains.empty())
884  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
885 
886  // Build a sequence of copy-to-reg nodes chained together with token chain and
887  // flag operands which copy the outgoing args into registers. The InFlag in
888  // necessary since all emitted instructions must be stuck together.
889  SDValue InFlag;
890  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
891  Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
892  RegsToPass[i].second, InFlag);
893  InFlag = Chain.getValue(1);
894  }
895 
896  // If the callee is a GlobalAddress node (quite common, every direct call is)
897  // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
898  // Likewise ExternalSymbol -> TargetExternalSymbol.
899  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
900  Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i16);
901  else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
902  Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i16);
903 
904  // Returns a chain & a flag for retval copy to use.
905  SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
907  Ops.push_back(Chain);
908  Ops.push_back(Callee);
909 
910  // Add argument registers to the end of the list so that they are
911  // known live into the call.
912  for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
913  Ops.push_back(DAG.getRegister(RegsToPass[i].first,
914  RegsToPass[i].second.getValueType()));
915 
916  if (InFlag.getNode())
917  Ops.push_back(InFlag);
918 
919  Chain = DAG.getNode(MSP430ISD::CALL, dl, NodeTys, Ops);
920  InFlag = Chain.getValue(1);
921 
922  // Create the CALLSEQ_END node.
923  Chain = DAG.getCALLSEQ_END(Chain, DAG.getConstant(NumBytes, dl, PtrVT, true),
924  DAG.getConstant(0, dl, PtrVT, true), InFlag, dl);
925  InFlag = Chain.getValue(1);
926 
927  // Handle result values, copying them out of physregs into vregs that we
928  // return.
929  return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl,
930  DAG, InVals);
931 }
932 
933 /// LowerCallResult - Lower the result values of a call into the
934 /// appropriate copies out of appropriate physical registers.
935 ///
936 SDValue MSP430TargetLowering::LowerCallResult(
937  SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool isVarArg,
938  const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
939  SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
940 
941  // Assign locations to each value returned by this call.
943  CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
944  *DAG.getContext());
945 
946  AnalyzeReturnValues(CCInfo, RVLocs, Ins);
947 
948  // Copy all of the result registers out of their specified physreg.
949  for (unsigned i = 0; i != RVLocs.size(); ++i) {
950  Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
951  RVLocs[i].getValVT(), InFlag).getValue(1);
952  InFlag = Chain.getValue(2);
953  InVals.push_back(Chain.getValue(0));
954  }
955 
956  return Chain;
957 }
958 
960  SelectionDAG &DAG) const {
961  unsigned Opc = Op.getOpcode();
962  SDNode* N = Op.getNode();
963  EVT VT = Op.getValueType();
964  SDLoc dl(N);
965 
966  // Expand non-constant shifts to loops:
967  if (!isa<ConstantSDNode>(N->getOperand(1)))
968  return Op;
969 
970  uint64_t ShiftAmount = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
971 
972  // Expand the stuff into sequence of shifts.
973  SDValue Victim = N->getOperand(0);
974 
975  if (ShiftAmount >= 8) {
976  assert(VT == MVT::i16 && "Can not shift i8 by 8 and more");
977  switch(Opc) {
978  default:
979  llvm_unreachable("Unknown shift");
980  case ISD::SHL:
981  // foo << (8 + N) => swpb(zext(foo)) << N
982  Victim = DAG.getZeroExtendInReg(Victim, dl, MVT::i8);
983  Victim = DAG.getNode(ISD::BSWAP, dl, VT, Victim);
984  break;
985  case ISD::SRA:
986  case ISD::SRL:
987  // foo >> (8 + N) => sxt(swpb(foo)) >> N
988  Victim = DAG.getNode(ISD::BSWAP, dl, VT, Victim);
989  Victim = (Opc == ISD::SRA)
990  ? DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, VT, Victim,
991  DAG.getValueType(MVT::i8))
992  : DAG.getZeroExtendInReg(Victim, dl, MVT::i8);
993  break;
994  }
995  ShiftAmount -= 8;
996  }
997 
998  if (Opc == ISD::SRL && ShiftAmount) {
999  // Emit a special goodness here:
1000  // srl A, 1 => clrc; rrc A
1001  Victim = DAG.getNode(MSP430ISD::RRCL, dl, VT, Victim);
1002  ShiftAmount -= 1;
1003  }
1004 
1005  while (ShiftAmount--)
1006  Victim = DAG.getNode((Opc == ISD::SHL ? MSP430ISD::RLA : MSP430ISD::RRA),
1007  dl, VT, Victim);
1008 
1009  return Victim;
1010 }
1011 
1013  SelectionDAG &DAG) const {
1014  const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1015  int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
1016  auto PtrVT = getPointerTy(DAG.getDataLayout());
1017 
1018  // Create the TargetGlobalAddress node, folding in the constant offset.
1019  SDValue Result = DAG.getTargetGlobalAddress(GV, SDLoc(Op), PtrVT, Offset);
1020  return DAG.getNode(MSP430ISD::Wrapper, SDLoc(Op), PtrVT, Result);
1021 }
1022 
1024  SelectionDAG &DAG) const {
1025  SDLoc dl(Op);
1026  const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
1027  auto PtrVT = getPointerTy(DAG.getDataLayout());
1028  SDValue Result = DAG.getTargetExternalSymbol(Sym, PtrVT);
1029 
1030  return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
1031 }
1032 
1034  SelectionDAG &DAG) const {
1035  SDLoc dl(Op);
1036  auto PtrVT = getPointerTy(DAG.getDataLayout());
1037  const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
1038  SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT);
1039 
1040  return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
1041 }
1042 
1043 static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC,
1044  ISD::CondCode CC, const SDLoc &dl, SelectionDAG &DAG) {
1045  // FIXME: Handle bittests someday
1046  assert(!LHS.getValueType().isFloatingPoint() && "We don't handle FP yet");
1047 
1048  // FIXME: Handle jump negative someday
1050  switch (CC) {
1051  default: llvm_unreachable("Invalid integer condition!");
1052  case ISD::SETEQ:
1053  TCC = MSP430CC::COND_E; // aka COND_Z
1054  // Minor optimization: if LHS is a constant, swap operands, then the
1055  // constant can be folded into comparison.
1056  if (LHS.getOpcode() == ISD::Constant)
1057  std::swap(LHS, RHS);
1058  break;
1059  case ISD::SETNE:
1060  TCC = MSP430CC::COND_NE; // aka COND_NZ
1061  // Minor optimization: if LHS is a constant, swap operands, then the
1062  // constant can be folded into comparison.
1063  if (LHS.getOpcode() == ISD::Constant)
1064  std::swap(LHS, RHS);
1065  break;
1066  case ISD::SETULE:
1067  std::swap(LHS, RHS);
1069  case ISD::SETUGE:
1070  // Turn lhs u>= rhs with lhs constant into rhs u< lhs+1, this allows us to
1071  // fold constant into instruction.
1072  if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
1073  LHS = RHS;
1074  RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
1075  TCC = MSP430CC::COND_LO;
1076  break;
1077  }
1078  TCC = MSP430CC::COND_HS; // aka COND_C
1079  break;
1080  case ISD::SETUGT:
1081  std::swap(LHS, RHS);
1083  case ISD::SETULT:
1084  // Turn lhs u< rhs with lhs constant into rhs u>= lhs+1, this allows us to
1085  // fold constant into instruction.
1086  if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
1087  LHS = RHS;
1088  RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
1089  TCC = MSP430CC::COND_HS;
1090  break;
1091  }
1092  TCC = MSP430CC::COND_LO; // aka COND_NC
1093  break;
1094  case ISD::SETLE:
1095  std::swap(LHS, RHS);
1097  case ISD::SETGE:
1098  // Turn lhs >= rhs with lhs constant into rhs < lhs+1, this allows us to
1099  // fold constant into instruction.
1100  if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
1101  LHS = RHS;
1102  RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
1103  TCC = MSP430CC::COND_L;
1104  break;
1105  }
1106  TCC = MSP430CC::COND_GE;
1107  break;
1108  case ISD::SETGT:
1109  std::swap(LHS, RHS);
1111  case ISD::SETLT:
1112  // Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows us to
1113  // fold constant into instruction.
1114  if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
1115  LHS = RHS;
1116  RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
1117  TCC = MSP430CC::COND_GE;
1118  break;
1119  }
1120  TCC = MSP430CC::COND_L;
1121  break;
1122  }
1123 
1124  TargetCC = DAG.getConstant(TCC, dl, MVT::i8);
1125  return DAG.getNode(MSP430ISD::CMP, dl, MVT::Glue, LHS, RHS);
1126 }
1127 
1128 
1130  SDValue Chain = Op.getOperand(0);
1131  ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
1132  SDValue LHS = Op.getOperand(2);
1133  SDValue RHS = Op.getOperand(3);
1134  SDValue Dest = Op.getOperand(4);
1135  SDLoc dl (Op);
1136 
1137  SDValue TargetCC;
1138  SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1139 
1140  return DAG.getNode(MSP430ISD::BR_CC, dl, Op.getValueType(),
1141  Chain, Dest, TargetCC, Flag);
1142 }
1143 
1145  SDValue LHS = Op.getOperand(0);
1146  SDValue RHS = Op.getOperand(1);
1147  SDLoc dl (Op);
1148 
1149  // If we are doing an AND and testing against zero, then the CMP
1150  // will not be generated. The AND (or BIT) will generate the condition codes,
1151  // but they are different from CMP.
1152  // FIXME: since we're doing a post-processing, use a pseudoinstr here, so
1153  // lowering & isel wouldn't diverge.
1154  bool andCC = false;
1155  if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
1156  if (RHSC->isNullValue() && LHS.hasOneUse() &&
1157  (LHS.getOpcode() == ISD::AND ||
1158  (LHS.getOpcode() == ISD::TRUNCATE &&
1159  LHS.getOperand(0).getOpcode() == ISD::AND))) {
1160  andCC = true;
1161  }
1162  }
1163  ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
1164  SDValue TargetCC;
1165  SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1166 
1167  // Get the condition codes directly from the status register, if its easy.
1168  // Otherwise a branch will be generated. Note that the AND and BIT
1169  // instructions generate different flags than CMP, the carry bit can be used
1170  // for NE/EQ.
1171  bool Invert = false;
1172  bool Shift = false;
1173  bool Convert = true;
1174  switch (cast<ConstantSDNode>(TargetCC)->getZExtValue()) {
1175  default:
1176  Convert = false;
1177  break;
1178  case MSP430CC::COND_HS:
1179  // Res = SR & 1, no processing is required
1180  break;
1181  case MSP430CC::COND_LO:
1182  // Res = ~(SR & 1)
1183  Invert = true;
1184  break;
1185  case MSP430CC::COND_NE:
1186  if (andCC) {
1187  // C = ~Z, thus Res = SR & 1, no processing is required
1188  } else {
1189  // Res = ~((SR >> 1) & 1)
1190  Shift = true;
1191  Invert = true;
1192  }
1193  break;
1194  case MSP430CC::COND_E:
1195  Shift = true;
1196  // C = ~Z for AND instruction, thus we can put Res = ~(SR & 1), however,
1197  // Res = (SR >> 1) & 1 is 1 word shorter.
1198  break;
1199  }
1200  EVT VT = Op.getValueType();
1201  SDValue One = DAG.getConstant(1, dl, VT);
1202  if (Convert) {
1203  SDValue SR = DAG.getCopyFromReg(DAG.getEntryNode(), dl, MSP430::SR,
1204  MVT::i16, Flag);
1205  if (Shift)
1206  // FIXME: somewhere this is turned into a SRL, lower it MSP specific?
1207  SR = DAG.getNode(ISD::SRA, dl, MVT::i16, SR, One);
1208  SR = DAG.getNode(ISD::AND, dl, MVT::i16, SR, One);
1209  if (Invert)
1210  SR = DAG.getNode(ISD::XOR, dl, MVT::i16, SR, One);
1211  return SR;
1212  } else {
1213  SDValue Zero = DAG.getConstant(0, dl, VT);
1214  SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
1215  SDValue Ops[] = {One, Zero, TargetCC, Flag};
1216  return DAG.getNode(MSP430ISD::SELECT_CC, dl, VTs, Ops);
1217  }
1218 }
1219 
1221  SelectionDAG &DAG) const {
1222  SDValue LHS = Op.getOperand(0);
1223  SDValue RHS = Op.getOperand(1);
1224  SDValue TrueV = Op.getOperand(2);
1225  SDValue FalseV = Op.getOperand(3);
1226  ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
1227  SDLoc dl (Op);
1228 
1229  SDValue TargetCC;
1230  SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1231 
1232  SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
1233  SDValue Ops[] = {TrueV, FalseV, TargetCC, Flag};
1234 
1235  return DAG.getNode(MSP430ISD::SELECT_CC, dl, VTs, Ops);
1236 }
1237 
1239  SelectionDAG &DAG) const {
1240  SDValue Val = Op.getOperand(0);
1241  EVT VT = Op.getValueType();
1242  SDLoc dl(Op);
1243 
1244  assert(VT == MVT::i16 && "Only support i16 for now!");
1245 
1246  return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, VT,
1247  DAG.getNode(ISD::ANY_EXTEND, dl, VT, Val),
1248  DAG.getValueType(Val.getValueType()));
1249 }
1250 
1251 SDValue
1253  MachineFunction &MF = DAG.getMachineFunction();
1255  int ReturnAddrIndex = FuncInfo->getRAIndex();
1256  auto PtrVT = getPointerTy(MF.getDataLayout());
1257 
1258  if (ReturnAddrIndex == 0) {
1259  // Set up a frame object for the return address.
1260  uint64_t SlotSize = MF.getDataLayout().getPointerSize();
1261  ReturnAddrIndex = MF.getFrameInfo().CreateFixedObject(SlotSize, -SlotSize,
1262  true);
1263  FuncInfo->setRAIndex(ReturnAddrIndex);
1264  }
1265 
1266  return DAG.getFrameIndex(ReturnAddrIndex, PtrVT);
1267 }
1268 
1270  SelectionDAG &DAG) const {
1272  MFI.setReturnAddressIsTaken(true);
1273 
1275  return SDValue();
1276 
1277  unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1278  SDLoc dl(Op);
1279  auto PtrVT = getPointerTy(DAG.getDataLayout());
1280 
1281  if (Depth > 0) {
1282  SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
1283  SDValue Offset =
1285  return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
1286  DAG.getNode(ISD::ADD, dl, PtrVT, FrameAddr, Offset),
1287  MachinePointerInfo());
1288  }
1289 
1290  // Just load the return address.
1291  SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
1292  return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), RetAddrFI,
1293  MachinePointerInfo());
1294 }
1295 
1297  SelectionDAG &DAG) const {
1299  MFI.setFrameAddressIsTaken(true);
1300 
1301  EVT VT = Op.getValueType();
1302  SDLoc dl(Op); // FIXME probably not meaningful
1303  unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
1304  SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
1305  MSP430::FP, VT);
1306  while (Depth--)
1307  FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr,
1308  MachinePointerInfo());
1309  return FrameAddr;
1310 }
1311 
1313  SelectionDAG &DAG) const {
1314  MachineFunction &MF = DAG.getMachineFunction();
1316  auto PtrVT = getPointerTy(DAG.getDataLayout());
1317 
1318  // Frame index of first vararg argument
1320  DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT);
1321  const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1322 
1323  // Create a store of the frame index to the location operand
1324  return DAG.getStore(Op.getOperand(0), SDLoc(Op), FrameIndex, Op.getOperand(1),
1325  MachinePointerInfo(SV));
1326 }
1327 
1329  SelectionDAG &DAG) const {
1330  JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1331  auto PtrVT = getPointerTy(DAG.getDataLayout());
1332  SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
1333  return DAG.getNode(MSP430ISD::Wrapper, SDLoc(JT), PtrVT, Result);
1334 }
1335 
1336 /// getPostIndexedAddressParts - returns true by value, base pointer and
1337 /// offset pointer and addressing mode by reference if this node can be
1338 /// combined with a load / store to form a post-indexed load / store.
1339 bool MSP430TargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1340  SDValue &Base,
1341  SDValue &Offset,
1342  ISD::MemIndexedMode &AM,
1343  SelectionDAG &DAG) const {
1344 
1345  LoadSDNode *LD = cast<LoadSDNode>(N);
1346  if (LD->getExtensionType() != ISD::NON_EXTLOAD)
1347  return false;
1348 
1349  EVT VT = LD->getMemoryVT();
1350  if (VT != MVT::i8 && VT != MVT::i16)
1351  return false;
1352 
1353  if (Op->getOpcode() != ISD::ADD)
1354  return false;
1355 
1356  if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
1357  uint64_t RHSC = RHS->getZExtValue();
1358  if ((VT == MVT::i16 && RHSC != 2) ||
1359  (VT == MVT::i8 && RHSC != 1))
1360  return false;
1361 
1362  Base = Op->getOperand(0);
1363  Offset = DAG.getConstant(RHSC, SDLoc(N), VT);
1364  AM = ISD::POST_INC;
1365  return true;
1366  }
1367 
1368  return false;
1369 }
1370 
1371 
1372 const char *MSP430TargetLowering::getTargetNodeName(unsigned Opcode) const {
1373  switch ((MSP430ISD::NodeType)Opcode) {
1374  case MSP430ISD::FIRST_NUMBER: break;
1375  case MSP430ISD::RET_FLAG: return "MSP430ISD::RET_FLAG";
1376  case MSP430ISD::RETI_FLAG: return "MSP430ISD::RETI_FLAG";
1377  case MSP430ISD::RRA: return "MSP430ISD::RRA";
1378  case MSP430ISD::RLA: return "MSP430ISD::RLA";
1379  case MSP430ISD::RRC: return "MSP430ISD::RRC";
1380  case MSP430ISD::RRCL: return "MSP430ISD::RRCL";
1381  case MSP430ISD::CALL: return "MSP430ISD::CALL";
1382  case MSP430ISD::Wrapper: return "MSP430ISD::Wrapper";
1383  case MSP430ISD::BR_CC: return "MSP430ISD::BR_CC";
1384  case MSP430ISD::CMP: return "MSP430ISD::CMP";
1385  case MSP430ISD::SETCC: return "MSP430ISD::SETCC";
1386  case MSP430ISD::SELECT_CC: return "MSP430ISD::SELECT_CC";
1387  case MSP430ISD::DADD: return "MSP430ISD::DADD";
1388  }
1389  return nullptr;
1390 }
1391 
1393  Type *Ty2) const {
1394  if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
1395  return false;
1396 
1397  return (Ty1->getPrimitiveSizeInBits() > Ty2->getPrimitiveSizeInBits());
1398 }
1399 
1401  if (!VT1.isInteger() || !VT2.isInteger())
1402  return false;
1403 
1404  return (VT1.getSizeInBits() > VT2.getSizeInBits());
1405 }
1406 
1408  // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
1409  return 0 && Ty1->isIntegerTy(8) && Ty2->isIntegerTy(16);
1410 }
1411 
1413  // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
1414  return 0 && VT1 == MVT::i8 && VT2 == MVT::i16;
1415 }
1416 
1418  return isZExtFree(Val.getValueType(), VT2);
1419 }
1420 
1421 //===----------------------------------------------------------------------===//
1422 // Other Lowering Code
1423 //===----------------------------------------------------------------------===//
1424 
1427  MachineBasicBlock *BB) const {
1428  MachineFunction *F = BB->getParent();
1429  MachineRegisterInfo &RI = F->getRegInfo();
1430  DebugLoc dl = MI.getDebugLoc();
1431  const TargetInstrInfo &TII = *F->getSubtarget().getInstrInfo();
1432 
1433  unsigned Opc;
1434  bool ClearCarry = false;
1435  const TargetRegisterClass * RC;
1436  switch (MI.getOpcode()) {
1437  default: llvm_unreachable("Invalid shift opcode!");
1438  case MSP430::Shl8:
1439  Opc = MSP430::ADD8rr;
1440  RC = &MSP430::GR8RegClass;
1441  break;
1442  case MSP430::Shl16:
1443  Opc = MSP430::ADD16rr;
1444  RC = &MSP430::GR16RegClass;
1445  break;
1446  case MSP430::Sra8:
1447  Opc = MSP430::RRA8r;
1448  RC = &MSP430::GR8RegClass;
1449  break;
1450  case MSP430::Sra16:
1451  Opc = MSP430::RRA16r;
1452  RC = &MSP430::GR16RegClass;
1453  break;
1454  case MSP430::Srl8:
1455  ClearCarry = true;
1456  Opc = MSP430::RRC8r;
1457  RC = &MSP430::GR8RegClass;
1458  break;
1459  case MSP430::Srl16:
1460  ClearCarry = true;
1461  Opc = MSP430::RRC16r;
1462  RC = &MSP430::GR16RegClass;
1463  break;
1464  case MSP430::Rrcl8:
1465  case MSP430::Rrcl16: {
1466  BuildMI(*BB, MI, dl, TII.get(MSP430::BIC16rc), MSP430::SR)
1467  .addReg(MSP430::SR).addImm(1);
1468  Register SrcReg = MI.getOperand(1).getReg();
1469  Register DstReg = MI.getOperand(0).getReg();
1470  unsigned RrcOpc = MI.getOpcode() == MSP430::Rrcl16
1471  ? MSP430::RRC16r : MSP430::RRC8r;
1472  BuildMI(*BB, MI, dl, TII.get(RrcOpc), DstReg)
1473  .addReg(SrcReg);
1474  MI.eraseFromParent(); // The pseudo instruction is gone now.
1475  return BB;
1476  }
1477  }
1478 
1479  const BasicBlock *LLVM_BB = BB->getBasicBlock();
1481 
1482  // Create loop block
1483  MachineBasicBlock *LoopBB = F->CreateMachineBasicBlock(LLVM_BB);
1484  MachineBasicBlock *RemBB = F->CreateMachineBasicBlock(LLVM_BB);
1485 
1486  F->insert(I, LoopBB);
1487  F->insert(I, RemBB);
1488 
1489  // Update machine-CFG edges by transferring all successors of the current
1490  // block to the block containing instructions after shift.
1491  RemBB->splice(RemBB->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
1492  BB->end());
1494 
1495  // Add edges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB
1496  BB->addSuccessor(LoopBB);
1497  BB->addSuccessor(RemBB);
1498  LoopBB->addSuccessor(RemBB);
1499  LoopBB->addSuccessor(LoopBB);
1500 
1501  Register ShiftAmtReg = RI.createVirtualRegister(&MSP430::GR8RegClass);
1502  Register ShiftAmtReg2 = RI.createVirtualRegister(&MSP430::GR8RegClass);
1503  Register ShiftReg = RI.createVirtualRegister(RC);
1504  Register ShiftReg2 = RI.createVirtualRegister(RC);
1505  Register ShiftAmtSrcReg = MI.getOperand(2).getReg();
1506  Register SrcReg = MI.getOperand(1).getReg();
1507  Register DstReg = MI.getOperand(0).getReg();
1508 
1509  // BB:
1510  // cmp 0, N
1511  // je RemBB
1512  BuildMI(BB, dl, TII.get(MSP430::CMP8ri))
1513  .addReg(ShiftAmtSrcReg).addImm(0);
1514  BuildMI(BB, dl, TII.get(MSP430::JCC))
1515  .addMBB(RemBB)
1517 
1518  // LoopBB:
1519  // ShiftReg = phi [%SrcReg, BB], [%ShiftReg2, LoopBB]
1520  // ShiftAmt = phi [%N, BB], [%ShiftAmt2, LoopBB]
1521  // ShiftReg2 = shift ShiftReg
1522  // ShiftAmt2 = ShiftAmt - 1;
1523  BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftReg)
1524  .addReg(SrcReg).addMBB(BB)
1525  .addReg(ShiftReg2).addMBB(LoopBB);
1526  BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftAmtReg)
1527  .addReg(ShiftAmtSrcReg).addMBB(BB)
1528  .addReg(ShiftAmtReg2).addMBB(LoopBB);
1529  if (ClearCarry)
1530  BuildMI(LoopBB, dl, TII.get(MSP430::BIC16rc), MSP430::SR)
1531  .addReg(MSP430::SR).addImm(1);
1532  if (Opc == MSP430::ADD8rr || Opc == MSP430::ADD16rr)
1533  BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2)
1534  .addReg(ShiftReg)
1535  .addReg(ShiftReg);
1536  else
1537  BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2)
1538  .addReg(ShiftReg);
1539  BuildMI(LoopBB, dl, TII.get(MSP430::SUB8ri), ShiftAmtReg2)
1540  .addReg(ShiftAmtReg).addImm(1);
1541  BuildMI(LoopBB, dl, TII.get(MSP430::JCC))
1542  .addMBB(LoopBB)
1544 
1545  // RemBB:
1546  // DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB]
1547  BuildMI(*RemBB, RemBB->begin(), dl, TII.get(MSP430::PHI), DstReg)
1548  .addReg(SrcReg).addMBB(BB)
1549  .addReg(ShiftReg2).addMBB(LoopBB);
1550 
1551  MI.eraseFromParent(); // The pseudo instruction is gone now.
1552  return RemBB;
1553 }
1554 
1557  MachineBasicBlock *BB) const {
1558  unsigned Opc = MI.getOpcode();
1559 
1560  if (Opc == MSP430::Shl8 || Opc == MSP430::Shl16 ||
1561  Opc == MSP430::Sra8 || Opc == MSP430::Sra16 ||
1562  Opc == MSP430::Srl8 || Opc == MSP430::Srl16 ||
1563  Opc == MSP430::Rrcl8 || Opc == MSP430::Rrcl16)
1564  return EmitShiftInstr(MI, BB);
1565 
1566  const TargetInstrInfo &TII = *BB->getParent()->getSubtarget().getInstrInfo();
1567  DebugLoc dl = MI.getDebugLoc();
1568 
1569  assert((Opc == MSP430::Select16 || Opc == MSP430::Select8) &&
1570  "Unexpected instr type to insert");
1571 
1572  // To "insert" a SELECT instruction, we actually have to insert the diamond
1573  // control-flow pattern. The incoming instruction knows the destination vreg
1574  // to set, the condition code register to branch on, the true/false values to
1575  // select between, and a branch opcode to use.
1576  const BasicBlock *LLVM_BB = BB->getBasicBlock();
1578 
1579  // thisMBB:
1580  // ...
1581  // TrueVal = ...
1582  // cmpTY ccX, r1, r2
1583  // jCC copy1MBB
1584  // fallthrough --> copy0MBB
1585  MachineBasicBlock *thisMBB = BB;
1586  MachineFunction *F = BB->getParent();
1587  MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
1588  MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
1589  F->insert(I, copy0MBB);
1590  F->insert(I, copy1MBB);
1591  // Update machine-CFG edges by transferring all successors of the current
1592  // block to the new block which will contain the Phi node for the select.
1593  copy1MBB->splice(copy1MBB->begin(), BB,
1594  std::next(MachineBasicBlock::iterator(MI)), BB->end());
1595  copy1MBB->transferSuccessorsAndUpdatePHIs(BB);
1596  // Next, add the true and fallthrough blocks as its successors.
1597  BB->addSuccessor(copy0MBB);
1598  BB->addSuccessor(copy1MBB);
1599 
1600  BuildMI(BB, dl, TII.get(MSP430::JCC))
1601  .addMBB(copy1MBB)
1602  .addImm(MI.getOperand(3).getImm());
1603 
1604  // copy0MBB:
1605  // %FalseValue = ...
1606  // # fallthrough to copy1MBB
1607  BB = copy0MBB;
1608 
1609  // Update machine-CFG edges
1610  BB->addSuccessor(copy1MBB);
1611 
1612  // copy1MBB:
1613  // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1614  // ...
1615  BB = copy1MBB;
1616  BuildMI(*BB, BB->begin(), dl, TII.get(MSP430::PHI), MI.getOperand(0).getReg())
1617  .addReg(MI.getOperand(2).getReg())
1618  .addMBB(copy0MBB)
1619  .addReg(MI.getOperand(1).getReg())
1620  .addMBB(thisMBB);
1621 
1622  MI.eraseFromParent(); // The pseudo instruction is gone now.
1623  return BB;
1624 }
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)
uint64_t CallInst * C
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
EVT getValueType() const
Return the ValueType of the referenced return value.
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...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Return with a flag operand. Operand 0 is the chain operand.
MSP430MachineFunctionInfo - This class is derived from MachineFunction and contains private MSP430 ta...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
LLVMContext & Context
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&#39;s not CSE&#39;d)...
Definition: SelectionDAG.h:895
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:140
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:708
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Register getLocReg() const
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const
MSP430 conditional branches.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
DADD - Decimal addition with carry TODO Nothing generates a node of this type yet.
void push_back(const T &Elt)
Definition: SmallVector.h:211
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:400
void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Y = RRC X, rotate right via carry.
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:760
unsigned Reg
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
MachineBasicBlock * EmitShiftInstr(MachineInstr &MI, MachineBasicBlock *BB) const
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:255
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
SELECT_CC - Operand 0 and operand 1 are selection variable, operand 3 is condition code and operand 4...
bool hasHWMult16() const
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
unsigned second
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...
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:141
F(f)
static void AnalyzeVarArgs(CCState &State, const SmallVectorImpl< ISD::OutputArg > &Outs)
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const override
Return true if creating a shift of the type by the given amount is not profitable.
static void ParseFunctionArgs(const SmallVectorImpl< ArgT > &Args, SmallVectorImpl< unsigned > &Out)
For each argument in a function store the number of pieces it is composed of.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:496
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
bool hasHWMult32() const
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
bool isMemLoc() const
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:611
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:211
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:136
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations...
Definition: ISDOpcodes.h:517
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
The address of a basic block.
Definition: Constants.h:840
SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const
const TargetRegisterInfo * getRegisterInfo() const override
const HexagonInstrInfo * TII
Shift and rotation operations.
Definition: ISDOpcodes.h:471
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void eraseFromParent()
Unlink &#39;this&#39; from the containing basic block and delete it.
void addLoc(const CCValAssign &V)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Rotate right via carry, carry gets cleared beforehand by clrc.
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
Definition: SelectionDAG.h:660
SimpleValueType SimpleTy
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:485
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...
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:423
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG...
Definition: ISDOpcodes.h:74
LocInfo getLocInfo() const
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
This represents a list of ValueType&#39;s that has been intern&#39;d by a SelectionDAG.
SmallVector< ISD::InputArg, 32 > Ins
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:756
Same as RET_FLAG, but used for returning from ISRs.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:420
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
void setMinFunctionAlignment(Align Alignment)
Set the target&#39;s minimum function alignment.
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:202
SmallVector< ISD::OutputArg, 32 > Outs
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:151
bool isTruncateFree(Type *Ty1, Type *Ty2) const override
isTruncateFree - Return true if it&#39;s free to truncate a value of type Ty1 to type Ty2...
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
LowerOperation - Provide custom lowering hooks for some operations.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:1047
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
virtual const TargetInstrInfo * getInstrInfo() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
unsigned getByValSize() const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition: MCRegister.h:19
void setPrefFunctionAlignment(Align Alignment)
Set the target&#39;s preferred function alignment.
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:139
TargetInstrInfo - Interface to description of machine instruction set.
SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
Machine Value Type.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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:63
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type...
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE...
Definition: ISDOpcodes.h:789
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:654
const SDValue & getOperand(unsigned Num) const
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const
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:883
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const
constexpr double e
Definition: MathExtras.h:57
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
SetCC - Operand 0 is condition code, and operand 1 is the flag operand produced by a CMP instruction...
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:115
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:58
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
Definition: CallingConv.h:116
self_iterator getIterator()
Definition: ilist_node.h:81
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:780
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:298
This structure contains all information that is necessary for lowering calls.
size_t size() const
Definition: SmallVector.h:52
This class contains a discriminated union of information about pointers in memory operands...
void HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, int MinSize, int MinAlign, ISD::ArgFlagsTy ArgFlags)
Allocate space on the stack large enough to pass an argument by value.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC)
Set the CallingConv that should be used for the specified libcall.
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value...
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...
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:698
static cl::opt< bool > MSP430NoLegalImmediate("msp430-no-legal-immediate", cl::Hidden, cl::desc("Enable non legal immediates (for testing purposes only)"), cl::init(false))
unsigned first
void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC)
Override the default CondCode to be used to test the result of the comparison libcall against zero...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:51
Iterator for intrusive lists based on ilist_node.
CCState - This class holds information needed while lowering arguments and return values...
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:650
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
bool isVarArg() const
CMP - Compare instruction.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:223
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)
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:1027
BRCOND - Conditional branch.
Definition: ISDOpcodes.h:702
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
CallingConv::ID getCallingConv() const
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:474
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
int64_t getImm() const
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
Definition: SelectionDAG.h:703
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const char * getTargetNodeName(unsigned Opcode) const override
getTargetNodeName - This method returns the name of a target specific DAG node.
static mvt_range integer_valuetypes()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:940
void setIndexedLoadAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
EVT getMemoryVT() const
Return the type of the in-memory value.
static void AnalyzeRetResult(CCState &State, const SmallVectorImpl< ISD::InputArg > &Ins)
unsigned getByValAlign() const
amdgpu Simplify well known AMD library false FunctionCallee Callee
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:481
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:529
bool hasHWMultF5() const
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:532
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const
bool isLegalICmpImmediate(int64_t) const override
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
TargetLowering::ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target...
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.
virtual bool isLegalICmpImmediate(int64_t) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:696
Representation of each machine instruction.
Definition: MachineInstr.h:63
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:785
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
SmallVector< SDValue, 32 > OutVals
bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:448
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB &#39;Other&#39; at the position From, and insert it into this MBB right before &#39;...
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:729
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getLocMemOffset() const
SDValue LowerSIGN_EXTEND(SDValue Op, SelectionDAG &DAG) const
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:207
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:547
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
static void AnalyzeArguments(CCState &State, SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ArgT > &Args)
Analyze incoming and outgoing function arguments.
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
void setStackPointerRegisterToSaveRestore(unsigned R)
If set to a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save and restore.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const
unsigned getOpcode() const
SDValue getValue(unsigned R) const
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
Wrapper - A wrapper node for TargetConstantPool, TargetExternalSymbol, and TargetGlobalAddress.
CondCodes
Definition: MSP430.h:22
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
Calling convention used for special MSP430 rtlib functions which have an "optimized" convention using...
Definition: CallingConv.h:222
bool isRegLoc() const
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const
bool isZExtFree(Type *Ty1, Type *Ty2) const override
isZExtFree - Return true if any actual instruction that defines a value of type Ty1 implicit zero-ext...
static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC, ISD::CondCode CC, const SDLoc &dl, SelectionDAG &DAG)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
Y = R{R,L}A X, rotate right (left) arithmetically.
void setReturnAddressIsTaken(bool s)
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the &#39;usesCustomInserter&#39; fla...
LLVM Value Representation.
Definition: Value.h:74
SDValue getRegister(unsigned Reg, EVT VT)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:42
CALL - These operations represent an abstract call instruction, which includes a bunch of information...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:279
SDValue getValueType(EVT)
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:504
Register getReg() const
getReg - Returns the register number.
Conversion operators.
Definition: ISDOpcodes.h:526
const SDValue & getOperand(unsigned i) const
bool verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:535
unsigned AllocateReg(unsigned Reg)
AllocateReg - Attempt to allocate one register.
static void AnalyzeReturnValues(CCState &State, SmallVectorImpl< CCValAssign > &RVLocs, const SmallVectorImpl< ArgT > &Args)
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
LLVMContext * getContext() const
Definition: SelectionDAG.h:430
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
MSP430TargetLowering(const TargetMachine &TM, const MSP430Subtarget &STI)
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:985
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:441
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:681