Skip to content

Commit 12903fb

Browse files
[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.
1 parent e8811ad commit 12903fb

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

llvm/include/llvm/Passes/DroppedVariableStatsIR.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
2828
DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
2929
: llvm::DroppedVariableStats(DroppedVarStatsEnabled) {}
3030

31-
void runBeforePass(Any IR) {
31+
void runBeforePass(StringRef P, Any IR) {
3232
setup();
3333
if (const auto *M = unwrapIR<Module>(IR))
34-
return this->runOnModule(M, true);
34+
return this->runOnModule(P, M, true);
3535
if (const auto *F = unwrapIR<Function>(IR))
36-
return this->runOnFunction(F, true);
36+
return this->runOnFunction(P, F, true);
3737
}
3838

3939
void runAfterPass(StringRef P, Any IR) {
@@ -50,19 +50,19 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
5050
const Function *Func;
5151

5252
void runAfterPassFunction(StringRef PassID, const Function *F) {
53-
runOnFunction(F, false);
53+
runOnFunction(PassID, F, false);
5454
calculateDroppedVarStatsOnFunction(F, PassID, F->getName().str(),
5555
"Function");
5656
}
5757

5858
void runAfterPassModule(StringRef PassID, const Module *M) {
59-
runOnModule(M, false);
59+
runOnModule(PassID, M, false);
6060
calculateDroppedVarStatsOnModule(M, PassID, M->getName().str(), "Module");
6161
}
6262
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
6363
/// after a pass has run to facilitate dropped variable calculation for an
6464
/// llvm::Function.
65-
void runOnFunction(const Function *F, bool Before);
65+
void runOnFunction(StringRef PassID, const Function *F, bool Before);
6666
/// Iterate over all Instructions in a Function and report any dropped debug
6767
/// information.
6868
void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
@@ -71,7 +71,7 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
7171
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
7272
/// after a pass has run to facilitate dropped variable calculation for an
7373
/// llvm::Module. Calls runOnFunction on every Function in the Module.
74-
void runOnModule(const Module *M, bool Before);
74+
void runOnModule(StringRef PassID, const Module *M, bool Before);
7575
/// Iterate over all Functions in a Module and report any dropped debug
7676
/// information. Will call calculateDroppedVarStatsOnFunction on every
7777
/// Function.

llvm/lib/Passes/DroppedVariableStatsIR.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
using namespace llvm;
1717

18-
void DroppedVariableStatsIR::runOnFunction(const Function *F, bool Before) {
18+
void DroppedVariableStatsIR::runOnFunction(StringRef PassID, const Function *F,
19+
bool Before) {
1920
auto &DebugVariables = DebugVariablesStack.back()[F];
2021
auto FuncName = F->getName();
2122
Func = F;
@@ -32,9 +33,11 @@ void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
3233
PassLevel, Func);
3334
}
3435

35-
void DroppedVariableStatsIR::runOnModule(const Module *M, bool Before) {
36-
for (auto &F : *M)
37-
runOnFunction(&F, Before);
36+
void DroppedVariableStatsIR::runOnModule(StringRef PassID, const Module *M,
37+
bool Before) {
38+
for (auto &F : *M) {
39+
runOnFunction(PassID, &F, Before);
40+
}
3841
}
3942

4043
void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
@@ -51,7 +54,7 @@ void DroppedVariableStatsIR::registerCallbacks(
5154
return;
5255

5356
PIC.registerBeforeNonSkippedPassCallback(
54-
[this](StringRef P, Any IR) { return runBeforePass(IR); });
57+
[this](StringRef P, Any IR) { return runBeforePass(P, IR); });
5558
PIC.registerAfterPassCallback(
5659
[this](StringRef P, Any IR, const PreservedAnalyses &PA) {
5760
return runAfterPass(P, IR);

llvm/unittests/IR/DroppedVariableStatsIRTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TEST(DroppedVariableStatsIR, BothDeleted) {
7979
ASSERT_TRUE(M);
8080

8181
DroppedVariableStatsIR Stats(true);
82-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
82+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
8383

8484
// This loop simulates an IR pass that drops debug information.
8585
for (auto &F : *M) {
@@ -134,7 +134,7 @@ TEST(DroppedVariableStatsIR, DbgValLost) {
134134
ASSERT_TRUE(M);
135135

136136
DroppedVariableStatsIR Stats(true);
137-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
137+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
138138

139139
// This loop simulates an IR pass that drops debug information.
140140
for (auto &F : *M) {
@@ -189,7 +189,7 @@ TEST(DroppedVariableStatsIR, UnrelatedScopes) {
189189
ASSERT_TRUE(M);
190190

191191
DroppedVariableStatsIR Stats(true);
192-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
192+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
193193

194194
// This loop simulates an IR pass that drops debug information.
195195
for (auto &F : *M) {
@@ -244,7 +244,7 @@ TEST(DroppedVariableStatsIR, ChildScopes) {
244244
ASSERT_TRUE(M);
245245

246246
DroppedVariableStatsIR Stats(true);
247-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
247+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
248248

249249
// This loop simulates an IR pass that drops debug information.
250250
for (auto &F : *M) {
@@ -300,7 +300,7 @@ TEST(DroppedVariableStatsIR, InlinedAt) {
300300
ASSERT_TRUE(M);
301301

302302
DroppedVariableStatsIR Stats(true);
303-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
303+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
304304

305305
// This loop simulates an IR pass that drops debug information.
306306
for (auto &F : *M) {
@@ -356,7 +356,7 @@ TEST(DroppedVariableStatsIR, InlinedAtShared) {
356356
ASSERT_TRUE(M);
357357

358358
DroppedVariableStatsIR Stats(true);
359-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
359+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
360360

361361
// This loop simulates an IR pass that drops debug information.
362362
for (auto &F : *M) {
@@ -413,7 +413,7 @@ TEST(DroppedVariableStatsIR, InlinedAtChild) {
413413
ASSERT_TRUE(M);
414414

415415
DroppedVariableStatsIR Stats(true);
416-
Stats.runBeforePass(llvm::Any(const_cast<const llvm::Module *>(M.get())));
416+
Stats.runBeforePass("", llvm::Any(const_cast<const llvm::Module *>(M.get())));
417417

418418
// This loop simulates an IR pass that drops debug information.
419419
for (auto &F : *M) {

0 commit comments

Comments
 (0)