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