[llvm] [LLVM][TableGen] Change a few emitters to use const Record pointers (PR #110112)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 04:46:25 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/110112
Change DirectiveEmitter, Option Emitter, and X86 Emitters to use const Record pointers.
>From 5515e5f7d0c998bbfad7f069f4af150322d197fd Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 26 Sep 2024 04:44:13 -0700
Subject: [PATCH] [LLVM][TableGen] Change a few emitters to use const Record
pointers
---
llvm/include/llvm/TableGen/DirectiveEmitter.h | 24 +++++++++----------
llvm/utils/TableGen/DirectiveEmitter.cpp | 9 +++----
llvm/utils/TableGen/OptionParserEmitter.cpp | 4 ++--
llvm/utils/TableGen/OptionRSTEmitter.cpp | 1 -
llvm/utils/TableGen/X86FoldTablesEmitter.cpp | 2 +-
.../utils/TableGen/X86InstrMappingEmitter.cpp | 2 +-
6 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/llvm/include/llvm/TableGen/DirectiveEmitter.h b/llvm/include/llvm/TableGen/DirectiveEmitter.h
index 4ab0e889078ffd..014a2bc4b88313 100644
--- a/llvm/include/llvm/TableGen/DirectiveEmitter.h
+++ b/llvm/include/llvm/TableGen/DirectiveEmitter.h
@@ -135,24 +135,24 @@ class Directive : public BaseRecord {
public:
Directive(const Record *Def) : BaseRecord(Def) {}
- std::vector<Record *> getAllowedClauses() const {
- return Def->getValueAsListOfDefs("allowedClauses");
+ std::vector<const Record *> getAllowedClauses() const {
+ return Def->getValueAsListOfConstDefs("allowedClauses");
}
- std::vector<Record *> getAllowedOnceClauses() const {
- return Def->getValueAsListOfDefs("allowedOnceClauses");
+ std::vector<const Record *> getAllowedOnceClauses() const {
+ return Def->getValueAsListOfConstDefs("allowedOnceClauses");
}
- std::vector<Record *> getAllowedExclusiveClauses() const {
- return Def->getValueAsListOfDefs("allowedExclusiveClauses");
+ std::vector<const Record *> getAllowedExclusiveClauses() const {
+ return Def->getValueAsListOfConstDefs("allowedExclusiveClauses");
}
- std::vector<Record *> getRequiredClauses() const {
- return Def->getValueAsListOfDefs("requiredClauses");
+ std::vector<const Record *> getRequiredClauses() const {
+ return Def->getValueAsListOfConstDefs("requiredClauses");
}
- std::vector<Record *> getLeafConstructs() const {
- return Def->getValueAsListOfDefs("leafConstructs");
+ std::vector<const Record *> getLeafConstructs() const {
+ return Def->getValueAsListOfConstDefs("leafConstructs");
}
Record *getAssociation() const { return Def->getValueAsDef("association"); }
@@ -203,8 +203,8 @@ class Clause : public BaseRecord {
return Def->getValueAsString("enumClauseValue");
}
- std::vector<Record *> getClauseVals() const {
- return Def->getValueAsListOfDefs("allowedClauseValues");
+ std::vector<const Record *> getClauseVals() const {
+ return Def->getValueAsListOfConstDefs("allowedClauseValues");
}
bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index fafdfa0db89af2..dc9ed2b08972e2 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -343,8 +343,9 @@ static void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
if (ClauseVals.size() <= 0)
continue;
- auto DefaultIt = find_if(
- ClauseVals, [](Record *CV) { return CV->getValueAsBit("isDefault"); });
+ auto DefaultIt = find_if(ClauseVals, [](const Record *CV) {
+ return CV->getValueAsBit("isDefault");
+ });
if (DefaultIt == ClauseVals.end()) {
PrintError("At least one val in Clause " + C.getFormattedName() +
@@ -505,7 +506,7 @@ static void EmitLeafTable(const DirectiveLanguage &DirLang, raw_ostream &OS,
std::vector<LeafList> LeafTable(Directives.size());
for (auto [Idx, Rec] : enumerate(Directives)) {
Directive Dir(Rec);
- std::vector<Record *> Leaves = Dir.getLeafConstructs();
+ std::vector<const Record *> Leaves = Dir.getLeafConstructs();
auto &List = LeafTable[Idx];
List.resize(MaxLeafCount + 2);
@@ -680,7 +681,7 @@ static void GenerateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
return AS;
}
// Compute the association from leaf constructs.
- std::vector<Record *> leaves = D.getLeafConstructs();
+ std::vector<const Record *> leaves = D.getLeafConstructs();
if (leaves.empty()) {
errs() << D.getName() << '\n';
PrintFatalError(errorPrefixFor(D) +
diff --git a/llvm/utils/TableGen/OptionParserEmitter.cpp b/llvm/utils/TableGen/OptionParserEmitter.cpp
index 5ae6f773a3c603..424cf16e719d5d 100644
--- a/llvm/utils/TableGen/OptionParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptionParserEmitter.cpp
@@ -471,13 +471,13 @@ static void EmitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
std::vector<std::pair<std::vector<std::string>, StringRef>>
HelpTextsForVariants;
- for (Record *VisibilityHelp :
+ for (const Record *VisibilityHelp :
R.getValueAsListOfDefs("HelpTextsForVariants")) {
ArrayRef<Init *> Visibilities =
VisibilityHelp->getValueAsListInit("Visibilities")->getValues();
std::vector<std::string> VisibilityNames;
- for (Init *Visibility : Visibilities)
+ for (const Init *Visibility : Visibilities)
VisibilityNames.push_back(Visibility->getAsUnquotedString());
HelpTextsForVariants.push_back(std::make_pair(
diff --git a/llvm/utils/TableGen/OptionRSTEmitter.cpp b/llvm/utils/TableGen/OptionRSTEmitter.cpp
index b798896a80963e..1b4c4cad4f0a45 100644
--- a/llvm/utils/TableGen/OptionRSTEmitter.cpp
+++ b/llvm/utils/TableGen/OptionRSTEmitter.cpp
@@ -18,7 +18,6 @@ using namespace llvm;
/// and emits a RST man page.
static void EmitOptionRST(const RecordKeeper &Records, raw_ostream &OS) {
llvm::StringMap<std::vector<const Record *>> OptionsByGroup;
- std::vector<Record *> OptionsWithoutGroup;
// Get the options.
std::vector<const Record *> Opts = Records.getAllDerivedDefinitions("Option");
diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
index dfa10f74974c7e..8ab7bdcd2214b3 100644
--- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
+++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
@@ -475,7 +475,7 @@ void X86FoldTablesEmitter::addEntryWithFlags(FoldTable &Table,
StringRef RegInstName = RegRec->getName();
unsigned DropLen =
RegInstName.ends_with("rkz") ? 2 : (RegInstName.ends_with("rk") ? 1 : 0);
- Record *BaseDef =
+ const Record *BaseDef =
DropLen ? Records.getDef(RegInstName.drop_back(DropLen)) : nullptr;
bool IsMoveReg =
BaseDef ? Target.getInstruction(BaseDef).isMoveReg : RegInst->isMoveReg;
diff --git a/llvm/utils/TableGen/X86InstrMappingEmitter.cpp b/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
index f68c727cbe9230..47df5bf0df8e5c 100644
--- a/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
+++ b/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
@@ -215,7 +215,7 @@ void X86InstrMappingEmitter::emitCompressEVEXTable(
StringRef Name = Rec->getName();
const CodeGenInstruction *NewInst = nullptr;
if (ManualMap.find(Name) != ManualMap.end()) {
- Record *NewRec = Records.getDef(ManualMap.at(Rec->getName()));
+ const Record *NewRec = Records.getDef(ManualMap.at(Rec->getName()));
assert(NewRec && "Instruction not found!");
NewInst = &Target.getInstruction(NewRec);
} else if (Name.ends_with("_EVEX")) {
More information about the llvm-commits
mailing list