[llvm] 5fdf07d - [LLVM][TableGen] Change ARMTargetDefEmitter to use const RecordKeeper (#108916)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 06:20:43 PDT 2024
Author: Rahul Joshi
Date: 2024-09-17T06:20:38-07:00
New Revision: 5fdf07dda697a7752aad64ba93d4c38de21f8d3b
URL: https://github.com/llvm/llvm-project/commit/5fdf07dda697a7752aad64ba93d4c38de21f8d3b
DIFF: https://github.com/llvm/llvm-project/commit/5fdf07dda697a7752aad64ba93d4c38de21f8d3b.diff
LOG: [LLVM][TableGen] Change ARMTargetDefEmitter to use const RecordKeeper (#108916)
Change ARMTargetDefEmitter to use const RecordKeeper.
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
Added:
Modified:
llvm/utils/TableGen/ARMTargetDefEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
index 71ca331461c00c..6b8ebf96cdf383 100644
--- a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
@@ -25,24 +25,26 @@
using namespace llvm;
/// Collect the full set of implied features for a SubtargetFeature.
-static void CollectImpliedFeatures(std::set<Record *> &SeenFeats, Record *Rec) {
+static void CollectImpliedFeatures(std::set<const Record *> &SeenFeats,
+ const Record *Rec) {
assert(Rec->isSubClassOf("SubtargetFeature") &&
"Rec is not a SubtargetFeature");
SeenFeats.insert(Rec);
- for (Record *Implied : Rec->getValueAsListOfDefs("Implies"))
+ for (const Record *Implied : Rec->getValueAsListOfDefs("Implies"))
CollectImpliedFeatures(SeenFeats, Implied);
}
-static void CheckFeatureTree(Record *Root) {
- std::set<Record *> SeenFeats;
+static void CheckFeatureTree(const Record *Root) {
+ std::set<const Record *> SeenFeats;
CollectImpliedFeatures(SeenFeats, Root);
// Check that each of the mandatory (implied) features which is an
// ExtensionWithMArch is also enabled by default.
auto DefaultExtsVec = Root->getValueAsListOfDefs("DefaultExts");
- std::set<Record *> DefaultExts{DefaultExtsVec.begin(), DefaultExtsVec.end()};
- for (auto *Feat : SeenFeats) {
+ std::set<const Record *> DefaultExts{DefaultExtsVec.begin(),
+ DefaultExtsVec.end()};
+ for (const Record *Feat : SeenFeats) {
if (Feat->isSubClassOf("ExtensionWithMArch") && !DefaultExts.count(Feat))
PrintFatalError(Root->getLoc(),
"ExtensionWithMArch " + Feat->getName() +
@@ -51,7 +53,7 @@ static void CheckFeatureTree(Record *Root) {
}
}
-static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitARMTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
OS << "// Autogenerated by ARMTargetDefEmitter.cpp\n\n";
// Look through all SubtargetFeature defs with the given FieldName, and
@@ -67,14 +69,14 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
};
// Sort the extensions alphabetically, so they don't appear in tablegen order.
- std::vector<Record *> SortedExtensions =
+ std::vector<const Record *> SortedExtensions =
RK.getAllDerivedDefinitions("Extension");
- auto Alphabetical = [](Record *A, Record *B) -> bool {
+ auto Alphabetical = [](const Record *A, const Record *B) -> bool {
const auto NameA = A->getValueAsString("Name");
const auto NameB = B->getValueAsString("Name");
return NameA.compare(NameB) < 0; // A lexographically less than B
};
- std::sort(SortedExtensions.begin(), SortedExtensions.end(), Alphabetical);
+ sort(SortedExtensions, Alphabetical);
// The ARMProcFamilyEnum values are initialised by SubtargetFeature defs
// which set the ARMProcFamily field. We can generate the enum from these defs
@@ -287,7 +289,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
if (Name == "apple-latest")
continue;
- Record *Arch;
+ const Record *Arch;
if (Name == "generic") {
// "generic" is an exception. It does not have an architecture, and there
// are tests that depend on e.g. -mattr=-v8.4a meaning HasV8_0aOps==false.
@@ -295,7 +297,9 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
Arch = RK.getDef("HasV8_0aOps");
} else {
// Search for an Architecture64 in the list of features.
- auto IsArch = [](Record *F) { return F->isSubClassOf("Architecture64"); };
+ auto IsArch = [](const Record *F) {
+ return F->isSubClassOf("Architecture64");
+ };
auto ArchIter = llvm::find_if(Features, IsArch);
if (ArchIter == Features.end())
PrintFatalError(Rec, "Features must include an Architecture64.");
@@ -320,7 +324,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
// Keep track of extensions we have seen
StringSet<> SeenExts;
- for (auto *E : Rec->getValueAsListOfDefs("Features"))
+ for (const Record *E : Rec->getValueAsListOfDefs("Features"))
// Only process subclasses of Extension
if (E->isSubClassOf("Extension")) {
const auto AEK = E->getValueAsString("ArchExtKindSpelling").upper();
More information about the llvm-commits
mailing list