LLVM 20.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
54 regclass_iterator RCE, const char *const *SRINames,
55 const SubRegCoveredBits *SubIdxRanges, const LaneBitmask *SRILaneMasks,
56 LaneBitmask SRICoveringLanes, const RegClassInfo *const RCIs,
57 const MVT::SimpleValueType *const RCVTLists, unsigned Mode)
58 : InfoDesc(ID), SubRegIndexNames(SRINames), SubRegIdxRanges(SubIdxRanges),
59 SubRegIndexLaneMasks(SRILaneMasks), RegClassBegin(RCB), RegClassEnd(RCE),
60 CoveringLanes(SRICoveringLanes), RCInfos(RCIs), RCVTLists(RCVTLists),
61 HwMode(Mode) {}
62
64
66 const MachineFunction &MF, const LiveInterval &VirtReg) const {
69 MachineInstr *MI = MRI.getUniqueVRegDef(VirtReg.reg());
70 if (MI && TII->isTriviallyReMaterializable(*MI) &&
71 VirtReg.size() > HugeSizeForSplit)
72 return false;
73 return true;
74}
75
77 MCRegister Reg) const {
78 for (MCPhysReg SR : superregs_inclusive(Reg))
79 RegisterSet.set(SR);
80}
81
83 ArrayRef<MCPhysReg> Exceptions) const {
84 // Check that all super registers of reserved regs are reserved as well.
85 BitVector Checked(getNumRegs());
86 for (unsigned Reg : RegisterSet.set_bits()) {
87 if (Checked[Reg])
88 continue;
89 for (MCPhysReg SR : superregs(Reg)) {
90 if (!RegisterSet[SR] && !is_contained(Exceptions, Reg)) {
91 dbgs() << "Error: Super register " << printReg(SR, this)
92 << " of reserved register " << printReg(Reg, this)
93 << " is not reserved.\n";
94 return false;
95 }
96
97 // We transitively check superregs. So we can remember this for later
98 // to avoid compiletime explosion in deep register hierarchies.
99 Checked.set(SR);
100 }
101 }
102 return true;
103}
104
105namespace llvm {
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 (Register::isStackSlot(Reg))
113 OS << "SS#" << Register::stackSlot2Index(Reg);
114 else if (Reg.isVirtual()) {
115 StringRef Name = MRI ? MRI->getVRegName(Reg) : "";
116 if (Name != "") {
117 OS << '%' << Name;
118 } else {
119 OS << '%' << Register::virtReg2Index(Reg);
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~" << Unit;
143 return;
144 }
145
146 // Check for invalid register units.
147 if (Unit >= TRI->getNumRegUnits()) {
148 OS << "BadUnit~" << 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 return Printable([Unit, TRI](raw_ostream &OS) {
163 if (Register::isVirtualRegister(Unit)) {
164 OS << '%' << Register::virtReg2Index(Unit);
165 } else {
166 OS << printRegUnit(Unit, TRI);
167 }
168 });
169}
170
172 const TargetRegisterInfo *TRI) {
173 return Printable([Reg, &RegInfo, TRI](raw_ostream &OS) {
174 if (RegInfo.getRegClassOrNull(Reg))
175 OS << StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
176 else if (RegInfo.getRegBankOrNull(Reg))
177 OS << StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
178 else {
179 OS << "_";
180 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
181 "Generic registers must have a valid type");
182 }
183 });
184}
185
186} // end namespace llvm
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
204template <typename TypeT>
205static const TargetRegisterClass *
207 TypeT Ty) {
208 static_assert(std::is_same_v<TypeT, MVT> || std::is_same_v<TypeT, LLT>);
210 "reg must be a physical register");
211
212 bool IsDefault = [&]() {
213 if constexpr (std::is_same_v<TypeT, MVT>)
214 return Ty == MVT::Other;
215 else
216 return !Ty.isValid();
217 }();
218
219 // Pick the most sub register class of the right type that contains
220 // this physreg.
221 const TargetRegisterClass *BestRC = nullptr;
222 for (const TargetRegisterClass *RC : TRI->regclasses()) {
223 if ((IsDefault || TRI->isTypeLegalForClass(*RC, Ty)) && RC->contains(Reg) &&
224 (!BestRC || BestRC->hasSubClass(RC)))
225 BestRC = RC;
226 }
227
228 if constexpr (std::is_same_v<TypeT, MVT>)
229 assert(BestRC && "Couldn't find the register class");
230 return BestRC;
231}
232
233template <typename TypeT>
234static const TargetRegisterClass *
236 MCRegister Reg2, TypeT Ty) {
237 static_assert(std::is_same_v<TypeT, MVT> || std::is_same_v<TypeT, LLT>);
240 "Reg1/Reg2 must be a physical register");
241
242 bool IsDefault = [&]() {
243 if constexpr (std::is_same_v<TypeT, MVT>)
244 return Ty == MVT::Other;
245 else
246 return !Ty.isValid();
247 }();
248
249 // Pick the most sub register class of the right type that contains
250 // this physreg.
251 const TargetRegisterClass *BestRC = nullptr;
252 for (const TargetRegisterClass *RC : TRI->regclasses()) {
253 if ((IsDefault || TRI->isTypeLegalForClass(*RC, Ty)) &&
254 RC->contains(Reg1, Reg2) && (!BestRC || BestRC->hasSubClass(RC)))
255 BestRC = RC;
256 }
257
258 if constexpr (std::is_same_v<TypeT, MVT>)
259 assert(BestRC && "Couldn't find the register class");
260 return BestRC;
261}
262
265 return ::getMinimalPhysRegClass(this, Reg, VT);
266}
267
269 MCRegister Reg1, MCRegister Reg2, MVT VT) const {
270 return ::getCommonMinimalPhysRegClass(this, Reg1, Reg2, VT);
271}
272
275 return ::getMinimalPhysRegClass(this, Reg, Ty);
276}
277
279 MCRegister Reg1, MCRegister Reg2, LLT Ty) const {
280 return ::getCommonMinimalPhysRegClass(this, Reg1, Reg2, Ty);
281}
282
283/// getAllocatableSetForRC - Toggle the bits that represent allocatable
284/// registers for the specific register class.
286 const TargetRegisterClass *RC, BitVector &R){
287 assert(RC->isAllocatable() && "invalid for nonallocatable sets");
289 for (MCPhysReg PR : Order)
290 R.set(PR);
291}
292
294 const TargetRegisterClass *RC) const {
295 BitVector Allocatable(getNumRegs());
296 if (RC) {
297 // A register class with no allocatable subclass returns an empty set.
298 const TargetRegisterClass *SubClass = getAllocatableClass(RC);
299 if (SubClass)
300 getAllocatableSetForRC(MF, SubClass, Allocatable);
301 } else {
302 for (const TargetRegisterClass *C : regclasses())
303 if (C->isAllocatable())
304 getAllocatableSetForRC(MF, C, Allocatable);
305 }
306
307 // Mask out the reserved registers
308 const MachineRegisterInfo &MRI = MF.getRegInfo();
309 const BitVector &Reserved = MRI.getReservedRegs();
310 Allocatable.reset(Reserved);
311
312 return Allocatable;
313}
314
315static inline
317 const uint32_t *B,
318 const TargetRegisterInfo *TRI) {
319 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; I += 32)
320 if (unsigned Common = *A++ & *B++)
321 return TRI->getRegClass(I + llvm::countr_zero(Common));
322 return nullptr;
323}
324
327 const TargetRegisterClass *B) const {
328 // First take care of the trivial cases.
329 if (A == B)
330 return A;
331 if (!A || !B)
332 return nullptr;
333
334 // Register classes are ordered topologically, so the largest common
335 // sub-class it the common sub-class with the smallest ID.
336 return firstCommonClass(A->getSubClassMask(), B->getSubClassMask(), this);
337}
338
341 const TargetRegisterClass *B,
342 unsigned Idx) const {
343 assert(A && B && "Missing register class");
344 assert(Idx && "Bad sub-register index");
345
346 // Find Idx in the list of super-register indices.
347 for (SuperRegClassIterator RCI(B, this); RCI.isValid(); ++RCI)
348 if (RCI.getSubReg() == Idx)
349 // The bit mask contains all register classes that are projected into B
350 // by Idx. Find a class that is also a sub-class of A.
351 return firstCommonClass(RCI.getMask(), A->getSubClassMask(), this);
352 return nullptr;
353}
354
356getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
357 const TargetRegisterClass *RCB, unsigned SubB,
358 unsigned &PreA, unsigned &PreB) const {
359 assert(RCA && SubA && RCB && SubB && "Invalid arguments");
360
361 // Search all pairs of sub-register indices that project into RCA and RCB
362 // respectively. This is quadratic, but usually the sets are very small. On
363 // most targets like X86, there will only be a single sub-register index
364 // (e.g., sub_16bit projecting into GR16).
365 //
366 // The worst case is a register class like DPR on ARM.
367 // We have indices dsub_0..dsub_7 projecting into that class.
368 //
369 // It is very common that one register class is a sub-register of the other.
370 // Arrange for RCA to be the larger register so the answer will be found in
371 // the first iteration. This makes the search linear for the most common
372 // case.
373 const TargetRegisterClass *BestRC = nullptr;
374 unsigned *BestPreA = &PreA;
375 unsigned *BestPreB = &PreB;
376 if (getRegSizeInBits(*RCA) < getRegSizeInBits(*RCB)) {
377 std::swap(RCA, RCB);
378 std::swap(SubA, SubB);
379 std::swap(BestPreA, BestPreB);
380 }
381
382 // Also terminate the search one we have found a register class as small as
383 // RCA.
384 unsigned MinSize = getRegSizeInBits(*RCA);
385
386 for (SuperRegClassIterator IA(RCA, this, true); IA.isValid(); ++IA) {
387 unsigned FinalA = composeSubRegIndices(IA.getSubReg(), SubA);
388 for (SuperRegClassIterator IB(RCB, this, true); IB.isValid(); ++IB) {
389 // Check if a common super-register class exists for this index pair.
390 const TargetRegisterClass *RC =
391 firstCommonClass(IA.getMask(), IB.getMask(), this);
392 if (!RC || getRegSizeInBits(*RC) < MinSize)
393 continue;
394
395 // The indexes must compose identically: PreA+SubA == PreB+SubB.
396 unsigned FinalB = composeSubRegIndices(IB.getSubReg(), SubB);
397 if (FinalA != FinalB)
398 continue;
399
400 // Is RC a better candidate than BestRC?
401 if (BestRC && getRegSizeInBits(*RC) >= getRegSizeInBits(*BestRC))
402 continue;
403
404 // Yes, RC is the smallest super-register seen so far.
405 BestRC = RC;
406 *BestPreA = IA.getSubReg();
407 *BestPreB = IB.getSubReg();
408
409 // Bail early if we reached MinSize. We won't find a better candidate.
410 if (getRegSizeInBits(*BestRC) == MinSize)
411 return BestRC;
412 }
413 }
414 return BestRC;
415}
416
417/// Check if the registers defined by the pair (RegisterClass, SubReg)
418/// share the same register file.
420 const TargetRegisterClass *DefRC,
421 unsigned DefSubReg,
422 const TargetRegisterClass *SrcRC,
423 unsigned SrcSubReg) {
424 // Same register class.
425 if (DefRC == SrcRC)
426 return true;
427
428 // Both operands are sub registers. Check if they share a register class.
429 unsigned SrcIdx, DefIdx;
430 if (SrcSubReg && DefSubReg) {
431 return TRI.getCommonSuperRegClass(SrcRC, SrcSubReg, DefRC, DefSubReg,
432 SrcIdx, DefIdx) != nullptr;
433 }
434
435 // At most one of the register is a sub register, make it Src to avoid
436 // duplicating the test.
437 if (!SrcSubReg) {
438 std::swap(DefSubReg, SrcSubReg);
439 std::swap(DefRC, SrcRC);
440 }
441
442 // One of the register is a sub register, check if we can get a superclass.
443 if (SrcSubReg)
444 return TRI.getMatchingSuperRegClass(SrcRC, DefRC, SrcSubReg) != nullptr;
445
446 // Plain copy.
447 return TRI.getCommonSubClass(DefRC, SrcRC) != nullptr;
448}
449
451 unsigned DefSubReg,
452 const TargetRegisterClass *SrcRC,
453 unsigned SrcSubReg) const {
454 // If this source does not incur a cross register bank copy, use it.
455 return shareSameRegisterFile(*this, DefRC, DefSubReg, SrcRC, SrcSubReg);
456}
457
458// Compute target-independent register allocator hints to help eliminate copies.
460 Register VirtReg, ArrayRef<MCPhysReg> Order,
462 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
463 const MachineRegisterInfo &MRI = MF.getRegInfo();
464 const std::pair<unsigned, SmallVector<Register, 4>> *Hints_MRI =
465 MRI.getRegAllocationHints(VirtReg);
466
467 if (!Hints_MRI)
468 return false;
469
470 SmallSet<Register, 32> HintedRegs;
471 // First hint may be a target hint.
472 bool Skip = (Hints_MRI->first != 0);
473 for (auto Reg : Hints_MRI->second) {
474 if (Skip) {
475 Skip = false;
476 continue;
477 }
478
479 // Target-independent hints are either a physical or a virtual register.
480 Register Phys = Reg;
481 if (VRM && Phys.isVirtual())
482 Phys = VRM->getPhys(Phys);
483
484 // Don't add the same reg twice (Hints_MRI may contain multiple virtual
485 // registers allocated to the same physreg).
486 if (!HintedRegs.insert(Phys).second)
487 continue;
488 // Check that Phys is a valid hint in VirtReg's register class.
489 if (!Phys.isPhysical())
490 continue;
491 if (MRI.isReserved(Phys))
492 continue;
493 // Check that Phys is in the allocation order. We shouldn't heed hints
494 // from VirtReg's register class if they aren't in the allocation order. The
495 // target probably has a reason for removing the register.
496 if (!is_contained(Order, Phys))
497 continue;
498
499 // All clear, tell the register allocator to prefer this register.
500 Hints.push_back(Phys);
501 }
502 return false;
503}
504
506 MCRegister PhysReg, const MachineFunction &MF) const {
507 if (PhysReg == 0)
508 return false;
509 const uint32_t *callerPreservedRegs =
511 if (callerPreservedRegs) {
513 "Expected physical register");
514 return (callerPreservedRegs[PhysReg / 32] >> PhysReg % 32) & 1;
515 }
516 return false;
517}
518
520 return MF.getFrameInfo().isStackRealignable();
521}
522
524 return MF.getFrameInfo().shouldRealignStack();
525}
526
528 const uint32_t *mask1) const {
529 unsigned N = (getNumRegs()+31) / 32;
530 for (unsigned I = 0; I < N; ++I)
531 if ((mask0[I] & mask1[I]) != mask0[I])
532 return false;
533 return true;
534}
535
538 const MachineRegisterInfo &MRI) const {
539 const TargetRegisterClass *RC{};
540 if (Reg.isPhysical()) {
541 // The size is not directly available for physical registers.
542 // Instead, we need to access a register class that contains Reg and
543 // get the size of that register class.
544 RC = getMinimalPhysRegClass(Reg);
545 assert(RC && "Unable to deduce the register class");
546 return getRegSizeInBits(*RC);
547 }
548 LLT Ty = MRI.getType(Reg);
549 if (Ty.isValid())
550 return Ty.getSizeInBits();
551
552 // Since Reg is not a generic register, it may have a register class.
553 RC = MRI.getRegClass(Reg);
554 assert(RC && "Unable to deduce the register class");
555 return getRegSizeInBits(*RC);
556}
557
560 LaneBitmask LaneMask, SmallVectorImpl<unsigned> &NeededIndexes) const {
561 SmallVector<unsigned, 8> PossibleIndexes;
562 unsigned BestIdx = 0;
563 unsigned BestCover = 0;
564
565 for (unsigned Idx = 1, E = getNumSubRegIndices(); Idx < E; ++Idx) {
566 // Is this index even compatible with the given class?
567 if (getSubClassWithSubReg(RC, Idx) != RC)
568 continue;
570 // Early exit if we found a perfect match.
571 if (SubRegMask == LaneMask) {
572 BestIdx = Idx;
573 break;
574 }
575
576 // The index must not cover any lanes outside \p LaneMask.
577 if ((SubRegMask & ~LaneMask).any())
578 continue;
579
580 unsigned PopCount = SubRegMask.getNumLanes();
581 PossibleIndexes.push_back(Idx);
582 if (PopCount > BestCover) {
583 BestCover = PopCount;
584 BestIdx = Idx;
585 }
586 }
587
588 // Abort if we cannot possibly implement the COPY with the given indexes.
589 if (BestIdx == 0)
590 return false;
591
592 NeededIndexes.push_back(BestIdx);
593
594 // Greedy heuristic: Keep iterating keeping the best covering subreg index
595 // each time.
596 LaneBitmask LanesLeft = LaneMask & ~getSubRegIndexLaneMask(BestIdx);
597 while (LanesLeft.any()) {
598 unsigned BestIdx = 0;
599 int BestCover = std::numeric_limits<int>::min();
600 for (unsigned Idx : PossibleIndexes) {
602 // Early exit if we found a perfect match.
603 if (SubRegMask == LanesLeft) {
604 BestIdx = Idx;
605 break;
606 }
607
608 // Do not cover already-covered lanes to avoid creating cycles
609 // in copy bundles (= bundle contains copies that write to the
610 // registers).
611 if ((SubRegMask & ~LanesLeft).any())
612 continue;
613
614 // Try to cover as many of the remaining lanes as possible.
615 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
616 if (Cover > BestCover) {
617 BestCover = Cover;
618 BestIdx = Idx;
619 }
620 }
621
622 if (BestIdx == 0)
623 return false; // Impossible to handle
624
625 NeededIndexes.push_back(BestIdx);
626
627 LanesLeft &= ~getSubRegIndexLaneMask(BestIdx);
628 }
629
630 return BestIdx;
631}
632
635 "This is not a subregister index");
636 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Size;
637}
638
641 "This is not a subregister index");
642 return SubRegIdxRanges[HwMode * getNumSubRegIndices() + Idx].Offset;
643}
644
647 const MachineRegisterInfo *MRI) const {
648 while (true) {
649 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
650 if (!MI->isCopyLike())
651 return SrcReg;
652
653 Register CopySrcReg;
654 if (MI->isCopy())
655 CopySrcReg = MI->getOperand(1).getReg();
656 else {
657 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
658 CopySrcReg = MI->getOperand(2).getReg();
659 }
660
661 if (!CopySrcReg.isVirtual())
662 return CopySrcReg;
663
664 SrcReg = CopySrcReg;
665 }
666}
667
669 Register SrcReg, const MachineRegisterInfo *MRI) const {
670 while (true) {
671 const MachineInstr *MI = MRI->getVRegDef(SrcReg);
672 // Found the real definition, return it if it has a single use.
673 if (!MI->isCopyLike())
674 return MRI->hasOneNonDBGUse(SrcReg) ? SrcReg : Register();
675
676 Register CopySrcReg;
677 if (MI->isCopy())
678 CopySrcReg = MI->getOperand(1).getReg();
679 else {
680 assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike");
681 CopySrcReg = MI->getOperand(2).getReg();
682 }
683
684 // Continue only if the next definition in the chain is for a virtual
685 // register that has a single use.
686 if (!CopySrcReg.isVirtual() || !MRI->hasOneNonDBGUse(CopySrcReg))
687 return Register();
688
689 SrcReg = CopySrcReg;
690 }
691}
692
694 const StackOffset &Offset, SmallVectorImpl<uint64_t> &Ops) const {
695 assert(!Offset.getScalable() && "Scalable offsets are not handled");
696 DIExpression::appendOffset(Ops, Offset.getFixed());
697}
698
701 unsigned PrependFlags,
702 const StackOffset &Offset) const {
703 assert((PrependFlags &
706 "Unsupported prepend flag");
707 SmallVector<uint64_t, 16> OffsetExpr;
708 if (PrependFlags & DIExpression::DerefBefore)
709 OffsetExpr.push_back(dwarf::DW_OP_deref);
710 getOffsetOpcodes(Offset, OffsetExpr);
711 if (PrependFlags & DIExpression::DerefAfter)
712 OffsetExpr.push_back(dwarf::DW_OP_deref);
713 return DIExpression::prependOpcodes(Expr, OffsetExpr,
714 PrependFlags & DIExpression::StackValue,
715 PrependFlags & DIExpression::EntryValue);
716}
717
718#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
720void TargetRegisterInfo::dumpReg(Register Reg, unsigned SubRegIndex,
721 const TargetRegisterInfo *TRI) {
722 dbgs() << printReg(Reg, TRI, SubRegIndex) << "\n";
723}
724#endif
unsigned const MachineRegisterInfo * MRI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Live Register Matrix
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
if(PassOpts->AAPipeline)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
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))
static bool shareSameRegisterFile(const TargetRegisterInfo &TRI, const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg)
Check if the registers defined by the pair (RegisterClass, SubReg) share the same register file.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
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()
Definition: BitVector.h:392
BitVector & set()
Definition: BitVector.h:351
DWARF expression.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static 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:277
constexpr bool isValid() const
Definition: LowLevelType.h:145
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
Definition: LowLevelType.h:190
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:687
Register reg() const
Definition: LiveInterval.h:718
size_t size() const
Definition: LiveInterval.h:305
MCRegUnitRootIterator enumerates the root registers of a register unit.
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
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.
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:33
Machine Value Type.
bool shouldRealignStack() const
Return true if stack realignment is forced by function attributes or if the stack alignment.
bool isStackRealignable() const
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.
Definition: MachineInstr.h:69
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38
const char * getName() const
Get a user friendly name of this register bank.
Definition: RegisterBank.h:49
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static constexpr bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful to be able to store a non-negative frame index in a variable tha...
Definition: Register.h:44
static int stackSlot2Index(Register Reg)
Compute the frame index from a register value representing a stack slot.
Definition: Register.h:52
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
Definition: Register.h:77
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:91
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:71
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:65
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:95
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:132
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:181
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:33
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::string lower() const
Definition: StringRef.cpp:113
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
TargetInstrInfo - Interface to description of machine instruction set.
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.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const TargetRegisterClass *const * regclass_iterator
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.
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
Returns the largest legal sub-class of RC that supports the sub-register index Idx.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
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.
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 bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
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...
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB, regclass_iterator RCE, const char *const *SRINames, const SubRegCoveredBits *SubIdxRanges, const LaneBitmask *SRILaneMasks, LaneBitmask CoveringLanes, const RegClassInfo *const RCIs, const MVT::SimpleValueType *const RCVTLists, unsigned Mode=0)
DIExpression * prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags, const StackOffset &Offset) const
Prepends a DWARF expression for Offset to DIExpression Expr.
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 getCoveringSubRegIndexes(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, LaneBitmask LaneMask, SmallVectorImpl< unsigned > &Indexes) const
Try to find one or more subregister indexes to cover LaneMask.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the specified register class A so that each register in it has a sub-register of...
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:90
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
Printable printRegUnit(unsigned 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:215
Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
#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...