[llvm] 12903fb - [NFC] Include PassID for runBeforePass children.
Shubham Sandeep Rastogi via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 19:13:12 PST 2025
Author: Shubham Sandeep Rastogi
Date: 2025-01-21T19:12:55-08:00
New Revision: 12903fb3c73ad549c89585097f24d8b9952d849c
URL: https://github.com/llvm/llvm-project/commit/12903fb3c73ad549c89585097f24d8b9952d849c
DIFF: https://github.com/llvm/llvm-project/commit/12903fb3c73ad549c89585097f24d8b9952d849c.diff
LOG: [NFC] Include PassID for runBeforePass children.
Debugging the dropped variable statistics for large LLVM IR files can be
made easier if the functions called before an optimization pass is run
includes the PassID of the pass that will be run after statistics
metrics are collected. This patch adds that support.
Added:
Modified:
llvm/include/llvm/Passes/DroppedVariableStatsIR.h
llvm/lib/Passes/DroppedVariableStatsIR.cpp
llvm/unittests/IR/DroppedVariableStatsIRTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Passes/DroppedVariableStatsIR.h b/llvm/include/llvm/Passes/DroppedVariableStatsIR.h
index 99701e8c8e1c05..18847b5c1ead83 100644
--- a/llvm/include/llvm/Passes/DroppedVariableStatsIR.h
+++ b/llvm/include/llvm/Passes/DroppedVariableStatsIR.h
@@ -28,12 +28,12 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
: llvm::DroppedVariableStats(DroppedVarStatsEnabled) {}
- void runBeforePass(Any IR) {
+ void runBeforePass(StringRef P, Any IR) {
setup();
if (const auto *M = unwrapIR<Module>(IR))
- return this->runOnModule(M, true);
+ return this->runOnModule(P, M, true);
if (const auto *F = unwrapIR<Function>(IR))
- return this->runOnFunction(F, true);
+ return this->runOnFunction(P, F, true);
}
void runAfterPass(StringRef P, Any IR) {
@@ -50,19 +50,19 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
const Function *Func;
void runAfterPassFunction(StringRef PassID, const Function *F) {
- runOnFunction(F, false);
+ runOnFunction(PassID, F, false);
calculateDroppedVarStatsOnFunction(F, PassID, F->getName().str(),
"Function");
}
void runAfterPassModule(StringRef PassID, const Module *M) {
- runOnModule(M, false);
+ runOnModule(PassID, M, false);
calculateDroppedVarStatsOnModule(M, PassID, M->getName().str(), "Module");
}
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
/// after a pass has run to facilitate dropped variable calculation for an
/// llvm::Function.
- void runOnFunction(const Function *F, bool Before);
+ void runOnFunction(StringRef PassID, const Function *F, bool Before);
/// Iterate over all Instructions in a Function and report any dropped debug
/// information.
void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
@@ -71,7 +71,7 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
/// after a pass has run to facilitate dropped variable calculation for an
/// llvm::Module. Calls runOnFunction on every Function in the Module.
- void runOnModule(const Module *M, bool Before);
+ void runOnModule(StringRef PassID, const Module *M, bool Before);
/// Iterate over all Functions in a Module and report any dropped debug
/// information. Will call calculateDroppedVarStatsOnFunction on every
/// Function.
diff --git a/llvm/lib/Passes/DroppedVariableStatsIR.cpp b/llvm/lib/Passes/DroppedVariableStatsIR.cpp
index 496a47e71182e9..e1c277e87efb35 100644
--- a/llvm/lib/Passes/DroppedVariableStatsIR.cpp
+++ b/llvm/lib/Passes/DroppedVariableStatsIR.cpp
@@ -15,7 +15,8 @@
using namespace llvm;
-void DroppedVariableStatsIR::runOnFunction(const Function *F, bool Before) {
+void DroppedVariableStatsIR::runOnFunction(StringRef PassID, const Function *F,
+ bool Before) {
auto &DebugVariables = DebugVariablesStack.back()[F];
auto FuncName = F->getName();
Func = F;
@@ -32,9 +33,11 @@ void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
PassLevel, Func);
}
-void DroppedVariableStatsIR::runOnModule(const Module *M, bool Before) {
- for (auto &F : *M)
- runOnFunction(&F, Before);
+void DroppedVariableStatsIR::runOnModule(StringRef PassID, const Module *M,
+ bool Before) {
+ for (auto &F : *M) {
+ runOnFunction(PassID, &F, Before);
+ }
}
void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
@@ -51,7 +54,7 @@ void DroppedVariableStatsIR::registerCallbacks(
return;
PIC.registerBeforeNonSkippedPassCallback(
- [this](StringRef P, Any IR) { return runBeforePass(IR); });
+ [this](StringRef P, Any IR) { return runBeforePass(P, IR); });
PIC.registerAfterPassCallback(
[this](StringRef P, Any IR, const PreservedAnalyses &PA) {
return runAfterPass(P, IR);
diff --git a/llvm/unittests/IR/DroppedVariableStatsIRTest.cpp b/llvm/unittests/IR/DroppedVariableStatsIRTest.cpp
index 34803a9771850a..72d8373fc45dfa 100644
--- a/llvm/unittests/IR/DroppedVariableStatsIRTest.cpp
+++ b/llvm/unittests/IR/DroppedVariableStatsIRTest.cpp
@@ -79,7 +79,7 @@ TEST(DroppedVariableStatsIR, BothDeleted) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -134,7 +134,7 @@ TEST(DroppedVariableStatsIR, DbgValLost) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -189,7 +189,7 @@ TEST(DroppedVariableStatsIR, UnrelatedScopes) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -244,7 +244,7 @@ TEST(DroppedVariableStatsIR, ChildScopes) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -300,7 +300,7 @@ TEST(DroppedVariableStatsIR, InlinedAt) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -356,7 +356,7 @@ TEST(DroppedVariableStatsIR, InlinedAtShared) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
@@ -413,7 +413,7 @@ TEST(DroppedVariableStatsIR, InlinedAtChild) {
ASSERT_TRUE(M);
DroppedVariableStatsIR Stats(true);
- Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
+ Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
// This loop simulates an IR pass that drops debug information.
for (auto &F : *M) {
More information about the llvm-commits
mailing list