Skip to content

Commit e914d97

Browse files
Revert "[NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (llvm#115563)"
This reverts commit 2de7881. Reverted due to buildbot failure: unittests/IR/CMakeFiles/IRTests.dir/DroppedVariableStatsIRTest.cpp.o:DroppedVariableStatsIRTest.cpp:function llvm::DroppedVariableStatsIR::runAfterPass(llvm::StringRef, llvm::Any): error: undefined reference to 'llvm::DroppedVariableStatsIR::runOnModule(llvm::Module const*, bool)'
1 parent 81924ac commit e914d97

File tree

7 files changed

+299
-455
lines changed

7 files changed

+299
-455
lines changed

llvm/include/llvm/CodeGen/DroppedVariableStats.h

Lines changed: 0 additions & 226 deletions
This file was deleted.

llvm/include/llvm/Passes/StandardInstrumentations.h

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/StringSet.h"
22-
#include "llvm/CodeGen/DroppedVariableStats.h"
2322
#include "llvm/CodeGen/MachineBasicBlock.h"
2423
#include "llvm/IR/BasicBlock.h"
2524
#include "llvm/IR/DebugInfoMetadata.h"
@@ -580,6 +579,83 @@ class PrintCrashIRInstrumentation {
580579
static void SignalHandler(void *);
581580
};
582581

582+
/// A class to collect and print dropped debug information variable statistics.
583+
/// After every LLVM IR pass is run, it will print how many #dbg_values were
584+
/// dropped due to that pass.
585+
class DroppedVariableStats {
586+
public:
587+
DroppedVariableStats(bool DroppedVarStatsEnabled) {
588+
if (DroppedVarStatsEnabled)
589+
llvm::outs()
590+
<< "Pass Level, Pass Name, Num of Dropped Variables, Func or "
591+
"Module Name\n";
592+
};
593+
// We intend this to be unique per-compilation, thus no copies.
594+
DroppedVariableStats(const DroppedVariableStats &) = delete;
595+
void operator=(const DroppedVariableStats &) = delete;
596+
597+
void registerCallbacks(PassInstrumentationCallbacks &PIC);
598+
void runBeforePass(StringRef PassID, Any IR);
599+
void runAfterPass(StringRef PassID, Any IR, const PreservedAnalyses &PA);
600+
void runAfterPassInvalidated(StringRef PassID, const PreservedAnalyses &PA);
601+
bool getPassDroppedVariables() { return PassDroppedVariables; }
602+
603+
private:
604+
bool PassDroppedVariables = false;
605+
/// A unique key that represents a #dbg_value.
606+
using VarID =
607+
std::tuple<const DIScope *, const DIScope *, const DILocalVariable *>;
608+
609+
struct DebugVariables {
610+
/// DenseSet of VarIDs before an optimization pass has run.
611+
DenseSet<VarID> DebugVariablesBefore;
612+
/// DenseSet of VarIDs after an optimization pass has run.
613+
DenseSet<VarID> DebugVariablesAfter;
614+
};
615+
616+
/// A stack of a DenseMap, that maps DebugVariables for every pass to an
617+
/// llvm::Function. A stack is used because an optimization pass can call
618+
/// other passes.
619+
SmallVector<DenseMap<const Function *, DebugVariables>> DebugVariablesStack;
620+
621+
/// A DenseSet tracking whether a scope was visited before.
622+
DenseSet<const DIScope *> VisitedScope;
623+
/// A stack of DenseMaps, which map the name of an llvm::Function to a
624+
/// DenseMap of VarIDs and their inlinedAt locations before an optimization
625+
/// pass has run.
626+
SmallVector<DenseMap<StringRef, DenseMap<VarID, DILocation *>>> InlinedAts;
627+
628+
/// Iterate over all Functions in a Module and report any dropped debug
629+
/// information. Will call calculateDroppedVarStatsOnFunction on every
630+
/// Function.
631+
void calculateDroppedVarStatsOnModule(const Module *M, StringRef PassID,
632+
std::string FuncOrModName,
633+
std::string PassLevel);
634+
/// Iterate over all Instructions in a Function and report any dropped debug
635+
/// information.
636+
void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
637+
std::string FuncOrModName,
638+
std::string PassLevel);
639+
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
640+
/// after a pass has run to facilitate dropped variable calculation for an
641+
/// llvm::Function.
642+
void runOnFunction(const Function *F, bool Before);
643+
/// Populate DebugVariablesBefore, DebugVariablesAfter, InlinedAts before or
644+
/// after a pass has run to facilitate dropped variable calculation for an
645+
/// llvm::Module. Calls runOnFunction on every Function in the Module.
646+
void runOnModule(const Module *M, bool Before);
647+
/// Remove a dropped #dbg_value VarID from all Sets in the
648+
/// DroppedVariablesBefore stack.
649+
void removeVarFromAllSets(VarID Var, const Function *F);
650+
/// Return true if \p Scope is the same as \p DbgValScope or a child scope of
651+
/// \p DbgValScope, return false otherwise.
652+
bool isScopeChildOfOrEqualTo(DIScope *Scope, const DIScope *DbgValScope);
653+
/// Return true if \p InlinedAt is the same as \p DbgValInlinedAt or part of
654+
/// the InlinedAt chain, return false otherwise.
655+
bool isInlinedAtChildOfOrEqualTo(const DILocation *InlinedAt,
656+
const DILocation *DbgValInlinedAt);
657+
};
658+
583659
/// This class provides an interface to register all the standard pass
584660
/// instrumentations and manages their state (if any).
585661
class StandardInstrumentations {
@@ -597,7 +673,7 @@ class StandardInstrumentations {
597673
PrintCrashIRInstrumentation PrintCrashIR;
598674
IRChangedTester ChangeTester;
599675
VerifyInstrumentation Verify;
600-
DroppedVariableStatsIR DroppedStatsIR;
676+
DroppedVariableStats DroppedStats;
601677

602678
bool VerifyEach;
603679

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ add_llvm_component_library(LLVMCodeGen
5050
DeadMachineInstructionElim.cpp
5151
DetectDeadLanes.cpp
5252
DFAPacketizer.cpp
53-
DroppedVariableStats.cpp
5453
DwarfEHPrepare.cpp
5554
EarlyIfConversion.cpp
5655
EdgeBundles.cpp

0 commit comments

Comments
 (0)