Skip to content

[RemoveDIs] Enable DPLabels conversion [3b/3] #82639

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
Feb 23, 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
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class BasicBlock;
class MDNode;
class Module;
class DbgVariableIntrinsic;
class DbgInfoIntrinsic;
class DbgLabelInst;
class DIAssignID;
class DPMarker;
class DPValue;
Expand All @@ -80,6 +82,7 @@ class raw_ostream;
/// clone
/// isIdenticalToWhenDefined
/// both print methods
/// createDebugIntrinsic
class DbgRecord : public ilist_node<DbgRecord> {
public:
/// Marker that this DbgRecord is linked into.
Expand All @@ -103,6 +106,11 @@ class DbgRecord : public ilist_node<DbgRecord> {
void print(raw_ostream &O, bool IsForDebug = false) const;
void print(raw_ostream &O, ModuleSlotTracker &MST, bool IsForDebug) const;
bool isIdenticalToWhenDefined(const DbgRecord &R) const;
/// Convert this DbgRecord back into an appropriate llvm.dbg.* intrinsic.
/// \p InsertBefore Optional position to insert this intrinsic.
/// \returns A new llvm.dbg.* intrinsic representiung this DbgRecord.
DbgInfoIntrinsic *createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const;
///@}

/// Same as isIdenticalToWhenDefined but checks DebugLoc too.
Expand Down Expand Up @@ -177,6 +185,8 @@ class DPLabel : public DbgRecord {
DPLabel *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,
Instruction *InsertBefore) const;

void setLabel(DILabel *NewLabel) { Label = NewLabel; }
DILabel *getLabel() const { return Label; }
Expand Down
18 changes: 10 additions & 8 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ void BasicBlock::convertToNewDbgValues() {
continue;
}

if (DbgLabelInst *DLI = dyn_cast<DbgLabelInst>(&I)) {
DPVals.push_back(new DPLabel(DLI->getLabel(), DLI->getDebugLoc()));
DLI->eraseFromParent();
continue;
}

if (DPVals.empty())
continue;

Expand All @@ -107,16 +113,12 @@ void BasicBlock::convertFromNewDbgValues() {
continue;

DPMarker &Marker = *Inst.DbgMarker;
for (DbgRecord &DR : Marker.getDbgValueRange()) {
if (auto *DPV = dyn_cast<DPValue>(&DR))
InstList.insert(Inst.getIterator(),
DPV->createDebugIntrinsic(getModule(), nullptr));
else
llvm_unreachable("unsupported DbgRecord kind");
}
for (DbgRecord &DR : Marker.getDbgValueRange())
InstList.insert(Inst.getIterator(),
DR.createDebugIntrinsic(getModule(), nullptr));

Marker.eraseFromParent();
};
}

// Assume no trailing DPValues: we could technically create them at the end
// of the block, after a terminator, but this would be non-cannonical and
Expand Down
25 changes: 25 additions & 0 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ bool DbgRecord::isEquivalentTo(const DbgRecord &R) const {
return getDebugLoc() == R.getDebugLoc() && isIdenticalToWhenDefined(R);
}

DbgInfoIntrinsic *
DbgRecord::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
switch (RecordKind) {
case ValueKind:
return cast<DPValue>(this)->createDebugIntrinsic(M, InsertBefore);
case LabelKind:
return cast<DPLabel>(this)->createDebugIntrinsic(M, InsertBefore);
};
llvm_unreachable("unsupported DbgRecord kind");
}

DPValue *DPValue::createDPValue(Value *Location, DILocalVariable *DV,
DIExpression *Expr, const DILocation *DI) {
return new DPValue(ValueAsMetadata::get(Location), DV, Expr, DI,
Expand Down Expand Up @@ -377,6 +388,20 @@ DPValue::createDebugIntrinsic(Module *M, Instruction *InsertBefore) const {
return DVI;
}

DbgLabelInst *DPLabel::createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const {
auto *LabelFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_label);
Value *Args[] = {
MetadataAsValue::get(getDebugLoc()->getContext(), getLabel())};
DbgLabelInst *DbgLabel = cast<DbgLabelInst>(
CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
DbgLabel->setTailCall();
DbgLabel->setDebugLoc(getDebugLoc());
if (InsertBefore)
DbgLabel->insertBefore(InsertBefore);
return DbgLabel;
}

Value *DPValue::getAddress() const {
auto *MD = getRawAddress();
if (auto *V = dyn_cast<ValueAsMetadata>(MD))
Expand Down