Skip to content

[TableGen] Use llvm::interleaved (NFC) #137483

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-tablegen

Author: Kazu Hirata (kazutakahirata)

Changes

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

2 Files Affected:

  • (modified) llvm/utils/TableGen/CallingConvEmitter.cpp (+9-23)
  • (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+3-7)
diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index c94d294db547a..d2700816b0ad0 100644
--- a/llvm/utils/TableGen/CallingConvEmitter.cpp
+++ b/llvm/utils/TableGen/CallingConvEmitter.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Common/CodeGenTarget.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TGTimer.h"
@@ -395,22 +396,16 @@ void CallingConvEmitter::emitArgRegisterLists(raw_ostream &O) {
 
   O << "\n#else\n\n";
 
-  for (auto &Entry : AssignedRegsMap) {
-    const std::string &RegName = Entry.first;
-    std::set<std::string> &Registers = Entry.second;
-
+  for (const auto &[RegName, Registers] : AssignedRegsMap) {
     if (RegName.empty())
       continue;
 
-    O << "const MCRegister " << Entry.first << "_ArgRegs[] = { ";
+    O << "const MCRegister " << RegName << "_ArgRegs[] = { ";
 
-    if (Registers.empty()) {
+    if (Registers.empty())
       O << "0";
-    } else {
-      ListSeparator LS;
-      for (const std::string &Reg : Registers)
-        O << LS << Reg;
-    }
+    else
+      O << llvm::interleaved(Registers);
 
     O << " };\n";
   }
@@ -419,18 +414,9 @@ void CallingConvEmitter::emitArgRegisterLists(raw_ostream &O) {
     return;
 
   O << "\n// Registers used by Swift.\n";
-  for (auto &Entry : AssignedSwiftRegsMap) {
-    const std::string &RegName = Entry.first;
-    std::set<std::string> &Registers = Entry.second;
-
-    O << "const MCRegister " << RegName << "_Swift_ArgRegs[] = { ";
-
-    ListSeparator LS;
-    for (const std::string &Reg : Registers)
-      O << LS << Reg;
-
-    O << " };\n";
-  }
+  for (const auto &[RegName, Registers] : AssignedSwiftRegsMap)
+    O << "const MCRegister " << RegName << "_Swift_ArgRegs[] = { "
+      << llvm::interleaved(Registers) << " };\n";
 }
 
 static TableGen::Emitter::OptClass<CallingConvEmitter>
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 615c077fe4bdc..20b313d4428db 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/TypeSize.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
@@ -3217,13 +3218,8 @@ bool TreePattern::InferAllTypes(
 
 void TreePattern::print(raw_ostream &OS) const {
   OS << getRecord()->getName();
-  if (!Args.empty()) {
-    OS << "(";
-    ListSeparator LS;
-    for (const std::string &Arg : Args)
-      OS << LS << Arg;
-    OS << ")";
-  }
+  if (!Args.empty())
+    OS << '(' << llvm::interleaved(Args) << ')';
   OS << ": ";
 
   if (Trees.size() > 1)

@kazutakahirata kazutakahirata merged commit 4c1dc85 into llvm:main Apr 27, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_interleaved_TableGen branch April 27, 2025 01:18
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
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