Skip to content

Commit e2c74aa

Browse files
authored
[TableGen][MVT] Lower the maximum 16-bit MVT from 16384 to 511. (#101401)
MachineValueTypeSet in tablegen allocates an array with a bit per MVT. This used to be 256 bits, with the introduction of 16-bit MVT it ballooned to 65536 bits. I suspect this is increasing the memory usage of many of the data structures used by CodeGenDAGPatterns. Since we don't need the full 16-bit range yet, this patch proposes lowering the maximum MVT to 511 and using only 512 bits for MachineValueTypeSet's storage.
1 parent 87af9ee commit e2c74aa

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

llvm/include/llvm/CodeGen/ValueTypes.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,34 +289,34 @@ def aarch64svcount
289289
def spirvbuiltin : ValueType<0, 200>; // SPIR-V's builtin type
290290

291291
let isNormalValueType = false in {
292-
def token : ValueType<0, 16376>; // TokenTy
293-
def MetadataVT : ValueType<0, 16377> { // Metadata
292+
def token : ValueType<0, 504>; // TokenTy
293+
def MetadataVT : ValueType<0, 505> { // Metadata
294294
let LLVMName = "Metadata";
295295
}
296296

297297
// Pseudo valuetype mapped to the current pointer size to any address space.
298298
// Should only be used in TableGen.
299-
def iPTRAny : VTAny<16378>;
299+
def iPTRAny : VTAny<506>;
300300

301301
// Pseudo valuetype to represent "vector of any size"
302302
// Should only be used in TableGen.
303-
def vAny : VTAny<16379>;
303+
def vAny : VTAny<507>;
304304

305305
// Pseudo valuetype to represent "float of any format"
306306
// Should only be used in TableGen.
307-
def fAny : VTAny<16380>;
307+
def fAny : VTAny<508>;
308308

309309
// Pseudo valuetype to represent "integer of any bit width"
310310
// Should only be used in TableGen.
311-
def iAny : VTAny<16381>;
311+
def iAny : VTAny<509>;
312312

313313
// Pseudo valuetype mapped to the current pointer size.
314314
// Should only be used in TableGen.
315-
def iPTR : ValueType<0, 16382>;
315+
def iPTR : ValueType<0, 510>;
316316

317317
// Pseudo valuetype to represent "any type of any size".
318318
// Should only be used in TableGen.
319-
def Any : VTAny<16383>;
319+
def Any : VTAny<511>;
320320

321321
} // isNormalValueType = false
322322

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ using TreePatternNodePtr = IntrusiveRefCntPtr<TreePatternNode>;
5353
/// To reduce the allocations even further, make MachineValueTypeSet own
5454
/// the storage and use std::array as the bit container.
5555
struct MachineValueTypeSet {
56-
static_assert(std::is_same<std::underlying_type_t<MVT::SimpleValueType>,
57-
uint16_t>::value,
58-
"Change uint16_t here to the SimpleValueType's type");
59-
static unsigned constexpr Capacity = std::numeric_limits<uint16_t>::max() + 1;
56+
static unsigned constexpr Capacity = 512;
6057
using WordType = uint64_t;
6158
static unsigned constexpr WordWidth = CHAR_BIT * sizeof(WordType);
6259
static unsigned constexpr NumWords = Capacity / WordWidth;
@@ -84,9 +81,11 @@ struct MachineValueTypeSet {
8481
}
8582
LLVM_ATTRIBUTE_ALWAYS_INLINE
8683
unsigned count(MVT T) const {
84+
assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
8785
return (Words[T.SimpleTy / WordWidth] >> (T.SimpleTy % WordWidth)) & 1;
8886
}
8987
std::pair<MachineValueTypeSet &, bool> insert(MVT T) {
88+
assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
9089
bool V = count(T.SimpleTy);
9190
Words[T.SimpleTy / WordWidth] |= WordType(1) << (T.SimpleTy % WordWidth);
9291
return {*this, V};
@@ -98,6 +97,7 @@ struct MachineValueTypeSet {
9897
}
9998
LLVM_ATTRIBUTE_ALWAYS_INLINE
10099
void erase(MVT T) {
100+
assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
101101
Words[T.SimpleTy / WordWidth] &= ~(WordType(1) << (T.SimpleTy % WordWidth));
102102
}
103103

llvm/utils/TableGen/VTEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void VTtoGetLLVMTyString(raw_ostream &OS, const Record *VT) {
7979
void VTEmitter::run(raw_ostream &OS) {
8080
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
8181

82-
std::vector<const Record *> VTsByNumber{16384};
82+
std::vector<const Record *> VTsByNumber{512};
8383
auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
8484
for (auto *VT : ValueTypes) {
8585
auto Number = VT->getValueAsInt("Value");

0 commit comments

Comments
 (0)