aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Eckhardt <jeckhardt@nvidia.com>2024-02-07 21:33:16 -0600
committerGitHub <noreply@github.com>2024-02-07 19:33:16 -0800
commitd01864eb2f21d56cf432da7d80c505f510533c46 (patch)
tree8f42bd648bcc86719480dd927bc4f6e5e8e2ff22
parent5c4a630ab70f98138d6f95d19712bb114d92323d (diff)
downloadllvm-d01864eb2f21d56cf432da7d80c505f510533c46.zip
llvm-d01864eb2f21d56cf432da7d80c505f510533c46.tar.gz
llvm-d01864eb2f21d56cf432da7d80c505f510533c46.tar.bz2
[TableGen] Remove map CodeGenTarget::InstrToIntMap. (#81079)
This patch removes CodeGenTarget::InstrToIntMap, using instead a new member CodeGenInstruction::EnumVal to store each enum value. This value is computed and set by CodeGenTarget::computeInstrsByEnum and queried by CodeGenTarget::getInstrIntValue.
-rw-r--r--llvm/utils/TableGen/CodeGenInstruction.h3
-rw-r--r--llvm/utils/TableGen/CodeGenTarget.cpp6
-rw-r--r--llvm/utils/TableGen/CodeGenTarget.h9
3 files changed, 8 insertions, 10 deletions
diff --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h
index 8b3e670..4a34c29 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.h
+++ b/llvm/utils/TableGen/CodeGenInstruction.h
@@ -303,6 +303,9 @@ namespace llvm {
// have been inferred.
Record *InferredFrom;
+ // The enum value assigned by CodeGenTarget::computeInstrsByEnum.
+ mutable unsigned EnumVal;
+
CodeGenInstruction(Record *R);
/// HasOneImplicitDefWithKnownVT - If the instruction has at least one
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index cf0049e..ceaa51b1 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -539,12 +539,10 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
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());
+ // Assign an enum value to each instruction according to the sorted order.
unsigned Num = 0;
for (const CodeGenInstruction *Inst : InstrsByEnum)
- InstrToIntMap[Inst->TheDef] = Num++;
+ Inst->EnumVal = Num++;
}
diff --git a/llvm/utils/TableGen/CodeGenTarget.h b/llvm/utils/TableGen/CodeGenTarget.h
index 0bb8e45..29f1024 100644
--- a/llvm/utils/TableGen/CodeGenTarget.h
+++ b/llvm/utils/TableGen/CodeGenTarget.h
@@ -17,6 +17,7 @@
#define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
#include "CodeGenHwModes.h"
+#include "CodeGenInstruction.h"
#include "InfoByHwMode.h"
#include "SDNodeProperties.h"
#include "llvm/ADT/ArrayRef.h"
@@ -34,7 +35,6 @@ namespace llvm {
class RecordKeeper;
class Record;
-class CodeGenInstruction;
class CodeGenRegBank;
class CodeGenRegister;
class CodeGenRegisterClass;
@@ -73,8 +73,7 @@ class CodeGenTarget {
mutable std::unique_ptr<CodeGenSchedModels> SchedModels;
mutable StringRef InstNamespace;
- mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
- mutable DenseMap<const Record *, unsigned> InstrToIntMap;
+ mutable std::vector<const CodeGenInstruction *> InstrsByEnum;
mutable unsigned NumPseudoInstructions = 0;
public:
CodeGenTarget(RecordKeeper &Records);
@@ -197,9 +196,7 @@ public:
unsigned getInstrIntValue(const Record *R) const {
if (InstrsByEnum.empty())
ComputeInstrsByEnum();
- auto V = InstrToIntMap.find(R);
- assert(V != InstrToIntMap.end() && "instr not in InstrToIntMap");
- return V->second;
+ return getInstruction(R).EnumVal;
}
typedef ArrayRef<const CodeGenInstruction *>::const_iterator inst_iterator;