Skip to content

Commit ecb0daa

Browse files
authored
[NFC][LLVM][TableGen] Eliminate inheritance from std::vector (llvm#136573)
1 parent cc6def4 commit ecb0daa

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,32 @@ typedef std::vector<FixupList> FixupScopeList;
127127
typedef SmallSetVector<CachedHashString, 16> PredicateSet;
128128
typedef SmallSetVector<CachedHashString, 16> DecoderSet;
129129

130-
struct DecoderTable : public std::vector<uint8_t> {
130+
class DecoderTable {
131+
public:
132+
DecoderTable() { Data.reserve(16384); }
133+
134+
void clear() { Data.clear(); }
135+
void push_back(uint8_t Item) { Data.push_back(Item); }
136+
size_t size() const { return Data.size(); }
137+
const uint8_t *data() const { return Data.data(); }
138+
139+
using const_iterator = std::vector<uint8_t>::const_iterator;
140+
const_iterator begin() const { return Data.begin(); }
141+
const_iterator end() const { return Data.end(); }
142+
131143
// Insert a ULEB128 encoded value into the table.
132144
void insertULEB128(uint64_t Value) {
133145
// Encode and emit the value to filter against.
134146
uint8_t Buffer[16];
135147
unsigned Len = encodeULEB128(Value, Buffer);
136-
insert(end(), Buffer, Buffer + Len);
148+
Data.insert(Data.end(), Buffer, Buffer + Len);
137149
}
138150

139151
// Insert space for `NumToSkip` and return the position
140152
// in the table for patching.
141153
size_t insertNumToSkip() {
142-
size_t Size = size();
143-
insert(end(), getNumToSkipInBytes(), 0);
154+
size_t Size = Data.size();
155+
Data.insert(Data.end(), getNumToSkipInBytes(), 0);
144156
return Size;
145157
}
146158

@@ -156,11 +168,14 @@ struct DecoderTable : public std::vector<uint8_t> {
156168
PrintFatalError(
157169
"disassembler decoding table too large, try --large-decoder-table");
158170

159-
(*this)[FixupIdx] = static_cast<uint8_t>(Delta);
160-
(*this)[FixupIdx + 1] = static_cast<uint8_t>(Delta >> 8);
171+
Data[FixupIdx] = static_cast<uint8_t>(Delta);
172+
Data[FixupIdx + 1] = static_cast<uint8_t>(Delta >> 8);
161173
if (getNumToSkipInBytes() == 3)
162-
(*this)[FixupIdx + 2] = static_cast<uint8_t>(Delta >> 16);
174+
Data[FixupIdx + 2] = static_cast<uint8_t>(Delta >> 16);
163175
}
176+
177+
private:
178+
std::vector<uint8_t> Data;
164179
};
165180

166181
struct DecoderTableInfo {
@@ -2517,7 +2532,6 @@ namespace {
25172532
// decoders to give more opportunities for uniqueing.
25182533
TableInfo.Table.clear();
25192534
TableInfo.FixupStack.clear();
2520-
TableInfo.Table.reserve(16384);
25212535
TableInfo.FixupStack.emplace_back();
25222536
FC.emitTableEntries(TableInfo);
25232537
// Any NumToSkip fixups in the top level scope can resolve to the

0 commit comments

Comments
 (0)