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