Skip to content

Commit d01864e

Browse files
authored
[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.
1 parent 5c4a630 commit d01864e

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

llvm/utils/TableGen/CodeGenInstruction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ namespace llvm {
303303
// have been inferred.
304304
Record *InferredFrom;
305305

306+
// The enum value assigned by CodeGenTarget::computeInstrsByEnum.
307+
mutable unsigned EnumVal;
308+
306309
CodeGenInstruction(Record *R);
307310

308311
/// HasOneImplicitDefWithKnownVT - If the instruction has at least one

llvm/utils/TableGen/CodeGenTarget.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,10 @@ void CodeGenTarget::ComputeInstrsByEnum() const {
539539
std::make_tuple(!D2.getValueAsBit("isPseudo"), D2.getName());
540540
});
541541

542-
// Build the instruction-to-int map using the same values emitted by
543-
// InstrInfoEmitter::emitEnums.
544-
assert(InstrToIntMap.empty());
542+
// Assign an enum value to each instruction according to the sorted order.
545543
unsigned Num = 0;
546544
for (const CodeGenInstruction *Inst : InstrsByEnum)
547-
InstrToIntMap[Inst->TheDef] = Num++;
545+
Inst->EnumVal = Num++;
548546
}
549547

550548

llvm/utils/TableGen/CodeGenTarget.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
1818

1919
#include "CodeGenHwModes.h"
20+
#include "CodeGenInstruction.h"
2021
#include "InfoByHwMode.h"
2122
#include "SDNodeProperties.h"
2223
#include "llvm/ADT/ArrayRef.h"
@@ -34,7 +35,6 @@ namespace llvm {
3435

3536
class RecordKeeper;
3637
class Record;
37-
class CodeGenInstruction;
3838
class CodeGenRegBank;
3939
class CodeGenRegister;
4040
class CodeGenRegisterClass;
@@ -73,8 +73,7 @@ class CodeGenTarget {
7373
mutable std::unique_ptr<CodeGenSchedModels> SchedModels;
7474

7575
mutable StringRef InstNamespace;
76-
mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
77-
mutable DenseMap<const Record *, unsigned> InstrToIntMap;
76+
mutable std::vector<const CodeGenInstruction *> InstrsByEnum;
7877
mutable unsigned NumPseudoInstructions = 0;
7978
public:
8079
CodeGenTarget(RecordKeeper &Records);
@@ -197,9 +196,7 @@ class CodeGenTarget {
197196
unsigned getInstrIntValue(const Record *R) const {
198197
if (InstrsByEnum.empty())
199198
ComputeInstrsByEnum();
200-
auto V = InstrToIntMap.find(R);
201-
assert(V != InstrToIntMap.end() && "instr not in InstrToIntMap");
202-
return V->second;
199+
return getInstruction(R).EnumVal;
203200
}
204201

205202
typedef ArrayRef<const CodeGenInstruction *>::const_iterator inst_iterator;

0 commit comments

Comments
 (0)