Skip to content

[NFC][TableGen] Change CodeGenIntrinsics to use const references #111219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Oct 4, 2024

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

Change `CodeGenIntrinsics` classes to vend out const references
to `CodeGenIntrinsic` or `TargetSet` objects.
@jurahul jurahul requested a review from kazutakahirata October 4, 2024 23:25
@jurahul jurahul marked this pull request as ready for review October 4, 2024 23:25
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2024

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes

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


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

3 Files Affected:

  • (modified) llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp (+1-1)
  • (modified) llvm/utils/TableGen/Basic/CodeGenIntrinsics.h (+5-5)
  • (modified) llvm/utils/TableGen/IntrinsicEmitter.cpp (+3-3)
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

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@jurahul jurahul merged commit 91fdfec into llvm:main Oct 5, 2024
13 checks passed
@jurahul jurahul deleted the const_CodegenIntrinsic branch October 5, 2024 08:01
Kyvangka1610 pushed a commit to Kyvangka1610/llvm-project that referenced this pull request Oct 5, 2024
…lvm#111219)

Change `CodeGenIntrinsics` classes to vend out const references to
`CodeGenIntrinsic` or `TargetSet` objects.
Kyvangka1610 added a commit to Kyvangka1610/llvm-project that referenced this pull request Oct 5, 2024
* commit 'FETCH_HEAD':
  [clang][bytecode] Handle UETT_OpenMPRequiredSimdAlign (llvm#111259)
  [mlir][polynomial] Add and verify constraints of coefficientModulus for ringAttr (llvm#111016)
  [clang][bytecode] Save a per-Block IsWeak bit (llvm#111248)
  [analyzer] Fix wrong `builtin_*_overflow` return type (llvm#111253)
  [SelectOpt] Don't convert constant selects to branches. (llvm#110858)
  [InstCombine] Update and-or-icmps.ll after 574266c. NFC
  [Instcombine] Test for more gep canonicalization
  [NFC][TableGen] Change `CodeGenIntrinsics` to use const references (llvm#111219)
  Add warning message to `session save` when transcript isn't saved. (llvm#109020)
  [RISCV][TTI] Recognize CONCAT_VECTORS if a shufflevector mask is multiple insert subvector. (llvm#110457)
  Revert "[InstCombine] Folding `(icmp eq/ne (and X, -P2), INT_MIN)`" (llvm#111236)
  [NFC][lsan] Add SuspendAllThreads traces
  [lsan] Add `thread_suspend_fail` flag

Signed-off-by: kyvangka1610 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants