[llvm] [TableGen] Fix OperandMap table size (PR #125424)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 2 09:23:03 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Mariusz Sikora (mariusz-sikora-at-amd)
<details>
<summary>Changes</summary>
- add missing value for OPERAND_LAST type. If function 'getNamedOperandIdx' is called with NamedIdx=OPERAND_LAST then we are accessing first element of next row in 2dim table.
- in most cases this will work unnoticed because 2dim OperandMap is sparse with most elements set to '-1'.
---
Full diff: https://github.com/llvm/llvm-project/pull/125424.diff
1 Files Affected:
- (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+4-3)
``````````diff
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 97c00ad4924197..ecf30c95f4b76b 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -300,8 +300,8 @@ void InstrInfoEmitter::emitOperandNameMappings(
assert(MaxOperandNo <= INT16_MAX &&
"Too many operands for the operand name -> index table");
StringRef Type = MaxOperandNo <= INT8_MAX ? "int8_t" : "int16_t";
- OS << " static constexpr " << Type << " OperandMap[][" << NumOperandNames
- << "] = {\n";
+ OS << " static constexpr " << Type << " OperandMap[]["
+ << NumOperandNames + 1 << "] = {\n";
for (const auto &Entry : OperandMap) {
const std::map<unsigned, unsigned> &OpList = Entry.first;
@@ -311,7 +311,8 @@ void InstrInfoEmitter::emitOperandNameMappings(
auto Iter = OpList.find(ID);
OS << (Iter != OpList.end() ? (int)Iter->second : -1) << ", ";
}
- OS << "},\n";
+ // value for OPERAND_LAST
+ OS << "-1 },\n";
}
OS << " };\n";
``````````
</details>
https://github.com/llvm/llvm-project/pull/125424
More information about the llvm-commits
mailing list