[llvm] [TableGen] Allow AsmWriter to generate uint64_t tables. NFC. (PR #227641)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 03:15:06 PDT 2026
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/227641
Each OpInfo entry in the generated AMDGPUInstPrinter::getMnemonic
carries 8 bytes of data. Previously GenAsmWriter would split that into
two uint32_t tables for no good reason. Generating a single uint64_t
table makes for shorter output and slightly better generated code.
>From 1a4bbf3fa433a8c69158633e72df7b4e11f2761b Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at gmail.com>
Date: Mon, 11 Jan 2016 05:13:41 +0000
Subject: [PATCH] [TableGen] Allow AsmWriter to generate uint64_t tables. NFC.
Each OpInfo entry in the generated AMDGPUInstPrinter::getMnemonic
carries 8 bytes of data. Previously GenAsmWriter would split that into
two uint32_t tables for no good reason. Generating a single uint64_t
table makes for shorter output and slightly better generated code.
---
llvm/utils/TableGen/AsmWriterEmitter.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index f3e04bb0f0849..c2d2fa574388b 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -462,15 +462,16 @@ void AsmWriterEmitter::EmitGetMnemonic(
BitsOS << " uint" << ((BitsLeft < (OpcodeInfoBits - 32)) ? 64 : 32)
<< "_t Bits = 0;\n";
while (BytesNeeded != 0) {
- // Figure out how big this table section needs to be, but no bigger than 4.
- unsigned TableSize = std::min(llvm::bit_floor(BytesNeeded), 4u);
+ // Figure out how big this table section needs to be.
+ unsigned TableSize = llvm::bit_floor(BytesNeeded);
BytesNeeded -= TableSize;
TableSize *= 8; // Convert to bits;
- uint64_t Mask = (1ULL << TableSize) - 1;
+ uint64_t Mask = maskTrailingOnes<uint64_t>(TableSize);
O << " static const uint" << TableSize << "_t OpInfo" << Table
<< "[] = {\n";
+ StringRef Suffix = TableSize == 64 ? "ULL" : "U";
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
- O << " " << ((OpcodeInfo[i] >> Shift) & Mask) << "U,\t// "
+ O << " " << ((OpcodeInfo[i] >> Shift) & Mask) << Suffix << ",\t// "
<< NumberedInstructions[i]->getName() << '\n';
}
O << " };\n\n";
More information about the llvm-commits
mailing list