Skip to content

[RemoveDIs][NFC] Rename DPLabel->DbgLabelRecord #85918

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 2 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
6 changes: 3 additions & 3 deletions llvm/docs/RemoveDIsDebugInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ We're using a dedicated C++ class called `DbgRecord` to store debug info, with a

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

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.
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 `DbgLabelRecord` and `dbg.label`s.

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

Expand Down Expand Up @@ -97,7 +97,7 @@ Each instruction has a pointer to a `DPMarker` (which will become optional), tha

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 `DbgVariableRecord`s, and a `LocationType` field in the `DbgVariableRecord` 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 `DbgLabelRecord`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

Expand Down
22 changes: 12 additions & 10 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,25 @@ inline raw_ostream &operator<<(raw_ostream &OS, const DbgRecord &R) {
/// llvm.dbg.label intrinsic.
/// FIXME: Rename DbgLabelRecord when DbgVariableRecord is renamed to
/// DbgVariableRecord.
class DPLabel : public DbgRecord {
class DbgLabelRecord : public DbgRecord {
DbgRecordParamRef<DILabel> Label;

/// This constructor intentionally left private, so that it is only called via
/// "createUnresolvedDPLabel", which clearly expresses that it is for parsing
/// only.
DPLabel(MDNode *Label, MDNode *DL);
/// "createUnresolvedDbgLabelRecord", which clearly expresses that it is for
/// parsing only.
DbgLabelRecord(MDNode *Label, MDNode *DL);

public:
DPLabel(DILabel *Label, DebugLoc DL);
DbgLabelRecord(DILabel *Label, DebugLoc DL);

/// For use during parsing; creates a DPLabel from as-of-yet unresolved
/// MDNodes. Trying to access the resulting DPLabel's fields before they are
/// resolved, or if they resolve to the wrong type, will result in a crash.
static DPLabel *createUnresolvedDPLabel(MDNode *Label, MDNode *DL);
/// For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved
/// MDNodes. Trying to access the resulting DbgLabelRecord's fields before
/// they are resolved, or if they resolve to the wrong type, will result in a
/// crash.
static DbgLabelRecord *createUnresolvedDbgLabelRecord(MDNode *Label,
MDNode *DL);

DPLabel *clone() const;
DbgLabelRecord *clone() const;
void print(raw_ostream &O, bool IsForDebug = false) const;
void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;
DbgLabelInst *createDebugIntrinsic(Module *M,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6607,7 +6607,7 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
return true;
if (parseToken(lltok::rparen, "Expected ')' here"))
return true;
DR = DPLabel::createUnresolvedDPLabel(Label, DbgLoc);
DR = DbgLabelRecord::createUnresolvedDbgLabelRecord(Label, DbgLoc);
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6426,14 +6426,15 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
break;
}
case bitc::FUNC_CODE_DEBUG_RECORD_LABEL: {
// DPLabels are placed after the Instructions that they are attached to.
// DbgLabelRecords are placed after the Instructions that they are
// attached to.
Instruction *Inst = getLastInstruction();
if (!Inst)
return error("Invalid dbg record: missing instruction");
DILocation *DIL = cast<DILocation>(getFnMetadataByID(Record[0]));
DILabel *Label = cast<DILabel>(getFnMetadataByID(Record[1]));
Inst->getParent()->insertDbgRecordBefore(
new DPLabel(Label, DebugLoc(DIL)), Inst->getIterator());
new DbgLabelRecord(Label, DebugLoc(DIL)), Inst->getIterator());
continue; // This isn't an instruction.
}
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3570,9 +3570,9 @@ void ModuleBitcodeWriter::writeFunction(
// 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()) {
if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
Vals.push_back(VE.getMetadataID(&*DPL->getDebugLoc()));
Vals.push_back(VE.getMetadataID(DPL->getLabel()));
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
Vals.push_back(VE.getMetadataID(&*DLR->getDebugLoc()));
Vals.push_back(VE.getMetadataID(DLR->getLabel()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_LABEL, Vals);
Vals.clear();
continue;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ ValueEnumerator::ValueEnumerator(const Module &M,
};

for (DbgRecord &DR : I.getDbgRecordRange()) {
if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
EnumerateMetadata(&F, DPL->getLabel());
EnumerateMetadata(&F, &*DPL->getDebugLoc());
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
EnumerateMetadata(&F, DLR->getLabel());
EnumerateMetadata(&F, &*DLR->getDebugLoc());
continue;
}
// Enumerate non-local location metadata.
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,13 +3376,13 @@ void IRTranslator::translateDbgDeclareRecord(Value *Address, bool HasArgList,
void IRTranslator::translateDbgInfo(const Instruction &Inst,
MachineIRBuilder &MIRBuilder) {
for (DbgRecord &DR : Inst.getDbgRecordRange()) {
if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
MIRBuilder.setDebugLoc(DPL->getDebugLoc());
assert(DPL->getLabel() && "Missing label");
assert(DPL->getLabel()->isValidLocationForIntrinsic(
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
MIRBuilder.setDebugLoc(DLR->getDebugLoc());
assert(DLR->getLabel() && "Missing label");
assert(DLR->getLabel()->isValidLocationForIntrinsic(
MIRBuilder.getDebugLoc()) &&
"Expected inlined-at fields to agree");
MIRBuilder.buildDbgLabel(DPL->getLabel());
MIRBuilder.buildDbgLabel(DLR->getLabel());
continue;
}
DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,16 +1192,16 @@ void FastISel::handleDbgInfo(const Instruction *II) {
flushLocalValueMap();
recomputeInsertPt();

if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
assert(DPL->getLabel() && "Missing label");
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
assert(DLR->getLabel() && "Missing label");
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DPL << "\n");
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DLR << "\n");
continue;
}

BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DPL->getDebugLoc(),
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DLR->getDebugLoc(),
TII.get(TargetOpcode::DBG_LABEL))
.addMetadata(DPL->getLabel());
.addMetadata(DLR->getLabel());
continue;
}

Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,18 +1248,19 @@ void SelectionDAGBuilder::visitDbgInfo(const Instruction &I) {
// We must skip DbgVariableRecords if they've already been processed above as
// we have just emitted the debug values resulting from assignment tracking
// analysis, making any existing DbgVariableRecords redundant (and probably
// less correct). We still need to process DPLabels. This does sink DPLabels
// to the bottom of the group of debug records. That sholdn't be important
// as it does so deterministcally and ordering between DPLabels and
// DbgVariableRecords is immaterial (other than for MIR/IR printing).
// less correct). We still need to process DbgLabelRecords. This does sink
// DbgLabelRecords to the bottom of the group of debug records. That sholdn't
// be important as it does so deterministcally and ordering between
// DbgLabelRecords and DbgVariableRecords is immaterial (other than for MIR/IR
// printing).
bool SkipDbgVariableRecords = DAG.getFunctionVarLocs();
// Is there is any debug-info attached to this instruction, in the form of
// DbgRecord non-instruction debug-info records.
for (DbgRecord &DR : I.getDbgRecordRange()) {
if (DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
assert(DPL->getLabel() && "Missing label");
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
assert(DLR->getLabel() && "Missing label");
SDDbgLabel *SDV =
DAG.getDbgLabel(DPL->getLabel(), DPL->getDebugLoc(), SDNodeOrder);
DAG.getDbgLabel(DLR->getLabel(), DLR->getDebugLoc(), SDNodeOrder);
DAG.AddDbgLabel(SDV);
continue;
}
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) {
if (auto *Empty = dyn_cast<MDNode>(DVR->getRawAddress()))
CreateMetadataSlot(Empty);
}
} else if (const DPLabel *DPL = dyn_cast<const DPLabel>(&DR)) {
CreateMetadataSlot(DPL->getRawLabel());
} else if (const DbgLabelRecord *DLR = dyn_cast<const DbgLabelRecord>(&DR)) {
CreateMetadataSlot(DLR->getRawLabel());
} else {
llvm_unreachable("unsupported DbgRecord kind");
}
Expand Down Expand Up @@ -2719,7 +2719,7 @@ class AssemblyWriter {
void printInstruction(const Instruction &I);
void printDPMarker(const DPMarker &DPI);
void printDbgVariableRecord(const DbgVariableRecord &DVR);
void printDPLabel(const DPLabel &DPL);
void printDbgLabelRecord(const DbgLabelRecord &DLR);
void printDbgRecord(const DbgRecord &DR);
void printDbgRecordLine(const DbgRecord &DR);

Expand Down Expand Up @@ -4621,8 +4621,8 @@ void AssemblyWriter::printDPMarker(const DPMarker &Marker) {
void AssemblyWriter::printDbgRecord(const DbgRecord &DR) {
if (auto *DVR = dyn_cast<DbgVariableRecord>(&DR))
printDbgVariableRecord(*DVR);
else if (auto *DPL = dyn_cast<DPLabel>(&DR))
printDPLabel(*DPL);
else if (auto *DLR = dyn_cast<DbgLabelRecord>(&DR))
printDbgLabelRecord(*DLR);
else
llvm_unreachable("Unexpected DbgRecord kind");
}
Expand Down Expand Up @@ -4672,7 +4672,7 @@ void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) {
Out << '\n';
}

void AssemblyWriter::printDPLabel(const DPLabel &Label) {
void AssemblyWriter::printDbgLabelRecord(const DbgLabelRecord &Label) {
auto WriterCtx = getContext();
Out << "#dbg_label(";
WriteAsOperandInternal(Out, Label.getRawLabel(), WriterCtx, true);
Expand Down Expand Up @@ -4934,7 +4934,7 @@ void DPMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST,
W.printDPMarker(*this);
}

void DPLabel::print(raw_ostream &ROS, bool IsForDebug) const {
void DbgLabelRecord::print(raw_ostream &ROS, bool IsForDebug) const {

ModuleSlotTracker MST(getModuleFromDPI(this), true);
print(ROS, MST, IsForDebug);
Expand All @@ -4957,8 +4957,8 @@ void DbgVariableRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST,
W.printDbgVariableRecord(*this);
}

void DPLabel::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
void DbgLabelRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
formatted_raw_ostream OS(ROS);
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
SlotTracker &SlotTable =
Expand All @@ -4970,7 +4970,7 @@ void DPLabel::print(raw_ostream &ROS, ModuleSlotTracker &MST,
incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent()
: nullptr);
AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);
W.printDPLabel(*this);
W.printDbgLabelRecord(*this);
}

void Value::print(raw_ostream &ROS, bool IsForDebug) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ static MDType *unwrapMAVOp(CallBase *CI, unsigned Op) {
static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) {
DbgRecord *DR = nullptr;
if (Name == "label") {
DR = new DPLabel(unwrapMAVOp<DILabel>(CI, 0), CI->getDebugLoc());
DR = new DbgLabelRecord(unwrapMAVOp<DILabel>(CI, 0), CI->getDebugLoc());
} else if (Name == "assign") {
DR = new DbgVariableRecord(
unwrapMAVOp<Metadata>(CI, 0), unwrapMAVOp<DILocalVariable>(CI, 1),
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void BasicBlock::convertToNewDbgValues() {
}

if (DbgLabelInst *DLI = dyn_cast<DbgLabelInst>(&I)) {
DbgVarRecs.push_back(new DPLabel(DLI->getLabel(), DLI->getDebugLoc()));
DbgVarRecs.push_back(
new DbgLabelRecord(DLI->getLabel(), DLI->getDebugLoc()));
DLI->eraseFromParent();
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,12 +1155,12 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,

trackIfUnresolved(LabelInfo);
if (M.IsNewDbgInfoFormat) {
DPLabel *DPL = new DPLabel(LabelInfo, DL);
DbgLabelRecord *DLR = new DbgLabelRecord(LabelInfo, DL);
if (InsertBB && InsertBefore)
InsertBB->insertDbgRecordBefore(DPL, InsertBefore->getIterator());
InsertBB->insertDbgRecordBefore(DLR, InsertBefore->getIterator());
else if (InsertBB)
InsertBB->insertDbgRecordBefore(DPL, InsertBB->end());
return DPL;
InsertBB->insertDbgRecordBefore(DLR, InsertBB->end());
return DLR;
}

if (!LabelFn)
Expand Down
31 changes: 17 additions & 14 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void DbgRecord::deleteRecord() {
delete cast<DbgVariableRecord>(this);
return;
case LabelKind:
delete cast<DPLabel>(this);
delete cast<DbgLabelRecord>(this);
return;
}
llvm_unreachable("unsupported DbgRecord kind");
Expand All @@ -94,7 +94,7 @@ void DbgRecord::print(raw_ostream &O, bool IsForDebug) const {
cast<DbgVariableRecord>(this)->print(O, IsForDebug);
return;
case LabelKind:
cast<DPLabel>(this)->print(O, IsForDebug);
cast<DbgLabelRecord>(this)->print(O, IsForDebug);
return;
};
llvm_unreachable("unsupported DbgRecord kind");
Expand All @@ -107,7 +107,7 @@ void DbgRecord::print(raw_ostream &O, ModuleSlotTracker &MST,
cast<DbgVariableRecord>(this)->print(O, MST, IsForDebug);
return;
case LabelKind:
cast<DPLabel>(this)->print(O, MST, IsForDebug);
cast<DbgLabelRecord>(this)->print(O, MST, IsForDebug);
return;
};
llvm_unreachable("unsupported DbgRecord kind");
Expand All @@ -121,7 +121,8 @@ bool DbgRecord::isIdenticalToWhenDefined(const DbgRecord &R) const {
return cast<DbgVariableRecord>(this)->isIdenticalToWhenDefined(
*cast<DbgVariableRecord>(&R));
case LabelKind:
return cast<DPLabel>(this)->getLabel() == cast<DPLabel>(R).getLabel();
return cast<DbgLabelRecord>(this)->getLabel() ==
cast<DbgLabelRecord>(R).getLabel();
};
llvm_unreachable("unsupported DbgRecord kind");
}
Expand All @@ -136,24 +137,25 @@ DbgRecord::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
case ValueKind:
return cast<DbgVariableRecord>(this)->createDebugIntrinsic(M, InsertBefore);
case LabelKind:
return cast<DPLabel>(this)->createDebugIntrinsic(M, InsertBefore);
return cast<DbgLabelRecord>(this)->createDebugIntrinsic(M, InsertBefore);
};
llvm_unreachable("unsupported DbgRecord kind");
}

DPLabel::DPLabel(MDNode *Label, MDNode *DL)
DbgLabelRecord::DbgLabelRecord(MDNode *Label, MDNode *DL)
: DbgRecord(LabelKind, DebugLoc(DL)), Label(Label) {
assert(Label && "Unexpected nullptr");
assert((isa<DILabel>(Label) || Label->isTemporary()) &&
"Label type must be or resolve to a DILabel");
}
DPLabel::DPLabel(DILabel *Label, DebugLoc DL)
DbgLabelRecord::DbgLabelRecord(DILabel *Label, DebugLoc DL)
: DbgRecord(LabelKind, DL), Label(Label) {
assert(Label && "Unexpected nullptr");
}

DPLabel *DPLabel::createUnresolvedDPLabel(MDNode *Label, MDNode *DL) {
return new DPLabel(Label, DL);
DbgLabelRecord *DbgLabelRecord::createUnresolvedDbgLabelRecord(MDNode *Label,
MDNode *DL) {
return new DbgLabelRecord(Label, DL);
}

DbgVariableRecord::DbgVariableRecord(DbgVariableRecord::LocationType Type,
Expand Down Expand Up @@ -380,7 +382,7 @@ DbgRecord *DbgRecord::clone() const {
case ValueKind:
return cast<DbgVariableRecord>(this)->clone();
case LabelKind:
return cast<DPLabel>(this)->clone();
return cast<DbgLabelRecord>(this)->clone();
};
llvm_unreachable("unsupported DbgRecord kind");
}
Expand All @@ -389,8 +391,8 @@ DbgVariableRecord *DbgVariableRecord::clone() const {
return new DbgVariableRecord(*this);
}

DPLabel *DPLabel::clone() const {
return new DPLabel(getLabel(), getDebugLoc());
DbgLabelRecord *DbgLabelRecord::clone() const {
return new DbgLabelRecord(getLabel(), getDebugLoc());
}

DbgVariableIntrinsic *
Expand Down Expand Up @@ -450,8 +452,9 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
return DVI;
}

DbgLabelInst *DPLabel::createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const {
DbgLabelInst *
DbgLabelRecord::createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const {
auto *LabelFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_label);
Value *Args[] = {
MetadataAsValue::get(getDebugLoc()->getContext(), getLabel())};
Expand Down
Loading