-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Conversation
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.
@llvm/pr-subscribers-llvm-ir Author: Shubham Sandeep Rastogi (rastogishubham) ChangesTo 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 Full diff: https://github.com/llvm/llvm-project/pull/120650.diff 8 Files Affected:
diff --git a/llvm/include/llvm/Passes/DroppedVariableStats.h b/llvm/include/llvm/CodeGen/DroppedVariableStats.h
similarity index 91%
rename from llvm/include/llvm/Passes/DroppedVariableStats.h
rename to llvm/include/llvm/CodeGen/DroppedVariableStats.h
index 4555157c942b51..8986da53284e87 100644
--- a/llvm/include/llvm/Passes/DroppedVariableStats.h
+++ b/llvm/include/llvm/CodeGen/DroppedVariableStats.h
@@ -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"
@@ -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);
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index 6ba466f9269f09..12a34c099eaffe 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -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"
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 145fd2fac8b564..11d8ebf869344b 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -50,6 +50,7 @@ add_llvm_component_library(LLVMCodeGen
DeadMachineInstructionElim.cpp
DetectDeadLanes.cpp
DFAPacketizer.cpp
+ DroppedVariableStats.cpp
DwarfEHPrepare.cpp
EarlyIfConversion.cpp
EdgeBundles.cpp
diff --git a/llvm/lib/Passes/DroppedVariableStats.cpp b/llvm/lib/CodeGen/DroppedVariableStats.cpp
similarity index 84%
rename from llvm/lib/Passes/DroppedVariableStats.cpp
rename to llvm/lib/CodeGen/DroppedVariableStats.cpp
index 5dc6b75fb8ace9..ef6abad802e4df 100644
--- a/llvm/lib/Passes/DroppedVariableStats.cpp
+++ b/llvm/lib/CodeGen/DroppedVariableStats.cpp
@@ -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"
@@ -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);
- }
- }
- }
-}
diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index 9e16a446c9b399..6425f4934b2103 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -1,6 +1,5 @@
add_llvm_component_library(LLVMPasses
CodeGenPassBuilder.cpp
- DroppedVariableStats.cpp
OptimizationLevel.cpp
PassBuilder.cpp
PassBuilderBindings.cpp
diff --git a/llvm/unittests/CodeGen/CMakeLists.txt b/llvm/unittests/CodeGen/CMakeLists.txt
index 963cdcc0275e16..807fd1a9b7b568 100644
--- a/llvm/unittests/CodeGen/CMakeLists.txt
+++ b/llvm/unittests/CodeGen/CMakeLists.txt
@@ -27,6 +27,7 @@ add_llvm_unittest(CodeGenTests
CCStateTest.cpp
DIEHashTest.cpp
DIETest.cpp
+ DroppedVariableStatsIRTest.cpp
DwarfStringPoolEntryRefTest.cpp
InstrRefLDVTest.cpp
LowLevelTypeTest.cpp
diff --git a/llvm/unittests/IR/DroppedVariableStatsIRTest.cpp b/llvm/unittests/CodeGen/DroppedVariableStatsIRTest.cpp
similarity index 100%
rename from llvm/unittests/IR/DroppedVariableStatsIRTest.cpp
rename to llvm/unittests/CodeGen/DroppedVariableStatsIRTest.cpp
diff --git a/llvm/unittests/IR/CMakeLists.txt b/llvm/unittests/IR/CMakeLists.txt
index 01f02bf5d70ac1..441ef271b20e12 100644
--- a/llvm/unittests/IR/CMakeLists.txt
+++ b/llvm/unittests/IR/CMakeLists.txt
@@ -43,7 +43,6 @@ add_llvm_unittest(IRTests
ShuffleVectorInstTest.cpp
StructuralHashTest.cpp
TimePassesTest.cpp
- DroppedVariableStatsIRTest.cpp
TypesTest.cpp
UseTest.cpp
UserTest.cpp
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/5498 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/198/builds/403 Here is the relevant piece of the build log for the reference
|
This reverts commit 4307198. Broke bot ppc64le-clang-multistage-test: undefined reference to `llvm::DroppedVariableStats::populateVarIDSetAndInlinedMap in In function `llvm::DroppedVariableStatsIR::visitEveryInstruction
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1892 Here is the relevant piece of the build log for the reference
|
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 forclass DroppedVariableStatsIR