diff options
author | Stephen Tozer <stephen.tozer@sony.com> | 2025-06-12 15:06:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-12 14:06:27 +0100 |
commit | a08a831515919bcc384b453799f33bc97860c73b (patch) | |
tree | 43c8fe486bd0c15ffa073d7fee8eebea06bb6362 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 36ac72f4e3e4752f85c16363d630f4cfbd682e48 (diff) | |
download | llvm-a08a831515919bcc384b453799f33bc97860c73b.zip llvm-a08a831515919bcc384b453799f33bc97860c73b.tar.gz llvm-a08a831515919bcc384b453799f33bc97860c73b.tar.bz2 |
[DLCov][NFC] Propagate annotated DebugLocs through transformations (#138047)
Part of the coverage-tracking feature, following #107279.
In order for DebugLoc coverage testing to work, we firstly have to set
annotations for intentionally-empty DebugLocs, and secondly we have to
ensure that we do not drop these annotations as we propagate DebugLocs
throughout compilation. As the annotations exist as part of the DebugLoc
class, and not the underlying DILocation, they will not survive a
DebugLoc->DILocation->DebugLoc roundtrip. Therefore this patch modifies
a number of places in the compiler to propagate DebugLocs directly
rather than via the underlying DILocation. This has no effect on the
output of normal builds; it only ensures that during coverage builds, we
do not drop incorrectly annotations and therefore create false
positives.
The bulk of these changes are in replacing
DILocation::getMergedLocation(s) with a DebugLoc equivalent, and in
changing the IRBuilder to store a DebugLoc directly rather than storing
DILocations in its general Metadata array. We also use a new function,
`DebugLoc::orElse`, which selects the "best" DebugLoc out of a pair
(valid location > annotated > empty), preferring the current DebugLoc on
a tie - this encapsulates the existing behaviour at a few sites where we
_may_ assign a DebugLoc to an existing instruction, while extending the
logic to handle annotation DebugLocs at the same time.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index f67a641..0980f0e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2095,11 +2095,11 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf( // Ensure terminator gets a debug location, even an unknown one, in case // it involves inlinable calls. - SmallVector<DILocation *, 4> Locs; + SmallVector<DebugLoc, 4> Locs; Locs.push_back(I1->getDebugLoc()); for (auto *OtherSuccTI : OtherSuccTIs) Locs.push_back(OtherSuccTI->getDebugLoc()); - NT->setDebugLoc(DILocation::getMergedLocations(Locs)); + NT->setDebugLoc(DebugLoc::getMergedLocations(Locs)); // PHIs created below will adopt NT's merged DebugLoc. IRBuilder<NoFolder> Builder(NT); @@ -2896,7 +2896,7 @@ static void mergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes, MergedDebugLoc = II->getDebugLoc(); else MergedDebugLoc = - DILocation::getMergedLocation(MergedDebugLoc, II->getDebugLoc()); + DebugLoc::getMergedLocation(MergedDebugLoc, II->getDebugLoc()); // And replace the old `invoke` with an unconditionally branch // to the block with the merged `invoke`. |