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