LLVM 24.0.0git
AArch64RegisterInfo.cpp
Go to the documentation of this file.
1//===- AArch64RegisterInfo.cpp - AArch64 Register Information -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the AArch64 implementation of the TargetRegisterInfo
10// class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AArch64RegisterInfo.h"
16#include "AArch64InstrInfo.h"
19#include "AArch64Subtarget.h"
22#include "llvm/ADT/BitVector.h"
32#include "llvm/IR/Function.h"
34
35using namespace llvm;
36
37#define GET_CC_REGISTER_LISTS
38#include "AArch64GenCallingConv.inc"
39#define GET_REGINFO_TARGET_DESC
40#include "AArch64GenRegisterInfo.inc"
41
43 : AArch64GenRegisterInfo(AArch64::LR, 0, 0, 0, HwMode), TT(TT) {
45}
46
47/// Return whether the register needs a CFI entry. Not all unwinders may know
48/// about SVE registers, so we assume the lowest common denominator, i.e. the
49/// callee-saves required by the base ABI. For the SVE registers z8-z15 only the
50/// lower 64-bits (d8-d15) need to be saved. The lower 64-bits subreg is
51/// returned in \p RegToUseForCFI.
53 MCRegister &RegToUseForCFI) const {
54 if (AArch64::PPRRegClass.contains(Reg))
55 return false;
56
57 if (AArch64::ZPRRegClass.contains(Reg)) {
58 RegToUseForCFI = getSubReg(Reg, AArch64::dsub);
59 for (int I = 0; CSR_AArch64_AAPCS_SaveList[I]; ++I) {
60 if (CSR_AArch64_AAPCS_SaveList[I] == RegToUseForCFI)
61 return true;
62 }
63 return false;
64 }
65
66 RegToUseForCFI = Reg;
67 return true;
68}
69
70const MCPhysReg *
72 assert(MF && "Invalid MachineFunction pointer.");
73
74 auto &AFI = *MF->getInfo<AArch64FunctionInfo>();
75 const auto &F = MF->getFunction();
76 const auto *TLI = MF->getSubtarget<AArch64Subtarget>().getTargetLowering();
77 const bool Darwin = MF->getSubtarget<AArch64Subtarget>().isTargetDarwin();
78 const bool Windows = MF->getSubtarget<AArch64Subtarget>().isTargetWindows();
79
80 if (TLI->supportSwiftError() &&
81 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError)) {
82 if (Darwin)
83 return CSR_Darwin_AArch64_AAPCS_SwiftError_SaveList;
84 if (Windows)
85 return CSR_Win_AArch64_AAPCS_SwiftError_SaveList;
86 return CSR_AArch64_AAPCS_SwiftError_SaveList;
87 }
88
89 switch (F.getCallingConv()) {
91 // GHC set of callee saved regs is empty as all those regs are
92 // used for passing STG regs around
93 return CSR_AArch64_NoRegs_SaveList;
94
96 // FIXME: Windows likely need this to be altered for properly unwinding.
97 return CSR_AArch64_NoneRegs_SaveList;
98
100 return CSR_AArch64_AllRegs_SaveList;
101
103 return CSR_Win_AArch64_Arm64EC_Thunk_SaveList;
104
106 if (Darwin)
107 return CSR_Darwin_AArch64_RT_MostRegs_SaveList;
108 if (Windows)
109 return CSR_Win_AArch64_RT_MostRegs_SaveList;
110 return CSR_AArch64_RT_MostRegs_SaveList;
111
113 if (Darwin)
114 return CSR_Darwin_AArch64_RT_AllRegs_SaveList;
115 if (Windows)
116 return CSR_Win_AArch64_RT_AllRegs_SaveList;
117 return CSR_AArch64_RT_AllRegs_SaveList;
118
120 if (Darwin)
122 "Calling convention CFGuard_Check is unsupported on Darwin.");
123 return CSR_Win_AArch64_CFGuard_Check_SaveList;
124
126 if (Darwin)
127 return CSR_Darwin_AArch64_AAPCS_SwiftTail_SaveList;
128 if (Windows)
129 return CSR_Win_AArch64_AAPCS_SwiftTail_SaveList;
130 return CSR_AArch64_AAPCS_SwiftTail_SaveList;
131
133 if (Darwin)
134 return CSR_Darwin_AArch64_AAVPCS_SaveList;
135 if (Windows)
136 return CSR_Win_AArch64_AAVPCS_SaveList;
137 return CSR_AArch64_AAVPCS_SaveList;
138
140 if (Darwin)
142 "Calling convention SVE_VectorCall is unsupported on Darwin.");
143 if (Windows)
144 return CSR_Win_AArch64_SVE_AAPCS_SaveList;
145 return CSR_AArch64_SVE_AAPCS_SaveList;
146
149 "Calling convention "
150 "AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0 is only "
151 "supported to improve calls to SME ACLE save/restore/disable-za "
152 "functions, and is not intended to be used beyond that scope.");
153
156 "Calling convention "
157 "AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1 is "
158 "only supported to improve calls to SME ACLE __arm_get_current_vg "
159 "function, and is not intended to be used beyond that scope.");
160
163 "Calling convention "
164 "AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2 is "
165 "only supported to improve calls to SME ACLE __arm_sme_state "
166 "and is not intended to be used beyond that scope.");
167
169 if (Darwin)
170 return CSR_Darwin_AArch64_AAPCS_Win64_SaveList;
171 if (Windows)
172 return CSR_Win_AArch64_AAPCS_SaveList;
173 return CSR_AArch64_AAPCS_X18_SaveList;
174
176 if (Darwin)
177 return AFI.isSplitCSR() ? CSR_Darwin_AArch64_CXX_TLS_PE_SaveList
178 : CSR_Darwin_AArch64_CXX_TLS_SaveList;
179 // FIXME: this likely should be a `report_fatal_error` condition, however,
180 // that would be a departure from the previously implemented behaviour.
182
183 default:
184 if (Darwin)
185 return AFI.hasSVE_AAPCS(*MF) ? CSR_Darwin_AArch64_SVE_AAPCS_SaveList
186 : CSR_Darwin_AArch64_AAPCS_SaveList;
187 if (Windows)
188 return AFI.hasSVE_AAPCS(*MF) ? CSR_Win_AArch64_SVE_AAPCS_SaveList
189 : CSR_Win_AArch64_AAPCS_SaveList;
190 return AFI.hasSVE_AAPCS(*MF) ? CSR_AArch64_SVE_AAPCS_SaveList
191 : CSR_AArch64_AAPCS_SaveList;
192 }
193}
194
196 const MachineFunction *MF) const {
197 assert(MF && "Invalid MachineFunction pointer.");
200 return CSR_Darwin_AArch64_CXX_TLS_ViaCopy_SaveList;
201 return nullptr;
202}
203
205 MachineFunction &MF) const {
206 const MCPhysReg *CSRs = getCalleeSavedRegs(&MF);
207 SmallVector<MCPhysReg, 32> UpdatedCSRs;
208 for (const MCPhysReg *I = CSRs; *I; ++I)
209 UpdatedCSRs.push_back(*I);
210
211 for (size_t i = 0; i < AArch64::GPR64commonRegClass.getNumRegs(); ++i) {
213 UpdatedCSRs.push_back(AArch64::GPR64commonRegClass.getRegister(i));
214 }
215 }
216 // Register lists are zero-terminated.
217 UpdatedCSRs.push_back(0);
218 MF.getRegInfo().setCalleeSavedRegs(UpdatedCSRs);
219}
220
223 unsigned Idx) const {
224 // edge case for GPR/FPR register classes
225 if (RC == &AArch64::GPR32allRegClass && Idx == AArch64::hsub)
226 return &AArch64::FPR32RegClass;
227 else if (RC == &AArch64::GPR64allRegClass && Idx == AArch64::hsub)
228 return &AArch64::FPR64RegClass;
229
230 // Forward to TableGen's default version.
231 return AArch64GenRegisterInfo::getSubClassWithSubReg(RC, Idx);
232}
233
234const uint32_t *
236 CallingConv::ID CC) const {
238 "Invalid subtarget for getDarwinCallPreservedMask");
239
241 return CSR_Darwin_AArch64_CXX_TLS_RegMask;
243 return CSR_Darwin_AArch64_AAVPCS_RegMask;
245 return CSR_Darwin_AArch64_SVE_AAPCS_RegMask;
247 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0_RegMask;
249 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1_RegMask;
251 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2_RegMask;
254 "Calling convention CFGuard_Check is unsupported on Darwin.");
257 ->supportSwiftError() &&
258 MF.getFunction().getAttributes().hasAttrSomewhere(Attribute::SwiftError))
259 return CSR_Darwin_AArch64_AAPCS_SwiftError_RegMask;
260 if (CC == CallingConv::SwiftTail)
261 return CSR_Darwin_AArch64_AAPCS_SwiftTail_RegMask;
263 return CSR_Darwin_AArch64_RT_MostRegs_RegMask;
264 if (CC == CallingConv::PreserveAll)
265 return CSR_Darwin_AArch64_RT_AllRegs_RegMask;
266 return CSR_Darwin_AArch64_AAPCS_RegMask;
267}
268
269const uint32_t *
271 CallingConv::ID CC) const {
272 bool SCS = MF.getFunction().hasFnAttribute(Attribute::ShadowCallStack);
273 if (CC == CallingConv::GHC)
274 // This is academic because all GHC calls are (supposed to be) tail calls
275 return SCS ? CSR_AArch64_NoRegs_SCS_RegMask : CSR_AArch64_NoRegs_RegMask;
277 return SCS ? CSR_AArch64_NoneRegs_SCS_RegMask
278 : CSR_AArch64_NoneRegs_RegMask;
279 if (CC == CallingConv::AnyReg)
280 return SCS ? CSR_AArch64_AllRegs_SCS_RegMask : CSR_AArch64_AllRegs_RegMask;
281
282 // All the following calling conventions are handled differently on Darwin.
284 if (SCS)
285 report_fatal_error("ShadowCallStack attribute not supported on Darwin.");
286 return getDarwinCallPreservedMask(MF, CC);
287 }
288
290 return SCS ? CSR_AArch64_AAVPCS_SCS_RegMask : CSR_AArch64_AAVPCS_RegMask;
292 return SCS ? CSR_AArch64_SVE_AAPCS_SCS_RegMask
293 : CSR_AArch64_SVE_AAPCS_RegMask;
295 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0_RegMask;
297 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1_RegMask;
299 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2_RegMask;
301 return CSR_Win_AArch64_CFGuard_Check_RegMask;
303 ->supportSwiftError() &&
304 MF.getFunction().getAttributes().hasAttrSomewhere(Attribute::SwiftError))
305 return SCS ? CSR_AArch64_AAPCS_SwiftError_SCS_RegMask
306 : CSR_AArch64_AAPCS_SwiftError_RegMask;
307 if (CC == CallingConv::SwiftTail) {
308 if (SCS)
309 report_fatal_error("ShadowCallStack attribute not supported with swifttail");
310 return CSR_AArch64_AAPCS_SwiftTail_RegMask;
311 }
313 return SCS ? CSR_AArch64_RT_MostRegs_SCS_RegMask
314 : CSR_AArch64_RT_MostRegs_RegMask;
315 if (CC == CallingConv::PreserveAll)
316 return SCS ? CSR_AArch64_RT_AllRegs_SCS_RegMask
317 : CSR_AArch64_RT_AllRegs_RegMask;
318
319 return SCS ? CSR_AArch64_AAPCS_SCS_RegMask : CSR_AArch64_AAPCS_RegMask;
320}
321
323 const MachineFunction &MF) const {
325 return CSR_AArch64_AAPCS_RegMask;
326
327 return nullptr;
328}
329
331 if (TT.isOSDarwin())
332 return CSR_Darwin_AArch64_TLS_RegMask;
333
334 assert(TT.isOSBinFormatELF() && "Invalid target");
335 return CSR_AArch64_TLS_ELF_RegMask;
336}
337
339 const uint32_t **Mask) const {
340 uint32_t *UpdatedMask = MF.allocateRegMask();
341 unsigned RegMaskSize = MachineOperand::getRegMaskSize(getNumRegs());
342 memcpy(UpdatedMask, *Mask, sizeof(UpdatedMask[0]) * RegMaskSize);
343
344 for (size_t i = 0; i < AArch64::GPR64commonRegClass.getNumRegs(); ++i) {
346 for (MCPhysReg SubReg :
347 subregs_inclusive(AArch64::GPR64commonRegClass.getRegister(i))) {
348 // See TargetRegisterInfo::getCallPreservedMask for how to interpret the
349 // register mask.
350 UpdatedMask[SubReg / 32] |= 1u << (SubReg % 32);
351 }
352 }
353 }
354 *Mask = UpdatedMask;
355}
356
358 return CSR_AArch64_SMStartStop_RegMask;
359}
360
361const uint32_t *
363 return CSR_AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0_RegMask;
364}
365
367 return CSR_AArch64_NoRegs_RegMask;
368}
369
370const uint32_t *
372 CallingConv::ID CC) const {
373 // This should return a register mask that is the same as that returned by
374 // getCallPreservedMask but that additionally preserves the register used for
375 // the first i64 argument (which must also be the register used to return a
376 // single i64 return value)
377 //
378 // In case that the calling convention does not use the same register for
379 // both, the function should return NULL (does not currently apply)
380 assert(CC != CallingConv::GHC && "should not be GHC calling convention.");
382 return CSR_Darwin_AArch64_AAPCS_ThisReturn_RegMask;
383 return CSR_AArch64_AAPCS_ThisReturn_RegMask;
384}
385
387 return CSR_AArch64_StackProbe_Windows_RegMask;
388}
389
390std::optional<std::string>
392 MCRegister PhysReg) const {
393 if (hasBasePointer(MF) && MCRegisterInfo::regsOverlap(PhysReg, AArch64::X19))
394 return std::string("X19 is used as the frame base pointer register.");
395
397 bool warn = false;
398 if (MCRegisterInfo::regsOverlap(PhysReg, AArch64::X13) ||
399 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X14) ||
400 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X23) ||
401 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X24) ||
402 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X28))
403 warn = true;
404
405 for (unsigned i = AArch64::B16; i <= AArch64::B31; ++i)
406 if (MCRegisterInfo::regsOverlap(PhysReg, i))
407 warn = true;
408
409 if (warn)
410 return std::string(AArch64InstPrinter::getRegisterName(PhysReg)) +
411 " is clobbered by asynchronous signals when using Arm64EC.";
412 }
413
414 return {};
415}
416
419 const AArch64FrameLowering *TFI = getFrameLowering(MF);
420
421 BitVector Reserved(getNumRegs());
422 markSuperRegs(Reserved, AArch64::WSP);
423 markSuperRegs(Reserved, AArch64::WZR);
424
425 if (TFI->isFPReserved(MF))
426 markSuperRegs(Reserved, AArch64::W29);
427
429 // x13, x14, x23, x24, x28, and v16-v31 are clobbered by asynchronous
430 // signals, so we can't ever use them.
431 markSuperRegs(Reserved, AArch64::W13);
432 markSuperRegs(Reserved, AArch64::W14);
433 markSuperRegs(Reserved, AArch64::W23);
434 markSuperRegs(Reserved, AArch64::W24);
435 markSuperRegs(Reserved, AArch64::W28);
436 for (unsigned i = AArch64::B16; i <= AArch64::B31; ++i)
437 markSuperRegs(Reserved, i);
438 }
439
440 if (MF.getSubtarget<AArch64Subtarget>().isLFI()) {
441 markSuperRegs(Reserved, AArch64::W28);
442 markSuperRegs(Reserved, AArch64::W27);
443 markSuperRegs(Reserved, AArch64::W26);
444 markSuperRegs(Reserved, AArch64::W25);
445 if (!MF.getProperties().hasNoVRegs()) {
446 markSuperRegs(Reserved, AArch64::LR);
447 markSuperRegs(Reserved, AArch64::W30);
448 }
449 }
450
451 for (size_t i = 0; i < AArch64::GPR32commonRegClass.getNumRegs(); ++i) {
453 markSuperRegs(Reserved, AArch64::GPR32commonRegClass.getRegister(i));
454 }
455
456 if (hasBasePointer(MF))
457 markSuperRegs(Reserved, AArch64::W19);
458
459 // SLH uses register W16/X16 as the taint register.
460 if (MF.getFunction().hasFnAttribute(Attribute::SpeculativeLoadHardening))
461 markSuperRegs(Reserved, AArch64::W16);
462
463 // FFR is modelled as global state that cannot be allocated.
464 if (MF.getSubtarget<AArch64Subtarget>().hasSVE())
465 Reserved.set(AArch64::FFR);
466
467 // SME tiles are not allocatable.
468 if (MF.getSubtarget<AArch64Subtarget>().hasSME()) {
469 for (MCPhysReg SubReg : subregs_inclusive(AArch64::ZA))
470 Reserved.set(SubReg);
471 }
472
473 // VG cannot be allocated
474 Reserved.set(AArch64::VG);
475
476 if (MF.getSubtarget<AArch64Subtarget>().hasSME2()) {
477 for (MCSubRegIterator SubReg(AArch64::ZT0, this, /*self=*/true);
478 SubReg.isValid(); ++SubReg)
479 Reserved.set(*SubReg);
480 }
481
482 markSuperRegs(Reserved, AArch64::FPCR);
483 markSuperRegs(Reserved, AArch64::FPMR);
484 markSuperRegs(Reserved, AArch64::FPSR);
485
487 markSuperRegs(Reserved, AArch64::X27);
488 markSuperRegs(Reserved, AArch64::X28);
489 markSuperRegs(Reserved, AArch64::W27);
490 markSuperRegs(Reserved, AArch64::W28);
491 }
492
493 assert(checkAllSuperRegsMarked(Reserved));
494
495 // Add _HI registers after checkAllSuperRegsMarked as this check otherwise
496 // becomes considerably more expensive.
497 Reserved.set(AArch64::WSP_HI);
498 Reserved.set(AArch64::WZR_HI);
499 static_assert(AArch64::W30_HI - AArch64::W0_HI == 30,
500 "Unexpected order of registers");
501 Reserved.set(AArch64::W0_HI, AArch64::W30_HI + 1);
502 static_assert(AArch64::B31_HI - AArch64::B0_HI == 31,
503 "Unexpected order of registers");
504 Reserved.set(AArch64::B0_HI, AArch64::B31_HI + 1);
505 static_assert(AArch64::H31_HI - AArch64::H0_HI == 31,
506 "Unexpected order of registers");
507 Reserved.set(AArch64::H0_HI, AArch64::H31_HI + 1);
508 static_assert(AArch64::S31_HI - AArch64::S0_HI == 31,
509 "Unexpected order of registers");
510 Reserved.set(AArch64::S0_HI, AArch64::S31_HI + 1);
511 static_assert(AArch64::D31_HI - AArch64::D0_HI == 31,
512 "Unexpected order of registers");
513 Reserved.set(AArch64::D0_HI, AArch64::D31_HI + 1);
514 static_assert(AArch64::Q31_HI - AArch64::Q0_HI == 31,
515 "Unexpected order of registers");
516 Reserved.set(AArch64::Q0_HI, AArch64::Q31_HI + 1);
517
518 return Reserved;
519}
520
523 BitVector Reserved(getNumRegs());
524 for (size_t i = 0; i < AArch64::GPR32commonRegClass.getNumRegs(); ++i) {
525 // ReserveXRegister is set for registers manually reserved
526 // through +reserve-x#i.
528 markSuperRegs(Reserved, AArch64::GPR32commonRegClass.getRegister(i));
529 }
530 return Reserved;
531}
532
535 BitVector Reserved(getNumRegs());
536 for (size_t i = 0; i < AArch64::GPR32commonRegClass.getNumRegs(); ++i) {
538 markSuperRegs(Reserved, AArch64::GPR32commonRegClass.getRegister(i));
539 }
540
542 // In order to prevent the register allocator from using LR, we need to
543 // mark it as reserved. However we don't want to keep it reserved throughout
544 // the pipeline since it prevents other infrastructure from reasoning about
545 // it's liveness. We use the NoVRegs property instead of IsSSA because
546 // IsSSA is removed before VirtRegRewriter runs.
547 if (!MF.getProperties().hasNoVRegs())
548 // Reserve LR (X30) by marking from its subregister W30 because otherwise
549 // the register allocator could clobber the subregister.
550 markSuperRegs(Reserved, AArch64::W30);
551 }
552
553 assert(checkAllSuperRegsMarked(Reserved));
554
555 // Handle strictlyReservedRegs separately to avoid re-evaluating the assert,
556 // which becomes considerably expensive when considering the _HI registers.
558
559 return Reserved;
560}
561
563 MCRegister Reg) const {
564 return getReservedRegs(MF)[Reg];
565}
566
568 MCRegister Reg) const {
569 return getUserReservedRegs(MF)[Reg];
570}
571
573 MCRegister Reg) const {
574 return getStrictlyReservedRegs(MF)[Reg];
575}
576
578 for (size_t i = 0; i < 8; ++i) {
580 return true;
581 }
582 return false;
583}
584
586 const MachineFunction &MF) const {
587 const Function &F = MF.getFunction();
588 F.getContext().diagnose(DiagnosticInfoUnsupported{F, ("AArch64 doesn't support"
589 " function calls if any of the argument registers is reserved.")});
590}
591
593 MCRegister PhysReg) const {
594 // SLH uses register X16 as the taint register but it will fallback to a different
595 // method if the user clobbers it. So X16 is not reserved for inline asm but is
596 // for normal codegen.
597 if (MF.getFunction().hasFnAttribute(Attribute::SpeculativeLoadHardening) &&
598 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
599 return true;
600
601 // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
602 if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
603 return true;
604
605 return !isReservedReg(MF, PhysReg);
606}
607
610 return &AArch64::GPR64spRegClass;
611}
612
615 if (RC == &AArch64::CCRRegClass)
616 return &AArch64::GPR64RegClass; // Only MSR & MRS copy NZCV.
617 return RC;
618}
619
620MCRegister AArch64RegisterInfo::getBaseRegister() const { return AArch64::X19; }
621
623 const MachineFrameInfo &MFI = MF.getFrameInfo();
624
625 // In the presence of variable sized objects or funclets, if the fixed stack
626 // size is large enough that referencing from the FP won't result in things
627 // being in range relatively often, we can use a base pointer to allow access
628 // from the other direction like the SP normally works.
629 //
630 // Furthermore, if both variable sized objects are present, and the
631 // stack needs to be dynamically re-aligned, the base pointer is the only
632 // reliable way to reference the locals.
633 if (MFI.hasVarSizedObjects() || MF.hasEHFunclets()) {
634 if (hasStackRealignment(MF))
635 return true;
636
637 auto &ST = MF.getSubtarget<AArch64Subtarget>();
639 if (ST.hasSVE() || ST.isStreaming()) {
640 // Frames that have variable sized objects and scalable SVE objects,
641 // should always use a basepointer.
642 if (!AFI->hasCalculatedStackSizeSVE() || AFI->hasSVEStackSize())
643 return true;
644 }
645
646 // Frames with hazard padding can have a large offset between the frame
647 // pointer and GPR locals, which includes the emergency spill slot. If the
648 // emergency spill slot is not within range of the load/store instructions
649 // (which have a signed 9-bit range), we will fail to compile if it is used.
650 // Since hasBasePointer() is called before we know if we have hazard padding
651 // or an emergency spill slot we need to enable the basepointer
652 // conservatively.
653 if (ST.getStreamingHazardSize() &&
654 !AFI->getSMEFnAttrs().hasNonStreamingInterfaceAndBody()) {
655 return true;
656 }
657
658 // Conservatively estimate whether the negative offset from the frame
659 // pointer will be sufficient to reach. If a function has a smallish
660 // frame, it's less likely to have lots of spills and callee saved
661 // space, so it's all more likely to be within range of the frame pointer.
662 // If it's wrong, we'll materialize the constant and still get to the
663 // object; it's just suboptimal. Negative offsets use the unscaled
664 // load/store instructions, which have a 9-bit signed immediate.
665 return MFI.getLocalFrameSize() >= 256;
666 }
667
668 return false;
669}
670
672 MCRegister Reg) const {
675 bool IsVarArg = STI.isCallingConvWin64(MF.getFunction().getCallingConv(),
676 MF.getFunction().isVarArg());
677
678 auto HasReg = [](ArrayRef<MCRegister> RegList, MCRegister Reg) {
679 return llvm::is_contained(RegList, Reg);
680 };
681
682 switch (CC) {
683 default:
684 report_fatal_error("Unsupported calling convention.");
685 case CallingConv::GHC:
686 return HasReg(CC_AArch64_GHC_ArgRegs, Reg);
688 if (!MF.getFunction().isVarArg())
689 return HasReg(CC_AArch64_Preserve_None_ArgRegs, Reg);
690 [[fallthrough]];
691 case CallingConv::C:
699 if (STI.isTargetWindows()) {
700 if (IsVarArg)
701 return HasReg(CC_AArch64_Win64_VarArg_ArgRegs, Reg);
702 switch (CC) {
703 default:
704 return HasReg(CC_AArch64_Win64PCS_ArgRegs, Reg);
707 return HasReg(CC_AArch64_Win64PCS_Swift_ArgRegs, Reg) ||
708 HasReg(CC_AArch64_Win64PCS_ArgRegs, Reg);
709 }
710 }
711 if (!STI.isTargetDarwin()) {
712 switch (CC) {
713 default:
714 return HasReg(CC_AArch64_AAPCS_ArgRegs, Reg);
717 return HasReg(CC_AArch64_AAPCS_ArgRegs, Reg) ||
718 HasReg(CC_AArch64_AAPCS_Swift_ArgRegs, Reg);
719 }
720 }
721 if (!IsVarArg) {
722 switch (CC) {
723 default:
724 return HasReg(CC_AArch64_DarwinPCS_ArgRegs, Reg);
727 return HasReg(CC_AArch64_DarwinPCS_ArgRegs, Reg) ||
728 HasReg(CC_AArch64_DarwinPCS_Swift_ArgRegs, Reg);
729 }
730 }
731 if (STI.isTargetILP32())
732 return HasReg(CC_AArch64_DarwinPCS_ILP32_VarArg_ArgRegs, Reg);
733 return HasReg(CC_AArch64_DarwinPCS_VarArg_ArgRegs, Reg);
735 if (IsVarArg)
736 HasReg(CC_AArch64_Win64_VarArg_ArgRegs, Reg);
737 return HasReg(CC_AArch64_Win64PCS_ArgRegs, Reg);
739 return HasReg(CC_AArch64_Win64_CFGuard_Check_ArgRegs, Reg);
745 if (STI.isTargetWindows())
746 return HasReg(CC_AArch64_Win64PCS_ArgRegs, Reg);
747 return HasReg(CC_AArch64_AAPCS_ArgRegs, Reg);
748 }
749}
750
753 const AArch64FrameLowering *TFI = getFrameLowering(MF);
754 return TFI->hasFP(MF) ? AArch64::FP : AArch64::SP;
755}
756
758 const MachineFunction &MF) const {
759 return true;
760}
761
763 const MachineFunction &MF) const {
764 return true;
765}
766
767bool
769 // This function indicates whether the emergency spillslot should be placed
770 // close to the beginning of the stackframe (closer to FP) or the end
771 // (closer to SP).
772 //
773 // The beginning works most reliably if we have a frame pointer.
774 // In the presence of any non-constant space between FP and locals,
775 // (e.g. in case of stack realignment or a scalable SVE area), it is
776 // better to use SP or BP.
777 const AArch64FrameLowering &TFI = *getFrameLowering(MF);
779 assert((!MF.getSubtarget<AArch64Subtarget>().hasSVE() ||
781 "Expected SVE area to be calculated by this point");
782 return TFI.hasFP(MF) && !hasStackRealignment(MF) && !AFI->hasSVEStackSize() &&
784}
785
787 const MachineFunction &MF) const {
788 return true;
789}
790
791bool
793 const MachineFrameInfo &MFI = MF.getFrameInfo();
794 if (MF.disableFramePointerElim() && MFI.adjustsStack())
795 return true;
796 return MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken();
797}
798
799/// needsFrameBaseReg - Returns true if the instruction's frame index
800/// reference would be better served by a base register other than FP
801/// or SP. Used by LocalStackFrameAllocation to determine which frame index
802/// references it should create new base registers for.
804 int64_t Offset) const {
805 for (unsigned i = 0; !MI->getOperand(i).isFI(); ++i)
806 assert(i < MI->getNumOperands() &&
807 "Instr doesn't have FrameIndex operand!");
808
809 // It's the load/store FI references that cause issues, as it can be difficult
810 // to materialize the offset if it won't fit in the literal field. Estimate
811 // based on the size of the local frame and some conservative assumptions
812 // about the rest of the stack frame (note, this is pre-regalloc, so
813 // we don't know everything for certain yet) whether this offset is likely
814 // to be out of range of the immediate. Return true if so.
815
816 // We only generate virtual base registers for loads and stores, so
817 // return false for everything else.
818 if (!MI->mayLoad() && !MI->mayStore())
819 return false;
820
821 // Without a virtual base register, if the function has variable sized
822 // objects, all fixed-size local references will be via the frame pointer,
823 // Approximate the offset and see if it's legal for the instruction.
824 // Note that the incoming offset is based on the SP value at function entry,
825 // so it'll be negative.
826 MachineFunction &MF = *MI->getParent()->getParent();
827 const AArch64FrameLowering *TFI = getFrameLowering(MF);
828 MachineFrameInfo &MFI = MF.getFrameInfo();
829
830 // Estimate an offset from the frame pointer.
831 // Conservatively assume all GPR callee-saved registers get pushed.
832 // FP, LR, X19-X28, D8-D15. 64-bits each.
833 int64_t FPOffset = Offset - 16 * 20;
834 // Estimate an offset from the stack pointer.
835 // The incoming offset is relating to the SP at the start of the function,
836 // but when we access the local it'll be relative to the SP after local
837 // allocation, so adjust our SP-relative offset by that allocation size.
838 Offset += MFI.getLocalFrameSize();
839 // Assume that we'll have at least some spill slots allocated.
840 // FIXME: This is a total SWAG number. We should run some statistics
841 // and pick a real one.
842 Offset += 128; // 128 bytes of spill slots
843
844 // If there is a frame pointer, try using it.
845 // The FP is only available if there is no dynamic realignment. We
846 // don't know for sure yet whether we'll need that, so we guess based
847 // on whether there are any local variables that would trigger it.
848 if (TFI->hasFP(MF) && isFrameOffsetLegal(MI, AArch64::FP, FPOffset))
849 return false;
850
851 // If we can reference via the stack pointer or base pointer, try that.
852 // FIXME: This (and the code that resolves the references) can be improved
853 // to only disallow SP relative references in the live range of
854 // the VLA(s). In practice, it's unclear how much difference that
855 // would make, but it may be worth doing.
856 if (isFrameOffsetLegal(MI, AArch64::SP, Offset))
857 return false;
858
859 // If even offset 0 is illegal, we don't want a virtual base register.
860 if (!isFrameOffsetLegal(MI, AArch64::SP, 0))
861 return false;
862
863 // The offset likely isn't legal; we want to allocate a virtual base register.
864 return true;
865}
866
868 Register BaseReg,
869 int64_t Offset) const {
870 assert(MI && "Unable to get the legal offset for nil instruction.");
873}
874
875/// Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx
876/// at the beginning of the basic block.
879 int FrameIdx,
880 int64_t Offset) const {
881 MachineBasicBlock::iterator Ins = MBB->begin();
882 DebugLoc DL; // Defaults to "unknown"
883 if (Ins != MBB->end())
884 DL = Ins->getDebugLoc();
885 const MachineFunction &MF = *MBB->getParent();
886 const AArch64InstrInfo *TII =
887 MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
888 const MCInstrDesc &MCID = TII->get(AArch64::ADDXri);
889 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
890 Register BaseReg = MRI.createVirtualRegister(&AArch64::GPR64spRegClass);
891 MRI.constrainRegClass(BaseReg, TII->getRegClass(MCID, 0));
892 unsigned Shifter = AArch64_AM::getShifterImm(AArch64_AM::LSL, 0);
893
894 BuildMI(*MBB, Ins, DL, MCID, BaseReg)
895 .addFrameIndex(FrameIdx)
896 .addImm(Offset)
897 .addImm(Shifter);
898
899 return BaseReg;
900}
901
903 int64_t Offset) const {
904 // ARM doesn't need the general 64-bit offsets
906
907 unsigned i = 0;
908 while (!MI.getOperand(i).isFI()) {
909 ++i;
910 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
911 }
912
913 const MachineFunction *MF = MI.getParent()->getParent();
914 const AArch64InstrInfo *TII =
915 MF->getSubtarget<AArch64Subtarget>().getInstrInfo();
916 bool Done = rewriteAArch64FrameIndex(MI, i, BaseReg, Off, TII);
917 assert(Done && "Unable to resolve frame index!");
918 (void)Done;
919}
920
921// Create a scratch register for the frame index elimination in an instruction.
922// This function has special handling of stack tagging loop pseudos, in which
923// case it can also change the instruction opcode.
924static Register
926 const AArch64InstrInfo *TII) {
927 // ST*Gloop have a reserved scratch register in operand 1. Use it, and also
928 // replace the instruction with the writeback variant because it will now
929 // satisfy the operand constraints for it.
930 Register ScratchReg;
931 if (MI.getOpcode() == AArch64::STGloop ||
932 MI.getOpcode() == AArch64::STZGloop) {
933 assert(FIOperandNum == 3 &&
934 "Wrong frame index operand for STGloop/STZGloop");
935 unsigned Op = MI.getOpcode() == AArch64::STGloop ? AArch64::STGloop_wback
936 : AArch64::STZGloop_wback;
937 ScratchReg = MI.getOperand(1).getReg();
938 MI.getOperand(3).ChangeToRegister(ScratchReg, false, false, true);
939 MI.setDesc(TII->get(Op));
940 MI.tieOperands(1, 3);
941 } else {
942 ScratchReg =
943 MI.getMF()->getRegInfo().createVirtualRegister(&AArch64::GPR64RegClass);
944 MI.getOperand(FIOperandNum)
945 .ChangeToRegister(ScratchReg, false, false, true);
946 }
947 return ScratchReg;
948}
949
952 // The smallest scalable element supported by scaled SVE addressing
953 // modes are predicates, which are 2 scalable bytes in size. So the scalable
954 // byte offset must always be a multiple of 2.
955 assert(Offset.getScalable() % 2 == 0 && "Invalid frame offset");
956
957 // Add fixed-sized offset using existing DIExpression interface.
959
960 unsigned VG = getDwarfRegNum(AArch64::VG, true);
961 int64_t VGSized = Offset.getScalable() / 2;
962 if (VGSized > 0) {
963 Ops.push_back(dwarf::DW_OP_constu);
964 Ops.push_back(VGSized);
965 Ops.append({dwarf::DW_OP_bregx, VG, 0ULL});
966 Ops.push_back(dwarf::DW_OP_mul);
967 Ops.push_back(dwarf::DW_OP_plus);
968 } else if (VGSized < 0) {
969 Ops.push_back(dwarf::DW_OP_constu);
970 Ops.push_back(-VGSized);
971 Ops.append({dwarf::DW_OP_bregx, VG, 0ULL});
972 Ops.push_back(dwarf::DW_OP_mul);
973 Ops.push_back(dwarf::DW_OP_minus);
974 }
975}
976
978 int SPAdj, unsigned FIOperandNum,
979 RegScavenger *RS) const {
980 assert(SPAdj == 0 && "Unexpected");
981
982 MachineInstr &MI = *II;
983 MachineBasicBlock &MBB = *MI.getParent();
984 MachineFunction &MF = *MBB.getParent();
985 const MachineFrameInfo &MFI = MF.getFrameInfo();
986 const AArch64InstrInfo *TII =
987 MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
988 const AArch64FrameLowering *TFI = getFrameLowering(MF);
989 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
990 bool Tagged =
991 MI.getOperand(FIOperandNum).getTargetFlags() & AArch64II::MO_TAGGED;
992 Register FrameReg;
993
994 // Special handling of dbg_value, stackmap patchpoint statepoint instructions.
995 if (MI.getOpcode() == TargetOpcode::STACKMAP ||
996 MI.getOpcode() == TargetOpcode::PATCHPOINT ||
997 MI.getOpcode() == TargetOpcode::STATEPOINT) {
999 TFI->resolveFrameIndexReference(MF, FrameIndex, FrameReg,
1000 /*PreferFP=*/true,
1001 /*ForSimm=*/false);
1002 Offset += StackOffset::getFixed(MI.getOperand(FIOperandNum + 1).getImm());
1003 MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false /*isDef*/);
1004 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset.getFixed());
1005 return false;
1006 }
1007
1008 if (MI.getOpcode() == TargetOpcode::LOCAL_ESCAPE) {
1009 MachineOperand &FI = MI.getOperand(FIOperandNum);
1010 StackOffset Offset = TFI->getNonLocalFrameIndexReference(MF, FrameIndex);
1011 assert(!Offset.getScalable() &&
1012 "Frame offsets with a scalable component are not supported");
1013 FI.ChangeToImmediate(Offset.getFixed());
1014 return false;
1015 }
1016
1018 if (MI.getOpcode() == AArch64::TAGPstack) {
1019 // TAGPstack must use the virtual frame register in its 3rd operand.
1021 FrameReg = MI.getOperand(3).getReg();
1022 Offset = StackOffset::getFixed(MFI.getObjectOffset(FrameIndex) +
1024 } else if (Tagged) {
1026 MFI.getObjectOffset(FrameIndex) + (int64_t)MFI.getStackSize());
1027 if (MFI.hasVarSizedObjects() ||
1028 isAArch64FrameOffsetLegal(MI, SPOffset, nullptr, nullptr, nullptr) !=
1030 // Can't update to SP + offset in place. Precalculate the tagged pointer
1031 // in a scratch register.
1033 MF, FrameIndex, FrameReg, /*PreferFP=*/false, /*ForSimm=*/true);
1034 Register ScratchReg =
1035 MF.getRegInfo().createVirtualRegister(&AArch64::GPR64RegClass);
1036 emitFrameOffset(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg, Offset,
1037 TII);
1038 BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(AArch64::LDG), ScratchReg)
1039 .addReg(ScratchReg)
1040 .addReg(ScratchReg)
1041 .addImm(0);
1042 MI.getOperand(FIOperandNum)
1043 .ChangeToRegister(ScratchReg, false, false, true);
1044 return false;
1045 }
1046 FrameReg = AArch64::SP;
1047 Offset = StackOffset::getFixed(MFI.getObjectOffset(FrameIndex) +
1048 (int64_t)MFI.getStackSize());
1049 } else {
1051 MF, FrameIndex, FrameReg, /*PreferFP=*/false, /*ForSimm=*/true);
1052 }
1053
1054 // Modify MI as necessary to handle as much of 'Offset' as possible
1055 if (rewriteAArch64FrameIndex(MI, FIOperandNum, FrameReg, Offset, TII))
1056 return true;
1057
1058 assert((!RS || !RS->isScavengingFrameIndex(FrameIndex)) &&
1059 "Emergency spill slot is out of reach");
1060
1061 // If we get here, the immediate doesn't fit into the instruction. We folded
1062 // as much as possible above. Handle the rest, providing a register that is
1063 // SP+LargeImm.
1064 Register ScratchReg =
1066 emitFrameOffset(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg, Offset, TII);
1067 return false;
1068}
1069
1071 MachineFunction &MF) const {
1072 const AArch64FrameLowering *TFI = getFrameLowering(MF);
1073
1074 switch (RC->getID()) {
1075 default:
1076 return 0;
1077 case AArch64::GPR32RegClassID:
1078 case AArch64::GPR32spRegClassID:
1079 case AArch64::GPR32allRegClassID:
1080 case AArch64::GPR64spRegClassID:
1081 case AArch64::GPR64allRegClassID:
1082 case AArch64::GPR64RegClassID:
1083 case AArch64::GPR32commonRegClassID:
1084 case AArch64::GPR64commonRegClassID:
1085 return 32 - 1 // XZR/SP
1086 - (TFI->hasFP(MF) || TT.isOSDarwin()) // FP
1087 - MF.getSubtarget<AArch64Subtarget>().getNumXRegisterReserved()
1088 - hasBasePointer(MF); // X19
1089 case AArch64::FPR8RegClassID:
1090 case AArch64::FPR16RegClassID:
1091 case AArch64::FPR32RegClassID:
1092 case AArch64::FPR64RegClassID:
1093 case AArch64::FPR128RegClassID:
1094 return 32;
1095
1096 case AArch64::MatrixIndexGPR32_8_11RegClassID:
1097 case AArch64::MatrixIndexGPR32_12_15RegClassID:
1098 return 4;
1099
1100 case AArch64::DDRegClassID:
1101 case AArch64::DDDRegClassID:
1102 case AArch64::DDDDRegClassID:
1103 case AArch64::QQRegClassID:
1104 case AArch64::QQQRegClassID:
1105 case AArch64::QQQQRegClassID:
1106 return 32;
1107
1108 case AArch64::FPR128_loRegClassID:
1109 case AArch64::FPR64_loRegClassID:
1110 case AArch64::FPR16_loRegClassID:
1111 return 16;
1112 case AArch64::FPR128_0to7RegClassID:
1113 return 8;
1114 }
1115}
1116
1118 Register VirtReg, ArrayRef<MCPhysReg> Order,
1119 SmallVectorImpl<MCPhysReg> &Hints, const VirtRegMap *VRM,
1120 const MachineRegisterInfo &MRI, const TargetInstrInfo &TII,
1121 const AArch64Subtarget &ST, const LiveRegMatrix *Matrix) {
1122 const TargetRegisterClass *RegRC = MRI.getRegClass(VirtReg);
1123 if (!ST.useDistinctPredicateDstReg() ||
1124 !AArch64::PPRRegClass.hasSubClassEq(RegRC) || !MRI.hasOneDef(VirtReg) ||
1125 Order.size() < 2)
1126 return false;
1127
1128 const MachineInstr *DefInst = MRI.getOneDef(VirtReg)->getParent();
1129 if ((TII.get(DefInst->getOpcode()).TSFlags &
1131 return false;
1132
1133 Register Op1Reg = DefInst->getOperand(1).getReg();
1134 if (Op1Reg.isVirtual())
1135 Op1Reg = VRM->getPhys(Op1Reg);
1136
1137 // If no register is allocated for the general-predicate, it's not yet
1138 // possible to choose a distinct register.
1139 if (!Op1Reg.isValid())
1140 return false;
1141
1142 // Move Op1Reg as the least preferred register.
1143 //
1144 // This might result in callee-save spills when the function takes/returns
1145 // arguments in SVE registers (i.e. needs to preserve p4-p15) and can't reuse
1146 // p0-p3. That's why we limit it to non-callee saved registers or to
1147 // callee-saved registers that have already been allocated for other uses in
1148 // the function.
1149 DenseSet<unsigned> CSRs;
1150 for (unsigned I = 0;; ++I) {
1151 Register R = MRI.getCalleeSavedRegs()[I];
1152 if (!R.isValid())
1153 break;
1154 if (AArch64::PPRRegClass.contains(R))
1155 CSRs.insert(R);
1156 }
1157
1158 Hints.append(Order.begin(), Order.end());
1159 auto CanUseReg = [&](Register R) {
1160 return !CSRs.contains(R) || !MRI.def_empty(R) || Matrix->isPhysRegUsed(R);
1161 };
1162 llvm::stable_sort(Hints, [&](Register A, Register B) {
1163 bool PrefA = (A != Op1Reg) && CanUseReg(A);
1164 bool PrefB = (B != Op1Reg) && CanUseReg(B);
1165 return PrefA && !PrefB;
1166 });
1167 return true;
1168}
1169
1170// We add regalloc hints for different cases:
1171// * Choosing a better destination operand for predicated SVE instructions
1172// where the inactive lanes are undef, by choosing a register that is not
1173// unique to the other operands of the instruction.
1174//
1175// * Improve register allocation for SME multi-vector instructions where we can
1176// benefit from the strided- and contiguous register multi-vector tuples.
1177//
1178// Here COPY_INTO_TRANSPOSED_TUPLE nodes are created to improve register
1179// allocation where a consecutive multi-vector tuple is constructed from the
1180// same indices of multiple strided loads. This may still result in
1181// unnecessary copies between the loads and the tuple. Here we try to return a
1182// hint to assign the contiguous ZPRMulReg starting at the same register as
1183// the first operand of the pseudo, which should be a subregister of the first
1184// strided load.
1185//
1186// For example, if the first strided load has been assigned $z16_z20_z24_z28
1187// and the operands of the pseudo are each accessing subregister zsub2, we
1188// should look through through Order to find a contiguous register which
1189// begins with $z24 (i.e. $z24_z25_z26_z27).
1191 Register VirtReg, ArrayRef<MCPhysReg> Order,
1193 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
1194 auto &ST = MF.getSubtarget<AArch64Subtarget>();
1195 const AArch64InstrInfo *TII =
1196 MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
1197 const MachineRegisterInfo &MRI = MF.getRegInfo();
1198
1199 bool ConsiderOnlyHints =
1200 TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints, MF, VRM);
1201
1202 // For predicated SVE instructions where the inactive lanes are undef,
1203 // pick a destination register that is not unique to avoid introducing
1204 // a movprfx.
1205 const TargetRegisterClass *RegRC = MRI.getRegClass(VirtReg);
1206 if (AArch64::ZPRRegClass.hasSubClassEq(RegRC)) {
1207 for (const MachineOperand &DefOp : MRI.def_operands(VirtReg)) {
1208 const MachineInstr &Def = *DefOp.getParent();
1209 if (DefOp.isImplicit() ||
1210 (TII->get(Def.getOpcode()).TSFlags & AArch64::FalseLanesMask) !=
1212 continue;
1213
1214 unsigned InstFlags =
1215 TII->get(AArch64::getSVEPseudoMap(Def.getOpcode())).TSFlags;
1216
1217 for (MCPhysReg R : Order) {
1218 auto AddHintIfSuitable = [&](MCPhysReg R,
1219 const MachineOperand &MO) -> bool {
1220 // R is a suitable register hint if R can reuse one of the other
1221 // source operands.
1222 MCPhysReg PhysReg = VRM->getPhys(MO.getReg());
1223 if (PhysReg && MO.getSubReg())
1224 PhysReg = getSubReg(PhysReg, MO.getSubReg());
1225 if (PhysReg != R)
1226 return false;
1227 Hints.push_back(R);
1228 return true;
1229 };
1230
1231 switch (InstFlags & AArch64::DestructiveInstTypeMask) {
1232 default:
1233 break;
1235 AddHintIfSuitable(R, Def.getOperand(2)) ||
1236 AddHintIfSuitable(R, Def.getOperand(3)) ||
1237 AddHintIfSuitable(R, Def.getOperand(4));
1238 break;
1241 AddHintIfSuitable(R, Def.getOperand(2)) ||
1242 AddHintIfSuitable(R, Def.getOperand(3));
1243 break;
1246 AddHintIfSuitable(R, Def.getOperand(2));
1247 break;
1249 AddHintIfSuitable(R, Def.getOperand(3));
1250 break;
1253 AddHintIfSuitable(R, Def.getOperand(1));
1254 break;
1255 }
1256 }
1257 }
1258
1259 if (Hints.size())
1260 return ConsiderOnlyHints;
1261 }
1262
1263 if (HandleDestructivePredicateHint(VirtReg, Order, Hints, VRM, MRI, *TII, ST,
1264 Matrix))
1265 return ConsiderOnlyHints;
1266
1267 if (!ST.hasSME() || !ST.isStreaming())
1268 return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints, MF,
1269 VRM);
1270
1271 // The SVE calling convention preserves registers Z8-Z23. As a result, there
1272 // are no ZPR2Strided or ZPR4Strided registers that do not overlap with the
1273 // callee-saved registers and so by default these will be pushed to the back
1274 // of the allocation order for the ZPRStridedOrContiguous classes.
1275 // If any of the instructions which define VirtReg are used by the
1276 // COPY_INTO_TRANSPOSED_TUPLE pseudos, we want to favour reducing copy
1277 // instructions over reducing the number of clobbered callee-save registers,
1278 // so we add the strided registers as a hint.
1279 unsigned RegID = RegRC->getID();
1280 if (RegID == AArch64::ZPR2StridedOrContiguousRegClassID ||
1281 RegID == AArch64::ZPR4StridedOrContiguousRegClassID) {
1282
1283 // Look through uses of the register for COPY_INTO_TRANSPOSED_TUPLE.
1284 for (const MachineInstr &Use : MRI.use_nodbg_instructions(VirtReg)) {
1285 if (Use.getOpcode() != AArch64::COPY_INTO_TRANSPOSED_TUPLE)
1286 continue;
1287
1288 const MachineOperand &Src = Use.getOperand(1);
1289 const MachineOperand &Dst = Use.getOperand(0);
1290
1291 if (!Src.getSubReg() || !Dst.getSubReg())
1292 continue;
1293
1294 const TargetRegisterClass *StridedRC;
1295 switch (RegID) {
1296 case AArch64::ZPR2StridedOrContiguousRegClassID:
1297 StridedRC = &AArch64::ZPR2StridedRegClass;
1298 break;
1299 case AArch64::ZPR4StridedOrContiguousRegClassID:
1300 StridedRC = &AArch64::ZPR4StridedRegClass;
1301 break;
1302 default:
1303 llvm_unreachable("Unexpected RegID");
1304 }
1305
1306 SmallVector<MCPhysReg, 4> StridedOrder;
1307 for (MCPhysReg Reg : Order)
1308 if (StridedRC->contains(Reg))
1309 StridedOrder.push_back(Reg);
1310
1311 unsigned TupleSize = Use.getOperand(2).getImm();
1312 unsigned TupIdx = Dst.getSubReg() - AArch64::zsub0;
1313
1314 unsigned TupleID = MRI.getRegClass(Dst.getReg())->getID();
1315 bool IsMulZPR = TupleID == AArch64::ZPR2Mul2RegClassID ||
1316 TupleID == AArch64::ZPR4Mul4RegClassID;
1317
1318 iterator_range Copies = MRI.def_instructions(Dst.getReg());
1319 MachineRegisterInfo::def_instr_iterator CopyWithAssignedSrc =
1320 llvm::find_if(Copies, [&](const MachineInstr &Def) {
1321 auto &Src = Def.getOperand(1);
1322 return Def.getOpcode() == Use.getOpcode() &&
1323 VRM->hasPhys(Src.getReg());
1324 });
1325
1326 // Example:
1327 //
1328 // When trying to find a suitable register allocation for VirtReg %v2 in:
1329 //
1330 // %v0:zpr2stridedorcontiguous = ld1 p0/z, [...]
1331 // %v1:zpr2stridedorcontiguous = ld1 p0/z, [...]
1332 // %v2:zpr2stridedorcontiguous = ld1 p0/z, [...]
1333 // %v3:zpr2stridedorcontiguous = ld1 p0/z, [...]
1334 // %v4.zsub0:zpr4mul4 = COPY_INTO_TRANSPOSED_TUPLE %v0:0
1335 // %v4.zsub1:zpr4mul4 = COPY_INTO_TRANSPOSED_TUPLE %v1:0
1336 // %v4.zsub2:zpr4mul4 = COPY_INTO_TRANSPOSED_TUPLE %v2:0
1337 // %v4.zsub3:zpr4mul4 = COPY_INTO_TRANSPOSED_TUPLE %v3:0
1338 //
1339 // One such suitable allocation would be:
1340 //
1341 // { z0, z8 } = ld1 p0/z, [...]
1342 // { z1, z9 } = ld1 p0/z, [...]
1343 // { z2, z10 } = ld1 p0/z, [...]
1344 // { z3, z11 } = ld1 p0/z, [...]
1345 // z0 = COPY_INTO_TRANSPOSED_TUPLE {z0, z8}:0
1346 // z1 = COPY_INTO_TRANSPOSED_TUPLE {z1, z9}:0
1347 // z2 = COPY_INTO_TRANSPOSED_TUPLE {z2, z10}:0
1348 // z3 = COPY_INTO_TRANSPOSED_TUPLE {z3, z11}:0
1349 //
1350 // Below we distinguish two cases when trying to find a register:
1351 // * None of the sources of the copies have been assigned a register yet.
1352 // In this case the code must ensure that there are at least TupleSize
1353 // free consecutive registers. If IsMulZPR is true, then the first of
1354 // registers must also be a multiple of TupleSize, e.g.
1355 // { z0, z1, z2, z3 } is valid but { z1, z2, z3, z5 } is not.
1356 // * One or more copies already have registers assigned to their sources,
1357 // which means only checking that a consecutive range of free tuple
1358 // registers exists which includes the assigned register.
1359 // e.g. in the example above, if { z0, z8 } is already allocated for
1360 // %v0, we just need to ensure that { z1, z9 }, { z2, z10 } and
1361 // { z3, z11 } are also free. If so, we add { z2, z10 }.
1362
1363 if (CopyWithAssignedSrc == Copies.end()) {
1364 // There are no registers already assigned to any of the pseudo
1365 // operands. Look for a valid starting register for the group.
1366 for (unsigned I = 0; I < StridedOrder.size(); ++I) {
1367 MCPhysReg Reg = StridedOrder[I];
1368
1369 // If the COPY_INTO_TRANSPOSED_TUPLE nodes use the ZPRMul classes, the
1370 // starting register of the first load should be a multiple of 2 or 4.
1371 unsigned SubRegIdx = Src.getSubReg();
1372 if (IsMulZPR &&
1373 (getSubReg(Reg, SubRegIdx) - AArch64::Z0) % TupleSize != TupIdx)
1374 continue;
1375
1376 // In the example above, if VirtReg is the third operand of the
1377 // tuple (%v2) and Reg == Z2_Z10, then we need to make sure that
1378 // Z0_Z8, Z1_Z9 and Z3_Z11 are also available.
1379 auto IsFreeConsecutiveReg = [&](unsigned I) {
1380 unsigned R = Reg - TupIdx + I;
1381 return StridedRC->contains(R) &&
1382 (I == 0 ||
1383 ((getSubReg(R, AArch64::zsub0) - AArch64::Z0) ==
1384 (getSubReg(R - 1, AArch64::zsub0) - AArch64::Z0) + 1)) &&
1385 !Matrix->isPhysRegUsed(R);
1386 };
1387 if (all_of(seq(0U, TupleSize), IsFreeConsecutiveReg))
1388 Hints.push_back(Reg);
1389 }
1390 } else {
1391 // At least copy already has a physical register assigned to its source.
1392 // Find the starting sub-register of this and use it to work out the
1393 // correct strided register to suggest based on the current op index.
1394 MachineOperand &AssignedSrc = CopyWithAssignedSrc->getOperand(1);
1395 MachineOperand &AssignedDst = CopyWithAssignedSrc->getOperand(0);
1396
1397 if (!AssignedSrc.getSubReg() || !AssignedDst.getSubReg())
1398 continue;
1399
1400 unsigned AssignedTupIdx = AssignedDst.getSubReg() - AArch64::zsub0;
1401 MCPhysReg TargetStartReg =
1402 getSubReg(VRM->getPhys(AssignedSrc.getReg()), AArch64::zsub0) +
1403 (TupIdx - AssignedTupIdx);
1404
1405 for (unsigned I = 0; I < StridedOrder.size(); ++I)
1406 if (getSubReg(StridedOrder[I], AArch64::zsub0) == TargetStartReg)
1407 Hints.push_back(StridedOrder[I]);
1408 }
1409
1410 if (!Hints.empty())
1411 return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints,
1412 MF, VRM);
1413 }
1414 }
1415
1416 for (auto &Def : MRI.def_instructions(VirtReg)) {
1417 if (Def.getOpcode() != AArch64::COPY_INTO_TRANSPOSED_TUPLE)
1418 continue;
1419
1420 MachineOperand &Src = Def.getOperand(1);
1421 MachineOperand &Dst = Def.getOperand(0);
1422
1423 if (!Src.getSubReg() || !Dst.getSubReg())
1424 continue;
1425
1426 // FIXME: This is fragile. If we allocate a register to the Dst before Src,
1427 // our hints are won't have any effect... This is currently mitigated by
1428 // by trying to schedule copies immediately before their uses. This gives
1429 // them a short live range (so they're low priority to allocate).
1430 if (!VRM->hasPhys(Src.getReg()))
1431 continue;
1432
1433 // Find the ZPR register mapped to the source of the copy.
1434 MCPhysReg SrcZPR = getSubReg(VRM->getPhys(Src.getReg()), Src.getSubReg());
1435
1436 // Try to pick a tuple register for Dst with Src as a member.
1437 for (MCPhysReg R : Order) {
1438 if (getSubReg(R, Dst.getSubReg()) == SrcZPR)
1439 Hints.push_back(R);
1440 }
1441 }
1442
1443 return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints, MF,
1444 VRM);
1445}
1446
1448 const MachineFunction &MF) const {
1449 const auto &MFI = MF.getFrameInfo();
1450 if (!MF.hasEHFunclets() && !MFI.hasVarSizedObjects())
1451 return AArch64::SP;
1452 else if (hasStackRealignment(MF))
1453 return getBaseRegister();
1454 return getFrameRegister(MF);
1455}
1456
1457/// SrcRC and DstRC will be morphed into NewRC if this returns true
1459 MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg,
1460 const TargetRegisterClass *DstRC, unsigned DstSubReg,
1461 const TargetRegisterClass *NewRC, LiveIntervals &LIS) const {
1462 MachineFunction &MF = *MI->getMF();
1463 MachineRegisterInfo &MRI = MF.getRegInfo();
1464
1465 if (MI->isSubregToReg() && MRI.subRegLivenessEnabled() &&
1467 return false;
1468
1469 if (MI->isCopy() &&
1470 ((DstRC->getID() == AArch64::GPR64RegClassID) ||
1471 (DstRC->getID() == AArch64::GPR64commonRegClassID)) &&
1472 MI->getOperand(0).getSubReg() && MI->getOperand(1).getSubReg())
1473 // Do not coalesce in the case of a 32-bit subregister copy
1474 // which implements a 32 to 64 bit zero extension
1475 // which relies on the upper 32 bits being zeroed.
1476 return false;
1477
1478 auto IsCoalescerBarrier = [](const MachineInstr &MI) {
1479 switch (MI.getOpcode()) {
1480 case AArch64::COALESCER_BARRIER_FPR16:
1481 case AArch64::COALESCER_BARRIER_FPR32:
1482 case AArch64::COALESCER_BARRIER_FPR64:
1483 case AArch64::COALESCER_BARRIER_FPR128:
1484 return true;
1485 default:
1486 return false;
1487 }
1488 };
1489
1490 // For calls that temporarily have to toggle streaming mode as part of the
1491 // call-sequence, we need to be more careful when coalescing copy instructions
1492 // so that we don't end up coalescing the NEON/FP result or argument register
1493 // with a whole Z-register, such that after coalescing the register allocator
1494 // will try to spill/reload the entire Z register.
1495 //
1496 // We do this by checking if the node has any defs/uses that are
1497 // COALESCER_BARRIER pseudos. These are 'nops' in practice, but they exist to
1498 // instruct the coalescer to avoid coalescing the copy.
1499 if (MI->isCopy() && SubReg != DstSubReg &&
1500 (AArch64::ZPRRegClass.hasSubClassEq(DstRC) ||
1501 AArch64::ZPRRegClass.hasSubClassEq(SrcRC))) {
1502 unsigned SrcReg = MI->getOperand(1).getReg();
1503 if (any_of(MRI.def_instructions(SrcReg), IsCoalescerBarrier))
1504 return false;
1505 unsigned DstReg = MI->getOperand(0).getReg();
1506 if (any_of(MRI.use_nodbg_instructions(DstReg), IsCoalescerBarrier))
1507 return false;
1508 }
1509
1510 return true;
1511}
1512
1514 MCRegister R) const {
1515 return R == AArch64::VG;
1516}
1517
1519 return (LLVMReg >= AArch64::Z0 && LLVMReg <= AArch64::Z31) ||
1520 (LLVMReg >= AArch64::P0 && LLVMReg <= AArch64::P15);
1521}
static bool isTargetWindows(const MachineFunction &MF)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Register createScratchRegisterForInstruction(MachineInstr &MI, unsigned FIOperandNum, const AArch64InstrInfo *TII)
static bool HandleDestructivePredicateHint(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const VirtRegMap *VRM, const MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const AArch64Subtarget &ST, const LiveRegMatrix *Matrix)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition Compiler.h:421
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Live Register Matrix
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
This file declares the machine register scavenger class.
SI Lower i1 Copies
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
static unsigned getDwarfRegNum(MCRegister Reg, const TargetRegisterInfo *TRI)
Go up the super-register chain until we hit a valid dwarf register number.
StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
bool isFPReserved(const MachineFunction &MF) const
Should the Frame Pointer be reserved for the current function?
StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg, bool PreferFP, bool ForSimm) const
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=AArch64::NoRegAltName)
BitVector getStrictlyReservedRegs(const MachineFunction &MF) const
const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const override
const uint32_t * getThisReturnPreservedMask(const MachineFunction &MF, CallingConv::ID) const
getThisReturnPreservedMask - Returns a call preserved mask specific to the case that 'returned' is on...
bool isReservedReg(const MachineFunction &MF, MCRegister Reg) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
bool isIgnoredCVReg(MCRegister LLVMReg) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
const TargetRegisterClass * getPointerRegClass(unsigned Kind=0) const override
bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const override
SrcRC and DstRC will be morphed into NewRC if this returns true.
bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override
bool isUserReservedReg(const MachineFunction &MF, MCRegister Reg) const
const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const override
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const override
Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx at the beginning of the basic ...
void UpdateCustomCalleeSavedRegs(MachineFunction &MF) const
bool requiresRegisterScavenging(const MachineFunction &MF) const override
bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const override
BitVector getUserReservedRegs(const MachineFunction &MF) const
void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const override
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
needsFrameBaseReg - Returns true if the instruction's frame index reference would be better served by...
const uint32_t * getWindowsStackProbePreservedMask() const
Stack probing calls preserve different CSRs to the normal CC.
bool regNeedsCFI(MCRegister Reg, MCRegister &RegToUseForCFI) const
Return whether the register needs a CFI entry.
bool isAnyArgRegReserved(const MachineFunction &MF) const
void emitReservedArgRegCallError(const MachineFunction &MF) const
bool isStrictlyReservedReg(const MachineFunction &MF, MCRegister Reg) const
bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
const uint32_t * getTLSCallPreservedMask() const
const uint32_t * getNoPreservedMask() const override
Register getFrameRegister(const MachineFunction &MF) const override
bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const override
void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const override
bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const override
AArch64RegisterInfo(const Triple &TT, unsigned HwMode)
const uint32_t * SMEABISupportRoutinesCallPreservedMaskFromX0() const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
const uint32_t * getCustomEHPadPreservedMask(const MachineFunction &MF) const override
unsigned getLocalAddressRegister(const MachineFunction &MF) const
bool hasBasePointer(const MachineFunction &MF) const
const uint32_t * getDarwinCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
const uint32_t * getSMStartStopCallPreservedMask() const
bool useFPForScavengingIndex(const MachineFunction &MF) const override
bool cannotEliminateFrame(const MachineFunction &MF) const
bool isArgumentRegister(const MachineFunction &MF, MCRegister Reg) const override
void UpdateCustomCallPreservedMask(MachineFunction &MF, const uint32_t **Mask) const
std::optional< std::string > explainReservedReg(const MachineFunction &MF, MCRegister PhysReg) const override
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
bool enableSRLTSubregToRegMitigation() const
bool isXRegisterReservedForRA(size_t i) const
const AArch64TargetLowering * getTargetLowering() const override
bool isXRegCustomCalleeSaved(size_t i) const
bool isXRegisterReserved(size_t i) const
bool isCallingConvWin64(CallingConv::ID CC, bool IsVarArg) const
bool supportSwiftError() const override
Return true if the target supports swifterror attribute.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
A debug info location.
Definition DebugLoc.h:126
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
Diagnostic information for unsupported feature in backend.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:273
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition Function.h:329
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition Function.h:230
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:730
Describe properties that are true of each instruction in the target description file.
unsigned getID() const
getID() - Return the register class ID number.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MCSubRegIterator enumerates all sub-registers of Reg.
bool isValid() const
Returns true if this iterator is not yet at the end.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
int64_t getLocalFrameSize() const
Get the size of the local object blob.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
uint32_t * allocateRegMask()
Allocate and initialize a register mask with NumRegister bits.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
LLVM_ABI bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addFrameIndex(int Idx) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
LLVM_ABI void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
iterator_range< def_instr_iterator > def_instructions(Register Reg) const
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
defusechain_instr_iterator< false, true, false, true > def_instr_iterator
def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the specified register,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
iterator_range< def_iterator > def_operands(Register Reg) const
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
LLVM_ABI void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isValid() const
Definition Register.h:112
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
int64_t getFixed() const
Returns the fixed component of the stack.
Definition TypeSize.h:46
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
TargetInstrInfo - Interface to description of machine instruction set.
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
bool hasPhys(Register virtReg) const
returns true if the specified virtual register is mapped to a physical register
Definition VirtRegMap.h:87
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:209
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:182
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ MO_TAGGED
MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag in bits 56-63.
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
void initLLVMToCVRegMapping(MCRegisterInfo *MRI)
int32_t getSVEPseudoMap(uint32_t Opcode)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ AArch64_VectorCall
Used between AArch64 Advanced SIMD functions.
@ Swift
Calling convention for Swift.
Definition CallingConv.h:69
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
Definition CallingConv.h:82
@ PreserveMost
Used for runtime calls that preserves most registers.
Definition CallingConv.h:63
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
Definition CallingConv.h:60
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2
Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ CXX_FAST_TLS
Used for access functions.
Definition CallingConv.h:72
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0
Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition CallingConv.h:50
@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1
Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
Definition CallingConv.h:66
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ PreserveNone
Used for runtime calls that preserves none general registers.
Definition CallingConv.h:90
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition CallingConv.h:87
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
@ ARM64EC_Thunk_X64
Calling convention used in the ARM64EC ABI to implement calls between x64 code and thunks.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
void stable_sort(R &&Range)
Definition STLExtras.h:2116
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
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
int isAArch64FrameOffsetLegal(const MachineInstr &MI, StackOffset &Offset, bool *OutUseUnscaledOp=nullptr, unsigned *OutUnscaledOp=nullptr, int64_t *EmittableOffset=nullptr)
Check if the Offset is a valid frame offset for MI.
@ Done
Definition Threading.h:60
@ AArch64FrameOffsetIsLegal
Offset is legal.
@ AArch64FrameOffsetCanUpdate
Offset can apply, at least partly.
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
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, StackOffset Offset, const TargetInstrInfo *TII, MachineInstr::MIFlag=MachineInstr::NoFlags, bool SetNZCV=false, bool NeedsWinCFI=false, bool *HasWinCFI=nullptr, bool EmitCFAOffset=false, StackOffset InitialOffset={}, unsigned FrameReg=AArch64::SP)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool rewriteAArch64FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, unsigned FrameReg, StackOffset &Offset, const AArch64InstrInfo *TII)
rewriteAArch64FrameIndex - Rewrite MI to access 'Offset' bytes from the FP.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58