Skip to content

Commit 835576d

Browse files
committed
[GlobalISel] Prefix MatchTable Lines with their Index
Fixes #119177
1 parent 8cb3d7b commit 835576d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,25 @@ MatchTableRecord MatchTable::JumpTarget(unsigned LabelID) {
286286
void MatchTable::emitUse(raw_ostream &OS) const { OS << "MatchTable" << ID; }
287287

288288
void MatchTable::emitDeclaration(raw_ostream &OS) const {
289-
unsigned Indentation = 4;
289+
static constexpr unsigned BaseIndent = 4;
290+
unsigned Indentation = 0;
290291
OS << " constexpr static uint8_t MatchTable" << ID << "[] = {";
291292
LineBreak.emit(OS, true, *this);
292-
OS << std::string(Indentation, ' ');
293293

294+
const unsigned NumColsForIdx = llvm::to_string(CurrentSize).size();
295+
296+
unsigned CurIndex = 0;
297+
const auto BeginLine = [&](){
298+
OS << std::string(BaseIndent, ' ');
299+
// To keep the /* index */ column consistent, pad
300+
// the string at the start so we can always fit the
301+
// exact number of characters to print the largest possible index.
302+
std::string IdxStr = llvm::to_string(CurIndex);
303+
OS << " /* " << std::string(NumColsForIdx - IdxStr.size(), ' ') << IdxStr << " */ ";
304+
OS << std::string(Indentation, ' ');
305+
};
306+
307+
BeginLine();
294308
for (auto I = Contents.begin(), E = Contents.end(); I != E; ++I) {
295309
bool LineBreakIsNext = false;
296310
const auto &NextI = std::next(I);
@@ -306,11 +320,14 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {
306320

307321
I->emit(OS, LineBreakIsNext, *this);
308322
if (I->Flags & MatchTableRecord::MTRF_LineBreakFollows)
309-
OS << std::string(Indentation, ' ');
323+
BeginLine();
310324

311325
if (I->Flags & MatchTableRecord::MTRF_Outdent)
312326
Indentation -= 2;
327+
328+
CurIndex += I->size();
313329
}
330+
assert(CurIndex == CurrentSize);
314331
OS << "}; // Size: " << CurrentSize << " bytes\n";
315332
}
316333

0 commit comments

Comments
 (0)