Skip to content

Commit f1b0a54

Browse files
committed
Reapply 7d77bbe, adding new debug-info classes
This reverts commit 957efa4. Original commit message below -- in this follow up, I've shifted un-necessary inclusions of DebugProgramInstruction.h into being forward declarations (fixes clang-compile time I hope), and a memory leak in the DebugInfoTest.cpp IR unittests. I also tracked a compile-time regression in D154080, more explanation there, but the result of which is hiding some of the changes behind the EXPERIMENTAL_DEBUGINFO_ITERATORS compile-time flag. This is tested by the "new-debug-iterators" buildbot. [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 671d10a commit f1b0a54

25 files changed

+1658
-9
lines changed

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class LLVMContext;
3636
class Module;
3737
class PHINode;
3838
class ValueSymbolTable;
39+
class DPValue;
40+
class DPMarker;
3941

4042
/// LLVM Basic Block Representation
4143
///
@@ -56,6 +58,9 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
5658
public ilist_node_with_parent<BasicBlock, Function> {
5759
public:
5860
using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>>;
61+
/// Flag recording whether or not this block stores debug-info in the form
62+
/// of intrinsic instructions (false) or non-instruction records (true).
63+
bool IsNewDbgInfoFormat;
5964

6065
private:
6166
friend class BlockAddress;
@@ -64,6 +69,55 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
6469
InstListType InstList;
6570
Function *Parent;
6671

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

69123
/// 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)