Skip to content

[TableGen] Remove map CodeGenTarget::InstrToIntMap. #81079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/utils/TableGen/CodeGenInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions llvm/utils/TableGen/CodeGenTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}


Expand Down
9 changes: 3 additions & 6 deletions llvm/utils/TableGen/CodeGenTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,7 +35,6 @@ namespace llvm {

class RecordKeeper;
class Record;
class CodeGenInstruction;
class CodeGenRegBank;
class CodeGenRegister;
class CodeGenRegisterClass;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down