Skip to content

Commit 94774f0

Browse files
committed
Resolve reviewers comment
1 parent aa89b84 commit 94774f0

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ static void constructSeqOffsettoOrigRowMapping(
435435

436436
std::vector<size_t> SeqStartRows;
437437
SeqStartRows.push_back(0);
438-
for (size_t I = 0; I < LT->Rows.size() - 1; ++I)
439-
if (LT->Rows[I].EndSequence)
438+
for (auto [I, Row] : llvm::enumerate(ArrayRef(LT->Rows).drop_back()))
439+
if (Row.EndSequence)
440440
SeqStartRows.push_back(I + 1);
441441

442442
// While SeqOffToOrigRow parsed from CU could be the ground truth,
@@ -468,74 +468,60 @@ static void constructSeqOffsettoOrigRowMapping(
468468
// 0x12 --
469469
// 0x14 15 <- LineTableMapping ground truth
470470

471-
// Dummy last element to make sure StmtAttrIdx and SeqStartIdx always
471+
ArrayRef StmtAttrsRef(StmtAttrs);
472+
ArrayRef SeqStartRowsRef(SeqStartRows);
473+
474+
// Dummy last element to make sure StmtAttrsRef and SeqStartRowsRef always
472475
// run out first.
473476
constexpr size_t DummyKey = UINT64_MAX;
474477
constexpr unsigned DummyVal = UINT32_MAX;
475478
LineTableMapping[DummyKey] = DummyVal;
476479

477-
size_t StmtAttrIdx = 0, SeqStartIdx = 0;
478-
size_t NextSeqOff = 0;
479-
unsigned NextRow = 0;
480-
481-
auto StmtIdxValidAndSmallerThanNext = [&]() {
482-
return StmtAttrIdx < StmtAttrs.size() &&
483-
StmtAttrs[StmtAttrIdx].get() < NextSeqOff;
484-
};
485-
486-
auto SeqStartIdxValidAndSmallerThanNext = [&]() {
487-
return SeqStartIdx < SeqStartRows.size() &&
488-
SeqStartRows[SeqStartIdx] < NextRow;
489-
};
490-
491-
for (auto It : LineTableMapping) {
492-
// More verbosed setup to make sure closure capture works.
493-
NextSeqOff = It.first;
494-
NextRow = It.second;
480+
for (auto [NextSeqOff, NextRow] : LineTableMapping) {
481+
auto StmtAttrSmallerThanNext = [NextSeqOff](const PatchLocation &SA) {
482+
return SA.get() < NextSeqOff;
483+
};
484+
auto SeqStartSmallerThanNext = [NextRow](const size_t &Row) {
485+
return Row < NextRow;
486+
};
495487

496488
// If both StmtAttrs and SeqStartRows points to value not in
497489
// the LineTableMapping yet, we do a dummy one to one mapping and
498490
// move the pointer.
499-
while (StmtIdxValidAndSmallerThanNext() &&
500-
SeqStartIdxValidAndSmallerThanNext()) {
501-
SeqOffToOrigRow[StmtAttrs[StmtAttrIdx].get()] = SeqStartRows[SeqStartIdx];
502-
++StmtAttrIdx;
503-
++SeqStartIdx;
491+
while (!StmtAttrsRef.empty() && !SeqStartRowsRef.empty() &&
492+
StmtAttrSmallerThanNext(StmtAttrsRef.front()) &&
493+
SeqStartSmallerThanNext(SeqStartRowsRef.front())) {
494+
SeqOffToOrigRow[StmtAttrsRef.consume_front().get()] =
495+
SeqStartRowsRef.consume_front();
504496
}
505497
// One of the pointer points to the value at or past Next in the
506498
// LineTableMapping, We move the pointer to re-align with the
507499
// LineTableMapping
508-
while (StmtIdxValidAndSmallerThanNext()) {
509-
++StmtAttrIdx;
510-
}
511-
while (SeqStartIdxValidAndSmallerThanNext()) {
512-
++SeqStartIdx;
513-
}
500+
StmtAttrsRef = StmtAttrsRef.drop_while(StmtAttrSmallerThanNext);
501+
SeqStartRowsRef = SeqStartRowsRef.drop_while(SeqStartSmallerThanNext);
514502
// Use the LineTableMapping's result as the ground truth and move
515503
// on.
516504
if (NextSeqOff != DummyKey) {
517505
SeqOffToOrigRow[NextSeqOff] = NextRow;
518506
}
519-
// It is possible that the first StmtAttrIdx/SeqStartIdx point to
520-
// later entries in LineTableMapping. Therefore we only increment
521-
// the pointers after we validate they are pointing to the `Next`
522-
// entry. e.g.
507+
// Move the pointers if they are pointed at Next.
508+
// It is possible that they point to later entries in LineTableMapping.
509+
// Therefore we only increment the pointers after we validate they are
510+
// pointing to the `Next` entry. e.g.
523511
//
524512
// LineTableMapping
525513
// SeqOff Row
526514
// 0x08 9 <- NextSeqOff/NextRow
527515
// 0x14 15
528516
//
529517
// StmtAttrs SeqStartRows
530-
// 0x14 13 <- StmtAttrIdx/SeqStartIdx
518+
// 0x14 13 <- StmtAttrsRef.front() / SeqStartRowsRef.front()
531519
// 0x16 15
532520
// -- 17
533-
if (StmtAttrIdx < StmtAttrs.size() &&
534-
StmtAttrs[StmtAttrIdx].get() == NextSeqOff)
535-
++StmtAttrIdx;
536-
if (SeqStartIdx < SeqStartRows.size() &&
537-
SeqStartRows[SeqStartIdx] == NextRow)
538-
++SeqStartIdx;
521+
if (!StmtAttrsRef.empty() && StmtAttrsRef.front().get() == NextSeqOff)
522+
StmtAttrsRef.consume_front();
523+
if (!SeqStartRowsRef.empty() && SeqStartRowsRef.front() == NextRow)
524+
SeqStartRowsRef.consume_front();
539525
}
540526
}
541527

0 commit comments

Comments
 (0)