aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenTarget.cpp
diff options
context:
space:
mode:
authorJason Eckhardt <jeckhardt@nvidia.com>2024-02-06 22:49:39 -0600
committerGitHub <noreply@github.com>2024-02-07 12:49:39 +0800
commit8ae048507086cc3a2ceb6974506d3048c516a726 (patch)
treef36bb4e37c00f40fc8fad4cc6a042846f07fd7c2 /llvm/utils/TableGen/CodeGenTarget.cpp
parent8ea7f1d20ad8ab8c381800eefda948d85c6860cc (diff)
downloadllvm-8ae048507086cc3a2ceb6974506d3048c516a726.zip
llvm-8ae048507086cc3a2ceb6974506d3048c516a726.tar.gz
llvm-8ae048507086cc3a2ceb6974506d3048c516a726.tar.bz2
[TableGen] Extend direct lookup to instruction values in generic tables. (#80486)
Currently, for some tables involving a single primary key field which is integral and densely numbered, a direct lookup is generated rather than a binary search. This patch extends the direct lookup function generation to instructions, where the integral value corresponds to the instruction's enum value. While this isn't as common as for other tables, it does occur in at least one downstream backend and one in-tree backend. Added a unit test and minimally updated the documentation.
Diffstat (limited to 'llvm/utils/TableGen/CodeGenTarget.cpp')
-rw-r--r--llvm/utils/TableGen/CodeGenTarget.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index 37fa303..cf0049e 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -538,6 +538,13 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
return std::make_tuple(!D1.getValueAsBit("isPseudo"), D1.getName()) <
std::make_tuple(!D2.getValueAsBit("isPseudo"), D2.getName());
});
+
+ // Build the instruction-to-int map using the same values emitted by
+ // InstrInfoEmitter::emitEnums.
+ assert(InstrToIntMap.empty());
+ unsigned Num = 0;
+ for (const CodeGenInstruction *Inst : InstrsByEnum)
+ InstrToIntMap[Inst->TheDef] = Num++;
}