Skip to content

Commit 7d77bbe

Browse files
committed
[DebugInfo][RemoveDIs] Add prototype storage classes for "new" debug-info
This patch adds a variety of classes needed to record variable location debug-info without using the existing intrinsic approach, see the rationale at [0]. The two added files and corresponding unit tests are the majority of the plumbing required for this, but at this point isn't accessible from the rest of LLVM as we need to stage it into the repo gently. An overview is that classes are added for recording variable information attached to Real (TM) instructions, in the form of DPValues and DPMarker objects. The metadata-uses of DPValues is plumbed into the metadata hierachy, and a field added to class Instruction, which are all stimulated in the unit tests. The next few patches in this series add utilities to convert to/from this new debug-info format and add instruction/block utilities to have debug-info automatically updated in the background when various operations occur. This patch was reviewed in Phab in D153990 and D154080, I've squashed them together into this commit as there are dependencies between the two patches, and there's little profit in landing them separately. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939
1 parent c95253b commit 7d77bbe

25 files changed

+1637
-11
lines changed

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/ilist_node.h"
2020
#include "llvm/ADT/iterator.h"
2121
#include "llvm/ADT/iterator_range.h"
22+
#include "llvm/IR/DebugProgramInstruction.h"
2223
#include "llvm/IR/Instruction.h"
2324
#include "llvm/IR/SymbolTableListTraits.h"
2425
#include "llvm/IR/Value.h"
@@ -56,6 +57,9 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
5657
public ilist_node_with_parent<BasicBlock, Function> {
5758
public:
5859
using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>>;
60+
/// Flag recording whether or not this block stores debug-info in the form
61+
/// of intrinsic instructions (false) or non-instruction records (true).
62+
bool IsNewDbgInfoFormat;
5963

6064
private:
6165
friend class BlockAddress;
@@ -64,6 +68,55 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
6468
InstListType InstList;
6569
Function *Parent;
6670

71+
public:
72+
/// Attach a DPMarker to the given instruction. Enables the storage of any
73+
/// debug-info at this position in the program.
74+
DPMarker *createMarker(Instruction *I);
75+
DPMarker *createMarker(InstListType::iterator It);
76+
77+
/// Convert variable location debugging information stored in dbg.value
78+
/// intrinsics into DPMarker / DPValue records. Deletes all dbg.values in
79+
/// the process and sets IsNewDbgInfoFormat = true. Only takes effect if
80+
/// the UseNewDbgInfoFormat LLVM command line option is given.
81+
void convertToNewDbgValues();
82+
83+
/// Convert variable location debugging information stored in DPMarkers and
84+
/// DPValues into the dbg.value intrinsic representation. Sets
85+
/// IsNewDbgInfoFormat = false.
86+
void convertFromNewDbgValues();
87+
88+
/// Ensure the block is in "old" dbg.value format (\p NewFlag == false) or
89+
/// in the new format (\p NewFlag == true), converting to the desired format
90+
/// if necessary.
91+
void setIsNewDbgInfoFormat(bool NewFlag);
92+
93+
/// Validate any DPMarkers / DPValues attached to instructions in this block,
94+
/// and block-level stored data too (TrailingDPValues).
95+
/// \p Assert Should this method fire an assertion if a problem is found?
96+
/// \p Msg Should this method print a message to errs() if a problem is found?
97+
/// \p OS Output stream to write errors to.
98+
/// \returns True if a problem is found.
99+
bool validateDbgValues(bool Assert = true, bool Msg = false,
100+
raw_ostream *OS = nullptr);
101+
102+
/// Record that the collection of DPValues in \p M "trails" after the last
103+
/// instruction of this block. These are equivalent to dbg.value intrinsics
104+
/// that exist at the end of a basic block with no terminator (a transient
105+
/// state that occurs regularly).
106+
void setTrailingDPValues(DPMarker *M);
107+
108+
/// Fetch the collection of DPValues that "trail" after the last instruction
109+
/// of this block, see \ref setTrailingDPValues. If there are none, returns
110+
/// nullptr.
111+
DPMarker *getTrailingDPValues();
112+
113+
/// Delete any trailing DPValues at the end of this block, see
114+
/// \ref setTrailingDPValues.
115+
void deleteTrailingDPValues();
116+
117+
void dumpDbgValues() const;
118+
119+
private:
67120
void setParent(Function *parent);
68121

69122
/// Constructor.

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,6 +3765,10 @@ class DIArgList : public MDNode {
37653765
iterator args_begin() { return Args.begin(); }
37663766
iterator args_end() { return Args.end(); }
37673767

3768+
ReplaceableMetadataImpl *getReplaceableUses() {
3769+
return Context.getReplaceableUses();
3770+
}
3771+
37683772
static bool classof(const Metadata *MD) {
37693773
return MD->getMetadataID() == DIArgListKind;
37703774
}

0 commit comments

Comments
 (0)