196 changes: 196 additions & 0 deletions llvm/lib/CodeGen/DroppedVariableStats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
///===- DroppedVariableStats.cpp ------------------------------------------===//
///
/// Part of the LLVM Project, under the Apache License v2.0 with LLVM
/// Exceptions. See https://llvm.org/LICENSE.txt for license information.
/// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
///
///===---------------------------------------------------------------------===//
/// \file
/// Dropped Variable Statistics for Debug Information. Reports any number
/// of #dbg_value that get dropped due to an optimization pass.
///
///===---------------------------------------------------------------------===//

#include "llvm/CodeGen/DroppedVariableStats.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"

using namespace llvm;

DroppedVariableStats::~DroppedVariableStats() {}

bool DroppedVariableStats::isScopeChildOfOrEqualTo(const 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;
}

bool DroppedVariableStats::isInlinedAtChildOfOrEqualTo(
const DILocation *InlinedAt, const DILocation *DbgValInlinedAt) {
if (DbgValInlinedAt == InlinedAt)
return true;
if (!DbgValInlinedAt)
return false;
auto *IA = InlinedAt;
while (IA) {
if (IA == DbgValInlinedAt)
return true;
IA = IA->getInlinedAt();
}
return false;
}

void DroppedVariableStats::calculateDroppedStatsAndPrint(
DebugVariables &DbgVariables, StringRef FuncName, StringRef PassID,
StringRef FuncOrModName, StringRef PassLevel, const Function *Func) {
unsigned DroppedCount = 0;
DenseSet<VarID> &DebugVariablesBeforeSet = DbgVariables.DebugVariablesBefore;
DenseSet<VarID> &DebugVariablesAfterSet = DbgVariables.DebugVariablesAfter;
DenseMap<VarID, DILocation *> &InlinedAtsMap = InlinedAts.back()[FuncName];
// Find an Instruction that shares the same scope as the dropped #dbg_value or
// has a scope that is the child of the scope of the #dbg_value, and has an
// inlinedAt equal to the inlinedAt of the #dbg_value or it's inlinedAt chain
// contains the inlinedAt of the #dbg_value, if such an Instruction is found,
// debug information is dropped.
for (VarID Var : DebugVariablesBeforeSet) {
if (DebugVariablesAfterSet.contains(Var))
continue;
visitEveryInstruction(DroppedCount, InlinedAtsMap, Var);
removeVarFromAllSets(Var, Func);
}
if (DroppedCount > 0) {
llvm::outs() << PassLevel << ", " << PassID << ", " << DroppedCount << ", "
<< FuncOrModName << "\n";
PassDroppedVariables = true;
} else
PassDroppedVariables = false;
}

bool DroppedVariableStats::updateDroppedCount(
DILocation *DbgLoc, const DIScope *Scope, const DIScope *DbgValScope,
DenseMap<VarID, DILocation *> &InlinedAtsMap, VarID Var,
unsigned &DroppedCount) {

// If the Scope is a child of, or equal to the DbgValScope and is inlined at
// the Var's InlinedAt location, return true to signify that the Var has been
// dropped.
if (isScopeChildOfOrEqualTo(Scope, DbgValScope))
if (isInlinedAtChildOfOrEqualTo(DbgLoc->getInlinedAt(),
InlinedAtsMap[Var])) {
// Found another instruction in the variable's scope, so there exists a
// break point at which the variable could be observed. Count it as
// dropped.
DroppedCount++;
return true;
}
return false;
}

void DroppedVariableStats::run(DebugVariables &DbgVariables, StringRef FuncName,
bool Before) {
auto &VarIDSet = (Before ? DbgVariables.DebugVariablesBefore
: DbgVariables.DebugVariablesAfter);
auto &InlinedAtsMap = InlinedAts.back();
if (Before)
InlinedAtsMap.try_emplace(FuncName, DenseMap<VarID, DILocation *>());
VarIDSet = DenseSet<VarID>();
visitEveryDebugRecord(VarIDSet, InlinedAtsMap, FuncName, Before);
}

void DroppedVariableStats::populateVarIDSetAndInlinedMap(
const DILocalVariable *DbgVar, DebugLoc DbgLoc, DenseSet<VarID> &VarIDSet,
DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
StringRef FuncName, bool Before) {
VarID Key{DbgVar->getScope(), DbgLoc->getInlinedAtScope(), DbgVar};
VarIDSet.insert(Key);
if (Before)
InlinedAtsMap[FuncName].try_emplace(Key, DbgLoc.getInlinedAt());
}

