[llvm] [LLVM][TableGen] Change a few emitters to use const Record pointers (PR #110112)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 06:16:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
@llvm/pr-subscribers-backend-x86
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
Change DirectiveEmitter, Option Emitter, and X86 Emitters to use const Record pointers.
This is a part of effort to have better const correctness in TableGen backends:
https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
---
Full diff: https://github.com/llvm/llvm-project/pull/110112.diff
7 Files Affected:
- (modified) llvm/include/llvm/TableGen/DirectiveEmitter.h (+12-12)
- (modified) llvm/utils/TableGen/CallingConvEmitter.cpp (+2-2)
- (modified) llvm/utils/TableGen/DirectiveEmitter.cpp (+5-4)
- (modified) llvm/utils/TableGen/OptionParserEmitter.cpp (+2-2)
- (modified) llvm/utils/TableGen/OptionRSTEmitter.cpp (-1)
- (modified) llvm/utils/TableGen/X86FoldTablesEmitter.cpp (+1-1)
- (modified) llvm/utils/TableGen/X86InstrMappingEmitter.cpp (+1-1)
``````````diff
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/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index 8876bb3ad31e19..1b95082ad07150 100644
--- a/llvm/utils/TableGen/CallingConvEmitter.cpp
+++ b/llvm/utils/TableGen/CallingConvEmitter.cpp
@@ -131,9 +131,9 @@ void CallingConvEmitter::EmitAction(const Record *Action, unsigned Indent,
O << IndentStr << "if (";
if (Action->isSubClassOf("CCIfType")) {
- ListInit *VTs = Action->getValueAsListInit("VTs");
+ const ListInit *VTs = Action->getValueAsListInit("VTs");
for (unsigned i = 0, e = VTs->size(); i != e; ++i) {
- Record *VT = VTs->getElementAsRecord(i);
+ const Record *VT = VTs->getElementAsRecord(i);
if (i != 0)
O << " ||\n " << IndentStr;
O << "LocVT == " << getEnumName(getValueType(VT));
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")) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/110112
More information about the llvm-commits
mailing list