[llvm] [TableGen] Migrate CodeGenHWModes to use const RecordKeeper (PR #107851)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 05:07:58 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/107851
Migrate CodeGenHWModes to use const RecordKeeper and const Record pointers.
>From d09413cdd738e8161611ae7d42ad3d94ac5d1620 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 9 Sep 2024 05:05:02 -0700
Subject: [PATCH] [TableGen] Migrate CodeGenHWModes to use const RecordKeeper
Migrate CodeGenHWModes to use const RecordKeeper and const
Record pointers.
---
llvm/utils/TableGen/CodeEmitterGen.cpp | 8 ++++----
llvm/utils/TableGen/Common/CodeGenHwModes.cpp | 17 ++++++++--------
llvm/utils/TableGen/Common/CodeGenHwModes.h | 20 +++++++++----------
llvm/utils/TableGen/Common/InfoByHwMode.cpp | 12 ++++++-----
llvm/utils/TableGen/Common/InfoByHwMode.h | 12 +++++------
.../TableGen/Common/VarLenCodeEmitterGen.cpp | 4 ++--
6 files changed, 37 insertions(+), 36 deletions(-)
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 755b819e748fd7..88acd79cab092e 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -58,7 +58,7 @@ class CodeEmitterGen {
int getVariableBit(const std::string &VarName, BitsInit *BI, int bit);
std::pair<std::string, std::string>
getInstructionCases(Record *R, CodeGenTarget &Target);
- void addInstructionCasesForEncoding(Record *R, Record *EncodingDef,
+ void addInstructionCasesForEncoding(Record *R, const Record *EncodingDef,
CodeGenTarget &Target, std::string &Case,
std::string &BitOffsetCase);
bool addCodeToMergeInOperand(Record *R, BitsInit *BI,
@@ -342,8 +342,8 @@ CodeEmitterGen::getInstructionCases(Record *R, CodeGenTarget &Target) {
}
void CodeEmitterGen::addInstructionCasesForEncoding(
- Record *R, Record *EncodingDef, CodeGenTarget &Target, std::string &Case,
- std::string &BitOffsetCase) {
+ Record *R, const Record *EncodingDef, CodeGenTarget &Target,
+ std::string &Case, std::string &BitOffsetCase) {
BitsInit *BI = EncodingDef->getValueAsBitsInit("Inst");
// Loop over all of the fields in the instruction, determining which are the
@@ -413,7 +413,7 @@ void CodeEmitterGen::emitInstructionBaseValues(
continue;
}
- Record *EncodingDef = R;
+ const Record *EncodingDef = R;
if (const RecordVal *RV = R->getValue("EncodingInfos")) {
if (auto *DI = dyn_cast_or_null<DefInit>(RV->getValue())) {
EncodingInfoByHwMode EBM(DI->getDef(), HWM);
diff --git a/llvm/utils/TableGen/Common/CodeGenHwModes.cpp b/llvm/utils/TableGen/Common/CodeGenHwModes.cpp
index 124cfbaf4fb747..fd2fd33740af4f 100644
--- a/llvm/utils/TableGen/Common/CodeGenHwModes.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenHwModes.cpp
@@ -18,15 +18,14 @@ using namespace llvm;
StringRef CodeGenHwModes::DefaultModeName = "DefaultMode";
-HwMode::HwMode(Record *R) {
+HwMode::HwMode(const Record *R) {
Name = R->getName();
Features = std::string(R->getValueAsString("Features"));
- std::vector<Record *> PredicateRecs = R->getValueAsListOfDefs("Predicates");
SmallString<128> PredicateCheck;
raw_svector_ostream OS(PredicateCheck);
ListSeparator LS(" && ");
- for (Record *Pred : PredicateRecs) {
+ for (const Record *Pred : R->getValueAsListOfDefs("Predicates")) {
StringRef CondString = Pred->getValueAsString("CondString");
if (CondString.empty())
continue;
@@ -39,7 +38,7 @@ HwMode::HwMode(Record *R) {
LLVM_DUMP_METHOD
void HwMode::dump() const { dbgs() << Name << ": " << Features << '\n'; }
-HwModeSelect::HwModeSelect(Record *R, CodeGenHwModes &CGH) {
+HwModeSelect::HwModeSelect(const Record *R, CodeGenHwModes &CGH) {
std::vector<Record *> Modes = R->getValueAsListOfDefs("Modes");
std::vector<Record *> Objects = R->getValueAsListOfDefs("Objects");
if (Modes.size() != Objects.size()) {
@@ -64,8 +63,8 @@ void HwModeSelect::dump() const {
dbgs() << " }\n";
}
-CodeGenHwModes::CodeGenHwModes(RecordKeeper &RK) : Records(RK) {
- for (Record *R : Records.getAllDerivedDefinitions("HwMode")) {
+CodeGenHwModes::CodeGenHwModes(const RecordKeeper &RK) : Records(RK) {
+ for (const Record *R : Records.getAllDerivedDefinitions("HwMode")) {
// The default mode needs a definition in the .td sources for TableGen
// to accept references to it. We need to ignore the definition here.
if (R->getName() == DefaultModeName)
@@ -76,14 +75,14 @@ CodeGenHwModes::CodeGenHwModes(RecordKeeper &RK) : Records(RK) {
assert(Modes.size() <= 32 && "number of HwModes exceeds maximum of 32");
- for (Record *R : Records.getAllDerivedDefinitions("HwModeSelect")) {
+ for (const Record *R : Records.getAllDerivedDefinitions("HwModeSelect")) {
auto P = ModeSelects.emplace(std::pair(R, HwModeSelect(R, *this)));
assert(P.second);
(void)P;
}
}
-unsigned CodeGenHwModes::getHwModeId(Record *R) const {
+unsigned CodeGenHwModes::getHwModeId(const Record *R) const {
if (R->getName() == DefaultModeName)
return DefaultMode;
auto F = ModeIds.find(R);
@@ -91,7 +90,7 @@ unsigned CodeGenHwModes::getHwModeId(Record *R) const {
return F->second;
}
-const HwModeSelect &CodeGenHwModes::getHwModeSelect(Record *R) const {
+const HwModeSelect &CodeGenHwModes::getHwModeSelect(const Record *R) const {
auto F = ModeSelects.find(R);
assert(F != ModeSelects.end() && "Record is not a \"mode select\"");
return F->second;
diff --git a/llvm/utils/TableGen/Common/CodeGenHwModes.h b/llvm/utils/TableGen/Common/CodeGenHwModes.h
index 305ee7c42ce1be..4ced4208cea076 100644
--- a/llvm/utils/TableGen/Common/CodeGenHwModes.h
+++ b/llvm/utils/TableGen/Common/CodeGenHwModes.h
@@ -28,7 +28,7 @@ class RecordKeeper;
struct CodeGenHwModes;
struct HwMode {
- HwMode(Record *R);
+ HwMode(const Record *R);
StringRef Name;
std::string Features;
std::string Predicates;
@@ -36,8 +36,8 @@ struct HwMode {
};
struct HwModeSelect {
- HwModeSelect(Record *R, CodeGenHwModes &CGH);
- typedef std::pair<unsigned, Record *> PairType;
+ HwModeSelect(const Record *R, CodeGenHwModes &CGH);
+ typedef std::pair<unsigned, const Record *> PairType;
std::vector<PairType> Items;
void dump() const;
};
@@ -46,8 +46,8 @@ struct CodeGenHwModes {
enum : unsigned { DefaultMode = 0 };
static StringRef DefaultModeName;
- CodeGenHwModes(RecordKeeper &R);
- unsigned getHwModeId(Record *R) const;
+ CodeGenHwModes(const RecordKeeper &R);
+ unsigned getHwModeId(const 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,18 +57,18 @@ struct CodeGenHwModes {
return DefaultModeName;
return getMode(Id).Name;
}
- const HwModeSelect &getHwModeSelect(Record *R) const;
- const std::map<Record *, HwModeSelect> &getHwModeSelects() const {
+ const HwModeSelect &getHwModeSelect(const Record *R) const;
+ const std::map<const Record *, HwModeSelect> &getHwModeSelects() const {
return ModeSelects;
}
unsigned getNumModeIds() const { return Modes.size() + 1; }
void dump() const;
private:
- RecordKeeper &Records;
- DenseMap<Record *, unsigned> ModeIds; // HwMode Record -> HwModeId
+ const RecordKeeper &Records;
+ DenseMap<const Record *, unsigned> ModeIds; // HwMode Record -> HwModeId
std::vector<HwMode> Modes;
- std::map<Record *, HwModeSelect> ModeSelects;
+ std::map<const Record *, HwModeSelect> ModeSelects;
};
} // namespace llvm
diff --git a/llvm/utils/TableGen/Common/InfoByHwMode.cpp b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
index cacf4ece667137..7425e7f48c2b03 100644
--- a/llvm/utils/TableGen/Common/InfoByHwMode.cpp
+++ b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
@@ -115,7 +115,7 @@ ValueTypeByHwMode llvm::getValueTypeByHwMode(Record *Rec,
return ValueTypeByHwMode(Rec, llvm::getValueType(Rec));
}
-RegSizeInfo::RegSizeInfo(Record *R) {
+RegSizeInfo::RegSizeInfo(const Record *R) {
RegSize = R->getValueAsInt("RegSize");
SpillSize = R->getValueAsInt("SpillSize");
SpillAlignment = R->getValueAsInt("SpillAlignment");
@@ -136,7 +136,8 @@ void RegSizeInfo::writeToStream(raw_ostream &OS) const {
<< ']';
}
-RegSizeInfoByHwMode::RegSizeInfoByHwMode(Record *R, const CodeGenHwModes &CGH) {
+RegSizeInfoByHwMode::RegSizeInfoByHwMode(const Record *R,
+ const CodeGenHwModes &CGH) {
const HwModeSelect &MS = CGH.getHwModeSelect(R);
for (const HwModeSelect::PairType &P : MS.Items) {
auto I = Map.insert({P.first, RegSizeInfo(P.second)});
@@ -183,12 +184,13 @@ void RegSizeInfoByHwMode::writeToStream(raw_ostream &OS) const {
OS << '}';
}
-SubRegRange::SubRegRange(Record *R) {
+SubRegRange::SubRegRange(const Record *R) {
Size = R->getValueAsInt("Size");
Offset = R->getValueAsInt("Offset");
}
-SubRegRangeByHwMode::SubRegRangeByHwMode(Record *R, const CodeGenHwModes &CGH) {
+SubRegRangeByHwMode::SubRegRangeByHwMode(const Record *R,
+ const CodeGenHwModes &CGH) {
const HwModeSelect &MS = CGH.getHwModeSelect(R);
for (const HwModeSelect::PairType &P : MS.Items) {
auto I = Map.insert({P.first, SubRegRange(P.second)});
@@ -197,7 +199,7 @@ SubRegRangeByHwMode::SubRegRangeByHwMode(Record *R, const CodeGenHwModes &CGH) {
}
}
-EncodingInfoByHwMode::EncodingInfoByHwMode(Record *R,
+EncodingInfoByHwMode::EncodingInfoByHwMode(const Record *R,
const CodeGenHwModes &CGH) {
const HwModeSelect &MS = CGH.getHwModeSelect(R);
for (const HwModeSelect::PairType &P : MS.Items) {
diff --git a/llvm/utils/TableGen/Common/InfoByHwMode.h b/llvm/utils/TableGen/Common/InfoByHwMode.h
index f614cd5af815b8..a6edf3c90da25b 100644
--- a/llvm/utils/TableGen/Common/InfoByHwMode.h
+++ b/llvm/utils/TableGen/Common/InfoByHwMode.h
@@ -183,7 +183,7 @@ struct RegSizeInfo {
unsigned SpillSize;
unsigned SpillAlignment;
- RegSizeInfo(Record *R);
+ RegSizeInfo(const Record *R);
RegSizeInfo() = default;
bool operator<(const RegSizeInfo &I) const;
bool operator==(const RegSizeInfo &I) const {
@@ -197,7 +197,7 @@ struct RegSizeInfo {
};
struct RegSizeInfoByHwMode : public InfoByHwMode<RegSizeInfo> {
- RegSizeInfoByHwMode(Record *R, const CodeGenHwModes &CGH);
+ RegSizeInfoByHwMode(const Record *R, const CodeGenHwModes &CGH);
RegSizeInfoByHwMode() = default;
bool operator<(const RegSizeInfoByHwMode &VI) const;
bool operator==(const RegSizeInfoByHwMode &VI) const;
@@ -222,12 +222,12 @@ struct SubRegRange {
uint16_t Size;
uint16_t Offset;
- SubRegRange(Record *R);
+ SubRegRange(const Record *R);
SubRegRange(uint16_t Size, uint16_t Offset) : Size(Size), Offset(Offset) {}
};
struct SubRegRangeByHwMode : public InfoByHwMode<SubRegRange> {
- SubRegRangeByHwMode(Record *R, const CodeGenHwModes &CGH);
+ SubRegRangeByHwMode(const Record *R, const CodeGenHwModes &CGH);
SubRegRangeByHwMode(SubRegRange Range) { Map.insert({DefaultMode, Range}); }
SubRegRangeByHwMode() = default;
@@ -236,8 +236,8 @@ struct SubRegRangeByHwMode : public InfoByHwMode<SubRegRange> {
}
};
-struct EncodingInfoByHwMode : public InfoByHwMode<Record *> {
- EncodingInfoByHwMode(Record *R, const CodeGenHwModes &CGH);
+struct EncodingInfoByHwMode : public InfoByHwMode<const Record *> {
+ EncodingInfoByHwMode(const Record *R, const CodeGenHwModes &CGH);
EncodingInfoByHwMode() = default;
};
diff --git a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
index e633dc36e2343b..049bd37dc83e58 100644
--- a/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp
@@ -241,8 +241,8 @@ void VarLenCodeEmitterGen::run(raw_ostream &OS) {
for (auto &KV : EBM) {
AltEncodingTy Mode = KV.first;
Modes.insert({Mode, "_" + HWM.getMode(Mode).Name.str()});
- Record *EncodingDef = KV.second;
- RecordVal *RV = EncodingDef->getValue("Inst");
+ const Record *EncodingDef = KV.second;
+ const RecordVal *RV = EncodingDef->getValue("Inst");
DagInit *DI = cast<DagInit>(RV->getValue());
VarLenInsts[R].insert({Mode, VarLenInst(DI, RV)});
}
More information about the llvm-commits
mailing list