void DroppedVariableStatsIR::runOnFunction(const Function *F, bool Before) {
auto &DebugVariables = DebugVariablesStack.back()[F];
auto FuncName = F->getName();
Func = F;
run(DebugVariables, FuncName, Before);
}

void DroppedVariableStatsIR::calculateDroppedVarStatsOnFunction(
const Function *F, StringRef PassID, StringRef FuncOrModName,
StringRef PassLevel) {
Func = F;
StringRef FuncName = F->getName();
DebugVariables &DbgVariables = DebugVariablesStack.back()[F];
calculateDroppedStatsAndPrint(DbgVariables, FuncName, PassID, FuncOrModName,
PassLevel, Func);
}

void DroppedVariableStatsIR::runOnModule(const Module *M, bool Before) {
for (auto &F : *M)
runOnFunction(&F, Before);
}

void DroppedVariableStatsIR::calculateDroppedVarStatsOnModule(
const Module *M, StringRef PassID, StringRef FuncOrModName,
StringRef PassLevel) {
for (auto &F : *M) {
calculateDroppedVarStatsOnFunction(&F, PassID, FuncOrModName, PassLevel);
}
}

void DroppedVariableStatsIR::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
if (!DroppedVariableStatsEnabled)
return;

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(); });
}

void DroppedVariableStatsIR::visitEveryInstruction(
unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,
VarID Var) {
const DIScope *DbgValScope = std::get<0>(Var);
for (const auto &I : instructions(Func)) {
auto *DbgLoc = I.getDebugLoc().get();
if (!DbgLoc)
continue;
if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope,
InlinedAtsMap, Var, DroppedCount))
break;
}
}

void DroppedVariableStatsIR::visitEveryDebugRecord(
DenseSet<VarID> &VarIDSet,
DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
StringRef FuncName, bool Before) {
for (const auto &I : instructions(Func)) {
for (DbgRecord &DR : I.getDbgRecordRange()) {
if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
auto *DbgVar = Dbg->getVariable();
auto DbgLoc = DR.getDebugLoc();
populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
FuncName, Before);
}
}
}
}
178 changes: 2 additions & 176 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ StandardInstrumentations::StandardInstrumentations(
PrintChanged == ChangePrinter::ColourDiffVerbose ||
PrintChanged == ChangePrinter::ColourDiffQuiet),
WebsiteChangeReporter(PrintChanged == ChangePrinter::DotCfgVerbose),
Verify(DebugLogging), DroppedStats(DroppedVarStats),
Verify(DebugLogging), DroppedStatsIR(DroppedVarStats),
VerifyEach(VerifyEach) {}

PrintCrashIRInstrumentation *PrintCrashIRInstrumentation::CrashReporter =
Expand Down Expand Up @@ -2523,180 +2523,6 @@ void PrintCrashIRInstrumentation::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);
});
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef P, const PreservedAnalyses &PA) {
return this->runAfterPassInvalidated(P, PA);
});
}

void DroppedVariableStats::runBeforePass(StringRef PassID, Any IR) {
DebugVariablesStack.push_back({DenseMap<const Function *, DebugVariables>()});
InlinedAts.push_back({DenseMap<StringRef, DenseMap<VarID, DILocation *>>()});
if (auto *M = unwrapIR<Module>(IR))
return this->runOnModule(M, true);
if (auto *F = unwrapIR<Function>(IR))
return this->runOnFunction(F, true);
}

void DroppedVariableStats::runOnFunction(const Function *F, bool Before) {
auto &DebugVariables = DebugVariablesStack.back()[F];
auto &VarIDSet = (Before ? DebugVariables.DebugVariablesBefore
: DebugVariables.DebugVariablesAfter);
auto &InlinedAtsMap = InlinedAts.back();
auto FuncName = F->getName();
if (Before)
InlinedAtsMap.try_emplace(FuncName, DenseMap<VarID, DILocation *>());
VarIDSet = DenseSet<VarID>();
for (const auto &I : instructions(F)) {
for (DbgRecord &DR : I.getDbgRecordRange()) {
if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
auto *DbgVar = Dbg->getVariable();
auto DbgLoc = DR.getDebugLoc();
VarID Key{DbgVar->getScope(), DbgLoc->getInlinedAtScope(), DbgVar};
VarIDSet.insert(Key);
if (Before)
InlinedAtsMap[FuncName].try_emplace(Key, DbgLoc.getInlinedAt());
}
}
}
}

