[llvm] Fix performance bug in buildLocationList (PR #109343)
Sriraman Tallam via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 16:22:43 PDT 2024
================
@@ -1824,22 +1821,27 @@ bool DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
RangeMBB = &Asm->MF->front();
else
RangeMBB = Entries.begin()->getInstr()->getParent();
+ auto RangeIt = Asm->MBBSectionRanges.find(RangeMBB->getSectionID());
+ assert(RangeIt != Asm->MBBSectionRanges.end() &&
+ "Range MBB not found in MBBSectionRanges!");
auto *CurEntry = DebugLoc.begin();
auto *NextEntry = std::next(CurEntry);
+ auto NextRangeIt = std::next(RangeIt);
while (NextEntry != DebugLoc.end()) {
- // Get the last machine basic block of this section.
- while (!RangeMBB->isEndSection())
- RangeMBB = RangeMBB->getNextNode();
- if (!RangeMBB->getNextNode())
+ if (NextRangeIt == Asm->MBBSectionRanges.end())
return false;
// CurEntry should end the current section and NextEntry should start
// the next section and the Values must match for these two ranges to be
- // merged.
- if (CurEntry->getEndSym() != RangeMBB->getEndSymbol() ||
- NextEntry->getBeginSym() != RangeMBB->getNextNode()->getSymbol() ||
+ // merged. Do not match the section label end if it is the entry block
+ // section. This is because the end label for the Debug Loc and the
+ // Function end label could be different.
+ if ((RangeIt->second.EndLabel != Asm->getFunctionEnd() &&
+ CurEntry->getEndSym() != RangeIt->second.EndLabel) ||
+ NextEntry->getBeginSym() != NextRangeIt->second.BeginLabel ||
----------------
tmsri wrote:
Basically, MBBSectionRanges stores the ranges for each section. For the entry section, the end label is the Function End Label, Asm->getFunctionEnd(). The entry section is actually the original function section.
Now, take a look at this assembly:
```
.section .text._Z4testv,"ax", at progbits
.globl _Z4testv # -- Begin function _Z4testv
.type _Z4testv, at function
_Z4testv: # @_Z4testv
.Lfunc_begin0:
.loc 0 3 0 # ex4.cc:3:0
# %bb.0: # %entry
pushq %rax
.Ltmp0:
#DEBUG_VALUE: test:i <- 7
.loc 0 7 5 prologue_end # ex4.cc:7:5
callq _Z2f1v at PLT
...
.LBB_END0_0:
.cfi_endproc
.section .text._Z4testv,"ax", at progbits,unique,1
_Z4testv.__part.1: # %if.then
.section .text._Z4testv,"ax", at progbits
.Lfunc_end0:
```
The entry block section uses label ".Lfunc_end0" which is Asm->getFunctionEnd(). There is an additional label that is created immediately after the end of the entry section ".LBB_END0_0" which is what the debug loc uses, like an alias. In this case and this case alone, these two labels won't match even though semantically, they are the same. So, I exclude that match.
CurEntry and entry block are different things. Sorry for the use of the overloaded entry.
https://github.com/llvm/llvm-project/pull/109343
More information about the llvm-commits
mailing list