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