[llvm] 91fdfec - [NFC][TableGen] Change `CodeGenIntrinsics` to use const references (#111219)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 5 01:01:36 PDT 2024


Author: Rahul Joshi
Date: 2024-10-05T01:01:32-07:00
New Revision: 91fdfec263ff2b8e88433c4294a550cabb0f2314

URL: https://github.com/llvm/llvm-project/commit/91fdfec263ff2b8e88433c4294a550cabb0f2314
DIFF: https://github.com/llvm/llvm-project/commit/91fdfec263ff2b8e88433c4294a550cabb0f2314.diff

LOG: [NFC][TableGen] Change `CodeGenIntrinsics` to use const references (#111219)

Change `CodeGenIntrinsics` classes to vend out const references to
`CodeGenIntrinsic` or `TargetSet` objects.

Added: 
    

Modified: 
    llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
    llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
    llvm/utils/TableGen/IntrinsicEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
index c3bd7efd8387a8..fe3c83ce92e99d 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
@@ -124,7 +124,7 @@ void CodeGenIntrinsicTable::CheckTargetIndependentIntrinsics() const {
   }
 }
 
-CodeGenIntrinsic &CodeGenIntrinsicMap::operator[](const Record *Record) {
+const CodeGenIntrinsic &CodeGenIntrinsicMap::operator[](const Record *Record) {
   if (!Record->isSubClassOf("Intrinsic"))
     PrintFatalError("Intrinsic defs should be subclass of 'Intrinsic' class");
 

diff  --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
index 1cdeaacd52dcdb..c2701e1586ee34 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
@@ -169,15 +169,12 @@ struct CodeGenIntrinsic {
 };
 
 class CodeGenIntrinsicTable {
-  std::vector<CodeGenIntrinsic> Intrinsics;
-
 public:
   struct TargetSet {
     StringRef Name;
     size_t Offset;
     size_t Count;
   };
-  std::vector<TargetSet> Targets;
 
   explicit CodeGenIntrinsicTable(const RecordKeeper &RC);
 
@@ -185,14 +182,17 @@ class CodeGenIntrinsicTable {
   size_t size() const { return Intrinsics.size(); }
   auto begin() const { return Intrinsics.begin(); }
   auto end() const { return Intrinsics.end(); }
-  CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
   const CodeGenIntrinsic &operator[](size_t Pos) const {
     return Intrinsics[Pos];
   }
+  ArrayRef<TargetSet> getTargets() const { return Targets; }
 
 private:
   void CheckDuplicateIntrinsics() const;
   void CheckTargetIndependentIntrinsics() const;
+
+  std::vector<CodeGenIntrinsic> Intrinsics;
+  std::vector<TargetSet> Targets;
 };
 
 // This class builds `CodeGenIntrinsic` on demand for a given Def.
@@ -202,7 +202,7 @@ class CodeGenIntrinsicMap {
 
 public:
   explicit CodeGenIntrinsicMap(const RecordKeeper &RC) : Ctx(RC) {}
-  CodeGenIntrinsic &operator[](const Record *Def);
+  const CodeGenIntrinsic &operator[](const Record *Def);
 };
 
 } // namespace llvm

diff  --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index c8b5ec146dc503..6d92c733ea3d6d 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -124,7 +124,7 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
   // intrinsics like dbg.value.
   using TargetSet = CodeGenIntrinsicTable::TargetSet;
   const TargetSet *Set = nullptr;
-  for (const auto &Target : Ints.Targets) {
+  for (const auto &Target : Ints.getTargets()) {
     if (Target.Name == IntrinsicPrefix) {
       Set = &Target;
       break;
@@ -132,7 +132,7 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
   }
   if (!Set) {
     // The first entry is for target independent intrinsics, so drop it.
-    auto KnowTargets = ArrayRef<TargetSet>(Ints.Targets).drop_front();
+    auto KnowTargets = Ints.getTargets().drop_front();
     PrintFatalError([KnowTargets](raw_ostream &OS) {
       OS << "tried to generate intrinsics for unknown target "
          << IntrinsicPrefix << "\nKnown targets are: ";
@@ -230,7 +230,7 @@ struct IntrinsicTargetInfo {
 };
 static constexpr IntrinsicTargetInfo TargetInfos[] = {
 )";
-  for (const auto [Name, Offset, Count] : Ints.Targets)
+  for (const auto [Name, Offset, Count] : Ints.getTargets())
     OS << formatv("  {{\"{}\", {}, {}},\n", Name, Offset, Count);
   OS << R"(};
 #endif


        


More information about the llvm-commits mailing list