Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/CodeGenRegisters.h
96353 views
//===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines structures to encapsulate information gleaned from the9// target register and register class definitions.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_UTILS_TABLEGEN_CODEGENREGISTERS_H14#define LLVM_UTILS_TABLEGEN_CODEGENREGISTERS_H1516#include "CodeGenHwModes.h"17#include "InfoByHwMode.h"18#include "llvm/ADT/ArrayRef.h"19#include "llvm/ADT/BitVector.h"20#include "llvm/ADT/DenseMap.h"21#include "llvm/ADT/STLExtras.h"22#include "llvm/ADT/SetVector.h"23#include "llvm/ADT/SmallPtrSet.h"24#include "llvm/ADT/SmallVector.h"25#include "llvm/ADT/SparseBitVector.h"26#include "llvm/ADT/StringMap.h"27#include "llvm/ADT/StringRef.h"28#include "llvm/MC/LaneBitmask.h"29#include "llvm/Support/ErrorHandling.h"30#include "llvm/TableGen/Record.h"31#include "llvm/TableGen/SetTheory.h"32#include <cassert>33#include <cstdint>34#include <deque>35#include <functional>36#include <list>37#include <map>38#include <memory>39#include <optional>40#include <string>41#include <utility>42#include <vector>4344namespace llvm {4546class CodeGenRegBank;4748/// Used to encode a step in a register lane mask transformation.49/// Mask the bits specified in Mask, then rotate them Rol bits to the left50/// assuming a wraparound at 32bits.51struct MaskRolPair {52LaneBitmask Mask;53uint8_t RotateLeft;5455bool operator==(const MaskRolPair Other) const {56return Mask == Other.Mask && RotateLeft == Other.RotateLeft;57}58bool operator!=(const MaskRolPair Other) const {59return Mask != Other.Mask || RotateLeft != Other.RotateLeft;60}61};6263/// CodeGenSubRegIndex - Represents a sub-register index.64class CodeGenSubRegIndex {65Record *const TheDef;66std::string Name;67std::string Namespace;6869public:70SubRegRangeByHwMode Range;71const unsigned EnumValue;72mutable LaneBitmask LaneMask;73mutable SmallVector<MaskRolPair, 1> CompositionLaneMaskTransform;7475/// A list of subregister indexes concatenated resulting in this76/// subregister index. This is the reverse of CodeGenRegBank::ConcatIdx.77SmallVector<CodeGenSubRegIndex *, 4> ConcatenationOf;7879// Are all super-registers containing this SubRegIndex covered by their80// sub-registers?81bool AllSuperRegsCovered;82// A subregister index is "artificial" if every subregister obtained83// from applying this index is artificial. Artificial subregister84// indexes are not used to create new register classes.85bool Artificial;8687CodeGenSubRegIndex(Record *R, unsigned Enum, const CodeGenHwModes &CGH);88CodeGenSubRegIndex(StringRef N, StringRef Nspace, unsigned Enum);89CodeGenSubRegIndex(CodeGenSubRegIndex &) = delete;9091const std::string &getName() const { return Name; }92const std::string &getNamespace() const { return Namespace; }93std::string getQualifiedName() const;9495// Map of composite subreg indices.96typedef std::map<CodeGenSubRegIndex *, CodeGenSubRegIndex *,97deref<std::less<>>>98CompMap;99100// Returns the subreg index that results from composing this with Idx.101// Returns NULL if this and Idx don't compose.102CodeGenSubRegIndex *compose(CodeGenSubRegIndex *Idx) const {103CompMap::const_iterator I = Composed.find(Idx);104return I == Composed.end() ? nullptr : I->second;105}106107// Add a composite subreg index: this+A = B.108// Return a conflicting composite, or NULL109CodeGenSubRegIndex *addComposite(CodeGenSubRegIndex *A, CodeGenSubRegIndex *B,110const CodeGenHwModes &CGH) {111assert(A && B);112std::pair<CompMap::iterator, bool> Ins = Composed.insert(std::pair(A, B));113114// Synthetic subreg indices that aren't contiguous (for instance ARM115// register tuples) don't have a bit range, so it's OK to let116// B->Offset == -1. For the other cases, accumulate the offset and set117// the size here. Only do so if there is no offset yet though.118unsigned NumModes = CGH.getNumModeIds();119// Skip default mode.120for (unsigned M = 0; M < NumModes; ++M) {121// Handle DefaultMode last.122if (M == DefaultMode)123continue;124SubRegRange &Range = this->Range.get(M);125SubRegRange &ARange = A->Range.get(M);126SubRegRange &BRange = B->Range.get(M);127128if (Range.Offset != (uint16_t)-1 && ARange.Offset != (uint16_t)-1 &&129BRange.Offset == (uint16_t)-1) {130BRange.Offset = Range.Offset + ARange.Offset;131BRange.Size = ARange.Size;132}133}134135// Now handle default.136SubRegRange &Range = this->Range.get(DefaultMode);137SubRegRange &ARange = A->Range.get(DefaultMode);138SubRegRange &BRange = B->Range.get(DefaultMode);139if (Range.Offset != (uint16_t)-1 && ARange.Offset != (uint16_t)-1 &&140BRange.Offset == (uint16_t)-1) {141BRange.Offset = Range.Offset + ARange.Offset;142BRange.Size = ARange.Size;143}144145return (Ins.second || Ins.first->second == B) ? nullptr : Ins.first->second;146}147148// Update the composite maps of components specified in 'ComposedOf'.149void updateComponents(CodeGenRegBank &);150151// Return the map of composites.152const CompMap &getComposites() const { return Composed; }153154// Compute LaneMask from Composed. Return LaneMask.155LaneBitmask computeLaneMask() const;156157void setConcatenationOf(ArrayRef<CodeGenSubRegIndex *> Parts);158159/// Replaces subregister indexes in the `ConcatenationOf` list with160/// list of subregisters they are composed of (if any). Do this recursively.161void computeConcatTransitiveClosure();162163bool operator<(const CodeGenSubRegIndex &RHS) const {164return this->EnumValue < RHS.EnumValue;165}166167private:168CompMap Composed;169};170171/// CodeGenRegister - Represents a register definition.172class CodeGenRegister {173public:174Record *TheDef;175unsigned EnumValue;176std::vector<int64_t> CostPerUse;177bool CoveredBySubRegs = true;178bool HasDisjunctSubRegs = false;179bool Artificial = true;180bool Constant = false;181182// Map SubRegIndex -> Register.183typedef std::map<CodeGenSubRegIndex *, CodeGenRegister *, deref<std::less<>>>184SubRegMap;185186CodeGenRegister(Record *R, unsigned Enum);187188StringRef getName() const;189190// Extract more information from TheDef. This is used to build an object191// graph after all CodeGenRegister objects have been created.192void buildObjectGraph(CodeGenRegBank &);193194// Lazily compute a map of all sub-registers.195// This includes unique entries for all sub-sub-registers.196const SubRegMap &computeSubRegs(CodeGenRegBank &);197198// Compute extra sub-registers by combining the existing sub-registers.199void computeSecondarySubRegs(CodeGenRegBank &);200201// Add this as a super-register to all sub-registers after the sub-register202// graph has been built.203void computeSuperRegs(CodeGenRegBank &);204205const SubRegMap &getSubRegs() const {206assert(SubRegsComplete && "Must precompute sub-registers");207return SubRegs;208}209210// Add sub-registers to OSet following a pre-order defined by the .td file.211void addSubRegsPreOrder(SetVector<const CodeGenRegister *> &OSet,212CodeGenRegBank &) const;213214// Return the sub-register index naming Reg as a sub-register of this215// register. Returns NULL if Reg is not a sub-register.216CodeGenSubRegIndex *getSubRegIndex(const CodeGenRegister *Reg) const {217return SubReg2Idx.lookup(Reg);218}219220typedef std::vector<const CodeGenRegister *> SuperRegList;221222// Get the list of super-registers in topological order, small to large.223// This is valid after computeSubRegs visits all registers during RegBank224// construction.225const SuperRegList &getSuperRegs() const {226assert(SubRegsComplete && "Must precompute sub-registers");227return SuperRegs;228}229230// Get the list of ad hoc aliases. The graph is symmetric, so the list231// contains all registers in 'Aliases', and all registers that mention this232// register in 'Aliases'.233ArrayRef<CodeGenRegister *> getExplicitAliases() const {234return ExplicitAliases;235}236237// Get the topological signature of this register. This is a small integer238// less than RegBank.getNumTopoSigs(). Registers with the same TopoSig have239// identical sub-register structure. That is, they support the same set of240// sub-register indices mapping to the same kind of sub-registers241// (TopoSig-wise).242unsigned getTopoSig() const {243assert(SuperRegsComplete && "TopoSigs haven't been computed yet.");244return TopoSig;245}246247// List of register units in ascending order.248typedef SparseBitVector<> RegUnitList;249typedef SmallVector<LaneBitmask, 16> RegUnitLaneMaskList;250251// How many entries in RegUnitList are native?252RegUnitList NativeRegUnits;253254// Get the list of register units.255// This is only valid after computeSubRegs() completes.256const RegUnitList &getRegUnits() const { return RegUnits; }257258ArrayRef<LaneBitmask> getRegUnitLaneMasks() const {259return ArrayRef(RegUnitLaneMasks).slice(0, NativeRegUnits.count());260}261262// Get the native register units. This is a prefix of getRegUnits().263RegUnitList getNativeRegUnits() const { return NativeRegUnits; }264265void setRegUnitLaneMasks(const RegUnitLaneMaskList &LaneMasks) {266RegUnitLaneMasks = LaneMasks;267}268269// Inherit register units from subregisters.270// Return true if the RegUnits changed.271bool inheritRegUnits(CodeGenRegBank &RegBank);272273// Adopt a register unit for pressure tracking.274// A unit is adopted iff its unit number is >= NativeRegUnits.count().275void adoptRegUnit(unsigned RUID) { RegUnits.set(RUID); }276277// Get the sum of this register's register unit weights.278unsigned getWeight(const CodeGenRegBank &RegBank) const;279280// Canonically ordered set.281typedef std::vector<const CodeGenRegister *> Vec;282283private:284bool SubRegsComplete;285bool SuperRegsComplete;286unsigned TopoSig;287288// The sub-registers explicit in the .td file form a tree.289SmallVector<CodeGenSubRegIndex *, 8> ExplicitSubRegIndices;290SmallVector<CodeGenRegister *, 8> ExplicitSubRegs;291292// Explicit ad hoc aliases, symmetrized to form an undirected graph.293SmallVector<CodeGenRegister *, 8> ExplicitAliases;294295// Super-registers where this is the first explicit sub-register.296SuperRegList LeadingSuperRegs;297298SubRegMap SubRegs;299SuperRegList SuperRegs;300DenseMap<const CodeGenRegister *, CodeGenSubRegIndex *> SubReg2Idx;301RegUnitList RegUnits;302RegUnitLaneMaskList RegUnitLaneMasks;303};304305inline bool operator<(const CodeGenRegister &A, const CodeGenRegister &B) {306return A.EnumValue < B.EnumValue;307}308309inline bool operator==(const CodeGenRegister &A, const CodeGenRegister &B) {310return A.EnumValue == B.EnumValue;311}312313class CodeGenRegisterClass {314CodeGenRegister::Vec Members;315// Allocation orders. Order[0] always contains all registers in Members.316std::vector<SmallVector<Record *, 16>> Orders;317// Bit mask of sub-classes including this, indexed by their EnumValue.318BitVector SubClasses;319// List of super-classes, topologocally ordered to have the larger classes320// first. This is the same as sorting by EnumValue.321SmallVector<CodeGenRegisterClass *, 4> SuperClasses;322Record *TheDef;323std::string Name;324325// For a synthesized class, inherit missing properties from the nearest326// super-class.327void inheritProperties(CodeGenRegBank &);328329// Map SubRegIndex -> sub-class. This is the largest sub-class where all330// registers have a SubRegIndex sub-register.331DenseMap<const CodeGenSubRegIndex *, CodeGenRegisterClass *>332SubClassWithSubReg;333334// Map SubRegIndex -> set of super-reg classes. This is all register335// classes SuperRC such that:336//337// R:SubRegIndex in this RC for all R in SuperRC.338//339DenseMap<const CodeGenSubRegIndex *, SmallPtrSet<CodeGenRegisterClass *, 8>>340SuperRegClasses;341342// Bit vector of TopoSigs for the registers in this class. This will be343// very sparse on regular architectures.344BitVector TopoSigs;345346public:347unsigned EnumValue;348StringRef Namespace;349SmallVector<ValueTypeByHwMode, 4> VTs;350RegSizeInfoByHwMode RSI;351int CopyCost;352bool Allocatable;353StringRef AltOrderSelect;354uint8_t AllocationPriority;355bool GlobalPriority;356uint8_t TSFlags;357/// Contains the combination of the lane masks of all subregisters.358LaneBitmask LaneMask;359/// True if there are at least 2 subregisters which do not interfere.360bool HasDisjunctSubRegs;361bool CoveredBySubRegs;362/// A register class is artificial if all its members are artificial.363bool Artificial;364/// Generate register pressure set for this register class and any class365/// synthesized from it.366bool GeneratePressureSet;367368// Return the Record that defined this class, or NULL if the class was369// created by TableGen.370Record *getDef() const { return TheDef; }371372std::string getNamespaceQualification() const;373const std::string &getName() const { return Name; }374std::string getQualifiedName() const;375std::string getIdName() const;376std::string getQualifiedIdName() const;377ArrayRef<ValueTypeByHwMode> getValueTypes() const { return VTs; }378unsigned getNumValueTypes() const { return VTs.size(); }379bool hasType(const ValueTypeByHwMode &VT) const;380381const ValueTypeByHwMode &getValueTypeNum(unsigned VTNum) const {382if (VTNum < VTs.size())383return VTs[VTNum];384llvm_unreachable("VTNum greater than number of ValueTypes in RegClass!");385}386387// Return true if this class contains the register.388bool contains(const CodeGenRegister *) const;389390// Returns true if RC is a subclass.391// RC is a sub-class of this class if it is a valid replacement for any392// instruction operand where a register of this classis required. It must393// satisfy these conditions:394//395// 1. All RC registers are also in this.396// 2. The RC spill size must not be smaller than our spill size.397// 3. RC spill alignment must be compatible with ours.398//399bool hasSubClass(const CodeGenRegisterClass *RC) const {400return SubClasses.test(RC->EnumValue);401}402403// getSubClassWithSubReg - Returns the largest sub-class where all404// registers have a SubIdx sub-register.405CodeGenRegisterClass *406getSubClassWithSubReg(const CodeGenSubRegIndex *SubIdx) const {407return SubClassWithSubReg.lookup(SubIdx);408}409410/// Find largest subclass where all registers have SubIdx subregisters in411/// SubRegClass and the largest subregister class that contains those412/// subregisters without (as far as possible) also containing additional413/// registers.414///415/// This can be used to find a suitable pair of classes for subregister416/// copies. \return std::pair<SubClass, SubRegClass> where SubClass is a417/// SubClass is a class where every register has SubIdx and SubRegClass is a418/// class where every register is covered by the SubIdx subregister of419/// SubClass.420std::optional<std::pair<CodeGenRegisterClass *, CodeGenRegisterClass *>>421getMatchingSubClassWithSubRegs(CodeGenRegBank &RegBank,422const CodeGenSubRegIndex *SubIdx) const;423424void setSubClassWithSubReg(const CodeGenSubRegIndex *SubIdx,425CodeGenRegisterClass *SubRC) {426SubClassWithSubReg[SubIdx] = SubRC;427}428429// getSuperRegClasses - Returns a bit vector of all register classes430// containing only SubIdx super-registers of this class.431void getSuperRegClasses(const CodeGenSubRegIndex *SubIdx,432BitVector &Out) const;433434// addSuperRegClass - Add a class containing only SubIdx super-registers.435void addSuperRegClass(CodeGenSubRegIndex *SubIdx,436CodeGenRegisterClass *SuperRC) {437SuperRegClasses[SubIdx].insert(SuperRC);438}439440// getSubClasses - Returns a constant BitVector of subclasses indexed by441// EnumValue.442// The SubClasses vector includes an entry for this class.443const BitVector &getSubClasses() const { return SubClasses; }444445// getSuperClasses - Returns a list of super classes ordered by EnumValue.446// The array does not include an entry for this class.447ArrayRef<CodeGenRegisterClass *> getSuperClasses() const {448return SuperClasses;449}450451// Returns an ordered list of class members.452// The order of registers is the same as in the .td file.453// No = 0 is the default allocation order, No = 1 is the first alternative.454ArrayRef<Record *> getOrder(unsigned No = 0) const { return Orders[No]; }455456// Return the total number of allocation orders available.457unsigned getNumOrders() const { return Orders.size(); }458459// Get the set of registers. This set contains the same registers as460// getOrder(0).461const CodeGenRegister::Vec &getMembers() const { return Members; }462463// Get a bit vector of TopoSigs present in this register class.464const BitVector &getTopoSigs() const { return TopoSigs; }465466// Get a weight of this register class.467unsigned getWeight(const CodeGenRegBank &) const;468469// Populate a unique sorted list of units from a register set.470void buildRegUnitSet(const CodeGenRegBank &RegBank,471std::vector<unsigned> &RegUnits) const;472473CodeGenRegisterClass(CodeGenRegBank &, Record *R);474CodeGenRegisterClass(CodeGenRegisterClass &) = delete;475476// A key representing the parts of a register class used for forming477// sub-classes. Note the ordering provided by this key is not the same as478// the topological order used for the EnumValues.479struct Key {480const CodeGenRegister::Vec *Members;481RegSizeInfoByHwMode RSI;482483Key(const CodeGenRegister::Vec *M, const RegSizeInfoByHwMode &I)484: Members(M), RSI(I) {}485486Key(const CodeGenRegisterClass &RC)487: Members(&RC.getMembers()), RSI(RC.RSI) {}488489// Lexicographical order of (Members, RegSizeInfoByHwMode).490bool operator<(const Key &) const;491};492493// Create a non-user defined register class.494CodeGenRegisterClass(CodeGenRegBank &, StringRef Name, Key Props);495496// Called by CodeGenRegBank::CodeGenRegBank().497static void computeSubClasses(CodeGenRegBank &);498499// Get ordering value among register base classes.500std::optional<int> getBaseClassOrder() const {501if (TheDef && !TheDef->isValueUnset("BaseClassOrder"))502return TheDef->getValueAsInt("BaseClassOrder");503return {};504}505};506507// Register categories are used when we need to deterine the category a508// register falls into (GPR, vector, fixed, etc.) without having to know509// specific information about the target architecture.510class CodeGenRegisterCategory {511Record *TheDef;512std::string Name;513std::list<CodeGenRegisterClass *> Classes;514515public:516CodeGenRegisterCategory(CodeGenRegBank &, Record *R);517CodeGenRegisterCategory(CodeGenRegisterCategory &) = delete;518519// Return the Record that defined this class, or NULL if the class was520// created by TableGen.521Record *getDef() const { return TheDef; }522523std::string getName() const { return Name; }524std::list<CodeGenRegisterClass *> getClasses() const { return Classes; }525};526527// Register units are used to model interference and register pressure.528// Every register is assigned one or more register units such that two529// registers overlap if and only if they have a register unit in common.530//531// Normally, one register unit is created per leaf register. Non-leaf532// registers inherit the units of their sub-registers.533struct RegUnit {534// Weight assigned to this RegUnit for estimating register pressure.535// This is useful when equalizing weights in register classes with mixed536// register topologies.537unsigned Weight;538539// Each native RegUnit corresponds to one or two root registers. The full540// set of registers containing this unit can be computed as the union of541// these two registers and their super-registers.542const CodeGenRegister *Roots[2];543544// Index into RegClassUnitSets where we can find the list of UnitSets that545// contain this unit.546unsigned RegClassUnitSetsIdx;547// A register unit is artificial if at least one of its roots is548// artificial.549bool Artificial;550551RegUnit() : Weight(0), RegClassUnitSetsIdx(0), Artificial(false) {552Roots[0] = Roots[1] = nullptr;553}554555ArrayRef<const CodeGenRegister *> getRoots() const {556assert(!(Roots[1] && !Roots[0]) && "Invalid roots array");557return ArrayRef(Roots, !!Roots[0] + !!Roots[1]);558}559};560561// Each RegUnitSet is a sorted vector with a name.562struct RegUnitSet {563typedef std::vector<unsigned>::const_iterator iterator;564565std::string Name;566std::vector<unsigned> Units;567unsigned Weight = 0; // Cache the sum of all unit weights.568unsigned Order = 0; // Cache the sort key.569570RegUnitSet(std::string Name) : Name(Name) {}571};572573// Base vector for identifying TopoSigs. The contents uniquely identify a574// TopoSig, only computeSuperRegs needs to know how.575typedef SmallVector<unsigned, 16> TopoSigId;576577// CodeGenRegBank - Represent a target's registers and the relations between578// them.579class CodeGenRegBank {580SetTheory Sets;581582const CodeGenHwModes &CGH;583584std::deque<CodeGenSubRegIndex> SubRegIndices;585DenseMap<Record *, CodeGenSubRegIndex *> Def2SubRegIdx;586587CodeGenSubRegIndex *createSubRegIndex(StringRef Name, StringRef NameSpace);588589typedef std::map<SmallVector<CodeGenSubRegIndex *, 8>, CodeGenSubRegIndex *>590ConcatIdxMap;591ConcatIdxMap ConcatIdx;592593// Registers.594std::deque<CodeGenRegister> Registers;595StringMap<CodeGenRegister *> RegistersByName;596DenseMap<Record *, CodeGenRegister *> Def2Reg;597unsigned NumNativeRegUnits;598599std::map<TopoSigId, unsigned> TopoSigs;600601// Includes native (0..NumNativeRegUnits-1) and adopted register units.602SmallVector<RegUnit, 8> RegUnits;603604// Register classes.605std::list<CodeGenRegisterClass> RegClasses;606DenseMap<Record *, CodeGenRegisterClass *> Def2RC;607typedef std::map<CodeGenRegisterClass::Key, CodeGenRegisterClass *> RCKeyMap;608RCKeyMap Key2RC;609610// Register categories.611std::list<CodeGenRegisterCategory> RegCategories;612DenseMap<Record *, CodeGenRegisterCategory *> Def2RCat;613using RCatKeyMap =614std::map<CodeGenRegisterClass::Key, CodeGenRegisterCategory *>;615RCatKeyMap Key2RCat;616617// Remember each unique set of register units. Initially, this contains a618// unique set for each register class. Simliar sets are coalesced with619// pruneUnitSets and new supersets are inferred during computeRegUnitSets.620std::vector<RegUnitSet> RegUnitSets;621622// Map RegisterClass index to the index of the RegUnitSet that contains the623// class's units and any inferred RegUnit supersets.624//625// NOTE: This could grow beyond the number of register classes when we map626// register units to lists of unit sets. If the list of unit sets does not627// already exist for a register class, we create a new entry in this vector.628std::vector<std::vector<unsigned>> RegClassUnitSets;629630// Give each register unit set an order based on sorting criteria.631std::vector<unsigned> RegUnitSetOrder;632633// Keep track of synthesized definitions generated in TupleExpander.634std::vector<std::unique_ptr<Record>> SynthDefs;635636// Add RC to *2RC maps.637void addToMaps(CodeGenRegisterClass *);638639// Create a synthetic sub-class if it is missing.640CodeGenRegisterClass *getOrCreateSubClass(const CodeGenRegisterClass *RC,641const CodeGenRegister::Vec *Membs,642StringRef Name);643644// Infer missing register classes.645void computeInferredRegisterClasses();646void inferCommonSubClass(CodeGenRegisterClass *RC);647void inferSubClassWithSubReg(CodeGenRegisterClass *RC);648649void inferMatchingSuperRegClass(CodeGenRegisterClass *RC) {650inferMatchingSuperRegClass(RC, RegClasses.begin());651}652653void inferMatchingSuperRegClass(654CodeGenRegisterClass *RC,655std::list<CodeGenRegisterClass>::iterator FirstSubRegRC);656657// Iteratively prune unit sets.658void pruneUnitSets();659660// Compute a weight for each register unit created during getSubRegs.661void computeRegUnitWeights();662663// Create a RegUnitSet for each RegClass and infer superclasses.664void computeRegUnitSets();665666// Populate the Composite map from sub-register relationships.667void computeComposites();668669// Compute a lane mask for each sub-register index.670void computeSubRegLaneMasks();671672/// Computes a lane mask for each register unit enumerated by a physical673/// register.674void computeRegUnitLaneMasks();675676public:677CodeGenRegBank(RecordKeeper &, const CodeGenHwModes &);678CodeGenRegBank(CodeGenRegBank &) = delete;679680SetTheory &getSets() { return Sets; }681682const CodeGenHwModes &getHwModes() const { return CGH; }683684// Sub-register indices. The first NumNamedIndices are defined by the user685// in the .td files. The rest are synthesized such that all sub-registers686// have a unique name.687const std::deque<CodeGenSubRegIndex> &getSubRegIndices() const {688return SubRegIndices;689}690691// Find a SubRegIndex from its Record def or add to the list if it does692// not exist there yet.693CodeGenSubRegIndex *getSubRegIdx(Record *);694695// Find a SubRegIndex from its Record def.696const CodeGenSubRegIndex *findSubRegIdx(const Record *Def) const;697698// Find or create a sub-register index representing the A+B composition.699CodeGenSubRegIndex *getCompositeSubRegIndex(CodeGenSubRegIndex *A,700CodeGenSubRegIndex *B);701702// Find or create a sub-register index representing the concatenation of703// non-overlapping sibling indices.704CodeGenSubRegIndex *705getConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex *, 8> &,706const CodeGenHwModes &CGH);707708const std::deque<CodeGenRegister> &getRegisters() const { return Registers; }709710const StringMap<CodeGenRegister *> &getRegistersByName() const {711return RegistersByName;712}713714// Find a register from its Record def.715CodeGenRegister *getReg(Record *);716717// Get a Register's index into the Registers array.718unsigned getRegIndex(const CodeGenRegister *Reg) const {719return Reg->EnumValue - 1;720}721722// Return the number of allocated TopoSigs. The first TopoSig representing723// leaf registers is allocated number 0.724unsigned getNumTopoSigs() const { return TopoSigs.size(); }725726// Find or create a TopoSig for the given TopoSigId.727// This function is only for use by CodeGenRegister::computeSuperRegs().728// Others should simply use Reg->getTopoSig().729unsigned getTopoSig(const TopoSigId &Id) {730return TopoSigs.insert(std::pair(Id, TopoSigs.size())).first->second;731}732733// Create a native register unit that is associated with one or two root734// registers.735unsigned newRegUnit(CodeGenRegister *R0, CodeGenRegister *R1 = nullptr) {736RegUnit &RU = RegUnits.emplace_back();737RU.Roots[0] = R0;738RU.Roots[1] = R1;739RU.Artificial = R0->Artificial;740if (R1)741RU.Artificial |= R1->Artificial;742return RegUnits.size() - 1;743}744745// Create a new non-native register unit that can be adopted by a register746// to increase its pressure. Note that NumNativeRegUnits is not increased.747unsigned newRegUnit(unsigned Weight) {748RegUnit &RU = RegUnits.emplace_back();749RU.Weight = Weight;750return RegUnits.size() - 1;751}752753// Native units are the singular unit of a leaf register. Register aliasing754// is completely characterized by native units. Adopted units exist to give755// register additional weight but don't affect aliasing.756bool isNativeUnit(unsigned RUID) const { return RUID < NumNativeRegUnits; }757758unsigned getNumNativeRegUnits() const { return NumNativeRegUnits; }759760RegUnit &getRegUnit(unsigned RUID) { return RegUnits[RUID]; }761const RegUnit &getRegUnit(unsigned RUID) const { return RegUnits[RUID]; }762763std::list<CodeGenRegisterClass> &getRegClasses() { return RegClasses; }764765const std::list<CodeGenRegisterClass> &getRegClasses() const {766return RegClasses;767}768769std::list<CodeGenRegisterCategory> &getRegCategories() {770return RegCategories;771}772773const std::list<CodeGenRegisterCategory> &getRegCategories() const {774return RegCategories;775}776777// Find a register class from its def.778CodeGenRegisterClass *getRegClass(const Record *) const;779780/// getRegisterClassForRegister - Find the register class that contains the781/// specified physical register. If the register is not in a register782/// class, return null. If the register is in multiple classes, and the783/// classes have a superset-subset relationship and the same set of types,784/// return the superclass. Otherwise return null.785const CodeGenRegisterClass *getRegClassForRegister(Record *R);786787// Analog of TargetRegisterInfo::getMinimalPhysRegClass. Unlike788// getRegClassForRegister, this tries to find the smallest class containing789// the physical register. If \p VT is specified, it will only find classes790// with a matching type791const CodeGenRegisterClass *792getMinimalPhysRegClass(Record *RegRecord, ValueTypeByHwMode *VT = nullptr);793794// Get the sum of unit weights.795unsigned getRegUnitSetWeight(const std::vector<unsigned> &Units) const {796unsigned Weight = 0;797for (unsigned Unit : Units)798Weight += getRegUnit(Unit).Weight;799return Weight;800}801802unsigned getRegSetIDAt(unsigned Order) const {803return RegUnitSetOrder[Order];804}805806const RegUnitSet &getRegSetAt(unsigned Order) const {807return RegUnitSets[RegUnitSetOrder[Order]];808}809810// Increase a RegUnitWeight.811void increaseRegUnitWeight(unsigned RUID, unsigned Inc) {812getRegUnit(RUID).Weight += Inc;813}814815// Get the number of register pressure dimensions.816unsigned getNumRegPressureSets() const { return RegUnitSets.size(); }817818// Get a set of register unit IDs for a given dimension of pressure.819const RegUnitSet &getRegPressureSet(unsigned Idx) const {820return RegUnitSets[Idx];821}822823// The number of pressure set lists may be larget than the number of824// register classes if some register units appeared in a list of sets that825// did not correspond to an existing register class.826unsigned getNumRegClassPressureSetLists() const {827return RegClassUnitSets.size();828}829830// Get a list of pressure set IDs for a register class. Liveness of a831// register in this class impacts each pressure set in this list by the832// weight of the register. An exact solution requires all registers in a833// class to have the same class, but it is not strictly guaranteed.834ArrayRef<unsigned> getRCPressureSetIDs(unsigned RCIdx) const {835return RegClassUnitSets[RCIdx];836}837838// Computed derived records such as missing sub-register indices.839void computeDerivedInfo();840841// Compute the set of registers completely covered by the registers in Regs.842// The returned BitVector will have a bit set for each register in Regs,843// all sub-registers, and all super-registers that are covered by the844// registers in Regs.845//846// This is used to compute the mask of call-preserved registers from a list847// of callee-saves.848BitVector computeCoveredRegisters(ArrayRef<Record *> Regs);849850// Bit mask of lanes that cover their registers. A sub-register index whose851// LaneMask is contained in CoveringLanes will be completely covered by852// another sub-register with the same or larger lane mask.853LaneBitmask CoveringLanes;854855// Helper function for printing debug information. Handles artificial856// (non-native) reg units.857void printRegUnitName(unsigned Unit) const;858};859860} // end namespace llvm861862#endif // LLVM_UTILS_TABLEGEN_CODEGENREGISTERS_H863864865