[llvm] e80d2ca - [TableGen] Emit static const globals in getOperandType
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 00:57:19 PST 2023
Author: Michael Liao
Date: 2023-02-22T03:56:55-05:00
New Revision: e80d2cad349117fc49b790b71234c7b9293ec86e
URL: https://github.com/llvm/llvm-project/commit/e80d2cad349117fc49b790b71234c7b9293ec86e
DIFF: https://github.com/llvm/llvm-project/commit/e80d2cad349117fc49b790b71234c7b9293ec86e.diff
LOG: [TableGen] Emit static const globals in getOperandType
- That saves the overhead of operand type querying.
Added:
Modified:
llvm/test/TableGen/get-operand-type.td
llvm/utils/TableGen/InstrInfoEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/get-operand-type.td b/llvm/test/TableGen/get-operand-type.td
index a8d96e25b2899..6ebda5cffe8af 100644
--- a/llvm/test/TableGen/get-operand-type.td
+++ b/llvm/test/TableGen/get-operand-type.td
@@ -46,7 +46,8 @@ def InstC : Instruction {
}
// CHECK: #ifdef GET_INSTRINFO_OPERAND_TYPE
-// CHECK: OpcodeOperandTypes[] = {
+// CHECK: static const uint{{.*}}_t Offsets[] = {
+// CHECK: static const {{.*}} OpcodeOperandTypes[] = {
// CHECK: /* InstA */
// CHECK-NEXT: OpA, OpB, i32imm,
// CHECK-NEXT: /* InstB */
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 14ee24c15a65d..4eef1fef2a91e 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -419,8 +419,7 @@ void InstrInfoEmitter::emitOperandTypeMappings(
// Size the unsigned integer offset to save space.
assert(OperandRecords.size() <= UINT32_MAX &&
"Too many operands for offset table");
- OS << ((OperandRecords.size() <= UINT16_MAX) ? " const uint16_t"
- : " const uint32_t");
+ OS << " static const " << getMinimalTypeForRange(OperandRecords.size());
OS << " Offsets[] = {\n";
for (int I = 0, E = OperandOffsets.size(); I != E; ++I) {
OS << " /* " << getInstrName(I) << " */\n";
@@ -436,7 +435,8 @@ void InstrInfoEmitter::emitOperandTypeMappings(
assert(EnumVal <= INT16_MAX &&
"Too many operand types for operand types table");
OS << "\n using namespace OpTypes;\n";
- OS << ((EnumVal <= INT8_MAX) ? " const int8_t" : " const int16_t");
+ OS << " static";
+ OS << ((EnumVal <= INT8_MAX) ? " const int8_t" : " const int16_t");
OS << " OpcodeOperandTypes[] = {\n ";
for (int I = 0, E = OperandRecords.size(), CurOffset = 0; I != E; ++I) {
// We print each Opcode's operands in its own row.
More information about the llvm-commits
mailing list