LLVM 24.0.0git
MipsISelLowering.cpp
Go to the documentation of this file.
1//===- MipsISelLowering.cpp - Mips 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 defines the interfaces that Mips uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MipsISelLowering.h"
18#include "MipsCCState.h"
19#include "MipsInstrInfo.h"
20#include "MipsMachineFunction.h"
21#include "MipsRegisterInfo.h"
22#include "MipsSubtarget.h"
23#include "MipsTargetMachine.h"
25#include "llvm/ADT/APFloat.h"
26#include "llvm/ADT/ArrayRef.h"
28#include "llvm/ADT/Statistic.h"
29#include "llvm/ADT/StringRef.h"
49#include "llvm/IR/CallingConv.h"
50#include "llvm/IR/Constants.h"
51#include "llvm/IR/DataLayout.h"
52#include "llvm/IR/DebugLoc.h"
54#include "llvm/IR/Function.h"
55#include "llvm/IR/GlobalValue.h"
56#include "llvm/IR/Module.h"
57#include "llvm/IR/Type.h"
58#include "llvm/IR/Value.h"
59#include "llvm/MC/MCContext.h"
67#include <algorithm>
68#include <cassert>
69#include <cctype>
70#include <cstdint>
71#include <deque>
72#include <iterator>
73#include <string>
74#include <utility>
75#include <vector>
76
77using namespace llvm;
78
79#define DEBUG_TYPE "mips-lower"
80
81STATISTIC(NumTailCalls, "Number of tail calls");
82
83static const MCPhysReg Mips64DPRegs[8] = {
84 Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64,
85 Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64
86};
87
89 Break, // MIPS I
90 Teq, // MIPS II+
91 TeqMM, // microMIPS
92};
93
94// The MIPS MSA ABI passes vector arguments in the integer register set.
95// The number of integer registers used is dependant on the ABI used.
98 EVT VT) const {
99 if (!VT.isVector())
100 return getRegisterType(Context, VT);
101
103 return Subtarget.isABI_O32() || VT.getSizeInBits() == 32 ? MVT::i32
104 : MVT::i64;
105 return getRegisterType(Context, VT.getVectorElementType());
106}
107
110 EVT VT) const {
111 if (VT.isVector()) {
113 return divideCeil(VT.getSizeInBits(), Subtarget.isABI_O32() ? 32 : 64);
114 return VT.getVectorNumElements() *
116 }
117 return MipsTargetLowering::getNumRegisters(Context, VT);
118}
119
121 LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
122 unsigned &NumIntermediates, MVT &RegisterVT) const {
123 if (VT.isPow2VectorType() && VT.getVectorElementType().isRound()) {
124 IntermediateVT = getRegisterTypeForCallingConv(Context, CC, VT);
125 RegisterVT = IntermediateVT.getSimpleVT();
126 NumIntermediates = getNumRegistersForCallingConv(Context, CC, VT);
127 return NumIntermediates;
128 }
129 IntermediateVT = VT.getVectorElementType();
130 NumIntermediates = VT.getVectorNumElements();
131 RegisterVT = getRegisterType(Context, IntermediateVT);
132 return NumIntermediates * getNumRegisters(Context, IntermediateVT);
133}
134
140
141SDValue MipsTargetLowering::getTargetNode(GlobalAddressSDNode *N, EVT Ty,
142 SelectionDAG &DAG,
143 unsigned Flag) const {
144 return DAG.getTargetGlobalAddress(N->getGlobal(), SDLoc(N), Ty, 0, Flag);
145}
146
147SDValue MipsTargetLowering::getTargetNode(ExternalSymbolSDNode *N, EVT Ty,
148 SelectionDAG &DAG,
149 unsigned Flag) const {
150 return DAG.getTargetExternalSymbol(N->getSymbol(), Ty, Flag);
151}
152
153SDValue MipsTargetLowering::getTargetNode(BlockAddressSDNode *N, EVT Ty,
154 SelectionDAG &DAG,
155 unsigned Flag) const {
156 return DAG.getTargetBlockAddress(N->getBlockAddress(), Ty, 0, Flag);
157}
158
159SDValue MipsTargetLowering::getTargetNode(JumpTableSDNode *N, EVT Ty,
160 SelectionDAG &DAG,
161 unsigned Flag) const {
162 return DAG.getTargetJumpTable(N->getIndex(), Ty, Flag);
163}
164
165SDValue MipsTargetLowering::getTargetNode(ConstantPoolSDNode *N, EVT Ty,
166 SelectionDAG &DAG,
167 unsigned Flag) const {
168 return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlign(),
169 N->getOffset(), Flag);
170}
171
173 const MipsSubtarget &STI)
174 : TargetLowering(TM, STI), Subtarget(STI), ABI(STI.getABI()) {
175 // Mips does not have i1 type, so use i32 for
176 // setcc operations results (slt, sgt, ...).
179 // The cmp.cond.fmt instruction in MIPS32r6/MIPS64r6 uses 0 and -1 like MSA
180 // does. Integer booleans still use 0 and 1.
181 if (Subtarget.hasMips32r6())
184
185 // Load extented operations for i1 types must be promoted
186 for (MVT VT : MVT::integer_valuetypes()) {
190 }
191
192 // MIPS doesn't have extending float->double load/store. Set LoadExtAction
193 // for f32, f16
194 for (MVT VT : MVT::fp_valuetypes()) {
195 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand);
196 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand);
197 }
198
199 // Set LoadExtAction for f16 vectors to Expand
201 MVT F16VT = MVT::getVectorVT(MVT::f16, VT.getVectorNumElements());
202 if (F16VT.isValid())
204 }
205
206 setTruncStoreAction(MVT::f32, MVT::f16, Expand);
207 setTruncStoreAction(MVT::f64, MVT::f16, Expand);
208
209 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
210
211 // Used by legalize types to correctly generate the setcc result.
212 // Without this, every float setcc comes with a AND/OR with the result,
213 // we don't want this, since the fpcmp result goes to a flag register,
214 // which is used implicitly by brcond and select operations.
215 AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32);
216
217 // Mips Custom Operations
223 if (!Subtarget.inMips16Mode())
238
243
244 if (Subtarget.hasMips32r2() ||
245 getTargetMachine().getTargetTriple().isOSLinux())
247
248 // Lower fmin/fmax/fclass operations for MIPS R6.
249 if (Subtarget.hasMips32r6()) {
262 } else {
265 }
266
267 if (Subtarget.hasMTHC1())
269
270 if (Subtarget.isGP64bit()) {
275 if (!Subtarget.inMips16Mode())
278 if (Subtarget.hasMips64r6()) {
281 } else {
284 }
291 }
292
293 if (!Subtarget.isGP64bit()) {
297 }
298
300 if (Subtarget.isGP64bit())
302
311
312 // Operations not directly supported by Mips.
326
327 if (Subtarget.hasCnMips()) {
330 } else {
333 }
340
341 if (!Subtarget.hasMips32r2())
343
344 if (!Subtarget.hasMips64r2())
346
363
364 // Lower f16 conversion operations into library calls
369
371
376
377 // Use the default for now
380
381 if (!Subtarget.isGP64bit()) {
384 }
385
386 if (!Subtarget.hasMips32r2()) {
389 }
390
391 // MIPS16 lacks MIPS32's clz and clo instructions.
392 if (!Subtarget.hasMips32() || Subtarget.inMips16Mode())
394 if (!Subtarget.hasMips64())
396
397 if (!Subtarget.hasMips32r2())
399 if (!Subtarget.hasMips64r2())
401
402 if (Subtarget.isGP64bit() && Subtarget.hasMips64r6()) {
403 setLoadExtAction(ISD::SEXTLOAD, MVT::i64, MVT::i32, Legal);
404 setLoadExtAction(ISD::ZEXTLOAD, MVT::i64, MVT::i32, Legal);
405 setLoadExtAction(ISD::EXTLOAD, MVT::i64, MVT::i32, Legal);
406 setTruncStoreAction(MVT::i64, MVT::i32, Legal);
407 } else if (Subtarget.isGP64bit()) {
408 setLoadExtAction(ISD::SEXTLOAD, MVT::i64, MVT::i32, Custom);
409 setLoadExtAction(ISD::ZEXTLOAD, MVT::i64, MVT::i32, Custom);
410 setLoadExtAction(ISD::EXTLOAD, MVT::i64, MVT::i32, Custom);
411 setTruncStoreAction(MVT::i64, MVT::i32, Custom);
412 }
413
414 setOperationAction(ISD::TRAP, MVT::Other, Legal);
415
419
420 // Sink shifts into their users' blocks to expose extract patterns.
421 setHasExtractBitsInsn(Subtarget.hasExtractInsert());
422
423 // R5900 has no LL/SC instructions for atomic operations
424 if (Subtarget.isR5900())
426 else if (Subtarget.isGP64bit())
428 else
430
431 setMinFunctionAlignment(Subtarget.isGP64bit() ? Align(8) : Align(4));
432
433 // The arguments on the stack are defined in terms of 4-byte slots on O32
434 // and 8-byte slots on N32/N64.
435 setMinStackArgumentAlignment((ABI.IsN32() || ABI.IsN64()) ? Align(8)
436 : Align(4));
437
439
441
442 isMicroMips = Subtarget.inMicroMipsMode();
443}
444
445const MipsTargetLowering *
447 const MipsSubtarget &STI) {
448 if (STI.inMips16Mode())
449 return createMips16TargetLowering(TM, STI);
450
451 return createMipsSETargetLowering(TM, STI);
452}
453
454// Create a fast isel object.
456 FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo,
457 const LibcallLoweringInfo *libcallLowering) const {
458 const MipsTargetMachine &TM =
459 static_cast<const MipsTargetMachine &>(funcInfo.MF->getTarget());
460
461 // We support only the standard encoding [MIPS32,MIPS32R5] ISAs.
462 bool UseFastISel = TM.Options.EnableFastISel && Subtarget.hasMips32() &&
463 !Subtarget.hasMips32r6() && !Subtarget.inMips16Mode() &&
464 !Subtarget.inMicroMipsMode();
465
466 // Disable if either of the following is true:
467 // We do not generate PIC, the ABI is not O32, XGOT is being used.
468 if (!TM.isPositionIndependent() || !Subtarget.getABI().IsO32() ||
469 Subtarget.useXGOT())
470 UseFastISel = false;
471
472 return UseFastISel ? Mips::createFastISel(funcInfo, libInfo, libcallLowering)
473 : nullptr;
474}
475
477 EVT VT) const {
478 if (!VT.isVector())
479 return MVT::i32;
481}
482
485 const MipsSubtarget &Subtarget) {
486 if (DCI.isBeforeLegalizeOps())
487 return SDValue();
488
489 EVT Ty = N->getValueType(0);
490 unsigned LO = (Ty == MVT::i32) ? Mips::LO0 : Mips::LO0_64;
491 unsigned HI = (Ty == MVT::i32) ? Mips::HI0 : Mips::HI0_64;
492 unsigned Opc = N->getOpcode() == ISD::SDIVREM ? MipsISD::DivRem16 :
493 MipsISD::DivRemU16;
494 SDLoc DL(N);
495
496 SDValue DivRem = DAG.getNode(Opc, DL, MVT::Glue,
497 N->getOperand(0), N->getOperand(1));
498 SDValue InChain = DAG.getEntryNode();
499 SDValue InGlue = DivRem;
500
501 // insert MFLO
502 if (N->hasAnyUseOfValue(0)) {
503 SDValue CopyFromLo = DAG.getCopyFromReg(InChain, DL, LO, Ty,
504 InGlue);
505 DAG.ReplaceAllUsesOfValueWith(SDValue(N, 0), CopyFromLo);
506 InChain = CopyFromLo.getValue(1);
507 InGlue = CopyFromLo.getValue(2);
508 }
509
510 // insert MFHI
511 if (N->hasAnyUseOfValue(1)) {
512 SDValue CopyFromHi = DAG.getCopyFromReg(InChain, DL,
513 HI, Ty, InGlue);
514 DAG.ReplaceAllUsesOfValueWith(SDValue(N, 1), CopyFromHi);
515 }
516
517 return SDValue();
518}
519
521 switch (CC) {
522 default: llvm_unreachable("Unknown fp condition code!");
523 case ISD::SETEQ:
524 case ISD::SETOEQ: return Mips::FCOND_OEQ;
525 case ISD::SETUNE: return Mips::FCOND_UNE;
526 case ISD::SETLT:
527 case ISD::SETOLT: return Mips::FCOND_OLT;
528 case ISD::SETGT:
529 case ISD::SETOGT: return Mips::FCOND_OGT;
530 case ISD::SETLE:
531 case ISD::SETOLE: return Mips::FCOND_OLE;
532 case ISD::SETGE:
533 case ISD::SETOGE: return Mips::FCOND_OGE;
534 case ISD::SETULT: return Mips::FCOND_ULT;
535 case ISD::SETULE: return Mips::FCOND_ULE;
536 case ISD::SETUGT: return Mips::FCOND_UGT;
537 case ISD::SETUGE: return Mips::FCOND_UGE;
538 case ISD::SETUO: return Mips::FCOND_UN;
539 case ISD::SETO: return Mips::FCOND_OR;
540 case ISD::SETNE:
541 case ISD::SETONE: return Mips::FCOND_ONE;
542 case ISD::SETUEQ: return Mips::FCOND_UEQ;
543 }
544}
545
546/// This function returns true if the floating point conditional branches and
547/// conditional moves which use condition code CC should be inverted.
549 if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT)
550 return false;
551
553 "Illegal Condition Code");
554
555 return true;
556}
557
558// Creates and returns an FPCmp node from a setcc node.
559// Returns Op if setcc is not a floating point comparison.
561 // must be a SETCC node
562 if (Op.getOpcode() != ISD::SETCC && Op.getOpcode() != ISD::STRICT_FSETCC &&
563 Op.getOpcode() != ISD::STRICT_FSETCCS)
564 return Op;
565
566 SDValue LHS = Op.getOperand(0);
567
568 if (!LHS.getValueType().isFloatingPoint())
569 return Op;
570
571 SDValue RHS = Op.getOperand(1);
572 SDLoc DL(Op);
573
574 // Assume the 3rd operand is a CondCodeSDNode. Add code to check the type of
575 // node if necessary.
576 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
577
578 return DAG.getNode(MipsISD::FPCmp, DL, MVT::Glue, LHS, RHS,
579 DAG.getConstant(condCodeToFCC(CC), DL, MVT::i32));
580}
581
582// Creates and returns a CMovFPT/F node.
584 SDValue False, const SDLoc &DL) {
585 ConstantSDNode *CC = cast<ConstantSDNode>(Cond.getOperand(2));
586 bool invert = invertFPCondCodeUser((Mips::CondCode)CC->getSExtValue());
587 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32);
588
589 return DAG.getNode((invert ? MipsISD::CMovFP_F : MipsISD::CMovFP_T), DL,
590 True.getValueType(), True, FCC0, False, Cond);
591}
592
595 const MipsSubtarget &Subtarget) {
596 if (DCI.isBeforeLegalizeOps())
597 return SDValue();
598
599 SDValue SetCC = N->getOperand(0);
600
601 if ((SetCC.getOpcode() != ISD::SETCC) ||
602 !SetCC.getOperand(0).getValueType().isInteger())
603 return SDValue();
604
605 SDValue False = N->getOperand(2);
606 EVT FalseTy = False.getValueType();
607
608 if (!FalseTy.isInteger())
609 return SDValue();
610
611 // r6 selects can test canonical words directly in i64.
612 SDValue LHS = SetCC.getOperand(0);
614 if (Subtarget.hasMips64r6() && FalseTy == MVT::i64 &&
615 LHS.getOpcode() == ISD::TRUNCATE && LHS.getValueType() == MVT::i32 &&
616 LHS.getOperand(0).getValueType() == MVT::i64 &&
617 (CC == ISD::SETEQ || CC == ISD::SETNE) &&
618 isNullConstant(SetCC.getOperand(1)) &&
619 DAG.ComputeNumSignBits(LHS.getOperand(0)) > 32) {
620 SDLoc DL(N);
621 SDValue WideCC = DAG.getSetCC(DL, SetCC.getValueType(), LHS.getOperand(0),
622 DAG.getConstant(0, DL, MVT::i64), CC);
623 return DAG.getNode(ISD::SELECT, DL, FalseTy, WideCC, N->getOperand(1),
624 False);
625 }
626
628
629 // If the RHS (False) is 0, we swap the order of the operands
630 // of ISD::SELECT (obviously also inverting the condition) so that we can
631 // take advantage of conditional moves using the $0 register.
632 // Example:
633 // return (a != 0) ? x : 0;
634 // load $reg, x
635 // movz $reg, $0, a
636 if (!FalseC)
637 return SDValue();
638
639 const SDLoc DL(N);
640
641 if (!FalseC->getZExtValue()) {
643 SDValue True = N->getOperand(1);
644
645 SetCC = DAG.getSetCC(DL, SetCC.getValueType(), SetCC.getOperand(0),
646 SetCC.getOperand(1),
648
649 return DAG.getNode(ISD::SELECT, DL, FalseTy, SetCC, False, True);
650 }
651
652 // If both operands are integer constants there's a possibility that we
653 // can do some interesting optimizations.
654 SDValue True = N->getOperand(1);
656
657 if (!TrueC || !True.getValueType().isInteger())
658 return SDValue();
659
660 // We'll also ignore MVT::i64 operands as this optimizations proves
661 // to be ineffective because of the required sign extensions as the result
662 // of a SETCC operator is always MVT::i32 for non-vector types.
663 if (True.getValueType() == MVT::i64)
664 return SDValue();
665
666 int64_t Diff = TrueC->getSExtValue() - FalseC->getSExtValue();
667
668 // 1) (a < x) ? y : y-1
669 // slti $reg1, a, x
670 // addiu $reg2, $reg1, y-1
671 if (Diff == 1)
672 return DAG.getNode(ISD::ADD, DL, SetCC.getValueType(), SetCC, False);
673
674 // 2) (a < x) ? y-1 : y
675 // slti $reg1, a, x
676 // xor $reg1, $reg1, 1
677 // addiu $reg2, $reg1, y-1
678 if (Diff == -1) {
680 SetCC = DAG.getSetCC(DL, SetCC.getValueType(), SetCC.getOperand(0),
681 SetCC.getOperand(1),
683 return DAG.getNode(ISD::ADD, DL, SetCC.getValueType(), SetCC, True);
684 }
685
686 // Could not optimize.
687 return SDValue();
688}
689
692 const MipsSubtarget &Subtarget) {
693 if (DCI.isBeforeLegalizeOps())
694 return SDValue();
695
696 SDValue ValueIfTrue = N->getOperand(0), ValueIfFalse = N->getOperand(2);
697
698 ConstantSDNode *FalseC = dyn_cast<ConstantSDNode>(ValueIfFalse);
699 if (!FalseC || FalseC->getZExtValue())
700 return SDValue();
701
702 // Since RHS (False) is 0, we swap the order of the True/False operands
703 // (obviously also inverting the condition) so that we can
704 // take advantage of conditional moves using the $0 register.
705 // Example:
706 // return (a != 0) ? x : 0;
707 // load $reg, x
708 // movz $reg, $0, a
709 unsigned Opc = (N->getOpcode() == MipsISD::CMovFP_T) ? MipsISD::CMovFP_F :
710 MipsISD::CMovFP_T;
711
712 SDValue FCC = N->getOperand(1), Glue = N->getOperand(3);
713 return DAG.getNode(Opc, SDLoc(N), ValueIfFalse.getValueType(),
714 ValueIfFalse, FCC, ValueIfTrue, Glue);
715}
716
719 const MipsSubtarget &Subtarget) {
720 if (DCI.isBeforeLegalizeOps() || !Subtarget.hasExtractInsert())
721 return SDValue();
722
723 SDValue FirstOperand = N->getOperand(0);
724 unsigned FirstOperandOpc = FirstOperand.getOpcode();
725 SDValue Mask = N->getOperand(1);
726 EVT ValTy = N->getValueType(0);
727 SDLoc DL(N);
728
729 uint64_t Pos = 0;
730 unsigned SMPos, SMSize;
731 ConstantSDNode *CN;
732 SDValue NewOperand;
733 unsigned Opc;
734
735 // Op's second operand must be a shifted mask.
736 if (!(CN = dyn_cast<ConstantSDNode>(Mask)) ||
737 !isShiftedMask_64(CN->getZExtValue(), SMPos, SMSize))
738 return SDValue();
739
740 if (FirstOperandOpc == ISD::SRA || FirstOperandOpc == ISD::SRL) {
741 // Pattern match EXT.
742 // $dst = and ((sra or srl) $src , pos), (2**size - 1)
743 // => ext $dst, $src, pos, size
744
745 // The second operand of the shift must be an immediate.
746 if (!(CN = dyn_cast<ConstantSDNode>(FirstOperand.getOperand(1))))
747 return SDValue();
748
749 Pos = CN->getZExtValue();
750
751 // Return if the shifted mask does not start at bit 0 or the sum of its size
752 // and Pos exceeds the word's size.
753 if (SMPos != 0 || Pos + SMSize > ValTy.getSizeInBits())
754 return SDValue();
755
756 Opc = MipsISD::Ext;
757 NewOperand = FirstOperand.getOperand(0);
758 } else if (FirstOperandOpc == ISD::SHL && Subtarget.hasCnMips()) {
759 // Pattern match CINS.
760 // $dst = and (shl $src , pos), mask
761 // => cins $dst, $src, pos, size
762 // mask is a shifted mask with consecutive 1's, pos = shift amount,
763 // size = population count.
764
765 // The second operand of the shift must be an immediate.
766 if (!(CN = dyn_cast<ConstantSDNode>(FirstOperand.getOperand(1))))
767 return SDValue();
768
769 Pos = CN->getZExtValue();
770
771 if (SMPos != Pos || Pos >= ValTy.getSizeInBits() || SMSize >= 32 ||
772 Pos + SMSize > ValTy.getSizeInBits())
773 return SDValue();
774
775 NewOperand = FirstOperand.getOperand(0);
776 // SMSize is 'location' (position) in this case, not size.
777 SMSize--;
778 Opc = MipsISD::CIns;
779 } else {
780 // Pattern match EXT.
781 // $dst = and $src, (2**size - 1) , if size > 16
782 // => ext $dst, $src, pos, size , pos = 0
783
784 // If the mask is <= 0xffff, andi can be used instead.
785 if (CN->getZExtValue() <= 0xffff)
786 return SDValue();
787
788 // Return if the mask doesn't start at position 0.
789 if (SMPos)
790 return SDValue();
791
792 Opc = MipsISD::Ext;
793 NewOperand = FirstOperand;
794 }
795 return DAG.getNode(Opc, DL, ValTy, NewOperand,
796 DAG.getConstant(Pos, DL, MVT::i32),
797 DAG.getConstant(SMSize, DL, MVT::i32));
798}
799
802 const MipsSubtarget &Subtarget) {
803 if (DCI.isBeforeLegalizeOps() || !Subtarget.hasExtractInsert())
804 return SDValue();
805
806 SDValue FirstOperand = N->getOperand(0), SecondOperand = N->getOperand(1);
807 unsigned SMPos0, SMSize0, SMPos1, SMSize1;
808 ConstantSDNode *CN, *CN1;
809
810 if ((FirstOperand.getOpcode() == ISD::AND &&
811 SecondOperand.getOpcode() == ISD::SHL) ||
812 (FirstOperand.getOpcode() == ISD::SHL &&
813 SecondOperand.getOpcode() == ISD::AND)) {
814 // Pattern match INS.
815 // $dst = or (and $src1, (2**size0 - 1)), (shl $src2, size0)
816 // ==> ins $src1, $src2, pos, size, pos = size0, size = 32 - pos;
817 // Or:
818 // $dst = or (shl $src2, size0), (and $src1, (2**size0 - 1))
819 // ==> ins $src1, $src2, pos, size, pos = size0, size = 32 - pos;
820 SDValue AndOperand0 = FirstOperand.getOpcode() == ISD::AND
821 ? FirstOperand.getOperand(0)
822 : SecondOperand.getOperand(0);
823 SDValue ShlOperand0 = FirstOperand.getOpcode() == ISD::AND
824 ? SecondOperand.getOperand(0)
825 : FirstOperand.getOperand(0);
826 SDValue AndMask = FirstOperand.getOpcode() == ISD::AND
827 ? FirstOperand.getOperand(1)
828 : SecondOperand.getOperand(1);
829 if (!(CN = dyn_cast<ConstantSDNode>(AndMask)) ||
830 !isShiftedMask_64(CN->getZExtValue(), SMPos0, SMSize0))
831 return SDValue();
832
833 SDValue ShlShift = FirstOperand.getOpcode() == ISD::AND
834 ? SecondOperand.getOperand(1)
835 : FirstOperand.getOperand(1);
836 if (!(CN = dyn_cast<ConstantSDNode>(ShlShift)))
837 return SDValue();
838 uint64_t ShlShiftValue = CN->getZExtValue();
839
840 if (SMPos0 != 0 || SMSize0 != ShlShiftValue)
841 return SDValue();
842
843 SDLoc DL(N);
844 EVT ValTy = N->getValueType(0);
845 SMPos1 = ShlShiftValue;
846 assert(SMPos1 < ValTy.getSizeInBits());
847 SMSize1 = (ValTy == MVT::i64 ? 64 : 32) - SMPos1;
848 return DAG.getNode(MipsISD::Ins, DL, ValTy, ShlOperand0,
849 DAG.getConstant(SMPos1, DL, MVT::i32),
850 DAG.getConstant(SMSize1, DL, MVT::i32), AndOperand0);
851 }
852
853 // See if Op's first operand matches (and $src1 , mask0).
854 if (FirstOperand.getOpcode() != ISD::AND)
855 return SDValue();
856
857 // Pattern match INS.
858 // $dst = or (and $src1 , mask0), (and (shl $src, pos), mask1),
859 // where mask1 = (2**size - 1) << pos, mask0 = ~mask1
860 // => ins $dst, $src, size, pos, $src1
861 if (!(CN = dyn_cast<ConstantSDNode>(FirstOperand.getOperand(1))) ||
862 !isShiftedMask_64(~CN->getSExtValue(), SMPos0, SMSize0))
863 return SDValue();
864
865 // See if Op's second operand matches (and (shl $src, pos), mask1).
866 if (SecondOperand.getOpcode() == ISD::AND &&
867 SecondOperand.getOperand(0).getOpcode() == ISD::SHL) {
868
869 if (!(CN = dyn_cast<ConstantSDNode>(SecondOperand.getOperand(1))) ||
870 !isShiftedMask_64(CN->getZExtValue(), SMPos1, SMSize1))
871 return SDValue();
872
873 // The shift masks must have the same position and size.
874 if (SMPos0 != SMPos1 || SMSize0 != SMSize1)
875 return SDValue();
876
877 SDValue Shl = SecondOperand.getOperand(0);
878
879 if (!(CN = dyn_cast<ConstantSDNode>(Shl.getOperand(1))))
880 return SDValue();
881
882 unsigned Shamt = CN->getZExtValue();
883
884 // Return if the shift amount and the first bit position of mask are not the
885 // same.
886 EVT ValTy = N->getValueType(0);
887 if ((Shamt != SMPos0) || (SMPos0 + SMSize0 > ValTy.getSizeInBits()))
888 return SDValue();
889
890 SDLoc DL(N);
891 return DAG.getNode(MipsISD::Ins, DL, ValTy, Shl.getOperand(0),
892 DAG.getConstant(SMPos0, DL, MVT::i32),
893 DAG.getConstant(SMSize0, DL, MVT::i32),
894 FirstOperand.getOperand(0));
895 } else {
896 // Pattern match DINS.
897 // $dst = or (and $src, mask0), mask1
898 // where mask0 = maskTrailingOnes<uint64_t>(SMSize0) << SMPos0
899 // => dins $dst, $src, pos, size
900 uint64_t Mask = maskTrailingOnes<uint64_t>(SMSize0) << SMPos0;
901 if (~CN->getSExtValue() == (int64_t)Mask &&
902 ((SMSize0 + SMPos0 <= 64 && Subtarget.hasMips64r2()) ||
903 (SMSize0 + SMPos0 <= 32))) {
904 // Check if AND instruction has constant as argument
905 bool isConstCase = SecondOperand.getOpcode() != ISD::AND;
906 if (SecondOperand.getOpcode() == ISD::AND) {
907 if (!(CN1 = dyn_cast<ConstantSDNode>(SecondOperand->getOperand(1))))
908 return SDValue();
909 } else {
910 if (!(CN1 = dyn_cast<ConstantSDNode>(N->getOperand(1))))
911 return SDValue();
912 }
913 // Don't generate INS if constant OR operand doesn't fit into bits
914 // cleared by constant AND operand.
915 if (CN->getSExtValue() & CN1->getSExtValue())
916 return SDValue();
917
918 SDLoc DL(N);
919 EVT ValTy = N->getOperand(0)->getValueType(0);
920 SDValue Const1;
921 SDValue SrlX;
922 if (!isConstCase) {
923 Const1 = DAG.getConstant(SMPos0, DL, MVT::i32);
924 SrlX = DAG.getNode(ISD::SRL, DL, SecondOperand->getValueType(0),
925 SecondOperand, Const1);
926 }
927 return DAG.getNode(
928 MipsISD::Ins, DL, N->getValueType(0),
929 isConstCase
930 ? DAG.getSignedConstant(CN1->getSExtValue() >> SMPos0, DL, ValTy)
931 : SrlX,
932 DAG.getConstant(SMPos0, DL, MVT::i32),
933 DAG.getConstant(ValTy.getSizeInBits() / 8 < 8 ? SMSize0 & 31
934 : SMSize0,
935 DL, MVT::i32),
936 FirstOperand->getOperand(0));
937 }
938 return SDValue();
939 }
940}
941
943 const MipsSubtarget &Subtarget) {
944 // ROOTNode must have a multiplication as an operand for the match to be
945 // successful.
946 if (ROOTNode->getOperand(0).getOpcode() != ISD::MUL &&
947 ROOTNode->getOperand(1).getOpcode() != ISD::MUL)
948 return SDValue();
949
950 // In the case where we have a multiplication as the left operand of
951 // of a subtraction, we can't combine into a MipsISD::MSub node as the
952 // the instruction definition of msub(u) places the multiplication on
953 // on the right.
954 if (ROOTNode->getOpcode() == ISD::SUB &&
955 ROOTNode->getOperand(0).getOpcode() == ISD::MUL)
956 return SDValue();
957
958 // We don't handle vector types here.
959 if (ROOTNode->getValueType(0).isVector())
960 return SDValue();
961
962 // For MIPS64, madd / msub instructions are inefficent to use with 64 bit
963 // arithmetic. E.g.
964 // (add (mul a b) c) =>
965 // let res = (madd (mthi (drotr c 32))x(mtlo c) a b) in
966 // MIPS64: (or (dsll (mfhi res) 32) (dsrl (dsll (mflo res) 32) 32)
967 // or
968 // MIPS64R2: (dins (mflo res) (mfhi res) 32 32)
969 //
970 // The overhead of setting up the Hi/Lo registers and reassembling the
971 // result makes this a dubious optimzation for MIPS64. The core of the
972 // problem is that Hi/Lo contain the upper and lower 32 bits of the
973 // operand and result.
974 //
975 // It requires a chain of 4 add/mul for MIPS64R2 to get better code
976 // density than doing it naively, 5 for MIPS64. Additionally, using
977 // madd/msub on MIPS64 requires the operands actually be 32 bit sign
978 // extended operands, not true 64 bit values.
979 //
980 // FIXME: For the moment, disable this completely for MIPS64.
981 if (Subtarget.hasMips64())
982 return SDValue();
983
984 SDValue Mult = ROOTNode->getOperand(0).getOpcode() == ISD::MUL
985 ? ROOTNode->getOperand(0)
986 : ROOTNode->getOperand(1);
987
988 SDValue AddOperand = ROOTNode->getOperand(0).getOpcode() == ISD::MUL
989 ? ROOTNode->getOperand(1)
990 : ROOTNode->getOperand(0);
991
992 // Transform this to a MADD only if the user of this node is the add.
993 // If there are other users of the mul, this function returns here.
994 if (!Mult.hasOneUse())
995 return SDValue();
996
997 // maddu and madd are unusual instructions in that on MIPS64 bits 63..31
998 // must be in canonical form, i.e. sign extended. For MIPS32, the operands
999 // of the multiply must have 32 or more sign bits, otherwise we cannot
1000 // perform this optimization. We have to check this here as we're performing
1001 // this optimization pre-legalization.
1002 SDValue MultLHS = Mult->getOperand(0);
1003 SDValue MultRHS = Mult->getOperand(1);
1004
1005 bool IsSigned = MultLHS->getOpcode() == ISD::SIGN_EXTEND &&
1006 MultRHS->getOpcode() == ISD::SIGN_EXTEND;
1007 bool IsUnsigned = MultLHS->getOpcode() == ISD::ZERO_EXTEND &&
1008 MultRHS->getOpcode() == ISD::ZERO_EXTEND;
1009
1010 if (!IsSigned && !IsUnsigned)
1011 return SDValue();
1012
1013 // Initialize accumulator.
1014 SDLoc DL(ROOTNode);
1015 SDValue BottomHalf, TopHalf;
1016 std::tie(BottomHalf, TopHalf) =
1017 CurDAG.SplitScalar(AddOperand, DL, MVT::i32, MVT::i32);
1018 SDValue ACCIn =
1019 CurDAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, BottomHalf, TopHalf);
1020
1021 // Create MipsMAdd(u) / MipsMSub(u) node.
1022 bool IsAdd = ROOTNode->getOpcode() == ISD::ADD;
1023 unsigned Opcode = IsAdd ? (IsUnsigned ? MipsISD::MAddu : MipsISD::MAdd)
1024 : (IsUnsigned ? MipsISD::MSubu : MipsISD::MSub);
1025 SDValue MAddOps[3] = {
1026 CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Mult->getOperand(0)),
1027 CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Mult->getOperand(1)), ACCIn};
1028 SDValue MAdd = CurDAG.getNode(Opcode, DL, MVT::Untyped, MAddOps);
1029
1030 SDValue ResLo = CurDAG.getNode(MipsISD::MFLO, DL, MVT::i32, MAdd);
1031 SDValue ResHi = CurDAG.getNode(MipsISD::MFHI, DL, MVT::i32, MAdd);
1032 SDValue Combined =
1033 CurDAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, ResLo, ResHi);
1034 return Combined;
1035}
1036
1039 const MipsSubtarget &Subtarget) {
1040 // (sub v0 (mul v1, v2)) => (msub v1, v2, v0)
1041 if (DCI.isBeforeLegalizeOps()) {
1042 if (Subtarget.hasMips32() && !Subtarget.hasMips32r6() &&
1043 !Subtarget.inMips16Mode() && N->getValueType(0) == MVT::i64)
1044 return performMADD_MSUBCombine(N, DAG, Subtarget);
1045
1046 return SDValue();
1047 }
1048
1049 return SDValue();
1050}
1051
1054 const MipsSubtarget &Subtarget) {
1055 // (add v0 (mul v1, v2)) => (madd v1, v2, v0)
1056 if (DCI.isBeforeLegalizeOps()) {
1057 if (Subtarget.hasMips32() && !Subtarget.hasMips32r6() &&
1058 !Subtarget.inMips16Mode() && N->getValueType(0) == MVT::i64)
1059 return performMADD_MSUBCombine(N, DAG, Subtarget);
1060
1061 return SDValue();
1062 }
1063
1064 // When loading from a jump table, push the Lo node to the position that
1065 // allows folding it into a load immediate.
1066 // (add v0, (add v1, abs_lo(tjt))) => (add (add v0, v1), abs_lo(tjt))
1067 // (add (add abs_lo(tjt), v1), v0) => (add (add v0, v1), abs_lo(tjt))
1068 SDValue InnerAdd = N->getOperand(1);
1069 SDValue Index = N->getOperand(0);
1070 if (InnerAdd.getOpcode() != ISD::ADD)
1071 std::swap(InnerAdd, Index);
1072 if (InnerAdd.getOpcode() != ISD::ADD)
1073 return SDValue();
1074
1075 SDValue Lo = InnerAdd.getOperand(0);
1076 SDValue Other = InnerAdd.getOperand(1);
1077 if (Lo.getOpcode() != MipsISD::Lo)
1078 std::swap(Lo, Other);
1079
1080 if ((Lo.getOpcode() != MipsISD::Lo) ||
1081 (Lo.getOperand(0).getOpcode() != ISD::TargetJumpTable))
1082 return SDValue();
1083
1084 EVT ValTy = N->getValueType(0);
1085 SDLoc DL(N);
1086
1087 SDValue Add1 = DAG.getNode(ISD::ADD, DL, ValTy, Index, Other);
1088 return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo);
1089}
1090
1093 const MipsSubtarget &Subtarget) {
1094 // Pattern match CINS.
1095 // $dst = shl (and $src , imm), pos
1096 // => cins $dst, $src, pos, size
1097
1098 if (DCI.isBeforeLegalizeOps() || !Subtarget.hasCnMips())
1099 return SDValue();
1100
1101 SDValue FirstOperand = N->getOperand(0);
1102 unsigned FirstOperandOpc = FirstOperand.getOpcode();
1103 SDValue SecondOperand = N->getOperand(1);
1104 EVT ValTy = N->getValueType(0);
1105 SDLoc DL(N);
1106
1107 uint64_t Pos = 0;
1108 unsigned SMPos, SMSize;
1109 ConstantSDNode *CN;
1110 SDValue NewOperand;
1111
1112 // The second operand of the shift must be an immediate.
1113 if (!(CN = dyn_cast<ConstantSDNode>(SecondOperand)))
1114 return SDValue();
1115
1116 Pos = CN->getZExtValue();
1117
1118 if (Pos >= ValTy.getSizeInBits())
1119 return SDValue();
1120
1121 if (FirstOperandOpc != ISD::AND)
1122 return SDValue();
1123
1124 // AND's second operand must be a shifted mask.
1125 if (!(CN = dyn_cast<ConstantSDNode>(FirstOperand.getOperand(1))) ||
1126 !isShiftedMask_64(CN->getZExtValue(), SMPos, SMSize))
1127 return SDValue();
1128
1129 // Return if the shifted mask does not start at bit 0 or the sum of its size
1130 // and Pos exceeds the word's size.
1131 if (SMPos != 0 || SMSize > 32 || Pos + SMSize > ValTy.getSizeInBits())
1132 return SDValue();
1133
1134 NewOperand = FirstOperand.getOperand(0);
1135 // SMSize is 'location' (position) in this case, not size.
1136 SMSize--;
1137
1138 return DAG.getNode(MipsISD::CIns, DL, ValTy, NewOperand,
1139 DAG.getConstant(Pos, DL, MVT::i32),
1140 DAG.getConstant(SMSize, DL, MVT::i32));
1141}
1142
1145 const MipsSubtarget &Subtarget) {
1146 if (DCI.Level != AfterLegalizeDAG || !Subtarget.isGP64bit()) {
1147 return SDValue();
1148 }
1149
1150 SDValue N0 = N->getOperand(0);
1151 EVT VT = N->getValueType(0);
1152
1153 // Widen AND/OR on canonical words; sign-extended constants preserve this
1154 // form. Require one use to avoid duplicating shared operations and constants.
1155 if (VT == MVT::i64 && N0.getValueType() == MVT::i32 && N0.hasOneUse() &&
1156 (N0.getOpcode() == ISD::AND || N0.getOpcode() == ISD::OR) &&
1157 N0.getOperand(0).getOpcode() == ISD::TRUNCATE &&
1159 SDValue Src = N0.getOperand(0).getOperand(0);
1160 if (Src.getValueType() == MVT::i64 && DAG.ComputeNumSignBits(Src) > 32) {
1161 int64_t Imm = cast<ConstantSDNode>(N0.getOperand(1))->getSExtValue();
1162 return DAG.getNode(N0.getOpcode(), SDLoc(N), VT, Src,
1163 DAG.getConstant(Imm, SDLoc(N), VT));
1164 }
1165 }
1166
1167 // Pattern match XOR.
1168 // $dst = sign_extend (xor (trunc $src, i32), imm)
1169 // => $dst = xor (signext_inreg $src, i32), imm
1170 if (N0.getOpcode() == ISD::XOR &&
1171 N0.getOperand(0).getOpcode() == ISD::TRUNCATE &&
1172 N0.getOperand(1).getOpcode() == ISD::Constant) {
1173 SDValue TruncateSource = N0.getOperand(0).getOperand(0);
1174 auto *ConstantOperand = dyn_cast<ConstantSDNode>(N0->getOperand(1));
1175
1176 SDValue FirstOperand =
1177 DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N0), VT, TruncateSource,
1178 DAG.getValueType(N0.getOperand(0).getValueType()));
1179
1180 int64_t ConstImm = ConstantOperand->getSExtValue();
1181 return DAG.getNode(ISD::XOR, SDLoc(N0), VT, FirstOperand,
1182 DAG.getConstant(ConstImm, SDLoc(N0), VT));
1183 }
1184
1185 return SDValue();
1186}
1187
1189 const {
1190 SelectionDAG &DAG = DCI.DAG;
1191 unsigned Opc = N->getOpcode();
1192
1193 switch (Opc) {
1194 default: break;
1195 case ISD::SDIVREM:
1196 case ISD::UDIVREM:
1197 return performDivRemCombine(N, DAG, DCI, Subtarget);
1198 case ISD::SELECT:
1199 return performSELECTCombine(N, DAG, DCI, Subtarget);
1200 case MipsISD::CMovFP_F:
1201 case MipsISD::CMovFP_T:
1202 return performCMovFPCombine(N, DAG, DCI, Subtarget);
1203 case ISD::AND:
1204 return performANDCombine(N, DAG, DCI, Subtarget);
1205 case ISD::OR:
1206 return performORCombine(N, DAG, DCI, Subtarget);
1207 case ISD::ADD:
1208 return performADDCombine(N, DAG, DCI, Subtarget);
1209 case ISD::SHL:
1210 return performSHLCombine(N, DAG, DCI, Subtarget);
1211 case ISD::SUB:
1212 return performSUBCombine(N, DAG, DCI, Subtarget);
1213 case ISD::SIGN_EXTEND:
1214 return performSignExtendCombine(N, DAG, DCI, Subtarget);
1215 }
1216
1217 return SDValue();
1218}
1219
1221 return Subtarget.hasMips32();
1222}
1223
1225 return Subtarget.hasMips32();
1226}
1227
1229 // We can use ANDI+SLTIU as a bit test. Y contains the bit position.
1230 // For MIPSR2 or later, we may be able to use the `ext` instruction or its
1231 // double-word variants.
1232 if (auto *C = dyn_cast<ConstantSDNode>(Y))
1233 return C->getAPIntValue().ule(15);
1234
1235 return false;
1236}
1237
1239 const SDNode *N) const {
1240 assert(((N->getOpcode() == ISD::SHL &&
1241 N->getOperand(0).getOpcode() == ISD::SRL) ||
1242 (N->getOpcode() == ISD::SRL &&
1243 N->getOperand(0).getOpcode() == ISD::SHL)) &&
1244 "Expected shift-shift mask");
1245
1246 if (N->getOperand(0).getValueType().isVector())
1247 return false;
1248 return true;
1249}
1250
1251void
1257
1260{
1261 switch (Op.getOpcode())
1262 {
1263 case ISD::BRCOND: return lowerBRCOND(Op, DAG);
1264 case ISD::ConstantPool: return lowerConstantPool(Op, DAG);
1265 case ISD::GlobalAddress: return lowerGlobalAddress(Op, DAG);
1266 case ISD::BlockAddress: return lowerBlockAddress(Op, DAG);
1267 case ISD::GlobalTLSAddress: return lowerGlobalTLSAddress(Op, DAG);
1268 case ISD::JumpTable: return lowerJumpTable(Op, DAG);
1269 case ISD::SELECT: return lowerSELECT(Op, DAG);
1270 case ISD::SETCC: return lowerSETCC(Op, DAG);
1271 case ISD::STRICT_FSETCC:
1273 return lowerFSETCC(Op, DAG);
1274 case ISD::VASTART: return lowerVASTART(Op, DAG);
1275 case ISD::VAARG: return lowerVAARG(Op, DAG);
1276 case ISD::FCOPYSIGN: return lowerFCOPYSIGN(Op, DAG);
1277 case ISD::FABS: return lowerFABS(Op, DAG);
1278 case ISD::FCANONICALIZE:
1279 return lowerFCANONICALIZE(Op, DAG);
1280 case ISD::FRAMEADDR: return lowerFRAMEADDR(Op, DAG);
1281 case ISD::RETURNADDR: return lowerRETURNADDR(Op, DAG);
1282 case ISD::EH_RETURN: return lowerEH_RETURN(Op, DAG);
1283 case ISD::ATOMIC_FENCE: return lowerATOMIC_FENCE(Op, DAG);
1284 case ISD::SHL_PARTS: return lowerShiftLeftParts(Op, DAG);
1285 case ISD::SRA_PARTS: return lowerShiftRightParts(Op, DAG, true);
1286 case ISD::SRL_PARTS: return lowerShiftRightParts(Op, DAG, false);
1287 case ISD::LOAD: return lowerLOAD(Op, DAG);
1288 case ISD::STORE: return lowerSTORE(Op, DAG);
1289 case ISD::EH_DWARF_CFA: return lowerEH_DWARF_CFA(Op, DAG);
1292 return lowerSTRICT_FP_TO_INT(Op, DAG);
1293 case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
1295 return lowerREADCYCLECOUNTER(Op, DAG);
1296 case ISD::ConstantFP:
1297 return lowerConstantFP(Op, DAG);
1298 }
1299 return SDValue();
1300}
1301
1302//===----------------------------------------------------------------------===//
1303// Lower helper functions
1304//===----------------------------------------------------------------------===//
1305
1306// addLiveIn - This helper function adds the specified physical register to the
1307// MachineFunction as a live in value. It also creates a corresponding
1308// virtual register for it.
1309static unsigned
1310addLiveIn(MachineFunction &MF, unsigned PReg, const TargetRegisterClass *RC)
1311{
1313 MF.getRegInfo().addLiveIn(PReg, VReg);
1314 return VReg;
1315}
1316
1317static MachineBasicBlock *
1318insertDivByZeroTrap(const MipsMCOptions &MCCLOpts, MachineInstr &MI,
1320 bool Is64Bit, const DivByZeroTrapKind TrapKind) {
1321 if (MCCLOpts.mno_check_zero_division)
1322 return &MBB;
1323
1324 MachineOperand &Divisor = MI.getOperand(2);
1325
1326 if (TrapKind == DivByZeroTrapKind::Break) {
1327 // Build instructions:
1328 // MBB:
1329 // bnez $divisor, $zero, SinkMBB
1330 // MI $dst, $dividend, $divisor (delay slot)
1331 //
1332 // BreakMBB:
1333 // break 7
1334 //
1335 // SinkMBB:
1336 // fallthrough
1337 const DebugLoc &DL = MI.getDebugLoc();
1338 const BasicBlock *BB = MBB.getBasicBlock();
1339
1340 // Place all instructions after MI into SinkMBB.
1341 MachineBasicBlock *SinkMBB = MBB.splitAt(MI, true);
1342
1343 // BreakMBB setup.
1344 MachineFunction *MF = MBB.getParent();
1345 MachineBasicBlock *BreakMBB = MF->CreateMachineBasicBlock(BB);
1346 MF->insert(++MBB.getIterator(), BreakMBB);
1347
1348 // Place the branch at the end of the block. Since MI is defined as having
1349 // no side effects in TableGen, the filler will place it in the branch delay
1350 // slot.
1351 BuildMI(&MBB, DL, TII.get(Mips::BNE))
1352 .addReg(Divisor.getReg(), getKillRegState(Divisor.isKill()))
1353 .addReg(Mips::R0)
1354 .addMBB(SinkMBB);
1355
1356 // BreakMBB: break 7
1357 BuildMI(BreakMBB, DL, TII.get(Mips::BREAK)).addImm(7).addImm(0);
1358
1359 MBB.addSuccessor(BreakMBB);
1360 BreakMBB->addSuccessor(SinkMBB);
1361
1362 Divisor.setIsKill(false);
1363
1364 return SinkMBB;
1365 }
1366
1367 // Insert instruction "teq $divisor_reg, $zero, 7".
1370 MIB = BuildMI(MBB, std::next(I), MI.getDebugLoc(),
1371 TII.get(TrapKind == DivByZeroTrapKind::TeqMM ? Mips::TEQ_MM
1372 : Mips::TEQ))
1373 .addReg(Divisor.getReg(), getKillRegState(Divisor.isKill()))
1374 .addReg(Mips::R0)
1375 .addImm(7);
1376
1377 // Use the 32-bit sub-register if this is a 64-bit division.
1378 if (Is64Bit)
1379 MIB->getOperand(0).setSubReg(Mips::sub_32);
1380
1381 // Clear Divisor's kill flag.
1382 Divisor.setIsKill(false);
1383
1384 // We would normally delete the original instruction here but in this case
1385 // we only needed to inject an additional instruction rather than replace it.
1386
1387 return &MBB;
1388}
1389
1392 MachineBasicBlock *BB) const {
1393 switch (MI.getOpcode()) {
1394 default:
1395 llvm_unreachable("Unexpected instr type to insert");
1396 case Mips::ATOMIC_LOAD_ADD_I8:
1397 return emitAtomicBinaryPartword(MI, BB, 1);
1398 case Mips::ATOMIC_LOAD_ADD_I16:
1399 return emitAtomicBinaryPartword(MI, BB, 2);
1400 case Mips::ATOMIC_LOAD_ADD_I32:
1401 return emitAtomicBinary(MI, BB);
1402 case Mips::ATOMIC_LOAD_ADD_I64:
1403 return emitAtomicBinary(MI, BB);
1404
1405 case Mips::ATOMIC_LOAD_AND_I8:
1406 return emitAtomicBinaryPartword(MI, BB, 1);
1407 case Mips::ATOMIC_LOAD_AND_I16:
1408 return emitAtomicBinaryPartword(MI, BB, 2);
1409 case Mips::ATOMIC_LOAD_AND_I32:
1410 return emitAtomicBinary(MI, BB);
1411 case Mips::ATOMIC_LOAD_AND_I64:
1412 return emitAtomicBinary(MI, BB);
1413
1414 case Mips::ATOMIC_LOAD_OR_I8:
1415 return emitAtomicBinaryPartword(MI, BB, 1);
1416 case Mips::ATOMIC_LOAD_OR_I16:
1417 return emitAtomicBinaryPartword(MI, BB, 2);
1418 case Mips::ATOMIC_LOAD_OR_I32:
1419 return emitAtomicBinary(MI, BB);
1420 case Mips::ATOMIC_LOAD_OR_I64:
1421 return emitAtomicBinary(MI, BB);
1422
1423 case Mips::ATOMIC_LOAD_XOR_I8:
1424 return emitAtomicBinaryPartword(MI, BB, 1);
1425 case Mips::ATOMIC_LOAD_XOR_I16:
1426 return emitAtomicBinaryPartword(MI, BB, 2);
1427 case Mips::ATOMIC_LOAD_XOR_I32:
1428 return emitAtomicBinary(MI, BB);
1429 case Mips::ATOMIC_LOAD_XOR_I64:
1430 return emitAtomicBinary(MI, BB);
1431
1432 case Mips::ATOMIC_LOAD_NAND_I8:
1433 return emitAtomicBinaryPartword(MI, BB, 1);
1434 case Mips::ATOMIC_LOAD_NAND_I16:
1435 return emitAtomicBinaryPartword(MI, BB, 2);
1436 case Mips::ATOMIC_LOAD_NAND_I32:
1437 return emitAtomicBinary(MI, BB);
1438 case Mips::ATOMIC_LOAD_NAND_I64:
1439 return emitAtomicBinary(MI, BB);
1440
1441 case Mips::ATOMIC_LOAD_SUB_I8:
1442 return emitAtomicBinaryPartword(MI, BB, 1);
1443 case Mips::ATOMIC_LOAD_SUB_I16:
1444 return emitAtomicBinaryPartword(MI, BB, 2);
1445 case Mips::ATOMIC_LOAD_SUB_I32:
1446 return emitAtomicBinary(MI, BB);
1447 case Mips::ATOMIC_LOAD_SUB_I64:
1448 return emitAtomicBinary(MI, BB);
1449
1450 case Mips::ATOMIC_SWAP_I8:
1451 return emitAtomicBinaryPartword(MI, BB, 1);
1452 case Mips::ATOMIC_SWAP_I16:
1453 return emitAtomicBinaryPartword(MI, BB, 2);
1454 case Mips::ATOMIC_SWAP_I32:
1455 return emitAtomicBinary(MI, BB);
1456 case Mips::ATOMIC_SWAP_I64:
1457 return emitAtomicBinary(MI, BB);
1458
1459 case Mips::ATOMIC_CMP_SWAP_I8:
1460 return emitAtomicCmpSwapPartword(MI, BB, 1);
1461 case Mips::ATOMIC_CMP_SWAP_I16:
1462 return emitAtomicCmpSwapPartword(MI, BB, 2);
1463 case Mips::ATOMIC_CMP_SWAP_I32:
1464 return emitAtomicCmpSwap(MI, BB);
1465 case Mips::ATOMIC_CMP_SWAP_I64:
1466 return emitAtomicCmpSwap(MI, BB);
1467
1468 case Mips::ATOMIC_LOAD_MIN_I8:
1469 return emitAtomicBinaryPartword(MI, BB, 1);
1470 case Mips::ATOMIC_LOAD_MIN_I16:
1471 return emitAtomicBinaryPartword(MI, BB, 2);
1472 case Mips::ATOMIC_LOAD_MIN_I32:
1473 return emitAtomicBinary(MI, BB);
1474 case Mips::ATOMIC_LOAD_MIN_I64:
1475 return emitAtomicBinary(MI, BB);
1476
1477 case Mips::ATOMIC_LOAD_MAX_I8:
1478 return emitAtomicBinaryPartword(MI, BB, 1);
1479 case Mips::ATOMIC_LOAD_MAX_I16:
1480 return emitAtomicBinaryPartword(MI, BB, 2);
1481 case Mips::ATOMIC_LOAD_MAX_I32:
1482 return emitAtomicBinary(MI, BB);
1483 case Mips::ATOMIC_LOAD_MAX_I64:
1484 return emitAtomicBinary(MI, BB);
1485
1486 case Mips::ATOMIC_LOAD_UMIN_I8:
1487 return emitAtomicBinaryPartword(MI, BB, 1);
1488 case Mips::ATOMIC_LOAD_UMIN_I16:
1489 return emitAtomicBinaryPartword(MI, BB, 2);
1490 case Mips::ATOMIC_LOAD_UMIN_I32:
1491 return emitAtomicBinary(MI, BB);
1492 case Mips::ATOMIC_LOAD_UMIN_I64:
1493 return emitAtomicBinary(MI, BB);
1494
1495 case Mips::ATOMIC_LOAD_UMAX_I8:
1496 return emitAtomicBinaryPartword(MI, BB, 1);
1497 case Mips::ATOMIC_LOAD_UMAX_I16:
1498 return emitAtomicBinaryPartword(MI, BB, 2);
1499 case Mips::ATOMIC_LOAD_UMAX_I32:
1500 return emitAtomicBinary(MI, BB);
1501 case Mips::ATOMIC_LOAD_UMAX_I64:
1502 return emitAtomicBinary(MI, BB);
1503
1504 case Mips::PseudoSDIV:
1505 case Mips::PseudoUDIV:
1506 case Mips::DIV:
1507 case Mips::DIVU:
1508 case Mips::MOD:
1509 case Mips::MODU: {
1510 const DivByZeroTrapKind TrapKind = !Subtarget.hasMips2()
1513 return insertDivByZeroTrap(Subtarget.getMCCLOpts(), MI, *BB,
1514 *Subtarget.getInstrInfo(), false, TrapKind);
1515 }
1516 case Mips::SDIV_MM_Pseudo:
1517 case Mips::UDIV_MM_Pseudo:
1518 case Mips::SDIV_MM:
1519 case Mips::UDIV_MM:
1520 case Mips::DIV_MMR6:
1521 case Mips::DIVU_MMR6:
1522 case Mips::MOD_MMR6:
1523 case Mips::MODU_MMR6:
1524 return insertDivByZeroTrap(Subtarget.getMCCLOpts(), MI, *BB,
1525 *Subtarget.getInstrInfo(), false,
1527 case Mips::PseudoDSDIV:
1528 case Mips::PseudoDUDIV:
1529 case Mips::DDIV:
1530 case Mips::DDIVU:
1531 case Mips::DMOD:
1532 case Mips::DMODU:
1533 return insertDivByZeroTrap(Subtarget.getMCCLOpts(), MI, *BB,
1534 *Subtarget.getInstrInfo(), true,
1536
1537 case Mips::PseudoSELECT_I:
1538 case Mips::PseudoSELECT_I64:
1539 case Mips::PseudoSELECT_S:
1540 case Mips::PseudoSELECT_D32:
1541 case Mips::PseudoSELECT_D64:
1542 return emitPseudoSELECT(MI, BB, false, Mips::BNE);
1543 case Mips::PseudoSELECTFP_F_I:
1544 case Mips::PseudoSELECTFP_F_I64:
1545 case Mips::PseudoSELECTFP_F_S:
1546 case Mips::PseudoSELECTFP_F_D32:
1547 case Mips::PseudoSELECTFP_F_D64:
1548 return emitPseudoSELECT(MI, BB, true, Mips::BC1F);
1549 case Mips::PseudoSELECTFP_T_I:
1550 case Mips::PseudoSELECTFP_T_I64:
1551 case Mips::PseudoSELECTFP_T_S:
1552 case Mips::PseudoSELECTFP_T_D32:
1553 case Mips::PseudoSELECTFP_T_D64:
1554 return emitPseudoSELECT(MI, BB, true, Mips::BC1T);
1555 case Mips::PseudoD_SELECT_I:
1556 case Mips::PseudoD_SELECT_I64:
1557 return emitPseudoD_SELECT(MI, BB);
1558 case Mips::LDR_W:
1559 return emitLDR_W(MI, BB);
1560 case Mips::LDR_D:
1561 return emitLDR_D(MI, BB);
1562 case Mips::STR_W:
1563 return emitSTR_W(MI, BB);
1564 case Mips::STR_D:
1565 return emitSTR_D(MI, BB);
1566 }
1567}
1568
1569// This function also handles Mips::ATOMIC_SWAP_I32 (when BinOpcode == 0), and
1570// Mips::ATOMIC_LOAD_NAND_I32 (when Nand == true)
1572MipsTargetLowering::emitAtomicBinary(MachineInstr &MI,
1573 MachineBasicBlock *BB) const {
1574
1575 MachineFunction *MF = BB->getParent();
1576 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1578 DebugLoc DL = MI.getDebugLoc();
1579
1580 unsigned AtomicOp;
1581 bool NeedsAdditionalReg = false;
1582 switch (MI.getOpcode()) {
1583 case Mips::ATOMIC_LOAD_ADD_I32:
1584 AtomicOp = Mips::ATOMIC_LOAD_ADD_I32_POSTRA;
1585 break;
1586 case Mips::ATOMIC_LOAD_SUB_I32:
1587 AtomicOp = Mips::ATOMIC_LOAD_SUB_I32_POSTRA;
1588 break;
1589 case Mips::ATOMIC_LOAD_AND_I32:
1590 AtomicOp = Mips::ATOMIC_LOAD_AND_I32_POSTRA;
1591 break;
1592 case Mips::ATOMIC_LOAD_OR_I32:
1593 AtomicOp = Mips::ATOMIC_LOAD_OR_I32_POSTRA;
1594 break;
1595 case Mips::ATOMIC_LOAD_XOR_I32:
1596 AtomicOp = Mips::ATOMIC_LOAD_XOR_I32_POSTRA;
1597 break;
1598 case Mips::ATOMIC_LOAD_NAND_I32:
1599 AtomicOp = Mips::ATOMIC_LOAD_NAND_I32_POSTRA;
1600 break;
1601 case Mips::ATOMIC_SWAP_I32:
1602 AtomicOp = Mips::ATOMIC_SWAP_I32_POSTRA;
1603 break;
1604 case Mips::ATOMIC_LOAD_ADD_I64:
1605 AtomicOp = Mips::ATOMIC_LOAD_ADD_I64_POSTRA;
1606 break;
1607 case Mips::ATOMIC_LOAD_SUB_I64:
1608 AtomicOp = Mips::ATOMIC_LOAD_SUB_I64_POSTRA;
1609 break;
1610 case Mips::ATOMIC_LOAD_AND_I64:
1611 AtomicOp = Mips::ATOMIC_LOAD_AND_I64_POSTRA;
1612 break;
1613 case Mips::ATOMIC_LOAD_OR_I64:
1614 AtomicOp = Mips::ATOMIC_LOAD_OR_I64_POSTRA;
1615 break;
1616 case Mips::ATOMIC_LOAD_XOR_I64:
1617 AtomicOp = Mips::ATOMIC_LOAD_XOR_I64_POSTRA;
1618 break;
1619 case Mips::ATOMIC_LOAD_NAND_I64:
1620 AtomicOp = Mips::ATOMIC_LOAD_NAND_I64_POSTRA;
1621 break;
1622 case Mips::ATOMIC_SWAP_I64:
1623 AtomicOp = Mips::ATOMIC_SWAP_I64_POSTRA;
1624 break;
1625 case Mips::ATOMIC_LOAD_MIN_I32:
1626 AtomicOp = Mips::ATOMIC_LOAD_MIN_I32_POSTRA;
1627 NeedsAdditionalReg = true;
1628 break;
1629 case Mips::ATOMIC_LOAD_MAX_I32:
1630 AtomicOp = Mips::ATOMIC_LOAD_MAX_I32_POSTRA;
1631 NeedsAdditionalReg = true;
1632 break;
1633 case Mips::ATOMIC_LOAD_UMIN_I32:
1634 AtomicOp = Mips::ATOMIC_LOAD_UMIN_I32_POSTRA;
1635 NeedsAdditionalReg = true;
1636 break;
1637 case Mips::ATOMIC_LOAD_UMAX_I32:
1638 AtomicOp = Mips::ATOMIC_LOAD_UMAX_I32_POSTRA;
1639 NeedsAdditionalReg = true;
1640 break;
1641 case Mips::ATOMIC_LOAD_MIN_I64:
1642 AtomicOp = Mips::ATOMIC_LOAD_MIN_I64_POSTRA;
1643 NeedsAdditionalReg = true;
1644 break;
1645 case Mips::ATOMIC_LOAD_MAX_I64:
1646 AtomicOp = Mips::ATOMIC_LOAD_MAX_I64_POSTRA;
1647 NeedsAdditionalReg = true;
1648 break;
1649 case Mips::ATOMIC_LOAD_UMIN_I64:
1650 AtomicOp = Mips::ATOMIC_LOAD_UMIN_I64_POSTRA;
1651 NeedsAdditionalReg = true;
1652 break;
1653 case Mips::ATOMIC_LOAD_UMAX_I64:
1654 AtomicOp = Mips::ATOMIC_LOAD_UMAX_I64_POSTRA;
1655 NeedsAdditionalReg = true;
1656 break;
1657 default:
1658 llvm_unreachable("Unknown pseudo atomic for replacement!");
1659 }
1660
1661 Register OldVal = MI.getOperand(0).getReg();
1662 Register Ptr = MI.getOperand(1).getReg();
1663 Register Incr = MI.getOperand(2).getReg();
1664 Register Scratch = RegInfo.createVirtualRegister(RegInfo.getRegClass(OldVal));
1665
1667
1668 // The scratch registers here with the EarlyClobber | Define | Implicit
1669 // flags is used to persuade the register allocator and the machine
1670 // verifier to accept the usage of this register. This has to be a real
1671 // register which has an UNDEF value but is dead after the instruction which
1672 // is unique among the registers chosen for the instruction.
1673
1674 // The EarlyClobber flag has the semantic properties that the operand it is
1675 // attached to is clobbered before the rest of the inputs are read. Hence it
1676 // must be unique among the operands to the instruction.
1677 // The Define flag is needed to coerce the machine verifier that an Undef
1678 // value isn't a problem.
1679 // The Dead flag is needed as the value in scratch isn't used by any other
1680 // instruction. Kill isn't used as Dead is more precise.
1681 // The implicit flag is here due to the interaction between the other flags
1682 // and the machine verifier.
1683
1684 // For correctness purpose, a new pseudo is introduced here. We need this
1685 // new pseudo, so that FastRegisterAllocator does not see an ll/sc sequence
1686 // that is spread over >1 basic blocks. A register allocator which
1687 // introduces (or any codegen infact) a store, can violate the expectations
1688 // of the hardware.
1689 //
1690 // An atomic read-modify-write sequence starts with a linked load
1691 // instruction and ends with a store conditional instruction. The atomic
1692 // read-modify-write sequence fails if any of the following conditions
1693 // occur between the execution of ll and sc:
1694 // * A coherent store is completed by another process or coherent I/O
1695 // module into the block of synchronizable physical memory containing
1696 // the word. The size and alignment of the block is
1697 // implementation-dependent.
1698 // * A coherent store is executed between an LL and SC sequence on the
1699 // same processor to the block of synchornizable physical memory
1700 // containing the word.
1701 //
1702
1703 Register PtrCopy = RegInfo.createVirtualRegister(RegInfo.getRegClass(Ptr));
1704 Register IncrCopy = RegInfo.createVirtualRegister(RegInfo.getRegClass(Incr));
1705
1706 BuildMI(*BB, II, DL, TII->get(Mips::COPY), IncrCopy).addReg(Incr);
1707 BuildMI(*BB, II, DL, TII->get(Mips::COPY), PtrCopy).addReg(Ptr);
1708
1710 BuildMI(*BB, II, DL, TII->get(AtomicOp))
1712 .addReg(PtrCopy)
1713 .addReg(IncrCopy)
1716 if (NeedsAdditionalReg) {
1717 Register Scratch2 =
1718 RegInfo.createVirtualRegister(RegInfo.getRegClass(OldVal));
1721 }
1722
1723 MI.eraseFromParent();
1724
1725 return BB;
1726}
1727
1728MachineBasicBlock *MipsTargetLowering::emitSignExtendToI32InReg(
1729 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size, unsigned DstReg,
1730 unsigned SrcReg) const {
1731 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1732 const DebugLoc &DL = MI.getDebugLoc();
1733
1734 if (Subtarget.hasMips32r2() && Size == 1) {
1735 BuildMI(BB, DL, TII->get(Mips::SEB), DstReg).addReg(SrcReg);
1736 return BB;
1737 }
1738
1739 if (Subtarget.hasMips32r2() && Size == 2) {
1740 BuildMI(BB, DL, TII->get(Mips::SEH), DstReg).addReg(SrcReg);
1741 return BB;
1742 }
1743
1744 MachineFunction *MF = BB->getParent();
1745 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1746 const TargetRegisterClass *RC = getRegClassFor(MVT::i32);
1747 Register ScrReg = RegInfo.createVirtualRegister(RC);
1748
1749 assert(Size < 32);
1750 int64_t ShiftImm = 32 - (Size * 8);
1751
1752 BuildMI(BB, DL, TII->get(Mips::SLL), ScrReg).addReg(SrcReg).addImm(ShiftImm);
1753 BuildMI(BB, DL, TII->get(Mips::SRA), DstReg).addReg(ScrReg).addImm(ShiftImm);
1754
1755 return BB;
1756}
1757
1758MachineBasicBlock *MipsTargetLowering::emitAtomicBinaryPartword(
1759 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size) const {
1760 assert((Size == 1 || Size == 2) &&
1761 "Unsupported size for EmitAtomicBinaryPartial.");
1762
1763 MachineFunction *MF = BB->getParent();
1764 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1765 const TargetRegisterClass *RC = getRegClassFor(MVT::i32);
1766 const bool ArePtrs64bit = ABI.ArePtrs64bit();
1767 const TargetRegisterClass *RCp =
1768 getRegClassFor(ArePtrs64bit ? MVT::i64 : MVT::i32);
1769 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1770 DebugLoc DL = MI.getDebugLoc();
1771
1772 Register Dest = MI.getOperand(0).getReg();
1773 Register Ptr = MI.getOperand(1).getReg();
1774 Register Incr = MI.getOperand(2).getReg();
1775
1776 Register AlignedAddr = RegInfo.createVirtualRegister(RCp);
1777 Register ShiftAmt = RegInfo.createVirtualRegister(RC);
1778 Register Mask = RegInfo.createVirtualRegister(RC);
1779 Register Mask2 = RegInfo.createVirtualRegister(RC);
1780 Register Incr2 = RegInfo.createVirtualRegister(RC);
1781 Register MaskLSB2 = RegInfo.createVirtualRegister(RCp);
1782 Register PtrLSB2 = RegInfo.createVirtualRegister(RC);
1783 Register MaskUpper = RegInfo.createVirtualRegister(RC);
1784 Register Scratch = RegInfo.createVirtualRegister(RC);
1785 Register Scratch2 = RegInfo.createVirtualRegister(RC);
1786 Register Scratch3 = RegInfo.createVirtualRegister(RC);
1787
1788 unsigned AtomicOp = 0;
1789 bool NeedsAdditionalReg = false;
1790 switch (MI.getOpcode()) {
1791 case Mips::ATOMIC_LOAD_NAND_I8:
1792 AtomicOp = Mips::ATOMIC_LOAD_NAND_I8_POSTRA;
1793 break;
1794 case Mips::ATOMIC_LOAD_NAND_I16:
1795 AtomicOp = Mips::ATOMIC_LOAD_NAND_I16_POSTRA;
1796 break;
1797 case Mips::ATOMIC_SWAP_I8:
1798 AtomicOp = Mips::ATOMIC_SWAP_I8_POSTRA;
1799 break;
1800 case Mips::ATOMIC_SWAP_I16:
1801 AtomicOp = Mips::ATOMIC_SWAP_I16_POSTRA;
1802 break;
1803 case Mips::ATOMIC_LOAD_ADD_I8:
1804 AtomicOp = Mips::ATOMIC_LOAD_ADD_I8_POSTRA;
1805 break;
1806 case Mips::ATOMIC_LOAD_ADD_I16:
1807 AtomicOp = Mips::ATOMIC_LOAD_ADD_I16_POSTRA;
1808 break;
1809 case Mips::ATOMIC_LOAD_SUB_I8:
1810 AtomicOp = Mips::ATOMIC_LOAD_SUB_I8_POSTRA;
1811 break;
1812 case Mips::ATOMIC_LOAD_SUB_I16:
1813 AtomicOp = Mips::ATOMIC_LOAD_SUB_I16_POSTRA;
1814 break;
1815 case Mips::ATOMIC_LOAD_AND_I8:
1816 AtomicOp = Mips::ATOMIC_LOAD_AND_I8_POSTRA;
1817 break;
1818 case Mips::ATOMIC_LOAD_AND_I16:
1819 AtomicOp = Mips::ATOMIC_LOAD_AND_I16_POSTRA;
1820 break;
1821 case Mips::ATOMIC_LOAD_OR_I8:
1822 AtomicOp = Mips::ATOMIC_LOAD_OR_I8_POSTRA;
1823 break;
1824 case Mips::ATOMIC_LOAD_OR_I16:
1825 AtomicOp = Mips::ATOMIC_LOAD_OR_I16_POSTRA;
1826 break;
1827 case Mips::ATOMIC_LOAD_XOR_I8:
1828 AtomicOp = Mips::ATOMIC_LOAD_XOR_I8_POSTRA;
1829 break;
1830 case Mips::ATOMIC_LOAD_XOR_I16:
1831 AtomicOp = Mips::ATOMIC_LOAD_XOR_I16_POSTRA;
1832 break;
1833 case Mips::ATOMIC_LOAD_MIN_I8:
1834 AtomicOp = Mips::ATOMIC_LOAD_MIN_I8_POSTRA;
1835 NeedsAdditionalReg = true;
1836 break;
1837 case Mips::ATOMIC_LOAD_MIN_I16:
1838 AtomicOp = Mips::ATOMIC_LOAD_MIN_I16_POSTRA;
1839 NeedsAdditionalReg = true;
1840 break;
1841 case Mips::ATOMIC_LOAD_MAX_I8:
1842 AtomicOp = Mips::ATOMIC_LOAD_MAX_I8_POSTRA;
1843 NeedsAdditionalReg = true;
1844 break;
1845 case Mips::ATOMIC_LOAD_MAX_I16:
1846 AtomicOp = Mips::ATOMIC_LOAD_MAX_I16_POSTRA;
1847 NeedsAdditionalReg = true;
1848 break;
1849 case Mips::ATOMIC_LOAD_UMIN_I8:
1850 AtomicOp = Mips::ATOMIC_LOAD_UMIN_I8_POSTRA;
1851 NeedsAdditionalReg = true;
1852 break;
1853 case Mips::ATOMIC_LOAD_UMIN_I16:
1854 AtomicOp = Mips::ATOMIC_LOAD_UMIN_I16_POSTRA;
1855 NeedsAdditionalReg = true;
1856 break;
1857 case Mips::ATOMIC_LOAD_UMAX_I8:
1858 AtomicOp = Mips::ATOMIC_LOAD_UMAX_I8_POSTRA;
1859 NeedsAdditionalReg = true;
1860 break;
1861 case Mips::ATOMIC_LOAD_UMAX_I16:
1862 AtomicOp = Mips::ATOMIC_LOAD_UMAX_I16_POSTRA;
1863 NeedsAdditionalReg = true;
1864 break;
1865 default:
1866 llvm_unreachable("Unknown subword atomic pseudo for expansion!");
1867 }
1868
1869 // insert new blocks after the current block
1870 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1871 MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1873 MF->insert(It, exitMBB);
1874
1875 // Transfer the remainder of BB and its successor edges to exitMBB.
1876 exitMBB->splice(exitMBB->begin(), BB,
1877 std::next(MachineBasicBlock::iterator(MI)), BB->end());
1879
1881
1882 // thisMBB:
1883 // addiu masklsb2,$0,-4 # 0xfffffffc
1884 // and alignedaddr,ptr,masklsb2
1885 // andi ptrlsb2,ptr,3
1886 // sll shiftamt,ptrlsb2,3
1887 // ori maskupper,$0,255 # 0xff
1888 // sll mask,maskupper,shiftamt
1889 // nor mask2,$0,mask
1890 // sll incr2,incr,shiftamt
1891
1892 int64_t MaskImm = (Size == 1) ? 255 : 65535;
1893 BuildMI(BB, DL, TII->get(ABI.GetPtrAddiuOp()), MaskLSB2)
1894 .addReg(ABI.GetNullPtr()).addImm(-4);
1895 BuildMI(BB, DL, TII->get(ABI.GetPtrAndOp()), AlignedAddr)
1896 .addReg(Ptr).addReg(MaskLSB2);
1897 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2)
1898 .addReg(Ptr, {}, ArePtrs64bit ? Mips::sub_32 : 0)
1899 .addImm(3);
1900 if (Subtarget.isLittle()) {
1901 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3);
1902 } else {
1903 Register Off = RegInfo.createVirtualRegister(RC);
1904 BuildMI(BB, DL, TII->get(Mips::XORi), Off)
1905 .addReg(PtrLSB2).addImm((Size == 1) ? 3 : 2);
1906 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(Off).addImm(3);
1907 }
1908 BuildMI(BB, DL, TII->get(Mips::ORi), MaskUpper)
1909 .addReg(Mips::R0)
1910 .addImm(MaskImm);
1911 BuildMI(BB, DL, TII->get(Mips::SLLV), Mask)
1912 .addReg(MaskUpper).addReg(ShiftAmt);
1913 BuildMI(BB, DL, TII->get(Mips::NOR), Mask2).addReg(Mips::R0).addReg(Mask);
1914 BuildMI(BB, DL, TII->get(Mips::SLLV), Incr2).addReg(Incr).addReg(ShiftAmt);
1915
1916
1917 // The purposes of the flags on the scratch registers is explained in
1918 // emitAtomicBinary. In summary, we need a scratch register which is going to
1919 // be undef, that is unique among registers chosen for the instruction.
1920
1921 MachineInstrBuilder MIB =
1922 BuildMI(BB, DL, TII->get(AtomicOp))
1924 .addReg(AlignedAddr)
1925 .addReg(Incr2)
1926 .addReg(Mask)
1927 .addReg(Mask2)
1928 .addReg(ShiftAmt)
1935 if (NeedsAdditionalReg) {
1936 Register Scratch4 = RegInfo.createVirtualRegister(RC);
1939 }
1940
1941 MI.eraseFromParent(); // The instruction is gone now.
1942
1943 return exitMBB;
1944}
1945
1946// Lower atomic compare and swap to a pseudo instruction, taking care to
1947// define a scratch register for the pseudo instruction's expansion. The
1948// instruction is expanded after the register allocator as to prevent
1949// the insertion of stores between the linked load and the store conditional.
1950
1952MipsTargetLowering::emitAtomicCmpSwap(MachineInstr &MI,
1953 MachineBasicBlock *BB) const {
1954
1955 assert((MI.getOpcode() == Mips::ATOMIC_CMP_SWAP_I32 ||
1956 MI.getOpcode() == Mips::ATOMIC_CMP_SWAP_I64) &&
1957 "Unsupported atomic pseudo for EmitAtomicCmpSwap.");
1958
1959 const unsigned Size = MI.getOpcode() == Mips::ATOMIC_CMP_SWAP_I32 ? 4 : 8;
1960
1961 MachineFunction *MF = BB->getParent();
1962 MachineRegisterInfo &MRI = MF->getRegInfo();
1964 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1965 DebugLoc DL = MI.getDebugLoc();
1966
1967 unsigned AtomicOp = MI.getOpcode() == Mips::ATOMIC_CMP_SWAP_I32
1968 ? Mips::ATOMIC_CMP_SWAP_I32_POSTRA
1969 : Mips::ATOMIC_CMP_SWAP_I64_POSTRA;
1970 Register Dest = MI.getOperand(0).getReg();
1971 Register Ptr = MI.getOperand(1).getReg();
1972 Register OldVal = MI.getOperand(2).getReg();
1973 Register NewVal = MI.getOperand(3).getReg();
1974
1975 Register Scratch = MRI.createVirtualRegister(RC);
1977
1978 // We need to create copies of the various registers and kill them at the
1979 // atomic pseudo. If the copies are not made, when the atomic is expanded
1980 // after fast register allocation, the spills will end up outside of the
1981 // blocks that their values are defined in, causing livein errors.
1982
1984 Register OldValCopy = MRI.createVirtualRegister(MRI.getRegClass(OldVal));
1985 Register NewValCopy = MRI.createVirtualRegister(MRI.getRegClass(NewVal));
1986
1987 BuildMI(*BB, II, DL, TII->get(Mips::COPY), PtrCopy).addReg(Ptr);
1988 BuildMI(*BB, II, DL, TII->get(Mips::COPY), OldValCopy).addReg(OldVal);
1989 BuildMI(*BB, II, DL, TII->get(Mips::COPY), NewValCopy).addReg(NewVal);
1990
1991 // The purposes of the flags on the scratch registers is explained in
1992 // emitAtomicBinary. In summary, we need a scratch register which is going to
1993 // be undef, that is unique among registers chosen for the instruction.
1994
1995 BuildMI(*BB, II, DL, TII->get(AtomicOp))
1997 .addReg(PtrCopy)
1998 .addReg(OldValCopy)
1999 .addReg(NewValCopy)
2002
2003 MI.eraseFromParent(); // The instruction is gone now.
2004
2005 return BB;
2006}
2007
2008MachineBasicBlock *MipsTargetLowering::emitAtomicCmpSwapPartword(
2009 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size) const {
2010 assert((Size == 1 || Size == 2) &&
2011 "Unsupported size for EmitAtomicCmpSwapPartial.");
2012
2013 MachineFunction *MF = BB->getParent();
2014 MachineRegisterInfo &RegInfo = MF->getRegInfo();
2015 const TargetRegisterClass *RC = getRegClassFor(MVT::i32);
2016 const bool ArePtrs64bit = ABI.ArePtrs64bit();
2017 const TargetRegisterClass *RCp =
2018 getRegClassFor(ArePtrs64bit ? MVT::i64 : MVT::i32);
2019 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
2020 DebugLoc DL = MI.getDebugLoc();
2021
2022 Register Dest = MI.getOperand(0).getReg();
2023 Register Ptr = MI.getOperand(1).getReg();
2024 Register CmpVal = MI.getOperand(2).getReg();
2025 Register NewVal = MI.getOperand(3).getReg();
2026
2027 Register AlignedAddr = RegInfo.createVirtualRegister(RCp);
2028 Register ShiftAmt = RegInfo.createVirtualRegister(RC);
2029 Register Mask = RegInfo.createVirtualRegister(RC);
2030 Register Mask2 = RegInfo.createVirtualRegister(RC);
2031 Register ShiftedCmpVal = RegInfo.createVirtualRegister(RC);
2032 Register ShiftedNewVal = RegInfo.createVirtualRegister(RC);
2033 Register MaskLSB2 = RegInfo.createVirtualRegister(RCp);
2034 Register PtrLSB2 = RegInfo.createVirtualRegister(RC);
2035 Register MaskUpper = RegInfo.createVirtualRegister(RC);
2036 Register MaskedCmpVal = RegInfo.createVirtualRegister(RC);
2037 Register MaskedNewVal = RegInfo.createVirtualRegister(RC);
2038 unsigned AtomicOp = MI.getOpcode() == Mips::ATOMIC_CMP_SWAP_I8
2039 ? Mips::ATOMIC_CMP_SWAP_I8_POSTRA
2040 : Mips::ATOMIC_CMP_SWAP_I16_POSTRA;
2041
2042 // The scratch registers here with the EarlyClobber | Define | Dead | Implicit
2043 // flags are used to coerce the register allocator and the machine verifier to
2044 // accept the usage of these registers.
2045 // The EarlyClobber flag has the semantic properties that the operand it is
2046 // attached to is clobbered before the rest of the inputs are read. Hence it
2047 // must be unique among the operands to the instruction.
2048 // The Define flag is needed to coerce the machine verifier that an Undef
2049 // value isn't a problem.
2050 // The Dead flag is needed as the value in scratch isn't used by any other
2051 // instruction. Kill isn't used as Dead is more precise.
2052 Register Scratch = RegInfo.createVirtualRegister(RC);
2053 Register Scratch2 = RegInfo.createVirtualRegister(RC);
2054
2055 // insert new blocks after the current block
2056 const BasicBlock *LLVM_BB = BB->getBasicBlock();
2057 MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
2059 MF->insert(It, exitMBB);
2060
2061 // Transfer the remainder of BB and its successor edges to exitMBB.
2062 exitMBB->splice(exitMBB->begin(), BB,
2063 std::next(MachineBasicBlock::iterator(MI)), BB->end());
2065
2067
2068 // thisMBB:
2069 // addiu masklsb2,$0,-4 # 0xfffffffc
2070 // and alignedaddr,ptr,masklsb2
2071 // andi ptrlsb2,ptr,3
2072 // xori ptrlsb2,ptrlsb2,3 # Only for BE
2073 // sll shiftamt,ptrlsb2,3
2074 // ori maskupper,$0,255 # 0xff
2075 // sll mask,maskupper,shiftamt
2076 // nor mask2,$0,mask
2077 // andi maskedcmpval,cmpval,255
2078 // sll shiftedcmpval,maskedcmpval,shiftamt
2079 // andi maskednewval,newval,255
2080 // sll shiftednewval,maskednewval,shiftamt
2081 int64_t MaskImm = (Size == 1) ? 255 : 65535;
2082 BuildMI(BB, DL, TII->get(ArePtrs64bit ? Mips::DADDiu : Mips::ADDiu), MaskLSB2)
2083 .addReg(ABI.GetNullPtr()).addImm(-4);
2084 BuildMI(BB, DL, TII->get(ArePtrs64bit ? Mips::AND64 : Mips::AND), AlignedAddr)
2085 .addReg(Ptr).addReg(MaskLSB2);
2086 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2)
2087 .addReg(Ptr, {}, ArePtrs64bit ? Mips::sub_32 : 0)
2088 .addImm(3);
2089 if (Subtarget.isLittle()) {
2090 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3);
2091 } else {
2092 Register Off = RegInfo.createVirtualRegister(RC);
2093 BuildMI(BB, DL, TII->get(Mips::XORi), Off)
2094 .addReg(PtrLSB2).addImm((Size == 1) ? 3 : 2);
2095 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(Off).addImm(3);
2096 }
2097 BuildMI(BB, DL, TII->get(Mips::ORi), MaskUpper)
2098 .addReg(Mips::R0)
2099 .addImm(MaskImm);
2100 BuildMI(BB, DL, TII->get(Mips::SLLV), Mask)
2101 .addReg(MaskUpper).addReg(ShiftAmt);
2102 BuildMI(BB, DL, TII->get(Mips::NOR), Mask2).addReg(Mips::R0).addReg(Mask);
2103 BuildMI(BB, DL, TII->get(Mips::ANDi), MaskedCmpVal)
2104 .addReg(CmpVal).addImm(MaskImm);
2105 BuildMI(BB, DL, TII->get(Mips::SLLV), ShiftedCmpVal)
2106 .addReg(MaskedCmpVal).addReg(ShiftAmt);
2107 BuildMI(BB, DL, TII->get(Mips::ANDi), MaskedNewVal)
2108 .addReg(NewVal).addImm(MaskImm);
2109 BuildMI(BB, DL, TII->get(Mips::SLLV), ShiftedNewVal)
2110 .addReg(MaskedNewVal).addReg(ShiftAmt);
2111
2112 // The purposes of the flags on the scratch registers are explained in
2113 // emitAtomicBinary. In summary, we need a scratch register which is going to
2114 // be undef, that is unique among the register chosen for the instruction.
2115
2116 BuildMI(BB, DL, TII->get(AtomicOp))
2118 .addReg(AlignedAddr)
2119 .addReg(Mask)
2120 .addReg(ShiftedCmpVal)
2121 .addReg(Mask2)
2122 .addReg(ShiftedNewVal)
2123 .addReg(ShiftAmt)
2128
2129 MI.eraseFromParent(); // The instruction is gone now.
2130
2131 return exitMBB;
2132}
2133
2134SDValue MipsTargetLowering::lowerConstantFP(SDValue Op,
2135 SelectionDAG &DAG) const {
2136 EVT VT = Op.getValueType();
2137 ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op);
2138 const APFloat &FPVal = CFP->getValueAPF();
2139
2140 if (FPVal.isZero())
2141 return SDValue();
2142
2143 SDLoc DL(CFP);
2144 APInt INTVal = FPVal.bitcastToAPInt();
2145 switch (VT.getSimpleVT().SimpleTy) {
2146 default:
2147 llvm_unreachable("Unknown floating point type!");
2148 break;
2149 case MVT::f64: {
2150 if (!Subtarget.hasMTHC1() || !Subtarget.hasMips32r2())
2151 return SDValue();
2152 uint64_t Bits = INTVal.getZExtValue();
2153 uint32_t Lo = Bits & 0xFFFFFFFF;
2154 if (Lo != 0 || Bits == 0)
2155 return SDValue();
2156
2157 // TODO: DAG.getConstant(0) should be optimized to avoid generate an extra
2158 // instr `addiu $x, $zero, 0`.
2159 SDValue Low =
2160 DAG.getCopyFromReg(DAG.getEntryNode(), DL, Mips::R0, MVT::i32);
2161 SDValue Hi = DAG.getConstant(INTVal.extractBits(32, 32), DL, MVT::i32);
2162 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Low, Hi);
2163 }
2164 }
2165
2166 return SDValue();
2167}
2168
2169SDValue MipsTargetLowering::lowerREADCYCLECOUNTER(SDValue Op,
2170 SelectionDAG &DAG) const {
2172 SDLoc DL(Op);
2174 unsigned RdhwrOpc, DestReg;
2175 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2176
2177 if (PtrVT == MVT::i64) {
2178 RdhwrOpc = Mips::RDHWR64;
2179 DestReg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i64));
2180 SDNode *Rdhwr = DAG.getMachineNode(RdhwrOpc, DL, MVT::i64, MVT::Glue,
2181 DAG.getRegister(Mips::HWR2, MVT::i32),
2182 DAG.getTargetConstant(0, DL, MVT::i32));
2183 SDValue Chain = DAG.getCopyToReg(DAG.getEntryNode(), DL, DestReg,
2184 SDValue(Rdhwr, 0), SDValue(Rdhwr, 1));
2185 SDValue ResNode =
2186 DAG.getCopyFromReg(Chain, DL, DestReg, MVT::i64, Chain.getValue(1));
2187 Results.push_back(ResNode);
2188 Results.push_back(ResNode.getValue(1));
2189 } else {
2190 RdhwrOpc = Mips::RDHWR;
2191 DestReg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32));
2192 SDNode *Rdhwr = DAG.getMachineNode(RdhwrOpc, DL, MVT::i32, MVT::Glue,
2193 DAG.getRegister(Mips::HWR2, MVT::i32),
2194 DAG.getTargetConstant(0, DL, MVT::i32));
2195 SDValue Chain = DAG.getCopyToReg(DAG.getEntryNode(), DL, DestReg,
2196 SDValue(Rdhwr, 0), SDValue(Rdhwr, 1));
2197 SDValue ResNode =
2198 DAG.getCopyFromReg(Chain, DL, DestReg, MVT::i32, Chain.getValue(1));
2199 Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, ResNode,
2200 DAG.getConstant(0, DL, MVT::i32)));
2201 Results.push_back(ResNode.getValue(1));
2202 }
2203
2204 return DAG.getMergeValues(Results, DL);
2205}
2206
2207SDValue MipsTargetLowering::lowerBRCOND(SDValue Op, SelectionDAG &DAG) const {
2208 // The first operand is the chain, the second is the condition, the third is
2209 // the block to branch to if the condition is true.
2210 SDValue Chain = Op.getOperand(0);
2211 SDValue Dest = Op.getOperand(2);
2212 SDLoc DL(Op);
2213
2214 assert(!Subtarget.hasMips32r6() && !Subtarget.hasMips64r6());
2215 SDValue CondRes = createFPCmp(DAG, Op.getOperand(1));
2216
2217 // Return if flag is not set by a floating point comparison.
2218 if (CondRes.getOpcode() != MipsISD::FPCmp)
2219 return Op;
2220
2221 SDValue CCNode = CondRes.getOperand(2);
2224 SDValue BrCode = DAG.getConstant(Opc, DL, MVT::i32);
2225 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32);
2226 return DAG.getNode(MipsISD::FPBrcond, DL, Op.getValueType(), Chain, BrCode,
2227 FCC0, Dest, CondRes);
2228}
2229
2230SDValue MipsTargetLowering::
2231lowerSELECT(SDValue Op, SelectionDAG &DAG) const
2232{
2233 assert(!Subtarget.hasMips32r6() && !Subtarget.hasMips64r6());
2234 SDValue Cond = createFPCmp(DAG, Op.getOperand(0));
2235
2236 // Return if flag is not set by a floating point comparison.
2237 if (Cond.getOpcode() != MipsISD::FPCmp)
2238 return Op;
2239
2240 return createCMovFP(DAG, Cond, Op.getOperand(1), Op.getOperand(2),
2241 SDLoc(Op));
2242}
2243
2244SDValue MipsTargetLowering::lowerSETCC(SDValue Op, SelectionDAG &DAG) const {
2245 assert(!Subtarget.hasMips32r6() && !Subtarget.hasMips64r6());
2246 SDValue Cond = createFPCmp(DAG, Op);
2247
2248 assert(Cond.getOpcode() == MipsISD::FPCmp &&
2249 "Floating point operand expected.");
2250
2251 SDLoc DL(Op);
2252 SDValue True = DAG.getConstant(1, DL, MVT::i32);
2253 SDValue False = DAG.getConstant(0, DL, MVT::i32);
2254
2255 return createCMovFP(DAG, Cond, True, False, DL);
2256}
2257
2258SDValue MipsTargetLowering::lowerFSETCC(SDValue Op, SelectionDAG &DAG) const {
2259 assert(!Subtarget.hasMips32r6() && !Subtarget.hasMips64r6());
2260
2261 SDLoc DL(Op);
2262 SDValue Chain = Op.getOperand(0);
2263 SDValue LHS = Op.getOperand(1);
2264 SDValue RHS = Op.getOperand(2);
2265 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(3))->get();
2266
2267 SDValue Cond = DAG.getNode(MipsISD::FPCmp, DL, MVT::Glue, LHS, RHS,
2268 DAG.getConstant(condCodeToFCC(CC), DL, MVT::i32));
2269 SDValue True = DAG.getConstant(1, DL, MVT::i32);
2270 SDValue False = DAG.getConstant(0, DL, MVT::i32);
2271 SDValue CMovFP = createCMovFP(DAG, Cond, True, False, DL);
2272
2273 return DAG.getMergeValues({CMovFP, Chain}, DL);
2274}
2275
2276SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op,
2277 SelectionDAG &DAG) const {
2278 EVT Ty = Op.getValueType();
2279 GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op);
2280 const GlobalValue *GV = N->getGlobal();
2281
2282 if (GV->hasDLLImportStorageClass()) {
2283 assert(Subtarget.isTargetWindows() &&
2284 "Windows is the only supported COFF target");
2285 return getDllimportVariable(
2286 N, SDLoc(N), Ty, DAG, DAG.getEntryNode(),
2288 }
2289
2290 if (!isPositionIndependent()) {
2291 const MipsTargetObjectFile *TLOF =
2292 static_cast<const MipsTargetObjectFile *>(
2294 const GlobalObject *GO = GV->getAliaseeObject();
2295 if (Subtarget.useSmallSection() && GO && TLOF->IsGlobalInSmallSection(GO))
2296 // %gp_rel relocation
2297 return getAddrGPRel(N, SDLoc(N), Ty, DAG, ABI.IsN64());
2298
2299 // %hi/%lo relocation
2300 return Subtarget.hasSym32() ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
2301 // %highest/%higher/%hi/%lo relocation
2302 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
2303 }
2304
2305 // Every other architecture would use shouldAssumeDSOLocal in here, but
2306 // mips is special.
2307 // * In PIC code mips requires got loads even for local statics!
2308 // * To save on got entries, for local statics the got entry contains the
2309 // page and an additional add instruction takes care of the low bits.
2310 // * It is legal to access a hidden symbol with a non hidden undefined,
2311 // so one cannot guarantee that all access to a hidden symbol will know
2312 // it is hidden.
2313 // * Mips linkers don't support creating a page and a full got entry for
2314 // the same symbol.
2315 // * Given all that, we have to use a full got entry for hidden symbols :-(
2316 if (GV->hasLocalLinkage())
2317 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
2318
2319 if (Subtarget.useXGOT())
2320 return getAddrGlobalLargeGOT(
2321 N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, MipsII::MO_GOT_LO16,
2322 DAG.getEntryNode(),
2324
2325 return getAddrGlobal(
2326 N, SDLoc(N), Ty, DAG,
2327 (ABI.IsN32() || ABI.IsN64()) ? MipsII::MO_GOT_DISP : MipsII::MO_GOT,
2329}
2330
2331SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op,
2332 SelectionDAG &DAG) const {
2333 BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
2334 EVT Ty = Op.getValueType();
2335
2336 if (!isPositionIndependent())
2337 return Subtarget.hasSym32() ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
2338 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
2339
2340 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
2341}
2342
2343SDValue MipsTargetLowering::
2344lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
2345{
2346 // If the relocation model is PIC, use the General Dynamic TLS Model or
2347 // Local Dynamic TLS model, otherwise use the Initial Exec or
2348 // Local Exec TLS Model.
2349
2350 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
2351 if (DAG.getTarget().useEmulatedTLS())
2352 return LowerToTLSEmulatedModel(GA, DAG);
2353
2354 SDLoc DL(GA);
2355 const GlobalValue *GV = GA->getGlobal();
2356 EVT PtrVT = getPointerTy(DAG.getDataLayout());
2357
2359
2360 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) {
2361 // General Dynamic and Local Dynamic TLS Model.
2362 unsigned Flag = (model == TLSModel::LocalDynamic) ? MipsII::MO_TLSLDM
2363 : MipsII::MO_TLSGD;
2364
2365 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, Flag);
2366 SDValue Argument = DAG.getNode(MipsISD::Wrapper, DL, PtrVT,
2367 getGlobalReg(DAG, PtrVT), TGA);
2368 unsigned PtrSize = PtrVT.getSizeInBits();
2369 IntegerType *PtrTy = Type::getIntNTy(*DAG.getContext(), PtrSize);
2370
2371 SDValue TlsGetAddr = DAG.getExternalSymbol("__tls_get_addr", PtrVT);
2372
2374 Args.emplace_back(Argument, PtrTy);
2375
2376 TargetLowering::CallLoweringInfo CLI(DAG);
2377 CLI.setDebugLoc(DL)
2378 .setChain(DAG.getEntryNode())
2379 .setLibCallee(CallingConv::C, PtrTy, TlsGetAddr, std::move(Args));
2380 std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI);
2381
2382 SDValue Ret = CallResult.first;
2383
2384 if (model != TLSModel::LocalDynamic)
2385 return Ret;
2386
2387 SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
2389 SDValue Hi = DAG.getNode(MipsISD::TlsHi, DL, PtrVT, TGAHi);
2390 SDValue TGALo = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
2392 SDValue Lo = DAG.getNode(MipsISD::Lo, DL, PtrVT, TGALo);
2393 SDValue Add = DAG.getNode(ISD::ADD, DL, PtrVT, Hi, Ret);
2394 return DAG.getNode(ISD::ADD, DL, PtrVT, Add, Lo);
2395 }
2396
2397 SDValue Offset;
2398 if (model == TLSModel::InitialExec) {
2399 // Initial Exec TLS Model
2400 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
2402 TGA = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, getGlobalReg(DAG, PtrVT),
2403 TGA);
2404 Offset =
2405 DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), TGA, MachinePointerInfo());
2406 } else {
2407 // Local Exec TLS Model
2408 assert(model == TLSModel::LocalExec);
2409 SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
2411 SDValue TGALo = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
2413 SDValue Hi = DAG.getNode(MipsISD::TlsHi, DL, PtrVT, TGAHi);
2414 SDValue Lo = DAG.getNode(MipsISD::Lo, DL, PtrVT, TGALo);
2415 Offset = DAG.getNode(ISD::ADD, DL, PtrVT, Hi, Lo);
2416 }
2417
2418 SDValue ThreadPointer = DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT);
2419 return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer, Offset);
2420}
2421
2422SDValue MipsTargetLowering::
2423lowerJumpTable(SDValue Op, SelectionDAG &DAG) const
2424{
2425 JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
2426 EVT Ty = Op.getValueType();
2427
2428 if (!isPositionIndependent())
2429 return Subtarget.hasSym32() ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
2430 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
2431
2432 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
2433}
2434
2435SDValue MipsTargetLowering::
2436lowerConstantPool(SDValue Op, SelectionDAG &DAG) const
2437{
2438 ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op);
2439 EVT Ty = Op.getValueType();
2440
2441 if (!isPositionIndependent()) {
2442 const MipsTargetObjectFile *TLOF =
2443 static_cast<const MipsTargetObjectFile *>(
2445
2446 if (TLOF->IsConstantInSmallSection(DAG.getDataLayout(), N->getConstVal(),
2448 // %gp_rel relocation
2449 return getAddrGPRel(N, SDLoc(N), Ty, DAG, ABI.IsN64());
2450
2451 return Subtarget.hasSym32() ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
2452 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
2453 }
2454
2455 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
2456}
2457
2458SDValue MipsTargetLowering::lowerVASTART(SDValue Op, SelectionDAG &DAG) const {
2460 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
2461
2462 SDLoc DL(Op);
2463 SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(),
2465
2466 // vastart just stores the address of the VarArgsFrameIndex slot into the
2467 // memory location argument.
2468 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
2469 return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1),
2470 MachinePointerInfo(SV));
2471}
2472
2473SDValue MipsTargetLowering::lowerVAARG(SDValue Op, SelectionDAG &DAG) const {
2474 SDNode *Node = Op.getNode();
2475 EVT VT = Node->getValueType(0);
2476 SDValue Chain = Node->getOperand(0);
2477 SDValue VAListPtr = Node->getOperand(1);
2478 const Align Align =
2479 llvm::MaybeAlign(Node->getConstantOperandVal(3)).valueOrOne();
2480 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
2481 SDLoc DL(Node);
2482 unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4;
2483
2484 SDValue VAListLoad = DAG.getLoad(getPointerTy(DAG.getDataLayout()), DL, Chain,
2485 VAListPtr, MachinePointerInfo(SV));
2486 SDValue VAList = VAListLoad;
2487
2488 // Re-align the pointer if necessary.
2489 // It should only ever be necessary for 64-bit types on O32 since the minimum
2490 // argument alignment is the same as the maximum type alignment for N32/N64.
2491 //
2492 // FIXME: We currently align too often. The code generator doesn't notice
2493 // when the pointer is still aligned from the last va_arg (or pair of
2494 // va_args for the i64 on O32 case).
2495 if (Align > getMinStackArgumentAlignment()) {
2496 VAList = DAG.getNode(
2497 ISD::ADD, DL, VAList.getValueType(), VAList,
2498 DAG.getConstant(Align.value() - 1, DL, VAList.getValueType()));
2499
2500 VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList,
2501 DAG.getSignedConstant(-(int64_t)Align.value(), DL,
2502 VAList.getValueType()));
2503 }
2504
2505 // Increment the pointer, VAList, to the next vaarg.
2506 auto &TD = DAG.getDataLayout();
2507 unsigned ArgSizeInBytes =
2509 SDValue Tmp3 =
2510 DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList,
2511 DAG.getConstant(alignTo(ArgSizeInBytes, ArgSlotSizeInBytes),
2512 DL, VAList.getValueType()));
2513 // Store the incremented VAList to the legalized pointer
2514 Chain = DAG.getStore(VAListLoad.getValue(1), DL, Tmp3, VAListPtr,
2515 MachinePointerInfo(SV));
2516
2517 // In big-endian mode we must adjust the pointer when the load size is smaller
2518 // than the argument slot size. We must also reduce the known alignment to
2519 // match. For example in the N64 ABI, we must add 4 bytes to the offset to get
2520 // the correct half of the slot, and reduce the alignment from 8 (slot
2521 // alignment) down to 4 (type alignment).
2522 if (!Subtarget.isLittle() && ArgSizeInBytes < ArgSlotSizeInBytes) {
2523 unsigned Adjustment = ArgSlotSizeInBytes - ArgSizeInBytes;
2524 VAList = DAG.getNode(ISD::ADD, DL, VAListPtr.getValueType(), VAList,
2525 DAG.getIntPtrConstant(Adjustment, DL));
2526 }
2527 // Load the actual argument out of the pointer VAList
2528 return DAG.getLoad(VT, DL, Chain, VAList, MachinePointerInfo());
2529}
2530
2532 bool HasExtractInsert) {
2533 EVT TyX = Op.getOperand(0).getValueType();
2534 EVT TyY = Op.getOperand(1).getValueType();
2535 SDLoc DL(Op);
2536 SDValue Const1 = DAG.getConstant(1, DL, MVT::i32);
2537 SDValue Const31 = DAG.getConstant(31, DL, MVT::i32);
2538 SDValue Res;
2539
2540 // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it
2541 // to i32.
2542 SDValue X = (TyX == MVT::f32) ?
2543 DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(0)) :
2544 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
2545 Const1);
2546 SDValue Y = (TyY == MVT::f32) ?
2547 DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(1)) :
2548 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(1),
2549 Const1);
2550
2551 if (HasExtractInsert) {
2552 // ext E, Y, 31, 1 ; extract bit31 of Y
2553 // ins X, E, 31, 1 ; insert extracted bit at bit31 of X
2554 SDValue E = DAG.getNode(MipsISD::Ext, DL, MVT::i32, Y, Const31, Const1);
2555 Res = DAG.getNode(MipsISD::Ins, DL, MVT::i32, E, Const31, Const1, X);
2556 } else {
2557 // sll SllX, X, 1
2558 // srl SrlX, SllX, 1
2559 // srl SrlY, Y, 31
2560 // sll SllY, SrlX, 31
2561 // or Or, SrlX, SllY
2562 SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i32, X, Const1);
2563 SDValue SrlX = DAG.getNode(ISD::SRL, DL, MVT::i32, SllX, Const1);
2564 SDValue SrlY = DAG.getNode(ISD::SRL, DL, MVT::i32, Y, Const31);
2565 SDValue SllY = DAG.getNode(ISD::SHL, DL, MVT::i32, SrlY, Const31);
2566 Res = DAG.getNode(ISD::OR, DL, MVT::i32, SrlX, SllY);
2567 }
2568
2569 if (TyX == MVT::f32)
2570 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Res);
2571
2572 SDValue LowX = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
2573 Op.getOperand(0),
2574 DAG.getConstant(0, DL, MVT::i32));
2575 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res);
2576}
2577
2579 bool HasExtractInsert) {
2580 unsigned WidthX = Op.getOperand(0).getValueSizeInBits();
2581 unsigned WidthY = Op.getOperand(1).getValueSizeInBits();
2582 EVT TyX = MVT::getIntegerVT(WidthX), TyY = MVT::getIntegerVT(WidthY);
2583 SDLoc DL(Op);
2584 SDValue Const1 = DAG.getConstant(1, DL, MVT::i32);
2585
2586 // Bitcast to integer nodes.
2587 SDValue X = DAG.getNode(ISD::BITCAST, DL, TyX, Op.getOperand(0));
2588 SDValue Y = DAG.getNode(ISD::BITCAST, DL, TyY, Op.getOperand(1));
2589
2590 if (HasExtractInsert) {
2591 // ext E, Y, width(Y) - 1, 1 ; extract bit width(Y)-1 of Y
2592 // ins X, E, width(X) - 1, 1 ; insert extracted bit at bit width(X)-1 of X
2593 SDValue E = DAG.getNode(MipsISD::Ext, DL, TyY, Y,
2594 DAG.getConstant(WidthY - 1, DL, MVT::i32), Const1);
2595
2596 if (WidthX > WidthY)
2597 E = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, E);
2598 else if (WidthY > WidthX)
2599 E = DAG.getNode(ISD::TRUNCATE, DL, TyX, E);
2600
2601 SDValue I = DAG.getNode(MipsISD::Ins, DL, TyX, E,
2602 DAG.getConstant(WidthX - 1, DL, MVT::i32), Const1,
2603 X);
2604 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), I);
2605 }
2606
2607 // (d)sll SllX, X, 1
2608 // (d)srl SrlX, SllX, 1
2609 // (d)srl SrlY, Y, width(Y)-1
2610 // (d)sll SllY, SrlX, width(Y)-1
2611 // or Or, SrlX, SllY
2612 SDValue SllX = DAG.getNode(ISD::SHL, DL, TyX, X, Const1);
2613 SDValue SrlX = DAG.getNode(ISD::SRL, DL, TyX, SllX, Const1);
2614 SDValue SrlY = DAG.getNode(ISD::SRL, DL, TyY, Y,
2615 DAG.getConstant(WidthY - 1, DL, MVT::i32));
2616
2617 if (WidthX > WidthY)
2618 SrlY = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, SrlY);
2619 else if (WidthY > WidthX)
2620 SrlY = DAG.getNode(ISD::TRUNCATE, DL, TyX, SrlY);
2621
2622 SDValue SllY = DAG.getNode(ISD::SHL, DL, TyX, SrlY,
2623 DAG.getConstant(WidthX - 1, DL, MVT::i32));
2624 SDValue Or = DAG.getNode(ISD::OR, DL, TyX, SrlX, SllY);
2625 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Or);
2626}
2627
2628SDValue
2629MipsTargetLowering::lowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const {
2630 if (Subtarget.isGP64bit())
2631 return lowerFCOPYSIGN64(Op, DAG, Subtarget.hasExtractInsert());
2632
2633 return lowerFCOPYSIGN32(Op, DAG, Subtarget.hasExtractInsert());
2634}
2635
2636SDValue MipsTargetLowering::lowerFABS32(SDValue Op, SelectionDAG &DAG,
2637 bool HasExtractInsert) const {
2638 SDLoc DL(Op);
2639 SDValue Res, Const1 = DAG.getConstant(1, DL, MVT::i32);
2640
2641 if (Op->getFlags().hasNoNaNs() || Subtarget.inAbs2008Mode())
2642 return DAG.getNode(MipsISD::FAbs, DL, Op.getValueType(), Op.getOperand(0));
2643
2644 // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it
2645 // to i32.
2646 SDValue X = (Op.getValueType() == MVT::f32)
2647 ? DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(0))
2648 : DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
2649 Op.getOperand(0), Const1);
2650
2651 // Clear MSB.
2652 if (HasExtractInsert)
2653 Res = DAG.getNode(MipsISD::Ins, DL, MVT::i32,
2654 DAG.getRegister(Mips::R0, MVT::i32),
2655 DAG.getConstant(31, DL, MVT::i32), Const1, X);
2656 else {
2657 // TODO: Provide DAG patterns which transform (and x, cst)
2658 // back to a (shl (srl x (clz cst)) (clz cst)) sequence.
2659 SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i32, X, Const1);
2660 Res = DAG.getNode(ISD::SRL, DL, MVT::i32, SllX, Const1);
2661 }
2662
2663 if (Op.getValueType() == MVT::f32)
2664 return DAG.getNode(ISD::BITCAST, DL, MVT::f32, Res);
2665
2666 // FIXME: For mips32r2, the sequence of (BuildPairF64 (ins (ExtractElementF64
2667 // Op 1), $zero, 31 1) (ExtractElementF64 Op 0)) and the Op has one use, we
2668 // should be able to drop the usage of mfc1/mtc1 and rewrite the register in
2669 // place.
2670 SDValue LowX =
2671 DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0),
2672 DAG.getConstant(0, DL, MVT::i32));
2673 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res);
2674}
2675
2676SDValue MipsTargetLowering::lowerFABS64(SDValue Op, SelectionDAG &DAG,
2677 bool HasExtractInsert) const {
2678 SDLoc DL(Op);
2679 SDValue Res, Const1 = DAG.getConstant(1, DL, MVT::i32);
2680
2681 if (Op->getFlags().hasNoNaNs() || Subtarget.inAbs2008Mode())
2682 return DAG.getNode(MipsISD::FAbs, DL, Op.getValueType(), Op.getOperand(0));
2683
2684 // Bitcast to integer node.
2685 SDValue X = DAG.getNode(ISD::BITCAST, DL, MVT::i64, Op.getOperand(0));
2686
2687 // Clear MSB.
2688 if (HasExtractInsert)
2689 Res = DAG.getNode(MipsISD::Ins, DL, MVT::i64,
2690 DAG.getRegister(Mips::R0_64, MVT::i64),
2691 DAG.getConstant(63, DL, MVT::i32), Const1, X);
2692 else {
2693 SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i64, X, Const1);
2694 Res = DAG.getNode(ISD::SRL, DL, MVT::i64, SllX, Const1);
2695 }
2696
2697 return DAG.getNode(ISD::BITCAST, DL, MVT::f64, Res);
2698}
2699
2700SDValue MipsTargetLowering::lowerFABS(SDValue Op, SelectionDAG &DAG) const {
2701 if ((ABI.IsN32() || ABI.IsN64()) && (Op.getValueType() == MVT::f64))
2702 return lowerFABS64(Op, DAG, Subtarget.hasExtractInsert());
2703
2704 return lowerFABS32(Op, DAG, Subtarget.hasExtractInsert());
2705}
2706
2707SDValue MipsTargetLowering::lowerFCANONICALIZE(SDValue Op,
2708 SelectionDAG &DAG) const {
2709 SDLoc DL(Op);
2710 EVT VT = Op.getValueType();
2711 SDValue Operand = Op.getOperand(0);
2712 SDNodeFlags Flags = Op->getFlags();
2713
2714 if (Flags.hasNoNaNs() || DAG.isKnownNeverNaN(Operand))
2715 return Operand;
2716
2717 SDValue Quiet = DAG.getNode(ISD::FADD, DL, VT, Operand, Operand);
2718 return DAG.getSelectCC(DL, Operand, Operand, Quiet, Operand, ISD::SETUO);
2719}
2720
2721SDValue MipsTargetLowering::
2722lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const {
2723 // check the depth
2724 if (Op.getConstantOperandVal(0) != 0) {
2725 DAG.getContext()->emitError(
2726 "return address can be determined only for current frame");
2727 return SDValue();
2728 }
2729
2730 MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
2731 MFI.setFrameAddressIsTaken(true);
2732 EVT VT = Op.getValueType();
2733 SDLoc DL(Op);
2734 SDValue FrameAddr = DAG.getCopyFromReg(
2735 DAG.getEntryNode(), DL, ABI.IsN64() ? Mips::FP_64 : Mips::FP, VT);
2736 return FrameAddr;
2737}
2738
2739SDValue MipsTargetLowering::lowerRETURNADDR(SDValue Op,
2740 SelectionDAG &DAG) const {
2741 // check the depth
2742 if (Op.getConstantOperandVal(0) != 0) {
2743 DAG.getContext()->emitError(
2744 "return address can be determined only for current frame");
2745 return SDValue();
2746 }
2747
2749 MachineFrameInfo &MFI = MF.getFrameInfo();
2750 MVT VT = Op.getSimpleValueType();
2751 unsigned RA = ABI.IsN64() ? Mips::RA_64 : Mips::RA;
2752 MFI.setReturnAddressIsTaken(true);
2753
2754 // Return RA, which contains the return address. Mark it an implicit live-in.
2756 return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), Reg, VT);
2757}
2758
2759// An EH_RETURN is the result of lowering llvm.eh.return which in turn is
2760// generated from __builtin_eh_return (offset, handler)
2761// The effect of this is to adjust the stack pointer by "offset"
2762// and then branch to "handler".
2763SDValue MipsTargetLowering::lowerEH_RETURN(SDValue Op, SelectionDAG &DAG)
2764 const {
2766 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
2767
2768 MipsFI->setCallsEhReturn();
2769 SDValue Chain = Op.getOperand(0);
2770 SDValue Offset = Op.getOperand(1);
2771 SDValue Handler = Op.getOperand(2);
2772 SDLoc DL(Op);
2773 EVT Ty = ABI.IsN64() ? MVT::i64 : MVT::i32;
2774
2775 // Store stack offset in V1, store jump target in V0. Glue CopyToReg and
2776 // EH_RETURN nodes, so that instructions are emitted back-to-back.
2777 unsigned OffsetReg = ABI.getReturnRegPtr(1);
2778 unsigned AddrReg = ABI.getReturnRegPtr(0);
2779 Chain = DAG.getCopyToReg(Chain, DL, OffsetReg, Offset, SDValue());
2780 Chain = DAG.getCopyToReg(Chain, DL, AddrReg, Handler, Chain.getValue(1));
2781 return DAG.getNode(MipsISD::EH_RETURN, DL, MVT::Other, Chain,
2782 DAG.getRegister(OffsetReg, Ty),
2783 DAG.getRegister(AddrReg, getPointerTy(MF.getDataLayout())),
2784 Chain.getValue(1));
2785}
2786
2787SDValue MipsTargetLowering::lowerATOMIC_FENCE(SDValue Op,
2788 SelectionDAG &DAG) const {
2789 // FIXME: Need pseudo-fence for 'singlethread' fences
2790 // FIXME: Set SType for weaker fences where supported/appropriate.
2791 unsigned SType = 0;
2792 SDLoc DL(Op);
2793 SyncScope::ID FenceSSID =
2794 static_cast<SyncScope::ID>(Op.getConstantOperandVal(2));
2795
2796 if (Subtarget.hasMips2() && FenceSSID == SyncScope::System)
2797 return DAG.getNode(MipsISD::Sync, DL, MVT::Other, Op.getOperand(0),
2798 DAG.getTargetConstant(SType, DL, MVT::i32));
2799
2800 // singlethread fences only synchronize with signal handlers on the same
2801 // thread and thus only need to preserve instruction order, not actually
2802 // enforce memory ordering.
2803 if ((Subtarget.hasMips1() && !Subtarget.hasMips2()) ||
2804 FenceSSID == SyncScope::SingleThread) {
2805 // MEMBARRIER is a compiler barrier; it codegens to a no-op.
2806 return DAG.getNode(ISD::MEMBARRIER, DL, MVT::Other, Op.getOperand(0));
2807 }
2808
2809 return Op;
2810}
2811
2812SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op,
2813 SelectionDAG &DAG) const {
2814 SDLoc DL(Op);
2815 MVT VT = Subtarget.isGP64bit() ? MVT::i64 : MVT::i32;
2816
2817 SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1);
2818 SDValue Shamt = Op.getOperand(2);
2819 // if shamt < (VT.bits):
2820 // lo = (shl lo, shamt)
2821 // hi = (or (shl hi, shamt) (srl (srl lo, 1), (xor shamt, (VT.bits-1))))
2822 // else:
2823 // lo = 0
2824 // hi = (shl lo, shamt[4:0])
2825 SDValue Not =
2826 DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt,
2827 DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
2828 SDValue ShiftRight1Lo = DAG.getNode(ISD::SRL, DL, VT, Lo,
2829 DAG.getConstant(1, DL, VT));
2830 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, ShiftRight1Lo, Not);
2831 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, Hi, Shamt);
2832 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo);
2833 SDValue ShiftLeftLo = DAG.getNode(ISD::SHL, DL, VT, Lo, Shamt);
2834 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
2835 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32));
2836 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond,
2837 DAG.getConstant(0, DL, VT), ShiftLeftLo);
2838 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftLeftLo, Or);
2839
2840 SDValue Ops[2] = {Lo, Hi};
2841 return DAG.getMergeValues(Ops, DL);
2842}
2843
2844SDValue MipsTargetLowering::lowerShiftRightParts(SDValue Op, SelectionDAG &DAG,
2845 bool IsSRA) const {
2846 SDLoc DL(Op);
2847 SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1);
2848 SDValue Shamt = Op.getOperand(2);
2849 MVT VT = Subtarget.isGP64bit() ? MVT::i64 : MVT::i32;
2850
2851 // if shamt < (VT.bits):
2852 // lo = (or (shl (shl hi, 1), (xor shamt, (VT.bits-1))) (srl lo, shamt))
2853 // if isSRA:
2854 // hi = (sra hi, shamt)
2855 // else:
2856 // hi = (srl hi, shamt)
2857 // else:
2858 // if isSRA:
2859 // lo = (sra hi, shamt[4:0])
2860 // hi = (sra hi, 31)
2861 // else:
2862 // lo = (srl hi, shamt[4:0])
2863 // hi = 0
2864 SDValue Not =
2865 DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt,
2866 DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
2867 SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, VT, Hi,
2868 DAG.getConstant(1, DL, VT));
2869 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, ShiftLeft1Hi, Not);
2870 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, Lo, Shamt);
2871 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo);
2872 SDValue ShiftRightHi = DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL,
2873 DL, VT, Hi, Shamt);
2874 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
2875 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32));
2876 SDValue Ext = DAG.getNode(ISD::SRA, DL, VT, Hi,
2877 DAG.getConstant(VT.getSizeInBits() - 1, DL, VT));
2878
2879 if (!(Subtarget.hasMips4() || Subtarget.hasMips32())) {
2880 SDVTList VTList = DAG.getVTList(VT, VT);
2881 return DAG.getNode(Subtarget.isGP64bit() ? MipsISD::DOUBLE_SELECT_I64
2883 DL, VTList, Cond, ShiftRightHi,
2884 IsSRA ? Ext : DAG.getConstant(0, DL, VT), Or,
2885 ShiftRightHi);
2886 }
2887
2888 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftRightHi, Or);
2889 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond,
2890 IsSRA ? Ext : DAG.getConstant(0, DL, VT), ShiftRightHi);
2891
2892 SDValue Ops[2] = {Lo, Hi};
2893 return DAG.getMergeValues(Ops, DL);
2894}
2895
2897 SDValue Chain, SDValue Src, unsigned Offset) {
2898 SDValue Ptr = LD->getBasePtr();
2899 EVT VT = LD->getValueType(0), MemVT = LD->getMemoryVT();
2900 EVT BasePtrVT = Ptr.getValueType();
2901 SDLoc DL(LD);
2902 SDVTList VTList = DAG.getVTList(VT, MVT::Other);
2903
2904 if (Offset)
2905 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr,
2906 DAG.getConstant(Offset, DL, BasePtrVT));
2907
2908 SDValue Ops[] = { Chain, Ptr, Src };
2909 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT,
2910 LD->getMemOperand());
2911}
2912
2913// Expand an unaligned 32 or 64-bit integer load node.
2916 EVT MemVT = LD->getMemoryVT();
2917
2918 if (Subtarget.systemSupportsUnalignedAccess())
2919 return Op;
2920
2921 // Return if load is aligned or if MemVT is neither i32 nor i64.
2922 if ((LD->getAlign().value() >= (MemVT.getSizeInBits() / 8)) ||
2923 ((MemVT != MVT::i32) && (MemVT != MVT::i64)))
2924 return SDValue();
2925
2926 bool IsLittle = Subtarget.isLittle();
2927 EVT VT = Op.getValueType();
2928 ISD::LoadExtType ExtType = LD->getExtensionType();
2929 SDValue Chain = LD->getChain(), Undef = DAG.getUNDEF(VT);
2930
2931 assert((VT == MVT::i32) || (VT == MVT::i64));
2932
2933 // Expand
2934 // (set dst, (i64 (load baseptr)))
2935 // to
2936 // (set tmp, (ldl (add baseptr, 7), undef))
2937 // (set dst, (ldr baseptr, tmp))
2938 if ((VT == MVT::i64) && (ExtType == ISD::NON_EXTLOAD)) {
2939 SDValue LDL = createLoadLR(MipsISD::LDL, DAG, LD, Chain, Undef,
2940 IsLittle ? 7 : 0);
2941 return createLoadLR(MipsISD::LDR, DAG, LD, LDL.getValue(1), LDL,
2942 IsLittle ? 0 : 7);
2943 }
2944
2945 SDValue LWL = createLoadLR(MipsISD::LWL, DAG, LD, Chain, Undef,
2946 IsLittle ? 3 : 0);
2947 SDValue LWR = createLoadLR(MipsISD::LWR, DAG, LD, LWL.getValue(1), LWL,
2948 IsLittle ? 0 : 3);
2949
2950 // Expand
2951 // (set dst, (i32 (load baseptr))) or
2952 // (set dst, (i64 (sextload baseptr))) or
2953 // (set dst, (i64 (extload baseptr)))
2954 // to
2955 // (set tmp, (lwl (add baseptr, 3), undef))
2956 // (set dst, (lwr baseptr, tmp))
2957 if ((VT == MVT::i32) || (ExtType == ISD::SEXTLOAD) ||
2958 (ExtType == ISD::EXTLOAD))
2959 return LWR;
2960
2961 assert((VT == MVT::i64) && (ExtType == ISD::ZEXTLOAD));
2962
2963 // Expand
2964 // (set dst, (i64 (zextload baseptr)))
2965 // to
2966 // (set tmp0, (lwl (add baseptr, 3), undef))
2967 // (set tmp1, (lwr baseptr, tmp0))
2968 // (set tmp2, (shl tmp1, 32))
2969 // (set dst, (srl tmp2, 32))
2970 SDLoc DL(LD);
2971 SDValue Const32 = DAG.getConstant(32, DL, MVT::i32);
2972 SDValue SLL = DAG.getNode(ISD::SHL, DL, MVT::i64, LWR, Const32);
2973 SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i64, SLL, Const32);
2974 SDValue Ops[] = { SRL, LWR.getValue(1) };
2975 return DAG.getMergeValues(Ops, DL);
2976}
2977
2979 SDValue Chain, unsigned Offset) {
2980 SDValue Ptr = SD->getBasePtr(), Value = SD->getValue();
2981 EVT MemVT = SD->getMemoryVT(), BasePtrVT = Ptr.getValueType();
2982 SDLoc DL(SD);
2983 SDVTList VTList = DAG.getVTList(MVT::Other);
2984
2985 if (Offset)
2986 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr,
2987 DAG.getConstant(Offset, DL, BasePtrVT));
2988
2989 SDValue Ops[] = { Chain, Value, Ptr };
2990 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT,
2991 SD->getMemOperand());
2992}
2993
2994// Expand an unaligned 32 or 64-bit integer store node.
2996 bool IsLittle) {
2997 SDValue Value = SD->getValue(), Chain = SD->getChain();
2998 EVT VT = Value.getValueType();
2999
3000 // Expand
3001 // (store val, baseptr) or
3002 // (truncstore val, baseptr)
3003 // to
3004 // (swl val, (add baseptr, 3))
3005 // (swr val, baseptr)
3006 if ((VT == MVT::i32) || SD->isTruncatingStore()) {
3007 SDValue SWL = createStoreLR(MipsISD::SWL, DAG, SD, Chain,
3008 IsLittle ? 3 : 0);
3009 return createStoreLR(MipsISD::SWR, DAG, SD, SWL, IsLittle ? 0 : 3);
3010 }
3011
3012 assert(VT == MVT::i64);
3013
3014 // Expand
3015 // (store val, baseptr)
3016 // to
3017 // (sdl val, (add baseptr, 7))
3018 // (sdr val, baseptr)
3019 SDValue SDL = createStoreLR(MipsISD::SDL, DAG, SD, Chain, IsLittle ? 7 : 0);
3020 return createStoreLR(MipsISD::SDR, DAG, SD, SDL, IsLittle ? 0 : 7);
3021}
3022
3023// Lower (store (fp_to_sint $fp) $ptr) to (store (TruncIntFP $fp), $ptr).
3025 bool SingleFloat) {
3026 SDValue Val = SD->getValue();
3027
3028 if (Val.getOpcode() != ISD::FP_TO_SINT ||
3029 (Val.getValueSizeInBits() > 32 && SingleFloat))
3030 return SDValue();
3031
3033 SDValue Tr = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Val), FPTy,
3034 Val.getOperand(0));
3035 return DAG.getStore(SD->getChain(), SDLoc(SD), Tr, SD->getBasePtr(),
3036 SD->getPointerInfo(), SD->getAlign(),
3037 SD->getMemOperand()->getFlags());
3038}
3039
3042 EVT MemVT = SD->getMemoryVT();
3043
3044 // Lower unaligned integer stores.
3045 if (!Subtarget.systemSupportsUnalignedAccess() &&
3046 (SD->getAlign().value() < (MemVT.getSizeInBits() / 8)) &&
3047 ((MemVT == MVT::i32) || (MemVT == MVT::i64)))
3048 return lowerUnalignedIntStore(SD, DAG, Subtarget.isLittle());
3049
3050 return lowerFP_TO_SINT_STORE(SD, DAG, Subtarget.isSingleFloat());
3051}
3052
3053SDValue MipsTargetLowering::lowerEH_DWARF_CFA(SDValue Op,
3054 SelectionDAG &DAG) const {
3055
3056 // Return a fixed StackObject with offset 0 which points to the old stack
3057 // pointer.
3059 EVT ValTy = Op->getValueType(0);
3060 int FI = MFI.CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false);
3061 return DAG.getFrameIndex(FI, ValTy);
3062}
3063
3064SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
3065 SelectionDAG &DAG) const {
3066 if (Op.getValueSizeInBits() > 32 && Subtarget.isSingleFloat())
3067 return SDValue();
3068
3069 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits());
3070 SDValue Trunc = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Op), FPTy,
3071 Op.getOperand(0));
3072 return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
3073}
3074
3075SDValue MipsTargetLowering::lowerSTRICT_FP_TO_INT(SDValue Op,
3076 SelectionDAG &DAG) const {
3077 assert(Op->isStrictFPOpcode());
3078 SDValue SrcVal = Op.getOperand(1);
3079 SDLoc Loc(Op);
3080
3081 SDValue Result =
3084 Loc, Op.getValueType(), SrcVal);
3085
3086 return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
3087}
3088
3090 static const MCPhysReg RCRegs[] = {Mips::FCR31};
3091 return RCRegs;
3092}
3093
3094//===----------------------------------------------------------------------===//
3095// Calling Convention Implementation
3096//===----------------------------------------------------------------------===//
3097
3098//===----------------------------------------------------------------------===//
3099// TODO: Implement a generic logic using tblgen that can support this.
3100// Mips O32 ABI rules:
3101// ---
3102// i32 - Passed in A0, A1, A2, A3 and stack
3103// f32 - Only passed in f32 registers if no int reg has been used yet to hold
3104// an argument. Otherwise, passed in A1, A2, A3 and stack.
3105// f64 - Only passed in two aliased f32 registers if no int reg has been used
3106// yet to hold an argument. Otherwise, use A2, A3 and stack. If A1 is
3107// not used, it must be shadowed. If only A3 is available, shadow it and
3108// go to stack.
3109// vXiX - Received as scalarized i32s, passed in A0 - A3 and the stack.
3110// vXf32 - Passed in either a pair of registers {A0, A1}, {A2, A3} or {A0 - A3}
3111// with the remainder spilled to the stack.
3112// vXf64 - Passed in either {A0, A1, A2, A3} or {A2, A3} and in both cases
3113// spilling the remainder to the stack.
3114//
3115// For vararg functions, all arguments are passed in A0, A1, A2, A3 and stack.
3116//===----------------------------------------------------------------------===//
3117
3118static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT,
3119 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
3120 Type *OrigTy, CCState &State,
3121 ArrayRef<MCPhysReg> F64Regs) {
3122 const MipsSubtarget &Subtarget = static_cast<const MipsSubtarget &>(
3123 State.getMachineFunction().getSubtarget());
3124
3125 const MipsABIInfo &ABI = Subtarget.getABI();
3126 ArrayRef<MCPhysReg> IntRegs = ABI.getArgRegs(false);
3127
3128 static const MCPhysReg F32Regs[] = { Mips::F12, Mips::F14 };
3129
3130 const MCPhysReg FloatVectorIntRegs[] = {IntRegs[0], IntRegs[2]};
3131
3132 // Do not process byval args here.
3133 if (ArgFlags.isByVal())
3134 return true;
3135
3136 // Promote i8 and i16
3137 if (ArgFlags.isInReg() && !Subtarget.isLittle()) {
3138 if (LocVT == MVT::i8 || LocVT == MVT::i16 || LocVT == MVT::i32) {
3139 LocVT = MVT::i32;
3140 if (ArgFlags.isSExt())
3141 LocInfo = CCValAssign::SExtUpper;
3142 else if (ArgFlags.isZExt())
3143 LocInfo = CCValAssign::ZExtUpper;
3144 else
3145 LocInfo = CCValAssign::AExtUpper;
3146 }
3147 }
3148
3149 // Promote i8 and i16
3150 if (LocVT == MVT::i8 || LocVT == MVT::i16) {
3151 LocVT = MVT::i32;
3152 if (ArgFlags.isSExt())
3153 LocInfo = CCValAssign::SExt;
3154 else if (ArgFlags.isZExt())
3155 LocInfo = CCValAssign::ZExt;
3156 else
3157 LocInfo = CCValAssign::AExt;
3158 }
3159
3160 unsigned Reg;
3161
3162 // f32 and f64 are allocated in A0, A1, A2, A3 when either of the following
3163 // is true: function is vararg, argument is 3rd or higher, there is previous
3164 // argument which is not f32 or f64.
3165 bool AllocateFloatsInIntReg = State.isVarArg() || ValNo > 1 ||
3166 State.getFirstUnallocated(F32Regs) != ValNo;
3167 Align OrigAlign = ArgFlags.getNonZeroOrigAlign();
3168 bool isI64 = (ValVT == MVT::i32 && OrigAlign == Align(8));
3169 bool isVectorFloat = OrigTy->isVectorTy() && OrigTy->isFPOrFPVectorTy();
3170
3171 // The MIPS vector ABI for floats passes them in a pair of registers
3172 if (ValVT == MVT::i32 && isVectorFloat) {
3173 // This is the start of an vector that was scalarized into an unknown number
3174 // of components. It doesn't matter how many there are. Allocate one of the
3175 // notional 8 byte aligned registers which map onto the argument stack, and
3176 // shadow the register lost to alignment requirements.
3177 if (ArgFlags.isSplit()) {
3178 Reg = State.AllocateReg(FloatVectorIntRegs);
3179 if (Reg == IntRegs[2])
3180 State.AllocateReg(IntRegs[1]);
3181 else if (Reg == 0)
3182 State.AllocateReg(IntRegs[3]);
3183 } else {
3184 // If we're an intermediate component of the split, we can just attempt to
3185 // allocate a register directly.
3186 Reg = State.AllocateReg(IntRegs);
3187 }
3188 } else if (ValVT == MVT::i32 ||
3189 (ValVT == MVT::f32 && AllocateFloatsInIntReg)) {
3190 Reg = State.AllocateReg(IntRegs);
3191 // If this is the first part of an i64 arg,
3192 // the allocated register must be either A0 or A2.
3193 if (isI64 && (Reg == IntRegs[1] || Reg == IntRegs[3]))
3194 Reg = State.AllocateReg(IntRegs);
3195 LocVT = MVT::i32;
3196 } else if (ValVT == MVT::f64 && AllocateFloatsInIntReg) {
3197 // Allocate int register and shadow next int register. If first
3198 // available register is $a1 or $a3, shadow it too.
3199 Reg = State.AllocateReg(IntRegs);
3200 if (Reg == IntRegs[1] || Reg == IntRegs[3])
3201 Reg = State.AllocateReg(IntRegs);
3202
3203 if (Reg) {
3204 LocVT = MVT::i32;
3205
3206 State.addLoc(
3207 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
3208 MCRegister HiReg = State.AllocateReg(IntRegs);
3209 assert(HiReg);
3210 State.addLoc(
3211 CCValAssign::getCustomReg(ValNo, ValVT, HiReg, LocVT, LocInfo));
3212 return false;
3213 }
3214 } else if (ValVT.isFloatingPoint() && !AllocateFloatsInIntReg) {
3215 // we are guaranteed to find an available float register
3216 if (ValVT == MVT::f32) {
3217 Reg = State.AllocateReg(F32Regs);
3218 // Shadow int register
3219 State.AllocateReg(IntRegs);
3220 } else {
3221 Reg = State.AllocateReg(F64Regs);
3222 // Shadow int registers
3223 MCRegister Reg2 = State.AllocateReg(IntRegs);
3224 if (Reg2 == IntRegs[1] || Reg2 == IntRegs[3])
3225 State.AllocateReg(IntRegs);
3226 State.AllocateReg(IntRegs);
3227 }
3228 } else
3229 llvm_unreachable("Cannot handle this ValVT.");
3230
3231 if (!Reg) {
3232 unsigned Offset = State.AllocateStack(ValVT.getStoreSize(), OrigAlign);
3233 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
3234 } else
3235 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
3236
3237 return false;
3238}
3239
3240static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT,
3241 CCValAssign::LocInfo LocInfo,
3242 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3243 CCState &State) {
3244 static const MCPhysReg F64Regs[] = { Mips::D6, Mips::D7 };
3245
3246 return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
3247 F64Regs);
3248}
3249
3250static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT,
3251 CCValAssign::LocInfo LocInfo,
3252 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3253 CCState &State) {
3254 static const MCPhysReg F64Regs[] = { Mips::D12_64, Mips::D14_64 };
3255
3256 return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
3257 F64Regs);
3258}
3259
3260[[maybe_unused]] static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT,
3261 CCValAssign::LocInfo LocInfo,
3262 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3263 CCState &State);
3264
3265#define GET_CALLING_CONV_IMPL
3266#include "MipsGenCallingConv.inc"
3267
3269 return CC_Mips_FixedArg;
3270 }
3271
3273 return RetCC_Mips;
3274 }
3275//===----------------------------------------------------------------------===//
3276// Call Calling Convention Implementation
3277//===----------------------------------------------------------------------===//
3278
3279SDValue MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset,
3280 SDValue Chain, SDValue Arg,
3281 const SDLoc &DL, bool IsTailCall,
3282 SelectionDAG &DAG) const {
3283 if (!IsTailCall) {
3284 SDValue PtrOff =
3285 DAG.getNode(ISD::ADD, DL, getPointerTy(DAG.getDataLayout()), StackPtr,
3287 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo());
3288 }
3289
3291 int FI = MFI.CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false);
3292 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
3293 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), MaybeAlign(),
3295}
3296
3299 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
3300 bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
3301 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
3302 // Insert node "GP copy globalreg" before call to function.
3303 //
3304 // R_MIPS_CALL* operators (emitted when non-local functions are called
3305 // in PIC mode) allow symbols to be resolved via lazy binding.
3306 // The lazy binding stub requires GP to point to the GOT.
3307 // Note that we don't need GP to point to the GOT for indirect calls
3308 // (when R_MIPS_CALL* is not used for the call) because Mips linker generates
3309 // lazy binding stub for a function only when R_MIPS_CALL* are the only relocs
3310 // used for the function (that is, Mips linker doesn't generate lazy binding
3311 // stub for a function whose address is taken in the program).
3312 if (IsPICCall && !LocalLinkage && IsCallReloc) {
3313 unsigned GPReg = ABI.IsN64() ? Mips::GP_64 : Mips::GP;
3314 EVT Ty = ABI.IsN64() ? MVT::i64 : MVT::i32;
3315 RegsToPass.push_back(std::make_pair(GPReg, getGlobalReg(CLI.DAG, Ty)));
3316 }
3317
3318 // Build a sequence of copy-to-reg nodes chained together with token
3319 // chain and flag operands which copy the outgoing args into registers.
3320 // The InGlue in necessary since all emitted instructions must be
3321 // stuck together.
3322 SDValue InGlue;
3323
3324 for (auto &R : RegsToPass) {
3325 Chain = CLI.DAG.getCopyToReg(Chain, CLI.DL, R.first, R.second, InGlue);
3326 InGlue = Chain.getValue(1);
3327 }
3328
3329 // Add argument registers to the end of the list so that they are
3330 // known live into the call.
3331 for (auto &R : RegsToPass)
3332 Ops.push_back(CLI.DAG.getRegister(R.first, R.second.getValueType()));
3333
3334 // Add a register mask operand representing the call-preserved registers.
3335 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
3336 const uint32_t *Mask =
3337 TRI->getCallPreservedMask(CLI.DAG.getMachineFunction(), CLI.CallConv);
3338 assert(Mask && "Missing call preserved mask for calling convention");
3339 if (Subtarget.inMips16HardFloat()) {
3341 StringRef Sym = G->getGlobal()->getName();
3342 Function *F = G->getGlobal()->getParent()->getFunction(Sym);
3343 if (F && F->hasFnAttribute("__Mips16RetHelper")) {
3345 }
3346 }
3347 }
3348 Ops.push_back(CLI.DAG.getRegisterMask(Mask));
3349
3350 if (InGlue.getNode())
3351 Ops.push_back(InGlue);
3352}
3353
3355 SDNode *Node) const {
3356 switch (MI.getOpcode()) {
3357 default:
3358 return;
3359 case Mips::JALR:
3360 case Mips::JALRPseudo:
3361 case Mips::JALR64:
3362 case Mips::JALR64Pseudo:
3363 case Mips::JALR16_MM:
3364 case Mips::JALRC16_MMR6:
3365 case Mips::TAILCALLREG:
3366 case Mips::TAILCALLREG64:
3367 case Mips::TAILCALLR6REG:
3368 case Mips::TAILCALL64R6REG:
3369 case Mips::TAILCALLREG_MM:
3370 case Mips::TAILCALLREG_MMR6: {
3371 if (!Subtarget.getMCCLOpts().jalr_reloc || Subtarget.inMips16Mode() ||
3372 !isPositionIndependent() || Node->getNumOperands() < 1 ||
3373 Node->getOperand(0).getNumOperands() < 2) {
3374 return;
3375 }
3376 // We are after the callee address, set by LowerCall().
3377 // If added to MI, asm printer will emit .reloc R_MIPS_JALR for the
3378 // symbol.
3379 const SDValue TargetAddr = Node->getOperand(0).getOperand(1);
3380 MCSymbol *S = nullptr;
3381 if (const GlobalAddressSDNode *G =
3383 const GlobalValue *GV = G->getGlobal();
3384
3385 // We must not emit the R_MIPS_JALR relocation against data symbols
3386 // since this will cause run-time crashes if the linker replaces the
3387 // call instruction with a relative branch to the data symbol.
3388 if (!isa<Function>(GV)) {
3389 LLVM_DEBUG(dbgs() << "Not adding R_MIPS_JALR against data symbol "
3390 << GV->getName() << "\n");
3391 return;
3392 }
3393 S = getTargetMachine().getSymbol(GV);
3394 }
3395 else if (const ExternalSymbolSDNode *ES =
3397 S = MI.getParent()->getParent()->getContext().getOrCreateSymbol(
3398 ES->getSymbol());
3399 }
3400
3401 if (!S)
3402 return;
3403
3404 LLVM_DEBUG(dbgs() << "Adding R_MIPS_JALR against " << S->getName()
3405 << "\n");
3407 }
3408 }
3409}
3410
3411/// LowerCall - functions arguments are copied from virtual regs to
3412/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
3413SDValue
3414MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
3415 SmallVectorImpl<SDValue> &InVals) const {
3416 SelectionDAG &DAG = CLI.DAG;
3417 SDLoc DL = CLI.DL;
3419 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
3421 SDValue Chain = CLI.Chain;
3422 SDValue Callee = CLI.Callee;
3423 bool &IsTailCall = CLI.IsTailCall;
3424 CallingConv::ID CallConv = CLI.CallConv;
3425 bool IsVarArg = CLI.IsVarArg;
3426 const CallBase *CB = CLI.CB;
3427
3429 MachineFrameInfo &MFI = MF.getFrameInfo();
3431 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
3432 bool IsPIC = isPositionIndependent();
3433
3434 // Analyze operands of the call, assigning locations to each operand.
3436 MipsCCState CCInfo(
3437 CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, *DAG.getContext(),
3439
3440 const ExternalSymbolSDNode *ES =
3442
3443 // There is one case where CALLSEQ_START..CALLSEQ_END can be nested, which
3444 // is during the lowering of a call with a byval argument which produces
3445 // a call to memcpy. For the O32 case, this causes the caller to allocate
3446 // stack space for the reserved argument area for the callee, then recursively
3447 // again for the memcpy call. In the NEWABI case, this doesn't occur as those
3448 // ABIs mandate that the callee allocates the reserved argument area. We do
3449 // still produce nested CALLSEQ_START..CALLSEQ_END with zero space though.
3450 //
3451 // If the callee has a byval argument and memcpy is used, we are mandated
3452 // to already have produced a reserved argument area for the callee for O32.
3453 // Therefore, the reserved argument area can be reused for both calls.
3454 //
3455 // Other cases of calling memcpy cannot have a chain with a CALLSEQ_START
3456 // present, as we have yet to hook that node onto the chain.
3457 //
3458 // Hence, the CALLSEQ_START and CALLSEQ_END nodes can be eliminated in this
3459 // case. GCC does a similar trick, in that wherever possible, it calculates
3460 // the maximum out going argument area (including the reserved area), and
3461 // preallocates the stack space on entrance to the caller.
3462 //
3463 // FIXME: We should do the same for efficiency and space.
3464
3465 // Note: The check on the calling convention below must match
3466 // MipsABIInfo::GetCalleeAllocdArgSizeInBytes().
3467 bool MemcpyInByVal = ES && StringRef(ES->getSymbol()) == "memcpy" &&
3468 CallConv != CallingConv::Fast &&
3469 Chain.getOpcode() == ISD::CALLSEQ_START;
3470
3471 // Allocate the reserved argument area. It seems strange to do this from the
3472 // caller side but removing it breaks the frame size calculation.
3473 unsigned ReservedArgArea =
3474 MemcpyInByVal ? 0 : ABI.GetCalleeAllocdArgSizeInBytes(CallConv);
3475 CCInfo.AllocateStack(ReservedArgArea, Align(1));
3476
3477 CCInfo.AnalyzeCallOperands(Outs, CC_Mips);
3478
3479 // Get a count of how many bytes are to be pushed on the stack.
3480 unsigned StackSize = CCInfo.getStackSize();
3481
3482 // Call site info for function parameters tracking and call base type info.
3484 // Set type id for call site info.
3485 setTypeIdForCallsiteInfo(CB, MF, CSInfo);
3486
3487 // Check if it's really possible to do a tail call.
3488 // For non-musttail calls, restrict to functions that won't require $gp
3489 // restoration. In PIC mode, calling external functions via tail call can
3490 // cause issues with $gp register handling (see D24763).
3491 bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
3492 bool CalleeIsLocal = true;
3494 const GlobalValue *GV = G->getGlobal();
3495 bool HasLocalLinkage = GV->hasLocalLinkage() || GV->hasPrivateLinkage();
3496 bool HasHiddenVisibility =
3498 if (GV->isDeclarationForLinker())
3499 CalleeIsLocal = HasLocalLinkage || HasHiddenVisibility;
3500 else
3501 CalleeIsLocal = GV->isDSOLocal();
3502 }
3503
3504 if (IsTailCall) {
3505 if (!Subtarget.getCLOpts().tail_calls) {
3506 IsTailCall = false;
3507 if (IsMustTail)
3508 report_fatal_error("failed to perform tail call elimination on a call "
3509 "site marked musttail");
3510 } else {
3511 bool Eligible = isEligibleForTailCallOptimization(
3512 CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>());
3513 if (!Eligible || !CalleeIsLocal) {
3514 IsTailCall = false;
3515 if (IsMustTail)
3517 "failed to perform tail call elimination on a call "
3518 "site marked musttail");
3519 }
3520 }
3521 }
3522
3523 if (IsTailCall)
3524 ++NumTailCalls;
3525
3526 // Chain is the output chain of the last Load/Store or CopyToReg node.
3527 // ByValChain is the output chain of the last Memcpy node created for copying
3528 // byval arguments to the stack.
3529 unsigned StackAlignment = TFL->getStackAlignment();
3530 StackSize = alignTo(StackSize, StackAlignment);
3531
3532 if (!(IsTailCall || MemcpyInByVal))
3533 Chain = DAG.getCALLSEQ_START(Chain, StackSize, 0, DL);
3534
3535 SDValue StackPtr =
3536 DAG.getCopyFromReg(Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP,
3538 std::deque<std::pair<unsigned, SDValue>> RegsToPass;
3539 SmallVector<SDValue, 8> MemOpChains;
3540
3541 CCInfo.rewindByValRegsInfo();
3542
3543 // Walk the register/memloc assignments, inserting copies/loads.
3544 for (unsigned i = 0, e = ArgLocs.size(), OutIdx = 0; i != e; ++i, ++OutIdx) {
3545 SDValue Arg = OutVals[OutIdx];
3546 CCValAssign &VA = ArgLocs[i];
3547 MVT ValVT = VA.getValVT(), LocVT = VA.getLocVT();
3548 ISD::ArgFlagsTy Flags = Outs[OutIdx].Flags;
3549 bool UseUpperBits = false;
3550
3551 // ByVal Arg.
3552 if (Flags.isByVal()) {
3553 unsigned FirstByValReg, LastByValReg;
3554 unsigned ByValIdx = CCInfo.getInRegsParamsProcessed();
3555 CCInfo.getInRegsParamInfo(ByValIdx, FirstByValReg, LastByValReg);
3556
3557 assert(Flags.getByValSize() &&
3558 "ByVal args of size 0 should have been ignored by front-end.");
3559 assert(ByValIdx < CCInfo.getInRegsParamsCount());
3560 assert(!IsTailCall &&
3561 "Do not tail-call optimize if there is a byval argument.");
3562 passByValArg(Chain, DL, RegsToPass, MemOpChains, StackPtr, MFI, DAG, Arg,
3563 FirstByValReg, LastByValReg, Flags, Subtarget.isLittle(),
3564 VA);
3565 CCInfo.nextInRegsParam();
3566 continue;
3567 }
3568
3569 // Promote the value if needed.
3570 switch (VA.getLocInfo()) {
3571 default:
3572 llvm_unreachable("Unknown loc info!");
3573 case CCValAssign::Full:
3574 if (VA.isRegLoc()) {
3575 if ((ValVT == MVT::f32 && LocVT == MVT::i32) ||
3576 (ValVT == MVT::f64 && LocVT == MVT::i64) ||
3577 (ValVT == MVT::i64 && LocVT == MVT::f64))
3578 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
3579 else if (ValVT == MVT::f64 && LocVT == MVT::i32) {
3580 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
3581 Arg, DAG.getConstant(0, DL, MVT::i32));
3582 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
3583 Arg, DAG.getConstant(1, DL, MVT::i32));
3584 if (!Subtarget.isLittle())
3585 std::swap(Lo, Hi);
3586
3587 assert(VA.needsCustom());
3588
3589 Register LocRegLo = VA.getLocReg();
3590 Register LocRegHigh = ArgLocs[++i].getLocReg();
3591 RegsToPass.push_back(std::make_pair(LocRegLo, Lo));
3592 RegsToPass.push_back(std::make_pair(LocRegHigh, Hi));
3593 continue;
3594 }
3595 }
3596 break;
3597 case CCValAssign::BCvt:
3598 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
3599 break;
3601 UseUpperBits = true;
3602 [[fallthrough]];
3603 case CCValAssign::SExt:
3604 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg);
3605 break;
3607 UseUpperBits = true;
3608 [[fallthrough]];
3609 case CCValAssign::ZExt:
3610 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, LocVT, Arg);
3611 break;
3613 UseUpperBits = true;
3614 [[fallthrough]];
3615 case CCValAssign::AExt:
3616 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, LocVT, Arg);
3617 break;
3618 }
3619
3620 if (UseUpperBits) {
3621 unsigned ValSizeInBits = Outs[OutIdx].ArgVT.getSizeInBits();
3622 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3623 Arg = DAG.getNode(
3624 ISD::SHL, DL, VA.getLocVT(), Arg,
3625 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3626 }
3627
3628 // Arguments that can be passed on register must be kept at
3629 // RegsToPass vector
3630 if (VA.isRegLoc()) {
3631 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
3632
3633 // If the parameter is passed through reg $D, which splits into
3634 // two physical registers, avoid creating call site info.
3635 if (Mips::AFGR64RegClass.contains(VA.getLocReg()))
3636 continue;
3637
3638 // Collect CSInfo about which register passes which parameter.
3639 const TargetOptions &Options = DAG.getTarget().Options;
3640 if (Options.EmitCallSiteInfo)
3641 CSInfo.ArgRegPairs.emplace_back(VA.getLocReg(), i);
3642
3643 continue;
3644 }
3645
3646 // Register can't get to this point...
3647 assert(VA.isMemLoc());
3648
3649 // emit ISD::STORE whichs stores the
3650 // parameter value to a stack Location
3651 MemOpChains.push_back(passArgOnStack(StackPtr, VA.getLocMemOffset(),
3652 Chain, Arg, DL, IsTailCall, DAG));
3653 }
3654
3655 // Transform all store nodes into one single node because all store
3656 // nodes are independent of each other.
3657 if (!MemOpChains.empty())
3658 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
3659
3660 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
3661 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
3662 // node so that legalize doesn't hack it.
3663
3664 EVT Ty = Callee.getValueType();
3665 bool GlobalOrExternal = false, IsCallReloc = false;
3666
3667 // The long-calls feature is ignored in case of PIC.
3668 // While we do not support -mshared / -mno-shared properly,
3669 // ignore long-calls in case of -mabicalls too.
3670 if (!Subtarget.isABICalls() && !IsPIC) {
3671 // If the function should be called using "long call",
3672 // get its address into a register to prevent using
3673 // of the `jal` instruction for the direct call.
3674 if (auto *N = dyn_cast<ExternalSymbolSDNode>(Callee)) {
3675 if (Subtarget.useLongCalls())
3676 Callee = Subtarget.hasSym32()
3677 ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
3678 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
3679 } else if (auto *N = dyn_cast<GlobalAddressSDNode>(Callee)) {
3680 bool UseLongCalls = Subtarget.useLongCalls();
3681 // If the function has long-call/far/near attribute
3682 // it overrides command line switch pased to the backend.
3683 if (auto *F = dyn_cast<Function>(N->getGlobal())) {
3684 if (F->hasFnAttribute("long-call"))
3685 UseLongCalls = true;
3686 else if (F->hasFnAttribute("short-call"))
3687 UseLongCalls = false;
3688 }
3689 if (UseLongCalls)
3690 Callee = Subtarget.hasSym32()
3691 ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
3692 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
3693 }
3694 }
3695
3696 bool LocalLinkage = false;
3697 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
3698 if (Subtarget.isTargetCOFF() &&
3699 G->getGlobal()->hasDLLImportStorageClass()) {
3700 assert(Subtarget.isTargetWindows() &&
3701 "Windows is the only supported COFF target");
3702 auto PtrInfo = MachinePointerInfo();
3703 Callee = DAG.getLoad(Ty, DL, Chain,
3704 getDllimportSymbol(G, SDLoc(G), Ty, DAG), PtrInfo);
3705 } else if (IsPIC) {
3706 const GlobalValue *Val = G->getGlobal();
3707 LocalLinkage = Val->hasLocalLinkage();
3708
3709 if (LocalLinkage)
3710 Callee = getAddrLocal(G, DL, Ty, DAG, ABI.IsN32() || ABI.IsN64());
3711 else if (Subtarget.useXGOT()) {
3713 MipsII::MO_CALL_LO16, Chain,
3714 FuncInfo->callPtrInfo(MF, Val));
3715 IsCallReloc = true;
3716 } else {
3717 Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
3718 FuncInfo->callPtrInfo(MF, Val));
3719 IsCallReloc = true;
3720 }
3721 } else
3722 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL,
3723 getPointerTy(DAG.getDataLayout()), 0,
3725 GlobalOrExternal = true;
3726 }
3727 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
3728 const char *Sym = S->getSymbol();
3729
3730 if (!IsPIC) // static
3733 else if (Subtarget.useXGOT()) {
3735 MipsII::MO_CALL_LO16, Chain,
3736 FuncInfo->callPtrInfo(MF, Sym));
3737 IsCallReloc = true;
3738 } else { // PIC
3739 Callee = getAddrGlobal(S, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
3740 FuncInfo->callPtrInfo(MF, Sym));
3741 IsCallReloc = true;
3742 }
3743
3744 GlobalOrExternal = true;
3745 }
3746
3747 SmallVector<SDValue, 8> Ops(1, Chain);
3748 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
3749
3750 getOpndList(Ops, RegsToPass, IsPIC, GlobalOrExternal, LocalLinkage,
3751 IsCallReloc, CLI, Callee, Chain);
3752
3753 if (IsTailCall) {
3755 SDValue Ret = DAG.getNode(MipsISD::TailCall, DL, MVT::Other, Ops);
3756 DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
3757 return Ret;
3758 }
3759
3760 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops);
3761 SDValue InGlue = Chain.getValue(1);
3762
3763 DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
3764
3765 // Create the CALLSEQ_END node in the case of where it is not a call to
3766 // memcpy.
3767 if (!(MemcpyInByVal)) {
3768 Chain = DAG.getCALLSEQ_END(Chain, StackSize, 0, InGlue, DL);
3769 InGlue = Chain.getValue(1);
3770 }
3771
3772 // Handle result values, copying them out of physregs into vregs that we
3773 // return.
3774 return LowerCallResult(Chain, InGlue, CallConv, IsVarArg, Ins, DL, DAG,
3775 InVals, CLI);
3776}
3777
3778/// LowerCallResult - Lower the result values of a call into the
3779/// appropriate copies out of appropriate physical registers.
3780SDValue MipsTargetLowering::LowerCallResult(
3781 SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool IsVarArg,
3782 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
3785 // Assign locations to each value returned by this call.
3787 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
3788 *DAG.getContext());
3789
3790 CCInfo.AnalyzeCallResult(Ins, RetCC_Mips);
3791
3792 // Copy all of the result registers out of their specified physreg.
3793 for (unsigned i = 0; i != RVLocs.size(); ++i) {
3794 CCValAssign &VA = RVLocs[i];
3795 assert(VA.isRegLoc() && "Can only return in registers!");
3796
3797 SDValue Val = DAG.getCopyFromReg(Chain, DL, RVLocs[i].getLocReg(),
3798 RVLocs[i].getLocVT(), InGlue);
3799 Chain = Val.getValue(1);
3800 InGlue = Val.getValue(2);
3801
3802 if (VA.isUpperBitsInLoc()) {
3803 unsigned ValSizeInBits = Ins[i].ArgVT.getSizeInBits();
3804 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3805 unsigned Shift =
3807 Val = DAG.getNode(
3808 Shift, DL, VA.getLocVT(), Val,
3809 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3810 }
3811
3812 switch (VA.getLocInfo()) {
3813 default:
3814 llvm_unreachable("Unknown loc info!");
3815 case CCValAssign::Full:
3816 break;
3817 case CCValAssign::BCvt:
3818 Val = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), Val);
3819 break;
3820 case CCValAssign::AExt:
3822 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3823 break;
3824 case CCValAssign::ZExt:
3826 Val = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), Val,
3827 DAG.getValueType(VA.getValVT()));
3828 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3829 break;
3830 case CCValAssign::SExt:
3832 Val = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), Val,
3833 DAG.getValueType(VA.getValVT()));
3834 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3835 break;
3836 }
3837
3838 InVals.push_back(Val);
3839 }
3840
3841 return Chain;
3842}
3843
3845 EVT ArgVT, const SDLoc &DL,
3846 SelectionDAG &DAG) {
3847 MVT LocVT = VA.getLocVT();
3848 EVT ValVT = VA.getValVT();
3849
3850 // Shift into the upper bits if necessary.
3851 switch (VA.getLocInfo()) {
3852 default:
3853 break;
3857 unsigned ValSizeInBits = ArgVT.getSizeInBits();
3858 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3859 unsigned Opcode =
3861 Val = DAG.getNode(
3862 Opcode, DL, VA.getLocVT(), Val,
3863 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3864 break;
3865 }
3866 }
3867
3868 // If this is an value smaller than the argument slot size (32-bit for O32,
3869 // 64-bit for N32/N64), it has been promoted in some way to the argument slot
3870 // size. Extract the value and insert any appropriate assertions regarding
3871 // sign/zero extension.
3872 switch (VA.getLocInfo()) {
3873 default:
3874 llvm_unreachable("Unknown loc info!");
3875 case CCValAssign::Full:
3876 break;
3878 case CCValAssign::AExt:
3879 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3880 break;
3882 case CCValAssign::SExt:
3883 Val = DAG.getNode(ISD::AssertSext, DL, LocVT, Val, DAG.getValueType(ValVT));
3884 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3885 break;
3887 case CCValAssign::ZExt:
3888 Val = DAG.getNode(ISD::AssertZext, DL, LocVT, Val, DAG.getValueType(ValVT));
3889 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3890 break;
3891 case CCValAssign::BCvt:
3892 Val = DAG.getNode(ISD::BITCAST, DL, ValVT, Val);
3893 break;
3894 }
3895
3896 return Val;
3897}
3898
3899//===----------------------------------------------------------------------===//
3900// Formal Arguments Calling Convention Implementation
3901//===----------------------------------------------------------------------===//
3902/// LowerFormalArguments - transform physical registers into virtual registers
3903/// and generate load operations for arguments places on the stack.
3904SDValue MipsTargetLowering::LowerFormalArguments(
3905 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
3906 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
3907 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
3909 MachineFrameInfo &MFI = MF.getFrameInfo();
3910 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
3911
3912 MipsFI->setVarArgsFrameIndex(0);
3913
3914 // Used with vargs to acumulate store chains.
3915 std::vector<SDValue> OutChains;
3916
3917 // Assign locations to all of the incoming arguments.
3919 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
3920 *DAG.getContext());
3921 CCInfo.AllocateStack(ABI.GetCalleeAllocdArgSizeInBytes(CallConv), Align(1));
3923 Function::const_arg_iterator FuncArg = Func.arg_begin();
3924
3925 if (Func.hasFnAttribute("interrupt") && !Func.arg_empty())
3927 "Functions with the interrupt attribute cannot have arguments!");
3928
3929 CCInfo.AnalyzeFormalArguments(Ins, CC_Mips_FixedArg);
3930 MipsFI->setFormalArgInfo(CCInfo.getStackSize(),
3931 CCInfo.getInRegsParamsCount() > 0);
3932
3933 unsigned CurArgIdx = 0;
3934 CCInfo.rewindByValRegsInfo();
3935
3936 for (unsigned i = 0, e = ArgLocs.size(), InsIdx = 0; i != e; ++i, ++InsIdx) {
3937 CCValAssign &VA = ArgLocs[i];
3938 if (Ins[InsIdx].isOrigArg()) {
3939 std::advance(FuncArg, Ins[InsIdx].getOrigArgIndex() - CurArgIdx);
3940 CurArgIdx = Ins[InsIdx].getOrigArgIndex();
3941 }
3942 EVT ValVT = VA.getValVT();
3943 ISD::ArgFlagsTy Flags = Ins[InsIdx].Flags;
3944 bool IsRegLoc = VA.isRegLoc();
3945
3946 if (Flags.isByVal()) {
3947 assert(Ins[InsIdx].isOrigArg() && "Byval arguments cannot be implicit");
3948 unsigned FirstByValReg, LastByValReg;
3949 unsigned ByValIdx = CCInfo.getInRegsParamsProcessed();
3950 CCInfo.getInRegsParamInfo(ByValIdx, FirstByValReg, LastByValReg);
3951
3952 assert(Flags.getByValSize() &&
3953 "ByVal args of size 0 should have been ignored by front-end.");
3954 assert(ByValIdx < CCInfo.getInRegsParamsCount());
3955 copyByValRegs(Chain, DL, OutChains, DAG, Flags, InVals, &*FuncArg,
3956 FirstByValReg, LastByValReg, VA, CCInfo);
3957 CCInfo.nextInRegsParam();
3958 continue;
3959 }
3960
3961 // Arguments stored on registers
3962 if (IsRegLoc) {
3963 MVT RegVT = VA.getLocVT();
3964 Register ArgReg = VA.getLocReg();
3965 const TargetRegisterClass *RC = getRegClassFor(RegVT);
3966
3967 // Transform the arguments stored on
3968 // physical registers into virtual ones
3969 unsigned Reg = addLiveIn(DAG.getMachineFunction(), ArgReg, RC);
3970 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegVT);
3971
3972 ArgValue =
3973 UnpackFromArgumentSlot(ArgValue, VA, Ins[InsIdx].ArgVT, DL, DAG);
3974
3975 // Handle floating point arguments passed in integer registers and
3976 // long double arguments passed in floating point registers.
3977 if ((RegVT == MVT::i32 && ValVT == MVT::f32) ||
3978 (RegVT == MVT::i64 && ValVT == MVT::f64) ||
3979 (RegVT == MVT::f64 && ValVT == MVT::i64))
3980 ArgValue = DAG.getNode(ISD::BITCAST, DL, ValVT, ArgValue);
3981 else if (ABI.IsO32() && RegVT == MVT::i32 &&
3982 ValVT == MVT::f64) {
3983 assert(VA.needsCustom() && "Expected custom argument for f64 split");
3984 CCValAssign &NextVA = ArgLocs[++i];
3985 unsigned Reg2 =
3986 addLiveIn(DAG.getMachineFunction(), NextVA.getLocReg(), RC);
3987 SDValue ArgValue2 = DAG.getCopyFromReg(Chain, DL, Reg2, RegVT);
3988 if (!Subtarget.isLittle())
3989 std::swap(ArgValue, ArgValue2);
3990 ArgValue = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64,
3991 ArgValue, ArgValue2);
3992 }
3993
3994 InVals.push_back(ArgValue);
3995 } else { // VA.isRegLoc()
3996 MVT LocVT = VA.getLocVT();
3997
3998 assert(!VA.needsCustom() && "unexpected custom memory argument");
3999
4000 // Only arguments pased on the stack should make it here.
4001 assert(VA.isMemLoc());
4002
4003 // The stack pointer offset is relative to the caller stack frame.
4004 int FI = MFI.CreateFixedObject(LocVT.getSizeInBits() / 8,
4005 VA.getLocMemOffset(), true);
4006
4007 // Create load nodes to retrieve arguments from the stack
4008 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
4009 SDValue ArgValue = DAG.getLoad(
4010 LocVT, DL, Chain, FIN,
4012 OutChains.push_back(ArgValue.getValue(1));
4013
4014 ArgValue =
4015 UnpackFromArgumentSlot(ArgValue, VA, Ins[InsIdx].ArgVT, DL, DAG);
4016
4017 InVals.push_back(ArgValue);
4018 }
4019 }
4020
4021 for (unsigned i = 0, e = ArgLocs.size(), InsIdx = 0; i != e; ++i, ++InsIdx) {
4022
4023 if (ArgLocs[i].needsCustom()) {
4024 ++i;
4025 continue;
4026 }
4027
4028 // The mips ABIs for returning structs by value requires that we copy
4029 // the sret argument into $v0 for the return. Save the argument into
4030 // a virtual register so that we can access it from the return points.
4031 if (Ins[InsIdx].Flags.isSRet()) {
4032 unsigned Reg = MipsFI->getSRetReturnReg();
4033 if (!Reg) {
4035 getRegClassFor(ABI.IsN64() ? MVT::i64 : MVT::i32));
4036 MipsFI->setSRetReturnReg(Reg);
4037 }
4038 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), DL, Reg, InVals[i]);
4039 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Copy, Chain);
4040 break;
4041 }
4042 }
4043
4044 if (IsVarArg)
4045 writeVarArgRegs(OutChains, Chain, DL, DAG, CCInfo);
4046
4047 // All stores are grouped in one node to allow the matching between
4048 // the size of Ins and InVals. This only happens when on varg functions
4049 if (!OutChains.empty()) {
4050 OutChains.push_back(Chain);
4051 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
4052 }
4053
4054 return Chain;
4055}
4056
4057//===----------------------------------------------------------------------===//
4058// Return Value Calling Convention Implementation
4059//===----------------------------------------------------------------------===//
4060
4061bool
4062MipsTargetLowering::CanLowerReturn(CallingConv::ID CallConv,
4063 MachineFunction &MF, bool IsVarArg,
4065 LLVMContext &Context, const Type *RetTy) const {
4067 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
4068 return CCInfo.CheckReturn(Outs, RetCC_Mips);
4069}
4070
4071bool MipsTargetLowering::shouldSignExtendTypeInLibCall(Type *Ty,
4072 bool IsSigned) const {
4073 if ((ABI.IsN32() || ABI.IsN64()) && Ty->isIntegerTy(32))
4074 return true;
4075
4076 return IsSigned;
4077}
4078
4079SDValue
4080MipsTargetLowering::LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps,
4081 const SDLoc &DL,
4082 SelectionDAG &DAG) const {
4084 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4085
4086 MipsFI->setISR();
4087
4088 return DAG.getNode(MipsISD::ERet, DL, MVT::Other, RetOps);
4089}
4090
4091SDValue
4092MipsTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
4093 bool IsVarArg,
4095 const SmallVectorImpl<SDValue> &OutVals,
4096 const SDLoc &DL, SelectionDAG &DAG) const {
4097 // CCValAssign - represent the assignment of
4098 // the return value to a location
4101
4102 // CCState - Info about the registers and stack slot.
4103 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, *DAG.getContext());
4104
4105 // Analyze return values.
4106 CCInfo.AnalyzeReturn(Outs, RetCC_Mips);
4107
4108 SDValue Glue;
4109 SmallVector<SDValue, 4> RetOps(1, Chain);
4110
4111 // Copy the result values into the output registers.
4112 for (unsigned i = 0; i != RVLocs.size(); ++i) {
4113 SDValue Val = OutVals[i];
4114 CCValAssign &VA = RVLocs[i];
4115 assert(VA.isRegLoc() && "Can only return in registers!");
4116 bool UseUpperBits = false;
4117
4118 switch (VA.getLocInfo()) {
4119 default:
4120 llvm_unreachable("Unknown loc info!");
4121 case CCValAssign::Full:
4122 break;
4123 case CCValAssign::BCvt:
4124 Val = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Val);
4125 break;
4127 UseUpperBits = true;
4128 [[fallthrough]];
4129 case CCValAssign::AExt:
4130 Val = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Val);
4131 break;
4133 UseUpperBits = true;
4134 [[fallthrough]];
4135 case CCValAssign::ZExt:
4136 Val = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Val);
4137 break;
4139 UseUpperBits = true;
4140 [[fallthrough]];
4141 case CCValAssign::SExt:
4142 Val = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Val);
4143 break;
4144 }
4145
4146 if (UseUpperBits) {
4147 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits();
4148 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
4149 Val = DAG.getNode(
4150 ISD::SHL, DL, VA.getLocVT(), Val,
4151 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
4152 }
4153
4154 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Glue);
4155
4156 // Guarantee that all emitted copies are stuck together with flags.
4157 Glue = Chain.getValue(1);
4158 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
4159 }
4160
4161 // The mips ABIs for returning structs by value requires that we copy
4162 // the sret argument into $v0 for the return. We saved the argument into
4163 // a virtual register in the entry block, so now we copy the value out
4164 // and into $v0.
4165 if (MF.getFunction().hasStructRetAttr()) {
4166 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4167 unsigned Reg = MipsFI->getSRetReturnReg();
4168
4169 if (!Reg)
4170 llvm_unreachable("sret virtual register not created in the entry block");
4171 SDValue Val =
4172 DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy(DAG.getDataLayout()));
4173 unsigned V0 = ABI.getReturnRegPtr(0);
4174
4175 Chain = DAG.getCopyToReg(Chain, DL, V0, Val, Glue);
4176 Glue = Chain.getValue(1);
4177 RetOps.push_back(DAG.getRegister(V0, getPointerTy(DAG.getDataLayout())));
4178 }
4179
4180 RetOps[0] = Chain; // Update chain.
4181
4182 // Add the glue if we have it.
4183 if (Glue.getNode())
4184 RetOps.push_back(Glue);
4185
4186 // ISRs must use "eret".
4187 if (DAG.getMachineFunction().getFunction().hasFnAttribute("interrupt"))
4188 return LowerInterruptReturn(RetOps, DL, DAG);
4189
4190 // Standard return on Mips is a "jr $ra"
4191 return DAG.getNode(MipsISD::Ret, DL, MVT::Other, RetOps);
4192}
4193
4194//===----------------------------------------------------------------------===//
4195// Mips Inline Assembly Support
4196//===----------------------------------------------------------------------===//
4197
4198/// getConstraintType - Given a constraint letter, return the type of
4199/// constraint it is for this target.
4201MipsTargetLowering::getConstraintType(StringRef Constraint) const {
4202 // Mips specific constraints
4203 // GCC config/mips/constraints.md
4204 //
4205 // 'd' : An address register. Equivalent to r
4206 // unless generating MIPS16 code.
4207 // 'y' : Equivalent to r; retained for
4208 // backwards compatibility.
4209 // 'c' : A register suitable for use in an indirect
4210 // jump. This will always be $25 for -mabicalls.
4211 // 'l' : The lo register. 1 word storage.
4212 // 'x' : The hilo register pair. Double word storage.
4213 if (Constraint.size() == 1) {
4214 switch (Constraint[0]) {
4215 default : break;
4216 case 'd':
4217 case 'y':
4218 case 'f':
4219 case 'c':
4220 case 'l':
4221 case 'x':
4222 return C_RegisterClass;
4223 case 'R':
4224 return C_Memory;
4225 }
4226 }
4227
4228 if (Constraint == "ZC")
4229 return C_Memory;
4230
4231 return TargetLowering::getConstraintType(Constraint);
4232}
4233
4234/// Examine constraint type and operand type and determine a weight value.
4235/// This object must already have been set up with the operand type
4236/// and the current alternative constraint selected.
4238MipsTargetLowering::getSingleConstraintMatchWeight(
4239 AsmOperandInfo &info, const char *constraint) const {
4241 Value *CallOperandVal = info.CallOperandVal;
4242 // If we don't have a value, we can't do a match,
4243 // but allow it at the lowest weight.
4244 if (!CallOperandVal)
4245 return CW_Default;
4246 Type *type = CallOperandVal->getType();
4247 // Look at the constraint type.
4248 switch (*constraint) {
4249 default:
4251 break;
4252 case 'd':
4253 case 'y':
4254 if (type->isIntegerTy())
4255 weight = CW_Register;
4256 break;
4257 case 'f': // FPU or MSA register
4258 if (Subtarget.hasMSA() && type->isVectorTy() &&
4259 type->getPrimitiveSizeInBits().getFixedValue() == 128)
4260 weight = CW_Register;
4261 else if (type->isFloatTy())
4262 weight = CW_Register;
4263 break;
4264 case 'c': // $25 for indirect jumps
4265 case 'l': // lo register
4266 case 'x': // hilo register pair
4267 if (type->isIntegerTy())
4268 weight = CW_SpecificReg;
4269 break;
4270 case 'I': // signed 16 bit immediate
4271 case 'J': // integer zero
4272 case 'K': // unsigned 16 bit immediate
4273 case 'L': // signed 32 bit immediate where lower 16 bits are 0
4274 case 'N': // immediate in the range of -65535 to -1 (inclusive)
4275 case 'O': // signed 15 bit immediate (+- 16383)
4276 case 'P': // immediate in the range of 65535 to 1 (inclusive)
4277 if (isa<ConstantInt>(CallOperandVal))
4278 weight = CW_Constant;
4279 break;
4280 case 'R':
4281 weight = CW_Memory;
4282 break;
4283 }
4284 return weight;
4285}
4286
4287/// This is a helper function to parse a physical register string and split it
4288/// into non-numeric and numeric parts (Prefix and Reg). The first boolean flag
4289/// that is returned indicates whether parsing was successful. The second flag
4290/// is true if the numeric part exists.
4291static std::pair<bool, bool> parsePhysicalReg(StringRef C, StringRef &Prefix,
4292 unsigned long long &Reg) {
4293 if (C.front() != '{' || C.back() != '}')
4294 return std::make_pair(false, false);
4295
4296 // Search for the first numeric character.
4297 StringRef::const_iterator I, B = C.begin() + 1, E = C.end() - 1;
4298 I = std::find_if(B, E, isdigit);
4299
4300 Prefix = StringRef(B, I - B);
4301
4302 // The second flag is set to false if no numeric characters were found.
4303 if (I == E)
4304 return std::make_pair(true, false);
4305
4306 // Parse the numeric characters.
4307 return std::make_pair(!getAsUnsignedInteger(StringRef(I, E - I), 10, Reg),
4308 true);
4309}
4310
4312 ISD::NodeType) const {
4313 bool Cond = !Subtarget.isABI_O32() && VT.getSizeInBits() == 32;
4314 EVT MinVT = getRegisterType(Context, Cond ? MVT::i64 : MVT::i32);
4315 return VT.bitsLT(MinVT) ? MinVT : VT;
4316}
4317
4318std::pair<unsigned, const TargetRegisterClass *> MipsTargetLowering::
4319parseRegForInlineAsmConstraint(StringRef C, MVT VT) const {
4320 const TargetRegisterInfo *TRI =
4322 const TargetRegisterClass *RC;
4323 StringRef Prefix;
4324 unsigned long long Reg;
4325
4326 std::pair<bool, bool> R = parsePhysicalReg(C, Prefix, Reg);
4327
4328 if (!R.first)
4329 return std::make_pair(0U, nullptr);
4330
4331 for (unsigned RegClassID : {Mips::HI32RegClassID, Mips::LO32RegClassID}) {
4333 Prefix, *TRI, RegClassID, Mips::RegAliasName)) {
4334 // No numeric characters follow a hi/lo register name.
4335 if (R.second)
4336 return std::make_pair(0U, nullptr);
4337 return std::make_pair(NamedReg.id(), TRI->getRegClass(RegClassID));
4338 }
4339 }
4340
4341 if (Prefix.starts_with("$msa")) {
4342 // Parse $msa(ir|csr|access|save|modify|request|map|unmap)
4343
4344 // No numeric characters follow the name.
4345 if (R.second)
4346 return std::make_pair(0U, nullptr);
4347
4348 RC = TRI->getRegClass(Mips::MSACtrlRegClassID);
4350 Prefix.drop_front(), *TRI, Mips::MSACtrlRegClassID, Mips::RegAliasName);
4351 if (!Reg)
4352 return std::make_pair(0U, nullptr);
4353
4354 return std::make_pair(Reg, RC);
4355 }
4356
4357 if (!R.second)
4358 return std::make_pair(0U, nullptr);
4359
4360 if (Prefix == "$f") { // Parse $f0-$f31.
4361 // If the targets is single float only, always select 32-bit registers,
4362 // otherwise if the size of FP registers is 64-bit or Reg is an even number,
4363 // select the 64-bit register class. Otherwise, select the 32-bit register
4364 // class.
4365 if (VT == MVT::Other) {
4366 if (Subtarget.isSingleFloat())
4367 VT = MVT::f32;
4368 else
4369 VT = (Subtarget.isFP64bit() || !(Reg % 2)) ? MVT::f64 : MVT::f32;
4370 }
4371
4372 RC = getRegClassFor(VT);
4373
4374 if (RC == &Mips::AFGR64RegClass) {
4375 assert(Reg % 2 == 0);
4376 Reg >>= 1;
4377 }
4378 } else if (Prefix == "$fcc") // Parse $fcc0-$fcc7.
4379 RC = TRI->getRegClass(Mips::FCCRegClassID);
4380 else if (Prefix == "$w") { // Parse $w0-$w31.
4381 RC = getRegClassFor((VT == MVT::Other) ? MVT::v16i8 : VT);
4382 } else { // Parse $0-$31.
4383 assert(Prefix == "$");
4384 RC = getRegClassFor((VT == MVT::Other) ? MVT::i32 : VT);
4385 }
4386
4387 assert(Reg < RC->getNumRegs());
4388 return std::make_pair(*(RC->begin() + Reg), RC);
4389}
4390
4391/// Given a register class constraint, like 'r', if this corresponds directly
4392/// to an LLVM register class, return a register of 0 and the register class
4393/// pointer.
4394std::pair<unsigned, const TargetRegisterClass *>
4395MipsTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
4396 StringRef Constraint,
4397 MVT VT) const {
4398 if (Constraint.size() == 1) {
4399 switch (Constraint[0]) {
4400 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
4401 case 'y': // Same as 'r'. Exists for compatibility.
4402 case 'r':
4403 if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
4404 VT == MVT::i1) ||
4405 (VT == MVT::f32 && Subtarget.useSoftFloat())) {
4406 if (Subtarget.inMips16Mode())
4407 return std::make_pair(0U, &Mips::CPU16RegsRegClass);
4408 return std::make_pair(0U, &Mips::GPR32RegClass);
4409 }
4410 if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat()) ||
4411 (VT == MVT::f64 && Subtarget.isSingleFloat())) &&
4412 !Subtarget.isGP64bit())
4413 return std::make_pair(0U, &Mips::GPR32RegClass);
4414 if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat()) ||
4415 (VT == MVT::f64 && Subtarget.isSingleFloat())) &&
4416 Subtarget.isGP64bit())
4417 return std::make_pair(0U, &Mips::GPR64RegClass);
4418 // This will generate an error message
4419 return std::make_pair(0U, nullptr);
4420 case 'f': // FPU or MSA register
4421 if (VT == MVT::v16i8)
4422 return std::make_pair(0U, &Mips::MSA128BRegClass);
4423 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
4424 return std::make_pair(0U, &Mips::MSA128HRegClass);
4425 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
4426 return std::make_pair(0U, &Mips::MSA128WRegClass);
4427 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
4428 return std::make_pair(0U, &Mips::MSA128DRegClass);
4429 else if (VT == MVT::f32)
4430 return std::make_pair(0U, &Mips::FGR32RegClass);
4431 else if ((VT == MVT::f64) && (!Subtarget.isSingleFloat())) {
4432 if (Subtarget.isFP64bit())
4433 return std::make_pair(0U, &Mips::FGR64RegClass);
4434 return std::make_pair(0U, &Mips::AFGR64RegClass);
4435 }
4436 break;
4437 case 'c': // register suitable for indirect jump
4438 if (VT == MVT::i32)
4439 return std::make_pair(ABI.getTempReg(9, false).id(),
4440 &Mips::GPR32RegClass);
4441 if (VT == MVT::i64)
4442 return std::make_pair(ABI.getTempReg(9, true).id(),
4443 &Mips::GPR64RegClass);
4444 // This will generate an error message
4445 return std::make_pair(0U, nullptr);
4446 case 'l': // use the `lo` register to store values
4447 // that are no bigger than a word
4448 if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8)
4449 return std::make_pair((unsigned)Mips::LO0, &Mips::LO32RegClass);
4450 return std::make_pair((unsigned)Mips::LO0_64, &Mips::LO64RegClass);
4451 case 'x': // use the concatenated `hi` and `lo` registers
4452 // to store doubleword values
4453 // Fixme: Not triggering the use of both hi and low
4454 // This will generate an error message
4455 return std::make_pair(0U, nullptr);
4456 }
4457 }
4458
4459 if (!Constraint.empty()) {
4460 std::pair<unsigned, const TargetRegisterClass *> R;
4461 R = parseRegForInlineAsmConstraint(Constraint, VT);
4462
4463 if (R.second)
4464 return R;
4465 }
4466
4467 return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
4468}
4469
4470/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
4471/// vector. If it is invalid, don't add anything to Ops.
4472void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
4473 StringRef Constraint,
4474 std::vector<SDValue> &Ops,
4475 SelectionDAG &DAG) const {
4476 SDLoc DL(Op);
4477 SDValue Result;
4478
4479 // Only support length 1 constraints for now.
4480 if (Constraint.size() > 1)
4481 return;
4482
4483 char ConstraintLetter = Constraint[0];
4484 switch (ConstraintLetter) {
4485 default: break; // This will fall through to the generic implementation
4486 case 'I': // Signed 16 bit constant
4487 // If this fails, the parent routine will give an error
4488 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4489 EVT Type = Op.getValueType();
4490 int64_t Val = C->getSExtValue();
4491 if (isInt<16>(Val)) {
4493 break;
4494 }
4495 }
4496 return;
4497 case 'J': // integer zero
4498 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4499 EVT Type = Op.getValueType();
4500 int64_t Val = C->getZExtValue();
4501 if (Val == 0) {
4502 Result = DAG.getTargetConstant(0, DL, Type);
4503 break;
4504 }
4505 }
4506 return;
4507 case 'K': // unsigned 16 bit immediate
4508 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4509 EVT Type = Op.getValueType();
4510 uint64_t Val = C->getZExtValue();
4511 if (isUInt<16>(Val)) {
4512 Result = DAG.getTargetConstant(Val, DL, Type);
4513 break;
4514 }
4515 }
4516 return;
4517 case 'L': // signed 32 bit immediate where lower 16 bits are 0
4518 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4519 EVT Type = Op.getValueType();
4520 int64_t Val = C->getSExtValue();
4521 if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){
4523 break;
4524 }
4525 }
4526 return;
4527 case 'N': // immediate in the range of -65535 to -1 (inclusive)
4528 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4529 EVT Type = Op.getValueType();
4530 int64_t Val = C->getSExtValue();
4531 if ((Val >= -65535) && (Val <= -1)) {
4533 break;
4534 }
4535 }
4536 return;
4537 case 'O': // signed 15 bit immediate
4538 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4539 EVT Type = Op.getValueType();
4540 int64_t Val = C->getSExtValue();
4541 if ((isInt<15>(Val))) {
4543 break;
4544 }
4545 }
4546 return;
4547 case 'P': // immediate in the range of 1 to 65535 (inclusive)
4548 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4549 EVT Type = Op.getValueType();
4550 int64_t Val = C->getSExtValue();
4551 if ((Val <= 65535) && (Val >= 1)) {
4552 Result = DAG.getTargetConstant(Val, DL, Type);
4553 break;
4554 }
4555 }
4556 return;
4557 }
4558
4559 if (Result.getNode()) {
4560 Ops.push_back(Result);
4561 return;
4562 }
4563
4565}
4566
4567bool MipsTargetLowering::isLegalAddressingMode(const DataLayout &DL,
4568 const AddrMode &AM, Type *Ty,
4569 unsigned AS,
4570 Instruction *I) const {
4571 // No global is ever allowed as a base.
4572 if (AM.BaseGV)
4573 return false;
4574
4575 switch (AM.Scale) {
4576 case 0: // "r+i" or just "i", depending on HasBaseReg.
4577 break;
4578 case 1:
4579 if (!AM.HasBaseReg) // allow "r+i".
4580 break;
4581 return false; // disallow "r+r" or "r+r+i".
4582 default:
4583 return false;
4584 }
4585
4586 return true;
4587}
4588
4589bool
4590MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
4591 // The Mips target isn't yet aware of offsets.
4592 return false;
4593}
4594
4595EVT MipsTargetLowering::getOptimalMemOpType(
4596 LLVMContext &Context, const MemOp &Op,
4597 const AttributeList &FuncAttributes) const {
4598 if (Subtarget.hasMips64())
4599 return MVT::i64;
4600
4601 return MVT::i32;
4602}
4603
4605MipsTargetLowering::getFPImmAction(const APFloat &Imm, EVT VT,
4606 bool ForCodeSize) const {
4607 if (VT != MVT::f32 && VT != MVT::f64)
4609 if (Imm.isNegZero())
4612}
4613
4614bool MipsTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
4615 return isInt<16>(Imm);
4616}
4617
4618bool MipsTargetLowering::isLegalAddImmediate(int64_t Imm) const {
4619 return isInt<16>(Imm);
4620}
4621
4623 if (!isPositionIndependent())
4625 if (ABI.IsN64())
4628}
4629
4630SDValue MipsTargetLowering::getPICJumpTableRelocBase(SDValue Table,
4631 SelectionDAG &DAG) const {
4632 if (!isPositionIndependent())
4633 return Table;
4635}
4636
4638 return Subtarget.useSoftFloat();
4639}
4640
4641void MipsTargetLowering::copyByValRegs(
4642 SDValue Chain, const SDLoc &DL, std::vector<SDValue> &OutChains,
4643 SelectionDAG &DAG, const ISD::ArgFlagsTy &Flags,
4644 SmallVectorImpl<SDValue> &InVals, const Argument *FuncArg,
4645 unsigned FirstReg, unsigned LastReg, const CCValAssign &VA,
4646 MipsCCState &State) const {
4648 MachineFrameInfo &MFI = MF.getFrameInfo();
4649 unsigned GPRSizeInBytes = Subtarget.getGPRSizeInBytes();
4650 unsigned NumRegs = LastReg - FirstReg;
4651 unsigned RegAreaSize = NumRegs * GPRSizeInBytes;
4652 unsigned FrameObjSize = std::max(Flags.getByValSize(), RegAreaSize);
4653 int FrameObjOffset;
4654 ArrayRef<MCPhysReg> ByValArgRegs = ABI.GetByValArgRegs();
4655
4656 if (RegAreaSize)
4657 FrameObjOffset =
4658 (int)ABI.GetCalleeAllocdArgSizeInBytes(State.getCallingConv()) -
4659 (int)((ByValArgRegs.size() - FirstReg) * GPRSizeInBytes);
4660 else
4661 FrameObjOffset = VA.getLocMemOffset();
4662
4663 // Create frame object.
4664 EVT PtrTy = getPointerTy(DAG.getDataLayout());
4665 // Make the fixed object stored to mutable so that the load instructions
4666 // referencing it have their memory dependencies added.
4667 // Set the frame object as isAliased which clears the underlying objects
4668 // vector in ScheduleDAGInstrs::buildSchedGraph() resulting in addition of all
4669 // stores as dependencies for loads referencing this fixed object.
4670 int FI = MFI.CreateFixedObject(FrameObjSize, FrameObjOffset, false, true);
4671 SDValue FIN = DAG.getFrameIndex(FI, PtrTy);
4672 InVals.push_back(FIN);
4673
4674 if (!NumRegs)
4675 return;
4676
4677 // Copy arg registers.
4678 MVT RegTy = MVT::getIntegerVT(GPRSizeInBytes * 8);
4679 const TargetRegisterClass *RC = getRegClassFor(RegTy);
4680
4681 for (unsigned I = 0; I < NumRegs; ++I) {
4682 unsigned ArgReg = ByValArgRegs[FirstReg + I];
4683 unsigned VReg = addLiveIn(MF, ArgReg, RC);
4684 unsigned Offset = I * GPRSizeInBytes;
4685 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN,
4686 DAG.getConstant(Offset, DL, PtrTy));
4687 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy),
4688 StorePtr, MachinePointerInfo(FuncArg, Offset));
4689 OutChains.push_back(Store);
4690 }
4691}
4692
4693// Copy byVal arg to registers and stack.
4694void MipsTargetLowering::passByValArg(
4695 SDValue Chain, const SDLoc &DL,
4696 std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
4697 SmallVectorImpl<SDValue> &MemOpChains, SDValue StackPtr,
4698 MachineFrameInfo &MFI, SelectionDAG &DAG, SDValue Arg, unsigned FirstReg,
4699 unsigned LastReg, const ISD::ArgFlagsTy &Flags, bool isLittle,
4700 const CCValAssign &VA) const {
4701 unsigned ByValSizeInBytes = Flags.getByValSize();
4702 unsigned OffsetInBytes = 0; // From beginning of struct
4703 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4705 std::min(Flags.getNonZeroByValAlign(), Align(RegSizeInBytes));
4706 EVT PtrTy = getPointerTy(DAG.getDataLayout()),
4707 RegTy = MVT::getIntegerVT(RegSizeInBytes * 8);
4708 unsigned NumRegs = LastReg - FirstReg;
4709
4710 if (NumRegs) {
4711 ArrayRef<MCPhysReg> ArgRegs = ABI.GetByValArgRegs();
4712 bool LeftoverBytes = (NumRegs * RegSizeInBytes > ByValSizeInBytes);
4713 unsigned I = 0;
4714
4715 // Copy words to registers.
4716 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) {
4717 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4718 DAG.getConstant(OffsetInBytes, DL, PtrTy));
4719 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr,
4720 MachinePointerInfo(), Alignment);
4721 MemOpChains.push_back(LoadVal.getValue(1));
4722 unsigned ArgReg = ArgRegs[FirstReg + I];
4723 RegsToPass.push_back(std::make_pair(ArgReg, LoadVal));
4724 }
4725
4726 // Return if the struct has been fully copied.
4727 if (ByValSizeInBytes == OffsetInBytes)
4728 return;
4729
4730 // Copy the remainder of the byval argument with sub-word loads and shifts.
4731 if (LeftoverBytes) {
4732 SDValue Val;
4733
4734 for (unsigned LoadSizeInBytes = RegSizeInBytes / 2, TotalBytesLoaded = 0;
4735 OffsetInBytes < ByValSizeInBytes; LoadSizeInBytes /= 2) {
4736 unsigned RemainingSizeInBytes = ByValSizeInBytes - OffsetInBytes;
4737
4738 if (RemainingSizeInBytes < LoadSizeInBytes)
4739 continue;
4740
4741 // Load subword.
4742 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4743 DAG.getConstant(OffsetInBytes, DL,
4744 PtrTy));
4745 SDValue LoadVal = DAG.getExtLoad(
4746 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(),
4747 MVT::getIntegerVT(LoadSizeInBytes * 8), Alignment);
4748 MemOpChains.push_back(LoadVal.getValue(1));
4749
4750 // Shift the loaded value.
4751 unsigned Shamt;
4752
4753 if (isLittle)
4754 Shamt = TotalBytesLoaded * 8;
4755 else
4756 Shamt = (RegSizeInBytes - (TotalBytesLoaded + LoadSizeInBytes)) * 8;
4757
4758 SDValue Shift = DAG.getNode(ISD::SHL, DL, RegTy, LoadVal,
4759 DAG.getConstant(Shamt, DL, MVT::i32));
4760
4761 if (Val.getNode())
4762 Val = DAG.getNode(ISD::OR, DL, RegTy, Val, Shift);
4763 else
4764 Val = Shift;
4765
4766 OffsetInBytes += LoadSizeInBytes;
4767 TotalBytesLoaded += LoadSizeInBytes;
4768 Alignment = std::min(Alignment, Align(LoadSizeInBytes));
4769 }
4770
4771 unsigned ArgReg = ArgRegs[FirstReg + I];
4772 RegsToPass.push_back(std::make_pair(ArgReg, Val));
4773 return;
4774 }
4775 }
4776
4777 // Copy remainder of byval arg to it with memcpy.
4778 unsigned MemCpySize = ByValSizeInBytes - OffsetInBytes;
4779 SDValue Src = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4780 DAG.getConstant(OffsetInBytes, DL, PtrTy));
4781 SDValue Dst = DAG.getNode(ISD::ADD, DL, PtrTy, StackPtr,
4783 Chain = DAG.getMemcpy(
4784 Chain, DL, Dst, Src, DAG.getConstant(MemCpySize, DL, PtrTy), Alignment,
4785 Alignment, /*isVolatile=*/false, /*AlwaysInline=*/false,
4786 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(), MachinePointerInfo());
4787 MemOpChains.push_back(Chain);
4788}
4789
4790void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains,
4791 SDValue Chain, const SDLoc &DL,
4792 SelectionDAG &DAG,
4793 CCState &State) const {
4794 ArrayRef<MCPhysReg> ArgRegs = ABI.getVarArgRegs(Subtarget.isGP64bit());
4795 unsigned Idx = State.getFirstUnallocated(ArgRegs);
4796 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4797 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8);
4798 const TargetRegisterClass *RC = getRegClassFor(RegTy);
4800 MachineFrameInfo &MFI = MF.getFrameInfo();
4801 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4802
4803 // Offset of the first variable argument from stack pointer.
4804 int VaArgOffset;
4805
4806 if (ArgRegs.size() == Idx)
4807 VaArgOffset = alignTo(State.getStackSize(), RegSizeInBytes);
4808 else {
4809 VaArgOffset =
4810 (int)ABI.GetCalleeAllocdArgSizeInBytes(State.getCallingConv()) -
4811 (int)(RegSizeInBytes * (ArgRegs.size() - Idx));
4812 }
4813
4814 // Record the frame index of the first variable argument
4815 // which is a value necessary to VASTART.
4816 int FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
4817 MipsFI->setVarArgsFrameIndex(FI);
4818
4819 // Copy the integer registers that have not been used for argument passing
4820 // to the argument register save area. For O32, the save area is allocated
4821 // in the caller's stack frame, while for N32/64, it is allocated in the
4822 // callee's stack frame.
4823 for (unsigned I = Idx; I < ArgRegs.size();
4824 ++I, VaArgOffset += RegSizeInBytes) {
4825 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC);
4826 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy);
4827 FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
4828 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
4829 SDValue Store =
4830 DAG.getStore(Chain, DL, ArgValue, PtrOff, MachinePointerInfo());
4831 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue(
4832 (Value *)nullptr);
4833 OutChains.push_back(Store);
4834 }
4835}
4836
4838 Align Alignment) const {
4839 const TargetFrameLowering *TFL = Subtarget.getFrameLowering();
4840
4841 assert(Size && "Byval argument's size shouldn't be 0.");
4842
4843 Alignment = std::min(Alignment, TFL->getStackAlign());
4844
4845 unsigned FirstReg = 0;
4846 unsigned NumRegs = 0;
4847
4848 if (State->getCallingConv() != CallingConv::Fast) {
4849 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4850 ArrayRef<MCPhysReg> IntArgRegs = ABI.GetByValArgRegs();
4851 // FIXME: The O32 case actually describes no shadow registers.
4852 const MCPhysReg *ShadowRegs =
4853 ABI.IsO32() ? IntArgRegs.data() : Mips64DPRegs;
4854
4855 // We used to check the size as well but we can't do that anymore since
4856 // CCState::HandleByVal() rounds up the size after calling this function.
4857 assert(
4858 Alignment >= Align(RegSizeInBytes) &&
4859 "Byval argument's alignment should be a multiple of RegSizeInBytes.");
4860
4861 FirstReg = State->getFirstUnallocated(IntArgRegs);
4862
4863 // If Alignment > RegSizeInBytes, the first arg register must be even.
4864 // FIXME: This condition happens to do the right thing but it's not the
4865 // right way to test it. We want to check that the stack frame offset
4866 // of the register is aligned.
4867 if ((Alignment > RegSizeInBytes) && (FirstReg % 2)) {
4868 State->AllocateReg(IntArgRegs[FirstReg], ShadowRegs[FirstReg]);
4869 ++FirstReg;
4870 }
4871
4872 // Mark the registers allocated.
4873 Size = alignTo(Size, RegSizeInBytes);
4874 for (unsigned I = FirstReg; Size > 0 && (I < IntArgRegs.size());
4875 Size -= RegSizeInBytes, ++I, ++NumRegs)
4876 State->AllocateReg(IntArgRegs[I], ShadowRegs[I]);
4877 }
4878
4879 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs);
4880}
4881
4882MachineBasicBlock *MipsTargetLowering::emitPseudoSELECT(MachineInstr &MI,
4884 bool isFPCmp,
4885 unsigned Opc) const {
4887 "Subtarget already supports SELECT nodes with the use of"
4888 "conditional-move instructions.");
4889
4890 const TargetInstrInfo *TII =
4892 DebugLoc DL = MI.getDebugLoc();
4893
4894 // To "insert" a SELECT instruction, we actually have to insert the
4895 // diamond control-flow pattern. The incoming instruction knows the
4896 // destination vreg to set, the condition code register to branch on, the
4897 // true/false values to select between, and a branch opcode to use.
4898 const BasicBlock *LLVM_BB = BB->getBasicBlock();
4900
4901 // thisMBB:
4902 // ...
4903 // TrueVal = ...
4904 // setcc r1, r2, r3
4905 // bNE r1, r0, copy1MBB
4906 // fallthrough --> copy0MBB
4907 MachineBasicBlock *thisMBB = BB;
4908 MachineFunction *F = BB->getParent();
4909 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
4910 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
4911 F->insert(It, copy0MBB);
4912 F->insert(It, sinkMBB);
4913
4914 // Transfer the remainder of BB and its successor edges to sinkMBB.
4915 sinkMBB->splice(sinkMBB->begin(), BB,
4916 std::next(MachineBasicBlock::iterator(MI)), BB->end());
4918
4919 // Next, add the true and fallthrough blocks as its successors.
4920 BB->addSuccessor(copy0MBB);
4921 BB->addSuccessor(sinkMBB);
4922
4923 if (isFPCmp) {
4924 // bc1[tf] cc, sinkMBB
4925 BuildMI(BB, DL, TII->get(Opc))
4926 .addReg(MI.getOperand(1).getReg())
4927 .addMBB(sinkMBB);
4928 } else {
4929 // bne rs, $0, sinkMBB
4930 BuildMI(BB, DL, TII->get(Opc))
4931 .addReg(MI.getOperand(1).getReg())
4932 .addReg(Mips::R0)
4933 .addMBB(sinkMBB);
4934 }
4935
4936 // copy0MBB:
4937 // %FalseValue = ...
4938 // # fallthrough to sinkMBB
4939 BB = copy0MBB;
4940
4941 // Update machine-CFG edges
4942 BB->addSuccessor(sinkMBB);
4943
4944 // sinkMBB:
4945 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
4946 // ...
4947 BB = sinkMBB;
4948
4949 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
4950 .addReg(MI.getOperand(2).getReg())
4951 .addMBB(thisMBB)
4952 .addReg(MI.getOperand(3).getReg())
4953 .addMBB(copy0MBB);
4954
4955 MI.eraseFromParent(); // The pseudo instruction is gone now.
4956
4957 return BB;
4958}
4959
4961MipsTargetLowering::emitPseudoD_SELECT(MachineInstr &MI,
4962 MachineBasicBlock *BB) const {
4963 assert(!(Subtarget.hasMips4() || Subtarget.hasMips32()) &&
4964 "Subtarget already supports SELECT nodes with the use of"
4965 "conditional-move instructions.");
4966
4967 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
4968 DebugLoc DL = MI.getDebugLoc();
4969
4970 // D_SELECT substitutes two SELECT nodes that goes one after another and
4971 // have the same condition operand. On machines which don't have
4972 // conditional-move instruction, it reduces unnecessary branch instructions
4973 // which are result of using two diamond patterns that are result of two
4974 // SELECT pseudo instructions.
4975 const BasicBlock *LLVM_BB = BB->getBasicBlock();
4977
4978 // thisMBB:
4979 // ...
4980 // TrueVal = ...
4981 // setcc r1, r2, r3
4982 // bNE r1, r0, copy1MBB
4983 // fallthrough --> copy0MBB
4984 MachineBasicBlock *thisMBB = BB;
4985 MachineFunction *F = BB->getParent();
4986 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
4987 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
4988 F->insert(It, copy0MBB);
4989 F->insert(It, sinkMBB);
4990
4991 // Transfer the remainder of BB and its successor edges to sinkMBB.
4992 sinkMBB->splice(sinkMBB->begin(), BB,
4993 std::next(MachineBasicBlock::iterator(MI)), BB->end());
4995
4996 // Next, add the true and fallthrough blocks as its successors.
4997 BB->addSuccessor(copy0MBB);
4998 BB->addSuccessor(sinkMBB);
4999
5000 // bne rs, $0, sinkMBB
5001 BuildMI(BB, DL, TII->get(Mips::BNE))
5002 .addReg(MI.getOperand(2).getReg())
5003 .addReg(Mips::R0)
5004 .addMBB(sinkMBB);
5005
5006 // copy0MBB:
5007 // %FalseValue = ...
5008 // # fallthrough to sinkMBB
5009 BB = copy0MBB;
5010
5011 // Update machine-CFG edges
5012 BB->addSuccessor(sinkMBB);
5013
5014 // sinkMBB:
5015 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
5016 // ...
5017 BB = sinkMBB;
5018
5019 // Use two PHI nodes to select two reults
5020 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
5021 .addReg(MI.getOperand(3).getReg())
5022 .addMBB(thisMBB)
5023 .addReg(MI.getOperand(5).getReg())
5024 .addMBB(copy0MBB);
5025 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(1).getReg())
5026 .addReg(MI.getOperand(4).getReg())
5027 .addMBB(thisMBB)
5028 .addReg(MI.getOperand(6).getReg())
5029 .addMBB(copy0MBB);
5030
5031 MI.eraseFromParent(); // The pseudo instruction is gone now.
5032
5033 return BB;
5034}
5035
5038 const MachineFunction &MF) const {
5039 StringRef Name(RegName);
5040 Name.consume_front("$");
5041
5042 unsigned RegIdx;
5043 if (Name.getAsInteger(10, RegIdx)) {
5044 std::string LowerName = Name.lower();
5046 int Index =
5047 MIPS_MC::getCPURegisterIndex(LowerName, MRI, ABI.getRegAltNameIndex());
5048 if (Index < 0)
5050 Twine("Invalid register name \"" + StringRef(RegName) + "\"."));
5051 RegIdx = Index;
5052 }
5053
5054 if (RegIdx < 32) {
5056 unsigned RegClassID = Mips::GPR32RegClassID;
5057 if (VT.isValid()) {
5058 if (VT.getSizeInBits() == 64) {
5059 if (!Subtarget.isGP64bit())
5060 report_fatal_error("64-bit registers not supported on 32-bit target");
5061 RegClassID = Mips::GPR64RegClassID;
5062 } else if (VT.getSizeInBits() == 32) {
5063 RegClassID = Mips::GPR32RegClassID;
5064 } else {
5065 report_fatal_error(Twine("Invalid register \"" + StringRef(RegName) +
5066 "\" for " + Twine(VT.getSizeInBits()) +
5067 "-bit type."));
5068 }
5069 } else if (Subtarget.isGP64bit()) {
5070 RegClassID = Mips::GPR64RegClassID;
5071 }
5072 const MCRegisterClass &RC = MRI->getRegClass(RegClassID);
5073 Register Reg = RC.getRegister(RegIdx);
5074 BitVector ReservedRegs = Subtarget.getRegisterInfo()->getReservedRegs(MF);
5075 if (!ReservedRegs.test(Reg))
5076 reportFatalUsageError(Twine("Trying to obtain non-reserved register \"" +
5077 StringRef(RegName) + "\"."));
5078 return Reg;
5079 }
5080
5082 Twine("Invalid register name \"" + StringRef(RegName) + "\"."));
5083}
5084
5085MachineBasicBlock *MipsTargetLowering::emitLDR_W(MachineInstr &MI,
5086 MachineBasicBlock *BB) const {
5087 MachineFunction *MF = BB->getParent();
5090 const bool IsLittle = Subtarget.isLittle();
5091 DebugLoc DL = MI.getDebugLoc();
5092
5093 Register Dest = MI.getOperand(0).getReg();
5094 Register Address = MI.getOperand(1).getReg();
5095 unsigned Imm = MI.getOperand(2).getImm();
5096
5098
5100 // Mips release 6 can load from adress that is not naturally-aligned.
5101 Register Temp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5102 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5103 .addDef(Temp)
5104 .addUse(Address)
5105 .addImm(Imm);
5106 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Dest).addUse(Temp);
5107 } else {
5108 // Mips release 5 needs to use instructions that can load from an unaligned
5109 // memory address.
5110 Register LoadHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5111 Register LoadFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5112 Register Undef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5113 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(Undef);
5114 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5115 .addDef(LoadHalf)
5116 .addUse(Address)
5117 .addImm(Imm + (IsLittle ? 0 : 3))
5118 .addUse(Undef);
5119 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5120 .addDef(LoadFull)
5121 .addUse(Address)
5122 .addImm(Imm + (IsLittle ? 3 : 0))
5123 .addUse(LoadHalf);
5124 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Dest).addUse(LoadFull);
5125 }
5126
5127 MI.eraseFromParent();
5128 return BB;
5129}
5130
5131MachineBasicBlock *MipsTargetLowering::emitLDR_D(MachineInstr &MI,
5132 MachineBasicBlock *BB) const {
5133 MachineFunction *MF = BB->getParent();
5134 MachineRegisterInfo &MRI = MF->getRegInfo();
5135 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5136 const bool IsLittle = Subtarget.isLittle();
5137 DebugLoc DL = MI.getDebugLoc();
5138
5139 Register Dest = MI.getOperand(0).getReg();
5140 Register Address = MI.getOperand(1).getReg();
5141 unsigned Imm = MI.getOperand(2).getImm();
5142
5144
5145 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5146 // Mips release 6 can load from adress that is not naturally-aligned.
5147 if (Subtarget.isGP64bit()) {
5148 Register Temp = MRI.createVirtualRegister(&Mips::GPR64RegClass);
5149 BuildMI(*BB, I, DL, TII->get(Mips::LD))
5150 .addDef(Temp)
5151 .addUse(Address)
5152 .addImm(Imm);
5153 BuildMI(*BB, I, DL, TII->get(Mips::FILL_D)).addDef(Dest).addUse(Temp);
5154 } else {
5155 Register Wtemp = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5156 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5157 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5158 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5159 .addDef(Lo)
5160 .addUse(Address)
5161 .addImm(Imm + (IsLittle ? 0 : 4));
5162 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5163 .addDef(Hi)
5164 .addUse(Address)
5165 .addImm(Imm + (IsLittle ? 4 : 0));
5166 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Wtemp).addUse(Lo);
5167 BuildMI(*BB, I, DL, TII->get(Mips::INSERT_W), Dest)
5168 .addUse(Wtemp)
5169 .addUse(Hi)
5170 .addImm(1);
5171 }
5172 } else {
5173 // Mips release 5 needs to use instructions that can load from an unaligned
5174 // memory address.
5175 Register LoHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5176 Register LoFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5177 Register LoUndef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5178 Register HiHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5179 Register HiFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5180 Register HiUndef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5181 Register Wtemp = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5182 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(LoUndef);
5183 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5184 .addDef(LoHalf)
5185 .addUse(Address)
5186 .addImm(Imm + (IsLittle ? 0 : 7))
5187 .addUse(LoUndef);
5188 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5189 .addDef(LoFull)
5190 .addUse(Address)
5191 .addImm(Imm + (IsLittle ? 3 : 4))
5192 .addUse(LoHalf);
5193 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(HiUndef);
5194 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5195 .addDef(HiHalf)
5196 .addUse(Address)
5197 .addImm(Imm + (IsLittle ? 4 : 3))
5198 .addUse(HiUndef);
5199 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5200 .addDef(HiFull)
5201 .addUse(Address)
5202 .addImm(Imm + (IsLittle ? 7 : 0))
5203 .addUse(HiHalf);
5204 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Wtemp).addUse(LoFull);
5205 BuildMI(*BB, I, DL, TII->get(Mips::INSERT_W), Dest)
5206 .addUse(Wtemp)
5207 .addUse(HiFull)
5208 .addImm(1);
5209 }
5210
5211 MI.eraseFromParent();
5212 return BB;
5213}
5214
5215MachineBasicBlock *MipsTargetLowering::emitSTR_W(MachineInstr &MI,
5216 MachineBasicBlock *BB) const {
5217 MachineFunction *MF = BB->getParent();
5218 MachineRegisterInfo &MRI = MF->getRegInfo();
5219 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5220 const bool IsLittle = Subtarget.isLittle();
5221 DebugLoc DL = MI.getDebugLoc();
5222
5223 Register StoreVal = MI.getOperand(0).getReg();
5224 Register Address = MI.getOperand(1).getReg();
5225 unsigned Imm = MI.getOperand(2).getImm();
5226
5228
5229 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5230 // Mips release 6 can store to adress that is not naturally-aligned.
5231 Register BitcastW = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5232 Register Tmp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5233 BuildMI(*BB, I, DL, TII->get(Mips::COPY)).addDef(BitcastW).addUse(StoreVal);
5234 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5235 .addDef(Tmp)
5236 .addUse(BitcastW)
5237 .addImm(0);
5238 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5239 .addUse(Tmp)
5240 .addUse(Address)
5241 .addImm(Imm);
5242 } else {
5243 // Mips release 5 needs to use instructions that can store to an unaligned
5244 // memory address.
5245 Register Tmp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5246 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5247 .addDef(Tmp)
5248 .addUse(StoreVal)
5249 .addImm(0);
5250 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5251 .addUse(Tmp)
5252 .addUse(Address)
5253 .addImm(Imm + (IsLittle ? 0 : 3));
5254 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5255 .addUse(Tmp)
5256 .addUse(Address)
5257 .addImm(Imm + (IsLittle ? 3 : 0));
5258 }
5259
5260 MI.eraseFromParent();
5261
5262 return BB;
5263}
5264
5265MachineBasicBlock *MipsTargetLowering::emitSTR_D(MachineInstr &MI,
5266 MachineBasicBlock *BB) const {
5267 MachineFunction *MF = BB->getParent();
5268 MachineRegisterInfo &MRI = MF->getRegInfo();
5269 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5270 const bool IsLittle = Subtarget.isLittle();
5271 DebugLoc DL = MI.getDebugLoc();
5272
5273 Register StoreVal = MI.getOperand(0).getReg();
5274 Register Address = MI.getOperand(1).getReg();
5275 unsigned Imm = MI.getOperand(2).getImm();
5276
5278
5279 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5280 // Mips release 6 can store to adress that is not naturally-aligned.
5281 if (Subtarget.isGP64bit()) {
5282 Register BitcastD = MRI.createVirtualRegister(&Mips::MSA128DRegClass);
5283 Register Lo = MRI.createVirtualRegister(&Mips::GPR64RegClass);
5284 BuildMI(*BB, I, DL, TII->get(Mips::COPY))
5285 .addDef(BitcastD)
5286 .addUse(StoreVal);
5287 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_D))
5288 .addDef(Lo)
5289 .addUse(BitcastD)
5290 .addImm(0);
5291 BuildMI(*BB, I, DL, TII->get(Mips::SD))
5292 .addUse(Lo)
5293 .addUse(Address)
5294 .addImm(Imm);
5295 } else {
5296 Register BitcastW = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5297 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5298 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5299 BuildMI(*BB, I, DL, TII->get(Mips::COPY))
5300 .addDef(BitcastW)
5301 .addUse(StoreVal);
5302 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5303 .addDef(Lo)
5304 .addUse(BitcastW)
5305 .addImm(0);
5306 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5307 .addDef(Hi)
5308 .addUse(BitcastW)
5309 .addImm(1);
5310 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5311 .addUse(Lo)
5312 .addUse(Address)
5313 .addImm(Imm + (IsLittle ? 0 : 4));
5314 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5315 .addUse(Hi)
5316 .addUse(Address)
5317 .addImm(Imm + (IsLittle ? 4 : 0));
5318 }
5319 } else {
5320 // Mips release 5 needs to use instructions that can store to an unaligned
5321 // memory address.
5322 Register Bitcast = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5323 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5324 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5325 BuildMI(*BB, I, DL, TII->get(Mips::COPY)).addDef(Bitcast).addUse(StoreVal);
5326 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5327 .addDef(Lo)
5328 .addUse(Bitcast)
5329 .addImm(0);
5330 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5331 .addDef(Hi)
5332 .addUse(Bitcast)
5333 .addImm(1);
5334 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5335 .addUse(Lo)
5336 .addUse(Address)
5337 .addImm(Imm + (IsLittle ? 0 : 3));
5338 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5339 .addUse(Lo)
5340 .addUse(Address)
5341 .addImm(Imm + (IsLittle ? 3 : 0));
5342 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5343 .addUse(Hi)
5344 .addUse(Address)
5345 .addImm(Imm + (IsLittle ? 4 : 7));
5346 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5347 .addUse(Hi)
5348 .addUse(Address)
5349 .addImm(Imm + (IsLittle ? 7 : 4));
5350 }
5351
5352 MI.eraseFromParent();
5353 return BB;
5354}
static SDValue performSHLCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, SelectionDAG &DAG)
If the operand is a bitwise AND with a constant RHS, and the shift has a constant RHS and is the only...
static SDValue performORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SDValue performANDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
uint64_t Imm
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define RegName(no)
static LVOptions Options
Definition LVOptions.cpp:25
lazy value info
static SDValue performADDCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
static SDValue performSUBCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
static MachineBasicBlock * insertDivByZeroTrap(MachineInstr &MI, MachineBasicBlock *MBB)
static SDValue performSELECTCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const LoongArchSubtarget &Subtarget)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static bool CC_Mips(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static SDValue performMADD_MSUBCombine(SDNode *ROOTNode, SelectionDAG &CurDAG, const MipsSubtarget &Subtarget)
static bool invertFPCondCodeUser(Mips::CondCode CC)
This function returns true if the floating point conditional branches and conditional moves which use...
static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State, ArrayRef< MCPhysReg > F64Regs)
static SDValue lowerFP_TO_SINT_STORE(StoreSDNode *SD, SelectionDAG &DAG, bool SingleFloat)
static SDValue performDivRemCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const MipsSubtarget &Subtarget)
static const MCPhysReg Mips64DPRegs[8]
static SDValue lowerUnalignedIntStore(StoreSDNode *SD, SelectionDAG &DAG, bool IsLittle)
static SDValue createStoreLR(unsigned Opc, SelectionDAG &DAG, StoreSDNode *SD, SDValue Chain, unsigned Offset)
static unsigned addLiveIn(MachineFunction &MF, unsigned PReg, const TargetRegisterClass *RC)
static std::pair< bool, bool > parsePhysicalReg(StringRef C, StringRef &Prefix, unsigned long long &Reg)
This is a helper function to parse a physical register string and split it into non-numeric and numer...
static SDValue createLoadLR(unsigned Opc, SelectionDAG &DAG, LoadSDNode *LD, SDValue Chain, SDValue Src, unsigned Offset)
static SDValue lowerFCOPYSIGN64(SDValue Op, SelectionDAG &DAG, bool HasExtractInsert)
static SDValue createFPCmp(SelectionDAG &DAG, const SDValue &Op)
static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG, bool HasExtractInsert)
DivByZeroTrapKind
static SDValue performSignExtendCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const MipsSubtarget &Subtarget)
static SDValue performCMovFPCombine(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const MipsSubtarget &Subtarget)
static SDValue UnpackFromArgumentSlot(SDValue Val, const CCValAssign &VA, EVT ArgVT, const SDLoc &DL, SelectionDAG &DAG)
static Mips::CondCode condCodeToFCC(ISD::CondCode CC)
static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True, SDValue False, const SDLoc &DL)
uint64_t IntrinsicInst * II
SmallVector< MachineOperand, 4 > Cond
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
MachineInstr *& Lo
SI optimize exec mask operations pre RA
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:480
This file defines the SmallVector class.
static const MCPhysReg IntRegs[32]
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static const MCPhysReg F32Regs[64]
Value * RHS
Value * LHS
bool isZero() const
Definition APFloat.h:1579
APInt bitcastToAPInt() const
Definition APFloat.h:1475
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1560
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:478
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
const T * data() const
Definition ArrayRef.h:138
LLVM Basic Block Representation.
Definition BasicBlock.h:62
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:482
static constexpr BranchProbability getOne()
CCState - This class holds information needed while lowering arguments and return values.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
CallingConv::ID getCallingConv() const
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
LocInfo getLocInfo() const
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP)
bool isUpperBitsInLoc() const
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
bool needsCustom() const
int64_t getLocMemOffset() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
const APFloat & getValueAPF() const
uint64_t getZExtValue() const
int64_t getSExtValue() const
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
A debug info location.
Definition DebugLoc.h:126
const char * getSymbol() const
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition FastISel.h:67
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition Function.h:673
const Argument * const_arg_iterator
Definition Function.h:74
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
const GlobalValue * getGlobal() const
bool isDSOLocal() const
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
bool hasHiddenVisibility() const
bool hasDLLImportStorageClass() const
bool isDeclarationForLinker() const
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:521
bool hasProtectedVisibility() const
constexpr bool isValid() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Tracks which library functions to use for a particular subtarget or function.
This class is used to represent ISD::LOAD nodes.
const MCRegisterInfo * getRegisterInfo() const
Definition MCContext.h:413
MCRegisterClass - Base class of TargetRegisterClass.
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
iterator begin() const
begin/end - Return all of the registers in this class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Machine Value Type.
SimpleValueType SimpleTy
static auto integer_valuetypes()
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
bool isValid() const
Return true if this is a valid simple valuetype.
static MVT getIntegerVT(unsigned BitWidth)
static auto fp_valuetypes()
static auto fp_fixedlen_vector_valuetypes()
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void setFrameAddressIsTaken(bool T)
void setHasTailCall(bool V=true)
void setReturnAddressIsTaken(bool s)
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ MOVolatile
The memory access is volatile.
Flags getFlags() const
Return the raw flags of the source value,.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
void setIsKill(bool Val=true)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Align getAlign() const
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
static SpecialCallingConvType getSpecialCallingConvForCallee(const SDNode *Callee, const MipsSubtarget &Subtarget)
Determine the SpecialCallingConvType for the given callee.
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
void setVarArgsFrameIndex(int Index)
unsigned getSRetReturnReg() const
MachinePointerInfo callPtrInfo(MachineFunction &MF, const char *ES)
Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue object representing a GOT ent...
Register getGlobalBaseReg(MachineFunction &MF)
void setSRetReturnReg(unsigned Reg)
void setFormalArgInfo(unsigned Size, bool HasByval)
static const uint32_t * getMips16RetHelperMask()
bool hasMips32r6() const
bool hasMips4() const
bool hasMips64r2() const
bool isLittle() const
const MipsInstrInfo * getInstrInfo() const override
bool hasMips64r6() const
bool inMips16Mode() const
bool hasMips64() const
bool hasMips32() const
const MipsOptions & getCLOpts() const
const MipsRegisterInfo * getRegisterInfo() const override
bool hasCnMips() const
bool isGP64bit() const
bool hasExtractInsert() const
Features related to the presence of specific instructions.
bool isSingleFloat() const
const MipsABIInfo & getABI() const
const TargetFrameLowering * getFrameLowering() const override
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Return the register type for a given MVT, ensuring vectors are treated as a series of gpr sized integ...
bool hasBitTest(SDValue X, SDValue Y) const override
Return true if the target has a bit-test instruction: (X & (1 << Y)) ==/!= 0 This knowledge can be us...
static const MipsTargetLowering * create(const MipsTargetMachine &TM, const MipsSubtarget &STI)
SDValue getAddrGPRel(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, bool IsN64) const
unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const override
Break down vectors to the correct number of gpr sized integers.
Register getRegisterByName(const char *RegName, LLT VT, const MachineFunction &MF) const override
Return the register ID of the name passed in.
SDValue getAddrNonPICSym64(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
getSetCCResultType - get the ISD::SETCC result ValueType
SDValue getAddrGlobal(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, unsigned Flag, SDValue Chain, const MachinePointerInfo &PtrInfo) const
MipsTargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
const MipsABIInfo & ABI
SDValue getAddrGlobalLargeGOT(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, unsigned HiFlag, unsigned LoFlag, SDValue Chain, const MachinePointerInfo &PtrInfo) const
SDValue getDllimportVariable(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, SDValue Chain, const MachinePointerInfo &PtrInfo) const
bool shouldFoldConstantShiftPairToMask(const SDNode *N) const override
Return true if it is profitable to fold a pair of shifts into a mask.
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
CCAssignFn * CCAssignFnForReturn() const
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
ReplaceNodeResults - Replace the results of node with an illegal result type with new values built ou...
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
SDValue getDllimportSymbol(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG) const
CCAssignFn * CCAssignFnForCall() const
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Return the number of registers for a given MVT, ensuring vectors are treated as a series of gpr sized...
virtual void getOpndList(SmallVectorImpl< SDValue > &Ops, std::deque< std::pair< unsigned, SDValue > > &RegsToPass, bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const
This function fills Ops, which is the list of operands that will later be used when a function call n...
SDValue getAddrNonPIC(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG) const
SDValue lowerSTORE(SDValue Op, SelectionDAG &DAG) const
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo, const LibcallLoweringInfo *libcallLowering) const override
createFastISel - This method returns a target specific FastISel object, or null if the target does no...
void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const override
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag.
EVT getTypeForExtReturn(LLVMContext &Context, EVT VT, ISD::NodeType) const override
Return the type that should be used to zero or sign extend a zeroext/signext integer return value.
bool isCheapToSpeculateCtlz(Type *Ty) const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
LowerOperation - Provide custom lowering hooks for some operations.
bool isCheapToSpeculateCttz(Type *Ty) const override
Return true if it is cheap to speculate a call to intrinsic cttz.
SDValue getAddrLocal(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, bool IsN32OrN64) const
SDValue getGlobalReg(SelectionDAG &DAG, EVT Ty) const
const MipsSubtarget & Subtarget
void HandleByVal(CCState *, unsigned &, Align) const override
Target-specific cleanup for formal ByVal parameters.
SDValue lowerLOAD(SDValue Op, SelectionDAG &DAG) const
bool IsConstantInSmallSection(const DataLayout &DL, const Constant *CN, const Function *F) const
Return true if this constant should be placed into small data section.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
const SDValue & getOperand(unsigned Num) const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node, in exactly one operand.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
LLVM_ABI SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=LocationSize::precise(0), const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align DstAlign, Align SrcAlign, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
const TargetMachine & getTarget() const
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVM_ABI bool isKnownNeverNaN(SDValue Op, const APInt &DemandedElts, bool SNaN=false, unsigned Depth=0) const
Test whether the given SDValue (or all elements of it, if it is a vector) is known to never be NaN in...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits.
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
LLVM_ABI void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
MachineFunction & getMachineFunction() const
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask)
void addCallSiteInfo(const SDNode *Node, CallSiteInfo &&CallInfo)
Set CallSiteInfo to be associated with Node.
LLVMContext * getContext() const
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
SDValue getTargetConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
LLVM_ABI std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class is used to represent ISD::STORE nodes.
const SDValue & getBasePtr() const
const SDValue & getValue() const
bool isTruncatingStore() const
Return true if the op does a truncation before store.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
const char * const_iterator
Definition StringRef.h:61
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
Information about stack frame layout on the target.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
Provides information about what library functions are available for the current target.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
void setMinStackArgumentAlignment(Align Alignment)
Set the minimum stack alignment of an argument.
const TargetMachine & getTargetMachine() const
void setHasExtractBitsInsn(bool hasExtractInsn=true)
Tells the code generator that the target has BitExtract instructions.
MVT getRegisterType(LLVMContext &Context, EVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
void setMinFunctionAlignment(Align Alignment)
Set the target's minimum function alignment.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
FPImmAction
How the legalizer should materialize a floating-point immediate.
@ ConstantPool
Load the immediate from the constant pool.
@ Legal
The target can instruction select the immediate natively.
@ Bitcast
Build the immediate as a bitcast of an integer constant with the same bits.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
void setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
virtual bool useSoftFloat() const
Align getMinStackArgumentAlignment() const
Return the minimum stack alignment of an argument.
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
std::vector< ArgListEntry > ArgListTy
unsigned MaxStoresPerMemcpy
Specify maximum number of store instructions per memcpy call.
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA, SelectionDAG &DAG) const
Lower TLS global address SDNode for target independent emulated TLS model.
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
bool isPositionIndependent() const
virtual ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const
Examine constraint string and operand type and determine a weight value.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
TargetLowering(const TargetLowering &)=delete
virtual ArrayRef< MCPhysReg > getRoundingControlRegisters() const
Returns a 0 terminated array of rounding control registers that can be attached into strict FP call.
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
virtual unsigned getJumpTableEncoding() const
Return the entry encoding for a jump table in the current function.
virtual void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const
This callback is invoked by the type legalizer to legalize nodes with an illegal operand type but leg...
void setTypeIdForCallsiteInfo(const CallBase *CB, MachineFunction &MF, MachineFunction::CallSiteInfo &CSInfo) const
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
virtual TargetLoweringObjectFile * getObjFileLowering() const
TargetOptions Options
MCSymbol * getSymbol(const GlobalValue *GV) const
unsigned EnableFastISel
EnableFastISel - This flag enables fast-path instruction selection which trades away generated code q...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:155
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:187
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:303
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition Type.h:222
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:315
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:43
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:845
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition ISDOpcodes.h:516
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:805
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:266
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:879
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:523
@ GlobalAddress
Definition ISDOpcodes.h:90
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:420
@ MEMBARRIER
MEMBARRIER - Compiler barrier only; generate a no-op.
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:282
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition ISDOpcodes.h:256
@ GlobalTLSAddress
Definition ISDOpcodes.h:91
@ EH_RETURN
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin,...
Definition ISDOpcodes.h:158
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:870
@ TargetJumpTable
Definition ISDOpcodes.h:190
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
@ BR_CC
BR_CC - Conditional branch.
@ BR_JT
BR_JT - Jumptable branch.
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition ISDOpcodes.h:546
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
Definition ISDOpcodes.h:553
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:822
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:787
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Same as FMINNUM/FMAXNUM, except that a signaling NaN operand deterministi...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:876
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:837
@ FMINNUM
FMINNUM/FMAXNUM - Same semantics as the llvm.minnum/maxnum intrinsics.
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition ISDOpcodes.h:914
@ EH_DWARF_CFA
EH_DWARF_CFA - This node represents the pointer to the DWARF Canonical Frame Address (CFA),...
Definition ISDOpcodes.h:152
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition ISDOpcodes.h:112
@ STRICT_FP_TO_UINT
Definition ISDOpcodes.h:483
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:482
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:952
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:757
@ TRAP
TRAP - Trapping instruction.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:55
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:882
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
@ BRCOND
BRCOND - Conditional branch.
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition ISDOpcodes.h:859
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:64
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:539
@ CALLSEQ_START
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence,...
LLVM_ABI CondCode getSetCCInverse(CondCode Operation, EVT Type)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
@ MO_TLSGD
On a symbol operand, this indicates that the immediate is the offset to the slot in GOT which stores ...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
int getCPURegisterIndex(StringRef Name, const MCRegisterInfo &MRI, unsigned AltIdx, bool *IsDeprecated=nullptr)
Return a GPR name's hardware index, or -1 if unknown.
constexpr MCPhysReg FP_64
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo, const LibcallLoweringInfo *libcallLowering)
constexpr MCPhysReg GP_64
constexpr MCPhysReg FP
constexpr MCPhysReg GP
constexpr MCPhysReg RA_64
constexpr MCPhysReg SP
constexpr MCPhysReg SP_64
constexpr MCPhysReg RA
Not(const Pred &P) -> Not< Pred >
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
Definition LLVMContext.h:63
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:66
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Dead
Unused definition.
@ Undef
Value of the register doesn't matter.
@ EarlyClobber
Register definition happens before uses.
@ Define
Register definition.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
@ Store
The extracted value is stored (ExtractElement only).
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:274
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:389
@ Other
Any other memory.
Definition ModRef.h:68
@ AfterLegalizeDAG
Definition DAGCombine.h:19
const MipsTargetLowering * createMips16TargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
Create MipsTargetLowering objects.
@ Or
Bitwise or logical OR of integers.
@ Add
Sum of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
const MipsTargetLowering * createMipsSETargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
Definition MathExtras.h:78
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82
Extended Value Type.
Definition ValueTypes.h:35
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition ValueTypes.h:90
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition ValueTypes.h:323
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:396
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
Definition ValueTypes.h:501
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:339
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
Definition ValueTypes.h:55
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:176
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
bool isRound() const
Return true if the size is a power-of-two number of bytes.
Definition ValueTypes.h:271
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition ValueTypes.h:351
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:359
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:160
Align getNonZeroOrigAlign() const
SmallVector< ArgRegPair, 1 > ArgRegPairs
Vector of call argument and its forwarding register.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs