[llvm] [LLVM][TableGen] Change ARMTargetDefEmitter to use const RecordKeeper (PR #108916)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 19:49:28 PDT 2024


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/108916

Change ARMTargetDefEmitter to use const RecordKeeper

>From 67b62066812d88a91c180118689e2b924b35c412 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 16 Sep 2024 19:47:51 -0700
Subject: [PATCH] [LLVM][TableGen] Change ARMTargetDefEmitter to use const
 RecordKeeper

---
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp | 30 ++++++++++++---------
 1 file changed, 17 insertions(+), 13 deletions(-)

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