// sub-register in SubRegs.
uint32_t SubRegIndices;
- // Points to the list of register units. The low bits hold the first regunit
- // number, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
+ // RegUnits - Points to the list of register units. The low 4 bits holds the
+ // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator.
uint32_t RegUnits;
/// Index into list with lane mask sequences. The sequence contains a lanemask
unsigned NumClasses; // Number of entries in the array
unsigned NumRegUnits; // Number of regunits.
const MCPhysReg (*RegUnitRoots)[2]; // Pointer to regunit root table.
- const int16_t *DiffLists; // Pointer to the difflists array
+ const MCPhysReg *DiffLists; // Pointer to the difflists array
const LaneBitmask *RegUnitMaskSequences; // Pointer to lane mask sequences
// for register units.
const char *RegStrings; // Pointer to the string table.
/// Don't use this class directly, use one of the specialized sub-classes
/// defined below.
class DiffListIterator {
- unsigned Val = 0;
- const int16_t *List = nullptr;
+ uint16_t Val = 0;
+ const MCPhysReg *List = nullptr;
protected:
/// Create an invalid iterator. Call init() to point to something useful.
DiffListIterator() = default;
- /// Point the iterator to InitVal, decoding subsequent values from DiffList.
- void init(unsigned InitVal, const int16_t *DiffList) {
+ /// init - Point the iterator to InitVal, decoding subsequent values from
+ /// DiffList. The iterator will initially point to InitVal, sub-classes are
+ /// responsible for skipping the seed value if it is not part of the list.
+ void init(MCPhysReg InitVal, const MCPhysReg *DiffList) {
Val = InitVal;
List = DiffList;
}
+ /// advance - Move to the next list position, return the applied
+ /// differential. This function does not detect the end of the list, that
+ /// is the caller's responsibility (by checking for a 0 return value).
+ MCRegister advance() {
+ assert(isValid() && "Cannot move off the end of the list.");
+ MCPhysReg D = *List++;
+ Val += D;
+ return D;
+ }
+
public:
/// isValid - returns true if this iterator is not yet at the end.
bool isValid() const { return List; }
/// Pre-increment to move to the next position.
void operator++() {
- assert(isValid() && "Cannot move off the end of the list.");
- int16_t D = *List++;
- Val += D;
// The end of the list is encoded as a 0 differential.
- if (!D)
+ if (!advance())
List = nullptr;
}
mc_difflist_iterator(MCRegisterInfo::DiffListIterator Iter) : Iter(Iter) {}
// Allow conversion between instantiations where valid.
- mc_difflist_iterator(unsigned InitVal, const int16_t *DiffList) {
- Iter.init(InitVal, DiffList);
+ mc_difflist_iterator(MCRegister Reg, const MCPhysReg *DiffList) {
+ Iter.init(Reg, DiffList);
Val = *Iter;
}
/// Initialize MCRegisterInfo, called by TableGen
/// auto-generated routines. *DO NOT USE*.
void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR, unsigned RA,
- unsigned PC, const MCRegisterClass *C, unsigned NC,
- const MCPhysReg (*RURoots)[2], unsigned NRU,
- const int16_t *DL, const LaneBitmask *RUMS,
- const char *Strings, const char *ClassStrings,
- const uint16_t *SubIndices, unsigned NumIndices,
+ unsigned PC,
+ const MCRegisterClass *C, unsigned NC,
+ const MCPhysReg (*RURoots)[2],
+ unsigned NRU,
+ const MCPhysReg *DL,
+ const LaneBitmask *RUMS,
+ const char *Strings,
+ const char *ClassStrings,
+ const uint16_t *SubIndices,
+ unsigned NumIndices,
const SubRegCoveredBits *SubIdxRanges,
const uint16_t *RET) {
Desc = D;
// MCRegUnitIterator enumerates a list of register units for Reg. The list is
// in ascending numerical order.
class MCRegUnitIterator : public MCRegisterInfo::DiffListIterator {
- // The value must be kept in sync with RegisterInfoEmitter.cpp.
- static constexpr unsigned RegUnitBits = 12;
-
public:
/// MCRegUnitIterator - Create an iterator that traverses the register units
/// in Reg.
assert(MCRegister::isPhysicalRegister(Reg.id()));
// Decode the RegUnits MCRegisterDesc field.
unsigned RU = MCRI->get(Reg).RegUnits;
- unsigned FirstRU = RU & ((1u << RegUnitBits) - 1);
- unsigned Offset = RU >> RegUnitBits;
- init(FirstRU, MCRI->DiffLists + Offset);
+ unsigned Scale = RU & 15;
+ unsigned Offset = RU >> 4;
+
+ // Initialize the iterator to Reg * Scale, and the List pointer to
+ // DiffLists + Offset.
+ init(Reg * Scale, MCRI->DiffLists + Offset);
+
+ // That may not be a valid unit, we need to advance by one to get the real
+ // unit number. The first differential can be 0 which would normally
+ // terminate the list, but since we know every register has at least one
+ // unit, we can allow a 0 differential here.
+ advance();
}
MCRegUnitIterator &operator++() {
// The initial value depends on the specific list. The list is terminated by a
// 0 differential which means we can't encode repeated elements.
-typedef SmallVector<int16_t, 4> DiffVec;
+typedef SmallVector<uint16_t, 4> DiffVec;
typedef SmallVector<LaneBitmask, 4> MaskVec;
-// Fills V with differentials between every two consecutive elements of List.
-static DiffVec &diffEncode(DiffVec &V, SparseBitVector<> List) {
+// Differentially encode a sequence of numbers into V. The starting value and
+// terminating 0 are not added to V, so it will have the same size as List.
+static
+DiffVec &diffEncode(DiffVec &V, unsigned InitVal, SparseBitVector<> List) {
assert(V.empty() && "Clear DiffVec before diffEncode.");
- SparseBitVector<>::iterator I = List.begin(), E = List.end();
- unsigned Val = *I;
- while (++I != E) {
- unsigned Cur = *I;
+ uint16_t Val = uint16_t(InitVal);
+
+ for (uint16_t Cur : List) {
V.push_back(Cur - Val);
Val = Cur;
}
static
DiffVec &diffEncode(DiffVec &V, unsigned InitVal, Iter Begin, Iter End) {
assert(V.empty() && "Clear DiffVec before diffEncode.");
- unsigned Val = InitVal;
+ uint16_t Val = uint16_t(InitVal);
for (Iter I = Begin; I != End; ++I) {
- unsigned Cur = (*I)->EnumValue;
+ uint16_t Cur = (*I)->EnumValue;
V.push_back(Cur - Val);
Val = Cur;
}
return V;
}
-static void printDiff16(raw_ostream &OS, int16_t Val) { OS << Val; }
+static void printDiff16(raw_ostream &OS, uint16_t Val) {
+ OS << Val;
+}
static void printMask(raw_ostream &OS, LaneBitmask Val) {
OS << "LaneBitmask(0x" << PrintLaneMask(Val) << ')';
SmallVector<DiffVec, 4> SubRegLists(Regs.size());
SmallVector<DiffVec, 4> SuperRegLists(Regs.size());
SmallVector<DiffVec, 4> RegUnitLists(Regs.size());
+ SmallVector<unsigned, 4> RegUnitInitScale(Regs.size());
// List of lane masks accompanying register unit sequences.
SequenceToOffsetTable<MaskVec> LaneMaskSeqs;
SuperRegList.end());
DiffSeqs.add(SuperRegLists[i]);
- const SparseBitVector<> &RUs = Reg.getNativeRegUnits();
- DiffSeqs.add(diffEncode(RegUnitLists[i], RUs));
+ // Differentially encode the register unit list, seeded by register number.
+ // First compute a scale factor that allows more diff-lists to be reused:
+ //
+ // D0 -> (S0, S1)
+ // D1 -> (S2, S3)
+ //
+ // A scale factor of 2 allows D0 and D1 to share a diff-list. The initial
+ // value for the differential decoder is the register number multiplied by
+ // the scale.
+ //
+ // Check the neighboring registers for arithmetic progressions.
+ unsigned ScaleA = ~0u, ScaleB = ~0u;
+ SparseBitVector<> RUs = Reg.getNativeRegUnits();
+ if (I != Regs.begin() &&
+ std::prev(I)->getNativeRegUnits().count() == RUs.count())
+ ScaleB = *RUs.begin() - *std::prev(I)->getNativeRegUnits().begin();
+ if (std::next(I) != Regs.end() &&
+ std::next(I)->getNativeRegUnits().count() == RUs.count())
+ ScaleA = *std::next(I)->getNativeRegUnits().begin() - *RUs.begin();
+ unsigned Scale = std::min(ScaleB, ScaleA);
+ // Default the scale to 0 if it can't be encoded in 4 bits.
+ if (Scale >= 16)
+ Scale = 0;
+ RegUnitInitScale[i] = Scale;
+ DiffSeqs.add(diffEncode(RegUnitLists[i], Scale * Reg.EnumValue, RUs));
const auto &RUMasks = Reg.getRegUnitLaneMasks();
MaskVec &LaneMaskVec = RegUnitLaneMasks[i];
const std::string &TargetName = std::string(Target.getName());
// Emit the shared table of differential lists.
- OS << "extern const int16_t " << TargetName << "RegDiffLists[] = {\n";
+ OS << "extern const MCPhysReg " << TargetName << "RegDiffLists[] = {\n";
DiffSeqs.emit(OS, printDiff16);
OS << "};\n\n";
// Emit the register descriptors now.
i = 0;
for (const auto &Reg : Regs) {
- unsigned FirstRU = Reg.getNativeRegUnits().find_first();
- unsigned Offset = DiffSeqs.get(RegUnitLists[i]);
- // The value must be kept in sync with MCRegisterInfo.h.
- constexpr unsigned RegUnitBits = 12;
- assert(isUInt<RegUnitBits>(FirstRU) && "Too many regunits");
- assert(isUInt<32 - RegUnitBits>(Offset) && "Offset is too big");
OS << " { " << RegStrings.get(std::string(Reg.getName())) << ", "
<< DiffSeqs.get(SubRegLists[i]) << ", " << DiffSeqs.get(SuperRegLists[i])
<< ", " << SubRegIdxSeqs.get(SubRegIdxLists[i]) << ", "
- << (Offset << RegUnitBits | FirstRU) << ", "
+ << (DiffSeqs.get(RegUnitLists[i]) * 16 + RegUnitInitScale[i]) << ", "
<< LaneMaskSeqs.get(RegUnitLaneMasks[i]) << " },\n";
++i;
}
// Emit the constructor of the class...
OS << "extern const MCRegisterDesc " << TargetName << "RegDesc[];\n";
- OS << "extern const int16_t " << TargetName << "RegDiffLists[];\n";
+ OS << "extern const MCPhysReg " << TargetName << "RegDiffLists[];\n";
OS << "extern const LaneBitmask " << TargetName << "LaneMaskLists[];\n";
OS << "extern const char " << TargetName << "RegStrings[];\n";
OS << "extern const char " << TargetName << "RegClassStrings[];\n";