LLVM 24.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 legal register class to copy a register in the specified class
719 /// to or from. If it is possible to copy the register directly without using
720 /// a cross register class copy, return the specified RC. Returns NULL if it
721 /// is not possible to copy between two registers of the specified class.
722 virtual const TargetRegisterClass *
724 return RC;
725 }
726
727 /// Returns the largest super class of RC that is legal to use in the current
728 /// sub-target and has the same spill size.
729 /// The returned register class can be used to create virtual registers which
730 /// means that all its registers can be copied and spilled.
731 virtual const TargetRegisterClass *
733 const MachineFunction &) const {
734 /// The default implementation is very conservative and doesn't allow the
735 /// register allocator to inflate register classes.
736 return RC;
737 }
738
739 /// Return the register pressure "high water mark" for the specific register
740 /// class. The scheduler is in high register pressure mode (for the specific
741 /// register class) if it goes over the limit.
742 ///
743 /// Note: this is the old register pressure model that relies on a manually
744 /// specified representative register class per value type.
745 virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
746 MachineFunction &MF) const {
747 return 0;
748 }
749
750 /// Return a heuristic for the machine scheduler to compare the profitability
751 /// of increasing one register pressure set versus another. The scheduler
752 /// will prefer increasing the register pressure of the set which returns
753 /// the largest value for this function.
754 virtual unsigned getRegPressureSetScore(const MachineFunction &MF,
755 unsigned PSetID) const {
756 return PSetID;
757 }
758
759 /// Get the weight in units of pressure for this register class.
761 const TargetRegisterClass *RC) const = 0;
762
763 /// Returns size in bits of a phys/virtual/generic register.
765
766 /// Get the weight in units of pressure for this register unit.
767 virtual unsigned getRegUnitWeight(MCRegUnit RegUnit) const = 0;
768
769 /// Get the number of dimensions of register pressure.
770 virtual unsigned getNumRegPressureSets() const = 0;
771
772 /// Get the name of this register unit pressure set.
773 virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
774
775 /// Get the register unit pressure limit for this dimension.
776 /// This limit must be adjusted dynamically for reserved registers.
777 virtual unsigned getRegPressureSetLimit(const MachineFunction &MF,
778 unsigned Idx) const = 0;
779
780 /// Get the register class for this pressure set with the largest
781 /// `RegClassWeight::WeightLimit`.
782 virtual const TargetRegisterClass *
783 getLargestRegClassForRegPressureSet(unsigned Idx) const = 0;
784
785 /// Get the dimensions of register pressure impacted by this register class.
786 /// Returns a -1 terminated array of pressure set IDs.
787 virtual const int *getRegClassPressureSets(
788 const TargetRegisterClass *RC) const = 0;
789
790 /// Get the dimensions of register pressure impacted by this register unit.
791 /// Returns a -1 terminated array of pressure set IDs.
792 virtual const int *getRegUnitPressureSets(MCRegUnit RegUnit) const = 0;
793
794 /// Get the scale factor of spill weight for this register class.
795 virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const;
796
797 /// Returns the preferred order for allocating registers from this register
798 /// class in MF. The raw order comes directly from the .td file and may
799 /// include reserved registers that are not allocatable.
800 /// Register allocators should also make sure to allocate
801 /// callee-saved registers only after all the volatiles are used. The
802 /// RegisterClassInfo class provides filtered allocation orders with
803 /// callee-saved registers moved to the end.
804 ///
805 /// The MachineFunction argument can be used to tune the allocatable
806 /// registers based on the characteristics of the function, subtarget, or
807 /// other criteria.
808 ///
809 /// By default, this method returns all registers in the class.
810 virtual ArrayRef<MCPhysReg>
812 bool /*Rev*/ = false) const {
813 return RC.getRegisters();
814 }
815
816 /// Get a list of 'hint' registers that the register allocator should try
817 /// first when allocating a physical register for the virtual register
818 /// VirtReg. These registers are effectively moved to the front of the
819 /// allocation order. If true is returned, regalloc will try to only use
820 /// hints to the greatest extent possible even if it means spilling.
821 ///
822 /// The Order argument is the allocation order for VirtReg's register class
823 /// as returned from RegisterClassInfo::getOrder(). The hint registers must
824 /// come from Order, and they must not be reserved.
825 ///
826 /// The default implementation of this function will only add target
827 /// independent register allocation hints. Targets that override this
828 /// function should typically call this default implementation as well and
829 /// expect to see generic copy hints added.
830 virtual bool
831 getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
833 const MachineFunction &MF,
834 const VirtRegMap *VRM = nullptr,
835 const LiveRegMatrix *Matrix = nullptr) const;
836
837 /// A callback to allow target a chance to update register allocation hints
838 /// when a register is "changed" (e.g. coalesced) to another register.
839 /// e.g. On ARM, some virtual registers should target register pairs,
840 /// if one of pair is coalesced to another register, the allocation hint of
841 /// the other half of the pair should be changed to point to the new register.
843 MachineFunction &MF) const {
844 // Do nothing.
845 }
846
847 /// Allow the target to reverse allocation order of local live ranges. This
848 /// will generally allocate shorter local live ranges first. For targets with
849 /// many registers, this could reduce regalloc compile time by a large
850 /// factor. It is disabled by default for three reasons:
851 /// (1) Top-down allocation is simpler and easier to debug for targets that
852 /// don't benefit from reversing the order.
853 /// (2) Bottom-up allocation could result in poor evicition decisions on some
854 /// targets affecting the performance of compiled code.
855 /// (3) Bottom-up allocation is no longer guaranteed to optimally color.
856 virtual bool reverseLocalAssignment() const { return false; }
857
858 /// Allow the target to override the cost of using a callee-saved register for
859 /// the first time. Default value of 0 means we will use a callee-saved
860 /// register if it is available.
861 virtual unsigned getCSRFirstUseCost(const MachineFunction &MF) const {
862 return 0;
863 }
864 /// FIXME: We should deprecate this usage.
865 virtual unsigned getCSRCost() const { return 0; }
866
867 /// Scale the CSRFirstUseCost with this number.
868 /// The scale is a percentage (e.g., 30 means 30% of the base cost).
869 /// Target can tune and override this default value.
870 virtual unsigned getCSRCostScale(const MachineFunction &MF) const {
871 return 30;
872 }
873
874 /// Returns true if the target requires (and can make use of) the register
875 /// scavenger.
876 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
877 return false;
878 }
879
880 /// Returns true if the target wants to use frame pointer based accesses to
881 /// spill to the scavenger emergency spill slot.
882 virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
883 return true;
884 }
885
886 /// Returns true if the target requires post PEI scavenging of registers for
887 /// materializing frame index constants.
888 virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
889 return false;
890 }
891
892 /// Returns true if the target requires using the RegScavenger directly for
893 /// frame elimination despite using requiresFrameIndexScavenging.
895 const MachineFunction &MF) const {
896 return false;
897 }
898
899 /// Returns true if the target wants the LocalStackAllocation pass to be run
900 /// and virtual base registers used for more efficient stack access.
901 virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
902 return false;
903 }
904
905 /// Return true if target has reserved a spill slot in the stack frame of
906 /// the given function for the specified register. e.g. On x86, if the frame
907 /// register is required, the first fixed stack object is reserved as its
908 /// spill slot. This tells PEI not to create a new stack frame
909 /// object for the given register. It should be called only after
910 /// determineCalleeSaves().
912 int &FrameIdx) const {
913 return false;
914 }
915
916 /// Returns true if the live-ins should be tracked after register allocation.
917 virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
918 return true;
919 }
920
921 /// True if the stack can be realigned for the target.
922 virtual bool canRealignStack(const MachineFunction &MF) const;
923
924 /// True if storage within the function requires the stack pointer to be
925 /// aligned more than the normal calling convention calls for.
926 virtual bool shouldRealignStack(const MachineFunction &MF) const;
927
928 /// True if stack realignment is required and still possible.
929 bool hasStackRealignment(const MachineFunction &MF) const {
930 return shouldRealignStack(MF) && canRealignStack(MF);
931 }
932
933 /// Get the offset from the referenced frame index in the instruction,
934 /// if there is one.
936 int Idx) const {
937 return 0;
938 }
939
940 /// Returns true if the instruction's frame index reference would be better
941 /// served by a base register other than FP or SP.
942 /// Used by LocalStackFrameAllocation to determine which frame index
943 /// references it should create new base registers for.
944 virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
945 return false;
946 }
947
948 /// Insert defining instruction(s) for a pointer to FrameIdx before
949 /// insertion point I. Return materialized frame pointer.
951 int FrameIdx,
952 int64_t Offset) const {
953 llvm_unreachable("materializeFrameBaseRegister does not exist on this "
954 "target");
955 }
956
957 /// Resolve a frame index operand of an instruction
958 /// to reference the indicated base register plus offset instead.
960 int64_t Offset) const {
961 llvm_unreachable("resolveFrameIndex does not exist on this target");
962 }
963
964 /// Determine whether a given base register plus offset immediate is
965 /// encodable to resolve a frame index.
966 virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
967 int64_t Offset) const {
968 llvm_unreachable("isFrameOffsetLegal does not exist on this target");
969 }
970
971 /// Gets the DWARF expression opcodes for \p Offset.
972 virtual void getOffsetOpcodes(const StackOffset &Offset,
974
975 /// Prepends a DWARF expression for \p Offset to DIExpression \p Expr.
977 prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags,
978 const StackOffset &Offset) const;
979
980 virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const {
981 llvm_unreachable("getDwarfRegNumForVirtReg does not exist on this target");
982 }
983
984 /// Spill the register so it can be used by the register scavenger.
985 /// Return true if the register was spilled, false otherwise.
986 /// If this function does not spill the register, the scavenger
987 /// will instead spill it to the emergency spill slot.
995
996 /// Process frame indices in reverse block order. This changes the behavior of
997 /// the RegScavenger passed to eliminateFrameIndex. If this is true targets
998 /// should scavengeRegisterBackwards in eliminateFrameIndex. New targets
999 /// should prefer reverse scavenging behavior.
1000 /// TODO: Remove this when all targets return true.
1001 virtual bool eliminateFrameIndicesBackwards() const { return true; }
1002
1003 /// This method must be overriden to eliminate abstract frame indices from
1004 /// instructions which may use them. The instruction referenced by the
1005 /// iterator contains an MO_FrameIndex operand which must be eliminated by
1006 /// this method. This method may modify or replace the specified instruction,
1007 /// as long as it keeps the iterator pointing at the finished product.
1008 /// SPAdj is the SP adjustment due to call frame setup instruction.
1009 /// FIOperandNum is the FI operand number.
1010 /// Returns true if the current instruction was removed and the iterator
1011 /// is not longer valid
1013 int SPAdj, unsigned FIOperandNum,
1014 RegScavenger *RS = nullptr) const = 0;
1015
1016 /// Return the assembly name for \p Reg.
1018 // FIXME: We are assuming that the assembly name is equal to the TableGen
1019 // name converted to lower case
1020 //
1021 // The TableGen name is the name of the definition for this register in the
1022 // target's tablegen files. For example, the TableGen name of
1023 // def EAX : Register <...>; is "EAX"
1024 return StringRef(getName(Reg));
1025 }
1026
1027 //===--------------------------------------------------------------------===//
1028 /// Subtarget Hooks
1029
1030 /// SrcRC and DstRC will be morphed into NewRC if this returns true.
1032 const TargetRegisterClass *SrcRC,
1033 unsigned SubReg,
1034 const TargetRegisterClass *DstRC,
1035 unsigned DstSubReg,
1036 const TargetRegisterClass *NewRC,
1037 LiveIntervals &LIS) const
1038 { return true; }
1039
1040 /// Region split has a high compile time cost especially for large live range.
1041 /// This method is used to decide whether or not \p VirtReg should
1042 /// go through this expensive splitting heuristic.
1043 virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF,
1044 const LiveInterval &VirtReg) const;
1045
1046 /// Last chance recoloring has a high compile time cost especially for
1047 /// targets with a lot of registers.
1048 /// This method is used to decide whether or not \p VirtReg should
1049 /// go through this expensive heuristic.
1050 /// When this target hook is hit, by returning false, there is a high
1051 /// chance that the register allocation will fail altogether (usually with
1052 /// "ran out of registers").
1053 /// That said, this error usually points to another problem in the
1054 /// optimization pipeline.
1055 virtual bool
1057 const LiveInterval &VirtReg) const {
1058 return true;
1059 }
1060
1061 /// When prioritizing live ranges in register allocation, if this hook returns
1062 /// true then the AllocationPriority of the register class will be treated as
1063 /// more important than whether the range is local to a basic block or global.
1064 virtual bool
1066 return false;
1067 }
1068
1069 //===--------------------------------------------------------------------===//
1070 /// Debug information queries.
1071
1072 /// getFrameRegister - This method should return the register used as a base
1073 /// for values allocated in the current stack frame.
1074 virtual Register getFrameRegister(const MachineFunction &MF) const = 0;
1075
1076 /// Mark a register and all its aliases as reserved in the given set.
1077 void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const;
1078
1079 /// Returns true if for every register in the set all super registers are part
1080 /// of the set as well.
1081 bool checkAllSuperRegsMarked(const BitVector &RegisterSet,
1082 ArrayRef<MCPhysReg> Exceptions = ArrayRef<MCPhysReg>()) const;
1083
1084 virtual const TargetRegisterClass *
1086 const MachineRegisterInfo &MRI) const {
1087 return nullptr;
1088 }
1089
1090 /// Some targets have non-allocatable registers that aren't technically part
1091 /// of the explicit callee saved register list, but should be handled as such
1092 /// in certain cases.
1094 return false;
1095 }
1096
1097 /// Some targets delay assigning the frame until late and use a placeholder
1098 /// to represent it earlier. This method can be used to identify the frame
1099 /// register placeholder.
1100 virtual bool isVirtualFrameRegister(MCRegister Reg) const { return false; }
1101
1102 virtual std::optional<uint8_t> getVRegFlagValue(StringRef Name) const {
1103 return {};
1104 }
1105
1108 return {};
1109 }
1110
1111 // Whether this register should be ignored when generating CodeView debug
1112 // info, because it's a known there is no mapping available.
1113 virtual bool isIgnoredCVReg(MCRegister LLVMReg) const { return false; }
1114};
1115
1116//===----------------------------------------------------------------------===//
1117// SuperRegClassIterator
1118//===----------------------------------------------------------------------===//
1119//
1120// Iterate over the possible super-registers for a given register class. The
1121// iterator will visit a list of pairs (Idx, Mask) corresponding to the
1122// possible classes of super-registers.
1123//
1124// Each bit mask will have at least one set bit, and each set bit in Mask
1125// corresponds to a SuperRC such that:
1126//
1127// For all Reg in SuperRC: Reg:Idx is in RC.
1128//
1129// The iterator can include (O, RC->getSubClassMask()) as the first entry which
1130// also satisfies the above requirement, assuming Reg:0 == Reg.
1131//
1133 const unsigned RCMaskWords;
1134 unsigned SubReg = 0;
1135 const uint16_t *Idx;
1136 const uint32_t *Mask;
1137
1138public:
1139 /// Create a SuperRegClassIterator that visits all the super-register classes
1140 /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
1142 const TargetRegisterInfo *TRI,
1143 bool IncludeSelf = false)
1144 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1145 Idx(RC->getSuperRegIndices()), Mask(RC->getSubClassMask()) {
1146 if (!IncludeSelf)
1147 ++*this;
1148 }
1149
1150 /// Returns true if this iterator is still pointing at a valid entry.
1151 bool isValid() const { return Idx; }
1152
1153 /// Returns the current sub-register index.
1154 unsigned getSubReg() const { return SubReg; }
1155
1156 /// Returns the bit mask of register classes that getSubReg() projects into
1157 /// RC.
1158 /// See TargetRegisterClass::getSubClassMask() for how to use it.
1159 const uint32_t *getMask() const { return Mask; }
1160
1161 /// Advance iterator to the next entry.
1162 void operator++() {
1163 assert(isValid() && "Cannot move iterator past end.");
1164 Mask += RCMaskWords;
1165 SubReg = *Idx++;
1166 if (!SubReg)
1167 Idx = nullptr;
1168 }
1169};
1170
1171//===----------------------------------------------------------------------===//
1172// BitMaskClassIterator
1173//===----------------------------------------------------------------------===//
1174/// This class encapuslates the logic to iterate over bitmask returned by
1175/// the various RegClass related APIs.
1176/// E.g., this class can be used to iterate over the subclasses provided by
1177/// TargetRegisterClass::getSubClassMask or SuperRegClassIterator::getMask.
1179 /// Total number of register classes.
1180 const unsigned NumRegClasses;
1181 /// Base index of CurrentChunk.
1182 /// In other words, the number of bit we read to get at the
1183 /// beginning of that chunck.
1184 unsigned Base = 0;
1185 /// Adjust base index of CurrentChunk.
1186 /// Base index + how many bit we read within CurrentChunk.
1187 unsigned Idx = 0;
1188 /// Current register class ID.
1189 unsigned ID = 0;
1190 /// Mask we are iterating over.
1191 const uint32_t *Mask;
1192 /// Current chunk of the Mask we are traversing.
1193 uint32_t CurrentChunk;
1194
1195 /// Move ID to the next set bit.
1196 void moveToNextID() {
1197 // If the current chunk of memory is empty, move to the next one,
1198 // while making sure we do not go pass the number of register
1199 // classes.
1200 while (!CurrentChunk) {
1201 // Move to the next chunk.
1202 Base += 32;
1203 if (Base >= NumRegClasses) {
1204 ID = NumRegClasses;
1205 return;
1206 }
1207 CurrentChunk = *++Mask;
1208 Idx = Base;
1209 }
1210 // Otherwise look for the first bit set from the right
1211 // (representation of the class ID is big endian).
1212 // See getSubClassMask for more details on the representation.
1213 unsigned Offset = llvm::countr_zero(CurrentChunk);
1214 // Add the Offset to the adjusted base number of this chunk: Idx.
1215 // This is the ID of the register class.
1216 ID = Idx + Offset;
1217
1218 // Consume the zeros, if any, and the bit we just read
1219 // so that we are at the right spot for the next call.
1220 // Do not do Offset + 1 because Offset may be 31 and 32
1221 // will be UB for the shift, though in that case we could
1222 // have make the chunk being equal to 0, but that would
1223 // have introduced a if statement.
1224 moveNBits(Offset);
1225 moveNBits(1);
1226 }
1227
1228 /// Move \p NumBits Bits forward in CurrentChunk.
1229 void moveNBits(unsigned NumBits) {
1230 assert(NumBits < 32 && "Undefined behavior spotted!");
1231 // Consume the bit we read for the next call.
1232 CurrentChunk >>= NumBits;
1233 // Adjust the base for the chunk.
1234 Idx += NumBits;
1235 }
1236
1237public:
1238 /// Create a BitMaskClassIterator that visits all the register classes
1239 /// represented by \p Mask.
1240 ///
1241 /// \pre \p Mask != nullptr
1243 : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1244 // Move to the first ID.
1245 moveToNextID();
1246 }
1247
1248 /// Returns true if this iterator is still pointing at a valid entry.
1249 bool isValid() const { return getID() != NumRegClasses; }
1250
1251 /// Returns the current register class ID.
1252 unsigned getID() const { return ID; }
1253
1254 /// Advance iterator to the next entry.
1255 void operator++() {
1256 assert(isValid() && "Cannot move iterator past end.");
1257 moveToNextID();
1258 }
1259};
1260
1261// This is useful when building IndexedMaps keyed on virtual registers
1264 unsigned operator()(Register Reg) const { return Reg.virtRegIndex(); }
1265};
1266
1267/// Prints virtual and physical registers with or without a TRI instance.
1268///
1269/// The format is:
1270/// %noreg - NoRegister
1271/// %5 - a virtual register.
1272/// %5:sub_8bit - a virtual register with sub-register index (with TRI).
1273/// %eax - a physical register
1274/// %physreg17 - a physical register when no TRI instance given.
1275///
1276/// Usage: OS << printReg(Reg, TRI, SubRegIdx) << '\n';
1277LLVM_ABI Printable printReg(Register Reg,
1278 const TargetRegisterInfo *TRI = nullptr,
1279 unsigned SubIdx = 0,
1280 const MachineRegisterInfo *MRI = nullptr);
1281
1282/// Create Printable object to print register units on a \ref raw_ostream.
1283///
1284/// Register units are named after their root registers:
1285///
1286/// al - Single root.
1287/// fp0~st7 - Dual roots.
1288///
1289/// Usage: OS << printRegUnit(Unit, TRI) << '\n';
1290LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI);
1291
1292/// Create Printable object to print virtual registers and physical
1293/// registers on a \ref raw_ostream.
1294LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit,
1295 const TargetRegisterInfo *TRI);
1296
1297/// Create Printable object to print register classes or register banks
1298/// on a \ref raw_ostream.
1300 const MachineRegisterInfo &RegInfo,
1301 const TargetRegisterInfo *TRI);
1302
1303} // end namespace llvm
1304
1305#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.
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.
virtual const TargetRegisterClass * getLargestRegClassForRegPressureSet(unsigned Idx) const =0
Get the register class for this pressure set with the largest RegClassWeight::WeightLimit.
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.
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 unsigned getCSRCostScale(const MachineFunction &MF) const
Scale the CSRFirstUseCost with this number.
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.
virtual const TargetRegisterClass * getConstrainedRegClassForReg(Register Reg, const MachineRegisterInfo &MRI) const
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...
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 getCSRFirstUseCost(const MachineFunction &MF) const
Allow the target to override the cost of using a callee-saved register for the first time.
virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
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:339
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:577
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:1963
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