LLVM 23.0.0git
TargetRegisterInfo.h
Go to the documentation of this file.
1//==- CodeGen/TargetRegisterInfo.h - Target Register Information -*- C++ -*-==//
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 describes an abstract interface used to get information about a
10// target machines register file. This information is used for a variety of
11// purposed, especially register allocation.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_TARGETREGISTERINFO_H
16#define LLVM_CODEGEN_TARGETREGISTERINFO_H
17
18#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
25#include "llvm/IR/CallingConv.h"
26#include "llvm/MC/LaneBitmask.h"
32#include <cassert>
33#include <cstdint>
34
35namespace llvm {
36
37class BitVector;
38class DIExpression;
39class LiveRegMatrix;
40class MachineFunction;
41class MachineInstr;
42class RegScavenger;
43class VirtRegMap;
44class LiveIntervals;
45class LiveInterval;
46
47// TODO: Remove.
49
50/// Extra information, not in MCRegisterDesc, about registers.
51/// These are used by codegen, not by MC.
53 const uint8_t *CostPerUse; // Extra cost of instructions using register.
54 unsigned NumCosts; // Number of cost values associated with each register.
55 const bool
56 *InAllocatableClass; // Register belongs to an allocatable regclass.
57};
58
59/// Each TargetRegisterClass has a per register weight, and weight
60/// limit which must be less than the limits of its pressure sets.
62 unsigned RegWeight;
63 unsigned WeightLimit;
64};
65
66/// TargetRegisterInfo base class - We assume that the target defines a static
67/// array of TargetRegisterDesc objects that represent all of the machine
68/// registers that the target has. As such, we simply have to track a pointer
69/// to this array so that we can turn register number into a register
70/// descriptor.
71///
73public:
75 struct RegClassInfo {
77 unsigned VTListOffset;
78 };
79
80 /// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
81 /// index, -1 in any being invalid.
86
87private:
88 const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
89 const char *SubRegIndexStrings; // Names of subreg indexes.
90 ArrayRef<uint32_t> SubRegIndexNameOffsets;
91 const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
92 // bit ranges array.
93
94 // Pointer to array of lane masks, one per sub-reg index.
95 const LaneBitmask *SubRegIndexLaneMasks;
96
97 LaneBitmask CoveringLanes;
98 const RegClassInfo *const RCInfos;
99 const MVT::SimpleValueType *const RCVTLists;
100 unsigned HwMode;
101
102protected:
104 const char *SubRegIndexStrings,
105 ArrayRef<uint32_t> SubRegIndexNameOffsets,
106 const SubRegCoveredBits *SubRegIdxRanges,
107 const LaneBitmask *SubRegIndexLaneMasks,
108 LaneBitmask CoveringLanes,
109 const RegClassInfo *const RCInfos,
110 const MVT::SimpleValueType *const RCVTLists,
111 unsigned Mode = 0);
112
113public:
115
116 /// Return the number of registers for the function. (may overestimate)
117 virtual unsigned getNumSupportedRegs(const MachineFunction &) const {
118 return getNumRegs();
119 }
120
121 // Register numbers can represent physical registers, virtual registers, and
122 // sometimes stack slots. The unsigned values are divided into these ranges:
123 //
124 // 0 Not a register, can be used as a sentinel.
125 // [1;2^30) Physical registers assigned by TableGen.
126 // [2^30;2^31) Stack slots. (Rarely used.)
127 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
128 //
129 // Further sentinels can be allocated from the small negative integers.
130 // DenseMapInfo<unsigned> uses -1u and -2u.
131
132 /// Return the size in bits of a register from class RC.
136
137 /// Return the size in bytes of the stack slot allocated to hold a spilled
138 /// copy of a register from class RC.
139 unsigned getSpillSize(const TargetRegisterClass &RC) const {
140 return getRegClassInfo(RC).SpillSize / 8;
141 }
142
143 /// Return the minimum required alignment in bytes for a spill slot for
144 /// a register of this class.
146 return Align(getRegClassInfo(RC).SpillAlignment / 8);
147 }
148
149 /// Return the stack ID for spill slots holding a spilled copy of a register
150 /// from this class.
152 return static_cast<TargetStackID::Value>(RC.SpillStackID);
153 }
154
155 /// Return true if the given TargetRegisterClass has the ValueType T.
157 for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I)
158 if (MVT(*I) == T)
159 return true;
160 return false;
161 }
162
163 /// Return true if the given TargetRegisterClass is compatible with LLT T.
165 for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I) {
166 MVT VT(*I);
167 if (VT == MVT::Untyped)
168 return true;
169
170 if (LLT(VT) == T)
171 return true;
172 }
173 return false;
174 }
175
176 /// Loop over all of the value types that can be represented by values
177 /// in the given register class.
179 return &RCVTLists[getRegClassInfo(RC).VTListOffset];
180 }
181
184 while (*I != MVT::Other)
185 ++I;
186 return I;
187 }
188
189 /// Returns the Register Class of a physical register, picking the smallest
190 /// register subclass that contains this physreg.
191 virtual const TargetRegisterClass *
193
194 /// Returns the common Register Class of two physical registers, picking the
195 /// smallest register subclass that contains these two physregs.
196 const TargetRegisterClass *
198
199 /// Return the maximal subclass of the given register class that is
200 /// allocatable or NULL.
201 const TargetRegisterClass *
203
204 /// Returns a bitset indexed by register number indicating if a register is
205 /// allocatable or not. If a register class is specified, returns the subset
206 /// for the class.
208 const TargetRegisterClass *RC = nullptr) const;
209
210 /// Get a list of cost values for all registers that correspond to the index
211 /// returned by RegisterCostTableIndex.
213 unsigned Idx = getRegisterCostTableIndex(MF);
214 unsigned NumRegs = getNumRegs();
215 assert(Idx < InfoDesc->NumCosts && "CostPerUse index out of bounds");
216
217 return ArrayRef(&InfoDesc->CostPerUse[Idx * NumRegs], NumRegs);
218 }
219
220 /// Return true if the register is in the allocation of any register class.
222 return InfoDesc->InAllocatableClass[RegNo];
223 }
224
225 /// Return the human-readable symbolic target-specific name for the specified
226 /// SubRegIndex.
227 const char *getSubRegIndexName(unsigned SubIdx) const {
228 assert(SubIdx && SubIdx < getNumSubRegIndices() &&
229 "This is not a subregister index");
230 return SubRegIndexStrings + SubRegIndexNameOffsets[SubIdx - 1];
231 }
232
233 /// Get the size of the bit range covered by a sub-register index.
234 /// If the index isn't continuous, return the sum of the sizes of its parts.
235 /// If the index is used to access subregisters of different sizes, return -1.
236 unsigned getSubRegIdxSize(unsigned Idx) const;
237
238 /// Get the offset of the bit range covered by a sub-register index.
239 /// If an Offset doesn't make sense (the index isn't continuous, or is used to
240 /// access sub-registers at different offsets), return -1.
241 unsigned getSubRegIdxOffset(unsigned Idx) const;
242
243 /// Return a bitmask representing the parts of a register that are covered by
244 /// SubIdx \see LaneBitmask.
245 ///
246 /// SubIdx == 0 is allowed, it has the lane mask ~0u.
247 LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const {
248 assert(SubIdx < getNumSubRegIndices() && "This is not a subregister index");
249 return SubRegIndexLaneMasks[SubIdx];
250 }
251
252 /// Try to find one or more subregister indexes to cover \p LaneMask.
253 ///
254 /// If this is possible, returns true and appends the best matching set of
255 /// indexes to \p Indexes. If this is not possible, returns false.
256 bool getCoveringSubRegIndexes(const TargetRegisterClass *RC,
257 LaneBitmask LaneMask,
258 SmallVectorImpl<unsigned> &Indexes) const;
259
260 /// The lane masks returned by getSubRegIndexLaneMask() above can only be
261 /// used to determine if sub-registers overlap - they can't be used to
262 /// determine if a set of sub-registers completely cover another
263 /// sub-register.
264 ///
265 /// The X86 general purpose registers have two lanes corresponding to the
266 /// sub_8bit and sub_8bit_hi sub-registers. Both sub_32bit and sub_16bit have
267 /// lane masks '3', but the sub_16bit sub-register doesn't fully cover the
268 /// sub_32bit sub-register.
269 ///
270 /// On the other hand, the ARM NEON lanes fully cover their registers: The
271 /// dsub_0 sub-register is completely covered by the ssub_0 and ssub_1 lanes.
272 /// This is related to the CoveredBySubRegs property on register definitions.
273 ///
274 /// This function returns a bit mask of lanes that completely cover their
275 /// sub-registers. More precisely, given:
276 ///
277 /// Covering = getCoveringLanes();
278 /// MaskA = getSubRegIndexLaneMask(SubA);
279 /// MaskB = getSubRegIndexLaneMask(SubB);
280 ///
281 /// If (MaskA & ~(MaskB & Covering)) == 0, then SubA is completely covered by
282 /// SubB.
283 LaneBitmask getCoveringLanes() const { return CoveringLanes; }
284
285 /// Returns true if the two registers are equal or alias each other.
286 /// The registers may be virtual registers.
287 bool regsOverlap(Register RegA, Register RegB) const {
288 if (RegA == RegB)
289 return true;
290 if (RegA.isPhysical() && RegB.isPhysical())
291 return MCRegisterInfo::regsOverlap(RegA.asMCReg(), RegB.asMCReg());
292 return false;
293 }
294
295 /// Returns true if the two subregisters are equal or overlap.
296 /// The registers may be virtual registers.
297 bool checkSubRegInterference(Register RegA, unsigned SubA, Register RegB,
298 unsigned SubB) const;
299
300 /// Returns true if Reg contains RegUnit.
301 bool hasRegUnit(MCRegister Reg, MCRegUnit RegUnit) const {
302 return llvm::is_contained(regunits(Reg), RegUnit);
303 }
304
305 /// Returns the original SrcReg unless it is the target of a copy-like
306 /// operation, in which case we chain backwards through all such operations
307 /// to the ultimate source register. If a physical register is encountered,
308 /// we stop the search.
309 virtual Register lookThruCopyLike(Register SrcReg,
310 const MachineRegisterInfo *MRI) const;
311
312 /// Find the original SrcReg unless it is the target of a copy-like operation,
313 /// in which case we chain backwards through all such operations to the
314 /// ultimate source register. If a physical register is encountered, we stop
315 /// the search.
316 /// Return the original SrcReg if all the definitions in the chain only have
317 /// one user and not a physical register.
318 virtual Register
319 lookThruSingleUseCopyChain(Register SrcReg,
320 const MachineRegisterInfo *MRI) const;
321
322 /// Return a null-terminated list of all of the callee-saved registers on
323 /// this target. The register should be in the order of desired callee-save
324 /// stack frame offset. The first register is closest to the incoming stack
325 /// pointer if stack grows down, and vice versa.
326 /// Notice: This function does not take into account disabled CSRs.
327 /// In most cases you will want to use instead the function
328 /// getCalleeSavedRegs that is implemented in MachineRegisterInfo.
329 virtual const MCPhysReg*
331
332 /// Return a null-terminated list of all of the callee-saved registers on
333 /// this target when IPRA is on. The list should include any non-allocatable
334 /// registers that the backend uses and assumes will be saved by all calling
335 /// conventions. This is typically the ISA-standard frame pointer, but could
336 /// include the thread pointer, TOC pointer, or base pointer for different
337 /// targets.
338 virtual const MCPhysReg *getIPRACSRegs(const MachineFunction *MF) const {
339 return nullptr;
340 }
341
342 /// Return a mask of call-preserved registers for the given calling convention
343 /// on the current function. The mask should include all call-preserved
344 /// aliases. This is used by the register allocator to determine which
345 /// registers can be live across a call.
346 ///
347 /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
348 /// A set bit indicates that all bits of the corresponding register are
349 /// preserved across the function call. The bit mask is expected to be
350 /// sub-register complete, i.e. if A is preserved, so are all its
351 /// sub-registers.
352 ///
353 /// Bits are numbered from the LSB, so the bit for physical register Reg can
354 /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
355 ///
356 /// A NULL pointer means that no register mask will be used, and call
357 /// instructions should use implicit-def operands to indicate call clobbered
358 /// registers.
359 ///
361 CallingConv::ID) const {
362 // The default mask clobbers everything. All targets should override.
363 return nullptr;
364 }
365
366 /// Return a register mask for the registers preserved by the unwinder,
367 /// or nullptr if no custom mask is needed.
368 virtual const uint32_t *
370 return nullptr;
371 }
372
373 /// Return a register mask that clobbers everything.
374 virtual const uint32_t *getNoPreservedMask() const {
375 llvm_unreachable("target does not provide no preserved mask");
376 }
377
378 /// Return a list of all of the registers which are clobbered "inside" a call
379 /// to the given function. For example, these might be needed for PLT
380 /// sequences of long-branch veneers.
381 virtual ArrayRef<MCPhysReg>
383 return {};
384 }
385
386 /// Return true if all bits that are set in mask \p mask0 are also set in
387 /// \p mask1.
388 bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const;
389
390 /// Return all the call-preserved register masks defined for this target.
393
394 /// Returns a bitset indexed by physical register number indicating if a
395 /// register is a special register that has particular uses and should be
396 /// considered unavailable at all times, e.g. stack pointer, return address.
397 /// A reserved register:
398 /// - is not allocatable
399 /// - is considered always live
400 /// - is ignored by liveness tracking
401 /// It is often necessary to reserve the super registers of a reserved
402 /// register as well, to avoid them getting allocated indirectly. You may use
403 /// markSuperRegs() and checkAllSuperRegsMarked() in this case.
404 virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
405
406 /// Returns either a string explaining why the given register is reserved for
407 /// this function, or an empty optional if no explanation has been written.
408 /// The absence of an explanation does not mean that the register is not
409 /// reserved (meaning, you should check that PhysReg is in fact reserved
410 /// before calling this).
411 virtual std::optional<std::string>
413 return {};
414 }
415
416 /// Returns false if we can't guarantee that Physreg, specified as an IR asm
417 /// clobber constraint, will be preserved across the statement.
418 virtual bool isAsmClobberable(const MachineFunction &MF,
419 MCRegister PhysReg) const {
420 return true;
421 }
422
423 /// Returns true if PhysReg cannot be written to in inline asm statements.
425 MCRegister PhysReg) const {
426 return false;
427 }
428
429 /// Returns true if PhysReg is unallocatable and constant throughout the
430 /// function. Used by MachineRegisterInfo::isConstantPhysReg().
431 virtual bool isConstantPhysReg(MCRegister PhysReg) const { return false; }
432
433 /// Returns true if the register class is considered divergent.
434 virtual bool isDivergentRegClass(const TargetRegisterClass *RC) const {
435 return false;
436 }
437
438 /// Returns true if the register is considered uniform.
439 virtual bool isUniformReg(const MachineRegisterInfo &MRI,
440 const RegisterBankInfo &RBI, Register Reg) const {
441 return false;
442 }
443
444 /// Returns true if MachineLoopInfo should analyze the given physreg
445 /// for loop invariance.
447 return false;
448 }
449
450 /// Physical registers that may be modified within a function but are
451 /// guaranteed to be restored before any uses. This is useful for targets that
452 /// have call sequences where a GOT register may be updated by the caller
453 /// prior to a call and is guaranteed to be restored (also by the caller)
454 /// after the call.
456 const MachineFunction &MF) const {
457 return false;
458 }
459
460 /// This is a wrapper around getCallPreservedMask().
461 /// Return true if the register is preserved after the call.
462 virtual bool isCalleeSavedPhysReg(MCRegister PhysReg,
463 const MachineFunction &MF) const;
464
465 /// Returns true if PhysReg can be used as an argument to a function.
466 virtual bool isArgumentRegister(const MachineFunction &MF,
467 MCRegister PhysReg) const {
468 return false;
469 }
470
471 /// Returns true if PhysReg is a fixed register.
472 virtual bool isFixedRegister(const MachineFunction &MF,
473 MCRegister PhysReg) const {
474 return false;
475 }
476
477 /// Returns true if PhysReg is a general purpose register.
479 MCRegister PhysReg) const {
480 return false;
481 }
482
483 /// Returns true if RC is a class/subclass of general purpose register.
484 virtual bool
486 return false;
487 }
488
489 /// Prior to adding the live-out mask to a stackmap or patchpoint
490 /// instruction, provide the target the opportunity to adjust it (mainly to
491 /// remove pseudo-registers that should be ignored).
492 virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const {}
493
494 /// Return a subclass of the register class \p A so that each register in it
495 /// has a sub-register of sub-register index \p Idx which is in the register
496 /// class \p B.
497 ///
498 /// TableGen will synthesize missing A sub-classes.
499 virtual const TargetRegisterClass *
500 getMatchingSuperRegClass(const TargetRegisterClass *A,
501 const TargetRegisterClass *B, unsigned Idx) const;
502
503 /// Find a common register class that can accomodate both the source and
504 /// destination operands of a copy-like instruction:
505 ///
506 /// DefRC:DefSubReg = COPY SrcRC:SrcSubReg
507 ///
508 /// This is a generalized form of getMatchingSuperRegClass,
509 /// getCommonSuperRegClass, and getCommonSubClass which handles 0, 1, or 2
510 /// subregister indexes. Those utilities should be preferred if the number of
511 /// non-0 subregister indexes is known.
512 const TargetRegisterClass *
513 findCommonRegClass(const TargetRegisterClass *DefRC, unsigned DefSubReg,
514 const TargetRegisterClass *SrcRC,
515 unsigned SrcSubReg) const;
516
517 // For a copy-like instruction that defines a register of class DefRC with
518 // subreg index DefSubReg, reading from another source with class SrcRC and
519 // subregister SrcSubReg return true if this is a preferable copy
520 // instruction or an earlier use should be used.
521 virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
522 unsigned DefSubReg,
523 const TargetRegisterClass *SrcRC,
524 unsigned SrcSubReg) const {
525 // If this source does not incur a cross register bank copy, use it.
526 return findCommonRegClass(DefRC, DefSubReg, SrcRC, SrcSubReg) != nullptr;
527 }
528
529 /// Returns the largest legal sub-class of \p RC that supports the
530 /// sub-register index \p Idx.
531 /// If no such sub-class exists, return NULL.
532 /// If all registers in RC already have an Idx sub-register, return RC.
533 ///
534 /// TableGen generates a version of this function that is good enough in most
535 /// cases. Targets can override if they have constraints that TableGen
536 /// doesn't understand. For example, the x86 sub_8bit sub-register index is
537 /// supported by the full GR32 register class in 64-bit mode, but only by the
538 /// GR32_ABCD regiister class in 32-bit mode.
539 ///
540 /// TableGen will synthesize missing RC sub-classes.
541 virtual const TargetRegisterClass *
542 getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
543 assert(Idx == 0 && "Target has no sub-registers");
544 return RC;
545 }
546
547 /// Returns the register class of all sub-registers of \p SuperRC obtained by
548 /// applying the sub-register index \p SubRegIdx.
549 ///
550 /// TableGen *may not* synthesize the missing sub-register classes, so this
551 /// function may return null even if SubRegIdx can be applied to all registers
552 /// in SuperRC, i.e., even if
553 /// isSubRegValidForRegClass(SuperRC, SubRegIdx) is true.
554 virtual const TargetRegisterClass *
556 unsigned SubRegIdx) const {
557 return nullptr;
558 }
559
560 /// Returns true if sub-register \p Idx can be used with register class \p RC.
561 /// Idx is valid if the largest subclass of RC that supports sub-register
562 /// index Idx is same as RC. That is, every physical register in RC supports
563 /// sub-register index Idx.
565 unsigned Idx) const {
566 return getSubClassWithSubReg(RC, Idx) == RC;
567 }
568
569 /// Return the subregister index you get from composing
570 /// two subregister indices.
571 ///
572 /// The special null sub-register index composes as the identity.
573 ///
574 /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
575 /// returns c. Note that composeSubRegIndices does not tell you about illegal
576 /// compositions. If R does not have a subreg a, or R:a does not have a subreg
577 /// b, composeSubRegIndices doesn't tell you.
578 ///
579 /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
580 /// ssub_0:S0 - ssub_3:S3 subregs.
581 /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
582 unsigned composeSubRegIndices(unsigned a, unsigned b) const {
583 if (!a) return b;
584 if (!b) return a;
585 return composeSubRegIndicesImpl(a, b);
586 }
587
588 /// Return a subregister index that will compose to give you the subregister
589 /// index.
590 ///
591 /// Finds a subregister index x such that composeSubRegIndices(a, x) ==
592 /// b. Note that this relationship does not hold if
593 /// reverseComposeSubRegIndices returns the null subregister.
594 ///
595 /// The special null sub-register index composes as the identity.
596 unsigned reverseComposeSubRegIndices(unsigned a, unsigned b) const {
597 if (!a)
598 return b;
599 if (!b)
600 return a;
602 }
603
604 /// Transforms a LaneMask computed for one subregister to the lanemask that
605 /// would have been computed when composing the subsubregisters with IdxA
606 /// first. @sa composeSubRegIndices()
608 LaneBitmask Mask) const {
609 if (!IdxA)
610 return Mask;
611 return composeSubRegIndexLaneMaskImpl(IdxA, Mask);
612 }
613
614 /// Transform a lanemask given for a virtual register to the corresponding
615 /// lanemask before using subregister with index \p IdxA.
616 /// This is the reverse of composeSubRegIndexLaneMask(), assuming Mask is a
617 /// valie lane mask (no invalid bits set) the following holds:
618 /// X0 = composeSubRegIndexLaneMask(Idx, Mask)
619 /// X1 = reverseComposeSubRegIndexLaneMask(Idx, X0)
620 /// => X1 == Mask
622 LaneBitmask LaneMask) const {
623 if (!IdxA)
624 return LaneMask;
625 return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
626 }
627
628 /// Debugging helper: dump register in human readable form to dbgs() stream.
629 static void dumpReg(Register Reg, unsigned SubRegIndex = 0,
630 const TargetRegisterInfo *TRI = nullptr);
631
632 /// Return target defined base register class for a physical register.
633 /// This is the register class with the lowest BaseClassOrder containing the
634 /// register.
635 /// Will be nullptr if the register is not in any base register class.
637 return nullptr;
638 }
639
640protected:
641 /// Overridden by TableGen in targets that have sub-registers.
642 virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const {
643 llvm_unreachable("Target has no sub-registers");
644 }
645
646 /// Overridden by TableGen in targets that have sub-registers.
647 virtual unsigned reverseComposeSubRegIndicesImpl(unsigned, unsigned) const {
648 llvm_unreachable("Target has no sub-registers");
649 }
650
651 /// Overridden by TableGen in targets that have sub-registers.
652 virtual LaneBitmask
654 llvm_unreachable("Target has no sub-registers");
655 }
656
658 LaneBitmask) const {
659 llvm_unreachable("Target has no sub-registers");
660 }
661
662 /// Return the register cost table index. This implementation is sufficient
663 /// for most architectures and can be overriden by targets in case there are
664 /// multiple cost values associated with each register.
665 virtual unsigned getRegisterCostTableIndex(const MachineFunction &MF) const {
666 return 0;
667 }
668
669public:
670 /// Find a common super-register class if it exists.
671 ///
672 /// Find a register class, SuperRC and two sub-register indices, PreA and
673 /// PreB, such that:
674 ///
675 /// 1. PreA + SubA == PreB + SubB (using composeSubRegIndices()), and
676 ///
677 /// 2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
678 ///
679 /// 3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
680 ///
681 /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
682 /// requirements, and there is no register class with a smaller spill size
683 /// that satisfies the requirements.
684 ///
685 /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
686 ///
687 /// Either of the PreA and PreB sub-register indices may be returned as 0. In
688 /// that case, the returned register class will be a sub-class of the
689 /// corresponding argument register class.
690 ///
691 /// The function returns NULL if no register class can be found.
693 getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
694 const TargetRegisterClass *RCB, unsigned SubB,
695 unsigned &PreA, unsigned &PreB) const;
696
697 //===--------------------------------------------------------------------===//
698 // Register Class Information
699 //
700protected:
702 return RCInfos[getNumRegClasses() * HwMode + RC.getID()];
703 }
704
705public:
706 /// Returns the register class associated with the enumeration value.
707 /// See class MCOperandInfo.
708 const TargetRegisterClass *getRegClass(unsigned i) const {
710 }
711
712 /// Find the largest common subclass of A and B.
713 /// Return NULL if there is no common subclass.
714 const TargetRegisterClass *
715 getCommonSubClass(const TargetRegisterClass *A,
716 const TargetRegisterClass *B) const;
717
718 /// Returns a TargetRegisterClass used for pointer values.
719 /// If a target supports multiple different pointer register classes,
720 /// kind specifies which one is indicated.
721 virtual const TargetRegisterClass *
722 getPointerRegClass(unsigned Kind = 0) const {
723 llvm_unreachable("Target didn't implement getPointerRegClass!");
724 }
725
726 /// Returns a legal register class to copy a register in the specified class
727 /// to or from. If it is possible to copy the register directly without using
728 /// a cross register class copy, return the specified RC. Returns NULL if it
729 /// is not possible to copy between two registers of the specified class.
730 virtual const TargetRegisterClass *
732 return RC;
733 }
734
735 /// Returns the largest super class of RC that is legal to use in the current
736 /// sub-target and has the same spill size.
737 /// The returned register class can be used to create virtual registers which
738 /// means that all its registers can be copied and spilled.
739 virtual const TargetRegisterClass *
741 const MachineFunction &) const {
742 /// The default implementation is very conservative and doesn't allow the
743 /// register allocator to inflate register classes.
744 return RC;
745 }
746
747 /// Return the register pressure "high water mark" for the specific register
748 /// class. The scheduler is in high register pressure mode (for the specific
749 /// register class) if it goes over the limit.
750 ///
751 /// Note: this is the old register pressure model that relies on a manually
752 /// specified representative register class per value type.
753 virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
754 MachineFunction &MF) const {
755 return 0;
756 }
757
758 /// Return a heuristic for the machine scheduler to compare the profitability
759 /// of increasing one register pressure set versus another. The scheduler
760 /// will prefer increasing the register pressure of the set which returns
761 /// the largest value for this function.
762 virtual unsigned getRegPressureSetScore(const MachineFunction &MF,
763 unsigned PSetID) const {
764 return PSetID;
765 }
766
767 /// Get the weight in units of pressure for this register class.
769 const TargetRegisterClass *RC) const = 0;
770
771 /// Returns size in bits of a phys/virtual/generic register.
773
774 /// Get the weight in units of pressure for this register unit.
775 virtual unsigned getRegUnitWeight(MCRegUnit RegUnit) const = 0;
776
777 /// Get the number of dimensions of register pressure.
778 virtual unsigned getNumRegPressureSets() const = 0;
779
780 /// Get the name of this register unit pressure set.
781 virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
782
783 /// Get the register unit pressure limit for this dimension.
784 /// This limit must be adjusted dynamically for reserved registers.
785 virtual unsigned getRegPressureSetLimit(const MachineFunction &MF,
786 unsigned Idx) const = 0;
787
788 /// Get the dimensions of register pressure impacted by this register class.
789 /// Returns a -1 terminated array of pressure set IDs.
790 virtual const int *getRegClassPressureSets(
791 const TargetRegisterClass *RC) const = 0;
792
793 /// Get the dimensions of register pressure impacted by this register unit.
794 /// Returns a -1 terminated array of pressure set IDs.
795 virtual const int *getRegUnitPressureSets(MCRegUnit RegUnit) const = 0;
796
797 /// Get the scale factor of spill weight for this register class.
798 virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const;
799
800 /// Returns the preferred order for allocating registers from this register
801 /// class in MF. The raw order comes directly from the .td file and may
802 /// include reserved registers that are not allocatable.
803 /// Register allocators should also make sure to allocate
804 /// callee-saved registers only after all the volatiles are used. The
805 /// RegisterClassInfo class provides filtered allocation orders with
806 /// callee-saved registers moved to the end.
807 ///
808 /// The MachineFunction argument can be used to tune the allocatable
809 /// registers based on the characteristics of the function, subtarget, or
810 /// other criteria.
811 ///
812 /// By default, this method returns all registers in the class.
813 virtual ArrayRef<MCPhysReg>
815 bool /*Rev*/ = false) const {
816 return RC.getRegisters();
817 }
818
819 /// Get a list of 'hint' registers that the register allocator should try
820 /// first when allocating a physical register for the virtual register
821 /// VirtReg. These registers are effectively moved to the front of the
822 /// allocation order. If true is returned, regalloc will try to only use
823 /// hints to the greatest extent possible even if it means spilling.
824 ///
825 /// The Order argument is the allocation order for VirtReg's register class
826 /// as returned from RegisterClassInfo::getOrder(). The hint registers must
827 /// come from Order, and they must not be reserved.
828 ///
829 /// The default implementation of this function will only add target
830 /// independent register allocation hints. Targets that override this
831 /// function should typically call this default implementation as well and
832 /// expect to see generic copy hints added.
833 virtual bool
834 getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
836 const MachineFunction &MF,
837 const VirtRegMap *VRM = nullptr,
838 const LiveRegMatrix *Matrix = nullptr) const;
839
840 /// A callback to allow target a chance to update register allocation hints
841 /// when a register is "changed" (e.g. coalesced) to another register.
842 /// e.g. On ARM, some virtual registers should target register pairs,
843 /// if one of pair is coalesced to another register, the allocation hint of
844 /// the other half of the pair should be changed to point to the new register.
846 MachineFunction &MF) const {
847 // Do nothing.
848 }
849
850 /// Allow the target to reverse allocation order of local live ranges. This
851 /// will generally allocate shorter local live ranges first. For targets with
852 /// many registers, this could reduce regalloc compile time by a large
853 /// factor. It is disabled by default for three reasons:
854 /// (1) Top-down allocation is simpler and easier to debug for targets that
855 /// don't benefit from reversing the order.
856 /// (2) Bottom-up allocation could result in poor evicition decisions on some
857 /// targets affecting the performance of compiled code.
858 /// (3) Bottom-up allocation is no longer guaranteed to optimally color.
859 virtual bool reverseLocalAssignment() const { return false; }
860
861 /// Allow the target to override the cost of using a callee-saved register for
862 /// the first time. Default value of 0 means we will use a callee-saved
863 /// register if it is available.
864 virtual unsigned getCSRFirstUseCost() const { return 0; }
865 /// FIXME: We should deprecate this usage.
866 virtual unsigned getCSRCost() const { return 0; }
867
868 /// Returns true if the target requires (and can make use of) the register
869 /// scavenger.
870 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
871 return false;
872 }
873
874 /// Returns true if the target wants to use frame pointer based accesses to
875 /// spill to the scavenger emergency spill slot.
876 virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
877 return true;
878 }
879
880 /// Returns true if the target requires post PEI scavenging of registers for
881 /// materializing frame index constants.
882 virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
883 return false;
884 }
885
886 /// Returns true if the target requires using the RegScavenger directly for
887 /// frame elimination despite using requiresFrameIndexScavenging.
889 const MachineFunction &MF) const {
890 return false;
891 }
892
893 /// Returns true if the target wants the LocalStackAllocation pass to be run
894 /// and virtual base registers used for more efficient stack access.
895 virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
896 return false;
897 }
898
899 /// Return true if target has reserved a spill slot in the stack frame of
900 /// the given function for the specified register. e.g. On x86, if the frame
901 /// register is required, the first fixed stack object is reserved as its
902 /// spill slot. This tells PEI not to create a new stack frame
903 /// object for the given register. It should be called only after
904 /// determineCalleeSaves().
906 int &FrameIdx) const {
907 return false;
908 }
909
910 /// Returns true if the live-ins should be tracked after register allocation.
911 virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
912 return true;
913 }
914
915 /// True if the stack can be realigned for the target.
916 virtual bool canRealignStack(const MachineFunction &MF) const;
917
918 /// True if storage within the function requires the stack pointer to be
919 /// aligned more than the normal calling convention calls for.
920 virtual bool shouldRealignStack(const MachineFunction &MF) const;
921
922 /// True if stack realignment is required and still possible.
923 bool hasStackRealignment(const MachineFunction &MF) const {
924 return shouldRealignStack(MF) && canRealignStack(MF);
925 }
926
927 /// Get the offset from the referenced frame index in the instruction,
928 /// if there is one.
930 int Idx) const {
931 return 0;
932 }
933
934 /// Returns true if the instruction's frame index reference would be better
935 /// served by a base register other than FP or SP.
936 /// Used by LocalStackFrameAllocation to determine which frame index
937 /// references it should create new base registers for.
938 virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
939 return false;
940 }
941
942 /// Insert defining instruction(s) for a pointer to FrameIdx before
943 /// insertion point I. Return materialized frame pointer.
945 int FrameIdx,
946 int64_t Offset) const {
947 llvm_unreachable("materializeFrameBaseRegister does not exist on this "
948 "target");
949 }
950
951 /// Resolve a frame index operand of an instruction
952 /// to reference the indicated base register plus offset instead.
954 int64_t Offset) const {
955 llvm_unreachable("resolveFrameIndex does not exist on this target");
956 }
957
958 /// Determine whether a given base register plus offset immediate is
959 /// encodable to resolve a frame index.
960 virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
961 int64_t Offset) const {
962 llvm_unreachable("isFrameOffsetLegal does not exist on this target");
963 }
964
965 /// Gets the DWARF expression opcodes for \p Offset.
966 virtual void getOffsetOpcodes(const StackOffset &Offset,
968
969 /// Prepends a DWARF expression for \p Offset to DIExpression \p Expr.
971 prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags,
972 const StackOffset &Offset) const;
973
974 virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const {
975 llvm_unreachable("getDwarfRegNumForVirtReg does not exist on this target");
976 }
977
978 /// Spill the register so it can be used by the register scavenger.
979 /// Return true if the register was spilled, false otherwise.
980 /// If this function does not spill the register, the scavenger
981 /// will instead spill it to the emergency spill slot.
989
990 /// Process frame indices in reverse block order. This changes the behavior of
991 /// the RegScavenger passed to eliminateFrameIndex. If this is true targets
992 /// should scavengeRegisterBackwards in eliminateFrameIndex. New targets
993 /// should prefer reverse scavenging behavior.
994 /// TODO: Remove this when all targets return true.
995 virtual bool eliminateFrameIndicesBackwards() const { return true; }
996
997 /// This method must be overriden to eliminate abstract frame indices from
998 /// instructions which may use them. The instruction referenced by the
999 /// iterator contains an MO_FrameIndex operand which must be eliminated by
1000 /// this method. This method may modify or replace the specified instruction,
1001 /// as long as it keeps the iterator pointing at the finished product.
1002 /// SPAdj is the SP adjustment due to call frame setup instruction.
1003 /// FIOperandNum is the FI operand number.
1004 /// Returns true if the current instruction was removed and the iterator
1005 /// is not longer valid
1007 int SPAdj, unsigned FIOperandNum,
1008 RegScavenger *RS = nullptr) const = 0;
1009
1010 /// Return the assembly name for \p Reg.
1012 // FIXME: We are assuming that the assembly name is equal to the TableGen
1013 // name converted to lower case
1014 //
1015 // The TableGen name is the name of the definition for this register in the
1016 // target's tablegen files. For example, the TableGen name of
1017 // def EAX : Register <...>; is "EAX"
1018 return StringRef(getName(Reg));
1019 }
1020
1021 //===--------------------------------------------------------------------===//
1022 /// Subtarget Hooks
1023
1024 /// SrcRC and DstRC will be morphed into NewRC if this returns true.
1026 const TargetRegisterClass *SrcRC,
1027 unsigned SubReg,
1028 const TargetRegisterClass *DstRC,
1029 unsigned DstSubReg,
1030 const TargetRegisterClass *NewRC,
1031 LiveIntervals &LIS) const
1032 { return true; }
1033
1034 /// Region split has a high compile time cost especially for large live range.
1035 /// This method is used to decide whether or not \p VirtReg should
1036 /// go through this expensive splitting heuristic.
1037 virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF,
1038 const LiveInterval &VirtReg) const;
1039
1040 /// Last chance recoloring has a high compile time cost especially for
1041 /// targets with a lot of registers.
1042 /// This method is used to decide whether or not \p VirtReg should
1043 /// go through this expensive heuristic.
1044 /// When this target hook is hit, by returning false, there is a high
1045 /// chance that the register allocation will fail altogether (usually with
1046 /// "ran out of registers").
1047 /// That said, this error usually points to another problem in the
1048 /// optimization pipeline.
1049 virtual bool
1051 const LiveInterval &VirtReg) const {
1052 return true;
1053 }
1054
1055 /// When prioritizing live ranges in register allocation, if this hook returns
1056 /// true then the AllocationPriority of the register class will be treated as
1057 /// more important than whether the range is local to a basic block or global.
1058 virtual bool
1060 return false;
1061 }
1062
1063 //===--------------------------------------------------------------------===//
1064 /// Debug information queries.
1065
1066 /// getFrameRegister - This method should return the register used as a base
1067 /// for values allocated in the current stack frame.
1068 virtual Register getFrameRegister(const MachineFunction &MF) const = 0;
1069
1070 /// Mark a register and all its aliases as reserved in the given set.
1071 void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const;
1072
1073 /// Returns true if for every register in the set all super registers are part
1074 /// of the set as well.
1075 bool checkAllSuperRegsMarked(const BitVector &RegisterSet,
1076 ArrayRef<MCPhysReg> Exceptions = ArrayRef<MCPhysReg>()) const;
1077
1078 virtual const TargetRegisterClass *
1080 const MachineRegisterInfo &MRI) const {
1081 return nullptr;
1082 }
1083
1084 /// Some targets have non-allocatable registers that aren't technically part
1085 /// of the explicit callee saved register list, but should be handled as such
1086 /// in certain cases.
1088 return false;
1089 }
1090
1091 /// Some targets delay assigning the frame until late and use a placeholder
1092 /// to represent it earlier. This method can be used to identify the frame
1093 /// register placeholder.
1094 virtual bool isVirtualFrameRegister(MCRegister Reg) const { return false; }
1095
1096 virtual std::optional<uint8_t> getVRegFlagValue(StringRef Name) const {
1097 return {};
1098 }
1099
1102 return {};
1103 }
1104
1105 // Whether this register should be ignored when generating CodeView debug
1106 // info, because it's a known there is no mapping available.
1107 virtual bool isIgnoredCVReg(MCRegister LLVMReg) const { return false; }
1108};
1109
1110//===----------------------------------------------------------------------===//
1111// SuperRegClassIterator
1112//===----------------------------------------------------------------------===//
1113//
1114// Iterate over the possible super-registers for a given register class. The
1115// iterator will visit a list of pairs (Idx, Mask) corresponding to the
1116// possible classes of super-registers.
1117//
1118// Each bit mask will have at least one set bit, and each set bit in Mask
1119// corresponds to a SuperRC such that:
1120//
1121// For all Reg in SuperRC: Reg:Idx is in RC.
1122//
1123// The iterator can include (O, RC->getSubClassMask()) as the first entry which
1124// also satisfies the above requirement, assuming Reg:0 == Reg.
1125//
1127 const unsigned RCMaskWords;
1128 unsigned SubReg = 0;
1129 const uint16_t *Idx;
1130 const uint32_t *Mask;
1131
1132public:
1133 /// Create a SuperRegClassIterator that visits all the super-register classes
1134 /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
1136 const TargetRegisterInfo *TRI,
1137 bool IncludeSelf = false)
1138 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1139 Idx(RC->getSuperRegIndices()), Mask(RC->getSubClassMask()) {
1140 if (!IncludeSelf)
1141 ++*this;
1142 }
1143
1144 /// Returns true if this iterator is still pointing at a valid entry.
1145 bool isValid() const { return Idx; }
1146
1147 /// Returns the current sub-register index.
1148 unsigned getSubReg() const { return SubReg; }
1149
1150 /// Returns the bit mask of register classes that getSubReg() projects into
1151 /// RC.
1152 /// See TargetRegisterClass::getSubClassMask() for how to use it.
1153 const uint32_t *getMask() const { return Mask; }
1154
1155 /// Advance iterator to the next entry.
1156 void operator++() {
1157 assert(isValid() && "Cannot move iterator past end.");
1158 Mask += RCMaskWords;
1159 SubReg = *Idx++;
1160 if (!SubReg)
1161 Idx = nullptr;
1162 }
1163};
1164
1165//===----------------------------------------------------------------------===//
1166// BitMaskClassIterator
1167//===----------------------------------------------------------------------===//
1168/// This class encapuslates the logic to iterate over bitmask returned by
1169/// the various RegClass related APIs.
1170/// E.g., this class can be used to iterate over the subclasses provided by
1171/// TargetRegisterClass::getSubClassMask or SuperRegClassIterator::getMask.
1173 /// Total number of register classes.
1174 const unsigned NumRegClasses;
1175 /// Base index of CurrentChunk.
1176 /// In other words, the number of bit we read to get at the
1177 /// beginning of that chunck.
1178 unsigned Base = 0;
1179 /// Adjust base index of CurrentChunk.
1180 /// Base index + how many bit we read within CurrentChunk.
1181 unsigned Idx = 0;
1182 /// Current register class ID.
1183 unsigned ID = 0;
1184 /// Mask we are iterating over.
1185 const uint32_t *Mask;
1186 /// Current chunk of the Mask we are traversing.
1187 uint32_t CurrentChunk;
1188
1189 /// Move ID to the next set bit.
1190 void moveToNextID() {
1191 // If the current chunk of memory is empty, move to the next one,
1192 // while making sure we do not go pass the number of register
1193 // classes.
1194 while (!CurrentChunk) {
1195 // Move to the next chunk.
1196 Base += 32;
1197 if (Base >= NumRegClasses) {
1198 ID = NumRegClasses;
1199 return;
1200 }
1201 CurrentChunk = *++Mask;
1202 Idx = Base;
1203 }
1204 // Otherwise look for the first bit set from the right
1205 // (representation of the class ID is big endian).
1206 // See getSubClassMask for more details on the representation.
1207 unsigned Offset = llvm::countr_zero(CurrentChunk);
1208 // Add the Offset to the adjusted base number of this chunk: Idx.
1209 // This is the ID of the register class.
1210 ID = Idx + Offset;
1211
1212 // Consume the zeros, if any, and the bit we just read
1213 // so that we are at the right spot for the next call.
1214 // Do not do Offset + 1 because Offset may be 31 and 32
1215 // will be UB for the shift, though in that case we could
1216 // have make the chunk being equal to 0, but that would
1217 // have introduced a if statement.
1218 moveNBits(Offset);
1219 moveNBits(1);
1220 }
1221
1222 /// Move \p NumBits Bits forward in CurrentChunk.
1223 void moveNBits(unsigned NumBits) {
1224 assert(NumBits < 32 && "Undefined behavior spotted!");
1225 // Consume the bit we read for the next call.
1226 CurrentChunk >>= NumBits;
1227 // Adjust the base for the chunk.
1228 Idx += NumBits;
1229 }
1230
1231public:
1232 /// Create a BitMaskClassIterator that visits all the register classes
1233 /// represented by \p Mask.
1234 ///
1235 /// \pre \p Mask != nullptr
1237 : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1238 // Move to the first ID.
1239 moveToNextID();
1240 }
1241
1242 /// Returns true if this iterator is still pointing at a valid entry.
1243 bool isValid() const { return getID() != NumRegClasses; }
1244
1245 /// Returns the current register class ID.
1246 unsigned getID() const { return ID; }
1247
1248 /// Advance iterator to the next entry.
1249 void operator++() {
1250 assert(isValid() && "Cannot move iterator past end.");
1251 moveToNextID();
1252 }
1253};
1254
1255// This is useful when building IndexedMaps keyed on virtual registers
1258 unsigned operator()(Register Reg) const { return Reg.virtRegIndex(); }
1259};
1260
1261/// Prints virtual and physical registers with or without a TRI instance.
1262///
1263/// The format is:
1264/// %noreg - NoRegister
1265/// %5 - a virtual register.
1266/// %5:sub_8bit - a virtual register with sub-register index (with TRI).
1267/// %eax - a physical register
1268/// %physreg17 - a physical register when no TRI instance given.
1269///
1270/// Usage: OS << printReg(Reg, TRI, SubRegIdx) << '\n';
1271LLVM_ABI Printable printReg(Register Reg,
1272 const TargetRegisterInfo *TRI = nullptr,
1273 unsigned SubIdx = 0,
1274 const MachineRegisterInfo *MRI = nullptr);
1275
1276/// Create Printable object to print register units on a \ref raw_ostream.
1277///
1278/// Register units are named after their root registers:
1279///
1280/// al - Single root.
1281/// fp0~st7 - Dual roots.
1282///
1283/// Usage: OS << printRegUnit(Unit, TRI) << '\n';
1284LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI);
1285
1286/// Create Printable object to print virtual registers and physical
1287/// registers on a \ref raw_ostream.
1288LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit,
1289 const TargetRegisterInfo *TRI);
1290
1291/// Create Printable object to print register classes or register banks
1292/// on a \ref raw_ostream.
1294 const MachineRegisterInfo &RegInfo,
1295 const TargetRegisterInfo *TRI);
1296
1297} // end namespace llvm
1298
1299#endif // LLVM_CODEGEN_TARGETREGISTERINFO_H
MachineInstrBuilder & UseMI
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
A common definition of LaneBitmask for use in TableGen and CodeGen.
Live Register Matrix
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static StringRef getName(Value *V)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
static const TargetRegisterClass * getCommonMinimalPhysRegClass(const TargetRegisterInfo *TRI, MCRegister Reg1, MCRegister Reg2)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void operator++()
Advance iterator to the next entry.
unsigned getID() const
Returns the current register class ID.
BitMaskClassIterator(const uint32_t *Mask, const TargetRegisterInfo &TRI)
Create a BitMaskClassIterator that visits all the register classes represented by Mask.
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
DWARF expression.
LiveInterval - This class represents the liveness of a register, or stack slot.
MCRegisterClass - Base class of TargetRegisterClass.
const uint8_t SpillStackID
unsigned getID() const
getID() - Return the register class ID number.
ArrayRef< MCPhysReg > getRegisters() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
unsigned getNumRegClasses() const
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
const MCRegisterClass & getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Holds all the information related to register banks.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void operator++()
Advance iterator to the next entry.
unsigned getSubReg() const
Returns the current sub-register index.
const uint32_t * getMask() const
Returns the bit mask of register classes that getSubReg() projects into RC.
SuperRegClassIterator(const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, bool IncludeSelf=false)
Create a SuperRegClassIterator that visits all the super-register classes of RC.
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool isConstantPhysReg(MCRegister PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
virtual SmallVector< StringLiteral > getVRegFlagsOfReg(Register Reg, const MachineFunction &MF) const
virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const
Determine whether a given base register plus offset immediate is encodable to resolve a frame index.
virtual ArrayRef< MCPhysReg > getRawAllocationOrder(const TargetRegisterClass &RC, const MachineFunction &, bool=false) const
Returns the preferred order for allocating registers from this register class in MF.
vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const
bool isTypeLegalForClass(const TargetRegisterClass &RC, LLT T) const
Return true if the given TargetRegisterClass is compatible with LLT T.
bool hasRegUnit(MCRegister Reg, MCRegUnit RegUnit) const
Returns true if Reg contains RegUnit.
virtual unsigned getNumRegPressureSets() const =0
Get the number of dimensions of register pressure.
~TargetRegisterInfo() override
unsigned reverseComposeSubRegIndices(unsigned a, unsigned b) const
Return a subregister index that will compose to give you the subregister index.
virtual const int * getRegUnitPressureSets(MCRegUnit RegUnit) const =0
Get the dimensions of register pressure impacted by this register unit.
virtual const TargetRegisterClass * getPhysRegBaseClass(MCRegister Reg) const
Return target defined base register class for a physical register.
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
virtual bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const
Returns false if we can't guarantee that Physreg, specified as an IR asm clobber constraint,...
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
Returns the largest legal sub-class of RC that supports the sub-register index Idx.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
virtual bool useFPForScavengingIndex(const MachineFunction &MF) const
Returns true if the target wants to use frame pointer based accesses to spill to the scavenger emerge...
virtual const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const
Returns a legal register class to copy a register in the specified class to or from.
virtual bool isVirtualFrameRegister(MCRegister Reg) const
Some targets delay assigning the frame until late and use a placeholder to represent it earlier.
virtual bool shouldUseLastChanceRecoloringForVirtReg(const MachineFunction &MF, const LiveInterval &VirtReg) const
Last chance recoloring has a high compile time cost especially for targets with a lot of registers.
virtual bool eliminateFrameIndicesBackwards() const
Process frame indices in reverse block order.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
virtual LaneBitmask composeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
Overridden by TableGen in targets that have sub-registers.
virtual bool isIgnoredCVReg(MCRegister LLVMReg) const
virtual bool isGeneralPurposeRegisterClass(const TargetRegisterClass *RC) const
Returns true if RC is a class/subclass of general purpose register.
virtual unsigned getCSRFirstUseCost() const
Allow the target to override the cost of using a callee-saved register for the first time.
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
virtual const MCPhysReg * getIPRACSRegs(const MachineFunction *MF) const
Return a null-terminated list of all of the callee-saved registers on this target when IPRA is on.
virtual const uint32_t * getCustomEHPadPreservedMask(const MachineFunction &MF) const
Return a register mask for the registers preserved by the unwinder, or nullptr if no custom mask is n...
virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const
Get the scale factor of spill weight for this register class.
const MVT::SimpleValueType * vt_iterator
virtual bool isUniformReg(const MachineRegisterInfo &MRI, const RegisterBankInfo &RBI, Register Reg) const
Returns true if the register is considered uniform.
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
virtual std::optional< std::string > explainReservedReg(const MachineFunction &MF, MCRegister PhysReg) const
Returns either a string explaining why the given register is reserved for this function,...
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
const char * getSubRegIndexName(unsigned SubIdx) const
Return the human-readable symbolic target-specific name for the specified SubRegIndex.
virtual const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
Return a mask of call-preserved registers for the given calling convention on the current function.
virtual const char * getRegPressureSetName(unsigned Idx) const =0
Get the name of this register unit pressure set.
virtual LaneBitmask reverseComposeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
LaneBitmask getCoveringLanes() const
The lane masks returned by getSubRegIndexLaneMask() above can only be used to determine if sub-regist...
virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const
Get the offset from the referenced frame index in the instruction, if there is one.
ArrayRef< uint8_t > getRegisterCosts(const MachineFunction &MF) const
Get a list of cost values for all registers that correspond to the index returned by RegisterCostTabl...
virtual bool isGeneralPurposeRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a general purpose register.
virtual ArrayRef< const uint32_t * > getRegMasks() const =0
Return all the call-preserved register masks defined for this target.
LaneBitmask reverseComposeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask LaneMask) const
Transform a lanemask given for a virtual register to the corresponding lanemask before using subregis...
virtual unsigned getRegPressureSetScore(const MachineFunction &MF, unsigned PSetID) const
Return a heuristic for the machine scheduler to compare the profitability of increasing one register ...
virtual const int * getRegClassPressureSets(const TargetRegisterClass *RC) const =0
Get the dimensions of register pressure impacted by this register class.
virtual const RegClassWeight & getRegClassWeight(const TargetRegisterClass *RC) const =0
Get the weight in units of pressure for this register class.
virtual ArrayRef< MCPhysReg > getIntraCallClobberedRegs(const MachineFunction *MF) const
Return a list of all of the registers which are clobbered "inside" a call to the given function.
virtual bool reverseLocalAssignment() const
Allow the target to reverse allocation order of local live ranges.
virtual bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const
Some targets have non-allocatable registers that aren't technically part of the explicit callee saved...
vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const
Loop over all of the value types that can be represented by values in the given register class.
virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const
Return the register pressure "high water mark" for the specific register class.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx.
virtual const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg) const =0
Returns the Register Class of a physical register, picking the smallest register subclass that contai...
bool checkAllSuperRegsMarked(const BitVector &RegisterSet, ArrayRef< MCPhysReg > Exceptions=ArrayRef< MCPhysReg >()) const
Returns true if for every register in the set all super registers are part of the set as well.
virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const
virtual const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const
Returns the largest super class of RC that is legal to use in the current sub-target and has the same...
virtual BitVector getReservedRegs(const MachineFunction &MF) const =0
Returns a bitset indexed by physical register number indicating if a register is a special register t...
const RegClassInfo & getRegClassInfo(const TargetRegisterClass &RC) const
virtual const uint32_t * getNoPreservedMask() const
Return a register mask that clobbers everything.
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const
Returns true if the live-ins should be tracked after register allocation.
virtual bool isArgumentRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg can be used as an argument to a function.
Align getSpillAlign(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
virtual std::optional< uint8_t > getVRegFlagValue(StringRef Name) const
virtual const TargetRegisterClass * getSubRegisterClass(const TargetRegisterClass *SuperRC, unsigned SubRegIdx) const
Returns the register class of all sub-registers of SuperRC obtained by applying the sub-register inde...
virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const =0
Get the register unit pressure limit for this dimension.
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
virtual bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
virtual unsigned getRegUnitWeight(MCRegUnit RegUnit) const =0
Get the weight in units of pressure for this register unit.
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger.
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
Return the maximal subclass of the given register class that is allocatable or NULL.
LaneBitmask composeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask Mask) const
Transforms a LaneMask computed for one subregister to the lanemask that would have been computed when...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const
Returns true if MachineLoopInfo should analyze the given physreg for loop invariance.
virtual bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, Register Reg) const
Spill the register so it can be used by the register scavenger.
virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
virtual bool isCallerPreservedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
Physical registers that may be modified within a function but are guaranteed to be restored before an...
virtual bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
virtual void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const
Resolve a frame index operand of an instruction to reference the indicated base register plus offset ...
virtual bool isDivergentRegClass(const TargetRegisterClass *RC) const
Returns true if the register class is considered divergent.
virtual Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const
Insert defining instruction(s) for a pointer to FrameIdx before insertion point I.
bool regsOverlap(Register RegA, Register RegB) const
Returns true if the two registers are equal or alias each other.
virtual bool shouldRealignStack(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
virtual unsigned getNumSupportedRegs(const MachineFunction &) const
Return the number of registers for the function. (may overestimate)
TargetStackID::Value getSpillStackID(const TargetRegisterClass &RC) const
Return the stack ID for spill slots holding a spilled copy of a register from this class.
virtual unsigned getCSRCost() const
FIXME: We should deprecate this usage.
virtual ArrayRef< const char * > getRegMaskNames() const =0
virtual bool isFixedRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a fixed register.
const TargetRegisterClass * findCommonRegClass(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
Find a common register class that can accomodate both the source and destination operands of a copy-l...
virtual const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
virtual StringRef getRegAsmName(MCRegister Reg) const
Return the assembly name for Reg.
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, const char *SubRegIndexStrings, ArrayRef< uint32_t > SubRegIndexNameOffsets, const SubRegCoveredBits *SubRegIdxRanges, const LaneBitmask *SubRegIndexLaneMasks, LaneBitmask CoveringLanes, const RegClassInfo *const RCInfos, const MVT::SimpleValueType *const RCVTLists, unsigned Mode=0)
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
virtual unsigned getRegisterCostTableIndex(const MachineFunction &MF) const
Return the register cost table index.
virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const
Returns true if the instruction's frame index reference would be better served by a base register oth...
virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
virtual const TargetRegisterClass * getPointerRegClass(unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
virtual unsigned reverseComposeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const
Prior to adding the live-out mask to a stackmap or patchpoint instruction, provide the target the opp...
bool isSubRegValidForRegClass(const TargetRegisterClass *RC, unsigned Idx) const
Returns true if sub-register Idx can be used with register class RC.
virtual bool isInlineAsmReadOnlyReg(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg cannot be written to in inline asm statements.
virtual bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const
Subtarget Hooks.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
virtual bool regClassPriorityTrumpsGlobalness(const MachineFunction &MF) const
When prioritizing live ranges in register allocation, if this hook returns true then the AllocationPr...
bool isInAllocatableClass(MCRegister RegNo) const
Return true if the register is in the allocation of any register class.
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not.
virtual void updateRegAllocHint(Register Reg, Register NewReg, MachineFunction &MF) const
A callback to allow target a chance to update register allocation hints when a register is "changed" ...
virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const
Returns true if the target wants the LocalStackAllocation pass to be run and virtual base registers u...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:573
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Each TargetRegisterClass has a per register weight, and weight limit which must be less than the limi...
Extra information, not in MCRegisterDesc, about registers.
SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg index, -1 in any being invalid...
unsigned operator()(Register Reg) const