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 = Op.getOperandCondCode(2);
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();
1577 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
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 = Op.getOperandCondCode(3);
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
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 // The masked shift amount is 0 or VT.bits, not a 0/1 boolean, so compare it
2835 // against zero to form a proper select condition.
2836 SDValue Masked =
2837 DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
2838 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32));
2839 SDValue Cond = DAG.getSetCC(DL, MVT::i32, Masked,
2840 DAG.getConstant(0, DL, MVT::i32), ISD::SETNE);
2841 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond,
2842 DAG.getConstant(0, DL, VT), ShiftLeftLo);
2843 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftLeftLo, Or);
2844
2845 SDValue Ops[2] = {Lo, Hi};
2846 return DAG.getMergeValues(Ops, DL);
2847}
2848
2849SDValue MipsTargetLowering::lowerShiftRightParts(SDValue Op, SelectionDAG &DAG,
2850 bool IsSRA) const {
2851 SDLoc DL(Op);
2852 SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1);
2853 SDValue Shamt = Op.getOperand(2);
2854 MVT VT = Subtarget.isGP64bit() ? MVT::i64 : MVT::i32;
2855
2856 // if shamt < (VT.bits):
2857 // lo = (or (shl (shl hi, 1), (xor shamt, (VT.bits-1))) (srl lo, shamt))
2858 // if isSRA:
2859 // hi = (sra hi, shamt)
2860 // else:
2861 // hi = (srl hi, shamt)
2862 // else:
2863 // if isSRA:
2864 // lo = (sra hi, shamt[4:0])
2865 // hi = (sra hi, 31)
2866 // else:
2867 // lo = (srl hi, shamt[4:0])
2868 // hi = 0
2869 SDValue Not =
2870 DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt,
2871 DAG.getConstant(VT.getSizeInBits() - 1, DL, MVT::i32));
2872 SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, VT, Hi,
2873 DAG.getConstant(1, DL, VT));
2874 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, ShiftLeft1Hi, Not);
2875 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, Lo, Shamt);
2876 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo);
2877 SDValue ShiftRightHi = DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL,
2878 DL, VT, Hi, Shamt);
2879 SDValue Masked =
2880 DAG.getNode(ISD::AND, DL, MVT::i32, Shamt,
2881 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32));
2882 SDValue Ext = DAG.getNode(ISD::SRA, DL, VT, Hi,
2883 DAG.getConstant(VT.getSizeInBits() - 1, DL, VT));
2884
2885 if (!(Subtarget.hasMips4() || Subtarget.hasMips32())) {
2886 // DOUBLE_SELECT_I* branches on the condition being non-zero, so the
2887 // masked shift amount can be used directly.
2888 SDVTList VTList = DAG.getVTList(VT, VT);
2889 return DAG.getNode(Subtarget.isGP64bit() ? MipsISD::DOUBLE_SELECT_I64
2891 DL, VTList, Masked, ShiftRightHi,
2892 IsSRA ? Ext : DAG.getConstant(0, DL, VT), Or,
2893 ShiftRightHi);
2894 }
2895
2896 // The masked shift amount is 0 or VT.bits, not a 0/1 boolean, so compare it
2897 // against zero to form a proper select condition.
2898 SDValue Cond = DAG.getSetCC(DL, MVT::i32, Masked,
2899 DAG.getConstant(0, DL, MVT::i32), ISD::SETNE);
2900 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftRightHi, Or);
2901 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond,
2902 IsSRA ? Ext : DAG.getConstant(0, DL, VT), ShiftRightHi);
2903
2904 SDValue Ops[2] = {Lo, Hi};
2905 return DAG.getMergeValues(Ops, DL);
2906}
2907
2909 SDValue Chain, SDValue Src, unsigned Offset) {
2910 SDValue Ptr = LD->getBasePtr();
2911 EVT VT = LD->getValueType(0), MemVT = LD->getMemoryVT();
2912 EVT BasePtrVT = Ptr.getValueType();
2913 SDLoc DL(LD);
2914 SDVTList VTList = DAG.getVTList(VT, MVT::Other);
2915
2916 if (Offset)
2917 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr,
2918 DAG.getConstant(Offset, DL, BasePtrVT));
2919
2920 SDValue Ops[] = { Chain, Ptr, Src };
2921 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT,
2922 LD->getMemOperand());
2923}
2924
2925// Expand an unaligned 32 or 64-bit integer load node.
2928 EVT MemVT = LD->getMemoryVT();
2929
2930 if (Subtarget.systemSupportsUnalignedAccess())
2931 return Op;
2932
2933 // Return if load is aligned or if MemVT is neither i32 nor i64.
2934 if ((LD->getAlign().value() >= (MemVT.getSizeInBits() / 8)) ||
2935 ((MemVT != MVT::i32) && (MemVT != MVT::i64)))
2936 return SDValue();
2937
2938 bool IsLittle = Subtarget.isLittle();
2939 EVT VT = Op.getValueType();
2940 ISD::LoadExtType ExtType = LD->getExtensionType();
2941 SDValue Chain = LD->getChain(), Undef = DAG.getUNDEF(VT);
2942
2943 assert((VT == MVT::i32) || (VT == MVT::i64));
2944
2945 // Expand
2946 // (set dst, (i64 (load baseptr)))
2947 // to
2948 // (set tmp, (ldl (add baseptr, 7), undef))
2949 // (set dst, (ldr baseptr, tmp))
2950 if ((VT == MVT::i64) && (ExtType == ISD::NON_EXTLOAD)) {
2951 SDValue LDL = createLoadLR(MipsISD::LDL, DAG, LD, Chain, Undef,
2952 IsLittle ? 7 : 0);
2953 return createLoadLR(MipsISD::LDR, DAG, LD, LDL.getValue(1), LDL,
2954 IsLittle ? 0 : 7);
2955 }
2956
2957 SDValue LWL = createLoadLR(MipsISD::LWL, DAG, LD, Chain, Undef,
2958 IsLittle ? 3 : 0);
2959 SDValue LWR = createLoadLR(MipsISD::LWR, DAG, LD, LWL.getValue(1), LWL,
2960 IsLittle ? 0 : 3);
2961
2962 // Expand
2963 // (set dst, (i32 (load baseptr))) or
2964 // (set dst, (i64 (sextload baseptr))) or
2965 // (set dst, (i64 (extload baseptr)))
2966 // to
2967 // (set tmp, (lwl (add baseptr, 3), undef))
2968 // (set dst, (lwr baseptr, tmp))
2969 if ((VT == MVT::i32) || (ExtType == ISD::SEXTLOAD) ||
2970 (ExtType == ISD::EXTLOAD))
2971 return LWR;
2972
2973 assert((VT == MVT::i64) && (ExtType == ISD::ZEXTLOAD));
2974
2975 // Expand
2976 // (set dst, (i64 (zextload baseptr)))
2977 // to
2978 // (set tmp0, (lwl (add baseptr, 3), undef))
2979 // (set tmp1, (lwr baseptr, tmp0))
2980 // (set tmp2, (shl tmp1, 32))
2981 // (set dst, (srl tmp2, 32))
2982 SDLoc DL(LD);
2983 SDValue Const32 = DAG.getConstant(32, DL, MVT::i32);
2984 SDValue SLL = DAG.getNode(ISD::SHL, DL, MVT::i64, LWR, Const32);
2985 SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i64, SLL, Const32);
2986 SDValue Ops[] = { SRL, LWR.getValue(1) };
2987 return DAG.getMergeValues(Ops, DL);
2988}
2989
2991 SDValue Chain, unsigned Offset) {
2992 SDValue Ptr = SD->getBasePtr(), Value = SD->getValue();
2993 EVT MemVT = SD->getMemoryVT(), BasePtrVT = Ptr.getValueType();
2994 SDLoc DL(SD);
2995 SDVTList VTList = DAG.getVTList(MVT::Other);
2996
2997 if (Offset)
2998 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr,
2999 DAG.getConstant(Offset, DL, BasePtrVT));
3000
3001 SDValue Ops[] = { Chain, Value, Ptr };
3002 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT,
3003 SD->getMemOperand());
3004}
3005
3006// Expand an unaligned 32 or 64-bit integer store node.
3008 bool IsLittle) {
3009 SDValue Value = SD->getValue(), Chain = SD->getChain();
3010 EVT VT = Value.getValueType();
3011
3012 // Expand
3013 // (store val, baseptr) or
3014 // (truncstore val, baseptr)
3015 // to
3016 // (swl val, (add baseptr, 3))
3017 // (swr val, baseptr)
3018 if ((VT == MVT::i32) || SD->isTruncatingStore()) {
3019 SDValue SWL = createStoreLR(MipsISD::SWL, DAG, SD, Chain,
3020 IsLittle ? 3 : 0);
3021 return createStoreLR(MipsISD::SWR, DAG, SD, SWL, IsLittle ? 0 : 3);
3022 }
3023
3024 assert(VT == MVT::i64);
3025
3026 // Expand
3027 // (store val, baseptr)
3028 // to
3029 // (sdl val, (add baseptr, 7))
3030 // (sdr val, baseptr)
3031 SDValue SDL = createStoreLR(MipsISD::SDL, DAG, SD, Chain, IsLittle ? 7 : 0);
3032 return createStoreLR(MipsISD::SDR, DAG, SD, SDL, IsLittle ? 0 : 7);
3033}
3034
3035// Lower (store (fp_to_sint $fp) $ptr) to (store (TruncIntFP $fp), $ptr).
3037 bool SingleFloat) {
3038 SDValue Val = SD->getValue();
3039
3040 if (Val.getOpcode() != ISD::FP_TO_SINT ||
3041 (Val.getValueSizeInBits() > 32 && SingleFloat))
3042 return SDValue();
3043
3045 SDValue Tr = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Val), FPTy,
3046 Val.getOperand(0));
3047 return DAG.getStore(SD->getChain(), SDLoc(SD), Tr, SD->getBasePtr(),
3048 SD->getPointerInfo(), SD->getAlign(),
3049 SD->getMemOperand()->getFlags());
3050}
3051
3054 EVT MemVT = SD->getMemoryVT();
3055
3056 // Lower unaligned integer stores.
3057 if (!Subtarget.systemSupportsUnalignedAccess() &&
3058 (SD->getAlign().value() < (MemVT.getSizeInBits() / 8)) &&
3059 ((MemVT == MVT::i32) || (MemVT == MVT::i64)))
3060 return lowerUnalignedIntStore(SD, DAG, Subtarget.isLittle());
3061
3062 return lowerFP_TO_SINT_STORE(SD, DAG, Subtarget.isSingleFloat());
3063}
3064
3065SDValue MipsTargetLowering::lowerEH_DWARF_CFA(SDValue Op,
3066 SelectionDAG &DAG) const {
3067
3068 // Return a fixed StackObject with offset 0 which points to the old stack
3069 // pointer.
3071 EVT ValTy = Op->getValueType(0);
3072 int FI = MFI.CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false);
3073 return DAG.getFrameIndex(FI, ValTy);
3074}
3075
3076SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
3077 SelectionDAG &DAG) const {
3078 if (Op.getValueSizeInBits() > 32 && Subtarget.isSingleFloat())
3079 return SDValue();
3080
3081 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits());
3082 SDValue Trunc = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Op), FPTy,
3083 Op.getOperand(0));
3084 return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
3085}
3086
3087SDValue MipsTargetLowering::lowerSTRICT_FP_TO_INT(SDValue Op,
3088 SelectionDAG &DAG) const {
3089 assert(Op->isStrictFPOpcode());
3090 SDValue SrcVal = Op.getOperand(1);
3091 SDLoc Loc(Op);
3092
3093 SDValue Result =
3096 Loc, Op.getValueType(), SrcVal);
3097
3098 return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
3099}
3100
3102 static const MCPhysReg RCRegs[] = {Mips::FCR31};
3103 return RCRegs;
3104}
3105
3106//===----------------------------------------------------------------------===//
3107// Calling Convention Implementation
3108//===----------------------------------------------------------------------===//
3109
3110//===----------------------------------------------------------------------===//
3111// TODO: Implement a generic logic using tblgen that can support this.
3112// Mips O32 ABI rules:
3113// ---
3114// i32 - Passed in A0, A1, A2, A3 and stack
3115// f32 - Only passed in f32 registers if no int reg has been used yet to hold
3116// an argument. Otherwise, passed in A1, A2, A3 and stack.
3117// f64 - Only passed in two aliased f32 registers if no int reg has been used
3118// yet to hold an argument. Otherwise, use A2, A3 and stack. If A1 is
3119// not used, it must be shadowed. If only A3 is available, shadow it and
3120// go to stack.
3121// vXiX - Received as scalarized i32s, passed in A0 - A3 and the stack.
3122// vXf32 - Passed in either a pair of registers {A0, A1}, {A2, A3} or {A0 - A3}
3123// with the remainder spilled to the stack.
3124// vXf64 - Passed in either {A0, A1, A2, A3} or {A2, A3} and in both cases
3125// spilling the remainder to the stack.
3126//
3127// For vararg functions, all arguments are passed in A0, A1, A2, A3 and stack.
3128//===----------------------------------------------------------------------===//
3129
3130static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT,
3131 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
3132 Type *OrigTy, CCState &State,
3133 ArrayRef<MCPhysReg> F64Regs) {
3134 const MipsSubtarget &Subtarget = static_cast<const MipsSubtarget &>(
3135 State.getMachineFunction().getSubtarget());
3136
3137 const MipsABIInfo &ABI = Subtarget.getABI();
3138 ArrayRef<MCPhysReg> IntRegs = ABI.getArgRegs(false);
3139
3140 static const MCPhysReg F32Regs[] = { Mips::F12, Mips::F14 };
3141
3142 const MCPhysReg FloatVectorIntRegs[] = {IntRegs[0], IntRegs[2]};
3143
3144 // Do not process byval args here.
3145 if (ArgFlags.isByVal())
3146 return true;
3147
3148 // Promote i8 and i16
3149 if (ArgFlags.isInReg() && !Subtarget.isLittle()) {
3150 if (LocVT == MVT::i8 || LocVT == MVT::i16 || LocVT == MVT::i32) {
3151 LocVT = MVT::i32;
3152 if (ArgFlags.isSExt())
3153 LocInfo = CCValAssign::SExtUpper;
3154 else if (ArgFlags.isZExt())
3155 LocInfo = CCValAssign::ZExtUpper;
3156 else
3157 LocInfo = CCValAssign::AExtUpper;
3158 }
3159 }
3160
3161 // Promote i8 and i16
3162 if (LocVT == MVT::i8 || LocVT == MVT::i16) {
3163 LocVT = MVT::i32;
3164 if (ArgFlags.isSExt())
3165 LocInfo = CCValAssign::SExt;
3166 else if (ArgFlags.isZExt())
3167 LocInfo = CCValAssign::ZExt;
3168 else
3169 LocInfo = CCValAssign::AExt;
3170 }
3171
3172 unsigned Reg;
3173
3174 // f32 and f64 are allocated in A0, A1, A2, A3 when either of the following
3175 // is true: function is vararg, argument is 3rd or higher, there is previous
3176 // argument which is not f32 or f64.
3177 bool AllocateFloatsInIntReg = State.isVarArg() || ValNo > 1 ||
3178 State.getFirstUnallocated(F32Regs) != ValNo;
3179 Align OrigAlign = ArgFlags.getNonZeroOrigAlign();
3180 bool isI64 = (ValVT == MVT::i32 && OrigAlign == Align(8));
3181 bool isVectorFloat = OrigTy->isVectorTy() && OrigTy->isFPOrFPVectorTy();
3182
3183 // The MIPS vector ABI for floats passes them in a pair of registers
3184 if (ValVT == MVT::i32 && isVectorFloat) {
3185 // This is the start of an vector that was scalarized into an unknown number
3186 // of components. It doesn't matter how many there are. Allocate one of the
3187 // notional 8 byte aligned registers which map onto the argument stack, and
3188 // shadow the register lost to alignment requirements.
3189 if (ArgFlags.isSplit()) {
3190 Reg = State.AllocateReg(FloatVectorIntRegs);
3191 if (Reg == IntRegs[2])
3192 State.AllocateReg(IntRegs[1]);
3193 else if (Reg == 0)
3194 State.AllocateReg(IntRegs[3]);
3195 } else {
3196 // If we're an intermediate component of the split, we can just attempt to
3197 // allocate a register directly.
3198 Reg = State.AllocateReg(IntRegs);
3199 }
3200 } else if (ValVT == MVT::i32 ||
3201 (ValVT == MVT::f32 && AllocateFloatsInIntReg)) {
3202 Reg = State.AllocateReg(IntRegs);
3203 // If this is the first part of an i64 arg,
3204 // the allocated register must be either A0 or A2.
3205 if (isI64 && (Reg == IntRegs[1] || Reg == IntRegs[3]))
3206 Reg = State.AllocateReg(IntRegs);
3207 LocVT = MVT::i32;
3208 } else if (ValVT == MVT::f64 && AllocateFloatsInIntReg) {
3209 // Allocate int register and shadow next int register. If first
3210 // available register is $a1 or $a3, shadow it too.
3211 Reg = State.AllocateReg(IntRegs);
3212 if (Reg == IntRegs[1] || Reg == IntRegs[3])
3213 Reg = State.AllocateReg(IntRegs);
3214
3215 if (Reg) {
3216 LocVT = MVT::i32;
3217
3218 State.addLoc(
3219 CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
3220 MCRegister HiReg = State.AllocateReg(IntRegs);
3221 assert(HiReg);
3222 State.addLoc(
3223 CCValAssign::getCustomReg(ValNo, ValVT, HiReg, LocVT, LocInfo));
3224 return false;
3225 }
3226 } else if (ValVT.isFloatingPoint() && !AllocateFloatsInIntReg) {
3227 // we are guaranteed to find an available float register
3228 if (ValVT == MVT::f32) {
3229 Reg = State.AllocateReg(F32Regs);
3230 // Shadow int register
3231 State.AllocateReg(IntRegs);
3232 } else {
3233 Reg = State.AllocateReg(F64Regs);
3234 // Shadow int registers
3235 MCRegister Reg2 = State.AllocateReg(IntRegs);
3236 if (Reg2 == IntRegs[1] || Reg2 == IntRegs[3])
3237 State.AllocateReg(IntRegs);
3238 State.AllocateReg(IntRegs);
3239 }
3240 } else
3241 llvm_unreachable("Cannot handle this ValVT.");
3242
3243 if (!Reg) {
3244 unsigned Offset = State.AllocateStack(ValVT.getStoreSize(), OrigAlign);
3245 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
3246 } else
3247 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
3248
3249 return false;
3250}
3251
3252static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT,
3253 CCValAssign::LocInfo LocInfo,
3254 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3255 CCState &State) {
3256 static const MCPhysReg F64Regs[] = { Mips::D6, Mips::D7 };
3257
3258 return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
3259 F64Regs);
3260}
3261
3262static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT,
3263 CCValAssign::LocInfo LocInfo,
3264 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3265 CCState &State) {
3266 static const MCPhysReg F64Regs[] = { Mips::D12_64, Mips::D14_64 };
3267
3268 return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, OrigTy, State,
3269 F64Regs);
3270}
3271
3272[[maybe_unused]] static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT,
3273 CCValAssign::LocInfo LocInfo,
3274 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
3275 CCState &State);
3276
3277#define GET_CALLING_CONV_IMPL
3278#include "MipsGenCallingConv.inc"
3279
3281 return CC_Mips_FixedArg;
3282 }
3283
3285 return RetCC_Mips;
3286 }
3287//===----------------------------------------------------------------------===//
3288// Call Calling Convention Implementation
3289//===----------------------------------------------------------------------===//
3290
3291SDValue MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset,
3292 SDValue Chain, SDValue Arg,
3293 const SDLoc &DL, bool IsTailCall,
3294 SelectionDAG &DAG) const {
3295 if (!IsTailCall) {
3296 SDValue PtrOff =
3297 DAG.getNode(ISD::ADD, DL, getPointerTy(DAG.getDataLayout()), StackPtr,
3299 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo());
3300 }
3301
3303 int FI = MFI.CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false);
3304 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
3305 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), MaybeAlign(),
3307}
3308
3311 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
3312 bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
3313 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
3314 // Insert node "GP copy globalreg" before call to function.
3315 //
3316 // R_MIPS_CALL* operators (emitted when non-local functions are called
3317 // in PIC mode) allow symbols to be resolved via lazy binding.
3318 // The lazy binding stub requires GP to point to the GOT.
3319 // Note that we don't need GP to point to the GOT for indirect calls
3320 // (when R_MIPS_CALL* is not used for the call) because Mips linker generates
3321 // lazy binding stub for a function only when R_MIPS_CALL* are the only relocs
3322 // used for the function (that is, Mips linker doesn't generate lazy binding
3323 // stub for a function whose address is taken in the program).
3324 if (IsPICCall && !LocalLinkage && IsCallReloc) {
3325 unsigned GPReg = ABI.IsN64() ? Mips::GP_64 : Mips::GP;
3326 EVT Ty = ABI.IsN64() ? MVT::i64 : MVT::i32;
3327 RegsToPass.push_back(std::make_pair(GPReg, getGlobalReg(CLI.DAG, Ty)));
3328 }
3329
3330 // Build a sequence of copy-to-reg nodes chained together with token
3331 // chain and flag operands which copy the outgoing args into registers.
3332 // The InGlue in necessary since all emitted instructions must be
3333 // stuck together.
3334 SDValue InGlue;
3335
3336 for (auto &R : RegsToPass) {
3337 Chain = CLI.DAG.getCopyToReg(Chain, CLI.DL, R.first, R.second, InGlue);
3338 InGlue = Chain.getValue(1);
3339 }
3340
3341 // Add argument registers to the end of the list so that they are
3342 // known live into the call.
3343 for (auto &R : RegsToPass)
3344 Ops.push_back(CLI.DAG.getRegister(R.first, R.second.getValueType()));
3345
3346 // Add a register mask operand representing the call-preserved registers.
3347 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
3348 const uint32_t *Mask =
3349 TRI->getCallPreservedMask(CLI.DAG.getMachineFunction(), CLI.CallConv);
3350 assert(Mask && "Missing call preserved mask for calling convention");
3351 if (Subtarget.inMips16HardFloat()) {
3353 StringRef Sym = G->getGlobal()->getName();
3354 Function *F = G->getGlobal()->getParent()->getFunction(Sym);
3355 if (F && F->hasFnAttribute("__Mips16RetHelper")) {
3357 }
3358 }
3359 }
3360 Ops.push_back(CLI.DAG.getRegisterMask(Mask));
3361
3362 if (InGlue.getNode())
3363 Ops.push_back(InGlue);
3364}
3365
3367 SDNode *Node) const {
3368 switch (MI.getOpcode()) {
3369 default:
3370 return;
3371 case Mips::JALR:
3372 case Mips::JALRPseudo:
3373 case Mips::JALR64:
3374 case Mips::JALR64Pseudo:
3375 case Mips::JALR16_MM:
3376 case Mips::JALRC16_MMR6:
3377 case Mips::TAILCALLREG:
3378 case Mips::TAILCALLREG64:
3379 case Mips::TAILCALLR6REG:
3380 case Mips::TAILCALL64R6REG:
3381 case Mips::TAILCALLREG_MM:
3382 case Mips::TAILCALLREG_MMR6: {
3383 if (!Subtarget.getMCCLOpts().jalr_reloc || Subtarget.inMips16Mode() ||
3384 !isPositionIndependent() || Node->getNumOperands() < 1 ||
3385 Node->getOperand(0).getNumOperands() < 2) {
3386 return;
3387 }
3388 // We are after the callee address, set by LowerCall().
3389 // If added to MI, asm printer will emit .reloc R_MIPS_JALR for the
3390 // symbol.
3391 const SDValue TargetAddr = Node->getOperand(0).getOperand(1);
3392 MCSymbol *S = nullptr;
3393 if (const GlobalAddressSDNode *G =
3395 const GlobalValue *GV = G->getGlobal();
3396
3397 // We must not emit the R_MIPS_JALR relocation against data symbols
3398 // since this will cause run-time crashes if the linker replaces the
3399 // call instruction with a relative branch to the data symbol.
3400 if (!isa<Function>(GV)) {
3401 LLVM_DEBUG(dbgs() << "Not adding R_MIPS_JALR against data symbol "
3402 << GV->getName() << "\n");
3403 return;
3404 }
3405 S = getTargetMachine().getSymbol(GV);
3406 }
3407 else if (const ExternalSymbolSDNode *ES =
3409 S = MI.getParent()->getParent()->getContext().getOrCreateSymbol(
3410 ES->getSymbol());
3411 }
3412
3413 if (!S)
3414 return;
3415
3416 LLVM_DEBUG(dbgs() << "Adding R_MIPS_JALR against " << S->getName()
3417 << "\n");
3419 }
3420 }
3421}
3422
3423/// LowerCall - functions arguments are copied from virtual regs to
3424/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
3425SDValue
3426MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
3427 SmallVectorImpl<SDValue> &InVals) const {
3428 SelectionDAG &DAG = CLI.DAG;
3429 SDLoc DL = CLI.DL;
3431 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
3433 SDValue Chain = CLI.Chain;
3434 SDValue Callee = CLI.Callee;
3435 bool &IsTailCall = CLI.IsTailCall;
3436 CallingConv::ID CallConv = CLI.CallConv;
3437 bool IsVarArg = CLI.IsVarArg;
3438 const CallBase *CB = CLI.CB;
3439
3441 MachineFrameInfo &MFI = MF.getFrameInfo();
3442 const TargetFrameLowering *TFL = Subtarget.getFrameLowering();
3443 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
3444 bool IsPIC = isPositionIndependent();
3445
3446 // Analyze operands of the call, assigning locations to each operand.
3448 MipsCCState CCInfo(
3449 CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, *DAG.getContext(),
3451
3452 const ExternalSymbolSDNode *ES =
3454
3455 // There is one case where CALLSEQ_START..CALLSEQ_END can be nested, which
3456 // is during the lowering of a call with a byval argument which produces
3457 // a call to memcpy. For the O32 case, this causes the caller to allocate
3458 // stack space for the reserved argument area for the callee, then recursively
3459 // again for the memcpy call. In the NEWABI case, this doesn't occur as those
3460 // ABIs mandate that the callee allocates the reserved argument area. We do
3461 // still produce nested CALLSEQ_START..CALLSEQ_END with zero space though.
3462 //
3463 // If the callee has a byval argument and memcpy is used, we are mandated
3464 // to already have produced a reserved argument area for the callee for O32.
3465 // Therefore, the reserved argument area can be reused for both calls.
3466 //
3467 // Other cases of calling memcpy cannot have a chain with a CALLSEQ_START
3468 // present, as we have yet to hook that node onto the chain.
3469 //
3470 // Hence, the CALLSEQ_START and CALLSEQ_END nodes can be eliminated in this
3471 // case. GCC does a similar trick, in that wherever possible, it calculates
3472 // the maximum out going argument area (including the reserved area), and
3473 // preallocates the stack space on entrance to the caller.
3474 //
3475 // FIXME: We should do the same for efficiency and space.
3476
3477 // Note: The check on the calling convention below must match
3478 // MipsABIInfo::GetCalleeAllocdArgSizeInBytes().
3479 bool MemcpyInByVal = ES && StringRef(ES->getSymbol()) == "memcpy" &&
3480 CallConv != CallingConv::Fast &&
3481 Chain.getOpcode() == ISD::CALLSEQ_START;
3482
3483 // Allocate the reserved argument area. It seems strange to do this from the
3484 // caller side but removing it breaks the frame size calculation.
3485 unsigned ReservedArgArea =
3486 MemcpyInByVal ? 0 : ABI.GetCalleeAllocdArgSizeInBytes(CallConv);
3487 CCInfo.AllocateStack(ReservedArgArea, Align(1));
3488
3489 CCInfo.AnalyzeCallOperands(Outs, CC_Mips);
3490
3491 // Get a count of how many bytes are to be pushed on the stack.
3492 unsigned StackSize = CCInfo.getStackSize();
3493
3494 // Call site info for function parameters tracking and call base type info.
3496 // Set type id for call site info.
3497 setTypeIdForCallsiteInfo(CB, MF, CSInfo);
3498
3499 // Check if it's really possible to do a tail call.
3500 // For non-musttail calls, restrict to functions that won't require $gp
3501 // restoration. In PIC mode, calling external functions via tail call can
3502 // cause issues with $gp register handling (see D24763).
3503 bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
3504 bool CalleeIsLocal = true;
3506 const GlobalValue *GV = G->getGlobal();
3507 bool HasLocalLinkage = GV->hasLocalLinkage() || GV->hasPrivateLinkage();
3508 bool HasHiddenVisibility =
3510 if (GV->isDeclarationForLinker())
3511 CalleeIsLocal = HasLocalLinkage || HasHiddenVisibility;
3512 else
3513 CalleeIsLocal = GV->isDSOLocal();
3514 }
3515
3516 if (IsTailCall) {
3517 if (!Subtarget.getCLOpts().tail_calls) {
3518 IsTailCall = false;
3519 if (IsMustTail)
3520 report_fatal_error("failed to perform tail call elimination on a call "
3521 "site marked musttail");
3522 } else {
3523 bool Eligible = isEligibleForTailCallOptimization(
3524 CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>());
3525 if (!Eligible || !CalleeIsLocal) {
3526 IsTailCall = false;
3527 if (IsMustTail)
3529 "failed to perform tail call elimination on a call "
3530 "site marked musttail");
3531 }
3532 }
3533 }
3534
3535 if (IsTailCall)
3536 ++NumTailCalls;
3537
3538 // Chain is the output chain of the last Load/Store or CopyToReg node.
3539 // ByValChain is the output chain of the last Memcpy node created for copying
3540 // byval arguments to the stack.
3541 unsigned StackAlignment = TFL->getStackAlignment();
3542 StackSize = alignTo(StackSize, StackAlignment);
3543
3544 if (!(IsTailCall || MemcpyInByVal))
3545 Chain = DAG.getCALLSEQ_START(Chain, StackSize, 0, DL);
3546
3548 DAG.getCopyFromReg(Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP,
3550 std::deque<std::pair<unsigned, SDValue>> RegsToPass;
3551 SmallVector<SDValue, 8> MemOpChains;
3552
3553 CCInfo.rewindByValRegsInfo();
3554
3555 // Walk the register/memloc assignments, inserting copies/loads.
3556 for (unsigned i = 0, e = ArgLocs.size(), OutIdx = 0; i != e; ++i, ++OutIdx) {
3557 SDValue Arg = OutVals[OutIdx];
3558 CCValAssign &VA = ArgLocs[i];
3559 MVT ValVT = VA.getValVT(), LocVT = VA.getLocVT();
3560 ISD::ArgFlagsTy Flags = Outs[OutIdx].Flags;
3561 bool UseUpperBits = false;
3562
3563 // ByVal Arg.
3564 if (Flags.isByVal()) {
3565 unsigned FirstByValReg, LastByValReg;
3566 unsigned ByValIdx = CCInfo.getInRegsParamsProcessed();
3567 CCInfo.getInRegsParamInfo(ByValIdx, FirstByValReg, LastByValReg);
3568
3569 assert(Flags.getByValSize() &&
3570 "ByVal args of size 0 should have been ignored by front-end.");
3571 assert(ByValIdx < CCInfo.getInRegsParamsCount());
3572 assert(!IsTailCall &&
3573 "Do not tail-call optimize if there is a byval argument.");
3574 passByValArg(Chain, DL, RegsToPass, MemOpChains, StackPtr, MFI, DAG, Arg,
3575 FirstByValReg, LastByValReg, Flags, Subtarget.isLittle(),
3576 VA);
3577 CCInfo.nextInRegsParam();
3578 continue;
3579 }
3580
3581 // Promote the value if needed.
3582 switch (VA.getLocInfo()) {
3583 default:
3584 llvm_unreachable("Unknown loc info!");
3585 case CCValAssign::Full:
3586 if (VA.isRegLoc()) {
3587 if ((ValVT == MVT::f32 && LocVT == MVT::i32) ||
3588 (ValVT == MVT::f64 && LocVT == MVT::i64) ||
3589 (ValVT == MVT::i64 && LocVT == MVT::f64))
3590 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
3591 else if (ValVT == MVT::f64 && LocVT == MVT::i32) {
3592 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
3593 Arg, DAG.getConstant(0, DL, MVT::i32));
3594 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32,
3595 Arg, DAG.getConstant(1, DL, MVT::i32));
3596 if (!Subtarget.isLittle())
3597 std::swap(Lo, Hi);
3598
3599 assert(VA.needsCustom());
3600
3601 Register LocRegLo = VA.getLocReg();
3602 Register LocRegHigh = ArgLocs[++i].getLocReg();
3603 RegsToPass.push_back(std::make_pair(LocRegLo, Lo));
3604 RegsToPass.push_back(std::make_pair(LocRegHigh, Hi));
3605 continue;
3606 }
3607 }
3608 break;
3609 case CCValAssign::BCvt:
3610 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
3611 break;
3613 UseUpperBits = true;
3614 [[fallthrough]];
3615 case CCValAssign::SExt:
3616 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg);
3617 break;
3619 UseUpperBits = true;
3620 [[fallthrough]];
3621 case CCValAssign::ZExt:
3622 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, LocVT, Arg);
3623 break;
3625 UseUpperBits = true;
3626 [[fallthrough]];
3627 case CCValAssign::AExt:
3628 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, LocVT, Arg);
3629 break;
3630 }
3631
3632 if (UseUpperBits) {
3633 unsigned ValSizeInBits = Outs[OutIdx].ArgVT.getSizeInBits();
3634 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3635 Arg = DAG.getNode(
3636 ISD::SHL, DL, VA.getLocVT(), Arg,
3637 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3638 }
3639
3640 // Arguments that can be passed on register must be kept at
3641 // RegsToPass vector
3642 if (VA.isRegLoc()) {
3643 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
3644
3645 // If the parameter is passed through reg $D, which splits into
3646 // two physical registers, avoid creating call site info.
3647 if (Mips::AFGR64RegClass.contains(VA.getLocReg()))
3648 continue;
3649
3650 // Collect CSInfo about which register passes which parameter.
3651 const TargetOptions &Options = DAG.getTarget().Options;
3652 if (Options.EmitCallSiteInfo)
3653 CSInfo.ArgRegPairs.emplace_back(VA.getLocReg(), i);
3654
3655 continue;
3656 }
3657
3658 // Register can't get to this point...
3659 assert(VA.isMemLoc());
3660
3661 // emit ISD::STORE whichs stores the
3662 // parameter value to a stack Location
3663 MemOpChains.push_back(passArgOnStack(StackPtr, VA.getLocMemOffset(),
3664 Chain, Arg, DL, IsTailCall, DAG));
3665 }
3666
3667 // Transform all store nodes into one single node because all store
3668 // nodes are independent of each other.
3669 if (!MemOpChains.empty())
3670 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
3671
3672 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
3673 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
3674 // node so that legalize doesn't hack it.
3675
3676 EVT Ty = Callee.getValueType();
3677 bool GlobalOrExternal = false, IsCallReloc = false;
3678
3679 // The long-calls feature is ignored in case of PIC.
3680 // While we do not support -mshared / -mno-shared properly,
3681 // ignore long-calls in case of -mabicalls too.
3682 if (!Subtarget.isABICalls() && !IsPIC) {
3683 // If the function should be called using "long call",
3684 // get its address into a register to prevent using
3685 // of the `jal` instruction for the direct call.
3686 if (auto *N = dyn_cast<ExternalSymbolSDNode>(Callee)) {
3687 if (Subtarget.useLongCalls())
3688 Callee = Subtarget.hasSym32()
3689 ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
3690 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
3691 } else if (auto *N = dyn_cast<GlobalAddressSDNode>(Callee)) {
3692 bool UseLongCalls = Subtarget.useLongCalls();
3693 // If the function has long-call/far/near attribute
3694 // it overrides command line switch pased to the backend.
3695 if (auto *F = dyn_cast<Function>(N->getGlobal())) {
3696 if (F->hasFnAttribute("long-call"))
3697 UseLongCalls = true;
3698 else if (F->hasFnAttribute("short-call"))
3699 UseLongCalls = false;
3700 }
3701 if (UseLongCalls)
3702 Callee = Subtarget.hasSym32()
3703 ? getAddrNonPIC(N, SDLoc(N), Ty, DAG)
3704 : getAddrNonPICSym64(N, SDLoc(N), Ty, DAG);
3705 }
3706 }
3707
3708 bool LocalLinkage = false;
3709 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
3710 if (Subtarget.isTargetCOFF() &&
3711 G->getGlobal()->hasDLLImportStorageClass()) {
3712 assert(Subtarget.isTargetWindows() &&
3713 "Windows is the only supported COFF target");
3714 auto PtrInfo = MachinePointerInfo();
3715 Callee = DAG.getLoad(Ty, DL, Chain,
3716 getDllimportSymbol(G, SDLoc(G), Ty, DAG), PtrInfo);
3717 } else if (IsPIC) {
3718 const GlobalValue *Val = G->getGlobal();
3719 LocalLinkage = Val->hasLocalLinkage();
3720
3721 if (LocalLinkage)
3722 Callee = getAddrLocal(G, DL, Ty, DAG, ABI.IsN32() || ABI.IsN64());
3723 else if (Subtarget.useXGOT()) {
3725 MipsII::MO_CALL_LO16, Chain,
3726 FuncInfo->callPtrInfo(MF, Val));
3727 IsCallReloc = true;
3728 } else {
3729 Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
3730 FuncInfo->callPtrInfo(MF, Val));
3731 IsCallReloc = true;
3732 }
3733 } else
3734 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL,
3735 getPointerTy(DAG.getDataLayout()), 0,
3737 GlobalOrExternal = true;
3738 }
3739 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
3740 const char *Sym = S->getSymbol();
3741
3742 if (!IsPIC) // static
3745 else if (Subtarget.useXGOT()) {
3747 MipsII::MO_CALL_LO16, Chain,
3748 FuncInfo->callPtrInfo(MF, Sym));
3749 IsCallReloc = true;
3750 } else { // PIC
3751 Callee = getAddrGlobal(S, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
3752 FuncInfo->callPtrInfo(MF, Sym));
3753 IsCallReloc = true;
3754 }
3755
3756 GlobalOrExternal = true;
3757 }
3758
3759 SmallVector<SDValue, 8> Ops(1, Chain);
3760 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
3761
3762 getOpndList(Ops, RegsToPass, IsPIC, GlobalOrExternal, LocalLinkage,
3763 IsCallReloc, CLI, Callee, Chain);
3764
3765 if (IsTailCall) {
3767 SDValue Ret = DAG.getNode(MipsISD::TailCall, DL, MVT::Other, Ops);
3768 DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
3769 return Ret;
3770 }
3771
3772 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops);
3773 SDValue InGlue = Chain.getValue(1);
3774
3775 DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
3776
3777 // Create the CALLSEQ_END node in the case of where it is not a call to
3778 // memcpy.
3779 if (!(MemcpyInByVal)) {
3780 Chain = DAG.getCALLSEQ_END(Chain, StackSize, 0, InGlue, DL);
3781 InGlue = Chain.getValue(1);
3782 }
3783
3784 // Handle result values, copying them out of physregs into vregs that we
3785 // return.
3786 return LowerCallResult(Chain, InGlue, CallConv, IsVarArg, Ins, DL, DAG,
3787 InVals, CLI);
3788}
3789
3790/// LowerCallResult - Lower the result values of a call into the
3791/// appropriate copies out of appropriate physical registers.
3792SDValue MipsTargetLowering::LowerCallResult(
3793 SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool IsVarArg,
3794 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
3797 // Assign locations to each value returned by this call.
3799 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
3800 *DAG.getContext());
3801
3802 CCInfo.AnalyzeCallResult(Ins, RetCC_Mips);
3803
3804 // Copy all of the result registers out of their specified physreg.
3805 for (unsigned i = 0; i != RVLocs.size(); ++i) {
3806 CCValAssign &VA = RVLocs[i];
3807 assert(VA.isRegLoc() && "Can only return in registers!");
3808
3809 SDValue Val = DAG.getCopyFromReg(Chain, DL, RVLocs[i].getLocReg(),
3810 RVLocs[i].getLocVT(), InGlue);
3811 Chain = Val.getValue(1);
3812 InGlue = Val.getValue(2);
3813
3814 if (VA.isUpperBitsInLoc()) {
3815 unsigned ValSizeInBits = Ins[i].ArgVT.getSizeInBits();
3816 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3817 unsigned Shift =
3819 Val = DAG.getNode(
3820 Shift, DL, VA.getLocVT(), Val,
3821 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3822 }
3823
3824 switch (VA.getLocInfo()) {
3825 default:
3826 llvm_unreachable("Unknown loc info!");
3827 case CCValAssign::Full:
3828 break;
3829 case CCValAssign::BCvt:
3830 Val = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), Val);
3831 break;
3832 case CCValAssign::AExt:
3834 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3835 break;
3836 case CCValAssign::ZExt:
3838 Val = DAG.getNode(ISD::AssertZext, DL, VA.getLocVT(), Val,
3839 DAG.getValueType(VA.getValVT()));
3840 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3841 break;
3842 case CCValAssign::SExt:
3844 Val = DAG.getNode(ISD::AssertSext, DL, VA.getLocVT(), Val,
3845 DAG.getValueType(VA.getValVT()));
3846 Val = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Val);
3847 break;
3848 }
3849
3850 InVals.push_back(Val);
3851 }
3852
3853 return Chain;
3854}
3855
3857 EVT ArgVT, const SDLoc &DL,
3858 SelectionDAG &DAG) {
3859 MVT LocVT = VA.getLocVT();
3860 EVT ValVT = VA.getValVT();
3861
3862 // Shift into the upper bits if necessary.
3863 switch (VA.getLocInfo()) {
3864 default:
3865 break;
3869 unsigned ValSizeInBits = ArgVT.getSizeInBits();
3870 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
3871 unsigned Opcode =
3873 Val = DAG.getNode(
3874 Opcode, DL, VA.getLocVT(), Val,
3875 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
3876 break;
3877 }
3878 }
3879
3880 // If this is an value smaller than the argument slot size (32-bit for O32,
3881 // 64-bit for N32/N64), it has been promoted in some way to the argument slot
3882 // size. Extract the value and insert any appropriate assertions regarding
3883 // sign/zero extension.
3884 switch (VA.getLocInfo()) {
3885 default:
3886 llvm_unreachable("Unknown loc info!");
3887 case CCValAssign::Full:
3888 break;
3890 case CCValAssign::AExt:
3891 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3892 break;
3894 case CCValAssign::SExt:
3895 Val = DAG.getNode(ISD::AssertSext, DL, LocVT, Val, DAG.getValueType(ValVT));
3896 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3897 break;
3899 case CCValAssign::ZExt:
3900 Val = DAG.getNode(ISD::AssertZext, DL, LocVT, Val, DAG.getValueType(ValVT));
3901 Val = DAG.getNode(ISD::TRUNCATE, DL, ValVT, Val);
3902 break;
3903 case CCValAssign::BCvt:
3904 Val = DAG.getNode(ISD::BITCAST, DL, ValVT, Val);
3905 break;
3906 }
3907
3908 return Val;
3909}
3910
3911//===----------------------------------------------------------------------===//
3912// Formal Arguments Calling Convention Implementation
3913//===----------------------------------------------------------------------===//
3914/// LowerFormalArguments - transform physical registers into virtual registers
3915/// and generate load operations for arguments places on the stack.
3916SDValue MipsTargetLowering::LowerFormalArguments(
3917 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
3918 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
3919 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
3921 MachineFrameInfo &MFI = MF.getFrameInfo();
3922 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
3923
3924 MipsFI->setVarArgsFrameIndex(0);
3925
3926 // Used with vargs to acumulate store chains.
3927 std::vector<SDValue> OutChains;
3928
3929 // Assign locations to all of the incoming arguments.
3931 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
3932 *DAG.getContext());
3933 CCInfo.AllocateStack(ABI.GetCalleeAllocdArgSizeInBytes(CallConv), Align(1));
3935 Function::const_arg_iterator FuncArg = Func.arg_begin();
3936
3937 if (Func.hasFnAttribute("interrupt") && !Func.arg_empty())
3939 "Functions with the interrupt attribute cannot have arguments!");
3940
3941 CCInfo.AnalyzeFormalArguments(Ins, CC_Mips_FixedArg);
3942 MipsFI->setFormalArgInfo(CCInfo.getStackSize(),
3943 CCInfo.getInRegsParamsCount() > 0);
3944
3945 unsigned CurArgIdx = 0;
3946 CCInfo.rewindByValRegsInfo();
3947
3948 for (unsigned i = 0, e = ArgLocs.size(), InsIdx = 0; i != e; ++i, ++InsIdx) {
3949 CCValAssign &VA = ArgLocs[i];
3950 if (Ins[InsIdx].isOrigArg()) {
3951 std::advance(FuncArg, Ins[InsIdx].getOrigArgIndex() - CurArgIdx);
3952 CurArgIdx = Ins[InsIdx].getOrigArgIndex();
3953 }
3954 EVT ValVT = VA.getValVT();
3955 ISD::ArgFlagsTy Flags = Ins[InsIdx].Flags;
3956 bool IsRegLoc = VA.isRegLoc();
3957
3958 if (Flags.isByVal()) {
3959 assert(Ins[InsIdx].isOrigArg() && "Byval arguments cannot be implicit");
3960 unsigned FirstByValReg, LastByValReg;
3961 unsigned ByValIdx = CCInfo.getInRegsParamsProcessed();
3962 CCInfo.getInRegsParamInfo(ByValIdx, FirstByValReg, LastByValReg);
3963
3964 assert(Flags.getByValSize() &&
3965 "ByVal args of size 0 should have been ignored by front-end.");
3966 assert(ByValIdx < CCInfo.getInRegsParamsCount());
3967 copyByValRegs(Chain, DL, OutChains, DAG, Flags, InVals, &*FuncArg,
3968 FirstByValReg, LastByValReg, VA, CCInfo);
3969 CCInfo.nextInRegsParam();
3970 continue;
3971 }
3972
3973 // Arguments stored on registers
3974 if (IsRegLoc) {
3975 MVT RegVT = VA.getLocVT();
3976 Register ArgReg = VA.getLocReg();
3977 const TargetRegisterClass *RC = getRegClassFor(RegVT);
3978
3979 // Transform the arguments stored on
3980 // physical registers into virtual ones
3981 unsigned Reg = addLiveIn(DAG.getMachineFunction(), ArgReg, RC);
3982 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegVT);
3983
3984 ArgValue =
3985 UnpackFromArgumentSlot(ArgValue, VA, Ins[InsIdx].ArgVT, DL, DAG);
3986
3987 // Handle floating point arguments passed in integer registers and
3988 // long double arguments passed in floating point registers.
3989 if ((RegVT == MVT::i32 && ValVT == MVT::f32) ||
3990 (RegVT == MVT::i64 && ValVT == MVT::f64) ||
3991 (RegVT == MVT::f64 && ValVT == MVT::i64))
3992 ArgValue = DAG.getNode(ISD::BITCAST, DL, ValVT, ArgValue);
3993 else if (ABI.IsO32() && RegVT == MVT::i32 &&
3994 ValVT == MVT::f64) {
3995 assert(VA.needsCustom() && "Expected custom argument for f64 split");
3996 CCValAssign &NextVA = ArgLocs[++i];
3997 unsigned Reg2 =
3998 addLiveIn(DAG.getMachineFunction(), NextVA.getLocReg(), RC);
3999 SDValue ArgValue2 = DAG.getCopyFromReg(Chain, DL, Reg2, RegVT);
4000 if (!Subtarget.isLittle())
4001 std::swap(ArgValue, ArgValue2);
4002 ArgValue = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64,
4003 ArgValue, ArgValue2);
4004 }
4005
4006 InVals.push_back(ArgValue);
4007 } else { // VA.isRegLoc()
4008 MVT LocVT = VA.getLocVT();
4009
4010 assert(!VA.needsCustom() && "unexpected custom memory argument");
4011
4012 // Only arguments pased on the stack should make it here.
4013 assert(VA.isMemLoc());
4014
4015 // The stack pointer offset is relative to the caller stack frame.
4016 int FI = MFI.CreateFixedObject(LocVT.getSizeInBits() / 8,
4017 VA.getLocMemOffset(), true);
4018
4019 // Create load nodes to retrieve arguments from the stack
4020 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
4021 SDValue ArgValue = DAG.getLoad(
4022 LocVT, DL, Chain, FIN,
4024 OutChains.push_back(ArgValue.getValue(1));
4025
4026 ArgValue =
4027 UnpackFromArgumentSlot(ArgValue, VA, Ins[InsIdx].ArgVT, DL, DAG);
4028
4029 InVals.push_back(ArgValue);
4030 }
4031 }
4032
4033 for (unsigned i = 0, e = ArgLocs.size(), InsIdx = 0; i != e; ++i, ++InsIdx) {
4034
4035 if (ArgLocs[i].needsCustom()) {
4036 ++i;
4037 continue;
4038 }
4039
4040 // The mips ABIs for returning structs by value requires that we copy
4041 // the sret argument into $v0 for the return. Save the argument into
4042 // a virtual register so that we can access it from the return points.
4043 if (Ins[InsIdx].Flags.isSRet()) {
4044 unsigned Reg = MipsFI->getSRetReturnReg();
4045 if (!Reg) {
4047 getRegClassFor(ABI.IsN64() ? MVT::i64 : MVT::i32));
4048 MipsFI->setSRetReturnReg(Reg);
4049 }
4050 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), DL, Reg, InVals[i]);
4051 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Copy, Chain);
4052 break;
4053 }
4054 }
4055
4056 if (IsVarArg)
4057 writeVarArgRegs(OutChains, Chain, DL, DAG, CCInfo);
4058
4059 // All stores are grouped in one node to allow the matching between
4060 // the size of Ins and InVals. This only happens when on varg functions
4061 if (!OutChains.empty()) {
4062 OutChains.push_back(Chain);
4063 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
4064 }
4065
4066 return Chain;
4067}
4068
4069//===----------------------------------------------------------------------===//
4070// Return Value Calling Convention Implementation
4071//===----------------------------------------------------------------------===//
4072
4073bool
4074MipsTargetLowering::CanLowerReturn(CallingConv::ID CallConv,
4075 MachineFunction &MF, bool IsVarArg,
4077 LLVMContext &Context, const Type *RetTy) const {
4079 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
4080 return CCInfo.CheckReturn(Outs, RetCC_Mips);
4081}
4082
4083bool MipsTargetLowering::shouldSignExtendTypeInLibCall(Type *Ty,
4084 bool IsSigned) const {
4085 if ((ABI.IsN32() || ABI.IsN64()) && Ty->isIntegerTy(32))
4086 return true;
4087
4088 return IsSigned;
4089}
4090
4091SDValue
4092MipsTargetLowering::LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps,
4093 const SDLoc &DL,
4094 SelectionDAG &DAG) const {
4096 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4097
4098 MipsFI->setISR();
4099
4100 return DAG.getNode(MipsISD::ERet, DL, MVT::Other, RetOps);
4101}
4102
4103SDValue
4104MipsTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
4105 bool IsVarArg,
4107 const SmallVectorImpl<SDValue> &OutVals,
4108 const SDLoc &DL, SelectionDAG &DAG) const {
4109 // CCValAssign - represent the assignment of
4110 // the return value to a location
4113
4114 // CCState - Info about the registers and stack slot.
4115 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, *DAG.getContext());
4116
4117 // Analyze return values.
4118 CCInfo.AnalyzeReturn(Outs, RetCC_Mips);
4119
4120 SDValue Glue;
4121 SmallVector<SDValue, 4> RetOps(1, Chain);
4122
4123 // Copy the result values into the output registers.
4124 for (unsigned i = 0; i != RVLocs.size(); ++i) {
4125 SDValue Val = OutVals[i];
4126 CCValAssign &VA = RVLocs[i];
4127 assert(VA.isRegLoc() && "Can only return in registers!");
4128 bool UseUpperBits = false;
4129
4130 switch (VA.getLocInfo()) {
4131 default:
4132 llvm_unreachable("Unknown loc info!");
4133 case CCValAssign::Full:
4134 break;
4135 case CCValAssign::BCvt:
4136 Val = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Val);
4137 break;
4139 UseUpperBits = true;
4140 [[fallthrough]];
4141 case CCValAssign::AExt:
4142 Val = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Val);
4143 break;
4145 UseUpperBits = true;
4146 [[fallthrough]];
4147 case CCValAssign::ZExt:
4148 Val = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Val);
4149 break;
4151 UseUpperBits = true;
4152 [[fallthrough]];
4153 case CCValAssign::SExt:
4154 Val = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Val);
4155 break;
4156 }
4157
4158 if (UseUpperBits) {
4159 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits();
4160 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits();
4161 Val = DAG.getNode(
4162 ISD::SHL, DL, VA.getLocVT(), Val,
4163 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT()));
4164 }
4165
4166 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Glue);
4167
4168 // Guarantee that all emitted copies are stuck together with flags.
4169 Glue = Chain.getValue(1);
4170 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
4171 }
4172
4173 // The mips ABIs for returning structs by value requires that we copy
4174 // the sret argument into $v0 for the return. We saved the argument into
4175 // a virtual register in the entry block, so now we copy the value out
4176 // and into $v0.
4177 if (MF.getFunction().hasStructRetAttr()) {
4178 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4179 unsigned Reg = MipsFI->getSRetReturnReg();
4180
4181 if (!Reg)
4182 llvm_unreachable("sret virtual register not created in the entry block");
4183 SDValue Val =
4184 DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy(DAG.getDataLayout()));
4185 unsigned V0 = ABI.getReturnRegPtr(0);
4186
4187 Chain = DAG.getCopyToReg(Chain, DL, V0, Val, Glue);
4188 Glue = Chain.getValue(1);
4189 RetOps.push_back(DAG.getRegister(V0, getPointerTy(DAG.getDataLayout())));
4190 }
4191
4192 RetOps[0] = Chain; // Update chain.
4193
4194 // Add the glue if we have it.
4195 if (Glue.getNode())
4196 RetOps.push_back(Glue);
4197
4198 // ISRs must use "eret".
4199 if (DAG.getMachineFunction().getFunction().hasFnAttribute("interrupt"))
4200 return LowerInterruptReturn(RetOps, DL, DAG);
4201
4202 // Standard return on Mips is a "jr $ra"
4203 return DAG.getNode(MipsISD::Ret, DL, MVT::Other, RetOps);
4204}
4205
4206//===----------------------------------------------------------------------===//
4207// Mips Inline Assembly Support
4208//===----------------------------------------------------------------------===//
4209
4210/// getConstraintType - Given a constraint letter, return the type of
4211/// constraint it is for this target.
4213MipsTargetLowering::getConstraintType(StringRef Constraint) const {
4214 // Mips specific constraints
4215 // GCC config/mips/constraints.md
4216 //
4217 // 'd' : An address register. Equivalent to r
4218 // unless generating MIPS16 code.
4219 // 'y' : Equivalent to r; retained for
4220 // backwards compatibility.
4221 // 'c' : A register suitable for use in an indirect
4222 // jump. This will always be $25 for -mabicalls.
4223 // 'l' : The lo register. 1 word storage.
4224 // 'x' : The hilo register pair. Double word storage.
4225 if (Constraint.size() == 1) {
4226 switch (Constraint[0]) {
4227 default : break;
4228 case 'd':
4229 case 'y':
4230 case 'f':
4231 case 'c':
4232 case 'l':
4233 case 'x':
4234 return C_RegisterClass;
4235 case 'R':
4236 return C_Memory;
4237 }
4238 }
4239
4240 if (Constraint == "ZC")
4241 return C_Memory;
4242
4243 return TargetLowering::getConstraintType(Constraint);
4244}
4245
4246/// Examine constraint type and operand type and determine a weight value.
4247/// This object must already have been set up with the operand type
4248/// and the current alternative constraint selected.
4250MipsTargetLowering::getSingleConstraintMatchWeight(
4251 AsmOperandInfo &info, const char *constraint) const {
4253 Value *CallOperandVal = info.CallOperandVal;
4254 // If we don't have a value, we can't do a match,
4255 // but allow it at the lowest weight.
4256 if (!CallOperandVal)
4257 return CW_Default;
4258 Type *type = CallOperandVal->getType();
4259 // Look at the constraint type.
4260 switch (*constraint) {
4261 default:
4263 break;
4264 case 'd':
4265 case 'y':
4266 if (type->isIntegerTy())
4268 break;
4269 case 'f': // FPU or MSA register
4270 if (Subtarget.hasMSA() && type->isVectorTy() &&
4271 type->getPrimitiveSizeInBits().getFixedValue() == 128)
4273 else if (type->isFloatTy())
4275 break;
4276 case 'c': // $25 for indirect jumps
4277 case 'l': // lo register
4278 case 'x': // hilo register pair
4279 if (type->isIntegerTy())
4281 break;
4282 case 'I': // signed 16 bit immediate
4283 case 'J': // integer zero
4284 case 'K': // unsigned 16 bit immediate
4285 case 'L': // signed 32 bit immediate where lower 16 bits are 0
4286 case 'N': // immediate in the range of -65535 to -1 (inclusive)
4287 case 'O': // signed 15 bit immediate (+- 16383)
4288 case 'P': // immediate in the range of 65535 to 1 (inclusive)
4289 if (isa<ConstantInt>(CallOperandVal))
4291 break;
4292 case 'R':
4293 weight = CW_Memory;
4294 break;
4295 }
4296 return weight;
4297}
4298
4299/// This is a helper function to parse a physical register string and split it
4300/// into non-numeric and numeric parts (Prefix and Reg). The first boolean flag
4301/// that is returned indicates whether parsing was successful. The second flag
4302/// is true if the numeric part exists.
4303static std::pair<bool, bool> parsePhysicalReg(StringRef C, StringRef &Prefix,
4304 unsigned long long &Reg) {
4305 if (C.front() != '{' || C.back() != '}')
4306 return std::make_pair(false, false);
4307
4308 // Search for the first numeric character.
4309 StringRef::const_iterator I, B = C.begin() + 1, E = C.end() - 1;
4310 I = std::find_if(B, E, isdigit);
4311
4312 Prefix = StringRef(B, I - B);
4313
4314 // The second flag is set to false if no numeric characters were found.
4315 if (I == E)
4316 return std::make_pair(true, false);
4317
4318 // Parse the numeric characters.
4319 return std::make_pair(!getAsUnsignedInteger(StringRef(I, E - I), 10, Reg),
4320 true);
4321}
4322
4324 ISD::NodeType) const {
4325 bool Cond = !Subtarget.isABI_O32() && VT.getSizeInBits() == 32;
4326 EVT MinVT = getRegisterType(Context, Cond ? MVT::i64 : MVT::i32);
4327 return VT.bitsLT(MinVT) ? MinVT : VT;
4328}
4329
4330std::pair<unsigned, const TargetRegisterClass *> MipsTargetLowering::
4331parseRegForInlineAsmConstraint(StringRef C, MVT VT) const {
4332 const TargetRegisterInfo *TRI =
4333 Subtarget.getRegisterInfo();
4334 const TargetRegisterClass *RC;
4335 StringRef Prefix;
4336 unsigned long long Reg;
4337
4338 std::pair<bool, bool> R = parsePhysicalReg(C, Prefix, Reg);
4339
4340 if (!R.first)
4341 return std::make_pair(0U, nullptr);
4342
4343 for (unsigned RegClassID : {Mips::HI32RegClassID, Mips::LO32RegClassID}) {
4345 Prefix, *TRI, RegClassID, Mips::RegAliasName)) {
4346 // No numeric characters follow a hi/lo register name.
4347 if (R.second)
4348 return std::make_pair(0U, nullptr);
4349 return std::make_pair(NamedReg.id(), TRI->getRegClass(RegClassID));
4350 }
4351 }
4352
4353 if (Prefix.starts_with("$msa")) {
4354 // Parse $msa(ir|csr|access|save|modify|request|map|unmap)
4355
4356 // No numeric characters follow the name.
4357 if (R.second)
4358 return std::make_pair(0U, nullptr);
4359
4360 RC = TRI->getRegClass(Mips::MSACtrlRegClassID);
4362 Prefix.drop_front(), *TRI, Mips::MSACtrlRegClassID, Mips::RegAliasName);
4363 if (!Reg)
4364 return std::make_pair(0U, nullptr);
4365
4366 return std::make_pair(Reg, RC);
4367 }
4368
4369 if (!R.second)
4370 return std::make_pair(0U, nullptr);
4371
4372 if (Prefix == "$f") { // Parse $f0-$f31.
4373 // If the targets is single float only, always select 32-bit registers,
4374 // otherwise if the size of FP registers is 64-bit or Reg is an even number,
4375 // select the 64-bit register class. Otherwise, select the 32-bit register
4376 // class.
4377 if (VT == MVT::Other) {
4378 if (Subtarget.isSingleFloat())
4379 VT = MVT::f32;
4380 else
4381 VT = (Subtarget.isFP64bit() || !(Reg % 2)) ? MVT::f64 : MVT::f32;
4382 }
4383
4384 RC = getRegClassFor(VT);
4385
4386 if (RC == &Mips::AFGR64RegClass) {
4387 assert(Reg % 2 == 0);
4388 Reg >>= 1;
4389 }
4390 } else if (Prefix == "$fcc") // Parse $fcc0-$fcc7.
4391 RC = TRI->getRegClass(Mips::FCCRegClassID);
4392 else if (Prefix == "$w") { // Parse $w0-$w31.
4393 RC = getRegClassFor((VT == MVT::Other) ? MVT::v16i8 : VT);
4394 } else { // Parse $0-$31.
4395 assert(Prefix == "$");
4396 RC = getRegClassFor((VT == MVT::Other) ? MVT::i32 : VT);
4397 }
4398
4399 assert(Reg < RC->getNumRegs());
4400 return std::make_pair(*(RC->begin() + Reg), RC);
4401}
4402
4403/// Given a register class constraint, like 'r', if this corresponds directly
4404/// to an LLVM register class, return a register of 0 and the register class
4405/// pointer.
4406std::pair<unsigned, const TargetRegisterClass *>
4407MipsTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
4408 StringRef Constraint,
4409 MVT VT) const {
4410 if (Constraint.size() == 1) {
4411 switch (Constraint[0]) {
4412 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
4413 case 'y': // Same as 'r'. Exists for compatibility.
4414 case 'r':
4415 if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
4416 VT == MVT::i1) ||
4417 (VT == MVT::f32 && Subtarget.useSoftFloat())) {
4418 if (Subtarget.inMips16Mode())
4419 return std::make_pair(0U, &Mips::CPU16RegsRegClass);
4420 return std::make_pair(0U, &Mips::GPR32RegClass);
4421 }
4422 if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat()) ||
4423 (VT == MVT::f64 && Subtarget.isSingleFloat())) &&
4424 !Subtarget.isGP64bit())
4425 return std::make_pair(0U, &Mips::GPR32RegClass);
4426 if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat()) ||
4427 (VT == MVT::f64 && Subtarget.isSingleFloat())) &&
4428 Subtarget.isGP64bit())
4429 return std::make_pair(0U, &Mips::GPR64RegClass);
4430 // This will generate an error message
4431 return std::make_pair(0U, nullptr);
4432 case 'f': // FPU or MSA register
4433 if (VT == MVT::v16i8)
4434 return std::make_pair(0U, &Mips::MSA128BRegClass);
4435 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
4436 return std::make_pair(0U, &Mips::MSA128HRegClass);
4437 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
4438 return std::make_pair(0U, &Mips::MSA128WRegClass);
4439 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
4440 return std::make_pair(0U, &Mips::MSA128DRegClass);
4441 else if (VT == MVT::f32)
4442 return std::make_pair(0U, &Mips::FGR32RegClass);
4443 else if ((VT == MVT::f64) && (!Subtarget.isSingleFloat())) {
4444 if (Subtarget.isFP64bit())
4445 return std::make_pair(0U, &Mips::FGR64RegClass);
4446 return std::make_pair(0U, &Mips::AFGR64RegClass);
4447 }
4448 break;
4449 case 'c': // register suitable for indirect jump
4450 if (VT == MVT::i32)
4451 return std::make_pair(ABI.getTempReg(9, false).id(),
4452 &Mips::GPR32RegClass);
4453 if (VT == MVT::i64)
4454 return std::make_pair(ABI.getTempReg(9, true).id(),
4455 &Mips::GPR64RegClass);
4456 // This will generate an error message
4457 return std::make_pair(0U, nullptr);
4458 case 'l': // use the `lo` register to store values
4459 // that are no bigger than a word
4460 if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8)
4461 return std::make_pair((unsigned)Mips::LO0, &Mips::LO32RegClass);
4462 return std::make_pair((unsigned)Mips::LO0_64, &Mips::LO64RegClass);
4463 case 'x': // use the concatenated `hi` and `lo` registers
4464 // to store doubleword values
4465 // Fixme: Not triggering the use of both hi and low
4466 // This will generate an error message
4467 return std::make_pair(0U, nullptr);
4468 }
4469 }
4470
4471 if (!Constraint.empty()) {
4472 std::pair<unsigned, const TargetRegisterClass *> R;
4473 R = parseRegForInlineAsmConstraint(Constraint, VT);
4474
4475 if (R.second)
4476 return R;
4477 }
4478
4479 return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
4480}
4481
4482/// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
4483/// vector. If it is invalid, don't add anything to Ops.
4484void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
4485 StringRef Constraint,
4486 std::vector<SDValue> &Ops,
4487 SelectionDAG &DAG) const {
4488 SDLoc DL(Op);
4490
4491 // Only support length 1 constraints for now.
4492 if (Constraint.size() > 1)
4493 return;
4494
4495 char ConstraintLetter = Constraint[0];
4496 switch (ConstraintLetter) {
4497 default: break; // This will fall through to the generic implementation
4498 case 'I': // Signed 16 bit constant
4499 // If this fails, the parent routine will give an error
4500 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4501 EVT Type = Op.getValueType();
4502 int64_t Val = C->getSExtValue();
4503 if (isInt<16>(Val)) {
4505 break;
4506 }
4507 }
4508 return;
4509 case 'J': // integer zero
4510 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4511 EVT Type = Op.getValueType();
4512 int64_t Val = C->getZExtValue();
4513 if (Val == 0) {
4514 Result = DAG.getTargetConstant(0, DL, Type);
4515 break;
4516 }
4517 }
4518 return;
4519 case 'K': // unsigned 16 bit immediate
4520 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4521 EVT Type = Op.getValueType();
4522 uint64_t Val = C->getZExtValue();
4523 if (isUInt<16>(Val)) {
4524 Result = DAG.getTargetConstant(Val, DL, Type);
4525 break;
4526 }
4527 }
4528 return;
4529 case 'L': // signed 32 bit immediate where lower 16 bits are 0
4530 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4531 EVT Type = Op.getValueType();
4532 int64_t Val = C->getSExtValue();
4533 if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){
4535 break;
4536 }
4537 }
4538 return;
4539 case 'N': // immediate in the range of -65535 to -1 (inclusive)
4540 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4541 EVT Type = Op.getValueType();
4542 int64_t Val = C->getSExtValue();
4543 if ((Val >= -65535) && (Val <= -1)) {
4545 break;
4546 }
4547 }
4548 return;
4549 case 'O': // signed 15 bit immediate
4550 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4551 EVT Type = Op.getValueType();
4552 int64_t Val = C->getSExtValue();
4553 if ((isInt<15>(Val))) {
4555 break;
4556 }
4557 }
4558 return;
4559 case 'P': // immediate in the range of 1 to 65535 (inclusive)
4560 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
4561 EVT Type = Op.getValueType();
4562 int64_t Val = C->getSExtValue();
4563 if ((Val <= 65535) && (Val >= 1)) {
4564 Result = DAG.getTargetConstant(Val, DL, Type);
4565 break;
4566 }
4567 }
4568 return;
4569 }
4570
4571 if (Result.getNode()) {
4572 Ops.push_back(Result);
4573 return;
4574 }
4575
4577}
4578
4579bool MipsTargetLowering::isLegalAddressingMode(const DataLayout &DL,
4580 const AddrMode &AM, Type *Ty,
4581 unsigned AS,
4582 Instruction *I) const {
4583 // No global is ever allowed as a base.
4584 if (AM.BaseGV)
4585 return false;
4586
4587 switch (AM.Scale) {
4588 case 0: // "r+i" or just "i", depending on HasBaseReg.
4589 break;
4590 case 1:
4591 if (!AM.HasBaseReg) // allow "r+i".
4592 break;
4593 return false; // disallow "r+r" or "r+r+i".
4594 default:
4595 return false;
4596 }
4597
4598 return true;
4599}
4600
4601bool
4602MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
4603 // The Mips target isn't yet aware of offsets.
4604 return false;
4605}
4606
4607EVT MipsTargetLowering::getOptimalMemOpType(
4608 LLVMContext &Context, const MemOp &Op,
4609 const AttributeList &FuncAttributes) const {
4610 if (Subtarget.hasMips64())
4611 return MVT::i64;
4612
4613 return MVT::i32;
4614}
4615
4617MipsTargetLowering::getFPImmAction(const APFloat &Imm, EVT VT,
4618 bool ForCodeSize) const {
4619 if (VT != MVT::f32 && VT != MVT::f64)
4621 if (Imm.isNegZero())
4624}
4625
4626bool MipsTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
4627 return isInt<16>(Imm);
4628}
4629
4630bool MipsTargetLowering::isLegalAddImmediate(int64_t Imm) const {
4631 return isInt<16>(Imm);
4632}
4633
4635 if (!isPositionIndependent())
4637 if (ABI.IsN64())
4640}
4641
4642SDValue MipsTargetLowering::getPICJumpTableRelocBase(SDValue Table,
4643 SelectionDAG &DAG) const {
4644 if (!isPositionIndependent())
4645 return Table;
4647}
4648
4650 return Subtarget.useSoftFloat();
4651}
4652
4653void MipsTargetLowering::copyByValRegs(
4654 SDValue Chain, const SDLoc &DL, std::vector<SDValue> &OutChains,
4655 SelectionDAG &DAG, const ISD::ArgFlagsTy &Flags,
4656 SmallVectorImpl<SDValue> &InVals, const Argument *FuncArg,
4657 unsigned FirstReg, unsigned LastReg, const CCValAssign &VA,
4658 MipsCCState &State) const {
4660 MachineFrameInfo &MFI = MF.getFrameInfo();
4661 unsigned GPRSizeInBytes = Subtarget.getGPRSizeInBytes();
4662 unsigned NumRegs = LastReg - FirstReg;
4663 unsigned RegAreaSize = NumRegs * GPRSizeInBytes;
4664 unsigned FrameObjSize = std::max(Flags.getByValSize(), RegAreaSize);
4665 int FrameObjOffset;
4666 ArrayRef<MCPhysReg> ByValArgRegs = ABI.GetByValArgRegs();
4667
4668 if (RegAreaSize)
4669 FrameObjOffset =
4670 (int)ABI.GetCalleeAllocdArgSizeInBytes(State.getCallingConv()) -
4671 (int)((ByValArgRegs.size() - FirstReg) * GPRSizeInBytes);
4672 else
4673 FrameObjOffset = VA.getLocMemOffset();
4674
4675 // Create frame object.
4676 EVT PtrTy = getPointerTy(DAG.getDataLayout());
4677 // Make the fixed object stored to mutable so that the load instructions
4678 // referencing it have their memory dependencies added.
4679 // Set the frame object as isAliased which clears the underlying objects
4680 // vector in ScheduleDAGInstrs::buildSchedGraph() resulting in addition of all
4681 // stores as dependencies for loads referencing this fixed object.
4682 int FI = MFI.CreateFixedObject(FrameObjSize, FrameObjOffset, false, true);
4683 SDValue FIN = DAG.getFrameIndex(FI, PtrTy);
4684 InVals.push_back(FIN);
4685
4686 if (!NumRegs)
4687 return;
4688
4689 // Copy arg registers.
4690 MVT RegTy = MVT::getIntegerVT(GPRSizeInBytes * 8);
4691 const TargetRegisterClass *RC = getRegClassFor(RegTy);
4692
4693 for (unsigned I = 0; I < NumRegs; ++I) {
4694 unsigned ArgReg = ByValArgRegs[FirstReg + I];
4695 unsigned VReg = addLiveIn(MF, ArgReg, RC);
4696 unsigned Offset = I * GPRSizeInBytes;
4697 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN,
4698 DAG.getConstant(Offset, DL, PtrTy));
4699 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy),
4700 StorePtr, MachinePointerInfo(FuncArg, Offset));
4701 OutChains.push_back(Store);
4702 }
4703}
4704
4705// Copy byVal arg to registers and stack.
4706void MipsTargetLowering::passByValArg(
4707 SDValue Chain, const SDLoc &DL,
4708 std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
4709 SmallVectorImpl<SDValue> &MemOpChains, SDValue StackPtr,
4710 MachineFrameInfo &MFI, SelectionDAG &DAG, SDValue Arg, unsigned FirstReg,
4711 unsigned LastReg, const ISD::ArgFlagsTy &Flags, bool isLittle,
4712 const CCValAssign &VA) const {
4713 unsigned ByValSizeInBytes = Flags.getByValSize();
4714 unsigned OffsetInBytes = 0; // From beginning of struct
4715 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4717 std::min(Flags.getNonZeroByValAlign(), Align(RegSizeInBytes));
4718 EVT PtrTy = getPointerTy(DAG.getDataLayout()),
4719 RegTy = MVT::getIntegerVT(RegSizeInBytes * 8);
4720 unsigned NumRegs = LastReg - FirstReg;
4721
4722 if (NumRegs) {
4723 ArrayRef<MCPhysReg> ArgRegs = ABI.GetByValArgRegs();
4724 bool LeftoverBytes = (NumRegs * RegSizeInBytes > ByValSizeInBytes);
4725 unsigned I = 0;
4726
4727 // Copy words to registers.
4728 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) {
4729 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4730 DAG.getConstant(OffsetInBytes, DL, PtrTy));
4731 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr,
4732 MachinePointerInfo(), Alignment);
4733 MemOpChains.push_back(LoadVal.getValue(1));
4734 unsigned ArgReg = ArgRegs[FirstReg + I];
4735 RegsToPass.push_back(std::make_pair(ArgReg, LoadVal));
4736 }
4737
4738 // Return if the struct has been fully copied.
4739 if (ByValSizeInBytes == OffsetInBytes)
4740 return;
4741
4742 // Copy the remainder of the byval argument with sub-word loads and shifts.
4743 if (LeftoverBytes) {
4744 SDValue Val;
4745
4746 for (unsigned LoadSizeInBytes = RegSizeInBytes / 2, TotalBytesLoaded = 0;
4747 OffsetInBytes < ByValSizeInBytes; LoadSizeInBytes /= 2) {
4748 unsigned RemainingSizeInBytes = ByValSizeInBytes - OffsetInBytes;
4749
4750 if (RemainingSizeInBytes < LoadSizeInBytes)
4751 continue;
4752
4753 // Load subword.
4754 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4755 DAG.getConstant(OffsetInBytes, DL,
4756 PtrTy));
4757 SDValue LoadVal = DAG.getExtLoad(
4758 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(),
4759 MVT::getIntegerVT(LoadSizeInBytes * 8), Alignment);
4760 MemOpChains.push_back(LoadVal.getValue(1));
4761
4762 // Shift the loaded value.
4763 unsigned Shamt;
4764
4765 if (isLittle)
4766 Shamt = TotalBytesLoaded * 8;
4767 else
4768 Shamt = (RegSizeInBytes - (TotalBytesLoaded + LoadSizeInBytes)) * 8;
4769
4770 SDValue Shift = DAG.getNode(ISD::SHL, DL, RegTy, LoadVal,
4771 DAG.getConstant(Shamt, DL, MVT::i32));
4772
4773 if (Val.getNode())
4774 Val = DAG.getNode(ISD::OR, DL, RegTy, Val, Shift);
4775 else
4776 Val = Shift;
4777
4778 OffsetInBytes += LoadSizeInBytes;
4779 TotalBytesLoaded += LoadSizeInBytes;
4780 Alignment = std::min(Alignment, Align(LoadSizeInBytes));
4781 }
4782
4783 unsigned ArgReg = ArgRegs[FirstReg + I];
4784 RegsToPass.push_back(std::make_pair(ArgReg, Val));
4785 return;
4786 }
4787 }
4788
4789 // Copy remainder of byval arg to it with memcpy.
4790 unsigned MemCpySize = ByValSizeInBytes - OffsetInBytes;
4791 SDValue Src = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
4792 DAG.getConstant(OffsetInBytes, DL, PtrTy));
4793 SDValue Dst = DAG.getNode(ISD::ADD, DL, PtrTy, StackPtr,
4795 Chain = DAG.getMemcpy(
4796 Chain, DL, Dst, Src, DAG.getConstant(MemCpySize, DL, PtrTy), Alignment,
4797 Alignment, /*isVolatile=*/false, /*AlwaysInline=*/false,
4798 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(), MachinePointerInfo());
4799 MemOpChains.push_back(Chain);
4800}
4801
4802void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains,
4803 SDValue Chain, const SDLoc &DL,
4804 SelectionDAG &DAG,
4805 CCState &State) const {
4806 ArrayRef<MCPhysReg> ArgRegs = ABI.getVarArgRegs(Subtarget.isGP64bit());
4807 unsigned Idx = State.getFirstUnallocated(ArgRegs);
4808 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4809 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8);
4810 const TargetRegisterClass *RC = getRegClassFor(RegTy);
4812 MachineFrameInfo &MFI = MF.getFrameInfo();
4813 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
4814
4815 // Offset of the first variable argument from stack pointer.
4816 int VaArgOffset;
4817
4818 if (ArgRegs.size() == Idx)
4819 VaArgOffset = alignTo(State.getStackSize(), RegSizeInBytes);
4820 else {
4821 VaArgOffset =
4822 (int)ABI.GetCalleeAllocdArgSizeInBytes(State.getCallingConv()) -
4823 (int)(RegSizeInBytes * (ArgRegs.size() - Idx));
4824 }
4825
4826 // Record the frame index of the first variable argument
4827 // which is a value necessary to VASTART.
4828 int FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
4829 MipsFI->setVarArgsFrameIndex(FI);
4830
4831 // Copy the integer registers that have not been used for argument passing
4832 // to the argument register save area. For O32, the save area is allocated
4833 // in the caller's stack frame, while for N32/64, it is allocated in the
4834 // callee's stack frame.
4835 for (unsigned I = Idx; I < ArgRegs.size();
4836 ++I, VaArgOffset += RegSizeInBytes) {
4837 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC);
4838 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy);
4839 FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
4840 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
4841 SDValue Store =
4842 DAG.getStore(Chain, DL, ArgValue, PtrOff, MachinePointerInfo());
4843 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue(
4844 (Value *)nullptr);
4845 OutChains.push_back(Store);
4846 }
4847}
4848
4850 Align Alignment) const {
4851 const TargetFrameLowering *TFL = Subtarget.getFrameLowering();
4852
4853 assert(Size && "Byval argument's size shouldn't be 0.");
4854
4855 Alignment = std::min(Alignment, TFL->getStackAlign());
4856
4857 unsigned FirstReg = 0;
4858 unsigned NumRegs = 0;
4859
4860 if (State->getCallingConv() != CallingConv::Fast) {
4861 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
4862 ArrayRef<MCPhysReg> IntArgRegs = ABI.GetByValArgRegs();
4863 // FIXME: The O32 case actually describes no shadow registers.
4864 const MCPhysReg *ShadowRegs =
4865 ABI.IsO32() ? IntArgRegs.data() : Mips64DPRegs;
4866
4867 // We used to check the size as well but we can't do that anymore since
4868 // CCState::HandleByVal() rounds up the size after calling this function.
4869 assert(
4870 Alignment >= Align(RegSizeInBytes) &&
4871 "Byval argument's alignment should be a multiple of RegSizeInBytes.");
4872
4873 FirstReg = State->getFirstUnallocated(IntArgRegs);
4874
4875 // If Alignment > RegSizeInBytes, the first arg register must be even.
4876 // FIXME: This condition happens to do the right thing but it's not the
4877 // right way to test it. We want to check that the stack frame offset
4878 // of the register is aligned.
4879 if ((Alignment > RegSizeInBytes) && (FirstReg % 2)) {
4880 State->AllocateReg(IntArgRegs[FirstReg], ShadowRegs[FirstReg]);
4881 ++FirstReg;
4882 }
4883
4884 // Mark the registers allocated.
4885 Size = alignTo(Size, RegSizeInBytes);
4886 for (unsigned I = FirstReg; Size > 0 && (I < IntArgRegs.size());
4887 Size -= RegSizeInBytes, ++I, ++NumRegs)
4888 State->AllocateReg(IntArgRegs[I], ShadowRegs[I]);
4889 }
4890
4891 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs);
4892}
4893
4894MachineBasicBlock *MipsTargetLowering::emitPseudoSELECT(MachineInstr &MI,
4896 bool isFPCmp,
4897 unsigned Opc) const {
4898 assert(!(Subtarget.hasMips4() || Subtarget.hasMips32()) &&
4899 "Subtarget already supports SELECT nodes with the use of"
4900 "conditional-move instructions.");
4901
4902 const TargetInstrInfo *TII =
4903 Subtarget.getInstrInfo();
4904 DebugLoc DL = MI.getDebugLoc();
4905
4906 // To "insert" a SELECT instruction, we actually have to insert the
4907 // diamond control-flow pattern. The incoming instruction knows the
4908 // destination vreg to set, the condition code register to branch on, the
4909 // true/false values to select between, and a branch opcode to use.
4910 const BasicBlock *LLVM_BB = BB->getBasicBlock();
4912
4913 // thisMBB:
4914 // ...
4915 // TrueVal = ...
4916 // setcc r1, r2, r3
4917 // bNE r1, r0, copy1MBB
4918 // fallthrough --> copy0MBB
4919 MachineBasicBlock *thisMBB = BB;
4920 MachineFunction *F = BB->getParent();
4921 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
4922 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
4923 F->insert(It, copy0MBB);
4924 F->insert(It, sinkMBB);
4925
4926 // Transfer the remainder of BB and its successor edges to sinkMBB.
4927 sinkMBB->splice(sinkMBB->begin(), BB,
4928 std::next(MachineBasicBlock::iterator(MI)), BB->end());
4930
4931 // Next, add the true and fallthrough blocks as its successors.
4932 BB->addSuccessor(copy0MBB);
4933 BB->addSuccessor(sinkMBB);
4934
4935 if (isFPCmp) {
4936 // bc1[tf] cc, sinkMBB
4937 BuildMI(BB, DL, TII->get(Opc))
4938 .addReg(MI.getOperand(1).getReg())
4939 .addMBB(sinkMBB);
4940 } else {
4941 // bne rs, $0, sinkMBB
4942 BuildMI(BB, DL, TII->get(Opc))
4943 .addReg(MI.getOperand(1).getReg())
4944 .addReg(Mips::R0)
4945 .addMBB(sinkMBB);
4946 }
4947
4948 // copy0MBB:
4949 // %FalseValue = ...
4950 // # fallthrough to sinkMBB
4951 BB = copy0MBB;
4952
4953 // Update machine-CFG edges
4954 BB->addSuccessor(sinkMBB);
4955
4956 // sinkMBB:
4957 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
4958 // ...
4959 BB = sinkMBB;
4960
4961 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
4962 .addReg(MI.getOperand(2).getReg())
4963 .addMBB(thisMBB)
4964 .addReg(MI.getOperand(3).getReg())
4965 .addMBB(copy0MBB);
4966
4967 MI.eraseFromParent(); // The pseudo instruction is gone now.
4968
4969 return BB;
4970}
4971
4973MipsTargetLowering::emitPseudoD_SELECT(MachineInstr &MI,
4974 MachineBasicBlock *BB) const {
4975 assert(!(Subtarget.hasMips4() || Subtarget.hasMips32()) &&
4976 "Subtarget already supports SELECT nodes with the use of"
4977 "conditional-move instructions.");
4978
4979 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
4980 DebugLoc DL = MI.getDebugLoc();
4981
4982 // D_SELECT substitutes two SELECT nodes that goes one after another and
4983 // have the same condition operand. On machines which don't have
4984 // conditional-move instruction, it reduces unnecessary branch instructions
4985 // which are result of using two diamond patterns that are result of two
4986 // SELECT pseudo instructions.
4987 const BasicBlock *LLVM_BB = BB->getBasicBlock();
4989
4990 // thisMBB:
4991 // ...
4992 // TrueVal = ...
4993 // setcc r1, r2, r3
4994 // bNE r1, r0, copy1MBB
4995 // fallthrough --> copy0MBB
4996 MachineBasicBlock *thisMBB = BB;
4997 MachineFunction *F = BB->getParent();
4998 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
4999 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
5000 F->insert(It, copy0MBB);
5001 F->insert(It, sinkMBB);
5002
5003 // Transfer the remainder of BB and its successor edges to sinkMBB.
5004 sinkMBB->splice(sinkMBB->begin(), BB,
5005 std::next(MachineBasicBlock::iterator(MI)), BB->end());
5007
5008 // Next, add the true and fallthrough blocks as its successors.
5009 BB->addSuccessor(copy0MBB);
5010 BB->addSuccessor(sinkMBB);
5011
5012 // bne rs, $0, sinkMBB
5013 BuildMI(BB, DL, TII->get(Mips::BNE))
5014 .addReg(MI.getOperand(2).getReg())
5015 .addReg(Mips::R0)
5016 .addMBB(sinkMBB);
5017
5018 // copy0MBB:
5019 // %FalseValue = ...
5020 // # fallthrough to sinkMBB
5021 BB = copy0MBB;
5022
5023 // Update machine-CFG edges
5024 BB->addSuccessor(sinkMBB);
5025
5026 // sinkMBB:
5027 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
5028 // ...
5029 BB = sinkMBB;
5030
5031 // Use two PHI nodes to select two reults
5032 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
5033 .addReg(MI.getOperand(3).getReg())
5034 .addMBB(thisMBB)
5035 .addReg(MI.getOperand(5).getReg())
5036 .addMBB(copy0MBB);
5037 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(1).getReg())
5038 .addReg(MI.getOperand(4).getReg())
5039 .addMBB(thisMBB)
5040 .addReg(MI.getOperand(6).getReg())
5041 .addMBB(copy0MBB);
5042
5043 MI.eraseFromParent(); // The pseudo instruction is gone now.
5044
5045 return BB;
5046}
5047
5050 const MachineFunction &MF) const {
5051 StringRef Name(RegName);
5052 Name.consume_front("$");
5053
5054 unsigned RegIdx;
5055 if (Name.getAsInteger(10, RegIdx)) {
5056 std::string LowerName = Name.lower();
5058 int Index =
5059 MIPS_MC::getCPURegisterIndex(LowerName, MRI, ABI.getRegAltNameIndex());
5060 if (Index < 0)
5062 Twine("Invalid register name \"" + StringRef(RegName) + "\"."));
5063 RegIdx = Index;
5064 }
5065
5066 if (RegIdx < 32) {
5068 unsigned RegClassID = Mips::GPR32RegClassID;
5069 if (VT.isValid()) {
5070 if (VT.getSizeInBits() == 64) {
5071 if (!Subtarget.isGP64bit())
5072 report_fatal_error("64-bit registers not supported on 32-bit target");
5073 RegClassID = Mips::GPR64RegClassID;
5074 } else if (VT.getSizeInBits() == 32) {
5075 RegClassID = Mips::GPR32RegClassID;
5076 } else {
5077 report_fatal_error(Twine("Invalid register \"" + StringRef(RegName) +
5078 "\" for " + Twine(VT.getSizeInBits()) +
5079 "-bit type."));
5080 }
5081 } else if (Subtarget.isGP64bit()) {
5082 RegClassID = Mips::GPR64RegClassID;
5083 }
5084 const MCRegisterClass &RC = MRI->getRegClass(RegClassID);
5085 Register Reg = RC.getRegister(RegIdx);
5086 BitVector ReservedRegs = Subtarget.getRegisterInfo()->getReservedRegs(MF);
5087 if (!ReservedRegs.test(Reg))
5088 reportFatalUsageError(Twine("Trying to obtain non-reserved register \"" +
5089 StringRef(RegName) + "\"."));
5090 return Reg;
5091 }
5092
5094 Twine("Invalid register name \"" + StringRef(RegName) + "\"."));
5095}
5096
5097MachineBasicBlock *MipsTargetLowering::emitLDR_W(MachineInstr &MI,
5098 MachineBasicBlock *BB) const {
5099 MachineFunction *MF = BB->getParent();
5101 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5102 const bool IsLittle = Subtarget.isLittle();
5103 DebugLoc DL = MI.getDebugLoc();
5104
5105 Register Dest = MI.getOperand(0).getReg();
5106 Register Address = MI.getOperand(1).getReg();
5107 unsigned Imm = MI.getOperand(2).getImm();
5108
5110
5111 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5112 // Mips release 6 can load from adress that is not naturally-aligned.
5113 Register Temp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5114 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5115 .addDef(Temp)
5116 .addUse(Address)
5117 .addImm(Imm);
5118 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Dest).addUse(Temp);
5119 } else {
5120 // Mips release 5 needs to use instructions that can load from an unaligned
5121 // memory address.
5122 Register LoadHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5123 Register LoadFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5124 Register Undef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5125 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(Undef);
5126 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5127 .addDef(LoadHalf)
5128 .addUse(Address)
5129 .addImm(Imm + (IsLittle ? 0 : 3))
5130 .addUse(Undef);
5131 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5132 .addDef(LoadFull)
5133 .addUse(Address)
5134 .addImm(Imm + (IsLittle ? 3 : 0))
5135 .addUse(LoadHalf);
5136 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Dest).addUse(LoadFull);
5137 }
5138
5139 MI.eraseFromParent();
5140 return BB;
5141}
5142
5143MachineBasicBlock *MipsTargetLowering::emitLDR_D(MachineInstr &MI,
5144 MachineBasicBlock *BB) const {
5145 MachineFunction *MF = BB->getParent();
5146 MachineRegisterInfo &MRI = MF->getRegInfo();
5147 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5148 const bool IsLittle = Subtarget.isLittle();
5149 DebugLoc DL = MI.getDebugLoc();
5150
5151 Register Dest = MI.getOperand(0).getReg();
5152 Register Address = MI.getOperand(1).getReg();
5153 unsigned Imm = MI.getOperand(2).getImm();
5154
5156
5157 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5158 // Mips release 6 can load from adress that is not naturally-aligned.
5159 if (Subtarget.isGP64bit()) {
5160 Register Temp = MRI.createVirtualRegister(&Mips::GPR64RegClass);
5161 BuildMI(*BB, I, DL, TII->get(Mips::LD))
5162 .addDef(Temp)
5163 .addUse(Address)
5164 .addImm(Imm);
5165 BuildMI(*BB, I, DL, TII->get(Mips::FILL_D)).addDef(Dest).addUse(Temp);
5166 } else {
5167 Register Wtemp = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5168 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5169 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5170 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5171 .addDef(Lo)
5172 .addUse(Address)
5173 .addImm(Imm + (IsLittle ? 0 : 4));
5174 BuildMI(*BB, I, DL, TII->get(Mips::LW))
5175 .addDef(Hi)
5176 .addUse(Address)
5177 .addImm(Imm + (IsLittle ? 4 : 0));
5178 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Wtemp).addUse(Lo);
5179 BuildMI(*BB, I, DL, TII->get(Mips::INSERT_W), Dest)
5180 .addUse(Wtemp)
5181 .addUse(Hi)
5182 .addImm(1);
5183 }
5184 } else {
5185 // Mips release 5 needs to use instructions that can load from an unaligned
5186 // memory address.
5187 Register LoHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5188 Register LoFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5189 Register LoUndef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5190 Register HiHalf = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5191 Register HiFull = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5192 Register HiUndef = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5193 Register Wtemp = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5194 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(LoUndef);
5195 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5196 .addDef(LoHalf)
5197 .addUse(Address)
5198 .addImm(Imm + (IsLittle ? 0 : 7))
5199 .addUse(LoUndef);
5200 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5201 .addDef(LoFull)
5202 .addUse(Address)
5203 .addImm(Imm + (IsLittle ? 3 : 4))
5204 .addUse(LoHalf);
5205 BuildMI(*BB, I, DL, TII->get(Mips::IMPLICIT_DEF)).addDef(HiUndef);
5206 BuildMI(*BB, I, DL, TII->get(Mips::LWR))
5207 .addDef(HiHalf)
5208 .addUse(Address)
5209 .addImm(Imm + (IsLittle ? 4 : 3))
5210 .addUse(HiUndef);
5211 BuildMI(*BB, I, DL, TII->get(Mips::LWL))
5212 .addDef(HiFull)
5213 .addUse(Address)
5214 .addImm(Imm + (IsLittle ? 7 : 0))
5215 .addUse(HiHalf);
5216 BuildMI(*BB, I, DL, TII->get(Mips::FILL_W)).addDef(Wtemp).addUse(LoFull);
5217 BuildMI(*BB, I, DL, TII->get(Mips::INSERT_W), Dest)
5218 .addUse(Wtemp)
5219 .addUse(HiFull)
5220 .addImm(1);
5221 }
5222
5223 MI.eraseFromParent();
5224 return BB;
5225}
5226
5227MachineBasicBlock *MipsTargetLowering::emitSTR_W(MachineInstr &MI,
5228 MachineBasicBlock *BB) const {
5229 MachineFunction *MF = BB->getParent();
5230 MachineRegisterInfo &MRI = MF->getRegInfo();
5231 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5232 const bool IsLittle = Subtarget.isLittle();
5233 DebugLoc DL = MI.getDebugLoc();
5234
5235 Register StoreVal = MI.getOperand(0).getReg();
5236 Register Address = MI.getOperand(1).getReg();
5237 unsigned Imm = MI.getOperand(2).getImm();
5238
5240
5241 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5242 // Mips release 6 can store to adress that is not naturally-aligned.
5243 Register BitcastW = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5244 Register Tmp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5245 BuildMI(*BB, I, DL, TII->get(Mips::COPY)).addDef(BitcastW).addUse(StoreVal);
5246 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5247 .addDef(Tmp)
5248 .addUse(BitcastW)
5249 .addImm(0);
5250 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5251 .addUse(Tmp)
5252 .addUse(Address)
5253 .addImm(Imm);
5254 } else {
5255 // Mips release 5 needs to use instructions that can store to an unaligned
5256 // memory address.
5257 Register Tmp = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5258 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5259 .addDef(Tmp)
5260 .addUse(StoreVal)
5261 .addImm(0);
5262 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5263 .addUse(Tmp)
5264 .addUse(Address)
5265 .addImm(Imm + (IsLittle ? 0 : 3));
5266 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5267 .addUse(Tmp)
5268 .addUse(Address)
5269 .addImm(Imm + (IsLittle ? 3 : 0));
5270 }
5271
5272 MI.eraseFromParent();
5273
5274 return BB;
5275}
5276
5277MachineBasicBlock *MipsTargetLowering::emitSTR_D(MachineInstr &MI,
5278 MachineBasicBlock *BB) const {
5279 MachineFunction *MF = BB->getParent();
5280 MachineRegisterInfo &MRI = MF->getRegInfo();
5281 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
5282 const bool IsLittle = Subtarget.isLittle();
5283 DebugLoc DL = MI.getDebugLoc();
5284
5285 Register StoreVal = MI.getOperand(0).getReg();
5286 Register Address = MI.getOperand(1).getReg();
5287 unsigned Imm = MI.getOperand(2).getImm();
5288
5290
5291 if (Subtarget.hasMips32r6() || Subtarget.hasMips64r6()) {
5292 // Mips release 6 can store to adress that is not naturally-aligned.
5293 if (Subtarget.isGP64bit()) {
5294 Register BitcastD = MRI.createVirtualRegister(&Mips::MSA128DRegClass);
5295 Register Lo = MRI.createVirtualRegister(&Mips::GPR64RegClass);
5296 BuildMI(*BB, I, DL, TII->get(Mips::COPY))
5297 .addDef(BitcastD)
5298 .addUse(StoreVal);
5299 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_D))
5300 .addDef(Lo)
5301 .addUse(BitcastD)
5302 .addImm(0);
5303 BuildMI(*BB, I, DL, TII->get(Mips::SD))
5304 .addUse(Lo)
5305 .addUse(Address)
5306 .addImm(Imm);
5307 } else {
5308 Register BitcastW = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5309 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5310 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5311 BuildMI(*BB, I, DL, TII->get(Mips::COPY))
5312 .addDef(BitcastW)
5313 .addUse(StoreVal);
5314 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5315 .addDef(Lo)
5316 .addUse(BitcastW)
5317 .addImm(0);
5318 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5319 .addDef(Hi)
5320 .addUse(BitcastW)
5321 .addImm(1);
5322 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5323 .addUse(Lo)
5324 .addUse(Address)
5325 .addImm(Imm + (IsLittle ? 0 : 4));
5326 BuildMI(*BB, I, DL, TII->get(Mips::SW))
5327 .addUse(Hi)
5328 .addUse(Address)
5329 .addImm(Imm + (IsLittle ? 4 : 0));
5330 }
5331 } else {
5332 // Mips release 5 needs to use instructions that can store to an unaligned
5333 // memory address.
5334 Register Bitcast = MRI.createVirtualRegister(&Mips::MSA128WRegClass);
5335 Register Lo = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5336 Register Hi = MRI.createVirtualRegister(&Mips::GPR32RegClass);
5337 BuildMI(*BB, I, DL, TII->get(Mips::COPY)).addDef(Bitcast).addUse(StoreVal);
5338 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5339 .addDef(Lo)
5340 .addUse(Bitcast)
5341 .addImm(0);
5342 BuildMI(*BB, I, DL, TII->get(Mips::COPY_S_W))
5343 .addDef(Hi)
5344 .addUse(Bitcast)
5345 .addImm(1);
5346 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5347 .addUse(Lo)
5348 .addUse(Address)
5349 .addImm(Imm + (IsLittle ? 0 : 3));
5350 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5351 .addUse(Lo)
5352 .addUse(Address)
5353 .addImm(Imm + (IsLittle ? 3 : 0));
5354 BuildMI(*BB, I, DL, TII->get(Mips::SWR))
5355 .addUse(Hi)
5356 .addUse(Address)
5357 .addImm(Imm + (IsLittle ? 4 : 7));
5358 BuildMI(*BB, I, DL, TII->get(Mips::SWL))
5359 .addUse(Hi)
5360 .addUse(Address)
5361 .addImm(Imm + (IsLittle ? 7 : 4));
5362 }
5363
5364 MI.eraseFromParent();
5365 return BB;
5366}
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)
return SDValue()
static SDValue performANDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
const AArch64Subtarget & Subtarget
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
hexagon merge activate weight
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:479
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:483
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:410
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 inMips16Mode() const
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
ISD::CondCode getOperandCondCode(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:298
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:314
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:851
@ 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:811
@ 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:885
@ 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:876
@ 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:828
@ 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:793
@ 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:882
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:843
@ 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:920
@ 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:958
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:763
@ 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:888
@ 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:865
@ 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:881
#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:338
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
Definition ValueTypes.h:516
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
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:191
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:286
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition ValueTypes.h:366
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:374
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:175
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