void DroppedVariableStats::runOnModule(const Module *M, bool Before) {
for (auto &F : *M)
runOnFunction(&F, Before);
}

void DroppedVariableStats::removeVarFromAllSets(VarID Var, const Function *F) {
// Do not remove Var from the last element, it will be popped from the stack.
for (auto &DebugVariablesMap : llvm::drop_end(DebugVariablesStack))
DebugVariablesMap[F].DebugVariablesBefore.erase(Var);
}

void DroppedVariableStats::calculateDroppedVarStatsOnModule(
const Module *M, StringRef PassID, std::string FuncOrModName,
std::string PassLevel) {
for (auto &F : *M) {
calculateDroppedVarStatsOnFunction(&F, PassID, FuncOrModName, PassLevel);
}
}

void DroppedVariableStats::calculateDroppedVarStatsOnFunction(
const Function *F, StringRef PassID, std::string FuncOrModName,
std::string PassLevel) {
unsigned DroppedCount = 0;
StringRef FuncName = F->getName();
DebugVariables &DbgVariables = DebugVariablesStack.back()[F];
DenseSet<VarID> &DebugVariablesBeforeSet = DbgVariables.DebugVariablesBefore;
DenseSet<VarID> &DebugVariablesAfterSet = DbgVariables.DebugVariablesAfter;
DenseMap<VarID, DILocation *> &InlinedAtsMap = InlinedAts.back()[FuncName];
// Find an Instruction that shares the same scope as the dropped #dbg_value or
// has a scope that is the child of the scope of the #dbg_value, and has an
// inlinedAt equal to the inlinedAt of the #dbg_value or it's inlinedAt chain
// contains the inlinedAt of the #dbg_value, if such an Instruction is found,
// debug information is dropped.
for (VarID Var : DebugVariablesBeforeSet) {
if (DebugVariablesAfterSet.contains(Var))
continue;
const DIScope *DbgValScope = std::get<0>(Var);
for (const auto &I : instructions(F)) {
auto *DbgLoc = I.getDebugLoc().get();
if (!DbgLoc)
continue;

auto *Scope = DbgLoc->getScope();
if (isScopeChildOfOrEqualTo(Scope, DbgValScope)) {
if (isInlinedAtChildOfOrEqualTo(DbgLoc->getInlinedAt(),
InlinedAtsMap[Var])) {
// Found another instruction in the variable's scope, so there exists
// a break point at which the variable could be observed. Count it as
// dropped.
DroppedCount++;
break;
}
}
}
removeVarFromAllSets(Var, F);
}
if (DroppedCount > 0) {
llvm::outs() << PassLevel << ", " << PassID << ", " << DroppedCount << ", "
<< FuncOrModName << "\n";
PassDroppedVariables = true;
} else
PassDroppedVariables = false;
}

void DroppedVariableStats::runAfterPassInvalidated(
StringRef PassID, const PreservedAnalyses &PA) {
DebugVariablesStack.pop_back();
InlinedAts.pop_back();
}

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);
}

DebugVariablesStack.pop_back();
InlinedAts.pop_back();
}

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;
}

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;
}

