LLVM 24.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
53 const TargetRegisterInfoDesc *ID, const char *SubRegIndexStrings,
54 ArrayRef<uint32_t> SubRegIndexNameOffsets,
55 const SubRegCoveredBits *SubRegIdxRanges,
56 const LaneBitmask *SubRegIndexLaneMasks, LaneBitmask CoveringLanes,
57 const RegClassInfo *const RCInfos,
58 const MVT::SimpleValueType *const RCVTLists, unsigned Mode)
59 : InfoDesc(ID), SubRegIndexStrings(SubRegIndexStrings),
60 SubRegIndexNameOffsets(SubRegIndexNameOffsets),
61 SubRegIdxRanges(SubRegIdxRanges),
62 SubRegIndexLaneMasks(SubRegIndexLaneMasks), CoveringLanes(CoveringLanes),
63 RCInfos(RCInfos), RCVTLists(RCVTLists), HwMode(Mode) {}
64
66
68 const MachineFunction &MF, const LiveInterval &VirtReg) const {
70 const MachineRegisterInfo &MRI = MF.getRegInfo();
71 MachineInstr *MI = MRI.getUniqueVRegDef(VirtReg.reg());
72 if (MI && TII->isTriviallyReMaterializable(*MI) &&
73 VirtReg.size() > HugeSizeForSplit)
74 return false;
75 return true;
76}
77
79 MCRegister Reg) const {
80 for (MCPhysReg SR : superregs_inclusive(Reg))
81 RegisterSet.set(SR);
82}
83
85 ArrayRef<MCPhysReg> Exceptions) const {
86 // Check that all super registers of reserved regs are reserved as well.
87 BitVector Checked(getNumRegs());
88 for (unsigned Reg : RegisterSet.set_bits()) {
89 if (Checked[Reg])
90 continue;
91 for (MCPhysReg SR : superregs(Reg)) {
92 if (!RegisterSet[SR] && !is_contained(Exceptions, Reg)) {
93 dbgs() << "Error: Super register " << printReg(SR, this)
94 << " of reserved register " << printReg(Reg, this)
95 << " is not reserved.\n";
96 return false;
97 }
98
99 // We transitively check superregs. So we can remember this for later
100 // to avoid compiletime explosion in deep register hierarchies.
101 Checked.set(SR);
102 }
103 }
104 return true;
105}
106
108 unsigned SubIdx, const MachineRegisterInfo *MRI) {
109 return Printable([Reg, TRI, SubIdx, MRI](raw_ostream &OS) {
110 if (!Reg)
111 OS << "$noreg";
112 else if (Reg.isStack())
113 OS << "SS#" << Reg.stackSlotIndex();
114 else if (Reg.isVirtual()) {
115 StringRef Name = MRI ? MRI->getVRegName(Reg) : "";
116 if (Name != "") {
117 OS << '%' << Name;
118 } else {
119 OS << '%' << Reg.virtRegIndex();
120 }
121 } else if (!TRI)
122 OS << '$' << "physreg" << Reg.id();
123 else if (Reg < TRI->getNumRegs()) {
124 OS << '$';
125 printLowerCase(TRI->getName(Reg), OS);
126 } else
127 llvm_unreachable("Register kind is unsupported.");
128
129 if (SubIdx) {
130 if (TRI)
131 OS << ':' << TRI->getSubRegIndexName(SubIdx);
132 else
133 OS << ":sub(" << SubIdx << ')';
134 }
135 });
136}
137
139 return Printable([Unit, TRI](raw_ostream &OS) {
140 // Generic printout when TRI is missing.
141 if (!TRI) {
142 OS << "Unit~" << static_cast<unsigned>(Unit);
143 return;
144 }
145
146 // Check for invalid register units.
147 if (static_cast<unsigned>(Unit) >= TRI->getNumRegUnits()) {
148 OS << "BadUnit~" << static_cast<unsigned>(Unit);
149 return;
150 }
151
152 // Normal units have at least one root.
153 MCRegUnitRootIterator Roots(Unit, TRI);
154 assert(Roots.isValid() && "Unit has no roots.");
155 OS << TRI->getName(*Roots);
156 for (++Roots; Roots.isValid(); ++Roots)
157 OS << '~' << TRI->getName(*Roots);
158 });
159}
160
162 const TargetRegisterInfo *TRI) {
163 return Printable([VRegOrUnit, TRI](raw_ostream &OS) {
164 if (VRegOrUnit.isVirtualReg()) {
165 OS << '%' << VRegOrUnit.asVirtualReg().virtRegIndex();
166 } else {
167 OS << printRegUnit(VRegOrUnit.asMCRegUnit(), TRI);
168 }
169 });
170}
171
173 const MachineRegisterInfo &RegInfo,
174 const TargetRegisterInfo *TRI) {
175 return Printable([Reg, &RegInfo, TRI](raw_ostream &OS) {
176 if (RegInfo.getRegClassOrNull(Reg))
177 OS << StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
178 else if (RegInfo.getRegBankOrNull(Reg))
179 OS << StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
180 else {
181 OS << "_";
182 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
183 "Generic registers must have a valid type");
184 }
185 });
186}
187
188/// getAllocatableClass - Return the maximal subclass of the given register
189/// class that is alloctable, or NULL.
192 if (!RC || RC->isAllocatable())
193 return RC;
194
195 for (BitMaskClassIterator It(RC->getSubClassMask(), *this); It.isValid();
196 ++It) {
197 const TargetRegisterClass *SubRC = getRegClass(It.getID());
198 if (SubRC->isAllocatable())
199 return SubRC;
200 }
201 return nullptr;
202}
203
204static const TargetRegisterClass *
206 MCRegister Reg2) {
207 assert(Reg1.isPhysical() && Reg2.isPhysical() &&
208 "Reg1/Reg2 must be a physical register");
209
210 // Pick the most specific register class that contains both physregs.
211 const TargetRegisterClass *BestRC = nullptr;
212 for (const TargetRegisterClass &RC : TRI->regclasses()) {
213 if (RC.contains(Reg1, Reg2) && (!BestRC || BestRC->hasSubClass(&RC)))
214 BestRC = &RC;
215 }
216
217 assert(BestRC && "Couldn't find the register class");
218 return BestRC;
219}
220
223 MCRegister Reg2) const {
224 return ::getCommonMinimalPhysRegClass(this, Reg1, Reg2);
225}
226
227/// getAllocatableSetForRC - Toggle the bits that represent allocatable
228/// registers for the specific register class.
230 const TargetRegisterClass *RC, BitVector &R){
231 assert(RC->isAllocatable() && "invalid for nonallocatable sets");
233 ArrayRef<MCPhysReg> Order = TRI.getRawAllocationOrder(*RC, MF);
234 for (MCPhysReg PR : Order)
235 R.set(PR);
236}
237
239 const TargetRegisterClass *RC) const {
240 BitVector Allocatable(getNumRegs());
241 if (RC) {
242 // A register class with no allocatable subclass returns an empty set.
243 const TargetRegisterClass *SubClass = getAllocatableClass(RC);
244 if (SubClass)
245 getAllocatableSetForRC(MF, SubClass, Allocatable);
246 } else {
247 for (const TargetRegisterClass &C : regclasses())
248 if (C.isAllocatable())
249 getAllocatableSetForRC(MF, &C, Allocatable);
250 }
251
252 // Mask out the reserved registers
253 const MachineRegisterInfo &MRI = MF.getRegInfo();
254 const BitVector &Reserved = MRI.getReservedRegs();
255 Allocatable.reset(Reserved);
256
257 return Allocatable;
258}
259
260static inline
262 const uint32_t *B,
263 const TargetRegisterInfo *TRI) {
264 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
265 if (unsigned Common = *A++ & *B++)
266 return TRI->getRegClass(I + llvm::countr_zero(Common));
267 return nullptr;
268}
269
272 const TargetRegisterClass *B) const {
273 // First take care of the trivial cases.
274 if (A == B)
275 return A;
276 if (!A || !B)
277 return nullptr;
278
279 // Register classes are ordered topologically, so the largest common
280 // sub-class it the common sub-class with the smallest ID.
281 return firstCommonClass(A->getSubClassMask(), B->getSubClassMask(), this);
282}
283
286 const TargetRegisterClass *B,
287 unsigned Idx) const {
288 assert(A && B && "Missing register class");
289 assert(Idx && "Bad sub-register index");
290
291 // Find Idx in the list of super-register indices.
292 for (SuperRegClassIterator RCI(B, this); RCI.isValid(); ++RCI)
293 if (RCI.getSubReg() == Idx)
294 // The bit mask contains all register classes that are projected into B
295 // by Idx. Find a class that is also a sub-class of A.
296 return firstCommonClass(RCI.getMask(), A->getSubClassMask(), this);
297 return nullptr;
298}
299
301getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
302 const TargetRegisterClass *RCB, unsigned SubB,
303 unsigned &PreA, unsigned &PreB) const {
304 assert(RCA && SubA && RCB && SubB && "Invalid arguments");
305
306 // Search all pairs of sub-register indices that project into RCA and RCB
307 // respectively. This is quadratic, but usually the sets are very small. On
308 // most targets like X86, there will only be a single sub-register index
309 // (e.g., sub_16bit projecting into GR16).
310 //
311 // The worst case is a register class like DPR on ARM.
312 // We have indices dsub_0..dsub_7 projecting into that class.
313 //
314 // It is very common that one register class is a sub-register of the other.
315 // Arrange for RCA to be the larger register so the answer will be found in
316 // the first iteration. This makes the search linear for the most common
317 // case.
318 const TargetRegisterClass *BestRC = nullptr;
319 unsigned *BestPreA = &PreA;
320 unsigned *BestPreB = &PreB;
321 if (getRegSizeInBits(*RCA) < getRegSizeInBits(*RCB)) {
322 std::swap(RCA, RCB);
323 std::swap(SubA, SubB);
324 std::swap(BestPreA, BestPreB);
325 }
326
327 // Also terminate the search one we have found a register class as small as
328 // RCA.
329 unsigned MinSize = getRegSizeInBits(*RCA);
330
331 for (SuperRegClassIterator IA(RCA, this, true); IA.isValid(); ++IA) {
332 unsigned FinalA = composeSubRegIndices(IA.getSubReg(), SubA);
333 for (SuperRegClassIterator IB(RCB, this, true); IB.isValid(); ++IB) {
334 // Check if a common super-register class exists for this index pair.
335 const TargetRegisterClass *RC =
336 firstCommonClass(IA.getMask(), IB.getMask(), this);
337 if (!RC || getRegSizeInBits(*RC) < MinSize)
338 continue;
339
340 // The indexes must compose identically: PreA+SubA == PreB+SubB.
341 unsigned FinalB = composeSubRegIndices(IB.getSubReg(), SubB);
342 if (FinalA != FinalB)
343 continue;
344
345 // Is RC a better candidate than BestRC?
346 if (BestRC && getRegSizeInBits(*RC) >= getRegSizeInBits(*BestRC))
347 continue;
348
349 // Yes, RC is the smallest super-register seen so far.
350 BestRC = RC;
351 *BestPreA = IA.getSubReg();
352 *BestPreB = IB.getSubReg();
353
354 // Bail early if we reached MinSize. We won't find a better candidate.
355 if (getRegSizeInBits(*BestRC) == MinSize)
356 return BestRC;
357 }
358 }
359 return BestRC;
360}
361
363 const TargetRegisterClass *DefRC, unsigned DefSubReg,
364 const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const {
365 // Same register class.
366 //
367 // When processing uncoalescable copies / bitcasts, it is possible we reach
368 // here with the same register class, but mismatched subregister indices.
369 if (DefRC == SrcRC && DefSubReg == SrcSubReg)
370 return DefRC;
371
372 // Both operands are sub registers. Check if they share a register class.
373 unsigned SrcIdx, DefIdx;
374 if (SrcSubReg && DefSubReg) {
375 return getCommonSuperRegClass(SrcRC, SrcSubReg, DefRC, DefSubReg, SrcIdx,
376 DefIdx);
377 }
378
379 // At most one of the register is a sub register, make it Src to avoid
380 // duplicating the test.
381 if (!SrcSubReg) {
382 std::swap(DefSubReg, SrcSubReg);
383 std::swap(DefRC, SrcRC);
384 }
385
386 // One of the register is a sub register, check if we can get a superclass.
387 if (SrcSubReg)
388 return getMatchingSuperRegClass(SrcRC, DefRC, SrcSubReg);
389
390 // Plain copy.
391 return getCommonSubClass(DefRC, SrcRC);
392}
393
395 const TargetRegisterClass *RC) const {
396 return 1.0;
397}
398
399// Compute target-independent register allocator hints to help eliminate copies.
401 Register VirtReg, ArrayRef<MCPhysReg> Order,
403 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
404 const MachineRegisterInfo &MRI = MF.getRegInfo();
405 const std::pair<unsigned, SmallVector<Register, 4>> *Hints_MRI =
406 MRI.getRegAllocationHints(VirtReg);
407
408 if (!Hints_MRI)
409 return false;
410
411 SmallSet<Register, 32> HintedRegs;
412 // First hint may be a target hint.
413 bool Skip = (Hints_MRI->first != 0);
414 for (auto Reg : Hints_MRI->second) {
415 if (Skip) {
416 Skip = false;
417 continue;
418 }
419
420 // Target-independent hints are either a physical or a virtual register.
421 Register Phys = Reg;
422 if (VRM && Phys.isVirtual())
423 Phys = VRM->getPhys(Phys);
424
425 // Don't add the same reg twice (Hints_MRI may contain multiple virtual
426 // registers allocated to the same physreg).
427 if (!HintedRegs.insert(Phys).second)
428 continue;
429 // Check that Phys is a valid hint in VirtReg's register class.
430 if (!Phys.isPhysical())
431 continue;
432 if (MRI.isReserved(Phys))
433 continue;
434 // Check that Phys is in the allocation order. We shouldn't heed hints
435 // from VirtReg's register class if they aren't in the allocation order. The
436 // target probably has a reason for removing the register.
437 if (!is_contained(Order, Phys))
438 continue;
439
440 // All clear, tell the register allocator to prefer this register.
441 Hints.push_back(Phys.id());
442 }
443 return false;
444}
445
447 MCPhysReg Reg, const BitVector &AntiHintedRegUnits) const {
448 return llvm::any_of(regunits(Reg), [&](MCRegUnit Unit) {
449 return AntiHintedRegUnits.test(static_cast<unsigned>(Unit));
450 });
451}
452
454 Register VirtReg, ArrayRef<MCPhysReg> Order,
455 SmallVectorImpl<MCPhysReg> &HintsAndCustomOrder, unsigned NumHints,
456 const BitVector &AntiHintedRegUnits, const MachineFunction &MF,
457 const LiveRegMatrix *Matrix, const RegisterClassInfo *RegClassInfo) const {
458
459 if (AntiHintedRegUnits.none())
460 return;
461
462 assert(HintsAndCustomOrder.size() == NumHints &&
463 "HintsAndCustomOrder should only contain the hints here.");
464 HintsAndCustomOrder.append(Order.begin(), Order.end());
465
466 // Custom reordering of the allocation order.
468 VirtReg,
469 MutableArrayRef<MCPhysReg>(HintsAndCustomOrder).drop_front(NumHints),
470 AntiHintedRegUnits, MF, Matrix, RegClassInfo);
471}
472
474 Register VirtReg, MutableArrayRef<MCPhysReg> CustomOrder,
475 const BitVector &AntiHintedRegUnits, const MachineFunction &MF,
476 const LiveRegMatrix *Matrix, const RegisterClassInfo *RegClassInfo) const {
477
478 // Partition non-anti-hinted register go first.
479 [[maybe_unused]] auto *PartitionPoint = std::stable_partition(
480 CustomOrder.begin(), CustomOrder.end(),
481 [&](MCPhysReg Reg) { return !isAntiHintedReg(Reg, AntiHintedRegUnits); });
482
483 LLVM_DEBUG({
484 size_t NonAntiHintedCount =
485 std::distance(CustomOrder.begin(), PartitionPoint);
486 size_t AntiHintedCount = std::distance(PartitionPoint, CustomOrder.end());
487 dbgs() << "Added " << NonAntiHintedCount
488 << " non-anti-hinted registers first\n"
489 << "Added " << AntiHintedCount
490 << " anti-hinted registers at the end\n";
491 });
492}
493
495 MCRegister PhysReg, const MachineFunction &MF) const {
496 if (!PhysReg)
497 return false;
498 const uint32_t *callerPreservedRegs =
500 if (callerPreservedRegs) {
501 assert(PhysReg.isPhysical() && "Expected physical register");
502 return (callerPreservedRegs[PhysReg.id() / 32] >> PhysReg.id() % 32) & 1;
503 }
504 return false;
505}
506
510
514
516 const uint32_t *mask1) const {
517 unsigned N = (getNumRegs()+31) / 32;
518 for (unsigned I = 0; I < N; ++I)
519 if ((mask0[I] & mask1[I]) != mask0[I])
520 return false;
521 return true;
522}
523
526 const MachineRegisterInfo &MRI) const {
527 const TargetRegisterClass *RC{};
528 if (Reg.isPhysical()) {
529 // The size is not directly available for physical registers.
530 // Instead, we need to access a register class that contains Reg and
531 // get the size of that register class.
532 RC = getMinimalPhysRegClass(Reg);
533 assert(RC && "Unable to deduce the register class");
534 return getRegSizeInBits(*RC);
535 }
536 LLT Ty = MRI.getType(Reg);
537 if (Ty.isValid())
538 return Ty.getSizeInBits();
539
540 // Since Reg is not a generic register, it may have a register class.
541 RC = MRI.getRegClass(Reg);
542 assert(RC && "Unable to deduce the register class");
543 return getRegSizeInBits(*RC);
544}
545
547 const TargetRegisterClass *RC, LaneBitmask LaneMask,
548 SmallVectorImpl<unsigned> &NeededIndexes) const {
549 SmallVector<unsigned, 8> PossibleIndexes;
550 unsigned BestIdx = 0;
551 unsigned BestCover = 0;
552
553 for (unsigned Idx = 1, E = getNumSubRegIndices(); Idx < E; ++Idx) {
554 // Is this index even compatible with the given class?
555 if (!isSubRegValidForRegClass(RC, Idx))
556 continue;
557 LaneBitmask SubRegMask = getSubRegIndexLaneMask(Idx);
558 // Early exit if we found a perfect match.
559 if (SubRegMask == LaneMask) {
560 BestIdx = Idx;
561 break;
562 }
563
564 // The index must not cover any lanes outside \p LaneMask.
565 if ((SubRegMask & ~LaneMask).any())
566 continue;
567
568 unsigned PopCount = SubRegMask.getNumLanes();
569 PossibleIndexes.push_back(Idx);
570 if (PopCount > BestCover) {
571 BestCover = PopCount;
572 BestIdx = Idx;
573 }
574 }
575
576 // Abort if we cannot possibly implement the COPY with the given indexes.
577 if (BestIdx == 0)
578 return false;
579
580 NeededIndexes.push_back(BestIdx);
581
582 // Greedy heuristic: Keep iterating keeping the best covering subreg index
583 // each time.
584 LaneBitmask LanesLeft = LaneMask & ~getSubRegIndexLaneMask(BestIdx);
585 while (LanesLeft.any()) {
586 unsigned BestIdx = 0;
587 int BestCover = std::numeric_limits<int>::min();
588 for (unsigned Idx : PossibleIndexes) {
589 LaneBitmask SubRegMask = getSubRegIndexLaneMask(Idx);
590 // Early exit if we found a perfect match.
591 if (SubRegMask == LanesLeft) {
592 BestIdx = Idx;
593 break;
594 }
595
596 // Do not cover already-covered lanes to avoid creating cycles
597 // in copy bundles (= bundle contains copies that write to the
598 // registers).
599 if ((SubRegMask & ~LanesLeft).any())
600 continue;
601
602 // Try to cover as many of the remaining lanes as possible.
603 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
604 if (Cover > BestCover) {
605 BestCover = Cover;
606 BestIdx = Idx;
607 }
608 }
609
610 if (BestIdx == 0)
611 return false; // Impossible to handle
612
613 NeededIndexes.push_back(BestIdx);
614
615 LanesLeft &= ~getSubRegIndexLaneMask(BestIdx);
616 }
617
618 return BestIdx;
619}
620
622 Register RegB,
623 unsigned SubB) const {
624 if (RegA == RegB && SubA == SubB)
625 return true;
626 if (RegA.isVirtual() && RegB.isVirtual()) {
627 if (RegA != RegB)
628 return false;
631 return (LA & LB).any();
632 }
633 if (RegA.isPhysical() && RegB.isPhysical()) {
634 MCRegister MCRegA = SubA ? getSubReg(RegA, SubA) : RegA.asMCReg();
635 MCRegister MCRegB = SubB ? getSubReg(RegB, SubB) : RegB.asMCReg();
636 assert(MCRegB.isValid() && MCRegA.isValid() && "invalid subregister");
637 return MCRegisterInfo::regsOverlap(MCRegA, MCRegB);
638 }
639 llvm_unreachable("mixed virtual and physical registers");
640}
641
642unsigned TargetRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
643 assert(Idx && Idx < getNumSubRegIndices() &&
644 "This is not a subregister index");
645 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Size;
646}
647
648unsigned TargetRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
649 assert(Idx && Idx < getNumSubRegIndices() &&
650 "This is not a subregister index");
651 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Offset;
652}
653
656 const MachineRegisterInfo *MRI) const {
657 while (true) {
658 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
659 if (!MI || !MI->isCopyLike())
660 return SrcReg;
661
662 Register CopySrcReg;
663 if (MI->isCopy())
664 CopySrcReg = MI->getOperand(1).getReg();
665 else {
666 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
667 CopySrcReg = MI->getOperand(1).getReg();
668 }
669
670 if (!CopySrcReg.isVirtual())
671 return CopySrcReg;
672
673 SrcReg = CopySrcReg;
674 }
675}
676
678 Register SrcReg, const MachineRegisterInfo *MRI) const {
679 while (true) {
680 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
681 // Found the real definition, return it if it has a single use.
682 if (!MI || !MI->isCopyLike())
683 return MRI->hasOneNonDBGUse(SrcReg) ? SrcReg : Register();
684
685 Register CopySrcReg;
686 if (MI->isCopy())
687 CopySrcReg = MI->getOperand(1).getReg();
688 else {
689 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
690 CopySrcReg = MI->getOperand(1).getReg();
691 }
692
693 // Continue only if the next definition in the chain is for a virtual
694 // register that has a single use.
695 if (!CopySrcReg.isVirtual() || !MRI->hasOneNonDBGUse(CopySrcReg))
696 return Register();
697
698 SrcReg = CopySrcReg;
699 }
700}
701
704 assert(!Offset.getScalable() && "Scalable offsets are not handled");
706}
707
710 unsigned PrependFlags,
711 const StackOffset &Offset) const {
712 assert((PrependFlags &
715 "Unsupported prepend flag");
716 SmallVector<uint64_t, 16> OffsetExpr;
717 if (PrependFlags & DIExpression::DerefBefore)
718 OffsetExpr.push_back(dwarf::DW_OP_deref);
719 getOffsetOpcodes(Offset, OffsetExpr);
720 if (PrependFlags & DIExpression::DerefAfter)
721 OffsetExpr.push_back(dwarf::DW_OP_deref);
722 return DIExpression::prependOpcodes(Expr, OffsetExpr,
723 PrependFlags & DIExpression::StackValue,
724 PrependFlags & DIExpression::EntryValue);
725}
726
727#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
729void TargetRegisterInfo::dumpReg(Register Reg, unsigned SubRegIndex,
730 const TargetRegisterInfo *TRI) {
731 dbgs() << printReg(Reg, TRI, SubRegIndex) << "\n";
732}
733#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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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:678
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.
#define LLVM_DEBUG(...)
Definition Debug.h:119
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 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))
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
iterator end() const
Definition ArrayRef.h:130
iterator begin() const
Definition ArrayRef.h:129
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.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:482
BitVector & reset()
Reset all bits in the bitvector.
Definition BitVector.h:409
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:366
bool none() const
Returns true if none of the bits are set.
Definition BitVector.h:207
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:273
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.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
bool hasSubClass(const MCRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
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< regclass_iterator > regclasses() const
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
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
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 LLVM_READONLY 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 LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
iterator end() const
Definition ArrayRef.h:339
iterator begin() const
Definition ArrayRef.h:338
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
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.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
~TargetRegisterInfo() override
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.
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const
Get the scale factor of spill weight for this register class.
bool isAntiHintedReg(MCPhysReg Reg, const BitVector &AntiHintedRegUnits) const
Return true if Reg overlaps one of the anti-hinted register units.
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...
virtual void filterAndSortForAntiHintedRegs(Register VirtReg, MutableArrayRef< MCPhysReg > CustomOrder, const BitVector &AntiHintedRegUnits, const MachineFunction &MF, const LiveRegMatrix *Matrix=nullptr, const RegisterClassInfo *RegClassInfo=nullptr) const
Custom reordering of the allocation order.
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.
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 ...
void applyRegAllocationAntiHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &HintsAndCustomOrder, unsigned NumHints, const BitVector &AntiHintedRegUnits, const MachineFunction &MF, const LiveRegMatrix *Matrix=nullptr, const RegisterClassInfo *RegClassInfo=nullptr) const
Apply anti-hints to the allocation order.
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...
virtual bool isCalleeSavedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
This is a wrapper around getCallPreservedMask().
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)
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
const TargetRegisterClass * getCommonMinimalPhysRegClass(MCRegister Reg1, MCRegister Reg2) const
Returns the common Register Class of two physical registers, picking the smallest register subclass t...
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...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
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:175
constexpr bool isVirtualReg() const
Definition Register.h:191
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:195
constexpr Register asVirtualReg() const
Definition Register.h:200
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.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
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: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
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880
#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...