File indexing completed on 2026-05-10 08:44:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CODEGEN_DROPPEDVARIABLESTATSIR_H
0015 #define LLVM_CODEGEN_DROPPEDVARIABLESTATSIR_H
0016
0017 #include "llvm/IR/InstIterator.h"
0018 #include "llvm/IR/Module.h"
0019 #include "llvm/Passes/DroppedVariableStats.h"
0020
0021 namespace llvm {
0022
0023
0024
0025
0026 class DroppedVariableStatsIR : public DroppedVariableStats {
0027 public:
0028 DroppedVariableStatsIR(bool DroppedVarStatsEnabled)
0029 : llvm::DroppedVariableStats(DroppedVarStatsEnabled) {}
0030
0031 void runBeforePass(StringRef P, Any IR) {
0032 setup();
0033 if (const auto *M = unwrapIR<Module>(IR))
0034 return this->runOnModule(P, M, true);
0035 if (const auto *F = unwrapIR<Function>(IR))
0036 return this->runOnFunction(P, F, true);
0037 }
0038
0039 void runAfterPass(StringRef P, Any IR) {
0040 if (const auto *M = unwrapIR<Module>(IR))
0041 runAfterPassModule(P, M);
0042 else if (const auto *F = unwrapIR<Function>(IR))
0043 runAfterPassFunction(P, F);
0044 cleanup();
0045 }
0046
0047 void registerCallbacks(PassInstrumentationCallbacks &PIC);
0048
0049 private:
0050 const Function *Func;
0051
0052 void runAfterPassFunction(StringRef PassID, const Function *F) {
0053 runOnFunction(PassID, F, false);
0054 calculateDroppedVarStatsOnFunction(F, PassID, F->getName().str(),
0055 "Function");
0056 }
0057
0058 void runAfterPassModule(StringRef PassID, const Module *M) {
0059 runOnModule(PassID, M, false);
0060 calculateDroppedVarStatsOnModule(M, PassID, M->getName().str(), "Module");
0061 }
0062
0063
0064
0065 void runOnFunction(StringRef PassID, const Function *F, bool Before);
0066
0067
0068 void calculateDroppedVarStatsOnFunction(const Function *F, StringRef PassID,
0069 StringRef FuncOrModName,
0070 StringRef PassLevel);
0071
0072
0073
0074 void runOnModule(StringRef PassID, const Module *M, bool Before);
0075
0076
0077
0078 void calculateDroppedVarStatsOnModule(const Module *M, StringRef PassID,
0079 StringRef FuncOrModName,
0080 StringRef PassLevel);
0081
0082 virtual void
0083 visitEveryInstruction(unsigned &DroppedCount,
0084 DenseMap<VarID, DILocation *> &InlinedAtsMap,
0085 VarID Var) override;
0086
0087
0088 virtual void visitEveryDebugRecord(
0089 DenseSet<VarID> &VarIDSet,
0090 DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,
0091 StringRef FuncName, bool Before) override;
0092
0093 template <typename IRUnitT> static const IRUnitT *unwrapIR(Any IR) {
0094 const IRUnitT **IRPtr = llvm::any_cast<const IRUnitT *>(&IR);
0095 return IRPtr ? *IRPtr : nullptr;
0096 }
0097 };
0098
0099 }
0100
0101 #endif