Skip to content

[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord #85216

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 4 commits into from
Mar 19, 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
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4770,9 +4770,9 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
assert(!Last.isTerminator() && "unexpected terminator");
if (auto *Marker =
CGF.Builder.GetInsertBlock()->getTrailingDbgRecords()) {
for (llvm::DPValue &DPV : llvm::reverse(
for (llvm::DbgVariableRecord &DVR : llvm::reverse(
llvm::filterDbgVars(Marker->getDbgRecordRange()))) {
UpdateExpr(Last.getContext(), &DPV, Offset);
UpdateExpr(Last.getContext(), &DVR, Offset);
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions llvm/docs/RemoveDIsDebugInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ This will all happen transparently without needing to think about it!
We're using a dedicated C++ class called `DbgRecord` to store debug info, with a one-to-one relationship between each instance of a debug intrinsic and each `DbgRecord` object in any LLVM IR program; these `DbgRecord`s are represented in the IR as non-instruction debug records, as described in the [Source Level Debugging](project:SourceLevelDebugging.rst#Debug Records) document. This class has a set of subclasses that store exactly the same information as is stored in debugging intrinsics. Each one also has almost entirely the same set of methods, that behave in the same way:

https://llvm.org/docs/doxygen/classllvm_1_1DbgRecord.html
https://llvm.org/docs/doxygen/classllvm_1_1DPValue.html
https://llvm.org/docs/doxygen/classllvm_1_1DbgVariableRecord.html
https://llvm.org/docs/doxygen/classllvm_1_1DPLabel.html

This allows you to treat a `DPValue` as if it's a `dbg.value`/`dbg.declare`/`dbg.assign` intrinsic most of the time, for example in generic (auto-param) lambdas, and the same for `DPLabel` and `dbg.label`s.
This allows you to treat a `DbgVariableRecord` as if it's a `dbg.value`/`dbg.declare`/`dbg.assign` intrinsic most of the time, for example in generic (auto-param) lambdas, and the same for `DPLabel` and `dbg.label`s.

## How do these `DbgRecords` fit into the instruction stream?

Expand Down Expand Up @@ -95,13 +95,13 @@ Like so:

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.

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 `DPValue` 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.
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.

The various kinds of debug intrinsic (value, declare, assign, label) are all stored in `DbgRecord` subclasses, with a "RecordKind" field distinguishing `DPLabel`s from `DPValue`s, and a `LocationType` field in the `DPValue` class further disambiguating the various debug variable intrinsics it can represent.
The various kinds of debug intrinsic (value, declare, assign, label) are all stored in `DbgRecord` subclasses, with a "RecordKind" field distinguishing `DPLabel`s from `DbgVariableRecord`s, and a `LocationType` field in the `DbgVariableRecord` class further disambiguating the various debug variable intrinsics it can represent.

## Finding debug info records

Utilities such as `findDbgUsers` and the like now have an optional argument that will return the set of `DPValue` records that refer to a `Value`. You should be able to treat them the same as intrinsics.
Utilities such as `findDbgUsers` and the like now have an optional argument that will return the set of `DbgVariableRecord` records that refer to a `Value`. You should be able to treat them the same as intrinsics.

## Examining debug info records at positions

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class FunctionLoweringInfo {
/// Collection of dbg.declare instructions handled after argument
/// lowering and before ISel proper.
SmallPtrSet<const DbgDeclareInst *, 8> PreprocessedDbgDeclares;
SmallPtrSet<const DPValue *, 8> PreprocessedDPVDeclares;
SmallPtrSet<const DbgVariableRecord *, 8> PreprocessedDVRDeclares;

/// set - Initialize this FunctionLoweringInfo with the given Function
/// and its associated MachineFunction.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LLVMContext;
class Module;
class PHINode;
class ValueSymbolTable;
class DPValue;
class DbgVariableRecord;
class DPMarker;

/// LLVM Basic Block Representation
Expand Down Expand Up @@ -121,10 +121,10 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
DPMarker *getNextMarker(Instruction *I);

/// Insert a DbgRecord into a block at the position given by \p I.
void insertDbgRecordAfter(DbgRecord *DPV, Instruction *I);
void insertDbgRecordAfter(DbgRecord *DR, Instruction *I);

/// Insert a DbgRecord into a block at the position given by \p Here.
void insertDbgRecordBefore(DbgRecord *DPV, InstListType::iterator Here);
void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here);

/// Eject any debug-info trailing at the end of a block. DbgRecords can
/// transiently be located "off the end" of a block if the blocks terminator
Expand Down
7 changes: 4 additions & 3 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ namespace llvm {
DbgInstPtr insertLabel(DILabel *LabelInfo, const DILocation *DL,
BasicBlock *InsertBB, Instruction *InsertBefore);

/// Internal helper. Track metadata if untracked and insert \p DPV.
void insertDPValue(DPValue *DPV, BasicBlock *InsertBB,
Instruction *InsertBefore, bool InsertAtHead = false);
/// Internal helper. Track metadata if untracked and insert \p DVR.
void insertDbgVariableRecord(DbgVariableRecord *DVR, BasicBlock *InsertBB,
Instruction *InsertBefore,
bool InsertAtHead = false);

/// Internal helper with common code used by insertDbg{Value,Addr}Intrinsic.
Instruction *insertDbgIntrinsic(llvm::Function *Intrinsic, llvm::Value *Val,
Expand Down
40 changes: 22 additions & 18 deletions llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,33 @@ namespace llvm {
class DbgDeclareInst;
class DbgValueInst;
class DbgVariableIntrinsic;
class DPValue;
class DbgVariableRecord;
class Instruction;
class Module;

/// Finds dbg.declare intrinsics declaring local variables as living in the
/// memory that 'V' points to.
TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
/// As above, for DPVDeclares.
TinyPtrVector<DPValue *> findDPVDeclares(Value *V);
/// As above, for DVRDeclares.
TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);

/// Finds the llvm.dbg.value intrinsics describing a value.
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues,
Value *V, SmallVectorImpl<DPValue *> *DPValues = nullptr);
void findDbgValues(
SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);

/// Finds the debug info intrinsics describing a value.
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts,
Value *V, SmallVectorImpl<DPValue *> *DPValues = nullptr);
void findDbgUsers(
SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V,
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords = nullptr);

/// Find subprogram that is enclosing this scope.
DISubprogram *getDISubprogram(const MDNode *Scope);

/// Produce a DebugLoc to use for each dbg.declare that is promoted to a
/// dbg.value.
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII);
DebugLoc getDebugValueLoc(DPValue *DPV);
DebugLoc getDebugValueLoc(DbgVariableRecord *DVR);

/// Strip debug info in the module if it exists.
///
Expand Down Expand Up @@ -109,7 +111,8 @@ class DebugInfoFinder {
void processVariable(const Module &M, const DILocalVariable *DVI);
/// Process debug info location.
void processLocation(const Module &M, const DILocation *Loc);
/// Process a DbgRecord (e.g, treat a DPValue like a DbgVariableIntrinsic).
/// Process a DbgRecord (e.g, treat a DbgVariableRecord like a
/// DbgVariableIntrinsic).
void processDbgRecord(const Module &M, const DbgRecord &DR);

/// Process subprogram.
Expand Down Expand Up @@ -193,10 +196,10 @@ inline AssignmentInstRange getAssignmentInsts(const DbgAssignIntrinsic *DAI) {
return getAssignmentInsts(DAI->getAssignID());
}

inline AssignmentInstRange getAssignmentInsts(const DPValue *DPV) {
assert(DPV->isDbgAssign() &&
"Can't get assignment instructions for non-assign DPV!");
return getAssignmentInsts(DPV->getAssignID());
inline AssignmentInstRange getAssignmentInsts(const DbgVariableRecord *DVR) {
assert(DVR->isDbgAssign() &&
"Can't get assignment instructions for non-assign DVR!");
return getAssignmentInsts(DVR->getAssignID());
}

//
Expand Down Expand Up @@ -231,9 +234,10 @@ inline AssignmentMarkerRange getAssignmentMarkers(const Instruction *Inst) {
return make_range(Value::user_iterator(), Value::user_iterator());
}

inline SmallVector<DPValue *> getDPVAssignmentMarkers(const Instruction *Inst) {
inline SmallVector<DbgVariableRecord *>
getDVRAssignmentMarkers(const Instruction *Inst) {
if (auto *ID = Inst->getMetadata(LLVMContext::MD_DIAssignID))
return cast<DIAssignID>(ID)->getAllDPValueUsers();
return cast<DIAssignID>(ID)->getAllDbgVariableRecordUsers();
return {};
}

Expand Down Expand Up @@ -261,7 +265,7 @@ bool calculateFragmentIntersect(
std::optional<DIExpression::FragmentInfo> &Result);
bool calculateFragmentIntersect(
const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
uint64_t SliceSizeInBits, const DPValue *DPVAssign,
uint64_t SliceSizeInBits, const DbgVariableRecord *DVRAssign,
std::optional<DIExpression::FragmentInfo> &Result);

/// Helper struct for trackAssignments, below. We don't use the similar
Expand All @@ -276,8 +280,8 @@ struct VarRecord {

VarRecord(DbgVariableIntrinsic *DVI)
: Var(DVI->getVariable()), DL(getDebugValueLoc(DVI)) {}
VarRecord(DPValue *DPV)
: Var(DPV->getVariable()), DL(getDebugValueLoc(DPV)) {}
VarRecord(DbgVariableRecord *DVR)
: Var(DVR->getVariable()), DL(getDebugValueLoc(DVR)) {}
VarRecord(DILocalVariable *Var, DILocation *DL) : Var(Var), DL(DL) {}
friend bool operator<(const VarRecord &LHS, const VarRecord &RHS) {
return std::tie(LHS.Var, LHS.DL) < std::tie(RHS.Var, RHS.DL);
Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ enum Tag : uint16_t;
}

class DbgVariableIntrinsic;
class DPValue;
class DbgVariableRecord;

extern cl::opt<bool> EnableFSDiscriminator;

Expand Down Expand Up @@ -323,8 +323,8 @@ class DIAssignID : public MDNode {
// This node has no operands to replace.
void replaceOperandWith(unsigned I, Metadata *New) = delete;

SmallVector<DPValue *> getAllDPValueUsers() {
return Context.getReplaceableUses()->getAllDPValueUsers();
SmallVector<DbgVariableRecord *> getAllDbgVariableRecordUsers() {
return Context.getReplaceableUses()->getAllDbgVariableRecordUsers();
}

static DIAssignID *getDistinct(LLVMContext &Context) {
Expand Down Expand Up @@ -3840,8 +3840,8 @@ class DIArgList : public Metadata, ReplaceableMetadataImpl {
return MD->getMetadataID() == DIArgListKind;
}

SmallVector<DPValue *> getAllDPValueUsers() {
return ReplaceableMetadataImpl::getAllDPValueUsers();
SmallVector<DbgVariableRecord *> getAllDbgVariableRecordUsers() {
return ReplaceableMetadataImpl::getAllDbgVariableRecordUsers();
}

void handleChangedOperand(void *Ref, Metadata *New);
Expand Down Expand Up @@ -3871,7 +3871,7 @@ class DebugVariable {

public:
DebugVariable(const DbgVariableIntrinsic *DII);
DebugVariable(const DPValue *DPV);
DebugVariable(const DbgVariableRecord *DVR);

DebugVariable(const DILocalVariable *Var,
std::optional<FragmentInfo> FragmentInfo,
Expand Down
Loading