[llvm] 17c31fb - [TableGen] Replace a StringMap keyed by Record name with a DenseMap.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 22:55:09 PST 2023
Author: Craig Topper
Date: 2023-02-27T22:54:03-08:00
New Revision: 17c31fba5bcdf0ee1899a7d1ae751549e4521a1b
URL: https://github.com/llvm/llvm-project/commit/17c31fba5bcdf0ee1899a7d1ae751549e4521a1b
DIFF: https://github.com/llvm/llvm-project/commit/17c31fba5bcdf0ee1899a7d1ae751549e4521a1b.diff
LOG: [TableGen] Replace a StringMap keyed by Record name with a DenseMap.
We can use the Record* to uniquely identify the Record without using
its name.
Added:
Modified:
llvm/utils/TableGen/CodeGenHwModes.cpp
llvm/utils/TableGen/CodeGenHwModes.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenHwModes.cpp b/llvm/utils/TableGen/CodeGenHwModes.cpp
index 2fec46c44100f..9c5d5268516c3 100644
--- a/llvm/utils/TableGen/CodeGenHwModes.cpp
+++ b/llvm/utils/TableGen/CodeGenHwModes.cpp
@@ -38,7 +38,7 @@ HwModeSelect::HwModeSelect(Record *R, CodeGenHwModes &CGH) {
report_fatal_error("error in target description.");
}
for (unsigned i = 0, e = Modes.size(); i != e; ++i) {
- unsigned ModeId = CGH.getHwModeId(Modes[i]->getName());
+ unsigned ModeId = CGH.getHwModeId(Modes[i]);
Items.push_back(std::make_pair(ModeId, Objects[i]));
}
}
@@ -64,8 +64,7 @@ CodeGenHwModes::CodeGenHwModes(RecordKeeper &RK) : Records(RK) {
for (Record *R : MRs) {
Modes.emplace_back(R);
- unsigned NewId = Modes.size();
- ModeIds.insert(std::make_pair(Modes[NewId-1].Name, NewId));
+ ModeIds.insert(std::make_pair(R, Modes.size()));
}
std::vector<Record*> MSs = Records.getAllDerivedDefinitions("HwModeSelect");
@@ -76,10 +75,10 @@ CodeGenHwModes::CodeGenHwModes(RecordKeeper &RK) : Records(RK) {
}
}
-unsigned CodeGenHwModes::getHwModeId(StringRef Name) const {
- if (Name == DefaultModeName)
+unsigned CodeGenHwModes::getHwModeId(Record *R) const {
+ if (R->getName() == DefaultModeName)
return DefaultMode;
- auto F = ModeIds.find(Name);
+ auto F = ModeIds.find(R);
assert(F != ModeIds.end() && "Unknown mode name");
return F->second;
}
@@ -101,7 +100,7 @@ void CodeGenHwModes::dump() const {
dbgs() << "ModeIds: {\n";
for (const auto &P : ModeIds)
- dbgs() << " " << P.first() << " -> " << P.second << '\n';
+ dbgs() << " " << P.first->getName() << " -> " << P.second << '\n';
dbgs() << "}\n";
dbgs() << "ModeSelects: {\n";
diff --git a/llvm/utils/TableGen/CodeGenHwModes.h b/llvm/utils/TableGen/CodeGenHwModes.h
index 335e918bfe738..7923df1fc0a5f 100644
--- a/llvm/utils/TableGen/CodeGenHwModes.h
+++ b/llvm/utils/TableGen/CodeGenHwModes.h
@@ -11,7 +11,7 @@
#ifndef LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H
#define LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H
-#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <map>
@@ -46,7 +46,7 @@ namespace llvm {
static StringRef DefaultModeName;
CodeGenHwModes(RecordKeeper &R);
- unsigned getHwModeId(StringRef Name) const;
+ unsigned getHwModeId(Record *R) const;
const HwMode &getMode(unsigned Id) const {
assert(Id != 0 && "Mode id of 0 is reserved for the default mode");
return Modes[Id-1];
@@ -57,7 +57,7 @@ namespace llvm {
private:
RecordKeeper &Records;
- StringMap<unsigned> ModeIds; // HwMode (string) -> HwModeId
+ DenseMap<Record *, unsigned> ModeIds; // HwMode Record -> HwModeId
std::vector<HwMode> Modes;
std::map<Record*,HwModeSelect> ModeSelects;
};
More information about the llvm-commits
mailing list