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