[llvm] d01864e - [TableGen] Remove map CodeGenTarget::InstrToIntMap. (#81079)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 19:33:21 PST 2024
Author: Jason Eckhardt
Date: 2024-02-07T19:33:16-08:00
New Revision: d01864eb2f21d56cf432da7d80c505f510533c46
URL: https://github.com/llvm/llvm-project/commit/d01864eb2f21d56cf432da7d80c505f510533c46
DIFF: https://github.com/llvm/llvm-project/commit/d01864eb2f21d56cf432da7d80c505f510533c46.diff
LOG: [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.
Added:
Modified:
llvm/utils/TableGen/CodeGenInstruction.h
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/CodeGenTarget.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h
index 8b3e670d3ff7cd..4a34c296517c50 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 cf0049e6d33e3c..ceaa51b1dff36c 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 0bb8e45a56064e..29f10243e1efd6 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 @@ class CodeGenTarget {
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;
More information about the llvm-commits
mailing list