[llvm] [NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (PR #115563)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 12 01:23:33 PST 2024
================
@@ -132,64 +121,30 @@ void DroppedVariableStats::calculateDroppedVarStatsOnFunction(
PassDroppedVariables = false;
}
-void DroppedVariableStats::runAfterPassInvalidated(
- StringRef PassID, const PreservedAnalyses &PA) {
- DebugVariablesStack.pop_back();
- InlinedAts.pop_back();
+void DroppedVariableStatsIR::runOnModule(const Module *M, bool Before) {
+ for (auto &F : *M)
+ runOnFunction(&F, Before);
}
-void DroppedVariableStats::runAfterPass(StringRef PassID, Any IR,
- const PreservedAnalyses &PA) {
- std::string PassLevel;
- std::string FuncOrModName;
- if (auto *M = unwrapIR<Module>(IR)) {
- this->runOnModule(M, false);
- PassLevel = "Module";
- FuncOrModName = M->getName();
- calculateDroppedVarStatsOnModule(M, PassID, FuncOrModName, PassLevel);
- } else if (auto *F = unwrapIR<Function>(IR)) {
- this->runOnFunction(F, false);
- PassLevel = "Function";
- FuncOrModName = F->getName();
- calculateDroppedVarStatsOnFunction(F, PassID, FuncOrModName, PassLevel);
+void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
+ const Module *M, StringRef PassID, std::string FuncOrModName,
+ std::string PassLevel) {
+ for (auto &F : *M) {
+ calculateDroppedVarStatsOnFunction(&F, PassID, FuncOrModName, PassLevel);
}
-
- DebugVariablesStack.pop_back();
- InlinedAts.pop_back();
- return;
}
-bool DroppedVariableStats::isScopeChildOfOrEqualTo(DIScope *Scope,
- const DIScope *DbgValScope) {
- while (Scope != nullptr) {
- if (VisitedScope.find(Scope) == VisitedScope.end()) {
- VisitedScope.insert(Scope);
- if (Scope == DbgValScope) {
- VisitedScope.clear();
- return true;
- }
- Scope = Scope->getScope();
- } else {
- VisitedScope.clear();
- return false;
- }
- }
- return false;
-}
+void DroppedVariableStatsIR::registerCallbacks(
+ PassInstrumentationCallbacks &PIC) {
+ if (!DroppedVariableStatsEnabled)
+ return;
-bool DroppedVariableStats::isInlinedAtChildOfOrEqualTo(
- const DILocation *InlinedAt, const DILocation *DbgValInlinedAt) {
- if (DbgValInlinedAt == InlinedAt)
- return true;
- if (!DbgValInlinedAt)
- return false;
- if (!InlinedAt)
- return false;
- auto *IA = InlinedAt;
- while (IA) {
- if (IA == DbgValInlinedAt)
- return true;
- IA = IA->getInlinedAt();
- }
- return false;
-}
+ PIC.registerBeforeNonSkippedPassCallback(
+ [this](StringRef P, Any IR) { return runBeforePass(IR); });
+ PIC.registerAfterPassCallback(
+ [this](StringRef P, Any IR, const PreservedAnalyses &PA) {
+ return runAfterPass(P, IR);
+ });
+ PIC.registerAfterPassInvalidatedCallback(
+ [this](StringRef P, const PreservedAnalyses &PA) { return cleanup(); });
+}
----------------
OCHyams wrote:
nit: whitespace
https://github.com/llvm/llvm-project/pull/115563
More information about the llvm-commits
mailing list