void StandardInstrumentations::registerCallbacks(
PassInstrumentationCallbacks &PIC, ModuleAnalysisManager *MAM) {
PrintIR.registerCallbacks(PIC);
Expand All @@ -2712,7 +2538,7 @@ void StandardInstrumentations::registerCallbacks(
WebsiteChangeReporter.registerCallbacks(PIC);
ChangeTester.registerCallbacks(PIC);
PrintCrashIR.registerCallbacks(PIC);
DroppedStats.registerCallbacks(PIC);
DroppedStatsIR.registerCallbacks(PIC);
if (MAM)
PreservedCFGChecker.registerCallbacks(PIC, *MAM);

Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_llvm_unittest(CodeGenTests
CCStateTest.cpp
DIEHashTest.cpp
DIETest.cpp
DroppedVariableStatsIRTest.cpp
DwarfStringPoolEntryRefTest.cpp
InstrRefLDVTest.cpp
LowLevelTypeTest.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===- unittests/IR/DroppedVariableStatsTest.cpp - TimePassesHandler tests
//----------===//
//===- unittests/IR/DroppedVariableStatsIRTest.cpp ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/AsmParser/Parser.h"
#include "llvm/CodeGen/DroppedVariableStats.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/LegacyPassManager.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace {
// This test ensures that if a #dbg_value and an instruction that exists in the
// same scope as that #dbg_value are both deleted as a result of an optimization
// pass, debug information is considered not dropped.
TEST(DroppedVariableStats, BothDeleted) {
TEST(DroppedVariableStatsIR, BothDeleted) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -79,9 +79,8 @@ TEST(DroppedVariableStats, BothDeleted) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -92,16 +91,15 @@ TEST(DroppedVariableStats, BothDeleted) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), false);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that shares the same scope as the #dbg_value still exists,
// debug information is conisdered dropped.
TEST(DroppedVariableStats, DbgValLost) {
TEST(DroppedVariableStatsIR, DbgValLost) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -136,9 +134,8 @@ TEST(DroppedVariableStats, DbgValLost) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -148,16 +145,15 @@ TEST(DroppedVariableStats, DbgValLost) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), true);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that has an unrelated scope as the #dbg_value still
// exists, debug information is conisdered not dropped.
TEST(DroppedVariableStats, UnrelatedScopes) {
TEST(DroppedVariableStatsIR, UnrelatedScopes) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -193,9 +189,8 @@ TEST(DroppedVariableStats, UnrelatedScopes) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -205,16 +200,15 @@ TEST(DroppedVariableStats, UnrelatedScopes) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), false);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that has a scope which is a child of the #dbg_value scope
// still exists, debug information is conisdered dropped.
TEST(DroppedVariableStats, ChildScopes) {
TEST(DroppedVariableStatsIR, ChildScopes) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -250,9 +244,8 @@ TEST(DroppedVariableStats, ChildScopes) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -262,17 +255,16 @@ TEST(DroppedVariableStats, ChildScopes) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), true);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that has a scope which is a child of the #dbg_value scope
// still exists, and the #dbg_value is inlined at another location, debug
// information is conisdered not dropped.
TEST(DroppedVariableStats, InlinedAt) {
TEST(DroppedVariableStatsIR, InlinedAt) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -308,9 +300,8 @@ TEST(DroppedVariableStats, InlinedAt) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -320,17 +311,16 @@ TEST(DroppedVariableStats, InlinedAt) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), false);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that has a scope which is a child of the #dbg_value scope
// still exists, and the #dbg_value and the instruction are inlined at another
// location, debug information is conisdered dropped.
TEST(DroppedVariableStats, InlinedAtShared) {
TEST(DroppedVariableStatsIR, InlinedAtShared) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -366,9 +356,8 @@ TEST(DroppedVariableStats, InlinedAtShared) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -378,17 +367,16 @@ TEST(DroppedVariableStats, InlinedAtShared) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), true);
}

// This test ensures that if a #dbg_value is dropped after an optimization pass,
// but an instruction that has a scope which is a child of the #dbg_value scope
// still exists, and the instruction is inlined at a location that is the
// #dbg_value's inlined at location, debug information is conisdered dropped.
TEST(DroppedVariableStats, InlinedAtChild) {
TEST(DroppedVariableStatsIR, InlinedAtChild) {
PassInstrumentationCallbacks PIC;
PassInstrumentation PI(&PIC);

Expand Down Expand Up @@ -425,9 +413,8 @@ TEST(DroppedVariableStats, InlinedAtChild) {
std::unique_ptr<llvm::Module> M = parseIR(C, IR);
ASSERT_TRUE(M);

DroppedVariableStats Stats(true);
Stats.runBeforePass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())));
DroppedVariableStatsIR Stats(true);
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) {
Expand All @@ -437,9 +424,8 @@ TEST(DroppedVariableStats, InlinedAtChild) {
}
break;
}
PreservedAnalyses PA;
Stats.runAfterPass("Test",
llvm::Any(const_cast<const llvm::Module *>(M.get())), PA);
llvm::Any(const_cast<const llvm::Module *>(M.get())));
ASSERT_EQ(Stats.getPassDroppedVariables(), true);
}

Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ add_llvm_unittest(IRTests
ShuffleVectorInstTest.cpp
StructuralHashTest.cpp
TimePassesTest.cpp
DroppedVariableStatsTest.cpp
TypesTest.cpp
UseTest.cpp
UserTest.cpp
Expand Down