Skip to content
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

[RemoveDIs][NFC] Add DbgLabelRecord class [3/4] #4

Open
wants to merge 1 commit into
base: ddd/labels-upstream-2
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ class DbgRecord : public ilist_node<DbgRecord> {
/// Marker that this DbgRecord is linked into.
DbgMarker *Marker = nullptr;
/// Subclass discriminator.
enum Kind : uint8_t { ValueKind };
enum Kind : uint8_t { ValueKind, LabelKind };

protected:
DebugLoc DbgLoc;
@@ -141,6 +141,30 @@ class DbgRecord : public ilist_node<DbgRecord> {
~DbgRecord() = default;
};

/// Records a position in IR for a source label (DILabel). Corresponds to the
/// llvm.dbg.label intrinsic.
class DbgLabelRecord : public DbgRecord {
DILabel *Label;

public:
DbgLabelRecord(DILabel *Label, DebugLoc DL)
: DbgRecord(LabelKind, DL), Label(Label) {
assert(Label && "unexpected nullptr");
}

DbgLabelRecord *clone() const;
void print(raw_ostream &O, bool IsForDebug = false) const;
void print(raw_ostream &ROS, ModuleSlotTracker &MST, bool IsForDebug) const;

void setLabel(DILabel *NewLabel) { Label = NewLabel; }
DILabel *getLabel() const { return Label; }

/// Support type inquiry through isa, cast, and dyn_cast.
static bool classof(const DbgRecord *E) {
return E->getRecordKind() == LabelKind;
}
};

/// Record of a variable value-assignment, aka a non instruction representation
/// of the dbg.value intrinsic.
///
39 changes: 37 additions & 2 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
@@ -292,8 +292,8 @@ static const Module *getModuleFromDPI(const DbgMarker *Marker) {
return M ? M->getParent() : nullptr;
}

static const Module *getModuleFromDPI(const DbgVariableRecord *DPV) {
return getModuleFromDPI(DPV->getMarker());
static const Module *getModuleFromDPI(const DbgRecord *DR) {
return getModuleFromDPI(DR->getMarker());
}

static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
@@ -2667,6 +2667,7 @@ class AssemblyWriter {
void printInstruction(const Instruction &I);
void printDbgMarker(const DbgMarker &DPI);
void printDbgVariableRecord(const DbgVariableRecord &DPI);
void printDbgLabelRecord(const DbgLabelRecord &DPI);
void printDbgRecord(const DbgRecord &DPI);

void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle);
@@ -4596,6 +4597,16 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &Value) {
Out << " }";
}

void AssemblyWriter::printDbgLabelRecord(const DbgLabelRecord &Value) {
// There's no formal representation of a DbgLabelRecord -- print purely as
// a debugging aid.
Out << " DbgLabelRecord { ";
auto WriterCtx = getContext();
WriteAsOperandInternal(Out, Value.getLabel(), WriterCtx, true);
Out << " marker @" << Value.getMarker();
Out << " }";
}

void AssemblyWriter::printMetadataAttachments(
const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,
StringRef Separator) {
@@ -4842,6 +4853,12 @@ void DbgVariableRecord::print(raw_ostream &ROS, bool IsForDebug) const {
print(ROS, MST, IsForDebug);
}

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

ModuleSlotTracker MST(getModuleFromDPI(this), true);
print(ROS, MST, IsForDebug);
}

void DbgMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
// There's no formal representation of a DbgMarker -- print purely as a
@@ -4877,6 +4894,24 @@ void DbgVariableRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST,
W.printDbgVariableRecord(*this);
}

void DbgLabelRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
// There's no formal representation of a DbgLabelRecord -- print purely as
// a debugging aid.
formatted_raw_ostream OS(ROS);
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
SlotTracker &SlotTable =
MST.getMachine() ? *MST.getMachine() : EmptySlotTable;
auto incorporateFunction = [&](const Function *F) {
if (F)
MST.incorporateFunction(*F);
};
incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent()
: nullptr);
AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);
W.printDbgLabelRecord(*this);
}

void Value::print(raw_ostream &ROS, bool IsForDebug) const {
bool ShouldInitializeAllMetadata = false;
if (auto *I = dyn_cast<Instruction>(this))
11 changes: 11 additions & 0 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
@@ -46,6 +46,9 @@ void DbgRecord::deleteRecord() {
case ValueKind:
delete cast<DbgVariableRecord>(this);
break;
case LabelKind:
delete cast<DbgLabelRecord>(this);
break;
default:
llvm_unreachable("unsupported record kind");
}
@@ -55,6 +58,9 @@ void DbgRecord::print(raw_ostream &O, bool IsForDebug) const {
case ValueKind:
cast<DbgVariableRecord>(this)->print(O, IsForDebug);
break;
case LabelKind:
cast<DbgLabelRecord>(this)->print(O, IsForDebug);
break;
default:
llvm_unreachable("unsupported record kind");
};
@@ -66,6 +72,9 @@ void DbgRecord::print(raw_ostream &O, ModuleSlotTracker &MST,
case ValueKind:
cast<DbgVariableRecord>(this)->print(O, MST, IsForDebug);
break;
case LabelKind:
cast<DbgLabelRecord>(this)->print(O, MST, IsForDebug);
break;
default:
llvm_unreachable("unsupported record kind");
};
@@ -217,6 +226,8 @@ DbgRecord *DbgRecord::clone() const {
switch (RecordKind) {
case ValueKind:
return cast<DbgVariableRecord>(this)->clone();
case LabelKind:
return cast<DbgLabelRecord>(this)->clone();
default:
llvm_unreachable("unsupported record kind");
};