[llvm] e2c74aa - [TableGen][MVT] Lower the maximum 16-bit MVT from 16384 to 511. (#101401)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 31 18:52:32 PDT 2024
Author: Craig Topper
Date: 2024-07-31T18:52:28-07:00
New Revision: e2c74aa535752cd6cf098731608d26275d1e40ac
URL: https://github.com/llvm/llvm-project/commit/e2c74aa535752cd6cf098731608d26275d1e40ac
DIFF: https://github.com/llvm/llvm-project/commit/e2c74aa535752cd6cf098731608d26275d1e40ac.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/CodeGen/ValueTypes.td
llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
llvm/utils/TableGen/VTEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index 4636a2543b56a..0883f597dabc1 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -289,34 +289,34 @@ def aarch64svcount
def spirvbuiltin : ValueType<0, 200>; // SPIR-V's builtin type
let isNormalValueType = false in {
-def token : ValueType<0, 16376>; // TokenTy
-def MetadataVT : ValueType<0, 16377> { // Metadata
+def token : ValueType<0, 504>; // TokenTy
+def MetadataVT : ValueType<0, 505> { // Metadata
let LLVMName = "Metadata";
}
// Pseudo valuetype mapped to the current pointer size to any address space.
// Should only be used in TableGen.
-def iPTRAny : VTAny<16378>;
+def iPTRAny : VTAny<506>;
// Pseudo valuetype to represent "vector of any size"
// Should only be used in TableGen.
-def vAny : VTAny<16379>;
+def vAny : VTAny<507>;
// Pseudo valuetype to represent "float of any format"
// Should only be used in TableGen.
-def fAny : VTAny<16380>;
+def fAny : VTAny<508>;
// Pseudo valuetype to represent "integer of any bit width"
// Should only be used in TableGen.
-def iAny : VTAny<16381>;
+def iAny : VTAny<509>;
// Pseudo valuetype mapped to the current pointer size.
// Should only be used in TableGen.
-def iPTR : ValueType<0, 16382>;
+def iPTR : ValueType<0, 510>;
// Pseudo valuetype to represent "any type of any size".
// Should only be used in TableGen.
-def Any : VTAny<16383>;
+def Any : VTAny<511>;
} // isNormalValueType = false
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
index b4de20bb13184..d8df7427836c9 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
@@ -53,10 +53,7 @@ using TreePatternNodePtr = IntrusiveRefCntPtr<TreePatternNode>;
/// To reduce the allocations even further, make MachineValueTypeSet own
/// the storage and use std::array as the bit container.
struct MachineValueTypeSet {
- static_assert(std::is_same<std::underlying_type_t<MVT::SimpleValueType>,
- uint16_t>::value,
- "Change uint16_t here to the SimpleValueType's type");
- static unsigned constexpr Capacity = std::numeric_limits<uint16_t>::max() + 1;
+ static unsigned constexpr Capacity = 512;
using WordType = uint64_t;
static unsigned constexpr WordWidth = CHAR_BIT * sizeof(WordType);
static unsigned constexpr NumWords = Capacity / WordWidth;
@@ -84,9 +81,11 @@ struct MachineValueTypeSet {
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
unsigned count(MVT T) const {
+ assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
return (Words[T.SimpleTy / WordWidth] >> (T.SimpleTy % WordWidth)) & 1;
}
std::pair<MachineValueTypeSet &, bool> insert(MVT T) {
+ assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
bool V = count(T.SimpleTy);
Words[T.SimpleTy / WordWidth] |= WordType(1) << (T.SimpleTy % WordWidth);
return {*this, V};
@@ -98,6 +97,7 @@ struct MachineValueTypeSet {
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
void erase(MVT T) {
+ assert(T.SimpleTy < Capacity && "Capacity needs to be enlarged");
Words[T.SimpleTy / WordWidth] &= ~(WordType(1) << (T.SimpleTy % WordWidth));
}
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 79dbc37bb0b12..eb58148e4e364 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -79,7 +79,7 @@ static void VTtoGetLLVMTyString(raw_ostream &OS, const Record *VT) {
void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
- std::vector<const Record *> VTsByNumber{16384};
+ std::vector<const Record *> VTsByNumber{512};
auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
for (auto *VT : ValueTypes) {
auto Number = VT->getValueAsInt("Value");
More information about the llvm-commits
mailing list