Skip to content

[RemoveDIs][NFC] Rename DPMarker->DbgMarker #85931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions llvm/docs/RemoveDIsDebugInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ Like so:
|
|
v
+------------+
<-------+ DPMarker |<-------
/ +------------+ \
/ \
/ \
v ^
+-------------+
<-------+ DbgMarker |<-------
/ +-------------+ \
/ \
/ \
v ^
+-------------+ +-------------+ +-------------+
| DbgRecord +--->| DbgRecord +-->| DbgRecord |
+-------------+ +-------------+ +-------------+
```

Each instruction has a pointer to a `DPMarker` (which will become optional), that contains a list of `DbgRecord` objects. No debugging records appear in the instruction list at all. `DbgRecord`s have a parent pointer to their owning `DPMarker`, and each `DPMarker` has a pointer back to it's owning instruction.
Each instruction has a pointer to a `DbgMarker` (which will become optional), that contains a list of `DbgRecord` objects. No debugging records appear in the instruction list at all. `DbgRecord`s have a parent pointer to their owning `DbgMarker`, and each `DbgMarker` has a pointer back to it's owning instruction.

Not shown are the links from DbgRecord to other parts of the `Value`/`Metadata` hierachy: `DbgRecord` subclasses have tracking pointers to the DIMetadata that they use, and `DbgVariableRecord` has references to `Value`s that are stored in a `DebugValueUser` base class. This refers to a `ValueAsMetadata` object referring to `Value`s, via the `TrackingMetadata` facility.

Expand Down
28 changes: 14 additions & 14 deletions llvm/include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Module;
class PHINode;
class ValueSymbolTable;
class DbgVariableRecord;
class DPMarker;
class DbgMarker;

/// LLVM Basic Block Representation
///
Expand Down Expand Up @@ -72,18 +72,18 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
Function *Parent;

public:
/// Attach a DPMarker to the given instruction. Enables the storage of any
/// Attach a DbgMarker to the given instruction. Enables the storage of any
/// debug-info at this position in the program.
DPMarker *createMarker(Instruction *I);
DPMarker *createMarker(InstListType::iterator It);
DbgMarker *createMarker(Instruction *I);
DbgMarker *createMarker(InstListType::iterator It);

/// Convert variable location debugging information stored in dbg.value
/// intrinsics into DPMarkers / DbgRecords. Deletes all dbg.values in
/// intrinsics into DbgMarkers / DbgRecords. Deletes all dbg.values in
/// the process and sets IsNewDbgInfoFormat = true. Only takes effect if
/// the UseNewDbgInfoFormat LLVM command line option is given.
void convertToNewDbgValues();

/// Convert variable location debugging information stored in DPMarkers and
/// Convert variable location debugging information stored in DbgMarkers and
/// DbgRecords into the dbg.value intrinsic representation. Sets
/// IsNewDbgInfoFormat = false.
void convertFromNewDbgValues();
Expand All @@ -97,28 +97,28 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
/// instruction of this block. These are equivalent to dbg.value intrinsics
/// that exist at the end of a basic block with no terminator (a transient
/// state that occurs regularly).
void setTrailingDbgRecords(DPMarker *M);
void setTrailingDbgRecords(DbgMarker *M);

/// Fetch the collection of DbgRecords that "trail" after the last instruction
/// of this block, see \ref setTrailingDbgRecords. If there are none, returns
/// nullptr.
DPMarker *getTrailingDbgRecords();
DbgMarker *getTrailingDbgRecords();

/// Delete any trailing DbgRecords at the end of this block, see
/// \ref setTrailingDbgRecords.
void deleteTrailingDbgRecords();

void dumpDbgValues() const;

/// Return the DPMarker for the position given by \p It, so that DbgRecords
/// Return the DbgMarker for the position given by \p It, so that DbgRecords
/// can be inserted there. This will either be nullptr if not present, a
/// DPMarker, or TrailingDbgRecords if It is end().
DPMarker *getMarker(InstListType::iterator It);
/// DbgMarker, or TrailingDbgRecords if It is end().
DbgMarker *getMarker(InstListType::iterator It);

/// Return the DPMarker for the position that comes after \p I. \see
/// BasicBlock::getMarker, this can be nullptr, a DPMarker, or
/// Return the DbgMarker for the position that comes after \p I. \see
/// BasicBlock::getMarker, this can be nullptr, a DbgMarker, or
/// TrailingDbgRecords if there is no next instruction.
DPMarker *getNextMarker(Instruction *I);
DbgMarker *getNextMarker(Instruction *I);

/// Insert a DbgRecord into a block at the position given by \p I.
void insertDbgRecordAfter(DbgRecord *DR, Instruction *I);
Expand Down
71 changes: 36 additions & 35 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
//
// and all information is stored in the Value / Metadata hierachy defined
// elsewhere in LLVM. In the "DbgRecord" design, each instruction /may/ have a
// connection with a DPMarker, which identifies a position immediately before
// the instruction, and each DPMarker /may/ then have connections to DbgRecords
// connection with a DbgMarker, which identifies a position immediately before
// the instruction, and each DbgMarker /may/ then have connections to DbgRecords
// which record the variable assignment information. To illustrate:
//
// %foo = add i32 1, %0
// ; foo->DbgMarker == nullptr
// ; foo->DebugMarker == nullptr
// ;; There are no variable assignments / debug records "in front" of
// ;; the instruction for %foo, therefore it has no DbgMarker.
// ;; the instruction for %foo, therefore it has no DebugMarker.
// %bar = void call @ext(%foo)
// ; bar->DbgMarker = {
// ; bar->DebugMarker = {
// ; StoredDbgRecords = {
// ; DbgVariableRecord(metadata i32 %foo, ...)
// ; }
// ; }
// ;; There is a debug-info record in front of the %bar instruction,
// ;; thus it points at a DPMarker object. That DPMarker contains a
// ;; thus it points at a DbgMarker object. That DbgMarker contains a
// ;; DbgVariableRecord in it's ilist, storing the equivalent information
// to the
// ;; dbg.value above: the Value, DILocalVariable, etc.
Expand Down Expand Up @@ -66,7 +66,7 @@ class DbgVariableIntrinsic;
class DbgInfoIntrinsic;
class DbgLabelInst;
class DIAssignID;
class DPMarker;
class DbgMarker;
class DbgVariableRecord;
class raw_ostream;

Expand Down Expand Up @@ -120,7 +120,7 @@ template <typename T> class DbgRecordParamRef {
/// Base class for non-instruction debug metadata records that have positions
/// within IR. Features various methods copied across from the Instruction
/// class to aid ease-of-use. DbgRecords should always be linked into a
/// DPMarker's StoredDbgRecords list. The marker connects a DbgRecord back to
/// DbgMarker's StoredDbgRecords list. The marker connects a DbgRecord back to
/// it's position in the BasicBlock.
///
/// We need a discriminator for dyn/isa casts. In order to avoid paying for a
Expand All @@ -134,7 +134,7 @@ template <typename T> class DbgRecordParamRef {
class DbgRecord : public ilist_node<DbgRecord> {
public:
/// Marker that this DbgRecord is linked into.
DPMarker *Marker = nullptr;
DbgMarker *Marker = nullptr;
/// Subclass discriminator.
enum Kind : uint8_t { ValueKind, LabelKind };

Expand Down Expand Up @@ -166,10 +166,10 @@ class DbgRecord : public ilist_node<DbgRecord> {

Kind getRecordKind() const { return RecordKind; }

void setMarker(DPMarker *M) { Marker = M; }
void setMarker(DbgMarker *M) { Marker = M; }

DPMarker *getMarker() { return Marker; }
const DPMarker *getMarker() const { return Marker; }
DbgMarker *getMarker() { return Marker; }
const DbgMarker *getMarker() const { return Marker; }

BasicBlock *getBlock();
const BasicBlock *getBlock() const;
Expand Down Expand Up @@ -539,7 +539,7 @@ filterDbgVars(iterator_range<simple_ilist<DbgRecord>::iterator> R) {
}

/// Per-instruction record of debug-info. If an Instruction is the position of
/// some debugging information, it points at a DPMarker storing that info. Each
/// some debugging information, it points at a DbgMarker storing that info. Each
/// marker points back at the instruction that owns it. Various utilities are
/// provided for manipulating the DbgRecords contained within this marker.
///
Expand All @@ -559,9 +559,9 @@ filterDbgVars(iterator_range<simple_ilist<DbgRecord>::iterator> R) {
/// which we can improve in the future. Additionally, many improvements in the
/// way that debug-info is stored can be achieved in this class, at a future
/// date.
class DPMarker {
class DbgMarker {
public:
DPMarker() {}
DbgMarker() {}
/// Link back to the Instruction that owns this marker. Can be null during
/// operations that move a marker from one instruction to another.
Instruction *MarkedInstr = nullptr;
Expand All @@ -585,30 +585,31 @@ class DPMarker {
void removeFromParent();
void eraseFromParent();

/// Implement operator<< on DPMarker.
/// Implement operator<< on DbgMarker.
void print(raw_ostream &O, bool IsForDebug = false) const;
void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;

/// Produce a range over all the DbgRecords in this Marker.
iterator_range<simple_ilist<DbgRecord>::iterator> getDbgRecordRange();
iterator_range<simple_ilist<DbgRecord>::const_iterator>
getDbgRecordRange() const;
/// Transfer any DbgRecords from \p Src into this DPMarker. If \p InsertAtHead
/// is true, place them before existing DbgRecords, otherwise afterwards.
void absorbDebugValues(DPMarker &Src, bool InsertAtHead);
/// Transfer the DbgRecords in \p Range from \p Src into this DPMarker. If
/// Transfer any DbgRecords from \p Src into this DbgMarker. If \p
/// InsertAtHead is true, place them before existing DbgRecords, otherwise
/// afterwards.
void absorbDebugValues(DbgMarker &Src, bool InsertAtHead);
/// Transfer the DbgRecords in \p Range from \p Src into this DbgMarker. If
/// \p InsertAtHead is true, place them before existing DbgRecords, otherwise
// afterwards.
void absorbDebugValues(iterator_range<DbgRecord::self_iterator> Range,
DPMarker &Src, bool InsertAtHead);
/// Insert a DbgRecord into this DPMarker, at the end of the list. If
DbgMarker &Src, bool InsertAtHead);
/// Insert a DbgRecord into this DbgMarker, at the end of the list. If
/// \p InsertAtHead is true, at the start.
void insertDbgRecord(DbgRecord *New, bool InsertAtHead);
/// Insert a DbgRecord prior to a DbgRecord contained within this marker.
void insertDbgRecord(DbgRecord *New, DbgRecord *InsertBefore);
/// Insert a DbgRecord after a DbgRecord contained within this marker.
void insertDbgRecordAfter(DbgRecord *New, DbgRecord *InsertAfter);
/// Clone all DPMarkers from \p From into this marker. There are numerous
/// Clone all DbgMarkers from \p From into this marker. There are numerous
/// options to customise the source/destination, due to gnarliness, see class
/// comment.
/// \p FromHere If non-null, copy from FromHere to the end of From's
Expand All @@ -617,45 +618,45 @@ class DPMarker {
/// StoredDbgRecords
/// \returns Range over all the newly cloned DbgRecords
iterator_range<simple_ilist<DbgRecord>::iterator>
cloneDebugInfoFrom(DPMarker *From,
cloneDebugInfoFrom(DbgMarker *From,
std::optional<simple_ilist<DbgRecord>::iterator> FromHere,
bool InsertAtHead = false);
/// Erase all DbgRecords in this DPMarker.
/// Erase all DbgRecords in this DbgMarker.
void dropDbgRecords();
/// Erase a single DbgRecord from this marker. In an ideal future, we would
/// never erase an assignment in this way, but it's the equivalent to
/// erasing a debug intrinsic from a block.
void dropOneDbgRecord(DbgRecord *DR);

/// We generally act like all llvm Instructions have a range of DbgRecords
/// attached to them, but in reality sometimes we don't allocate the DPMarker
/// attached to them, but in reality sometimes we don't allocate the DbgMarker
/// to save time and memory, but still have to return ranges of DbgRecords.
/// When we need to describe such an unallocated DbgRecord range, use this
/// static markers range instead. This will bite us if someone tries to insert
/// a DbgRecord in that range, but they should be using the Official (TM) API
/// for that.
static DPMarker EmptyDPMarker;
static DbgMarker EmptyDbgMarker;
static iterator_range<simple_ilist<DbgRecord>::iterator>
getEmptyDbgRecordRange() {
return make_range(EmptyDPMarker.StoredDbgRecords.end(),
EmptyDPMarker.StoredDbgRecords.end());
return make_range(EmptyDbgMarker.StoredDbgRecords.end(),
EmptyDbgMarker.StoredDbgRecords.end());
}
};

inline raw_ostream &operator<<(raw_ostream &OS, const DPMarker &Marker) {
inline raw_ostream &operator<<(raw_ostream &OS, const DbgMarker &Marker) {
Marker.print(OS);
return OS;
}

/// Inline helper to return a range of DbgRecords attached to a marker. It needs
/// to be inlined as it's frequently called, but also come after the declaration
/// of DPMarker. Thus: it's pre-declared by users like Instruction, then an
/// of DbgMarker. Thus: it's pre-declared by users like Instruction, then an
/// inlineable body defined here.
inline iterator_range<simple_ilist<DbgRecord>::iterator>
getDbgRecordRange(DPMarker *DbgMarker) {
if (!DbgMarker)
return DPMarker::getEmptyDbgRecordRange();
return DbgMarker->getDbgRecordRange();
getDbgRecordRange(DbgMarker *DebugMarker) {
if (!DebugMarker)
return DbgMarker::getEmptyDbgRecordRange();
return DebugMarker->getDbgRecordRange();
}

DEFINE_ISA_CONVERSION_FUNCTIONS(DbgRecord, LLVMDbgRecordRef)
Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
namespace llvm {

class BasicBlock;
class DPMarker;
class DbgMarker;
class FastMathFlags;
class MDNode;
class Module;
struct AAMDNodes;
class DPMarker;
class DbgMarker;
class DbgRecord;

template <> struct ilist_alloc_traits<Instruction> {
static inline void deleteNode(Instruction *V);
};

iterator_range<simple_ilist<DbgRecord>::iterator> getDbgRecordRange(DPMarker *);
iterator_range<simple_ilist<DbgRecord>::iterator>
getDbgRecordRange(DbgMarker *);

class Instruction : public User,
public ilist_node_with_parent<Instruction, BasicBlock,
Expand All @@ -60,7 +61,7 @@ class Instruction : public User,
/// Optional marker recording the position for debugging information that
/// takes effect immediately before this instruction. Null unless there is
/// debugging information present.
DPMarker *DbgMarker = nullptr;
DbgMarker *DebugMarker = nullptr;

/// Clone any debug-info attached to \p From onto this instruction. Used to
/// copy debugging information from one block to another, when copying entire
Expand All @@ -81,7 +82,7 @@ class Instruction : public User,

/// Return a range over the DbgRecords attached to this instruction.
iterator_range<simple_ilist<DbgRecord>::iterator> getDbgRecordRange() const {
return llvm::getDbgRecordRange(DbgMarker);
return llvm::getDbgRecordRange(DebugMarker);
}

/// Return an iterator to the position of the "Next" DbgRecord after this
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3569,7 +3569,7 @@ void ModuleBitcodeWriter::writeFunction(
// Write out non-instruction debug information attached to this
// instruction. Write it after the instruction so that it's easy to
// re-attach to the instruction reading the records in.
for (DbgRecord &DR : I.DbgMarker->getDbgRecordRange()) {
for (DbgRecord &DR : I.DebugMarker->getDbgRecordRange()) {
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
Vals.push_back(VE.getMetadataID(&*DLR->getDebugLoc()));
Vals.push_back(VE.getMetadataID(DLR->getLabel()));
Expand Down
Loading