[llvm] [Debugify] Improve reduction of debugify coverage build output (PR #150212)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 04:48:40 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/Transforms/Utils/Debugify.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index 39ff6e945..3c3444a64 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -716,478 +716,480 @@ bool llvm::checkDebugInfoMetadata(Module &M,
L.first->setDebugLoc(DebugLoc::getUnknown());
#endif
- bool ResultForVars = checkVars(DIVarsBefore, DIVarsAfter, NameOfWrappedPass,
- FileNameFromCU, ShouldWriteIntoJSON, Bugs);
+ bool ResultForVars = checkVars(DIVarsBefore, DIVarsAfter, NameOfWrappedPass,
+ FileNameFromCU, ShouldWriteIntoJSON, Bugs);
- bool Result = ResultForFunc && ResultForInsts && ResultForVars;
+ bool Result = ResultForFunc && ResultForInsts && ResultForVars;
- StringRef ResultBanner = NameOfWrappedPass != "" ? NameOfWrappedPass : Banner;
- if (ShouldWriteIntoJSON && !Bugs.empty())
- writeJSON(OrigDIVerifyBugsReportFilePath, FileNameFromCU, NameOfWrappedPass,
- Bugs);
+ StringRef ResultBanner =
+ NameOfWrappedPass != "" ? NameOfWrappedPass : Banner;
+ if (ShouldWriteIntoJSON && !Bugs.empty())
+ writeJSON(OrigDIVerifyBugsReportFilePath, FileNameFromCU,
+ NameOfWrappedPass, Bugs);
- if (Result)
- dbg() << ResultBanner << ": PASS\n";
- else
- dbg() << ResultBanner << ": FAIL\n";
-
- // In the case of the `debugify-each`, no need to go over all the instructions
- // again in the collectDebugInfoMetadata(), since as an input we can use
- // the debugging information from the previous pass.
- DebugInfoBeforePass = DebugInfoAfterPass;
-
- LLVM_DEBUG(dbgs() << "\n\n");
- return Result;
-}
-
-namespace {
-/// Return true if a mis-sized diagnostic is issued for \p DbgVal.
-template <typename DbgValTy>
-bool diagnoseMisSizedDbgValue(Module &M, DbgValTy *DbgVal) {
- // The size of a dbg.value's value operand should match the size of the
- // variable it corresponds to.
- //
- // TODO: This, along with a check for non-null value operands, should be
- // promoted to verifier failures.
-
- // For now, don't try to interpret anything more complicated than an empty
- // DIExpression. Eventually we should try to handle OP_deref and fragments.
- if (DbgVal->getExpression()->getNumElements())
- return false;
-
- Value *V = DbgVal->getVariableLocationOp(0);
- if (!V)
- return false;
+ if (Result)
+ dbg() << ResultBanner << ": PASS\n";
+ else
+ dbg() << ResultBanner << ": FAIL\n";
- Type *Ty = V->getType();
- uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
- std::optional<uint64_t> DbgVarSize = DbgVal->getFragmentSizeInBits();
- if (!ValueOperandSize || !DbgVarSize)
- return false;
+ // In the case of the `debugify-each`, no need to go over all the
+ // instructions again in the collectDebugInfoMetadata(), since as an input
+ // we can use the debugging information from the previous pass.
+ DebugInfoBeforePass = DebugInfoAfterPass;
- bool HasBadSize = false;
- if (Ty->isIntegerTy()) {
- auto Signedness = DbgVal->getVariable()->getSignedness();
- if (Signedness == DIBasicType::Signedness::Signed)
- HasBadSize = ValueOperandSize < *DbgVarSize;
- } else {
- HasBadSize = ValueOperandSize != *DbgVarSize;
+ LLVM_DEBUG(dbgs() << "\n\n");
+ return Result;
}
- if (HasBadSize) {
- dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
- << ", but its variable has size " << *DbgVarSize << ": ";
- DbgVal->print(dbg());
- dbg() << "\n";
- }
- return HasBadSize;
-}
+ namespace {
+ /// Return true if a mis-sized diagnostic is issued for \p DbgVal.
+ template <typename DbgValTy>
+ bool diagnoseMisSizedDbgValue(Module &M, DbgValTy *DbgVal) {
+ // The size of a dbg.value's value operand should match the size of the
+ // variable it corresponds to.
+ //
+ // TODO: This, along with a check for non-null value operands, should be
+ // promoted to verifier failures.
+
+ // For now, don't try to interpret anything more complicated than an empty
+ // DIExpression. Eventually we should try to handle OP_deref and fragments.
+ if (DbgVal->getExpression()->getNumElements())
+ return false;
+
+ Value *V = DbgVal->getVariableLocationOp(0);
+ if (!V)
+ return false;
+
+ Type *Ty = V->getType();
+ uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
+ std::optional<uint64_t> DbgVarSize = DbgVal->getFragmentSizeInBits();
+ if (!ValueOperandSize || !DbgVarSize)
+ return false;
+
+ bool HasBadSize = false;
+ if (Ty->isIntegerTy()) {
+ auto Signedness = DbgVal->getVariable()->getSignedness();
+ if (Signedness == DIBasicType::Signedness::Signed)
+ HasBadSize = ValueOperandSize < *DbgVarSize;
+ } else {
+ HasBadSize = ValueOperandSize != *DbgVarSize;
+ }
-bool checkDebugifyMetadata(Module &M,
- iterator_range<Module::iterator> Functions,
- StringRef NameOfWrappedPass, StringRef Banner,
- bool Strip, DebugifyStatsMap *StatsMap) {
- // Skip modules without debugify metadata.
- NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
- if (!NMD) {
- dbg() << Banner << ": Skipping module without debugify metadata\n";
- return false;
+ if (HasBadSize) {
+ dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
+ << ", but its variable has size " << *DbgVarSize << ": ";
+ DbgVal->print(dbg());
+ dbg() << "\n";
+ }
+ return HasBadSize;
}
- auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
- return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
- ->getZExtValue();
- };
- assert(NMD->getNumOperands() == 2 &&
- "llvm.debugify should have exactly 2 operands!");
- unsigned OriginalNumLines = getDebugifyOperand(0);
- unsigned OriginalNumVars = getDebugifyOperand(1);
- bool HasErrors = false;
+ bool checkDebugifyMetadata(Module &M,
+ iterator_range<Module::iterator> Functions,
+ StringRef NameOfWrappedPass, StringRef Banner,
+ bool Strip, DebugifyStatsMap *StatsMap) {
+ // Skip modules without debugify metadata.
+ NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
+ if (!NMD) {
+ dbg() << Banner << ": Skipping module without debugify metadata\n";
+ return false;
+ }
- // Track debug info loss statistics if able.
- DebugifyStatistics *Stats = nullptr;
- if (StatsMap && !NameOfWrappedPass.empty())
- Stats = &StatsMap->operator[](NameOfWrappedPass);
+ auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
+ return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
+ ->getZExtValue();
+ };
+ assert(NMD->getNumOperands() == 2 &&
+ "llvm.debugify should have exactly 2 operands!");
+ unsigned OriginalNumLines = getDebugifyOperand(0);
+ unsigned OriginalNumVars = getDebugifyOperand(1);
+ bool HasErrors = false;
+
+ // Track debug info loss statistics if able.
+ DebugifyStatistics *Stats = nullptr;
+ if (StatsMap && !NameOfWrappedPass.empty())
+ Stats = &StatsMap->operator[](NameOfWrappedPass);
+
+ BitVector MissingLines{OriginalNumLines, true};
+ BitVector MissingVars{OriginalNumVars, true};
+ for (Function &F : Functions) {
+ if (isFunctionSkipped(F))
+ continue;
- BitVector MissingLines{OriginalNumLines, true};
- BitVector MissingVars{OriginalNumVars, true};
- for (Function &F : Functions) {
- if (isFunctionSkipped(F))
- continue;
+ // Find missing lines.
+ for (Instruction &I : instructions(F)) {
+ auto DL = I.getDebugLoc();
+ if (DL && DL.getLine() != 0) {
+ MissingLines.reset(DL.getLine() - 1);
+ continue;
+ }
- // Find missing lines.
- for (Instruction &I : instructions(F)) {
- auto DL = I.getDebugLoc();
- if (DL && DL.getLine() != 0) {
- MissingLines.reset(DL.getLine() - 1);
- continue;
+ if (!isa<PHINode>(&I) && !DL) {
+ dbg() << "WARNING: Instruction with empty DebugLoc in function ";
+ dbg() << F.getName() << " --";
+ I.print(dbg());
+ dbg() << "\n";
+ }
}
- if (!isa<PHINode>(&I) && !DL) {
- dbg() << "WARNING: Instruction with empty DebugLoc in function ";
- dbg() << F.getName() << " --";
- I.print(dbg());
- dbg() << "\n";
+ // Find missing variables and mis-sized debug values.
+ auto CheckForMisSized = [&](auto *DbgVal) {
+ unsigned Var = ~0U;
+ (void)to_integer(DbgVal->getVariable()->getName(), Var, 10);
+ assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
+ bool HasBadSize = diagnoseMisSizedDbgValue(M, DbgVal);
+ if (!HasBadSize)
+ MissingVars.reset(Var - 1);
+ HasErrors |= HasBadSize;
+ };
+ for (Instruction &I : instructions(F)) {
+ for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
+ if (DVR.isDbgValue() || DVR.isDbgAssign())
+ CheckForMisSized(&DVR);
}
}
- // Find missing variables and mis-sized debug values.
- auto CheckForMisSized = [&](auto *DbgVal) {
- unsigned Var = ~0U;
- (void)to_integer(DbgVal->getVariable()->getName(), Var, 10);
- assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
- bool HasBadSize = diagnoseMisSizedDbgValue(M, DbgVal);
- if (!HasBadSize)
- MissingVars.reset(Var - 1);
- HasErrors |= HasBadSize;
- };
- for (Instruction &I : instructions(F)) {
- for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
- if (DVR.isDbgValue() || DVR.isDbgAssign())
- CheckForMisSized(&DVR);
+ // Print the results.
+ for (unsigned Idx : MissingLines.set_bits())
+ dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
+
+ for (unsigned Idx : MissingVars.set_bits())
+ dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
+
+ // Update DI loss statistics.
+ if (Stats) {
+ Stats->NumDbgLocsExpected += OriginalNumLines;
+ Stats->NumDbgLocsMissing += MissingLines.count();
+ Stats->NumDbgValuesExpected += OriginalNumVars;
+ Stats->NumDbgValuesMissing += MissingVars.count();
}
- }
- // Print the results.
- for (unsigned Idx : MissingLines.set_bits())
- dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
+ dbg() << Banner;
+ if (!NameOfWrappedPass.empty())
+ dbg() << " [" << NameOfWrappedPass << "]";
+ dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
- for (unsigned Idx : MissingVars.set_bits())
- dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
+ // Strip debugify metadata if required.
+ bool Ret = false;
+ if (Strip)
+ Ret = stripDebugifyMetadata(M);
- // Update DI loss statistics.
- if (Stats) {
- Stats->NumDbgLocsExpected += OriginalNumLines;
- Stats->NumDbgLocsMissing += MissingLines.count();
- Stats->NumDbgValuesExpected += OriginalNumVars;
- Stats->NumDbgValuesMissing += MissingVars.count();
+ return Ret;
}
- dbg() << Banner;
- if (!NameOfWrappedPass.empty())
- dbg() << " [" << NameOfWrappedPass << "]";
- dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
-
- // Strip debugify metadata if required.
- bool Ret = false;
- if (Strip)
- Ret = stripDebugifyMetadata(M);
+ /// ModulePass for attaching synthetic debug info to everything, used with the
+ /// legacy module pass manager.
+ struct DebugifyModulePass : public ModulePass {
+ bool runOnModule(Module &M) override {
+ bool Result =
+ applyDebugify(M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
+ return Result;
+ }
- return Ret;
-}
+ DebugifyModulePass(
+ enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
+ StringRef NameOfWrappedPass = "",
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr)
+ : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
+ DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
-/// ModulePass for attaching synthetic debug info to everything, used with the
-/// legacy module pass manager.
-struct DebugifyModulePass : public ModulePass {
- bool runOnModule(Module &M) override {
- bool Result =
- applyDebugify(M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
- return Result;
- }
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
- DebugifyModulePass(enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- StringRef NameOfWrappedPass = "",
- DebugInfoPerPass *DebugInfoBeforePass = nullptr)
- : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
- DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
+ static char ID; // Pass identification.
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
+ private:
+ StringRef NameOfWrappedPass;
+ DebugInfoPerPass *DebugInfoBeforePass;
+ enum DebugifyMode Mode;
+ };
- static char ID; // Pass identification.
+ /// FunctionPass for attaching synthetic debug info to instructions within a
+ /// single function, used with the legacy module pass manager.
+ struct DebugifyFunctionPass : public FunctionPass {
+ bool runOnFunction(Function &F) override {
+ bool Result =
+ applyDebugify(F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
+ return Result;
+ }
-private:
- StringRef NameOfWrappedPass;
- DebugInfoPerPass *DebugInfoBeforePass;
- enum DebugifyMode Mode;
-};
+ DebugifyFunctionPass(
+ enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
+ StringRef NameOfWrappedPass = "",
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr)
+ : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
+ DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
-/// FunctionPass for attaching synthetic debug info to instructions within a
-/// single function, used with the legacy module pass manager.
-struct DebugifyFunctionPass : public FunctionPass {
- bool runOnFunction(Function &F) override {
- bool Result =
- applyDebugify(F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
- return Result;
- }
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
- DebugifyFunctionPass(
- enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- StringRef NameOfWrappedPass = "",
- DebugInfoPerPass *DebugInfoBeforePass = nullptr)
- : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
- DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode) {}
+ static char ID; // Pass identification.
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
+ private:
+ StringRef NameOfWrappedPass;
+ DebugInfoPerPass *DebugInfoBeforePass;
+ enum DebugifyMode Mode;
+ };
- static char ID; // Pass identification.
+ /// ModulePass for checking debug info inserted by -debugify, used with the
+ /// legacy module pass manager.
+ struct CheckDebugifyModulePass : public ModulePass {
+ bool runOnModule(Module &M) override {
+ bool Result;
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ Result = checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
+ "CheckModuleDebugify", Strip, StatsMap);
+ else
+ Result = checkDebugInfoMetadata(
+ M, M.functions(), *DebugInfoBeforePass,
+ "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
+ OrigDIVerifyBugsReportFilePath);
-private:
- StringRef NameOfWrappedPass;
- DebugInfoPerPass *DebugInfoBeforePass;
- enum DebugifyMode Mode;
-};
+ return Result;
+ }
-/// ModulePass for checking debug info inserted by -debugify, used with the
-/// legacy module pass manager.
-struct CheckDebugifyModulePass : public ModulePass {
- bool runOnModule(Module &M) override {
- bool Result;
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- Result = checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
- "CheckModuleDebugify", Strip, StatsMap);
- else
- Result = checkDebugInfoMetadata(
- M, M.functions(), *DebugInfoBeforePass,
- "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
- OrigDIVerifyBugsReportFilePath);
+ CheckDebugifyModulePass(
+ bool Strip = false, StringRef NameOfWrappedPass = "",
+ DebugifyStatsMap *StatsMap = nullptr,
+ enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
+ StringRef OrigDIVerifyBugsReportFilePath = "")
+ : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
+ OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
+ StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass),
+ Mode(Mode), Strip(Strip) {}
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
- return Result;
- }
+ static char ID; // Pass identification.
- CheckDebugifyModulePass(
- bool Strip = false, StringRef NameOfWrappedPass = "",
- DebugifyStatsMap *StatsMap = nullptr,
- enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPass *DebugInfoBeforePass = nullptr,
- StringRef OrigDIVerifyBugsReportFilePath = "")
- : ModulePass(ID), NameOfWrappedPass(NameOfWrappedPass),
- OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
- StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode),
- Strip(Strip) {}
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
+ private:
+ StringRef NameOfWrappedPass;
+ StringRef OrigDIVerifyBugsReportFilePath;
+ DebugifyStatsMap *StatsMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
+ enum DebugifyMode Mode;
+ bool Strip;
+ };
- static char ID; // Pass identification.
+ /// FunctionPass for checking debug info inserted by -debugify-function, used
+ /// with the legacy module pass manager.
+ struct CheckDebugifyFunctionPass : public FunctionPass {
+ bool runOnFunction(Function &F) override {
+ Module &M = *F.getParent();
+ auto FuncIt = F.getIterator();
+ bool Result;
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ Result = checkDebugifyMetadata(
+ M, make_range(FuncIt, std::next(FuncIt)), NameOfWrappedPass,
+ "CheckFunctionDebugify", Strip, StatsMap);
+ else
+ Result = checkDebugInfoMetadata(
+ M, make_range(FuncIt, std::next(FuncIt)), *DebugInfoBeforePass,
+ "CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
+ OrigDIVerifyBugsReportFilePath);
-private:
- StringRef NameOfWrappedPass;
- StringRef OrigDIVerifyBugsReportFilePath;
- DebugifyStatsMap *StatsMap;
- DebugInfoPerPass *DebugInfoBeforePass;
- enum DebugifyMode Mode;
- bool Strip;
-};
+ return Result;
+ }
-/// FunctionPass for checking debug info inserted by -debugify-function, used
-/// with the legacy module pass manager.
-struct CheckDebugifyFunctionPass : public FunctionPass {
- bool runOnFunction(Function &F) override {
- Module &M = *F.getParent();
- auto FuncIt = F.getIterator();
- bool Result;
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- Result = checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
- NameOfWrappedPass, "CheckFunctionDebugify",
- Strip, StatsMap);
- else
- Result = checkDebugInfoMetadata(
- M, make_range(FuncIt, std::next(FuncIt)), *DebugInfoBeforePass,
- "CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
- OrigDIVerifyBugsReportFilePath);
+ CheckDebugifyFunctionPass(
+ bool Strip = false, StringRef NameOfWrappedPass = "",
+ DebugifyStatsMap *StatsMap = nullptr,
+ enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
+ DebugInfoPerPass *DebugInfoBeforePass = nullptr,
+ StringRef OrigDIVerifyBugsReportFilePath = "")
+ : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
+ OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
+ StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass),
+ Mode(Mode), Strip(Strip) {}
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
- return Result;
- }
+ static char ID; // Pass identification.
- CheckDebugifyFunctionPass(
- bool Strip = false, StringRef NameOfWrappedPass = "",
- DebugifyStatsMap *StatsMap = nullptr,
- enum DebugifyMode Mode = DebugifyMode::SyntheticDebugInfo,
- DebugInfoPerPass *DebugInfoBeforePass = nullptr,
- StringRef OrigDIVerifyBugsReportFilePath = "")
- : FunctionPass(ID), NameOfWrappedPass(NameOfWrappedPass),
- OrigDIVerifyBugsReportFilePath(OrigDIVerifyBugsReportFilePath),
- StatsMap(StatsMap), DebugInfoBeforePass(DebugInfoBeforePass), Mode(Mode),
- Strip(Strip) {}
-
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
+ private:
+ StringRef NameOfWrappedPass;
+ StringRef OrigDIVerifyBugsReportFilePath;
+ DebugifyStatsMap *StatsMap;
+ DebugInfoPerPass *DebugInfoBeforePass;
+ enum DebugifyMode Mode;
+ bool Strip;
+ };
- static char ID; // Pass identification.
+ } // end anonymous namespace
-private:
- StringRef NameOfWrappedPass;
- StringRef OrigDIVerifyBugsReportFilePath;
- DebugifyStatsMap *StatsMap;
- DebugInfoPerPass *DebugInfoBeforePass;
- enum DebugifyMode Mode;
- bool Strip;
-};
+ void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) {
+ std::error_code EC;
+ raw_fd_ostream OS{Path, EC};
+ if (EC) {
+ errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
+ return;
+ }
-} // end anonymous namespace
+ OS << "Pass Name" << ',' << "# of missing debug values" << ','
+ << "# of missing locations" << ',' << "Missing/Expected value ratio"
+ << ',' << "Missing/Expected location ratio" << '\n';
+ for (const auto &Entry : Map) {
+ StringRef Pass = Entry.first;
+ DebugifyStatistics Stats = Entry.second;
-void llvm::exportDebugifyStats(StringRef Path, const DebugifyStatsMap &Map) {
- std::error_code EC;
- raw_fd_ostream OS{Path, EC};
- if (EC) {
- errs() << "Could not open file: " << EC.message() << ", " << Path << '\n';
- return;
+ OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
+ << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio()
+ << ',' << Stats.getEmptyLocationRatio() << '\n';
+ }
}
- OS << "Pass Name" << ',' << "# of missing debug values" << ','
- << "# of missing locations" << ',' << "Missing/Expected value ratio" << ','
- << "Missing/Expected location ratio" << '\n';
- for (const auto &Entry : Map) {
- StringRef Pass = Entry.first;
- DebugifyStatistics Stats = Entry.second;
-
- OS << Pass << ',' << Stats.NumDbgValuesMissing << ','
- << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ','
- << Stats.getEmptyLocationRatio() << '\n';
+ ModulePass *createDebugifyModulePass(enum DebugifyMode Mode,
+ llvm::StringRef NameOfWrappedPass,
+ DebugInfoPerPass * DebugInfoBeforePass) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ return new DebugifyModulePass();
+ assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
+ return new DebugifyModulePass(Mode, NameOfWrappedPass, DebugInfoBeforePass);
}
-}
-ModulePass *createDebugifyModulePass(enum DebugifyMode Mode,
- llvm::StringRef NameOfWrappedPass,
- DebugInfoPerPass *DebugInfoBeforePass) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- return new DebugifyModulePass();
- assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new DebugifyModulePass(Mode, NameOfWrappedPass, DebugInfoBeforePass);
-}
-
-FunctionPass *
-createDebugifyFunctionPass(enum DebugifyMode Mode,
- llvm::StringRef NameOfWrappedPass,
- DebugInfoPerPass *DebugInfoBeforePass) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- return new DebugifyFunctionPass();
- assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new DebugifyFunctionPass(Mode, NameOfWrappedPass, DebugInfoBeforePass);
-}
+ FunctionPass *createDebugifyFunctionPass(
+ enum DebugifyMode Mode, llvm::StringRef NameOfWrappedPass,
+ DebugInfoPerPass * DebugInfoBeforePass) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ return new DebugifyFunctionPass();
+ assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
+ return new DebugifyFunctionPass(Mode, NameOfWrappedPass,
+ DebugInfoBeforePass);
+ }
-PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- applyDebugifyMetadata(M, M.functions(),
- "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
- else
- collectDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
- "ModuleDebugify (original debuginfo)",
- NameOfWrappedPass);
-
- PreservedAnalyses PA;
- PA.preserveSet<CFGAnalyses>();
- return PA;
-}
+ PreservedAnalyses NewPMDebugifyPass::run(Module & M,
+ ModuleAnalysisManager &) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ applyDebugifyMetadata(M, M.functions(),
+ "ModuleDebugify: ", /*ApplyToMF*/ nullptr);
+ else
+ collectDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
+ "ModuleDebugify (original debuginfo)",
+ NameOfWrappedPass);
-ModulePass *createCheckDebugifyModulePass(
- bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
- enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
- StringRef OrigDIVerifyBugsReportFilePath) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
- assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode,
- DebugInfoBeforePass,
- OrigDIVerifyBugsReportFilePath);
-}
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
+ }
-FunctionPass *createCheckDebugifyFunctionPass(
- bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
- enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
- StringRef OrigDIVerifyBugsReportFilePath) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
- assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
- return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr, Mode,
+ ModulePass *createCheckDebugifyModulePass(
+ bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
+ enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
+ StringRef OrigDIVerifyBugsReportFilePath) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
+ assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
+ return new CheckDebugifyModulePass(false, NameOfWrappedPass, nullptr, Mode,
DebugInfoBeforePass,
OrigDIVerifyBugsReportFilePath);
-}
+ }
-PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
- ModuleAnalysisManager &) {
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
- "CheckModuleDebugify", Strip, StatsMap);
- else
- checkDebugInfoMetadata(
- M, M.functions(), *DebugInfoBeforePass,
- "CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
- OrigDIVerifyBugsReportFilePath);
-
- return PreservedAnalyses::all();
-}
+ FunctionPass *createCheckDebugifyFunctionPass(
+ bool Strip, StringRef NameOfWrappedPass, DebugifyStatsMap *StatsMap,
+ enum DebugifyMode Mode, DebugInfoPerPass *DebugInfoBeforePass,
+ StringRef OrigDIVerifyBugsReportFilePath) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
+ assert(Mode == DebugifyMode::OriginalDebugInfo && "Must be original mode");
+ return new CheckDebugifyFunctionPass(false, NameOfWrappedPass, nullptr,
+ Mode, DebugInfoBeforePass,
+ OrigDIVerifyBugsReportFilePath);
+ }
-static bool isIgnoredPass(StringRef PassID) {
- return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
- "AnalysisManagerProxy", "PrintFunctionPass",
- "PrintModulePass", "BitcodeWriterPass",
- "ThinLTOBitcodeWriterPass", "VerifierPass"});
-}
+ PreservedAnalyses NewPMCheckDebugifyPass::run(Module & M,
+ ModuleAnalysisManager &) {
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
+ "CheckModuleDebugify", Strip, StatsMap);
+ else
+ checkDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
+ "CheckModuleDebugify (original debuginfo)",
+ NameOfWrappedPass, OrigDIVerifyBugsReportFilePath);
-void DebugifyEachInstrumentation::registerCallbacks(
- PassInstrumentationCallbacks &PIC, ModuleAnalysisManager &MAM) {
- PIC.registerBeforeNonSkippedPassCallback([this, &MAM](StringRef P, Any IR) {
- if (isIgnoredPass(P))
- return;
- PreservedAnalyses PA;
- PA.preserveSet<CFGAnalyses>();
- if (const auto **CF = llvm::any_cast<const Function *>(&IR)) {
- Function &F = *const_cast<Function *>(*CF);
- applyDebugify(F, Mode, DebugInfoBeforePass, P);
- MAM.getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
- .getManager()
- .invalidate(F, PA);
- } else if (const auto **CM = llvm::any_cast<const Module *>(&IR)) {
- Module &M = *const_cast<Module *>(*CM);
- applyDebugify(M, Mode, DebugInfoBeforePass, P);
- MAM.invalidate(M, PA);
- }
- });
- PIC.registerAfterPassCallback(
- [this, &MAM](StringRef P, Any IR, const PreservedAnalyses &PassPA) {
- if (isIgnoredPass(P))
- return;
- PreservedAnalyses PA;
- PA.preserveSet<CFGAnalyses>();
- if (const auto **CF = llvm::any_cast<const Function *>(&IR)) {
- auto &F = *const_cast<Function *>(*CF);
- Module &M = *F.getParent();
- auto It = F.getIterator();
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
- "CheckFunctionDebugify", /*Strip=*/true,
- DIStatsMap);
- else
- checkDebugInfoMetadata(M, make_range(It, std::next(It)),
- *DebugInfoBeforePass,
- "CheckModuleDebugify (original debuginfo)",
- P, OrigDIVerifyBugsReportFilePath);
- MAM.getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
- .getManager()
- .invalidate(F, PA);
- } else if (const auto **CM = llvm::any_cast<const Module *>(&IR)) {
- Module &M = *const_cast<Module *>(*CM);
- if (Mode == DebugifyMode::SyntheticDebugInfo)
- checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
- /*Strip=*/true, DIStatsMap);
- else
- checkDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
- "CheckModuleDebugify (original debuginfo)",
- P, OrigDIVerifyBugsReportFilePath);
- MAM.invalidate(M, PA);
- }
- });
-}
+ return PreservedAnalyses::all();
+ }
+
+ static bool isIgnoredPass(StringRef PassID) {
+ return isSpecialPass(PassID, {"PassManager", "PassAdaptor",
+ "AnalysisManagerProxy", "PrintFunctionPass",
+ "PrintModulePass", "BitcodeWriterPass",
+ "ThinLTOBitcodeWriterPass", "VerifierPass"});
+ }
+
+ void DebugifyEachInstrumentation::registerCallbacks(
+ PassInstrumentationCallbacks & PIC, ModuleAnalysisManager & MAM) {
+ PIC.registerBeforeNonSkippedPassCallback([this, &MAM](StringRef P, Any IR) {
+ if (isIgnoredPass(P))
+ return;
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ if (const auto **CF = llvm::any_cast<const Function *>(&IR)) {
+ Function &F = *const_cast<Function *>(*CF);
+ applyDebugify(F, Mode, DebugInfoBeforePass, P);
+ MAM.getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
+ .getManager()
+ .invalidate(F, PA);
+ } else if (const auto **CM = llvm::any_cast<const Module *>(&IR)) {
+ Module &M = *const_cast<Module *>(*CM);
+ applyDebugify(M, Mode, DebugInfoBeforePass, P);
+ MAM.invalidate(M, PA);
+ }
+ });
+ PIC.registerAfterPassCallback(
+ [this, &MAM](StringRef P, Any IR, const PreservedAnalyses &PassPA) {
+ if (isIgnoredPass(P))
+ return;
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ if (const auto **CF = llvm::any_cast<const Function *>(&IR)) {
+ auto &F = *const_cast<Function *>(*CF);
+ Module &M = *F.getParent();
+ auto It = F.getIterator();
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ checkDebugifyMetadata(M, make_range(It, std::next(It)), P,
+ "CheckFunctionDebugify", /*Strip=*/true,
+ DIStatsMap);
+ else
+ checkDebugInfoMetadata(M, make_range(It, std::next(It)),
+ *DebugInfoBeforePass,
+ "CheckModuleDebugify (original debuginfo)",
+ P, OrigDIVerifyBugsReportFilePath);
+ MAM.getResult<FunctionAnalysisManagerModuleProxy>(*F.getParent())
+ .getManager()
+ .invalidate(F, PA);
+ } else if (const auto **CM = llvm::any_cast<const Module *>(&IR)) {
+ Module &M = *const_cast<Module *>(*CM);
+ if (Mode == DebugifyMode::SyntheticDebugInfo)
+ checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
+ /*Strip=*/true, DIStatsMap);
+ else
+ checkDebugInfoMetadata(M, M.functions(), *DebugInfoBeforePass,
+ "CheckModuleDebugify (original debuginfo)",
+ P, OrigDIVerifyBugsReportFilePath);
+ MAM.invalidate(M, PA);
+ }
+ });
+ }
-char DebugifyModulePass::ID = 0;
-static RegisterPass<DebugifyModulePass> DM("debugify",
- "Attach debug info to everything");
+ char DebugifyModulePass::ID = 0;
+ static RegisterPass<DebugifyModulePass> DM("debugify",
+ "Attach debug info to everything");
-char CheckDebugifyModulePass::ID = 0;
-static RegisterPass<CheckDebugifyModulePass>
- CDM("check-debugify", "Check debug info from -debugify");
+ char CheckDebugifyModulePass::ID = 0;
+ static RegisterPass<CheckDebugifyModulePass> CDM(
+ "check-debugify", "Check debug info from -debugify");
-char DebugifyFunctionPass::ID = 0;
-static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
- "Attach debug info to a function");
+ char DebugifyFunctionPass::ID = 0;
+ static RegisterPass<DebugifyFunctionPass> DF(
+ "debugify-function", "Attach debug info to a function");
-char CheckDebugifyFunctionPass::ID = 0;
-static RegisterPass<CheckDebugifyFunctionPass>
- CDF("check-debugify-function", "Check debug info from -debugify-function");
+ char CheckDebugifyFunctionPass::ID = 0;
+ static RegisterPass<CheckDebugifyFunctionPass> CDF(
+ "check-debugify-function", "Check debug info from -debugify-function");
``````````
</details>
https://github.com/llvm/llvm-project/pull/150212
More information about the llvm-commits
mailing list