Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Sep 7, 2024

Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper.

@jurahul
Copy link
Contributor Author

jurahul commented Sep 7, 2024

@jurahul jurahul marked this pull request as ready for review September 7, 2024 22:28
@jurahul jurahul requested review from BeMg, asb and wangpc-pp September 7, 2024 22:28
@jurahul jurahul requested a review from mshockwave September 7, 2024 22:28
@llvmbot
Copy link
Member

llvmbot commented Sep 7, 2024

@llvm/pr-subscribers-backend-risc-v

Author: Rahul Joshi (jurahul)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/107697.diff

2 Files Affected:

  • (modified) llvm/utils/TableGen/RISCVTargetDefEmitter.cpp (+13-14)
  • (modified) llvm/utils/TableGen/VTEmitter.cpp (+3-4)
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index ae5ce32d617b47..1fbcba59f964d8 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -25,14 +25,14 @@ static StringRef getExtensionName(const Record *R) {
 }
 
 static void printExtensionTable(raw_ostream &OS,
-                                const std::vector<Record *> &Extensions,
+                                ArrayRef<const Record *> Extensions,
                                 bool Experimental) {
   OS << "static const RISCVSupportedExtension Supported";
   if (Experimental)
     OS << "Experimental";
   OS << "Extensions[] = {\n";
 
-  for (Record *R : Extensions) {
+  for (const Record *R : Extensions) {
     if (R->getValueAsBit("Experimental") != Experimental)
       continue;
 
@@ -44,11 +44,11 @@ static void printExtensionTable(raw_ostream &OS,
   OS << "};\n\n";
 }
 
-static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVExtensions(const RecordKeeper &Records, raw_ostream &OS) {
   OS << "#ifdef GET_SUPPORTED_EXTENSIONS\n";
   OS << "#undef GET_SUPPORTED_EXTENSIONS\n\n";
 
-  std::vector<Record *> Extensions =
+  std::vector<const Record *> Extensions =
       Records.getAllDerivedDefinitionsIfDefined("RISCVExtension");
   llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
     return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -66,7 +66,7 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
 
   if (!Extensions.empty()) {
     OS << "\nstatic constexpr ImpliedExtsEntry ImpliedExts[] = {\n";
-    for (Record *Ext : Extensions) {
+    for (const Record *Ext : Extensions) {
       auto ImpliesList = Ext->getValueAsListOfDefs("Implies");
       if (ImpliesList.empty())
         continue;
@@ -94,12 +94,12 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
 //
 // This is almost the same as RISCVFeatures::parseFeatureBits, except that we
 // get feature name from feature records instead of feature bits.
-static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
+static void printMArch(raw_ostream &OS, ArrayRef<const Record *> Features) {
   RISCVISAUtils::OrderedExtensionMap Extensions;
   unsigned XLen = 0;
 
   // Convert features to FeatureVector.
-  for (auto *Feature : Features) {
+  for (const Record *Feature : Features) {
     StringRef FeatureName = getExtensionName(Feature);
     if (Feature->isSubClassOf("RISCVExtension")) {
       unsigned Major = Feature->getValueAsInt("MajorVersion");
@@ -124,7 +124,7 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
 }
 
 static void printProfileTable(raw_ostream &OS,
-                              const std::vector<Record *> &Profiles,
+                              ArrayRef<const Record *> Profiles,
                               bool Experimental) {
   OS << "static constexpr RISCVProfile Supported";
   if (Experimental)
@@ -145,7 +145,7 @@ static void printProfileTable(raw_ostream &OS,
   OS << "};\n\n";
 }
 
-static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVProfiles(const RecordKeeper &Records, raw_ostream &OS) {
   OS << "#ifdef GET_SUPPORTED_PROFILES\n";
   OS << "#undef GET_SUPPORTED_PROFILES\n\n";
 
@@ -163,7 +163,7 @@ static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
   OS << "#endif // GET_SUPPORTED_PROFILES\n\n";
 }
 
-static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
+static void emitRISCVProcs(const RecordKeeper &RK, raw_ostream &OS) {
   OS << "#ifndef PROC\n"
      << "#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN"
      << ", FAST_VECTOR_UNALIGN)\n"
@@ -210,9 +210,8 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
   OS << "\n#undef TUNE_PROC\n";
 }
 
-static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
-
-  std::vector<Record *> Extensions =
+static void emitRISCVExtensionBitmask(const RecordKeeper &RK, raw_ostream &OS) {
+  std::vector<const Record *> Extensions =
       RK.getAllDerivedDefinitionsIfDefined("RISCVExtensionBitmask");
   llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
     return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -245,7 +244,7 @@ static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
   OS << "#endif\n";
 }
 
-static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
   emitRISCVExtensions(RK, OS);
   emitRISCVProfiles(RK, OS);
   emitRISCVProcs(RK, OS);
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 6cfd29e710829f..8f4bcd5fccc73d 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -19,10 +19,10 @@ namespace {
 
 class VTEmitter {
 private:
-  RecordKeeper &Records;
+  const RecordKeeper &Records;
 
 public:
-  VTEmitter(RecordKeeper &R) : Records(R) {}
+  VTEmitter(const RecordKeeper &R) : Records(R) {}
 
   void run(raw_ostream &OS);
 };
@@ -91,8 +91,7 @@ void VTEmitter::run(raw_ostream &OS) {
   emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
 
   std::vector<const Record *> VTsByNumber{512};
-  auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
-  for (auto *VT : ValueTypes) {
+  for (auto *VT : Records.getAllDerivedDefinitions("ValueType")) {
     auto Number = VT->getValueAsInt("Value");
     assert(0 <= Number && Number < (int)VTsByNumber.size() &&
            "ValueType should be uint16_t");

@jurahul jurahul changed the title [TableGen] Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper [NFC][TableGen] Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper Sep 7, 2024
Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jurahul jurahul merged commit 4ea6552 into llvm:main Sep 8, 2024
@jurahul jurahul deleted the const_llvm_riscv_vt_emitter branch September 8, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants