[llvm-branch-commits] [llvm] [KeyInstr] Merge atoms in DILocation::getMergedLocation (PR #133480)
Stephen Tozer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 8 06:00:09 PDT 2025
================
@@ -226,8 +230,44 @@ DILocation *DILocation::getMergedLocation(DILocation *LocA, DILocation *LocB) {
bool SameCol = L1->getColumn() == L2->getColumn();
unsigned Line = SameLine ? L1->getLine() : 0;
unsigned Col = SameLine && SameCol ? L1->getColumn() : 0;
-
- return DILocation::get(C, Line, Col, Scope, InlinedAt);
+ bool IsImplicitCode = L1->isImplicitCode() && L2->isImplicitCode();
+ uint64_t Group = 0;
+ uint64_t Rank = 0;
+ if (SameLine) {
+ if (L1->getAtomGroup() || L2->getAtomGroup()) {
+ // If we're preserving the same matching inlined-at field we can
+ // preserve the atom.
+ if (LocBIA == LocAIA && InlinedAt == LocBIA) {
+ // Deterministically keep the lowest non-zero ranking atom group
+ // number.
+ // FIXME: It would be nice if we could track that an instruction
+ // belongs to two source atoms.
+ bool UseL1Atom = [L1, L2]() {
+ if (L1->getAtomRank() == L2->getAtomRank()) {
+ // Arbitrarily choose the lowest non-zero group number.
+ if (!L1->getAtomGroup() || !L2->getAtomGroup())
+ return !L2->getAtomGroup();
+ return L1->getAtomGroup() < L2->getAtomGroup();
+ }
+ // Choose the lowest non-zero rank.
+ if (!L1->getAtomRank() || !L2->getAtomRank())
+ return !L2->getAtomRank();
+ return L1->getAtomRank() < L2->getAtomRank();
+ }();
+ Group = UseL1Atom ? L1->getAtomGroup() : L2->getAtomGroup();
+ Rank = UseL1Atom ? L1->getAtomRank() : L2->getAtomRank();
+ } else {
+ // If either instruction is part of a source atom, reassign it a new
+ // atom group. This essentially regresses to non-key-instructions
+ // behaviour (now that it's the only instruction in its group it'll
+ // probably get is_stmt applied).
+ Group = C.incNextAtomGroup();
+ Rank = 1;
----------------
SLTozer wrote:
Is this necessary? Since we use `inlinedAt` as part of the tuple alongside `atomGroup`, keeping the group the same would still result in the merged instruction becoming part of a distinct "group" (with `is_stmt` likely applying). Likewise, since we're creating a new group it sounds to me like it would be unnecessary to change the rank?
https://github.com/llvm/llvm-project/pull/133480
More information about the llvm-branch-commits
mailing list