Skip to content

Commit 4307198

Browse files
Move DroppedVariableStats to CodeGen lib (#120650)
To get Dropped variable statistics for MIR, we need to move the base class DroppedVariableStats code to the CodeGen library because we cannot have CodeGen link against Passes. Also moved the code for the virtual functions to the header because clang/lib/CodeGen doesn't link against llvm/lib/CodeGen however it does link against Passes which contains the `class StandardInstrumentations` code but not the definition for the virtual functions leading to the error about not finding vtable for `class DroppedVariableStatsIR`
1 parent d3c4637 commit 4307198

File tree

8 files changed

+28
-36
lines changed

8 files changed

+28
-36
lines changed

llvm/include/llvm/Passes/DroppedVariableStats.h renamed to llvm/include/llvm/CodeGen/DroppedVariableStats.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/IR/DebugInfoMetadata.h"
1919
#include "llvm/IR/DiagnosticInfo.h"
2020
#include "llvm/IR/Function.h"
21+
#include "llvm/IR/InstIterator.h"
2122
#include "llvm/IR/Module.h"
2223
#include "llvm/IR/PassInstrumentation.h"
2324

@@ -206,12 +207,33 @@ class DroppedVariableStatsIR : public DroppedVariableStats {
206207
virtual void
207208
visitEveryInstruction(unsigned &DroppedCount,
208209
DenseMap<VarID, DILocation *> &InlinedAtsMap,
209-
VarID Var) override;
210+
VarID Var) override {
211+
const DIScope *DbgValScope = std::get<0>(Var);
212+
for (const auto &I : instructions(Func)) {
213+
auto *DbgLoc = I.getDebugLoc().get();
214+
if (!DbgLoc)
215+
continue;
216+
if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope,
217+
InlinedAtsMap, Var, DroppedCount))
218+
break;
219+
}
220+
}
210221
/// Override base class method to run on #dbg_values specifically.
211222
virtual void visitEveryDebugRecord(
212223
DenseSet<VarID> &VarIDSet,
213224
DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
214-
StringRef FuncName, bool Before) override;
225+
StringRef FuncName, bool Before) override {
226+
for (const auto &I : instructions(Func)) {
227+
for (DbgRecord &DR : I.getDbgRecordRange()) {
228+
if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
229+
auto *DbgVar = Dbg->getVariable();
230+
auto DbgLoc = DR.getDebugLoc();
231+
populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
232+
FuncName, Before);
233+
}
234+
}
235+
}
236+
}
215237

216238
template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR) {
217239
const IRUnitT **IRPtr = llvm::any_cast<const IRUnitT *>(&IR);

llvm/include/llvm/Passes/StandardInstrumentations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/StringSet.h"
22+
#include "llvm/CodeGen/DroppedVariableStats.h"
2223
#include "llvm/CodeGen/MachineBasicBlock.h"
2324
#include "llvm/IR/BasicBlock.h"
2425
#include "llvm/IR/DebugInfoMetadata.h"
2526
#include "llvm/IR/OptBisect.h"
2627
#include "llvm/IR/PassTimingInfo.h"
2728
#include "llvm/IR/ValueHandle.h"
28-
#include "llvm/Passes/DroppedVariableStats.h"
2929
#include "llvm/Support/CommandLine.h"
3030
#include "llvm/Support/TimeProfiler.h"
3131
#include "llvm/Transforms/IPO/SampleProfileProbe.h"

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_llvm_component_library(LLVMCodeGen
5050
DeadMachineInstructionElim.cpp
5151
DetectDeadLanes.cpp
5252
DFAPacketizer.cpp
53+
DroppedVariableStats.cpp
5354
DwarfEHPrepare.cpp
5455
EarlyIfConversion.cpp
5556
EdgeBundles.cpp

llvm/lib/Passes/DroppedVariableStats.cpp renamed to llvm/lib/CodeGen/DroppedVariableStats.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
///
1212
///===---------------------------------------------------------------------===//
1313

14-
#include "llvm/Passes/DroppedVariableStats.h"
14+
#include "llvm/CodeGen/DroppedVariableStats.h"
1515
#include "llvm/IR/DebugInfoMetadata.h"
1616
#include "llvm/IR/InstIterator.h"
1717
#include "llvm/IR/Module.h"
@@ -162,33 +162,3 @@ void DroppedVariableStatsIR::registerCallbacks(
162162
PIC.registerAfterPassInvalidatedCallback(
163163
[this](StringRef P, const PreservedAnalyses &PA) { return cleanup(); });
164164
}
165-
166-
void DroppedVariableStatsIR::visitEveryInstruction(
167-
unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,
168-
VarID Var) {
169-
const DIScope *DbgValScope = std::get<0>(Var);
170-
for (const auto &I : instructions(Func)) {
171-
auto *DbgLoc = I.getDebugLoc().get();
172-
if (!DbgLoc)
173-
continue;
174-
if (updateDroppedCount(DbgLoc, DbgLoc->getScope(), DbgValScope,
175-
InlinedAtsMap, Var, DroppedCount))
176-
break;
177-
}
178-
}
179-
180-
void DroppedVariableStatsIR::visitEveryDebugRecord(
181-
DenseSet<VarID> &VarIDSet,
182-
DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
183-
StringRef FuncName, bool Before) {
184-
for (const auto &I : instructions(Func)) {
185-
for (DbgRecord &DR : I.getDbgRecordRange()) {
186-
if (auto *Dbg = dyn_cast<DbgVariableRecord>(&DR)) {
187-
auto *DbgVar = Dbg->getVariable();
188-
auto DbgLoc = DR.getDebugLoc();
189-
populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,
190-
FuncName, Before);
191-
}
192-
}
193-
}
194-
}

llvm/lib/Passes/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_llvm_component_library(LLVMPasses
22
CodeGenPassBuilder.cpp
3-
DroppedVariableStats.cpp
43
OptimizationLevel.cpp
54
PassBuilder.cpp
65
PassBuilderBindings.cpp

llvm/unittests/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ add_llvm_unittest(CodeGenTests
2727
CCStateTest.cpp
2828
DIEHashTest.cpp
2929
DIETest.cpp
30+
DroppedVariableStatsIRTest.cpp
3031
DwarfStringPoolEntryRefTest.cpp
3132
InstrRefLDVTest.cpp
3233
LowLevelTypeTest.cpp

llvm/unittests/IR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ add_llvm_unittest(IRTests
4343
ShuffleVectorInstTest.cpp
4444
StructuralHashTest.cpp
4545
TimePassesTest.cpp
46-
DroppedVariableStatsIRTest.cpp
4746
TypesTest.cpp
4847
UseTest.cpp
4948
UserTest.cpp

0 commit comments

Comments
 (0)