[llvm] [WebAssembly] Avoid scanning unrelated debug values (NFCI) (PR #218378)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 21:51:43 PDT 2026
================
@@ -79,44 +88,65 @@ WebAssemblyDebugValueManager::getSinkableDebugValues(
MachineInstr *Insert) const {
if (DbgValues.empty())
return {};
- // DBG_VALUEs between Def and Insert
+
+ // If Def and Insert are in different BBs, we only handle a simple case in
+ // which Insert's BB is a successor of Def's BB.
+ if (Def->getParent() != Insert->getParent() &&
+ !Def->getParent()->isSuccessor(Insert->getParent()))
+ return {};
+
+ SmallDenseSet<std::pair<const DILocalVariable *, const DILocation *>, 4>
+ OurVars;
+ for (MachineInstr *DV : DbgValues)
+ OurVars.insert({DV->getDebugVariable(), DV->getDebugLoc()->getInlinedAt()});
+ auto IsRelevantDbgValue = [&](const MachineInstr &MI) {
+ return MI.isDebugValue() &&
+ OurVars.count(
+ {MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()});
+ };
----------------
aheejin wrote:
Is this pre-filtering mainly to reduce the size of `DbgValuesInBetween`? If so, it would be nice to write this in the PR description too.
---
And is there a reason we only comapre `getDebugVariable` and `getInlinedAt` here, given that we later compare all three (`getDebugVariable`, `getInlinedAt`, and `getDebugExpression`) later in the loop like this?
```cpp
DebugVariable Var(DV->getDebugVariable(), DV->getDebugExpression(),
DV->getDebugLoc()->getInlinedAt());
auto It = SeenDbgVarToDbgValues.find(Var);
if (It == SeenDbgVarToDbgValues.end()) {
SinkableDbgValues.push_back(DV);
continue;
}
```
How about we just create `OurVars` like
```cpp
SmallDenseSet<DebugVariable, 4> OurVars;
for (MachineInstr *DV : DbgValues)
OurVars.insert(DebugVariable(DV->getDebugVariable(), DV->getDebugExpression(),
DV->getDebugLoc()->getInlinedAt()));
```
and later we can do like
```cpp
if (OurVars.count(Var) && !llvm::is_contained(DbgValues, &MI))
SeenDbgVarToDbgValues[Var].push_back(&MI);
```
https://github.com/llvm/llvm-project/pull/218378
More information about the llvm-commits
mailing list