LLVM 23.0.0git
AArch64RegisterBankInfo.cpp
Go to the documentation of this file.
1//===- AArch64RegisterBankInfo.cpp ----------------------------------------===//
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/// \file
9/// This file implements the targeting of the RegisterBankInfo class for
10/// AArch64.
11/// \todo This should be generated by TableGen.
12//===----------------------------------------------------------------------===//
13
15#include "AArch64RegisterInfo.h"
16#include "AArch64Subtarget.h"
19#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/STLExtras.h"
36#include "llvm/IR/Constants.h"
37#include "llvm/IR/IntrinsicsAArch64.h"
40#include <cassert>
41
42#define GET_TARGET_REGBANK_IMPL
43#include "AArch64GenRegisterBank.inc"
44
45// This file will be TableGen'ed at some point.
46#include "AArch64GenRegisterBankInfo.def"
47
48using namespace llvm;
49static const unsigned CustomMappingID = 1;
50
52 const TargetRegisterInfo &TRI) {
53 static llvm::once_flag InitializeRegisterBankFlag;
54
55 static auto InitializeRegisterBankOnce = [&]() {
56 // We have only one set of register banks, whatever the subtarget
57 // is. Therefore, the initialization of the RegBanks table should be
58 // done only once. Indeed the table of all register banks
59 // (AArch64::RegBanks) is unique in the compiler. At some point, it
60 // will get tablegen'ed and the whole constructor becomes empty.
61
62 const RegisterBank &RBGPR = getRegBank(AArch64::GPRRegBankID);
63 (void)RBGPR;
64 assert(&AArch64::GPRRegBank == &RBGPR &&
65 "The order in RegBanks is messed up");
66
67 const RegisterBank &RBFPR = getRegBank(AArch64::FPRRegBankID);
68 (void)RBFPR;
69 assert(&AArch64::FPRRegBank == &RBFPR &&
70 "The order in RegBanks is messed up");
71
72 const RegisterBank &RBCCR = getRegBank(AArch64::CCRegBankID);
73 (void)RBCCR;
74 assert(&AArch64::CCRegBank == &RBCCR &&
75 "The order in RegBanks is messed up");
76
77 // The GPR register bank is fully defined by all the registers in
78 // GR64all + its subclasses.
79 assert(RBGPR.covers(*TRI.getRegClass(AArch64::GPR32RegClassID)) &&
80 "Subclass not added?");
81 assert(getMaximumSize(RBGPR.getID()) == 128 &&
82 "GPRs should hold up to 128-bit");
83
84 // The FPR register bank is fully defined by all the registers in
85 // GR64all + its subclasses.
86 assert(RBFPR.covers(*TRI.getRegClass(AArch64::QQRegClassID)) &&
87 "Subclass not added?");
88 assert(RBFPR.covers(*TRI.getRegClass(AArch64::FPR64RegClassID)) &&
89 "Subclass not added?");
90 assert(getMaximumSize(RBFPR.getID()) == 512 &&
91 "FPRs should hold up to 512-bit via QQQQ sequence");
92
93 assert(RBCCR.covers(*TRI.getRegClass(AArch64::CCRRegClassID)) &&
94 "Class not added?");
95 assert(getMaximumSize(RBCCR.getID()) == 32 &&
96 "CCR should hold up to 32-bit");
97
98 // Check that the TableGen'ed like file is in sync we our expectations.
99 // First, the Idx.
102 "PartialMappingIdx's are incorrectly ordered");
106 "PartialMappingIdx's are incorrectly ordered");
107// Now, the content.
108// Check partial mapping.
109#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB) \
110 do { \
111 assert( \
112 checkPartialMap(PartialMappingIdx::Idx, ValStartIdx, ValLength, RB) && \
113 #Idx " is incorrectly initialized"); \
114 } while (false)
115
116 CHECK_PARTIALMAP(PMI_GPR32, 0, 32, RBGPR);
117 CHECK_PARTIALMAP(PMI_GPR64, 0, 64, RBGPR);
118 CHECK_PARTIALMAP(PMI_GPR128, 0, 128, RBGPR);
119 CHECK_PARTIALMAP(PMI_FPR16, 0, 16, RBFPR);
120 CHECK_PARTIALMAP(PMI_FPR32, 0, 32, RBFPR);
121 CHECK_PARTIALMAP(PMI_FPR64, 0, 64, RBFPR);
122 CHECK_PARTIALMAP(PMI_FPR128, 0, 128, RBFPR);
123 CHECK_PARTIALMAP(PMI_FPR256, 0, 256, RBFPR);
124 CHECK_PARTIALMAP(PMI_FPR512, 0, 512, RBFPR);
125
126// Check value mapping.
127#define CHECK_VALUEMAP_IMPL(RBName, Size, Offset) \
128 do { \
129 assert(checkValueMapImpl(PartialMappingIdx::PMI_##RBName##Size, \
130 PartialMappingIdx::PMI_First##RBName, Size, \
131 Offset) && \
132 #RBName #Size " " #Offset " is incorrectly initialized"); \
133 } while (false)
134
135#define CHECK_VALUEMAP(RBName, Size) CHECK_VALUEMAP_IMPL(RBName, Size, 0)
136
137 CHECK_VALUEMAP(GPR, 32);
138 CHECK_VALUEMAP(GPR, 64);
139 CHECK_VALUEMAP(GPR, 128);
140 CHECK_VALUEMAP(FPR, 16);
141 CHECK_VALUEMAP(FPR, 32);
142 CHECK_VALUEMAP(FPR, 64);
143 CHECK_VALUEMAP(FPR, 128);
144 CHECK_VALUEMAP(FPR, 256);
145 CHECK_VALUEMAP(FPR, 512);
146
147// Check the value mapping for 3-operands instructions where all the operands
148// map to the same value mapping.
149#define CHECK_VALUEMAP_3OPS(RBName, Size) \
150 do { \
151 CHECK_VALUEMAP_IMPL(RBName, Size, 0); \
152 CHECK_VALUEMAP_IMPL(RBName, Size, 1); \
153 CHECK_VALUEMAP_IMPL(RBName, Size, 2); \
154 } while (false)
155
156 CHECK_VALUEMAP_3OPS(GPR, 32);
157 CHECK_VALUEMAP_3OPS(GPR, 64);
158 CHECK_VALUEMAP_3OPS(GPR, 128);
164
165#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size) \
166 do { \
167 unsigned PartialMapDstIdx = PMI_##RBNameDst##Size - PMI_Min; \
168 unsigned PartialMapSrcIdx = PMI_##RBNameSrc##Size - PMI_Min; \
169 (void)PartialMapDstIdx; \
170 (void)PartialMapSrcIdx; \
171 const ValueMapping *Map = getCopyMapping(AArch64::RBNameDst##RegBankID, \
172 AArch64::RBNameSrc##RegBankID, \
173 TypeSize::getFixed(Size)); \
174 (void)Map; \
175 assert(Map[0].BreakDown == \
176 &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \
177 Map[0].NumBreakDowns == 1 && \
178 #RBNameDst #Size " Dst is incorrectly initialized"); \
179 assert(Map[1].BreakDown == \
180 &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \
181 Map[1].NumBreakDowns == 1 && \
182 #RBNameSrc #Size " Src is incorrectly initialized"); \
183 \
184 } while (false)
185
186 CHECK_VALUEMAP_CROSSREGCPY(GPR, GPR, 32);
188 CHECK_VALUEMAP_CROSSREGCPY(GPR, GPR, 64);
194
195#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize) \
196 do { \
197 unsigned PartialMapDstIdx = PMI_FPR##DstSize - PMI_Min; \
198 unsigned PartialMapSrcIdx = PMI_FPR##SrcSize - PMI_Min; \
199 (void)PartialMapDstIdx; \
200 (void)PartialMapSrcIdx; \
201 const ValueMapping *Map = getFPExtMapping(DstSize, SrcSize); \
202 (void)Map; \
203 assert(Map[0].BreakDown == \
204 &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \
205 Map[0].NumBreakDowns == 1 && "FPR" #DstSize \
206 " Dst is incorrectly initialized"); \
207 assert(Map[1].BreakDown == \
208 &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \
209 Map[1].NumBreakDowns == 1 && "FPR" #SrcSize \
210 " Src is incorrectly initialized"); \
211 \
212 } while (false)
213
214 CHECK_VALUEMAP_FPEXT(32, 16);
215 CHECK_VALUEMAP_FPEXT(64, 16);
216 CHECK_VALUEMAP_FPEXT(64, 32);
217 CHECK_VALUEMAP_FPEXT(128, 64);
218
219 assert(verify(TRI) && "Invalid register bank information");
220 };
221
222 llvm::call_once(InitializeRegisterBankFlag, InitializeRegisterBankOnce);
223}
224
226 const RegisterBank &B,
227 const TypeSize Size) const {
228 // What do we do with different size?
229 // copy are same size.
230 // Will introduce other hooks for different size:
231 // * extract cost.
232 // * build_sequence cost.
233
234 // Copy from (resp. to) GPR to (resp. from) FPR involves FMOV.
235 // FIXME: This should be deduced from the scheduling model.
236 if (&A == &AArch64::GPRRegBank && &B == &AArch64::FPRRegBank)
237 // FMOVXDr or FMOVWSr.
238 return 5;
239 if (&A == &AArch64::FPRRegBank && &B == &AArch64::GPRRegBank)
240 // FMOVDXr or FMOVSWr.
241 return 4;
242
244}
245
246const RegisterBank &
248 LLT Ty) const {
249 switch (RC.getID()) {
250 case AArch64::GPR64sponlyRegClassID:
251 return getRegBank(AArch64::GPRRegBankID);
252 default:
254 }
255}
256
259 const MachineInstr &MI) const {
260 const MachineFunction &MF = *MI.getParent()->getParent();
261 const TargetSubtargetInfo &STI = MF.getSubtarget();
262 const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
263 const MachineRegisterInfo &MRI = MF.getRegInfo();
264
265 switch (MI.getOpcode()) {
266 case TargetOpcode::G_OR: {
267 // 32 and 64-bit or can be mapped on either FPR or
268 // GPR for the same cost.
269 TypeSize Size = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
270 if (Size != 32 && Size != 64)
271 break;
272
273 // If the instruction has any implicit-defs or uses,
274 // do not mess with it.
275 if (MI.getNumOperands() != 3)
276 break;
277 InstructionMappings AltMappings;
278 const InstructionMapping &GPRMapping = getInstructionMapping(
279 /*ID*/ 1, /*Cost*/ 1, getValueMapping(PMI_FirstGPR, Size),
280 /*NumOperands*/ 3);
281 const InstructionMapping &FPRMapping = getInstructionMapping(
282 /*ID*/ 2, /*Cost*/ 1, getValueMapping(PMI_FirstFPR, Size),
283 /*NumOperands*/ 3);
284
285 AltMappings.push_back(&GPRMapping);
286 AltMappings.push_back(&FPRMapping);
287 return AltMappings;
288 }
289 case TargetOpcode::G_BITCAST: {
290 TypeSize Size = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
291 if (Size != 32 && Size != 64)
292 break;
293
294 // If the instruction has any implicit-defs or uses,
295 // do not mess with it.
296 if (MI.getNumOperands() != 2)
297 break;
298
299 InstructionMappings AltMappings;
300 const InstructionMapping &GPRMapping = getInstructionMapping(
301 /*ID*/ 1, /*Cost*/ 1,
302 getCopyMapping(AArch64::GPRRegBankID, AArch64::GPRRegBankID, Size),
303 /*NumOperands*/ 2);
304 const InstructionMapping &FPRMapping = getInstructionMapping(
305 /*ID*/ 2, /*Cost*/ 1,
306 getCopyMapping(AArch64::FPRRegBankID, AArch64::FPRRegBankID, Size),
307 /*NumOperands*/ 2);
308 const InstructionMapping &GPRToFPRMapping = getInstructionMapping(
309 /*ID*/ 3,
310 /*Cost*/
311 copyCost(AArch64::GPRRegBank, AArch64::FPRRegBank,
313 getCopyMapping(AArch64::FPRRegBankID, AArch64::GPRRegBankID, Size),
314 /*NumOperands*/ 2);
315 const InstructionMapping &FPRToGPRMapping = getInstructionMapping(
316 /*ID*/ 3,
317 /*Cost*/
318 copyCost(AArch64::GPRRegBank, AArch64::FPRRegBank,
320 getCopyMapping(AArch64::GPRRegBankID, AArch64::FPRRegBankID, Size),
321 /*NumOperands*/ 2);
322
323 AltMappings.push_back(&GPRMapping);
324 AltMappings.push_back(&FPRMapping);
325 AltMappings.push_back(&GPRToFPRMapping);
326 AltMappings.push_back(&FPRToGPRMapping);
327 return AltMappings;
328 }
329 case TargetOpcode::G_LOAD: {
330 TypeSize Size = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
331 if (Size != 64)
332 break;
333
334 // If the instruction has any implicit-defs or uses,
335 // do not mess with it.
336 if (MI.getNumOperands() != 2)
337 break;
338
339 InstructionMappings AltMappings;
340 const InstructionMapping &GPRMapping = getInstructionMapping(
341 /*ID*/ 1, /*Cost*/ 1,
344 // Addresses are GPR 64-bit.
346 /*NumOperands*/ 2);
347 const InstructionMapping &FPRMapping = getInstructionMapping(
348 /*ID*/ 2, /*Cost*/ 1,
351 // Addresses are GPR 64-bit.
353 /*NumOperands*/ 2);
354
355 AltMappings.push_back(&GPRMapping);
356 AltMappings.push_back(&FPRMapping);
357 return AltMappings;
358 }
359 default:
360 break;
361 }
363}
364
366 const MachineRegisterInfo &MRI,
367 const AArch64Subtarget &STI) {
368 assert(MI.getOpcode() == TargetOpcode::G_FCONSTANT);
369 Register Dst = MI.getOperand(0).getReg();
370 LLT Ty = MRI.getType(Dst);
371
372 unsigned Size = Ty.getSizeInBits();
373 if (Size != 16 && Size != 32 && Size != 64)
374 return false;
375
377 const AArch64TargetLowering *TLI = STI.getTargetLowering();
378
379 const APFloat Imm = MI.getOperand(1).getFPImm()->getValueAPF();
380 const APInt ImmBits = Imm.bitcastToAPInt();
381
382 // Check if we can encode this as a movi. Note, we only have one pattern so
383 // far for movis, hence the one check.
384 if (Size == 32) {
385 uint64_t Val = APInt::getSplat(64, ImmBits).getZExtValue();
387 return false;
388 }
389
390 // We want to use GPR when the value cannot be encoded as the immediate value
391 // of a fmov and when it will not result in a constant pool load. As
392 // AArch64TargetLowering::isFPImmLegal is used by the instruction selector
393 // to choose whether to emit a constant pool load, negating this check will
394 // ensure it would not have become a constant pool load.
395 bool OptForSize =
396 shouldOptimizeForSize(&MI.getMF()->getFunction(), nullptr, nullptr);
397 bool IsLegal = TLI->isFPImmLegal(Imm, VT, OptForSize);
398 bool IsFMov = TLI->isFPImmLegalAsFMov(Imm, VT);
399 return !IsFMov && IsLegal;
400}
401
402// Some of the instructions in applyMappingImpl attempt to anyext small values.
403// It may be that these values come from a G_CONSTANT that has been expanded to
404// 32 bits and then truncated. If this is the case, we shouldn't insert an
405// anyext and should instead make use of the G_CONSTANT directly, deleting the
406// trunc if possible.
409 const AArch64RegisterBankInfo &RBI) {
410 MachineOperand &Op = MI.getOperand(OpIdx);
411
412 Register ScalarReg = Op.getReg();
413 MachineInstr *TruncMI = MRI.getVRegDef(ScalarReg);
414 if (!TruncMI || TruncMI->getOpcode() != TargetOpcode::G_TRUNC)
415 return false;
416
417 Register TruncSrc = TruncMI->getOperand(1).getReg();
418 MachineInstr *SrcDef = MRI.getVRegDef(TruncSrc);
419 if (!SrcDef || SrcDef->getOpcode() != TargetOpcode::G_CONSTANT)
420 return false;
421
422 LLT TruncSrcTy = MRI.getType(TruncSrc);
423 if (!TruncSrcTy.isScalar() || TruncSrcTy.getSizeInBits() != 32)
424 return false;
425
426 // Avoid truncating and extending a constant, this helps with selection.
427 Op.setReg(TruncSrc);
428 MRI.setRegBank(TruncSrc, RBI.getRegBank(AArch64::GPRRegBankID));
429
430 if (MRI.use_empty(ScalarReg))
431 TruncMI->eraseFromParent();
432
433 return true;
434}
435
436void AArch64RegisterBankInfo::applyMappingImpl(
437 MachineIRBuilder &Builder, const OperandsMapper &OpdMapper) const {
438 MachineInstr &MI = OpdMapper.getMI();
439 MachineRegisterInfo &MRI = OpdMapper.getMRI();
440
441 switch (MI.getOpcode()) {
442 case TargetOpcode::G_CONSTANT: {
443 Register Dst = MI.getOperand(0).getReg();
444 [[maybe_unused]] LLT DstTy = MRI.getType(Dst);
445 assert(MRI.getRegBank(Dst) == &AArch64::GPRRegBank && DstTy.isScalar() &&
446 DstTy.getSizeInBits() < 32 &&
447 "Expected a scalar smaller than 32 bits on a GPR.");
448 Builder.setInsertPt(*MI.getParent(), std::next(MI.getIterator()));
450 Builder.buildTrunc(Dst, ExtReg);
451
452 APInt Val = MI.getOperand(1).getCImm()->getValue().zext(32);
453 LLVMContext &Ctx = Builder.getMF().getFunction().getContext();
454 MI.getOperand(1).setCImm(ConstantInt::get(Ctx, Val));
455 MI.getOperand(0).setReg(ExtReg);
456 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
457
458 return applyDefaultMapping(OpdMapper);
459 }
460 case TargetOpcode::G_FCONSTANT: {
461 Register Dst = MI.getOperand(0).getReg();
462 assert(MRI.getRegBank(Dst) == &AArch64::GPRRegBank &&
463 "Expected Dst to be on a GPR.");
464 const APFloat &Imm = MI.getOperand(1).getFPImm()->getValueAPF();
465 APInt Bits = Imm.bitcastToAPInt();
466 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
467 if (Bits.getBitWidth() < 32) {
469 Builder.buildConstant(ExtReg, Bits.zext(32));
470 Builder.buildTrunc(Dst, ExtReg);
471 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
472 } else {
473 Builder.buildConstant(Dst, Bits);
474 }
475 MI.eraseFromParent();
476 return;
477 }
478 case TargetOpcode::G_STORE: {
479 Register Dst = MI.getOperand(0).getReg();
480 LLT Ty = MRI.getType(Dst);
481
482 if (MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.isScalar() &&
483 Ty.getSizeInBits() < 32) {
484
485 if (foldTruncOfI32Constant(MI, 0, MRI, *this))
486 return applyDefaultMapping(OpdMapper);
487
488 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
489 auto Ext = Builder.buildAnyExt(LLT::integer(32), Dst);
490 MI.getOperand(0).setReg(Ext.getReg(0));
491 MRI.setRegBank(Ext.getReg(0), AArch64::GPRRegBank);
492 }
493 return applyDefaultMapping(OpdMapper);
494 }
495 case TargetOpcode::G_LOAD: {
496 Register Dst = MI.getOperand(0).getReg();
497 LLT Ty = MRI.getType(Dst);
498 if (MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.isScalar() &&
499 Ty.getSizeInBits() < 32) {
500 Builder.setInsertPt(*MI.getParent(), std::next(MI.getIterator()));
502 Builder.buildTrunc(Dst, ExtReg);
503 MI.getOperand(0).setReg(ExtReg);
504 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
505 }
506 [[fallthrough]];
507 }
508 case TargetOpcode::G_OR:
509 case TargetOpcode::G_BITCAST:
510 // Those ID must match getInstrAlternativeMappings.
511 assert((OpdMapper.getInstrMapping().getID() >= 1 &&
512 OpdMapper.getInstrMapping().getID() <= 4) &&
513 "Don't know how to handle that ID");
514 return applyDefaultMapping(OpdMapper);
515 case TargetOpcode::G_INSERT_VECTOR_ELT: {
516 if (foldTruncOfI32Constant(MI, 2, MRI, *this))
517 return applyDefaultMapping(OpdMapper);
518
519 // Extend smaller gpr operands to 32 bit.
520 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
521 LLT OperandType = MRI.getType(MI.getOperand(2).getReg());
522 auto Ext = Builder.buildAnyExt(OperandType.changeElementSize(32),
523 MI.getOperand(2).getReg());
524 MRI.setRegBank(Ext.getReg(0), getRegBank(AArch64::GPRRegBankID));
525 MI.getOperand(2).setReg(Ext.getReg(0));
526 return applyDefaultMapping(OpdMapper);
527 }
528 case AArch64::G_DUP: {
529 if (foldTruncOfI32Constant(MI, 1, MRI, *this))
530 return applyDefaultMapping(OpdMapper);
531
532 // Extend smaller gpr to 32-bits
533 assert(MRI.getType(MI.getOperand(1).getReg()).getSizeInBits() < 32 &&
534 "Expected sources smaller than 32-bits");
535 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
536
537 Register ConstReg =
538 Builder.buildAnyExt(LLT::integer(32), MI.getOperand(1).getReg())
539 .getReg(0);
540 MRI.setRegBank(ConstReg, getRegBank(AArch64::GPRRegBankID));
541 MI.getOperand(1).setReg(ConstReg);
542
543 return applyDefaultMapping(OpdMapper);
544 }
545 default:
546 llvm_unreachable("Don't know how to handle that operation");
547 }
548}
549
551AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
552 const MachineInstr &MI) const {
553 const unsigned Opc = MI.getOpcode();
554 const MachineFunction &MF = *MI.getParent()->getParent();
555 const MachineRegisterInfo &MRI = MF.getRegInfo();
556
557 unsigned NumOperands = MI.getNumOperands();
558 assert(NumOperands <= 3 &&
559 "This code is for instructions with 3 or less operands");
560
561 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
562 TypeSize Size = Ty.getSizeInBits();
564
566
567#ifndef NDEBUG
568 // Make sure all the operands are using similar size and type.
569 // Should probably be checked by the machine verifier.
570 // This code won't catch cases where the number of lanes is
571 // different between the operands.
572 // If we want to go to that level of details, it is probably
573 // best to check that the types are the same, period.
574 // Currently, we just check that the register banks are the same
575 // for each types.
576 for (unsigned Idx = 1; Idx != NumOperands; ++Idx) {
577 LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg());
578 assert(
580 RBIdx, OpTy.getSizeInBits()) ==
582 "Operand has incompatible size");
583 bool OpIsFPR = OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc);
584 (void)OpIsFPR;
585 assert(IsFPR == OpIsFPR && "Operand has incompatible type");
586 }
587#endif // End NDEBUG.
588
590 getValueMapping(RBIdx, Size), NumOperands);
591}
592
593/// \returns true if a given intrinsic only uses and defines FPRs.
594static bool isFPIntrinsic(const MachineRegisterInfo &MRI,
595 const MachineInstr &MI) {
596 // TODO: Add more intrinsics.
598 default:
599 return false;
600 case Intrinsic::aarch64_neon_uaddlv:
601 case Intrinsic::aarch64_neon_uaddv:
602 case Intrinsic::aarch64_neon_saddv:
603 case Intrinsic::aarch64_neon_umaxv:
604 case Intrinsic::aarch64_neon_smaxv:
605 case Intrinsic::aarch64_neon_uminv:
606 case Intrinsic::aarch64_neon_sminv:
607 case Intrinsic::aarch64_neon_faddv:
608 case Intrinsic::aarch64_neon_fmaxv:
609 case Intrinsic::aarch64_neon_fminv:
610 case Intrinsic::aarch64_neon_fmaxnmv:
611 case Intrinsic::aarch64_neon_fminnmv:
612 case Intrinsic::aarch64_neon_fmulx:
613 case Intrinsic::aarch64_neon_frecpe:
614 case Intrinsic::aarch64_neon_frecps:
615 case Intrinsic::aarch64_neon_frecpx:
616 case Intrinsic::aarch64_neon_frsqrte:
617 case Intrinsic::aarch64_neon_frsqrts:
618 case Intrinsic::aarch64_neon_facge:
619 case Intrinsic::aarch64_neon_facgt:
620 case Intrinsic::aarch64_neon_fabd:
621 case Intrinsic::aarch64_neon_sqrdmlah:
622 case Intrinsic::aarch64_neon_sqrdmlsh:
623 case Intrinsic::aarch64_neon_sqrdmulh:
624 case Intrinsic::aarch64_neon_suqadd:
625 case Intrinsic::aarch64_neon_usqadd:
626 case Intrinsic::aarch64_neon_uqadd:
627 case Intrinsic::aarch64_neon_sqadd:
628 case Intrinsic::aarch64_neon_uqsub:
629 case Intrinsic::aarch64_neon_sqsub:
630 case Intrinsic::aarch64_neon_sqdmulls_scalar:
631 case Intrinsic::aarch64_neon_srshl:
632 case Intrinsic::aarch64_neon_urshl:
633 case Intrinsic::aarch64_neon_sqshl:
634 case Intrinsic::aarch64_neon_uqshl:
635 case Intrinsic::aarch64_neon_sqrshl:
636 case Intrinsic::aarch64_neon_uqrshl:
637 case Intrinsic::aarch64_neon_ushl:
638 case Intrinsic::aarch64_neon_sshl:
639 case Intrinsic::aarch64_neon_sqshrn:
640 case Intrinsic::aarch64_neon_sqshrun:
641 case Intrinsic::aarch64_neon_sqrshrn:
642 case Intrinsic::aarch64_neon_sqrshrun:
643 case Intrinsic::aarch64_neon_uqshrn:
644 case Intrinsic::aarch64_neon_uqrshrn:
645 case Intrinsic::aarch64_crypto_sha1h:
646 case Intrinsic::aarch64_crypto_sha1c:
647 case Intrinsic::aarch64_crypto_sha1p:
648 case Intrinsic::aarch64_crypto_sha1m:
649 case Intrinsic::aarch64_sisd_fcvtxn:
650 case Intrinsic::aarch64_sisd_fabd:
651 return true;
652 case Intrinsic::aarch64_neon_saddlv: {
653 const LLT SrcTy = MRI.getType(MI.getOperand(2).getReg());
654 return SrcTy.getElementType().getSizeInBits() >= 16 &&
655 SrcTy.getElementCount().getFixedValue() >= 4;
656 }
657 }
658}
659
660bool AArch64RegisterBankInfo::isPHIWithFPConstraints(
661 const MachineInstr &MI, const MachineRegisterInfo &MRI,
662 const AArch64RegisterInfo &TRI, const unsigned Depth) const {
663 if (!MI.isPHI() || Depth > MaxFPRSearchDepth)
664 return false;
665
666 return any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
667 [&](const MachineInstr &UseMI) {
668 if (onlyUsesFP(UseMI, MRI, TRI, Depth + 1))
669 return true;
670 return isPHIWithFPConstraints(UseMI, MRI, TRI, Depth + 1);
671 });
672}
673
674bool AArch64RegisterBankInfo::hasFPConstraints(const MachineInstr &MI,
675 const MachineRegisterInfo &MRI,
677 unsigned Depth) const {
678 unsigned Op = MI.getOpcode();
679 if (Op == TargetOpcode::G_INTRINSIC && isFPIntrinsic(MRI, MI))
680 return true;
681
682 // Do we have an explicit floating point instruction?
684 return true;
685
686 // No. Check if we have a copy-like instruction. If we do, then we could
687 // still be fed by floating point instructions.
688 if (Op != TargetOpcode::COPY && !MI.isPHI() &&
690 return false;
691
692 // Check if we already know the register bank.
693 auto *RB = getRegBank(MI.getOperand(0).getReg(), MRI, TRI);
694 if (RB == &AArch64::FPRRegBank)
695 return true;
696 if (RB == &AArch64::GPRRegBank)
697 return false;
698
699 // We don't know anything.
700 //
701 // If we have a phi, we may be able to infer that it will be assigned a FPR
702 // based off of its inputs.
703 if (!MI.isPHI() || Depth > MaxFPRSearchDepth)
704 return false;
705
706 return any_of(MI.explicit_uses(), [&](const MachineOperand &Op) {
707 return Op.isReg() &&
708 onlyDefinesFP(*MRI.getVRegDef(Op.getReg()), MRI, TRI, Depth + 1);
709 });
710}
711
712bool AArch64RegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
713 const MachineRegisterInfo &MRI,
715 unsigned Depth) const {
716 switch (MI.getOpcode()) {
717 case TargetOpcode::G_BITCAST: {
718 Register DstReg = MI.getOperand(0).getReg();
719 return all_of(MRI.use_nodbg_instructions(DstReg),
720 [&](const MachineInstr &UseMI) {
721 return onlyUsesFP(UseMI, MRI, TRI, Depth + 1) ||
722 prefersFPUse(UseMI, MRI, TRI);
723 });
724 }
725
726 case TargetOpcode::G_FPTOSI:
727 case TargetOpcode::G_FPTOUI:
728 case TargetOpcode::G_FPTOSI_SAT:
729 case TargetOpcode::G_FPTOUI_SAT:
730 case TargetOpcode::G_FCMP:
731 case TargetOpcode::G_LROUND:
732 case TargetOpcode::G_LLROUND:
733 case AArch64::G_PMULL:
734 case AArch64::G_SLI:
735 case AArch64::G_SRI:
736 return true;
737 case TargetOpcode::G_INTRINSIC:
739 case Intrinsic::aarch64_neon_fcvtas:
740 case Intrinsic::aarch64_neon_fcvtau:
741 case Intrinsic::aarch64_neon_fcvtzs:
742 case Intrinsic::aarch64_neon_fcvtzu:
743 case Intrinsic::aarch64_neon_fcvtms:
744 case Intrinsic::aarch64_neon_fcvtmu:
745 case Intrinsic::aarch64_neon_fcvtns:
746 case Intrinsic::aarch64_neon_fcvtnu:
747 case Intrinsic::aarch64_neon_fcvtps:
748 case Intrinsic::aarch64_neon_fcvtpu:
749 return true;
750 default:
751 break;
752 }
753 break;
754 default:
755 break;
756 }
757 return hasFPConstraints(MI, MRI, TRI, Depth);
758}
759
760bool AArch64RegisterBankInfo::onlyDefinesFP(const MachineInstr &MI,
761 const MachineRegisterInfo &MRI,
763 unsigned Depth) const {
764 switch (MI.getOpcode()) {
765 case AArch64::G_DUP:
766 case AArch64::G_SADDLP:
767 case AArch64::G_UADDLP:
768 case TargetOpcode::G_SITOFP:
769 case TargetOpcode::G_UITOFP:
770 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
771 case TargetOpcode::G_INSERT_VECTOR_ELT:
772 case TargetOpcode::G_BUILD_VECTOR:
773 case TargetOpcode::G_BUILD_VECTOR_TRUNC:
774 case AArch64::G_SLI:
775 case AArch64::G_SRI:
776 return true;
777 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
779 case Intrinsic::aarch64_neon_ld1x2:
780 case Intrinsic::aarch64_neon_ld1x3:
781 case Intrinsic::aarch64_neon_ld1x4:
782 case Intrinsic::aarch64_neon_ld2:
783 case Intrinsic::aarch64_neon_ld2lane:
784 case Intrinsic::aarch64_neon_ld2r:
785 case Intrinsic::aarch64_neon_ld3:
786 case Intrinsic::aarch64_neon_ld3lane:
787 case Intrinsic::aarch64_neon_ld3r:
788 case Intrinsic::aarch64_neon_ld4:
789 case Intrinsic::aarch64_neon_ld4lane:
790 case Intrinsic::aarch64_neon_ld4r:
791 return true;
792 default:
793 break;
794 }
795 break;
796 default:
797 break;
798 }
799 return hasFPConstraints(MI, MRI, TRI, Depth);
800}
801
802bool AArch64RegisterBankInfo::prefersFPUse(const MachineInstr &MI,
803 const MachineRegisterInfo &MRI,
805 unsigned Depth) const {
806 switch (MI.getOpcode()) {
807 case TargetOpcode::G_SITOFP:
808 case TargetOpcode::G_UITOFP:
809 return MRI.getType(MI.getOperand(0).getReg()).getSizeInBits() ==
810 MRI.getType(MI.getOperand(1).getReg()).getSizeInBits();
811 }
812 return onlyDefinesFP(MI, MRI, TRI, Depth);
813}
814
815bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
816 // GMemOperation because we also want to match indexed loads.
817 auto *MemOp = cast<GMemOperation>(&MI);
818 const Value *LdVal = MemOp->getMMO().getValue();
819 if (!LdVal)
820 return false;
821
822 Type *EltTy = nullptr;
823 if (const GlobalValue *GV = dyn_cast<GlobalValue>(LdVal)) {
824 EltTy = GV->getValueType();
825 // Look at the first element of the struct to determine the type we are
826 // loading
827 while (StructType *StructEltTy = dyn_cast<StructType>(EltTy)) {
828 if (StructEltTy->getNumElements() == 0)
829 break;
830 EltTy = StructEltTy->getTypeAtIndex(0U);
831 }
832 // Look at the first element of the array to determine its type
833 if (isa<ArrayType>(EltTy))
834 EltTy = EltTy->getArrayElementType();
835 } else if (!isa<Constant>(LdVal)) {
836 // FIXME: grubbing around uses is pretty ugly, but with no more
837 // `getPointerElementType` there's not much else we can do.
838 for (const auto *LdUser : LdVal->users()) {
839 if (isa<LoadInst>(LdUser)) {
840 EltTy = LdUser->getType();
841 break;
842 }
843 if (isa<StoreInst>(LdUser) && LdUser->getOperand(1) == LdVal) {
844 EltTy = LdUser->getOperand(0)->getType();
845 break;
846 }
847 }
848 }
849 return EltTy && EltTy->isFPOrFPVectorTy();
850}
851
854 const unsigned Opc = MI.getOpcode();
855
856 // Try the default logic for non-generic instructions that are either copies
857 // or already have some operands assigned to banks.
858 if ((Opc != TargetOpcode::COPY && !isPreISelGenericOpcode(Opc)) ||
859 Opc == TargetOpcode::G_PHI) {
862 if (Mapping.isValid())
863 return Mapping;
864 }
865
866 const MachineFunction &MF = *MI.getParent()->getParent();
867 const MachineRegisterInfo &MRI = MF.getRegInfo();
870
871 switch (Opc) {
872 // G_{F|S|U}REM are not listed because they are not legal.
873 // Arithmetic ops.
874 case TargetOpcode::G_ADD:
875 case TargetOpcode::G_SUB:
876 case TargetOpcode::G_PTR_ADD:
877 case TargetOpcode::G_MUL:
878 case TargetOpcode::G_SDIV:
879 case TargetOpcode::G_UDIV:
880 // Bitwise ops.
881 case TargetOpcode::G_AND:
882 case TargetOpcode::G_OR:
883 case TargetOpcode::G_XOR:
884 // Floating point ops.
885 case TargetOpcode::G_FADD:
886 case TargetOpcode::G_FSUB:
887 case TargetOpcode::G_FMUL:
888 case TargetOpcode::G_FDIV:
889 case TargetOpcode::G_FMAXIMUM:
890 case TargetOpcode::G_FMINIMUM:
891 return getSameKindOfOperandsMapping(MI);
892 case TargetOpcode::G_FPEXT: {
893 LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
894 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
896 DefaultMappingID, /*Cost*/ 1,
897 getFPExtMapping(DstTy.getSizeInBits(), SrcTy.getSizeInBits()),
898 /*NumOperands*/ 2);
899 }
900 // Shifts.
901 case TargetOpcode::G_SHL:
902 case TargetOpcode::G_LSHR:
903 case TargetOpcode::G_ASHR: {
904 LLT ShiftAmtTy = MRI.getType(MI.getOperand(2).getReg());
905 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
906 if (ShiftAmtTy.getSizeInBits() == 64 && SrcTy.getSizeInBits() == 32)
909 return getSameKindOfOperandsMapping(MI);
910 }
911 case TargetOpcode::G_BITCAST: {
912 Register SrcReg = MI.getOperand(1).getReg();
913 const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
914 if (SrcRB) {
915 TypeSize Size = getSizeInBits(SrcReg, MRI, TRI);
918 getCopyMapping(SrcRB->getID(), SrcRB->getID(), Size),
919 // We only care about the mapping of the destination.
920 /*NumOperands=*/2);
921 }
922 [[fallthrough]];
923 }
924 case TargetOpcode::COPY: {
925 Register DstReg = MI.getOperand(0).getReg();
926 Register SrcReg = MI.getOperand(1).getReg();
927 // Check if one of the register is not a generic register.
928 if ((DstReg.isPhysical() || !MRI.getType(DstReg).isValid()) ||
929 (SrcReg.isPhysical() || !MRI.getType(SrcReg).isValid())) {
930 const RegisterBank *DstRB = getRegBank(DstReg, MRI, TRI);
931 const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
932 if (!DstRB)
933 DstRB = SrcRB;
934 else if (!SrcRB)
935 SrcRB = DstRB;
936 // If both RB are null that means both registers are generic.
937 // We shouldn't be here.
938 assert(DstRB && SrcRB && "Both RegBank were nullptr");
939 TypeSize Size = getSizeInBits(DstReg, MRI, TRI);
941 DefaultMappingID, copyCost(*DstRB, *SrcRB, Size),
942 getCopyMapping(DstRB->getID(), SrcRB->getID(), Size),
943 // We only care about the mapping of the destination.
944 /*NumOperands*/ 1);
945 }
946 // Both registers are generic
947 LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
948 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
949 TypeSize Size = DstTy.getSizeInBits();
950 bool DstIsGPR = !DstTy.isVector() && DstTy.getSizeInBits() <= 64;
951 bool SrcIsGPR = !SrcTy.isVector() && SrcTy.getSizeInBits() <= 64;
952 const RegisterBank &DstRB =
953 DstIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
954 const RegisterBank &SrcRB =
955 SrcIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
957 DefaultMappingID, copyCost(DstRB, SrcRB, Size),
958 getCopyMapping(DstRB.getID(), SrcRB.getID(), Size),
959 // We only care about the mapping of the destination for COPY.
960 /*NumOperands*/ Opc == TargetOpcode::G_BITCAST ? 2 : 1);
961 }
962 default:
963 break;
964 }
965
966 unsigned NumOperands = MI.getNumOperands();
967 unsigned MappingID = DefaultMappingID;
968
969 // Track the size and bank of each register. We don't do partial mappings.
970 SmallVector<unsigned, 4> OpSize(NumOperands);
971 SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands);
972 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
973 auto &MO = MI.getOperand(Idx);
974 if (!MO.isReg() || !MO.getReg())
975 continue;
976
977 LLT Ty = MRI.getType(MO.getReg());
978 if (!Ty.isValid())
979 continue;
980 OpSize[Idx] = Ty.getSizeInBits().getKnownMinValue();
981
982 // As a top-level guess, vectors including both scalable and non-scalable
983 // ones go in FPRs, scalars and pointers in GPRs.
984 // For floating-point instructions, scalars go in FPRs.
985 if (Ty.isVector())
986 OpRegBankIdx[Idx] = PMI_FirstFPR;
988 (MO.isDef() && onlyDefinesFP(MI, MRI, TRI)) ||
989 (MO.isUse() && onlyUsesFP(MI, MRI, TRI)) ||
990 Ty.getSizeInBits() > 64)
991 OpRegBankIdx[Idx] = PMI_FirstFPR;
992 else
993 OpRegBankIdx[Idx] = PMI_FirstGPR;
994 }
995
996 unsigned Cost = 1;
997 // Some of the floating-point instructions have mixed GPR and FPR operands:
998 // fine-tune the computed mapping.
999 switch (Opc) {
1000 case TargetOpcode::G_CONSTANT: {
1001 Register Dst = MI.getOperand(0).getReg();
1002 LLT DstTy = MRI.getType(Dst);
1003 if (DstTy.isScalar() && DstTy.getSizeInBits() < 32)
1004 MappingID = CustomMappingID;
1005 break;
1006 }
1007 case TargetOpcode::G_FCONSTANT: {
1008 if (preferGPRForFPImm(MI, MRI, STI)) {
1009 // Materialize in GPR and rely on later bank copies for FP uses.
1010 MappingID = CustomMappingID;
1011 OpRegBankIdx = {PMI_FirstGPR};
1012 }
1013 break;
1014 }
1015 case AArch64::G_DUP: {
1016 Register ScalarReg = MI.getOperand(1).getReg();
1017 LLT ScalarTy = MRI.getType(ScalarReg);
1018 auto ScalarDef = MRI.getVRegDef(ScalarReg);
1019 // We want to select dup(load) into LD1R.
1020 if (ScalarDef->getOpcode() == TargetOpcode::G_LOAD)
1021 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1022 // s8 is an exception for G_DUP, which we always want on gpr.
1023 else if (ScalarTy.getSizeInBits() != 8 &&
1024 (getRegBank(ScalarReg, MRI, TRI) == &AArch64::FPRRegBank ||
1025 onlyDefinesFP(*ScalarDef, MRI, TRI)))
1026 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1027 else {
1028 if (ScalarTy.getSizeInBits() < 32 &&
1029 getRegBank(ScalarReg, MRI, TRI) == &AArch64::GPRRegBank) {
1030 // Calls applyMappingImpl()
1031 MappingID = CustomMappingID;
1032 }
1033 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR};
1034 }
1035 break;
1036 }
1037 case TargetOpcode::G_TRUNC: {
1038 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
1039 if (!SrcTy.isVector() && SrcTy.getSizeInBits() == 128)
1040 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1041 break;
1042 }
1043 case TargetOpcode::G_SITOFP:
1044 case TargetOpcode::G_UITOFP: {
1045 if (MRI.getType(MI.getOperand(0).getReg()).isVector())
1046 break;
1047 // Integer to FP conversions don't necessarily happen between GPR -> FPR
1048 // regbanks. They can also be done within an FPR register.
1049 Register SrcReg = MI.getOperand(1).getReg();
1050 if (getRegBank(SrcReg, MRI, TRI) == &AArch64::FPRRegBank &&
1051 MRI.getType(SrcReg).getSizeInBits() ==
1052 MRI.getType(MI.getOperand(0).getReg()).getSizeInBits())
1053 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1054 else
1055 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR};
1056 break;
1057 }
1058 case TargetOpcode::G_FPTOSI_SAT:
1059 case TargetOpcode::G_FPTOUI_SAT:
1060 case TargetOpcode::G_FPTOSI:
1061 case TargetOpcode::G_FPTOUI:
1062 case TargetOpcode::G_INTRINSIC_LRINT:
1063 case TargetOpcode::G_INTRINSIC_LLRINT:
1064 case TargetOpcode::G_LROUND:
1065 case TargetOpcode::G_LLROUND: {
1066 LLT DstType = MRI.getType(MI.getOperand(0).getReg());
1067 if (DstType.isVector())
1068 break;
1069 if (DstType == LLT::scalar(16)) {
1070 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1071 break;
1072 }
1073 TypeSize DstSize = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
1074 TypeSize SrcSize = getSizeInBits(MI.getOperand(1).getReg(), MRI, TRI);
1075 if (((DstSize == SrcSize) || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1076 all_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1077 [&](const MachineInstr &UseMI) {
1078 return onlyUsesFP(UseMI, MRI, TRI) ||
1079 prefersFPUse(UseMI, MRI, TRI);
1080 }))
1081 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1082 else
1083 OpRegBankIdx = {PMI_FirstGPR, PMI_FirstFPR};
1084 break;
1085 }
1086 case TargetOpcode::G_FCMP: {
1087 // If the result is a vector, it must use a FPR.
1089 MRI.getType(MI.getOperand(0).getReg()).isVector() ? PMI_FirstFPR
1090 : PMI_FirstGPR;
1091 OpRegBankIdx = {Idx0,
1092 /* Predicate */ PMI_None, PMI_FirstFPR, PMI_FirstFPR};
1093 break;
1094 }
1095 case TargetOpcode::G_BITCAST:
1096 // This is going to be a cross register bank copy and this is expensive.
1097 if (OpRegBankIdx[0] != OpRegBankIdx[1])
1098 Cost = copyCost(
1099 *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[0]].RegBank,
1100 *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[1]].RegBank,
1101 TypeSize::getFixed(OpSize[0]));
1102 break;
1103 case TargetOpcode::G_LOAD: {
1104 // Loading in vector unit is slightly more expensive.
1105 // This is actually only true for the LD1R and co instructions,
1106 // but anyway for the fast mode this number does not matter and
1107 // for the greedy mode the cost of the cross bank copy will
1108 // offset this number.
1109 // FIXME: Should be derived from the scheduling model.
1110 if (OpRegBankIdx[0] != PMI_FirstGPR) {
1111 Cost = 2;
1112 break;
1113 }
1114
1115 if (cast<GLoad>(MI).isAtomic()) {
1116 // Atomics always use GPR destinations. Don't refine any further.
1117 OpRegBankIdx[0] = PMI_FirstGPR;
1118 if (MRI.getType(MI.getOperand(0).getReg()).getSizeInBits() < 32)
1119 MappingID = CustomMappingID;
1120 break;
1121 }
1122
1123 // Try to guess the type of the load from the MMO.
1124 if (isLoadFromFPType(MI)) {
1125 OpRegBankIdx[0] = PMI_FirstFPR;
1126 break;
1127 }
1128
1129 // Check if that load feeds fp instructions.
1130 // In that case, we want the default mapping to be on FPR
1131 // instead of blind map every scalar to GPR.
1132 if (any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1133 [&](const MachineInstr &UseMI) {
1134 // If we have at least one direct or indirect use
1135 // in a FP instruction,
1136 // assume this was a floating point load in the IR. If it was
1137 // not, we would have had a bitcast before reaching that
1138 // instruction.
1139 //
1140 // Int->FP conversion operations are also captured in
1141 // prefersFPUse().
1142
1143 if (isPHIWithFPConstraints(UseMI, MRI, TRI))
1144 return true;
1145
1146 return onlyUsesFP(UseMI, MRI, TRI) ||
1147 prefersFPUse(UseMI, MRI, TRI);
1148 }))
1149 OpRegBankIdx[0] = PMI_FirstFPR;
1150
1151 // On GPR, extend any load < 32bits to 32bit.
1152 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
1153 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1154 MappingID = CustomMappingID;
1155 break;
1156 }
1157 case TargetOpcode::G_STORE:
1158 // Check if that store is fed by fp instructions.
1159 if (OpRegBankIdx[0] == PMI_FirstGPR) {
1160 Register VReg = MI.getOperand(0).getReg();
1161 if (VReg) {
1162 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1163 if (onlyDefinesFP(*DefMI, MRI, TRI)) {
1164 OpRegBankIdx[0] = PMI_FirstFPR;
1165 break;
1166 }
1167 }
1168
1169 // On GPR, extend any store < 32bits to 32bit.
1170 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
1171 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1172 MappingID = CustomMappingID;
1173 }
1174 break;
1175 case TargetOpcode::G_INDEXED_STORE:
1176 if (OpRegBankIdx[1] == PMI_FirstGPR) {
1177 Register VReg = MI.getOperand(1).getReg();
1178 if (!VReg)
1179 break;
1180 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1181 if (onlyDefinesFP(*DefMI, MRI, TRI))
1182 OpRegBankIdx[1] = PMI_FirstFPR;
1183 break;
1184 }
1185 break;
1186 case TargetOpcode::G_INDEXED_SEXTLOAD:
1187 case TargetOpcode::G_INDEXED_ZEXTLOAD:
1188 // These should always be GPR.
1189 OpRegBankIdx[0] = PMI_FirstGPR;
1190 break;
1191 case TargetOpcode::G_INDEXED_LOAD: {
1192 if (isLoadFromFPType(MI))
1193 OpRegBankIdx[0] = PMI_FirstFPR;
1194 break;
1195 }
1196 case TargetOpcode::G_SELECT: {
1197 // If the destination is FPR, preserve that.
1198 if (OpRegBankIdx[0] != PMI_FirstGPR)
1199 break;
1200
1201 // If we're taking in vectors, we have no choice but to put everything on
1202 // FPRs, except for the condition. The condition must always be on a GPR.
1203 LLT SrcTy = MRI.getType(MI.getOperand(2).getReg());
1204 if (SrcTy.isVector()) {
1206 break;
1207 }
1208
1209 // Try to minimize the number of copies. If we have more floating point
1210 // constrained values than not, then we'll put everything on FPR. Otherwise,
1211 // everything has to be on GPR.
1212 unsigned NumFP = 0;
1213
1214 // Check if the uses of the result always produce floating point values.
1215 //
1216 // For example:
1217 //
1218 // %z = G_SELECT %cond %x %y
1219 // fpr = G_FOO %z ...
1220 if (any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1221 [&](MachineInstr &MI) { return onlyUsesFP(MI, MRI, TRI); }))
1222 ++NumFP;
1223
1224 // Check if the defs of the source values always produce floating point
1225 // values.
1226 //
1227 // For example:
1228 //
1229 // %x = G_SOMETHING_ALWAYS_FLOAT %a ...
1230 // %z = G_SELECT %cond %x %y
1231 //
1232 // Also check whether or not the sources have already been decided to be
1233 // FPR. Keep track of this.
1234 //
1235 // This doesn't check the condition, since it's just whatever is in NZCV.
1236 // This isn't passed explicitly in a register to fcsel/csel.
1237 for (unsigned Idx = 2; Idx < 4; ++Idx) {
1238 Register VReg = MI.getOperand(Idx).getReg();
1239 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1240 if (getRegBank(VReg, MRI, TRI) == &AArch64::FPRRegBank ||
1241 onlyDefinesFP(*DefMI, MRI, TRI))
1242 ++NumFP;
1243 }
1244
1245 // If we have more FP constraints than not, then move everything over to
1246 // FPR.
1247 if (NumFP >= 2)
1249
1250 break;
1251 }
1252 case TargetOpcode::G_UNMERGE_VALUES: {
1253 // If the first operand belongs to a FPR register bank, then make sure that
1254 // we preserve that.
1255 if (OpRegBankIdx[0] != PMI_FirstGPR)
1256 break;
1257
1258 LLT SrcTy = MRI.getType(MI.getOperand(MI.getNumOperands()-1).getReg());
1259 // UNMERGE into scalars from a vector should always use FPR.
1260 // Likewise if any of the uses are FP instructions.
1261 if (SrcTy.isVector() || SrcTy == LLT::scalar(128) ||
1262 any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1263 [&](MachineInstr &MI) { return onlyUsesFP(MI, MRI, TRI); })) {
1264 // Set the register bank of every operand to FPR.
1265 for (unsigned Idx = 0, NumOperands = MI.getNumOperands();
1266 Idx < NumOperands; ++Idx)
1267 OpRegBankIdx[Idx] = PMI_FirstFPR;
1268 }
1269 break;
1270 }
1271 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
1272 // Destination and source need to be FPRs.
1273 OpRegBankIdx[0] = PMI_FirstFPR;
1274 OpRegBankIdx[1] = PMI_FirstFPR;
1275
1276 // Index needs to be a GPR.
1277 OpRegBankIdx[2] = PMI_FirstGPR;
1278 break;
1279 case AArch64::G_SQSHLU_I:
1280 // Destination and source need to be FPRs.
1281 OpRegBankIdx[0] = PMI_FirstFPR;
1282 OpRegBankIdx[1] = PMI_FirstFPR;
1283
1284 // Shift Index needs to be a GPR.
1285 OpRegBankIdx[2] = PMI_FirstGPR;
1286 break;
1287
1288 case TargetOpcode::G_INSERT_VECTOR_ELT:
1289 OpRegBankIdx[0] = PMI_FirstFPR;
1290 OpRegBankIdx[1] = PMI_FirstFPR;
1291
1292 // The element may be either a GPR or FPR. Preserve that behaviour.
1293 if (getRegBank(MI.getOperand(2).getReg(), MRI, TRI) == &AArch64::FPRRegBank)
1294 OpRegBankIdx[2] = PMI_FirstFPR;
1295 else {
1296 // If the type is i8/i16, and the regbank will be GPR, then we change the
1297 // type to i32 in applyMappingImpl.
1298 LLT Ty = MRI.getType(MI.getOperand(2).getReg());
1299 if (Ty.getSizeInBits() == 8 || Ty.getSizeInBits() == 16) {
1300 // Calls applyMappingImpl()
1301 MappingID = CustomMappingID;
1302 }
1303 OpRegBankIdx[2] = PMI_FirstGPR;
1304 }
1305
1306 // Index needs to be a GPR.
1307 OpRegBankIdx[3] = PMI_FirstGPR;
1308 break;
1309 case TargetOpcode::G_EXTRACT: {
1310 // For s128 sources we have to use fpr unless we know otherwise.
1311 auto Src = MI.getOperand(1).getReg();
1312 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
1313 if (SrcTy.getSizeInBits() != 128)
1314 break;
1315 auto Idx = MRI.getRegClassOrNull(Src) == &AArch64::XSeqPairsClassRegClass
1316 ? PMI_FirstGPR
1317 : PMI_FirstFPR;
1318 OpRegBankIdx[0] = Idx;
1319 OpRegBankIdx[1] = Idx;
1320 break;
1321 }
1322 case TargetOpcode::G_BUILD_VECTOR: {
1323 // If the first source operand belongs to a FPR register bank, then make
1324 // sure that we preserve that.
1325 if (OpRegBankIdx[1] != PMI_FirstGPR)
1326 break;
1327 Register VReg = MI.getOperand(1).getReg();
1328 if (!VReg)
1329 break;
1330
1331 // Get the instruction that defined the source operand reg, and check if
1332 // it's a floating point operation. Or, if it's a type like s16 which
1333 // doesn't have a exact size gpr register class. The exception is if the
1334 // build_vector has all constant operands, which may be better to leave as
1335 // gpr without copies, so it can be matched in imported patterns.
1336 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1337 unsigned DefOpc = DefMI->getOpcode();
1338 const LLT SrcTy = MRI.getType(VReg);
1339 if (all_of(MI.operands(), [&](const MachineOperand &Op) {
1340 return Op.isDef() || MRI.getVRegDef(Op.getReg())->getOpcode() ==
1341 TargetOpcode::G_CONSTANT;
1342 }))
1343 break;
1345 SrcTy.getSizeInBits() < 32 ||
1346 getRegBank(VReg, MRI, TRI) == &AArch64::FPRRegBank) {
1347 // Have a floating point op.
1348 // Make sure every operand gets mapped to a FPR register class.
1349 unsigned NumOperands = MI.getNumOperands();
1350 for (unsigned Idx = 0; Idx < NumOperands; ++Idx)
1351 OpRegBankIdx[Idx] = PMI_FirstFPR;
1352 }
1353 break;
1354 }
1355 case TargetOpcode::G_VECREDUCE_FADD:
1356 case TargetOpcode::G_VECREDUCE_FMUL:
1357 case TargetOpcode::G_VECREDUCE_FMAX:
1358 case TargetOpcode::G_VECREDUCE_FMIN:
1359 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1360 case TargetOpcode::G_VECREDUCE_FMINIMUM:
1361 case TargetOpcode::G_VECREDUCE_ADD:
1362 case TargetOpcode::G_VECREDUCE_MUL:
1363 case TargetOpcode::G_VECREDUCE_AND:
1364 case TargetOpcode::G_VECREDUCE_OR:
1365 case TargetOpcode::G_VECREDUCE_XOR:
1366 case TargetOpcode::G_VECREDUCE_SMAX:
1367 case TargetOpcode::G_VECREDUCE_SMIN:
1368 case TargetOpcode::G_VECREDUCE_UMAX:
1369 case TargetOpcode::G_VECREDUCE_UMIN:
1370 // Reductions produce a scalar value from a vector, the scalar should be on
1371 // FPR bank.
1372 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1373 break;
1374 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
1375 case TargetOpcode::G_VECREDUCE_SEQ_FMUL:
1376 // These reductions also take a scalar accumulator input.
1377 // Assign them FPR for now.
1378 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR, PMI_FirstFPR};
1379 break;
1380 case TargetOpcode::G_INTRINSIC:
1381 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: {
1382 switch (cast<GIntrinsic>(MI).getIntrinsicID()) {
1383 case Intrinsic::aarch64_neon_fcvtas:
1384 case Intrinsic::aarch64_neon_fcvtau:
1385 case Intrinsic::aarch64_neon_fcvtzs:
1386 case Intrinsic::aarch64_neon_fcvtzu:
1387 case Intrinsic::aarch64_neon_fcvtms:
1388 case Intrinsic::aarch64_neon_fcvtmu:
1389 case Intrinsic::aarch64_neon_fcvtns:
1390 case Intrinsic::aarch64_neon_fcvtnu:
1391 case Intrinsic::aarch64_neon_fcvtps:
1392 case Intrinsic::aarch64_neon_fcvtpu: {
1393 OpRegBankIdx[2] = PMI_FirstFPR;
1394 if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
1395 OpRegBankIdx[0] = PMI_FirstFPR;
1396 break;
1397 }
1398 TypeSize DstSize = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
1399 TypeSize SrcSize = getSizeInBits(MI.getOperand(2).getReg(), MRI, TRI);
1400 // Fp conversions to i16 must be kept on fp register banks to ensure
1401 // proper saturation, as there are no 16-bit gprs.
1402 // In addition, conversion intrinsics have fpr output when the input
1403 // size matches the output size, or FPRCVT is present.
1404 if (DstSize == 16 ||
1405 ((DstSize == SrcSize || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1406 all_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1407 [&](const MachineInstr &UseMI) {
1408 return onlyUsesFP(UseMI, MRI, TRI) ||
1409 prefersFPUse(UseMI, MRI, TRI);
1410 })))
1411 OpRegBankIdx[0] = PMI_FirstFPR;
1412 else
1413 OpRegBankIdx[0] = PMI_FirstGPR;
1414 break;
1415 }
1416 case Intrinsic::aarch64_neon_vcvtfxs2fp:
1417 case Intrinsic::aarch64_neon_vcvtfxu2fp:
1418 case Intrinsic::aarch64_neon_vcvtfp2fxs:
1419 case Intrinsic::aarch64_neon_vcvtfp2fxu:
1420 // Override these intrinsics, because they would have a partial
1421 // mapping. This is needed for 'half' types, which otherwise don't
1422 // get legalised correctly.
1423 OpRegBankIdx[0] = PMI_FirstFPR;
1424 OpRegBankIdx[2] = PMI_FirstFPR;
1425 // OpRegBankIdx[1] is the intrinsic ID.
1426 // OpRegBankIdx[3] is an integer immediate.
1427 break;
1428 default: {
1429 // Check if we know that the intrinsic has any constraints on its register
1430 // banks. If it does, then update the mapping accordingly.
1431 unsigned Idx = 0;
1432 if (onlyDefinesFP(MI, MRI, TRI))
1433 for (const auto &Op : MI.defs()) {
1434 if (Op.isReg())
1435 OpRegBankIdx[Idx] = PMI_FirstFPR;
1436 ++Idx;
1437 }
1438 else
1439 Idx += MI.getNumExplicitDefs();
1440
1441 if (onlyUsesFP(MI, MRI, TRI))
1442 for (const auto &Op : MI.explicit_uses()) {
1443 if (Op.isReg())
1444 OpRegBankIdx[Idx] = PMI_FirstFPR;
1445 ++Idx;
1446 }
1447 break;
1448 }
1449 }
1450 break;
1451 }
1452 }
1453
1454 // Finally construct the computed mapping.
1455 SmallVector<const ValueMapping *, 8> OpdsMapping(NumOperands);
1456 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
1457 if (MI.getOperand(Idx).isReg() && MI.getOperand(Idx).getReg()) {
1458 LLT Ty = MRI.getType(MI.getOperand(Idx).getReg());
1459 if (!Ty.isValid())
1460 continue;
1461 auto Mapping =
1462 getValueMapping(OpRegBankIdx[Idx], TypeSize::getFixed(OpSize[Idx]));
1463 if (!Mapping->isValid())
1465
1466 OpdsMapping[Idx] = Mapping;
1467 }
1468 }
1469
1470 return getInstructionMapping(MappingID, Cost, getOperandsMapping(OpdsMapping),
1471 NumOperands);
1472}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define CHECK_VALUEMAP(RBName, Size)
static bool isFPIntrinsic(const MachineRegisterInfo &MRI, const MachineInstr &MI)
#define CHECK_VALUEMAP_3OPS(RBName, Size)
static bool foldTruncOfI32Constant(MachineInstr &MI, unsigned OpIdx, MachineRegisterInfo &MRI, const AArch64RegisterBankInfo &RBI)
static const unsigned CustomMappingID
#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB)
#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size)
#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize)
static bool preferGPRForFPImm(const MachineInstr &MI, const MachineRegisterInfo &MRI, const AArch64Subtarget &STI)
This file declares the targeting of the RegisterBankInfo class for AArch64.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineInstr unsigned OpIdx
ppc ctr loops verify
static const MCPhysReg FPR[]
FPR - The set of FP registers that should be allocated for arguments on Darwin and AIX.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static unsigned getRegBankBaseIdxOffset(unsigned RBIdx, TypeSize Size)
static const RegisterBankInfo::ValueMapping * getCopyMapping(unsigned DstBankID, unsigned SrcBankID, TypeSize Size)
Get the pointer to the ValueMapping of the operands of a copy instruction from the SrcBankID register...
static bool checkPartialMappingIdx(PartialMappingIdx FirstAlias, PartialMappingIdx LastAlias, ArrayRef< PartialMappingIdx > Order)
static const RegisterBankInfo::PartialMapping PartMappings[]
static const RegisterBankInfo::ValueMapping * getFPExtMapping(unsigned DstSize, unsigned SrcSize)
Get the instruction mapping for G_FPEXT.
static const RegisterBankInfo::ValueMapping * getValueMapping(PartialMappingIdx RBIdx, TypeSize Size)
Get the pointer to the ValueMapping representing the RegisterBank at RBIdx with a size of Size.
static const RegisterBankInfo::ValueMapping ValMappings[]
This class provides the information for the target register banks.
InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const override
Get the alternative mappings for MI.
unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const override
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const override
Get a register bank that covers RC.
AArch64RegisterBankInfo(const TargetRegisterInfo &TRI)
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
const AArch64RegisterInfo * getRegisterInfo() const override
const AArch64TargetLowering * getTargetLowering() const override
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns true if the target can instruction select the specified FP immediate natively.
bool isFPImmLegalAsFMov(const APFloat &Imm, EVT VT) const
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1563
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
Definition APInt.cpp:651
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:358
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr bool isVector() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static LLT integer(unsigned SizeInBits)
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Register getReg(unsigned Idx) const
Get the register for the operand index.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const RegisterBank * getRegBank(Register Reg) const
Return the register bank of Reg.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
bool isValid() const
Check whether this object is valid.
virtual InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const
Get the alternative mappings for MI.
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
static void applyDefaultMapping(const OperandsMapper &OpdMapper)
Helper method to apply something that is like the default mapping.
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
TypeSize getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const
Get a register bank that covers RC.
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End.
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
SmallVector< const InstructionMapping *, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
virtual unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
This class implements the register bank concept.
LLVM_ABI bool covers(const TargetRegisterClass &RC) const
Check whether this register bank covers RC.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getID() const
Return the register class ID number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
Type * getArrayElementType() const
Definition Type.h:427
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition Type.h:227
iterator_range< user_iterator > users()
Definition Value.h:426
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isAdvSIMDModImmType4(uint64_t Imm)
OperandType
Operands are tagged with one of the values of this enum.
Definition MCInstrDesc.h:59
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
InstructionCost Cost
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool isPreISelGenericFloatingPointOpcode(unsigned Opc)
Returns whether opcode Opc is a pre-isel generic floating-point opcode, having only floating-point op...
Definition Utils.cpp:1685
Extended Value Type.
Definition ValueTypes.h:35
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
Definition ValueTypes.h:55
The llvm::once_flag structure.
Definition Threading.h:67