Skip to content

Move DroppedVariableStats to CodeGen lib #120650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassInstrumentation.h"

Expand Down Expand Up @@ -206,12 +207,33 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
virtual void
visitEveryInstruction(unsigned &DroppedCount,
DenseMap<VarID, DILocation *> &InlinedAtsMap,
VarID Var) override;
VarID Var) override {
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;
}
}
/// Override base class method to run on #dbg_values specifically.
virtual void visitEveryDebugRecord(
DenseSet<VarID> &VarIDSet,
DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
StringRef FuncName, bool Before) override;
StringRef FuncName, bool Before) override {
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);
}
}
}
}

template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR) {
const IRUnitT **IRPtr = llvm::any_cast<const IRUnitT *>(&IR);
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Passes/StandardInstrumentations.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/CodeGen/DroppedVariableStats.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/OptBisect.h"
#include "llvm/IR/PassTimingInfo.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Passes/DroppedVariableStats.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Transforms/IPO/SampleProfileProbe.h"
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_llvm_component_library(LLVMCodeGen
DeadMachineInstructionElim.cpp
DetectDeadLanes.cpp
DFAPacketizer.cpp
DroppedVariableStats.cpp
DwarfEHPrepare.cpp
EarlyIfConversion.cpp
EdgeBundles.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
///
///===---------------------------------------------------------------------===//

#include "llvm/Passes/DroppedVariableStats.h"
#include "llvm/CodeGen/DroppedVariableStats.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -162,33 +162,3 @@ void DroppedVariableStatsIR::registerCallbacks(
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);
}
}
}
}
1 change: 0 additions & 1 deletion llvm/lib/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add_llvm_component_library(LLVMPasses
CodeGenPassBuilder.cpp
DroppedVariableStats.cpp
OptimizationLevel.cpp
PassBuilder.cpp
PassBuilderBindings.cpp
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
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
DroppedVariableStatsIRTest.cpp
TypesTest.cpp
UseTest.cpp
UserTest.cpp
Expand Down
Loading