LLVM 23.0.0git
AArch64RegisterBankInfo.cpp
Go to the documentation of this file.
1//===- AArch64RegisterBankInfo.cpp ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements the targeting of the RegisterBankInfo class for
10/// AArch64.
11/// \todo This should be generated by TableGen.
12//===----------------------------------------------------------------------===//
13
15#include "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 getRegBank(AArch64::GPRRegBankID);
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.
417 const AArch64RegisterBankInfo &RBI) {
418 MachineOperand &Op = MI.getOperand(OpIdx);
419
420 Register ScalarReg = Op.getReg();
421 MachineInstr *TruncMI = MRI.getVRegDef(ScalarReg);
422 if (!TruncMI || TruncMI->getOpcode() != TargetOpcode::G_TRUNC)
423 return false;
424
425 Register TruncSrc = TruncMI->getOperand(1).getReg();
426 MachineInstr *SrcDef = MRI.getVRegDef(TruncSrc);
427 if (!SrcDef || SrcDef->getOpcode() != TargetOpcode::G_CONSTANT)
428 return false;
429
430 LLT TruncSrcTy = MRI.getType(TruncSrc);
431 if (!TruncSrcTy.isScalar() || TruncSrcTy.getSizeInBits() != 32)
432 return false;
433
434 // Avoid truncating and extending a constant, this helps with selection.
435 Op.setReg(TruncSrc);
436 MRI.setRegBank(TruncSrc, RBI.getRegBank(AArch64::GPRRegBankID));
437
438 if (MRI.use_empty(ScalarReg))
439 TruncMI->eraseFromParent();
440
441 return true;
442}
443
444void AArch64RegisterBankInfo::applyMappingImpl(
445 MachineIRBuilder &Builder, const OperandsMapper &OpdMapper) const {
446 MachineInstr &MI = OpdMapper.getMI();
447 MachineRegisterInfo &MRI = OpdMapper.getMRI();
448
449 switch (MI.getOpcode()) {
450 case TargetOpcode::G_CONSTANT: {
451 Register Dst = MI.getOperand(0).getReg();
452 [[maybe_unused]] LLT DstTy = MRI.getType(Dst);
453 assert(MRI.getRegBank(Dst) == &AArch64::GPRRegBank && DstTy.isScalar() &&
454 DstTy.getSizeInBits() < 32 &&
455 "Expected a scalar smaller than 32 bits on a GPR.");
456 Builder.setInsertPt(*MI.getParent(), std::next(MI.getIterator()));
458 Builder.buildTrunc(Dst, ExtReg);
459
460 APInt Val = MI.getOperand(1).getCImm()->getValue().zext(32);
461 LLVMContext &Ctx = Builder.getMF().getFunction().getContext();
462 MI.getOperand(1).setCImm(ConstantInt::get(Ctx, Val));
463 MI.getOperand(0).setReg(ExtReg);
464 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
465
466 return applyDefaultMapping(OpdMapper);
467 }
468 case TargetOpcode::G_FCONSTANT: {
469 Register Dst = MI.getOperand(0).getReg();
470 assert(MRI.getRegBank(Dst) == &AArch64::GPRRegBank &&
471 "Expected Dst to be on a GPR.");
472 const APFloat &Imm = MI.getOperand(1).getFPImm()->getValueAPF();
473 APInt Bits = Imm.bitcastToAPInt();
474 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
475 if (Bits.getBitWidth() < 32) {
477 Builder.buildConstant(ExtReg, Bits.zext(32));
478 Builder.buildTrunc(Dst, ExtReg);
479 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
480 } else {
481 Builder.buildConstant(Dst, Bits);
482 }
483 MI.eraseFromParent();
484 return;
485 }
486 case TargetOpcode::G_STORE: {
487 Register Dst = MI.getOperand(0).getReg();
488 LLT Ty = MRI.getType(Dst);
489
490 if (MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.isScalar() &&
491 Ty.getSizeInBits() < 32) {
492
493 if (foldTruncOfI32Constant(MI, 0, MRI, *this))
494 return applyDefaultMapping(OpdMapper);
495
496 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
497 auto Ext = Builder.buildAnyExt(LLT::integer(32), Dst);
498 MI.getOperand(0).setReg(Ext.getReg(0));
499 MRI.setRegBank(Ext.getReg(0), AArch64::GPRRegBank);
500 }
501 return applyDefaultMapping(OpdMapper);
502 }
503 case TargetOpcode::G_LOAD: {
504 Register Dst = MI.getOperand(0).getReg();
505 LLT Ty = MRI.getType(Dst);
506 if (MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.isScalar() &&
507 Ty.getSizeInBits() < 32) {
508 Builder.setInsertPt(*MI.getParent(), std::next(MI.getIterator()));
510 Builder.buildTrunc(Dst, ExtReg);
511 MI.getOperand(0).setReg(ExtReg);
512 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
513 }
514 [[fallthrough]];
515 }
516 case TargetOpcode::G_OR:
517 case TargetOpcode::G_BITCAST:
518 // Those ID must match getInstrAlternativeMappings.
519 assert((OpdMapper.getInstrMapping().getID() >= 1 &&
520 OpdMapper.getInstrMapping().getID() <= 4) &&
521 "Don't know how to handle that ID");
522 return applyDefaultMapping(OpdMapper);
523 case TargetOpcode::G_INSERT_VECTOR_ELT: {
524 if (foldTruncOfI32Constant(MI, 2, MRI, *this))
525 return applyDefaultMapping(OpdMapper);
526
527 // Extend smaller gpr operands to 32 bit.
528 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
529 LLT OperandType = MRI.getType(MI.getOperand(2).getReg());
530 auto Ext = Builder.buildAnyExt(OperandType.changeElementSize(32),
531 MI.getOperand(2).getReg());
532 MRI.setRegBank(Ext.getReg(0), getRegBank(AArch64::GPRRegBankID));
533 MI.getOperand(2).setReg(Ext.getReg(0));
534 return applyDefaultMapping(OpdMapper);
535 }
536 case AArch64::G_DUP: {
537 if (foldTruncOfI32Constant(MI, 1, MRI, *this))
538 return applyDefaultMapping(OpdMapper);
539
540 // Extend smaller gpr to 32-bits
541 assert(MRI.getType(MI.getOperand(1).getReg()).getSizeInBits() < 32 &&
542 "Expected sources smaller than 32-bits");
543 Builder.setInsertPt(*MI.getParent(), MI.getIterator());
544
545 Register ConstReg =
546 Builder.buildAnyExt(LLT::integer(32), MI.getOperand(1).getReg())
547 .getReg(0);
548 MRI.setRegBank(ConstReg, getRegBank(AArch64::GPRRegBankID));
549 MI.getOperand(1).setReg(ConstReg);
550
551 return applyDefaultMapping(OpdMapper);
552 }
553 default:
554 llvm_unreachable("Don't know how to handle that operation");
555 }
556}
557
559AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
560 const MachineInstr &MI) const {
561 const unsigned Opc = MI.getOpcode();
562 const MachineFunction &MF = *MI.getParent()->getParent();
563 const MachineRegisterInfo &MRI = MF.getRegInfo();
564
565 unsigned NumOperands = MI.getNumOperands();
566 assert(NumOperands <= 3 &&
567 "This code is for instructions with 3 or less operands");
568
569 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
570 TypeSize Size = Ty.getSizeInBits();
572
574
575#ifndef NDEBUG
576 // Make sure all the operands are using similar size and type.
577 // Should probably be checked by the machine verifier.
578 // This code won't catch cases where the number of lanes is
579 // different between the operands.
580 // If we want to go to that level of details, it is probably
581 // best to check that the types are the same, period.
582 // Currently, we just check that the register banks are the same
583 // for each types.
584 for (unsigned Idx = 1; Idx != NumOperands; ++Idx) {
585 LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg());
586 assert(
588 RBIdx, OpTy.getSizeInBits()) ==
590 "Operand has incompatible size");
591 bool OpIsFPR = OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc);
592 (void)OpIsFPR;
593 assert(IsFPR == OpIsFPR && "Operand has incompatible type");
594 }
595#endif // End NDEBUG.
596
598 getValueMapping(RBIdx, Size), NumOperands);
599}
600
601/// \returns true if a given intrinsic only uses and defines FPRs.
602static bool isFPIntrinsic(const MachineRegisterInfo &MRI,
603 const MachineInstr &MI) {
604 // TODO: Add more intrinsics.
606 default:
607 return false;
608 case Intrinsic::aarch64_neon_uaddlv:
609 case Intrinsic::aarch64_neon_uaddv:
610 case Intrinsic::aarch64_neon_saddv:
611 case Intrinsic::aarch64_neon_umaxv:
612 case Intrinsic::aarch64_neon_smaxv:
613 case Intrinsic::aarch64_neon_uminv:
614 case Intrinsic::aarch64_neon_sminv:
615 case Intrinsic::aarch64_neon_faddv:
616 case Intrinsic::aarch64_neon_fmaxv:
617 case Intrinsic::aarch64_neon_fminv:
618 case Intrinsic::aarch64_neon_fmaxnmv:
619 case Intrinsic::aarch64_neon_fminnmv:
620 case Intrinsic::aarch64_neon_fmulx:
621 case Intrinsic::aarch64_neon_frecpe:
622 case Intrinsic::aarch64_neon_frecps:
623 case Intrinsic::aarch64_neon_frecpx:
624 case Intrinsic::aarch64_neon_frsqrte:
625 case Intrinsic::aarch64_neon_frsqrts:
626 case Intrinsic::aarch64_neon_facge:
627 case Intrinsic::aarch64_neon_facgt:
628 case Intrinsic::aarch64_neon_fabd:
629 case Intrinsic::aarch64_neon_sqrdmlah:
630 case Intrinsic::aarch64_neon_sqrdmlsh:
631 case Intrinsic::aarch64_neon_sqrdmulh:
632 case Intrinsic::aarch64_neon_suqadd:
633 case Intrinsic::aarch64_neon_usqadd:
634 case Intrinsic::aarch64_neon_uqadd:
635 case Intrinsic::aarch64_neon_sqadd:
636 case Intrinsic::aarch64_neon_uqsub:
637 case Intrinsic::aarch64_neon_sqsub:
638 case Intrinsic::aarch64_neon_sqdmulh:
639 case Intrinsic::aarch64_neon_sqdmulls_scalar:
640 case Intrinsic::aarch64_neon_srshl:
641 case Intrinsic::aarch64_neon_urshl:
642 case Intrinsic::aarch64_neon_sqshl:
643 case Intrinsic::aarch64_neon_uqshl:
644 case Intrinsic::aarch64_neon_sqrshl:
645 case Intrinsic::aarch64_neon_uqrshl:
646 case Intrinsic::aarch64_neon_ushl:
647 case Intrinsic::aarch64_neon_sshl:
648 case Intrinsic::aarch64_neon_sqshrn:
649 case Intrinsic::aarch64_neon_sqshrun:
650 case Intrinsic::aarch64_neon_sqrshrn:
651 case Intrinsic::aarch64_neon_sqrshrun:
652 case Intrinsic::aarch64_neon_uqshrn:
653 case Intrinsic::aarch64_neon_uqrshrn:
654 case Intrinsic::aarch64_neon_sqneg:
655 case Intrinsic::aarch64_crypto_sha1h:
656 case Intrinsic::aarch64_crypto_sha1c:
657 case Intrinsic::aarch64_crypto_sha1p:
658 case Intrinsic::aarch64_crypto_sha1m:
659 case Intrinsic::aarch64_sisd_fcvtxn:
660 case Intrinsic::aarch64_sisd_fabd:
661 return true;
662 case Intrinsic::aarch64_neon_saddlv: {
663 const LLT SrcTy = MRI.getType(MI.getOperand(2).getReg());
664 return SrcTy.getElementType().getSizeInBits() >= 16 &&
665 SrcTy.getElementCount().getFixedValue() >= 4;
666 }
667 }
668}
669
670bool AArch64RegisterBankInfo::isPHIWithFPConstraints(
671 const MachineInstr &MI, const MachineRegisterInfo &MRI,
672 const AArch64RegisterInfo &TRI, const unsigned Depth) const {
673 if (!MI.isPHI() || Depth > MaxFPRSearchDepth)
674 return false;
675
676 return any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
677 [&](const MachineInstr &UseMI) {
678 if (onlyUsesFP(UseMI, MRI, TRI, Depth + 1))
679 return true;
680 return isPHIWithFPConstraints(UseMI, MRI, TRI, Depth + 1);
681 });
682}
683
684bool AArch64RegisterBankInfo::hasFPConstraints(const MachineInstr &MI,
685 const MachineRegisterInfo &MRI,
687 unsigned Depth) const {
688 unsigned Op = MI.getOpcode();
689 if (Op == TargetOpcode::G_INTRINSIC && isFPIntrinsic(MRI, MI))
690 return true;
691
692 // Do we have an explicit floating point instruction?
694 return true;
695
696 // No. Check if we have a copy-like instruction. If we do, then we could
697 // still be fed by floating point instructions.
698 if (Op != TargetOpcode::COPY && !MI.isPHI() &&
700 return false;
701
702 // Check if we already know the register bank.
703 auto *RB = getRegBank(MI.getOperand(0).getReg(), MRI, TRI);
704 if (RB == &AArch64::FPRRegBank)
705 return true;
706 if (RB == &AArch64::GPRRegBank)
707 return false;
708
709 // We don't know anything.
710 //
711 // If we have a phi, we may be able to infer that it will be assigned a FPR
712 // based off of its inputs.
713 if (!MI.isPHI() || Depth > MaxFPRSearchDepth)
714 return false;
715
716 return any_of(MI.explicit_uses(), [&](const MachineOperand &Op) {
717 return Op.isReg() &&
718 onlyDefinesFP(*MRI.getVRegDef(Op.getReg()), MRI, TRI, Depth + 1);
719 });
720}
721
722bool AArch64RegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
723 const MachineRegisterInfo &MRI,
725 unsigned Depth) const {
726 switch (MI.getOpcode()) {
727 case TargetOpcode::G_BITCAST: {
728 Register DstReg = MI.getOperand(0).getReg();
729 return all_of(MRI.use_nodbg_instructions(DstReg),
730 [&](const MachineInstr &UseMI) {
731 return onlyUsesFP(UseMI, MRI, TRI, Depth + 1) ||
732 prefersFPUse(UseMI, MRI, TRI);
733 });
734 }
735
736 case TargetOpcode::G_FPTOSI:
737 case TargetOpcode::G_FPTOUI:
738 case TargetOpcode::G_FPTOSI_SAT:
739 case TargetOpcode::G_FPTOUI_SAT:
740 case TargetOpcode::G_FCMP:
741 case TargetOpcode::G_LROUND:
742 case TargetOpcode::G_LLROUND:
743 case TargetOpcode::G_CLMUL:
744 case AArch64::G_PMULL:
745 case AArch64::G_SLI:
746 case AArch64::G_SRI:
747 case AArch64::G_FPTRUNC_ODD:
748 return true;
749 case TargetOpcode::G_INTRINSIC:
751 case Intrinsic::aarch64_neon_fcvtas:
752 case Intrinsic::aarch64_neon_fcvtau:
753 case Intrinsic::aarch64_neon_fcvtzs:
754 case Intrinsic::aarch64_neon_fcvtzu:
755 case Intrinsic::aarch64_neon_fcvtms:
756 case Intrinsic::aarch64_neon_fcvtmu:
757 case Intrinsic::aarch64_neon_fcvtns:
758 case Intrinsic::aarch64_neon_fcvtnu:
759 case Intrinsic::aarch64_neon_fcvtps:
760 case Intrinsic::aarch64_neon_fcvtpu:
761 return true;
762 default:
763 break;
764 }
765 break;
766 default:
767 break;
768 }
769 return hasFPConstraints(MI, MRI, TRI, Depth);
770}
771
772bool AArch64RegisterBankInfo::onlyDefinesFP(const MachineInstr &MI,
773 const MachineRegisterInfo &MRI,
775 unsigned Depth) const {
776 switch (MI.getOpcode()) {
777 case AArch64::G_DUP:
778 case AArch64::G_SADDLP:
779 case AArch64::G_UADDLP:
780 case TargetOpcode::G_SITOFP:
781 case TargetOpcode::G_UITOFP:
782 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
783 case TargetOpcode::G_INSERT_VECTOR_ELT:
784 case TargetOpcode::G_BUILD_VECTOR:
785 case TargetOpcode::G_BUILD_VECTOR_TRUNC:
786 case AArch64::G_SLI:
787 case AArch64::G_SRI:
788 case AArch64::G_FPTRUNC_ODD:
789 return true;
790 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
792 case Intrinsic::aarch64_neon_ld1x2:
793 case Intrinsic::aarch64_neon_ld1x3:
794 case Intrinsic::aarch64_neon_ld1x4:
795 case Intrinsic::aarch64_neon_ld2:
796 case Intrinsic::aarch64_neon_ld2lane:
797 case Intrinsic::aarch64_neon_ld2r:
798 case Intrinsic::aarch64_neon_ld3:
799 case Intrinsic::aarch64_neon_ld3lane:
800 case Intrinsic::aarch64_neon_ld3r:
801 case Intrinsic::aarch64_neon_ld4:
802 case Intrinsic::aarch64_neon_ld4lane:
803 case Intrinsic::aarch64_neon_ld4r:
804 return true;
805 default:
806 break;
807 }
808 break;
809 default:
810 break;
811 }
812 return hasFPConstraints(MI, MRI, TRI, Depth);
813}
814
815bool AArch64RegisterBankInfo::prefersFPUse(const MachineInstr &MI,
816 const MachineRegisterInfo &MRI,
818 unsigned Depth) const {
819 switch (MI.getOpcode()) {
820 case TargetOpcode::G_SITOFP:
821 case TargetOpcode::G_UITOFP:
822 return MRI.getType(MI.getOperand(0).getReg()).getSizeInBits() ==
823 MRI.getType(MI.getOperand(1).getReg()).getSizeInBits();
824 }
825 return onlyDefinesFP(MI, MRI, TRI, Depth);
826}
827
828bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
829 // GMemOperation because we also want to match indexed loads.
830 auto *MemOp = cast<GMemOperation>(&MI);
831 const Value *LdVal = MemOp->getMMO().getValue();
832 if (!LdVal)
833 return false;
834
835 Type *EltTy = nullptr;
836 if (const GlobalValue *GV = dyn_cast<GlobalValue>(LdVal)) {
837 EltTy = GV->getValueType();
838 // Look at the first element of the struct to determine the type we are
839 // loading
840 while (StructType *StructEltTy = dyn_cast<StructType>(EltTy)) {
841 if (StructEltTy->getNumElements() == 0)
842 break;
843 EltTy = StructEltTy->getTypeAtIndex(0U);
844 }
845 // Look at the first element of the array to determine its type
846 if (isa<ArrayType>(EltTy))
847 EltTy = EltTy->getArrayElementType();
848 } else if (!isa<Constant>(LdVal)) {
849 // FIXME: grubbing around uses is pretty ugly, but with no more
850 // `getPointerElementType` there's not much else we can do.
851 for (const auto *LdUser : LdVal->users()) {
852 if (isa<LoadInst>(LdUser)) {
853 EltTy = LdUser->getType();
854 break;
855 }
856 if (isa<StoreInst>(LdUser) && LdUser->getOperand(1) == LdVal) {
857 EltTy = LdUser->getOperand(0)->getType();
858 break;
859 }
860 }
861 }
862 return EltTy && EltTy->isFPOrFPVectorTy();
863}
864
867 const unsigned Opc = MI.getOpcode();
868
869 // Try the default logic for non-generic instructions that are either copies
870 // or already have some operands assigned to banks.
871 if ((Opc != TargetOpcode::COPY && !isPreISelGenericOpcode(Opc)) ||
872 Opc == TargetOpcode::G_PHI) {
875 if (Mapping.isValid())
876 return Mapping;
877 }
878
879 const MachineFunction &MF = *MI.getParent()->getParent();
880 const MachineRegisterInfo &MRI = MF.getRegInfo();
883
884 switch (Opc) {
885 // G_{F|S|U}REM are not listed because they are not legal.
886 // Arithmetic ops.
887 case TargetOpcode::G_ADD:
888 case TargetOpcode::G_SUB:
889 case TargetOpcode::G_PTR_ADD:
890 case TargetOpcode::G_MUL:
891 case TargetOpcode::G_SDIV:
892 case TargetOpcode::G_UDIV:
893 // Bitwise ops.
894 case TargetOpcode::G_AND:
895 case TargetOpcode::G_OR:
896 case TargetOpcode::G_XOR:
897 // Floating point ops.
898 case TargetOpcode::G_FADD:
899 case TargetOpcode::G_FSUB:
900 case TargetOpcode::G_FMUL:
901 case TargetOpcode::G_FDIV:
902 case TargetOpcode::G_FMAXIMUM:
903 case TargetOpcode::G_FMINIMUM:
904 return getSameKindOfOperandsMapping(MI);
905 case TargetOpcode::G_FPEXT: {
906 LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
907 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
909 DefaultMappingID, /*Cost*/ 1,
910 getFPExtMapping(DstTy.getSizeInBits(), SrcTy.getSizeInBits()),
911 /*NumOperands*/ 2);
912 }
913 // Shifts.
914 case TargetOpcode::G_SHL:
915 case TargetOpcode::G_LSHR:
916 case TargetOpcode::G_ASHR: {
917 LLT ShiftAmtTy = MRI.getType(MI.getOperand(2).getReg());
918 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
919 if (ShiftAmtTy.getSizeInBits() == 64 && SrcTy.getSizeInBits() == 32)
922 return getSameKindOfOperandsMapping(MI);
923 }
924 case TargetOpcode::G_BITCAST: {
925 Register SrcReg = MI.getOperand(1).getReg();
926 const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
927 if (SrcRB) {
928 TypeSize Size = getSizeInBits(SrcReg, MRI, TRI);
931 getCopyMapping(SrcRB->getID(), SrcRB->getID(), Size),
932 // We only care about the mapping of the destination.
933 /*NumOperands=*/2);
934 }
935 [[fallthrough]];
936 }
937 case TargetOpcode::COPY: {
938 Register DstReg = MI.getOperand(0).getReg();
939 Register SrcReg = MI.getOperand(1).getReg();
940 // Check if one of the register is not a generic register.
941 if ((DstReg.isPhysical() || !MRI.getType(DstReg).isValid()) ||
942 (SrcReg.isPhysical() || !MRI.getType(SrcReg).isValid())) {
943 const RegisterBank *DstRB = getRegBank(DstReg, MRI, TRI);
944 const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
945 if (!DstRB)
946 DstRB = SrcRB;
947 else if (!SrcRB)
948 SrcRB = DstRB;
949 // If both RB are null that means both registers are generic.
950 // We shouldn't be here.
951 assert(DstRB && SrcRB && "Both RegBank were nullptr");
952 TypeSize Size = getSizeInBits(DstReg, MRI, TRI);
954 DefaultMappingID, copyCost(*DstRB, *SrcRB, Size),
955 getCopyMapping(DstRB->getID(), SrcRB->getID(), Size),
956 // We only care about the mapping of the destination.
957 /*NumOperands*/ 1);
958 }
959 // Both registers are generic
960 LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
961 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
962 TypeSize Size = DstTy.getSizeInBits();
963 bool DstIsGPR = !DstTy.isVector() && DstTy.getSizeInBits() <= 64;
964 bool SrcIsGPR = !SrcTy.isVector() && SrcTy.getSizeInBits() <= 64;
965 const RegisterBank &DstRB =
966 DstIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
967 const RegisterBank &SrcRB =
968 SrcIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
970 DefaultMappingID, copyCost(DstRB, SrcRB, Size),
971 getCopyMapping(DstRB.getID(), SrcRB.getID(), Size),
972 // We only care about the mapping of the destination for COPY.
973 /*NumOperands*/ Opc == TargetOpcode::G_BITCAST ? 2 : 1);
974 }
975 case TargetOpcode::G_CONSTANT: {
976 LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
977 TypeSize Size = DstTy.getSizeInBits();
978 if (!DstTy.isPointer() && (!DstTy.isScalar() || Size < 32 || Size > 64))
979 break;
980 // Scalar constants materialize in GPRs.
981 [[fallthrough]];
982 }
983 case TargetOpcode::G_BRCOND:
984 case TargetOpcode::G_FRAME_INDEX: {
985 // Operand 0 is the only banked operand and is mapped to GPR.
987 DefaultMappingID, /*Cost=*/1,
991 MRI.getType(MI.getOperand(0).getReg()).getSizeInBits()),
992 nullptr}),
993 /*NumOperands=*/2);
994 }
995 default:
996 break;
997 }
998
999 unsigned NumOperands = MI.getNumOperands();
1000 unsigned MappingID = DefaultMappingID;
1001
1002 // Track the size and bank of each register. We don't do partial mappings.
1003 SmallVector<unsigned, 4> OpSize(NumOperands);
1004 SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands);
1005 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
1006 auto &MO = MI.getOperand(Idx);
1007 if (!MO.isReg() || !MO.getReg())
1008 continue;
1009
1010 LLT Ty = MRI.getType(MO.getReg());
1011 if (!Ty.isValid())
1012 continue;
1013 OpSize[Idx] = Ty.getSizeInBits().getKnownMinValue();
1014
1015 // As a top-level guess, vectors including both scalable and non-scalable
1016 // ones go in FPRs, scalars and pointers in GPRs.
1017 // For floating-point instructions, scalars go in FPRs.
1018 if (Ty.isVector())
1019 OpRegBankIdx[Idx] = PMI_FirstFPR;
1021 (MO.isDef() && onlyDefinesFP(MI, MRI, TRI)) ||
1022 (MO.isUse() && onlyUsesFP(MI, MRI, TRI)) ||
1023 Ty.getSizeInBits() > 64)
1024 OpRegBankIdx[Idx] = PMI_FirstFPR;
1025 else
1026 OpRegBankIdx[Idx] = PMI_FirstGPR;
1027 }
1028
1029 unsigned Cost = 1;
1030 // Some of the floating-point instructions have mixed GPR and FPR operands:
1031 // fine-tune the computed mapping.
1032 switch (Opc) {
1033 case TargetOpcode::G_CONSTANT: {
1034 Register Dst = MI.getOperand(0).getReg();
1035 LLT DstTy = MRI.getType(Dst);
1036 if (DstTy.isScalar() && DstTy.getSizeInBits() < 32)
1037 MappingID = CustomMappingID;
1038 break;
1039 }
1040 case TargetOpcode::G_FCONSTANT: {
1041 if (preferGPRForFPImm(MI, MRI, STI)) {
1042 // Materialize in GPR and rely on later bank copies for FP uses.
1043 MappingID = CustomMappingID;
1044 OpRegBankIdx = {PMI_FirstGPR};
1045 }
1046 break;
1047 }
1048 case AArch64::G_DUP: {
1049 Register ScalarReg = MI.getOperand(1).getReg();
1050 LLT ScalarTy = MRI.getType(ScalarReg);
1051 auto ScalarDef = MRI.getVRegDef(ScalarReg);
1052 // We want to select dup(load) into LD1R.
1053 if (ScalarDef->getOpcode() == TargetOpcode::G_LOAD)
1054 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1055 // s8 is an exception for G_DUP, which we always want on gpr.
1056 else if (ScalarTy.getSizeInBits() != 8 &&
1057 (getRegBank(ScalarReg, MRI, TRI) == &AArch64::FPRRegBank ||
1058 onlyDefinesFP(*ScalarDef, MRI, TRI)))
1059 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1060 else {
1061 if (ScalarTy.getSizeInBits() < 32 &&
1062 getRegBank(ScalarReg, MRI, TRI) == &AArch64::GPRRegBank) {
1063 // Calls applyMappingImpl()
1064 MappingID = CustomMappingID;
1065 }
1066 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR};
1067 }
1068 break;
1069 }
1070 case TargetOpcode::G_TRUNC: {
1071 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
1072 if (!SrcTy.isVector() && SrcTy.getSizeInBits() == 128)
1073 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1074 break;
1075 }
1076 case TargetOpcode::G_SITOFP:
1077 case TargetOpcode::G_UITOFP: {
1078 if (MRI.getType(MI.getOperand(0).getReg()).isVector())
1079 break;
1080 // Integer to FP conversions don't necessarily happen between GPR -> FPR
1081 // regbanks. They can also be done within an FPR register.
1082 Register SrcReg = MI.getOperand(1).getReg();
1083 if (getRegBank(SrcReg, MRI, TRI) == &AArch64::FPRRegBank &&
1084 MRI.getType(SrcReg).getSizeInBits() ==
1085 MRI.getType(MI.getOperand(0).getReg()).getSizeInBits())
1086 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1087 else
1088 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR};
1089 break;
1090 }
1091 case TargetOpcode::G_FPTOSI_SAT:
1092 case TargetOpcode::G_FPTOUI_SAT:
1093 case TargetOpcode::G_FPTOSI:
1094 case TargetOpcode::G_FPTOUI:
1095 case TargetOpcode::G_INTRINSIC_LRINT:
1096 case TargetOpcode::G_INTRINSIC_LLRINT:
1097 case TargetOpcode::G_LROUND:
1098 case TargetOpcode::G_LLROUND: {
1099 LLT DstType = MRI.getType(MI.getOperand(0).getReg());
1100 if (DstType.isVector())
1101 break;
1102 if (DstType == LLT::scalar(16)) {
1103 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1104 break;
1105 }
1106 TypeSize DstSize = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
1107 TypeSize SrcSize = getSizeInBits(MI.getOperand(1).getReg(), MRI, TRI);
1108 if (((DstSize == SrcSize) || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1109 all_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1110 [&](const MachineInstr &UseMI) {
1111 return onlyUsesFP(UseMI, MRI, TRI) ||
1112 prefersFPUse(UseMI, MRI, TRI);
1113 }))
1114 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1115 else
1116 OpRegBankIdx = {PMI_FirstGPR, PMI_FirstFPR};
1117 break;
1118 }
1119 case TargetOpcode::G_FCMP: {
1120 // If the result is a vector, it must use a FPR.
1122 MRI.getType(MI.getOperand(0).getReg()).isVector() ? PMI_FirstFPR
1123 : PMI_FirstGPR;
1124 OpRegBankIdx = {Idx0,
1125 /* Predicate */ PMI_None, PMI_FirstFPR, PMI_FirstFPR};
1126 break;
1127 }
1128 case TargetOpcode::G_BITCAST:
1129 // This is going to be a cross register bank copy and this is expensive.
1130 if (OpRegBankIdx[0] != OpRegBankIdx[1])
1131 Cost = copyCost(
1132 *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[0]].RegBank,
1133 *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[1]].RegBank,
1134 TypeSize::getFixed(OpSize[0]));
1135 break;
1136 case TargetOpcode::G_LOAD: {
1137 // Loading in vector unit is slightly more expensive.
1138 // This is actually only true for the LD1R and co instructions,
1139 // but anyway for the fast mode this number does not matter and
1140 // for the greedy mode the cost of the cross bank copy will
1141 // offset this number.
1142 // FIXME: Should be derived from the scheduling model.
1143 if (OpRegBankIdx[0] != PMI_FirstGPR) {
1144 Cost = 2;
1145 break;
1146 }
1147
1148 if (cast<GLoad>(MI).isAtomic()) {
1149 // Atomics always use GPR destinations. Don't refine any further.
1150 OpRegBankIdx[0] = PMI_FirstGPR;
1151 if (MRI.getType(MI.getOperand(0).getReg()).getSizeInBits() < 32)
1152 MappingID = CustomMappingID;
1153 break;
1154 }
1155
1156 // Try to guess the type of the load from the MMO.
1157 if (isLoadFromFPType(MI)) {
1158 OpRegBankIdx[0] = PMI_FirstFPR;
1159 break;
1160 }
1161
1162 // Check if that load feeds fp instructions.
1163 // In that case, we want the default mapping to be on FPR
1164 // instead of blind map every scalar to GPR.
1165 if (any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1166 [&](const MachineInstr &UseMI) {
1167 // If we have at least one direct or indirect use
1168 // in a FP instruction,
1169 // assume this was a floating point load in the IR. If it was
1170 // not, we would have had a bitcast before reaching that
1171 // instruction.
1172 //
1173 // Int->FP conversion operations are also captured in
1174 // prefersFPUse().
1175
1176 if (isPHIWithFPConstraints(UseMI, MRI, TRI))
1177 return true;
1178
1179 return onlyUsesFP(UseMI, MRI, TRI) ||
1180 prefersFPUse(UseMI, MRI, TRI);
1181 }))
1182 OpRegBankIdx[0] = PMI_FirstFPR;
1183
1184 // On GPR, extend any load < 32bits to 32bit.
1185 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
1186 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1187 MappingID = CustomMappingID;
1188 break;
1189 }
1190 case TargetOpcode::G_STORE:
1191 // Check if that store is fed by fp instructions.
1192 if (OpRegBankIdx[0] == PMI_FirstGPR) {
1193 Register VReg = MI.getOperand(0).getReg();
1194 if (VReg) {
1195 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1196 if (onlyDefinesFP(*DefMI, MRI, TRI)) {
1197 OpRegBankIdx[0] = PMI_FirstFPR;
1198 break;
1199 }
1200 }
1201
1202 // On GPR, extend any store < 32bits to 32bit.
1203 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
1204 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1205 MappingID = CustomMappingID;
1206 }
1207 break;
1208 case TargetOpcode::G_INDEXED_STORE:
1209 if (OpRegBankIdx[1] == PMI_FirstGPR) {
1210 Register VReg = MI.getOperand(1).getReg();
1211 if (!VReg)
1212 break;
1213 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1214 if (onlyDefinesFP(*DefMI, MRI, TRI))
1215 OpRegBankIdx[1] = PMI_FirstFPR;
1216 break;
1217 }
1218 break;
1219 case TargetOpcode::G_INDEXED_SEXTLOAD:
1220 case TargetOpcode::G_INDEXED_ZEXTLOAD:
1221 // These should always be GPR.
1222 OpRegBankIdx[0] = PMI_FirstGPR;
1223 break;
1224 case TargetOpcode::G_INDEXED_LOAD: {
1225 if (isLoadFromFPType(MI))
1226 OpRegBankIdx[0] = PMI_FirstFPR;
1227 break;
1228 }
1229 case TargetOpcode::G_SELECT: {
1230 // If the destination is FPR, preserve that.
1231 if (OpRegBankIdx[0] != PMI_FirstGPR)
1232 break;
1233
1234 // If we're taking in vectors, we have no choice but to put everything on
1235 // FPRs, except for the condition. The condition must always be on a GPR.
1236 LLT SrcTy = MRI.getType(MI.getOperand(2).getReg());
1237 if (SrcTy.isVector()) {
1239 break;
1240 }
1241
1242 // Try to minimize the number of copies. If we have more floating point
1243 // constrained values than not, then we'll put everything on FPR. Otherwise,
1244 // everything has to be on GPR.
1245 unsigned NumFP = 0;
1246
1247 // Check if the uses of the result always produce floating point values.
1248 //
1249 // For example:
1250 //
1251 // %z = G_SELECT %cond %x %y
1252 // fpr = G_FOO %z ...
1253 if (any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1254 [&](MachineInstr &MI) { return onlyUsesFP(MI, MRI, TRI); }))
1255 ++NumFP;
1256
1257 // Check if the defs of the source values always produce floating point
1258 // values.
1259 //
1260 // For example:
1261 //
1262 // %x = G_SOMETHING_ALWAYS_FLOAT %a ...
1263 // %z = G_SELECT %cond %x %y
1264 //
1265 // Also check whether or not the sources have already been decided to be
1266 // FPR. Keep track of this.
1267 //
1268 // This doesn't check the condition, since it's just whatever is in NZCV.
1269 // This isn't passed explicitly in a register to fcsel/csel.
1270 for (unsigned Idx = 2; Idx < 4; ++Idx) {
1271 Register VReg = MI.getOperand(Idx).getReg();
1272 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1273 if (getRegBank(VReg, MRI, TRI) == &AArch64::FPRRegBank ||
1274 onlyDefinesFP(*DefMI, MRI, TRI))
1275 ++NumFP;
1276 }
1277
1278 // If we have more FP constraints than not, then move everything over to
1279 // FPR.
1280 if (NumFP >= 2)
1282
1283 break;
1284 }
1285 case TargetOpcode::G_UNMERGE_VALUES: {
1286 // If the first operand belongs to a FPR register bank, then make sure that
1287 // we preserve that.
1288 if (OpRegBankIdx[0] != PMI_FirstGPR)
1289 break;
1290
1291 LLT SrcTy = MRI.getType(MI.getOperand(MI.getNumOperands()-1).getReg());
1292 // UNMERGE into scalars from a vector should always use FPR.
1293 // Likewise if any of the uses are FP instructions.
1294 if (SrcTy.isVector() || SrcTy == LLT::scalar(128) ||
1295 any_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1296 [&](MachineInstr &MI) { return onlyUsesFP(MI, MRI, TRI); })) {
1297 // Set the register bank of every operand to FPR.
1298 for (unsigned Idx = 0, NumOperands = MI.getNumOperands();
1299 Idx < NumOperands; ++Idx)
1300 OpRegBankIdx[Idx] = PMI_FirstFPR;
1301 }
1302 break;
1303 }
1304 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
1305 // Destination and source need to be FPRs.
1306 OpRegBankIdx[0] = PMI_FirstFPR;
1307 OpRegBankIdx[1] = PMI_FirstFPR;
1308
1309 // Index needs to be a GPR.
1310 OpRegBankIdx[2] = PMI_FirstGPR;
1311 break;
1312 case AArch64::G_SQSHLU_I:
1313 // Destination and source need to be FPRs.
1314 OpRegBankIdx[0] = PMI_FirstFPR;
1315 OpRegBankIdx[1] = PMI_FirstFPR;
1316
1317 // Shift Index needs to be a GPR.
1318 OpRegBankIdx[2] = PMI_FirstGPR;
1319 break;
1320
1321 case TargetOpcode::G_INSERT_VECTOR_ELT:
1322 OpRegBankIdx[0] = PMI_FirstFPR;
1323 OpRegBankIdx[1] = PMI_FirstFPR;
1324
1325 // The element may be either a GPR or FPR. Preserve that behaviour.
1326 if (getRegBank(MI.getOperand(2).getReg(), MRI, TRI) == &AArch64::FPRRegBank)
1327 OpRegBankIdx[2] = PMI_FirstFPR;
1328 else {
1329 // If the type is i8/i16, and the regbank will be GPR, then we change the
1330 // type to i32 in applyMappingImpl.
1331 LLT Ty = MRI.getType(MI.getOperand(2).getReg());
1332 if (Ty.getSizeInBits() == 8 || Ty.getSizeInBits() == 16) {
1333 // Calls applyMappingImpl()
1334 MappingID = CustomMappingID;
1335 }
1336 OpRegBankIdx[2] = PMI_FirstGPR;
1337 }
1338
1339 // Index needs to be a GPR.
1340 OpRegBankIdx[3] = PMI_FirstGPR;
1341 break;
1342 case TargetOpcode::G_EXTRACT: {
1343 // For s128 sources we have to use fpr unless we know otherwise.
1344 auto Src = MI.getOperand(1).getReg();
1345 LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
1346 if (SrcTy.getSizeInBits() != 128)
1347 break;
1348 auto Idx = MRI.getRegClassOrNull(Src) == &AArch64::XSeqPairsClassRegClass
1349 ? PMI_FirstGPR
1350 : PMI_FirstFPR;
1351 OpRegBankIdx[0] = Idx;
1352 OpRegBankIdx[1] = Idx;
1353 break;
1354 }
1355 case TargetOpcode::G_BUILD_VECTOR: {
1356 // If the first source operand belongs to a FPR register bank, then make
1357 // sure that we preserve that.
1358 if (OpRegBankIdx[1] != PMI_FirstGPR)
1359 break;
1360 Register VReg = MI.getOperand(1).getReg();
1361 if (!VReg)
1362 break;
1363
1364 // Get the instruction that defined the source operand reg, and check if
1365 // it's a floating point operation. Or, if it's a type like s16 which
1366 // doesn't have a exact size gpr register class. The exception is if the
1367 // build_vector has all constant operands, which may be better to leave as
1368 // gpr without copies, so it can be matched in imported patterns.
1369 MachineInstr *DefMI = MRI.getVRegDef(VReg);
1370 unsigned DefOpc = DefMI->getOpcode();
1371 const LLT SrcTy = MRI.getType(VReg);
1372 if (all_of(MI.operands(), [&](const MachineOperand &Op) {
1373 return Op.isDef() || MRI.getVRegDef(Op.getReg())->getOpcode() ==
1374 TargetOpcode::G_CONSTANT;
1375 }))
1376 break;
1378 SrcTy.getSizeInBits() < 32 ||
1379 getRegBank(VReg, MRI, TRI) == &AArch64::FPRRegBank) {
1380 // Have a floating point op.
1381 // Make sure every operand gets mapped to a FPR register class.
1382 unsigned NumOperands = MI.getNumOperands();
1383 for (unsigned Idx = 0; Idx < NumOperands; ++Idx)
1384 OpRegBankIdx[Idx] = PMI_FirstFPR;
1385 }
1386 break;
1387 }
1388 case TargetOpcode::G_VECREDUCE_FADD:
1389 case TargetOpcode::G_VECREDUCE_FMUL:
1390 case TargetOpcode::G_VECREDUCE_FMAX:
1391 case TargetOpcode::G_VECREDUCE_FMIN:
1392 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1393 case TargetOpcode::G_VECREDUCE_FMINIMUM:
1394 case TargetOpcode::G_VECREDUCE_ADD:
1395 case TargetOpcode::G_VECREDUCE_MUL:
1396 case TargetOpcode::G_VECREDUCE_AND:
1397 case TargetOpcode::G_VECREDUCE_OR:
1398 case TargetOpcode::G_VECREDUCE_XOR:
1399 case TargetOpcode::G_VECREDUCE_SMAX:
1400 case TargetOpcode::G_VECREDUCE_SMIN:
1401 case TargetOpcode::G_VECREDUCE_UMAX:
1402 case TargetOpcode::G_VECREDUCE_UMIN:
1403 // Reductions produce a scalar value from a vector, the scalar should be on
1404 // FPR bank.
1405 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR};
1406 break;
1407 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
1408 case TargetOpcode::G_VECREDUCE_SEQ_FMUL:
1409 // These reductions also take a scalar accumulator input.
1410 // Assign them FPR for now.
1411 OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR, PMI_FirstFPR};
1412 break;
1413 case TargetOpcode::G_INTRINSIC:
1414 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: {
1415 switch (cast<GIntrinsic>(MI).getIntrinsicID()) {
1416 case Intrinsic::aarch64_neon_fcvtas:
1417 case Intrinsic::aarch64_neon_fcvtau:
1418 case Intrinsic::aarch64_neon_fcvtzs:
1419 case Intrinsic::aarch64_neon_fcvtzu:
1420 case Intrinsic::aarch64_neon_fcvtms:
1421 case Intrinsic::aarch64_neon_fcvtmu:
1422 case Intrinsic::aarch64_neon_fcvtns:
1423 case Intrinsic::aarch64_neon_fcvtnu:
1424 case Intrinsic::aarch64_neon_fcvtps:
1425 case Intrinsic::aarch64_neon_fcvtpu: {
1426 OpRegBankIdx[2] = PMI_FirstFPR;
1427 if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
1428 OpRegBankIdx[0] = PMI_FirstFPR;
1429 break;
1430 }
1431 TypeSize DstSize = getSizeInBits(MI.getOperand(0).getReg(), MRI, TRI);
1432 TypeSize SrcSize = getSizeInBits(MI.getOperand(2).getReg(), MRI, TRI);
1433 // Fp conversions to i16 must be kept on fp register banks to ensure
1434 // proper saturation, as there are no 16-bit gprs.
1435 // In addition, conversion intrinsics have fpr output when the input
1436 // size matches the output size, or FPRCVT is present.
1437 if (DstSize == 16 ||
1438 ((DstSize == SrcSize || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1439 all_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
1440 [&](const MachineInstr &UseMI) {
1441 return onlyUsesFP(UseMI, MRI, TRI) ||
1442 prefersFPUse(UseMI, MRI, TRI);
1443 })))
1444 OpRegBankIdx[0] = PMI_FirstFPR;
1445 else
1446 OpRegBankIdx[0] = PMI_FirstGPR;
1447 break;
1448 }
1449 case Intrinsic::aarch64_neon_vcvtfxs2fp:
1450 case Intrinsic::aarch64_neon_vcvtfxu2fp:
1451 case Intrinsic::aarch64_neon_vcvtfp2fxs:
1452 case Intrinsic::aarch64_neon_vcvtfp2fxu:
1453 // Override these intrinsics, because they would have a partial
1454 // mapping. This is needed for 'half' types, which otherwise don't
1455 // get legalised correctly.
1456 OpRegBankIdx[0] = PMI_FirstFPR;
1457 OpRegBankIdx[2] = PMI_FirstFPR;
1458 // OpRegBankIdx[1] is the intrinsic ID.
1459 // OpRegBankIdx[3] is an integer immediate.
1460 break;
1461 default: {
1462 // Check if we know that the intrinsic has any constraints on its register
1463 // banks. If it does, then update the mapping accordingly.
1464 unsigned Idx = 0;
1465 if (onlyDefinesFP(MI, MRI, TRI))
1466 for (const auto &Op : MI.defs()) {
1467 if (Op.isReg())
1468 OpRegBankIdx[Idx] = PMI_FirstFPR;
1469 ++Idx;
1470 }
1471 else
1472 Idx += MI.getNumExplicitDefs();
1473
1474 if (onlyUsesFP(MI, MRI, TRI))
1475 for (const auto &Op : MI.explicit_uses()) {
1476 if (Op.isReg())
1477 OpRegBankIdx[Idx] = PMI_FirstFPR;
1478 ++Idx;
1479 }
1480 break;
1481 }
1482 }
1483 break;
1484 }
1485 }
1486
1487 // Finally construct the computed mapping.
1488 SmallVector<const ValueMapping *, 8> OpdsMapping(NumOperands);
1489 for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
1490 if (MI.getOperand(Idx).isReg() && MI.getOperand(Idx).getReg()) {
1491 LLT Ty = MRI.getType(MI.getOperand(Idx).getReg());
1492 if (!Ty.isValid())
1493 continue;
1494 auto Mapping =
1495 getValueMapping(OpRegBankIdx[Idx], TypeSize::getFixed(OpSize[Idx]));
1496 if (!Mapping->isValid())
1498
1499 OpdsMapping[Idx] = Mapping;
1500 }
1501 }
1502
1503 return getInstructionMapping(MappingID, Cost, getOperandsMapping(OpdsMapping),
1504 NumOperands);
1505}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define CHECK_VALUEMAP(RBName, Size)
static bool isFPIntrinsic(const MachineRegisterInfo &MRI, const MachineInstr &MI)
#define CHECK_VALUEMAP_3OPS(RBName, Size)
static bool foldTruncOfI32Constant(MachineInstr &MI, unsigned OpIdx, MachineRegisterInfo &MRI, const AArch64RegisterBankInfo &RBI)
static const unsigned CustomMappingID
#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB)
#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size)
#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize)
static bool preferGPRForFPImm(const MachineInstr &MI, const MachineRegisterInfo &MRI, const AArch64Subtarget &STI)
This file declares the targeting of the RegisterBankInfo class for AArch64.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineInstr unsigned OpIdx
ppc ctr loops verify
static const MCPhysReg FPR[]
FPR - The set of FP registers that should be allocated for arguments on Darwin and AIX.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static unsigned getRegBankBaseIdxOffset(unsigned RBIdx, TypeSize Size)
static const RegisterBankInfo::ValueMapping * getCopyMapping(unsigned DstBankID, unsigned SrcBankID, TypeSize Size)
Get the pointer to the ValueMapping of the operands of a copy instruction from the SrcBankID register...
static bool checkPartialMappingIdx(PartialMappingIdx FirstAlias, PartialMappingIdx LastAlias, ArrayRef< PartialMappingIdx > Order)
static const RegisterBankInfo::PartialMapping PartMappings[]
static const RegisterBankInfo::ValueMapping * getFPExtMapping(unsigned DstSize, unsigned SrcSize)
Get the instruction mapping for G_FPEXT.
static const RegisterBankInfo::ValueMapping * getValueMapping(PartialMappingIdx RBIdx, TypeSize Size)
Get the pointer to the ValueMapping representing the RegisterBank at RBIdx with a size of Size.
static const RegisterBankInfo::ValueMapping ValMappings[]
This class provides the information for the target register banks.
InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const override
Get the alternative mappings for MI.
unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const override
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const override
Get a register bank that covers RC.
AArch64RegisterBankInfo(const TargetRegisterInfo &TRI)
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
const AArch64RegisterInfo * getRegisterInfo() const override
const AArch64TargetLowering * getTargetLowering() const override
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns true if the target can instruction select the specified FP immediate natively.
bool isFPImmLegalAsFMov(const APFloat &Imm, EVT VT) const
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1563
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
Definition APInt.cpp:652
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:358
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr bool isVector() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
static LLT integer(unsigned SizeInBits)
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Register getReg(unsigned Idx) const
Get the register for the operand index.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const RegisterBank * getRegBank(Register Reg) const
Return the register bank of Reg.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
bool isValid() const
Check whether this object is valid.
virtual InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const
Get the alternative mappings for MI.
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
static void applyDefaultMapping(const OperandsMapper &OpdMapper)
Helper method to apply something that is like the default mapping.
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
TypeSize getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const
Get a register bank that covers RC.
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End.
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
SmallVector< const InstructionMapping *, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
virtual unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
This class implements the register bank concept.
LLVM_ABI bool covers(const TargetRegisterClass &RC) const
Check whether this register bank covers RC.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getID() const
Return the register class ID number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
Type * getArrayElementType() const
Definition Type.h: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)
OperandType
Operands are tagged with one of the values of this enum.
Definition MCInstrDesc.h:59
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1738
InstructionCost Cost
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1745
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:1706
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