[llvm] [GlobalISel] Prefix MatchTable Lines with their Index (PR #125845)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 04:13:05 PST 2025
https://github.com/Pierre-vh updated https://github.com/llvm/llvm-project/pull/125845
>From 835576db2f011eaa5b09271852729f46d2c9617d Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Wed, 5 Feb 2025 13:07:21 +0100
Subject: [PATCH 1/2] [GlobalISel] Prefix MatchTable Lines with their Index
Fixes #119177
---
.../GlobalISel/GlobalISelMatchTable.cpp | 23 ++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index 8564bf8d2d91ba..9083ce7c86a472 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -286,11 +286,25 @@ MatchTableRecord MatchTable::JumpTarget(unsigned LabelID) {
void MatchTable::emitUse(raw_ostream &OS) const { OS << "MatchTable" << ID; }
void MatchTable::emitDeclaration(raw_ostream &OS) const {
- unsigned Indentation = 4;
+ static constexpr unsigned BaseIndent = 4;
+ unsigned Indentation = 0;
OS << " constexpr static uint8_t MatchTable" << ID << "[] = {";
LineBreak.emit(OS, true, *this);
- OS << std::string(Indentation, ' ');
+ const unsigned NumColsForIdx = llvm::to_string(CurrentSize).size();
+
+ unsigned CurIndex = 0;
+ const auto BeginLine = [&](){
+ OS << std::string(BaseIndent, ' ');
+ // To keep the /* index */ column consistent, pad
+ // the string at the start so we can always fit the
+ // exact number of characters to print the largest possible index.
+ std::string IdxStr = llvm::to_string(CurIndex);
+ OS << " /* " << std::string(NumColsForIdx - IdxStr.size(), ' ') << IdxStr << " */ ";
+ OS << std::string(Indentation, ' ');
+ };
+
+ BeginLine();
for (auto I = Contents.begin(), E = Contents.end(); I != E; ++I) {
bool LineBreakIsNext = false;
const auto &NextI = std::next(I);
@@ -306,11 +320,14 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {
I->emit(OS, LineBreakIsNext, *this);
if (I->Flags & MatchTableRecord::MTRF_LineBreakFollows)
- OS << std::string(Indentation, ' ');
+ BeginLine();
if (I->Flags & MatchTableRecord::MTRF_Outdent)
Indentation -= 2;
+
+ CurIndex += I->size();
}
+ assert(CurIndex == CurrentSize);
OS << "}; // Size: " << CurrentSize << " bytes\n";
}
>From 8285c1b7d08fe3a1121cf051e3be5a2b666c948a Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Wed, 5 Feb 2025 13:11:52 +0100
Subject: [PATCH 2/2] clang-format
---
.../TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index 9083ce7c86a472..6b4cef18245376 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -294,13 +294,14 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {
const unsigned NumColsForIdx = llvm::to_string(CurrentSize).size();
unsigned CurIndex = 0;
- const auto BeginLine = [&](){
+ const auto BeginLine = [&]() {
OS << std::string(BaseIndent, ' ');
// To keep the /* index */ column consistent, pad
// the string at the start so we can always fit the
// exact number of characters to print the largest possible index.
std::string IdxStr = llvm::to_string(CurIndex);
- OS << " /* " << std::string(NumColsForIdx - IdxStr.size(), ' ') << IdxStr << " */ ";
+ OS << " /* " << std::string(NumColsForIdx - IdxStr.size(), ' ') << IdxStr
+ << " */ ";
OS << std::string(Indentation, ' ');
};
More information about the llvm-commits
mailing list