LLVM 23.0.0git
TargetRegisterInfo.cpp
Go to the documentation of this file.
1//==- TargetRegisterInfo.cpp - Target Register Information Implementation --==//
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 implements the TargetRegisterInfo interface.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/BitVector.h"
16#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/SmallSet.h"
29#include "llvm/Config/llvm-config.h"
30#include "llvm/IR/Attributes.h"
32#include "llvm/IR/Function.h"
36#include "llvm/Support/Debug.h"
39#include <cassert>
40#include <utility>
41
42#define DEBUG_TYPE "target-reg-info"
43
44using namespace llvm;
45
47 HugeSizeForSplit("huge-size-for-split", cl::Hidden,
48 cl::desc("A threshold of live range size which may cause "
49 "high compile time cost in global splitting."),
50 cl::init(5000));
51
55 const char *SubRegIndexStrings, ArrayRef<uint32_t> SubRegIndexNameOffsets,
56 const SubRegCoveredBits *SubRegIdxRanges,
57 const LaneBitmask *SubRegIndexLaneMasks, LaneBitmask CoveringLanes,
58 const RegClassInfo *const RCInfos,
59 const MVT::SimpleValueType *const RCVTLists, unsigned Mode)
60 : InfoDesc(ID), SubRegIndexStrings(SubRegIndexStrings),
61 SubRegIndexNameOffsets(SubRegIndexNameOffsets),
62 SubRegIdxRanges(SubRegIdxRanges),
63 SubRegIndexLaneMasks(SubRegIndexLaneMasks),
64 RegClassBegin(RegisterClasses.begin()),
65 RegClassEnd(RegisterClasses.end()), CoveringLanes(CoveringLanes),
66 RCInfos(RCInfos), RCVTLists(RCVTLists), HwMode(Mode) {}
67
69
71 const MachineFunction &MF, const LiveInterval &VirtReg) const {
73 const MachineRegisterInfo &MRI = MF.getRegInfo();
74 MachineInstr *MI = MRI.getUniqueVRegDef(VirtReg.reg());
75 if (MI && TII->isTriviallyReMaterializable(*MI) &&
76 VirtReg.size() > HugeSizeForSplit)
77 return false;
78 return true;
79}
80
82 MCRegister Reg) const {
83 for (MCPhysReg SR : superregs_inclusive(Reg))
84 RegisterSet.set(SR);
85}
86
88 ArrayRef<MCPhysReg> Exceptions) const {
89 // Check that all super registers of reserved regs are reserved as well.
90 BitVector Checked(getNumRegs());
91 for (unsigned Reg : RegisterSet.set_bits()) {
92 if (Checked[Reg])
93 continue;
94 for (MCPhysReg SR : superregs(Reg)) {
95 if (!RegisterSet[SR] && !is_contained(Exceptions, Reg)) {
96 dbgs() << "Error: Super register " << printReg(SR, this)
97 << " of reserved register " << printReg(Reg, this)
98 << " is not reserved.\n";
99 return false;
100 }
101
102 // We transitively check superregs. So we can remember this for later
103 // to avoid compiletime explosion in deep register hierarchies.
104 Checked.set(SR);
105 }
106 }
107 return true;
108}
109
111 unsigned SubIdx, const MachineRegisterInfo *MRI) {
112 return Printable([Reg, TRI, SubIdx, MRI](raw_ostream &OS) {
113 if (!Reg)
114 OS << "$noreg";
115 else if (Reg.isStack())
116 OS << "SS#" << Reg.stackSlotIndex();
117 else if (Reg.isVirtual()) {
118 StringRef Name = MRI ? MRI->getVRegName(Reg) : "";
119 if (Name != "") {
120 OS << '%' << Name;
121 } else {
122 OS << '%' << Reg.virtRegIndex();
123 }
124 } else if (!TRI)
125 OS << '$' << "physreg" << Reg.id();
126 else if (Reg < TRI->getNumRegs()) {
127 OS << '$';
128 printLowerCase(TRI->getName(Reg), OS);
129 } else
130 llvm_unreachable("Register kind is unsupported.");
131
132 if (SubIdx) {
133 if (TRI)
134 OS << ':' << TRI->getSubRegIndexName(SubIdx);
135 else
136 OS << ":sub(" << SubIdx << ')';
137 }
138 });
139}
140
142 return Printable([Unit, TRI](raw_ostream &OS) {
143 // Generic printout when TRI is missing.
144 if (!TRI) {
145 OS << "Unit~" << static_cast<unsigned>(Unit);
146 return;
147 }
148
149 // Check for invalid register units.
150 if (static_cast<unsigned>(Unit) >= TRI->getNumRegUnits()) {
151 OS << "BadUnit~" << static_cast<unsigned>(Unit);
152 return;
153 }
154
155 // Normal units have at least one root.
156 MCRegUnitRootIterator Roots(Unit, TRI);
157 assert(Roots.isValid() && "Unit has no roots.");
158 OS << TRI->getName(*Roots);
159 for (++Roots; Roots.isValid(); ++Roots)
160 OS << '~' << TRI->getName(*Roots);
161 });
162}
163
165 const TargetRegisterInfo *TRI) {
166 return Printable([VRegOrUnit, TRI](raw_ostream &OS) {
167 if (VRegOrUnit.isVirtualReg()) {
168 OS << '%' << VRegOrUnit.asVirtualReg().virtRegIndex();
169 } else {
170 OS << printRegUnit(VRegOrUnit.asMCRegUnit(), TRI);
171 }
172 });
173}
174
176 const MachineRegisterInfo &RegInfo,
177 const TargetRegisterInfo *TRI) {
178 return Printable([Reg, &RegInfo, TRI](raw_ostream &OS) {
179 if (RegInfo.getRegClassOrNull(Reg))
180 OS << StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
181 else if (RegInfo.getRegBankOrNull(Reg))
182 OS << StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
183 else {
184 OS << "_";
185 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
186 "Generic registers must have a valid type");
187 }
188 });
189}
190
191/// getAllocatableClass - Return the maximal subclass of the given register
192/// class that is alloctable, or NULL.
195 if (!RC || RC->isAllocatable())
196 return RC;
197
198 for (BitMaskClassIterator It(RC->getSubClassMask(), *this); It.isValid();
199 ++It) {
200 const TargetRegisterClass *SubRC = getRegClass(It.getID());
201 if (SubRC->isAllocatable())
202 return SubRC;
203 }
204 return nullptr;
205}
206
207template <typename TypeT>
208static const TargetRegisterClass *
210 TypeT Ty) {
211 static_assert(std::is_same_v<TypeT, MVT> || std::is_same_v<TypeT, LLT>);
212 assert(Reg.isPhysical() && "reg must be a physical register");
213
214 bool IsDefault = [&]() {
215 if constexpr (std::is_same_v<TypeT, MVT>)
216 return Ty == MVT::Other;
217 else
218 return !Ty.isValid();
219 }();
220
221 if (IsDefault) {
222 if (const TargetRegisterClass *RC = TRI->getDefaultMinimalPhysRegClass(Reg))
223 return RC;
224 }
225
226 // Pick the most sub register class of the right type that contains
227 // this physreg.
228 const TargetRegisterClass *BestRC = nullptr;
229 for (const TargetRegisterClass *RC : TRI->regclasses()) {
230 if ((IsDefault || TRI->isTypeLegalForClass(*RC, Ty)) && RC->contains(Reg) &&
231 (!BestRC || BestRC->hasSubClass(RC)))
232 BestRC = RC;
233 }
234
235 if constexpr (std::is_same_v<TypeT, MVT>)
236 assert(BestRC && "Couldn't find the register class");
237 return BestRC;
238}
239
240template <typename TypeT>
241static const TargetRegisterClass *
243 MCRegister Reg2, TypeT Ty) {
244 static_assert(std::is_same_v<TypeT, MVT> || std::is_same_v<TypeT, LLT>);
245 assert(Reg1.isPhysical() && Reg2.isPhysical() &&
246 "Reg1/Reg2 must be a physical register");
247
248 bool IsDefault = [&]() {
249 if constexpr (std::is_same_v<TypeT, MVT>)
250 return Ty == MVT::Other;
251 else
252 return !Ty.isValid();
253 }();
254
255 // Pick the most sub register class of the right type that contains
256 // this physreg.
257 const TargetRegisterClass *BestRC = nullptr;
258 for (const TargetRegisterClass *RC : TRI->regclasses()) {
259 if ((IsDefault || TRI->isTypeLegalForClass(*RC, Ty)) &&
260 RC->contains(Reg1, Reg2) && (!BestRC || BestRC->hasSubClass(RC)))
261 BestRC = RC;
262 }
263
264 if constexpr (std::is_same_v<TypeT, MVT>)
265 assert(BestRC && "Couldn't find the register class");
266 return BestRC;
267}
268
271 return ::getMinimalPhysRegClass(this, Reg, VT);
272}
273
275 MCRegister Reg1, MCRegister Reg2, MVT VT) const {
276 return ::getCommonMinimalPhysRegClass(this, Reg1, Reg2, VT);
277}
278
281 return ::getMinimalPhysRegClass(this, Reg, Ty);
282}
283
285 MCRegister Reg1, MCRegister Reg2, LLT Ty) const {
286 return ::getCommonMinimalPhysRegClass(this, Reg1, Reg2, Ty);
287}
288
289/// getAllocatableSetForRC - Toggle the bits that represent allocatable
290/// registers for the specific register class.
292 const TargetRegisterClass *RC, BitVector &R){
293 assert(RC->isAllocatable() && "invalid for nonallocatable sets");
295 for (MCPhysReg PR : Order)
296 R.set(PR);
297}
298
300 const TargetRegisterClass *RC) const {
301 BitVector Allocatable(getNumRegs());
302 if (RC) {
303 // A register class with no allocatable subclass returns an empty set.
304 const TargetRegisterClass *SubClass = getAllocatableClass(RC);
305 if (SubClass)
306 getAllocatableSetForRC(MF, SubClass, Allocatable);
307 } else {
308 for (const TargetRegisterClass *C : regclasses())
309 if (C->isAllocatable())
310 getAllocatableSetForRC(MF, C, Allocatable);
311 }
312
313 // Mask out the reserved registers
314 const MachineRegisterInfo &MRI = MF.getRegInfo();
315 const BitVector &Reserved = MRI.getReservedRegs();
316 Allocatable.reset(Reserved);
317
318 return Allocatable;
319}
320
321static inline
323 const uint32_t *B,
324 const TargetRegisterInfo *TRI) {
325 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
326 if (unsigned Common = *A++ & *B++)
327 return TRI->getRegClass(I + llvm::countr_zero(Common));
328 return nullptr;
329}
330
333 const TargetRegisterClass *B) const {
334 // First take care of the trivial cases.
335 if (A == B)
336 return A;
337 if (!A || !B)
338 return nullptr;
339
340 // Register classes are ordered topologically, so the largest common
341 // sub-class it the common sub-class with the smallest ID.
342 return firstCommonClass(A->getSubClassMask(), B->getSubClassMask(), this);
343}
344
347 const TargetRegisterClass *B,
348 unsigned Idx) const {
349 assert(A && B && "Missing register class");
350 assert(Idx && "Bad sub-register index");
351
352 // Find Idx in the list of super-register indices.
353 for (SuperRegClassIterator RCI(B, this); RCI.isValid(); ++RCI)
354 if (RCI.getSubReg() == Idx)
355 // The bit mask contains all register classes that are projected into B
356 // by Idx. Find a class that is also a sub-class of A.
357 return firstCommonClass(RCI.getMask(), A->getSubClassMask(), this);
358 return nullptr;
359}
360
362getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
363 const TargetRegisterClass *RCB, unsigned SubB,
364 unsigned &PreA, unsigned &PreB) const {
365 assert(RCA && SubA && RCB && SubB && "Invalid arguments");
366
367 // Search all pairs of sub-register indices that project into RCA and RCB
368 // respectively. This is quadratic, but usually the sets are very small. On
369 // most targets like X86, there will only be a single sub-register index
370 // (e.g., sub_16bit projecting into GR16).
371 //
372 // The worst case is a register class like DPR on ARM.
373 // We have indices dsub_0..dsub_7 projecting into that class.
374 //
375 // It is very common that one register class is a sub-register of the other.
376 // Arrange for RCA to be the larger register so the answer will be found in
377 // the first iteration. This makes the search linear for the most common
378 // case.
379 const TargetRegisterClass *BestRC = nullptr;
380 unsigned *BestPreA = &PreA;
381 unsigned *BestPreB = &PreB;
382 if (getRegSizeInBits(*RCA) < getRegSizeInBits(*RCB)) {
383 std::swap(RCA, RCB);
384 std::swap(SubA, SubB);
385 std::swap(BestPreA, BestPreB);
386 }
387
388 // Also terminate the search one we have found a register class as small as
389 // RCA.
390 unsigned MinSize = getRegSizeInBits(*RCA);
391
392 for (SuperRegClassIterator IA(RCA, this, true); IA.isValid(); ++IA) {
393 unsigned FinalA = composeSubRegIndices(IA.getSubReg(), SubA);
394 for (SuperRegClassIterator IB(RCB, this, true); IB.isValid(); ++IB) {
395 // Check if a common super-register class exists for this index pair.
396 const TargetRegisterClass *RC =
397 firstCommonClass(IA.getMask(), IB.getMask(), this);
398 if (!RC || getRegSizeInBits(*RC) < MinSize)
399 continue;
400
401 // The indexes must compose identically: PreA+SubA == PreB+SubB.
402 unsigned FinalB = composeSubRegIndices(IB.getSubReg(), SubB);
403 if (FinalA != FinalB)
404 continue;
405
406 // Is RC a better candidate than BestRC?
407 if (BestRC && getRegSizeInBits(*RC) >= getRegSizeInBits(*BestRC))
408 continue;
409
410 // Yes, RC is the smallest super-register seen so far.
411 BestRC = RC;
412 *BestPreA = IA.getSubReg();
413 *BestPreB = IB.getSubReg();
414
415 // Bail early if we reached MinSize. We won't find a better candidate.
416 if (getRegSizeInBits(*BestRC) == MinSize)
417 return BestRC;
418 }
419 }
420 return BestRC;
421}
422
424 const TargetRegisterClass *DefRC, unsigned DefSubReg,
425 const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const {
426 // Same register class.
427 //
428 // When processing uncoalescable copies / bitcasts, it is possible we reach
429 // here with the same register class, but mismatched subregister indices.
430 if (DefRC == SrcRC && DefSubReg == SrcSubReg)
431 return DefRC;
432
433 // Both operands are sub registers. Check if they share a register class.
434 unsigned SrcIdx, DefIdx;
435 if (SrcSubReg && DefSubReg) {
436 return getCommonSuperRegClass(SrcRC, SrcSubReg, DefRC, DefSubReg, SrcIdx,
437 DefIdx);
438 }
439
440 // At most one of the register is a sub register, make it Src to avoid
441 // duplicating the test.
442 if (!SrcSubReg) {
443 std::swap(DefSubReg, SrcSubReg);
444 std::swap(DefRC, SrcRC);
445 }
446
447 // One of the register is a sub register, check if we can get a superclass.
448 if (SrcSubReg)
449 return getMatchingSuperRegClass(SrcRC, DefRC, SrcSubReg);
450
451 // Plain copy.
452 return getCommonSubClass(DefRC, SrcRC);
453}
454
456 const TargetRegisterClass *RC) const {
457 return 1.0;
458}
459
460// Compute target-independent register allocator hints to help eliminate copies.
462 Register VirtReg, ArrayRef<MCPhysReg> Order,
464 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
465 const MachineRegisterInfo &MRI = MF.getRegInfo();
466 const std::pair<unsigned, SmallVector<Register, 4>> *Hints_MRI =
467 MRI.getRegAllocationHints(VirtReg);
468
469 if (!Hints_MRI)
470 return false;
471
472 SmallSet<Register, 32> HintedRegs;
473 // First hint may be a target hint.
474 bool Skip = (Hints_MRI->first != 0);
475 for (auto Reg : Hints_MRI->second) {
476 if (Skip) {
477 Skip = false;
478 continue;
479 }
480
481 // Target-independent hints are either a physical or a virtual register.
482 Register Phys = Reg;
483 if (VRM && Phys.isVirtual())
484 Phys = VRM->getPhys(Phys);
485
486 // Don't add the same reg twice (Hints_MRI may contain multiple virtual
487 // registers allocated to the same physreg).
488 if (!HintedRegs.insert(Phys).second)
489 continue;
490 // Check that Phys is a valid hint in VirtReg's register class.
491 if (!Phys.isPhysical())
492 continue;
493 if (MRI.isReserved(Phys))
494 continue;
495 // Check that Phys is in the allocation order. We shouldn't heed hints
496 // from VirtReg's register class if they aren't in the allocation order. The
497 // target probably has a reason for removing the register.
498 if (!is_contained(Order, Phys))
499 continue;
500
501 // All clear, tell the register allocator to prefer this register.
502 Hints.push_back(Phys.id());
503 }
504 return false;
505}
506
508 MCRegister PhysReg, const MachineFunction &MF) const {
509 if (!PhysReg)
510 return false;
511 const uint32_t *callerPreservedRegs =
513 if (callerPreservedRegs) {
514 assert(PhysReg.isPhysical() && "Expected physical register");
515 return (callerPreservedRegs[PhysReg.id() / 32] >> PhysReg.id() % 32) & 1;
516 }
517 return false;
518}
519
523
527
529 const uint32_t *mask1) const {
530 unsigned N = (getNumRegs()+31) / 32;
531 for (unsigned I = 0; I < N; ++I)
532 if ((mask0[I] & mask1[I]) != mask0[I])
533 return false;
534 return true;
535}
536
539 const MachineRegisterInfo &MRI) const {
540 const TargetRegisterClass *RC{};
541 if (Reg.isPhysical()) {
542 // The size is not directly available for physical registers.
543 // Instead, we need to access a register class that contains Reg and
544 // get the size of that register class.
545 RC = getMinimalPhysRegClass(Reg);
546 assert(RC && "Unable to deduce the register class");
547 return getRegSizeInBits(*RC);
548 }
549 LLT Ty = MRI.getType(Reg);
550 if (Ty.isValid())
551 return Ty.getSizeInBits();
552
553 // Since Reg is not a generic register, it may have a register class.
554 RC = MRI.getRegClass(Reg);
555 assert(RC && "Unable to deduce the register class");
556 return getRegSizeInBits(*RC);
557}
558
560 const TargetRegisterClass *RC, LaneBitmask LaneMask,
561 SmallVectorImpl<unsigned> &NeededIndexes) const {
562 SmallVector<unsigned, 8> PossibleIndexes;
563 unsigned BestIdx = 0;
564 unsigned BestCover = 0;
565
566 for (unsigned Idx = 1, E = getNumSubRegIndices(); Idx < E; ++Idx) {
567 // Is this index even compatible with the given class?
568 if (!isSubRegValidForRegClass(RC, Idx))
569 continue;
570 LaneBitmask SubRegMask = getSubRegIndexLaneMask(Idx);
571 // Early exit if we found a perfect match.
572 if (SubRegMask == LaneMask) {
573 BestIdx = Idx;
574 break;
575 }
576
577 // The index must not cover any lanes outside \p LaneMask.
578 if ((SubRegMask & ~LaneMask).any())
579 continue;
580
581 unsigned PopCount = SubRegMask.getNumLanes();
582 PossibleIndexes.push_back(Idx);
583 if (PopCount > BestCover) {
584 BestCover = PopCount;
585 BestIdx = Idx;
586 }
587 }
588
589 // Abort if we cannot possibly implement the COPY with the given indexes.
590 if (BestIdx == 0)
591 return false;
592
593 NeededIndexes.push_back(BestIdx);
594
595 // Greedy heuristic: Keep iterating keeping the best covering subreg index
596 // each time.
597 LaneBitmask LanesLeft = LaneMask & ~getSubRegIndexLaneMask(BestIdx);
598 while (LanesLeft.any()) {
599 unsigned BestIdx = 0;
600 int BestCover = std::numeric_limits<int>::min();
601 for (unsigned Idx : PossibleIndexes) {
602 LaneBitmask SubRegMask = getSubRegIndexLaneMask(Idx);
603 // Early exit if we found a perfect match.
604 if (SubRegMask == LanesLeft) {
605 BestIdx = Idx;
606 break;
607 }
608
609 // Do not cover already-covered lanes to avoid creating cycles
610 // in copy bundles (= bundle contains copies that write to the
611 // registers).
612 if ((SubRegMask & ~LanesLeft).any())
613 continue;
614
615 // Try to cover as many of the remaining lanes as possible.
616 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
617 if (Cover > BestCover) {
618 BestCover = Cover;
619 BestIdx = Idx;
620 }
621 }
622
623 if (BestIdx == 0)
624 return false; // Impossible to handle
625
626 NeededIndexes.push_back(BestIdx);
627
628 LanesLeft &= ~getSubRegIndexLaneMask(BestIdx);
629 }
630
631 return BestIdx;
632}
633
635 Register RegB,
636 unsigned SubB) const {
637 if (RegA == RegB && SubA == SubB)
638 return true;
639 if (RegA.isVirtual() && RegB.isVirtual()) {
640 if (RegA != RegB)
641 return false;
644 return (LA & LB).any();
645 }
646 if (RegA.isPhysical() && RegB.isPhysical()) {
647 MCRegister MCRegA = SubA ? getSubReg(RegA, SubA) : RegA.asMCReg();
648 MCRegister MCRegB = SubB ? getSubReg(RegB, SubB) : RegB.asMCReg();
649 assert(MCRegB.isValid() && MCRegA.isValid() && "invalid subregister");
650 return MCRegisterInfo::regsOverlap(MCRegA, MCRegB);
651 }
652 llvm_unreachable("mixed virtual and physical registers");
653}
654
655unsigned TargetRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
656 assert(Idx && Idx < getNumSubRegIndices() &&
657 "This is not a subregister index");
658 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Size;
659}
660
661unsigned TargetRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
662 assert(Idx && Idx < getNumSubRegIndices() &&
663 "This is not a subregister index");
664 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Offset;
665}
666
669 const MachineRegisterInfo *MRI) const {
670 while (true) {
671 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
672 if (!MI->isCopyLike())
673 return SrcReg;
674
675 Register CopySrcReg;
676 if (MI->isCopy())
677 CopySrcReg = MI->getOperand(1).getReg();
678 else {
679 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
680 CopySrcReg = MI->getOperand(1).getReg();
681 }
682
683 if (!CopySrcReg.isVirtual())
684 return CopySrcReg;
685
686 SrcReg = CopySrcReg;
687 }
688}
689
691 Register SrcReg, const MachineRegisterInfo *MRI) const {
692 while (true) {
693 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
694 // Found the real definition, return it if it has a single use.
695 if (!MI->isCopyLike())
696 return MRI->hasOneNonDBGUse(SrcReg) ? SrcReg : Register();
697
698 Register CopySrcReg;
699 if (MI->isCopy())
700 CopySrcReg = MI->getOperand(1).getReg();
701 else {
702 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
703 CopySrcReg = MI->getOperand(1).getReg();
704 }
705
706 // Continue only if the next definition in the chain is for a virtual
707 // register that has a single use.
708 if (!CopySrcReg.isVirtual() || !MRI->hasOneNonDBGUse(CopySrcReg))
709 return Register();
710
711 SrcReg = CopySrcReg;
712 }
713}
714
717 assert(!Offset.getScalable() && "Scalable offsets are not handled");
719}
720
723 unsigned PrependFlags,
724 const StackOffset &Offset) const {
725 assert((PrependFlags &
728 "Unsupported prepend flag");
729 SmallVector<uint64_t, 16> OffsetExpr;
730 if (PrependFlags & DIExpression::DerefBefore)
731 OffsetExpr.push_back(dwarf::DW_OP_deref);
732 getOffsetOpcodes(Offset, OffsetExpr);
733 if (PrependFlags & DIExpression::DerefAfter)
734 OffsetExpr.push_back(dwarf::DW_OP_deref);
735 return DIExpression::prependOpcodes(Expr, OffsetExpr,
736 PrependFlags & DIExpression::StackValue,
737 PrependFlags & DIExpression::EntryValue);
738}
739
740#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
742void TargetRegisterInfo::dumpReg(Register Reg, unsigned SubRegIndex,
743 const TargetRegisterInfo *TRI) {
744 dbgs() << printReg(Reg, TRI, SubRegIndex) << "\n";
745}
746#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Live Register Matrix
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallSet class.
This file contains some functions that are useful when dealing with strings.
static const TargetRegisterClass * getMinimalPhysRegClass(const TargetRegisterInfo *TRI, MCRegister Reg, TypeT Ty)
static void getAllocatableSetForRC(const MachineFunction &MF, const TargetRegisterClass *RC, BitVector &R)
getAllocatableSetForRC - Toggle the bits that represent allocatable registers for the specific regist...
static const TargetRegisterClass * firstCommonClass(const uint32_t *A, const uint32_t *B, const TargetRegisterInfo *TRI)
static const TargetRegisterClass * getCommonMinimalPhysRegClass(const TargetRegisterInfo *TRI, MCRegister Reg1, MCRegister Reg2, TypeT Ty)
static cl::opt< unsigned > HugeSizeForSplit("huge-size-for-split", cl::Hidden, cl::desc("A threshold of live range size which may cause " "high compile time cost in global splitting."), cl::init(5000))
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class encapuslates the logic to iterate over bitmask returned by the various RegClass related AP...
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
BitVector & reset()
Reset all bits in the bitvector.
Definition BitVector.h:409
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:366
DWARF expression.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:272
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LiveInterval - This class represents the liveness of a register, or stack slot.
Register reg() const
size_t size() const
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isValid() const
Check if the iterator is at the end of the list.
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.
iterator_range< MCSuperRegIterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
iterator_range< MCSuperRegIterator > superregs_inclusive(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, including Reg.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
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
constexpr bool isValid() const
Definition MCRegister.h:84
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:72
constexpr unsigned id() const
Definition MCRegister.h:82
Machine Value Type.
bool shouldRealignStack() const
Return true if stack realignment is forced by function attributes or if the stack alignment.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
const std::pair< unsigned, SmallVector< Register, 4 > > * getRegAllocationHints(Register VReg) const
getRegAllocationHints - Return a reference to the vector of all register allocation hints for VReg.
StringRef getVRegName(Register Reg) const
LLVM_ABI MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
Simple wrapper around std::function<void(raw_ostream&)>.
Definition Printable.h:38
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
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
Definition Register.h:87
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr unsigned id() const
Definition Register.h:100
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI std::string lower() const
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
TargetInstrInfo - Interface to description of machine instruction set.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF, bool Rev=false) const
Returns the preferred order for allocating registers from this register class in MF.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
~TargetRegisterInfo() override
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
iterator_range< regclass_iterator > regclasses() const
virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF, const LiveInterval &VirtReg) const
Region split has a high compile time cost especially for large live range.
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
bool getCoveringSubRegIndexes(const TargetRegisterClass *RC, LaneBitmask LaneMask, SmallVectorImpl< unsigned > &Indexes) const
Try to find one or more subregister indexes to cover LaneMask.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
bool checkSubRegInterference(Register RegA, unsigned SubA, Register RegB, unsigned SubB) const
Returns true if the two subregisters are equal or overlap.
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
Find the largest common subclass of A and B.
const TargetRegisterClass * getMinimalPhysRegClassLLT(MCRegister Reg, LLT Ty=LLT()) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, ArrayRef< const TargetRegisterClass * > RegisterClasses, 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)
virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const
Get the scale factor of spill weight for this register class.
bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const
Return true if all bits that are set in mask mask0 are also set in mask1.
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
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 Register lookThruSingleUseCopyChain(Register SrcReg, const MachineRegisterInfo *MRI) const
Find the original SrcReg unless it is the target of a copy-like operation, in which case we chain bac...
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx.
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.
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
Return the maximal subclass of the given register class that is allocatable or NULL.
virtual Register lookThruCopyLike(Register SrcReg, const MachineRegisterInfo *MRI) const
Returns the original SrcReg unless it is the target of a copy-like operation, in which case we chain ...
const TargetRegisterClass * getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA, const TargetRegisterClass *RCB, unsigned SubB, unsigned &PreA, unsigned &PreB) const
Find a common super-register class if it exists.
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index.
static void dumpReg(Register Reg, unsigned SubRegIndex=0, const TargetRegisterInfo *TRI=nullptr)
Debugging helper: dump register in human readable form to dbgs() stream.
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...
DIExpression * prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags, const StackOffset &Offset) const
Prepends a DWARF expression for Offset to DIExpression Expr.
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...
const TargetRegisterClass * getCommonMinimalPhysRegClass(MCRegister Reg1, MCRegister Reg2, MVT VT=MVT::Other) const
Returns the common Register Class of two physical registers of the given type, picking the most sub r...
virtual bool isCalleeSavedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
This is a wrapper around getCallPreservedMask().
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
bool isSubRegValidForRegClass(const TargetRegisterClass *RC, unsigned Idx) const
Returns true if sub-register Idx can be used with register class RC.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the register class A so that each register in it has a sub-register of sub-regis...
virtual void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const
Gets the DWARF expression opcodes for Offset.
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 bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
const TargetRegisterClass * getCommonMinimalPhysRegClassLLT(MCRegister Reg1, MCRegister Reg2, LLT Ty=LLT()) const
Returns the common Register Class of two physical registers of the given type, picking the most sub r...
virtual const TargetInstrInfo * getInstrInfo() const
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
Wrapper class representing a virtual register or register unit.
Definition Register.h:181
constexpr bool isVirtualReg() const
Definition Register.h:197
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:201
constexpr Register asVirtualReg() const
Definition Register.h:206
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#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
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
LLVM_ABI void printLowerCase(StringRef String, raw_ostream &Out)
printLowerCase - Print each character as lowercase if it is uppercase.
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 raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
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:1946
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:876
#define N
constexpr bool any() const
Definition LaneBitmask.h:53
unsigned getNumLanes() const
Definition LaneBitmask.h:76
Extra information, not in MCRegisterDesc, about registers.
SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg index, -1 in any being invalid...