Skip to content

Commit fd85b9d

Browse files
abhinavgabavmaksimo
authored andcommitted
Revert "Emit correct location lists with basic block sections."
Breaks check-llvm on non-linux, see comments on https://reviews.llvm.org/D85085 This reverts commit caae570 and follow-up commit 1546c52.
1 parent a9c07c1 commit fd85b9d

13 files changed

+39
-775
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,11 @@ void AsmPrinter::emitFunctionBody() {
13571357

13581358
// We must emit temporary symbol for the end of this basic block, if either
13591359
// we have BBLabels enabled or if this basic blocks marks the end of a
1360-
// section.
1360+
// section (except the section containing the entry basic block as the end
1361+
// symbol for that section is CurrentFnEnd).
13611362
if (MF->hasBBLabels() ||
1362-
(MAI->hasDotTypeDotSizeDirective() && MBB.isEndSection()))
1363+
(MAI->hasDotTypeDotSizeDirective() && MBB.isEndSection() &&
1364+
!MBB.sameSection(&MF->front())))
13631365
OutStreamer->emitLabel(MBB.getEndSymbol());
13641366

13651367
if (MBB.isEndSection()) {

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,16 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
290290
// doing that violates the ranges that are calculated in the history map.
291291
// However, we currently do not emit debug values for constant arguments
292292
// directly at the start of the function, so this code is still useful.
293+
// FIXME: If the first mention of an argument is in a unique section basic
294+
// block, we cannot always assign the CurrentFnBeginLabel as it lies in a
295+
// different section. Temporarily, we disable generating loc list
296+
// information or DW_AT_const_value when the block is in a different
297+
// section.
293298
const DILocalVariable *DIVar =
294299
Entries.front().getInstr()->getDebugVariable();
295300
if (DIVar->isParameter() &&
296-
getDISubprogram(DIVar->getScope())->describes(&MF->getFunction())) {
301+
getDISubprogram(DIVar->getScope())->describes(&MF->getFunction()) &&
302+
Entries.front().getInstr()->getParent()->sameSection(&MF->front())) {
297303
if (!IsDescribedByReg(Entries.front().getInstr()))
298304
LabelsBeforeInsn[Entries.front().getInstr()] = Asm->getFunctionBegin();
299305
if (Entries.front().getInstr()->getDebugExpression()->isFragment()) {
@@ -379,25 +385,22 @@ void DebugHandlerBase::endInstruction() {
379385

380386
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
381387
LabelsAfterInsn.find(CurMI);
388+
CurMI = nullptr;
382389

383-
// No label needed or label already assigned.
384-
if (I == LabelsAfterInsn.end() || I->second) {
385-
CurMI = nullptr;
390+
// No label needed.
391+
if (I == LabelsAfterInsn.end())
386392
return;
387-
}
388393

389-
// We need a label after this instruction. With basic block sections, just
390-
// use the end symbol of the section if this is the last instruction of the
391-
// section. This reduces the need for an additional label and also helps
392-
// merging ranges.
393-
if (CurMI->getParent()->isEndSection() && CurMI->getNextNode() == nullptr) {
394-
PrevLabel = CurMI->getParent()->getEndSymbol();
395-
} else if (!PrevLabel) {
394+
// Label already assigned.
395+
if (I->second)
396+
return;
397+
398+
// We need a label after this instruction.
399+
if (!PrevLabel) {
396400
PrevLabel = MMI->getContext().createTempSymbol();
397401
Asm->OutStreamer->emitLabel(PrevLabel);
398402
}
399403
I->second = PrevLabel;
400-
CurMI = nullptr;
401404
}
402405

403406
void DebugHandlerBase::endFunction(const MachineFunction *MF) {

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,30 +1741,7 @@ bool DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
17411741
SmallVector<DbgValueLoc, 4> Values;
17421742
for (auto &R : OpenRanges)
17431743
Values.push_back(R.second);
1744-
1745-
// With Basic block sections, it is posssible that the StartLabel and the
1746-
// Instr are not in the same section. This happens when the StartLabel is
1747-
// the function begin label and the dbg value appears in a basic block
1748-
// that is not the entry. In this case, the range needs to be split to
1749-
// span each individual section in the range from StartLabel to EndLabel.
1750-
if (Asm->MF->hasBBSections() && StartLabel == Asm->getFunctionBegin() &&
1751-
!Instr->getParent()->sameSection(&Asm->MF->front())) {
1752-
const MCSymbol *BeginSectionLabel = StartLabel;
1753-
1754-
for (const MachineBasicBlock &MBB : *Asm->MF) {
1755-
if (MBB.isBeginSection() && &MBB != &Asm->MF->front())
1756-
BeginSectionLabel = MBB.getSymbol();
1757-
1758-
if (MBB.sameSection(Instr->getParent())) {
1759-
DebugLoc.emplace_back(BeginSectionLabel, EndLabel, Values);
1760-
break;
1761-
}
1762-
if (MBB.isEndSection())
1763-
DebugLoc.emplace_back(BeginSectionLabel, MBB.getEndSymbol(), Values);
1764-
}
1765-
} else {
1766-
DebugLoc.emplace_back(StartLabel, EndLabel, Values);
1767-
}
1744+
DebugLoc.emplace_back(StartLabel, EndLabel, Values);
17681745

17691746
// Attempt to coalesce the ranges of two otherwise identical
17701747
// DebugLocEntries.
@@ -1781,46 +1758,8 @@ bool DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
17811758
DebugLoc.pop_back();
17821759
}
17831760

1784-
if (!isSafeForSingleLocation ||
1785-
!validThroughout(LScopes, StartDebugMI, EndMI, getInstOrdering()))
1786-
return false;
1787-
1788-
if (DebugLoc.size() == 1)
1789-
return true;
1790-
1791-
if (!Asm->MF->hasBBSections())
1792-
return false;
1793-
1794-
// Check here to see if loclist can be merged into a single range. If not,
1795-
// we must keep the split loclists per section. This does exactly what
1796-
// MergeRanges does without sections. We don't actually merge the ranges
1797-
// as the split ranges must be kept intact if this cannot be collapsed
1798-
// into a single range.
1799-
const MachineBasicBlock *RangeMBB = nullptr;
1800-
if (DebugLoc[0].getBeginSym() == Asm->getFunctionBegin())
1801-
RangeMBB = &Asm->MF->front();
1802-
else
1803-
RangeMBB = Entries.begin()->getInstr()->getParent();
1804-
auto *CurEntry = DebugLoc.begin();
1805-
auto *NextEntry = std::next(CurEntry);
1806-
while (NextEntry != DebugLoc.end()) {
1807-
// Get the last machine basic block of this section.
1808-
while (!RangeMBB->isEndSection())
1809-
RangeMBB = RangeMBB->getNextNode();
1810-
if (!RangeMBB->getNextNode())
1811-
return false;
1812-
// CurEntry should end the current section and NextEntry should start
1813-
// the next section and the Values must match for these two ranges to be
1814-
// merged.
1815-
if (CurEntry->getEndSym() != RangeMBB->getEndSymbol() ||
1816-
NextEntry->getBeginSym() != RangeMBB->getNextNode()->getSymbol() ||
1817-
CurEntry->getValues() != NextEntry->getValues())
1818-
return false;
1819-
RangeMBB = RangeMBB->getNextNode();
1820-
CurEntry = NextEntry;
1821-
NextEntry = std::next(CurEntry);
1822-
}
1823-
return true;
1761+
return DebugLoc.size() == 1 && isSafeForSingleLocation &&
1762+
validThroughout(LScopes, StartDebugMI, EndMI, getInstOrdering());
18241763
}
18251764

18261765
DbgEntity *DwarfDebug::createConcreteEntity(DwarfCompileUnit &TheCU,

llvm/test/DebugInfo/X86/basic-block-sections-debug-loc-const-value-1.ll

Lines changed: 0 additions & 82 deletions
This file was deleted.

llvm/test/DebugInfo/X86/basic-block-sections-debug-loc-const-value-2.ll

Lines changed: 0 additions & 60 deletions
This file was deleted.

llvm/test/DebugInfo/X86/basic-block-sections-debug-loc-split-range.ll

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)