[llvm] Add a pass to collect dropped variable statistics (PR #102233)
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 09:32:46 PDT 2024
================
@@ -2441,6 +2447,84 @@ void DotCfgChangeReporter::registerCallbacks(
}
}
+void DroppedVariableStats::registerCallbacks(
+ PassInstrumentationCallbacks &PIC) {
+ if (!DroppedVarStats)
+ return;
+
+ PIC.registerBeforeNonSkippedPassCallback(
+ [this](StringRef P, Any IR) { return this->runBeforePass(P, IR); });
+ PIC.registerAfterPassCallback(
+ [this](StringRef P, Any IR, const PreservedAnalyses &PA) {
+ return this->runAfterPass(P, IR, PA);
+ });
+}
+
+void DroppedVariableStats::runBeforePass(StringRef PassID, Any IR) {
+ DebugVariablesBefore.push_back(
+ std::make_pair(llvm::DenseSet<VarID>(), PassID.str()));
+ DebugVariablesAfter.push_back(
+ std::make_pair(llvm::DenseSet<VarID>(), PassID.str()));
+ if (auto *M = unwrapIR<Module>(IR))
+ return this->runOnModule(M, true);
+ if (auto *F = unwrapIR<Function>(IR))
+ return this->runOnFunction(F, true);
+ return;
+}
+
+void DroppedVariableStats::runOnFunction(const Function *F, bool Before) {
+ auto &DebugVariables = Before ? DebugVariablesBefore : DebugVariablesAfter;
----------------
felipepiovezan wrote:
```
void DroppedVariableStats::runOnFunction(const Function *F, bool Before) {
- auto &DebugVariables = Before ? DebugVariablesBefore : DebugVariablesAfter;
+ auto &[VarIDs, PassName] =
+ (Before ? DebugVariablesBefore : DebugVariablesAfter).back();
for (auto &BB : *F) {
for (const Instruction &I : BB) {
for (DbgRecord &DR : I.getDbgRecordRange()) {
@@ -2485,7 +2486,7 @@ void DroppedVariableStats::runOnFunction(const Function *F, bool Before) {
unsigned Col = DbgLoc->getColumn();
VarID Key(cast<DILocalScope>(DbgLoc.getScope()), UniqueName, Line,
Col);
- DebugVariables.back().first.insert(Key);
+ VarIDs.insert(Key);
}
}
}
```
https://github.com/llvm/llvm-project/pull/102233
More information about the llvm-commits
mailing list