[llvm] [ValueTypes] Automatically assign value numbers (NFC) (PR #169071)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 14:52:52 PST 2025
================
@@ -11,11 +11,12 @@
//
//===----------------------------------------------------------------------===//
-class ValueType<int size, int value> {
+class ValueType<int size, int value = -1> {
string Namespace = "MVT";
string LLVMName = NAME;
int Size = size;
- int Value = value;
+ int Value = !if(!ne(value, -1), value,
+ !add(!size(!instances<ValueType>()), 1));
----------------
AlexMaclean wrote:
Yep. This is pretty inefficient, but there doesn't seem to be a better way to implement this in table-gen.
I tested like this:
```
git checkout main
echo "main"
time ../cmake/bin/llvm-tblgen llvm/include/llvm/CodeGen/ValueTypes.td &> /dev/null
git checkout dev/amaclean/td-vts-indices
echo "dev/amaclean/td-vts-indices"
time ../cmake/bin/llvm-tblgen llvm/include/llvm/CodeGen/ValueTypes.td &> /dev/null
```
Here are the results:
```
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
main
real 0m0.021s
user 0m0.018s
sys 0m0.002s
Switched to branch 'dev/amaclean/td-vts-indices'
dev/amaclean/td-vts-indices
real 0m0.094s
user 0m0.092s
sys 0m0.001s
```
So, when isolating ValueTypes.td, it makes things nearly 5X slower (which is pretty bad) but we're still only talking about less then 1/10th of a second which seems like it will be pretty negligible on the scale of a complete LLVM build.
https://github.com/llvm/llvm-project/pull/169071
More information about the llvm-commits
mailing list