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