aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Debugify.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27[DebugInfo] Drop extra DIBuilder::finalizeSubprogram() calls (NFC) (#155618)Vladislav Dzhidzhoev1-1/+0
After #139914, `DIBilder::finalize()` finalizes both declaration and definition DISubprograms. Therefore, there is no need to call `DIBuilder::finalizeSubprogram()` right before `DIBilder::finalize()`.
2025-08-19[Debugify] Fix compile error in tracking coverage buildStephen Tozer1-1/+1
Forward-fixes a compile error in bc216b057d (#150212) in specific build configurations, due to a missing const_cast.
2025-08-15[Debugify] Improve reduction of debugify coverage build output (#150212)Stephen Tozer1-0/+9
In current DebugLoc coverage builds, the output for any reasonably large build can become very large if any missing DebugLocs are present; this happens because single errors in LLVM may result in many errors being reported in the output report. The main cause of this is that the empty locations attached to instructions may be propagated to other instructions in later passes, which will each be reported as new errors. This patch prevents this by adding an "unknown" annotation to instructions after reporting them once, ensuring that any other DebugLocs copied or derived from the original empty location will not be marked as new errors. As a separate but related change, this patch updates the report generation script to deduplicate results using the recorded stacktrace if they are available, instead of the pass+instruction combination. This reduces the size of the reduction, but makes the reduction highly reliable, as the stacktrace allows us to very precisely identify when two bugs have originated from the same place.
2025-07-23[llvm] Remove unused includes (NFC) (#150265)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-18[DebugInfo] Suppress lots of users of DbgValueInst (#149476)Jeremy Morse1-7/+0
This is another prune of dead code -- we never generate debug intrinsics nowadays, therefore there's no need for these codepaths to run. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2025-07-04[DLCov] Origin-Tracking: Add debugify support (#143594)Stephen Tozer1-10/+74
This patch is part of a series that adds origin-tracking to the debugify source location coverage checks, allowing us to report symbolized stack traces of the point where missing source locations appear. This patch completes the feature, having debugify handle origin stack traces by symbolizing them when an associated bug is found and printing them into the JSON report file as part of the bug entry. This patch also updates the script that parses the JSON report and creates a human-readable HTML report, adding an "Origin" entry to the table that contains an expandable textbox containing the symbolized stack trace.
2025-06-30[KeyInstr] Add DISubprogram::keyInstructions bit (#144107)Orlando Cazalet-Hyams1-1/+3
Patch 1/4 adding bitcode support. Store whether or not a function is using Key Instructions in its DISubprogram so that we don't need to rely on the -mllvm flag -dwarf-use-key-instructions to determine whether or not to interpret Key Instructions metadata to decide is_stmt placement at DWARF emission time. This makes bitcode support simple and enables well defined mixing of non-key-instructions and key-instructions functions in an LTO context. This patch adds the bit (using DISubprogram::SubclassData1). PR 144104 and 144103 use it during DWARF emission. PR 44102 adds bitcode support. See pull request for overview of alternative attempts.
2025-06-17[DebugInfo][RemoveDIs] Remove a swathe of debug-intrinsic code (#144389)Jeremy Morse1-14/+2
Seeing how we can't generate any debug intrinsics any more: delete a variety of codepaths where they're handled. For the most part these are plain deletions, in others I've tweaked comments to remain coherent, or added a type to (what was) type-generic-lambdas. This isn't all the DbgInfoIntrinsic call sites but it's most of the simple scenarios. Co-authored-by: Nikita Popov <github@npopov.com>
2025-06-16[build] Fixed LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING handling. (#144391)Slava Zakharin1-1/+1
Change in #107278 modified the CMake CACHE variable with values that are not supported for it as documented. This patch renames the derived vars so that they do not conflict with the CACHE variable.
2025-06-08[llvm] Compare std::optional<T> to values directly (NFC) (#143340)Kazu Hirata1-1/+1
This patch transforms: X && *X == Y to: X == Y where X is of std::optional<T>, and Y is of T or similar.
2025-05-06[KeyInstr][debugify] Add --debugify-atoms to add key instructions metadata ↵Orlando Cazalet-Hyams1-2/+9
(#133483) RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
2025-04-30Reapply "[DLCov] Implement DebugLoc coverage tracking (#107279)"Stephen Tozer1-7/+12
Reapplied after fixing the config issue that was causing issues following the previous merge. This reverts commit fdbf073a86573c9ac4d595fac8e06d252ce1469f.
2025-04-25Revert "[DLCov] Implement DebugLoc coverage tracking (#107279)"Stephen Tozer1-12/+7
This reverts commit a9d93ecf1f8d2cfe3f77851e0df179b386cff353. Reverted due to the commit including a config in LLVM headers that is not available outside of the llvm source tree.
2025-04-24[DLCov] Implement DebugLoc coverage tracking (#107279)Stephen Tozer1-7/+12
This is part of a series of patches that tries to improve DILocation bug detection in Debugify; see the review for more details. This is the patch that adds the main feature, adding a set of `DebugLoc::get<Kind>` functions that can be used for instructions with intentionally empty DebugLocs to prevent Debugify from treating them as bugs, removing the currently-pervasive false positives and allowing us to use Debugify (in its original DI preservation mode) to reliably detect existing bugs and regressions. This patch does not add uses of these functions, except for once in Clang before optimizations, and in `Instruction::dropLocation()`, since that is an obvious case that immediately removes a set of false positives.
2025-02-14[Debugify] applyDebugify - remove unnecessary defaults arg values and assert ↵Simon Pilgrim1-11/+8
dereferencable values (#127186) The applyDebugify helpers were providing default arguments despite all callers providing them, so strip them for clarity. The Function variant was asserting that DebugInfoBeforePass was non-null before dereferencing so I've added an equivalent assert to the Method variant as well. Fixes #97626
2025-02-13[reland][DebugInfo] Update DIBuilder insertion to take InsertPosition (#126967)Harald van Dijk1-6/+8
After #124287 updated several functions to return iterators rather than Instruction *, it was no longer straightforward to pass their result to DIBuilder. This commit updates DIBuilder methods to accept an InsertPosition instead, so that they can be called with an iterator (preferred), or with a deprecation warning an Instruction *, or a BasicBlock *. This commit also updates the existing calls to the DIBuilder methods to pass in iterators. As a special exception, DIBuilder::insertDeclare() keeps a separate overload accepting a BasicBlock *InsertAtEnd. This is because despite the name, this method does not insert at the end of the block, therefore this cannot be handled implicitly by using InsertPosition.
2025-02-12Revert "[DebugInfo] Update DIBuilder insertion to take InsertPosition (#126059)"Harald van Dijk1-8/+6
This reverts commit 3ec9f7494b31f2fe51d5ed0e07adcf4b7199def6.
2025-02-12[DebugInfo] Update DIBuilder insertion to take InsertPosition (#126059)Harald van Dijk1-6/+8
After #124287 updated several functions to return iterators rather than Instruction *, it was no longer straightforward to pass their result to DIBuilder. This commit updates DIBuilder methods to accept an InsertPosition instead, so that they can be called with an iterator (preferred), or with a deprecation warning an Instruction *, or a BasicBlock *. This commit also updates the existing calls to the DIBuilder methods to pass in iterators.
2024-09-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad1-2/+1
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-04-16[RemoveDI] Add support for debug records to debugify (#87383)Stephen Tozer1-67/+44
This patch changes debugify to support debug variable records, and subsequently to no longer convert modules automatically to intrinsics when entering debugify.
2024-02-06[DebugInfo][RemoveDIs] Extend intrinsic-conversion in debugify (#80861)Jeremy Morse1-38/+35
A while back the entry/exit points of debugify were instrumented with conversion functions to/from non-intrinsic-form debug-info. This is the path of least resistance to incrementally converting parts of LLVM to use the new format. However, it turns out that debugify registers callbacks with the pass manager and can be fed non-intrinsic form debug-info. Thus: this patch wraps each of the four major debugify functions with the convertion utilities, and extends test coverage to a test that exposes this problem. (An alternative would be to put this code in the callback lambdas, but then it would be fighting pass manager abstractions of what type the IR has). Handily debugify has been designed to record the /meaning/ of debug-info rather than take pointers to intrinsics and the like, so the storage mechanism for debug-info is transparent to it!
2023-11-29[DebugInfo][RemoveDIs] Make debugify pass convert to/from RemoveDIs mode ↵Jeremy Morse1-6/+59
(#73251) Debugify is extremely useful as a testing and debugging tool, and a good number of LLVM-IR transform tests use it. We need it to support "new" non-instruction debug-info to get test coverage, but it's not important enough to completely convert right now (and it'd be a large undertaking). Thus: convert to/from dbg.value/DPValue mode on entry and exit of the pass, which gives us the functionality without any further work. The cost is compile-time, but again this is only happening during tests. Tested by: the large set of debugify tests enabled here. Note the InstCombine test (cast-mul-select.ll) that hasn't been fully enabled: this is because there's a debug-info sinking piece of code there that hasn't been instrumented.
2023-09-07[llvm] Use llvm::any_cast instead of any_cast (NFC) (#65565)kazutakahirata1-4/+4
This patch replaces any_cast with llvm::any_cast. This in turn allows us to gracefully switch to std::any in future by forwarding llvm::Any and llvm::any_cast to: using Any = std::any; template <class T> T *any_cast(Any *Value) { return std::any_cast<T>(Value); } respectively. Without this patch, it's ambiguous whether any_cast refers to std::any_cast or llvm::any_cast. As an added bonus, this patch makes it easier to mechanically replace llvm::any_cast with std::any_cast without affecting other occurrences of any_cast (e.g. in libcxx).
2023-03-16[Debugify] Use ModuleAnalysisManager in instrumentationArthur Eubanks1-37/+44
In preparation for doing module checks of PreservedAnalyses.
2023-03-15[Debugify/Strip] Fix returned PreservedAnalysesArthur Eubanks1-1/+3
2023-03-15[Debugify] Invalidate function analysesArthur Eubanks1-4/+10
Since debugify inserts instructions.
2023-01-06[DebugInfo][NFC] Rename is/setUndef to is/setKilllocationOCHyams1-2/+2
These names better reflect the semantics and also the implementation, since it's not just "undef" operands that are sentinels used to signal that the debug intrinsic terminates dominating locations definitions. Related to https://discourse.llvm.org/t/auto-undef-debug-uses-of-a-deleted-value Reviewed By: StephenTozer Differential Revision: https://reviews.llvm.org/D140903
2022-12-20[llvm] Make llvm::Any similar to std::anySebastian Neubauer1-8/+8
This facilitates replacing llvm::Any with std::any. - Deprecate any_isa in favor of using any_cast(Any*) and checking for nullptr because C++17 has no any_isa. - Remove the assert from any_cast(Any*), so it returns nullptr if the type is not correct. This aligns it with std::any_cast(any*). Use any_cast(Any*) throughout LLVM instead of checks with any_isa. This is the first part outlined in https://discourse.llvm.org/t/rfc-switching-from-llvm-any-to-std-any/67176 Differential Revision: https://reviews.llvm.org/D139973
2022-12-08Revert "[llvm] Replace llvm::Any with std::any"Sebastian Neubauer1-12/+10
msvc fails to link when using any_cast. This seems to be fixed recently only. https://developercommunity.visualstudio.com/t/stdany-doesnt-link-when-exceptions-are-disabled/376072 This reverts commit aeac2e4884a3ce62c920cd51806a9396da64d9f7.
2022-12-08[llvm] Replace llvm::Any with std::anySebastian Neubauer1-10/+12
llvm::Any had several bugs in the past, due to being sensitive to symbol visibility. (See D101972 and D108943) Even with these fixes applied, I still encounter the same issue on Windows. Similar to llvm::Optional going away in favor of std::optional, we can use std::any from C++17. Using std::any fixes the problem and puts the burden to do it correctly on the standard library. Differential Revision: https://reviews.llvm.org/D139532
2022-12-04DebugInfoMetadata: convert Optional to std::optionalKrzysztof Parzyszek1-1/+2
2022-12-02[Transforms] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-24[Debugify] Strip llvm.mir.debugify metadataAnton Sidorenko1-1/+6
We don't strip llvm.mir.debugify metadata in `llvm::stripDebugifyMetadata`. This may lead to incorrect number of lines and variables in the metadata when we run debugify twice, e.g. -run-pass=mir-debugify,...,mir-strip-debug,...,mir-debugify. Differential Revision: https://reviews.llvm.org/D138417
2022-09-29[Debugify][OriginalDIMode] Make HTML reporting infrastructure more resilientNikola Tesic1-6/+10
Debugify in OriginalDebugInfo mode (verify-each-debuginfo-preserve), when used in parallel builds of large projects, can produce incorrect report. More precisely, simultaneous writes to JSON report file, could form incorrect JSON objects, which describe found Debug Info bugs. This patch uses the lock/unlock mechanism to protect JSON report file and also makes script llvm/utils/llvm-original-di-preservation.py resilient to corrupted lines in the report file. So, it ensures the creation of HTML report. Differential Revision: https://reviews.llvm.org/D115616
2022-07-06[Debugify] Port verify-debuginfo-preserve to NewPMNikola Tesic1-11/+36
Debugify in OriginalDebugInfo mode, introduced with D82545, runs only with legacy PassManager. This patch enables this utility for the NewPM. Differential Revision: https://reviews.llvm.org/D115351
2022-04-21[Debugify] Limit number of processed functions for original modeNikola Tesic1-0/+12
Debugify in OriginalDebugInfo mode, does (DebugInfo) collect-before-pass & check-after-pass for each instruction, which is pretty expensive. When used to analyze DebugInfo losses in large projects (like LLVM), this raises the build time unacceptably. This patch introduces a limit for the number of processed functions per compile unit. By default, the limit is set to UINT_MAX (practically unlimited), and by using the introduced option -debugify-func-limit the limit could be set to any positive integer number. Differential revision: https://reviews.llvm.org/D115714
2022-03-25[Utils] stripDebugifyMetadata - use cast<> instead of dyn_cast_or_null<> to ↵Simon Pilgrim1-1/+1
avoid dereference of nullptr The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-03-22[Debugify] Use DebugifyLevel in Debugify original modeDjordje Todorovic1-26/+29
Before this patch the DebugifyLevel option was used for the synthetic mode, so after this, it will be used in the original mode as well. Differential Revision: https://reviews.llvm.org/D115623
2022-03-22[Debugify] Optimize debugify original modeDjordje Todorovic1-57/+62
Before we start addressing the issue with having a lot of false positives when using debugify in the original mode, we have made a few patches that should speed up the execution of the testing utility Passes. For example, when testing a large project (let's say LLVM project itself), we can face a lot of potential DI issues. Usually, we use -verify-each-debuginfo-preserve (that is very similar to -debugify-each) -- it collects DI metadata before each Pass, and after the Pass it checks if the Pass preserved the DI metadata. However, we can speed up this process, since we don't need to collect DI metadata before each Pass -- we could use the DI metadata that are collected after the previous Pass from the pipeline as an input for the next Pass. This patch speeds up the utility for ~2x. Differential Revision: https://reviews.llvm.org/D115622
2021-12-21[Debugify] Use WeakWH map collected before Pass when checking loc dropDjordje Todorovic1-1/+1
This fixes a typo/bug when checking for pointer reuse when testing DI location preservation in the Debugify original mode (when checking -g generated Debug Info). Differential Revision: https://reviews.llvm.org/D115621
2021-09-29NFC: [Debugify] Fix a typo when checking variables in the original modeDjordje Todorovic1-5/+5
2021-05-21Recommit: "[Debugify][Original DI] Test dbg var loc preservation""Djordje Todorovic1-9/+92
[Debugify][Original DI] Test dbg var loc preservation This is an improvement of [0]. This adds checking of original llvm.dbg.values()/declares() instructions in optimizations. We have picked a real issue that has been found with this (actually, picked one variable location missing from [1] and resolved the issue), and the result is the fix for that -- D100844. Before applying the D100844, using the options from [0] (but with this patch applied) on the compilation of GDB 7.11, the final HTML report for the debug-info issues can be found at [1] (please scroll down, and look for "Summary of Variable Location Bugs"). After applying the D100844, the numbers has improved a bit -- please take a look into [2]. [0] https://llvm.org/docs/HowToUpdateDebugInfo.html#\ test-original-debug-info-preservation-in-optimizations [1] https://djolertrk.github.io/di-check-before-adce-fix/ [2] https://djolertrk.github.io/di-check-after-adce-fix/ Differential Revision: https://reviews.llvm.org/D100845 The Unit test was failing because the pass from the test that modifies the IR, in its runOnFunction() didn't return 'true', so the expensive-check configuration triggered an assertion.
2021-05-20Revert "[Debugify][Original DI] Test dbg var loc preservation"Djordje Todorovic1-92/+9
This reverts commit 76f375f3d9d6902820ffc21200e454926748c678. This will be pushed again, after investigating a test failure: https://lab.llvm.org/buildbot/#/builders/16/builds/11254
2021-05-20[Debugify][Original DI] Test dbg var loc preservationDjordje Todorovic1-9/+92
This is an improvement of [0]. This adds checking of original llvm.dbg.values()/declares() instructions in optimizations. We have picked a real issue that has been found with this (actually, picked one variable location missing from [1] and resolved the issue), and the result is the fix for that -- D100844. Before applying the D100844, using the options from [0] (but with this patch applied) on the compilation of GDB 7.11, the final HTML report for the debug-info issues can be found at [1] (please scroll down, and look for "Summary of Variable Location Bugs"). After applying the D100844, the numbers has improved a bit -- please take a look into [2]. [0] https://llvm.org/docs/HowToUpdateDebugInfo.html\ [1] https://djolertrk.github.io/di-check-before-adce-fix/ [2] https://djolertrk.github.io/di-check-after-adce-fix/ Differential Revision: https://reviews.llvm.org/D100845
2021-05-14[Transforms][Debugify] Fix "Missing line" false alarm on PHI nodesDjordje Todorovic1-2/+2
This is a fix for https://bugs.llvm.org/show_bug.cgi?id=49959 The "Missing line" false alarm was introduced in D75242. Patch by Yilong Guo<yilong.guo@intel.com> Differential Revision: https://reviews.llvm.org/D100446
2021-04-21[Support] Don't include VirtualFileSystem.h in CommandLine.hNico Weber1-0/+1
CommandLine.h is indirectly included in ~50% of TUs when building clang, and VirtualFileSystem.h is large. (Already remarked by jhenderson on D70769.) No behavior change. Differential Revision: https://reviews.llvm.org/D100957
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan1-1/+1
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2021-03-17Reapply "[DebugInfo] Handle multiple variable location operands in IR"Stephen Tozer1-3/+4
Fixed section of code that iterated through a SmallDenseMap and added instructions in each iteration, causing non-deterministic code; replaced SmallDenseMap with MapVector to prevent non-determinism. This reverts commit 01ac6d1587e8613ba4278786e8341f8b492ac941.
2021-03-17Revert "[DebugInfo] Handle multiple variable location operands in IR"Hans Wennborg1-4/+3
This caused non-deterministic compiler output; see comment on the code review. > This patch updates the various IR passes to correctly handle dbg.values with a > DIArgList location. This patch does not actually allow DIArgLists to be produced > by salvageDebugInfo, and it does not affect any pass after codegen-prepare. > Other than that, it should cover every IR pass. > > Most of the changes simply extend code that operated on a single debug value to > operate on the list of debug values in the style of any_of, all_of, for_each, > etc. Instances of setOperand(0, ...) have been replaced with with > replaceVariableLocationOp, which takes the value that is being replaced as an > additional argument. In places where this value isn't readily available, we have > to track the old value through to the point where it gets replaced. > > Differential Revision: https://reviews.llvm.org/D88232 This reverts commit df69c69427dea7f5b3b3a4d4564bc77b0926ec88.
2021-03-11[Debugify][OriginalDIMode] Export the report into JSON fileDjordje Todorovic1-30/+104
By using the original-di check with debugify in the combination with the llvm/utils/llvm-original-di-preservation.py it becomes very user friendly tool. An example of the HTML page with the issues related to debug info can be found at [0]. [0] https://djolertrk.github.io/di-checker-html-report-example/ Differential Revision: https://reviews.llvm.org/D82546