Skip to content
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
37 changes: 22 additions & 15 deletions llvm/docs/SourceLevelDebugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ directly, not its address. Note that the value operand of this intrinsic may
be indirect (i.e, a pointer to the source variable), provided that interpreting
the complex expression derives the direct value.


``#dbg_declare_value``
^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: llvm

#dbg_declare_value([Value|MDNode], DILocalVariable, DIExpression, DILocation)

This record provides information about a local element (e.g., variable). The
first argument is used to compute the value of the variable throughout the
entire function. The second argument is a
:ref:`local variable <dilocalvariable>` containing a description of the
variable. The third argument is a :ref:`complex expression <diexpression>`. The
foruth argument is a :ref:`source location <dilocation>`. A
``#dbg_declare_value`` record describes describes the *value* of a source
variable directly, not its address. The difference between a ``#dbg_value`` and
a ``#dbg_declare_value`` is that, just like a ``#dbg_declare``, a frontend
should generate exactly one ``#dbg_declare_value`` record. The idea is to have
``#dbg_declare`` guarantees but be able to describe a value rather than the
address of a value.


``#dbg_assign``
^^^^^^^^^^^^^^^^^^^
.. toctree::
Expand Down Expand Up @@ -401,21 +423,6 @@ This intrinsic is equivalent to ``#dbg_assign``:
metadata ptr %i.addr, metadata !DIExpression(), metadata !3), !dbg !3


``llvm.dbg.coroframe_entry``
^^^^^^^^^^^^^^^^^^^^

.. code-block:: llvm

void @llvm.dbg.coroframe_entry(metadata, metadata, metadata)

This intrinsic is equivalent to ``#dbg_coroframe_entry``:

.. code-block:: llvm

#dbg_coroframe_entry(i32 %i., !1, !DIExpression(), !2)
call void @llvm.dbg.coroframe_entry(metadata i32 %i., metadata !1,
metadata !DIExpression()), !dbg !2

Object lifetimes and scoping
============================

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ enum FunctionCodes {
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
64, // [DILocation, DILocalVariable, DIExpression, Value]
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY =
FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE =
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
};

Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,17 +1155,17 @@ namespace llvm {
DIExpression *Expr, const DILocation *DL,
InsertPosition InsertPt);

/// Insert a new llvm.dbg.coroframe_entry intrinsic call.
/// Insert a new llvm.dbg.declare_value intrinsic call.
/// \param Storage llvm::Value of the variable
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
/// \param InsertPt Location for the new intrinsic.
LLVM_ABI DbgInstPtr insertCoroFrameEntry(llvm::Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt);
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt);

/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
Expand Down
11 changes: 2 additions & 9 deletions llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ class Module;
LLVM_ABI TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
/// As above, for DVRDeclares.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
/// Finds dbg.coroframe_entry intrinsics declaring local variables as living in
/// the memory that 'V' points to.
// FIXME: Combine the findDbgCoroFrameEntrys and findDbgDeclares APIs into one
// that can take a 'kind' parameter, do the same for findDVRCoroFrameEntrys and
// findDVRCoroFrameEntrys
LLVM_ABI TinyPtrVector<DbgCoroFrameEntryInst *>
findDbgCoroFrameEntrys(Value *V);
/// As above, for DVRCoroFrameEntrys.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRCoroFrameEntrys(Value *V);
/// As above, for DVRValues.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
/// As above, for DVRDeclareValues.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclareValues(Value *V);

/// Finds the llvm.dbg.value intrinsics describing a value.
LLVM_ABI void findDbgValues(
Expand Down
25 changes: 13 additions & 12 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
Declare,
Value,
Assign,
CoroFrameEntry,
DeclareValue,

End, ///< Marks the end of the concrete types.
Any, ///< To indicate all LocationTypes in searches.
Expand Down Expand Up @@ -366,12 +366,11 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
const DILocation *DI, DbgVariableRecord &InsertBefore);

LLVM_ABI static DbgVariableRecord *
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
DIExpression *Expr, const DILocation *DI);
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI);
LLVM_ABI static DbgVariableRecord *
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
DIExpression *Expr, const DILocation *DI,
DbgVariableRecord &InsertBefore);
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI, DbgVariableRecord &InsertBefore);

/// Iterator for ValueAsMetadata that internally uses direct pointer iteration
/// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
Expand Down Expand Up @@ -423,9 +422,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {

bool isDbgDeclare() const { return Type == LocationType::Declare; }
bool isDbgValue() const { return Type == LocationType::Value; }
bool isDbgCoroFrameEntry() const {
return Type == LocationType::CoroFrameEntry;
}
bool isDbgDeclareValue() const { return Type == LocationType::DeclareValue; }

/// Get the locations corresponding to the variable referenced by the debug
/// info intrinsic. Depending on the intrinsic, this could be the
Expand All @@ -451,12 +448,16 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
bool hasValidLocation() const { return getVariableLocationOp(0) != nullptr; }

/// Does this describe the address of a local variable. True for dbg.addr
/// and dbg.declare, but not dbg.value, which describes its value.
/// and dbg.declare, but not dbg.value or dbg.declare_value, which describes
/// its value.
bool isAddressOfVariable() const { return Type == LocationType::Declare; }

/// Determine if this describes the value of a local variable. It is false for
/// dbg.declare, but true for dbg.value, which describes its value.
bool isValueOfVariable() const { return Type == LocationType::Value; }
/// dbg.declare, but true for dbg.value and dbg.declare_value, which describes
/// its value.
bool isValueOfVariable() const {
return Type == LocationType::Value || Type == LocationType::DeclareValue;
}

LocationType getType() const { return Type; }

Expand Down
21 changes: 0 additions & 21 deletions llvm/include/llvm/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_assign:
case Intrinsic::dbg_coroframe_entry:
return true;
default:
return false;
Expand Down Expand Up @@ -465,26 +464,6 @@ class DbgDeclareInst : public DbgVariableIntrinsic {
/// @}
};

/// This represents the llvm.dbg.coro instruction.
class DbgCoroFrameEntryInst : public DbgVariableIntrinsic {
public:
Value *getAddress() const {
assert(getNumVariableLocationOps() == 1 &&
"dbg.coro must have exactly 1 location operand.");
return getVariableLocationOp(0);
}

/// \name Casting methods
/// @{
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_coroframe_entry;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
/// @}
};

/// This represents the llvm.dbg.value instruction.
class DbgValueInst : public DbgVariableIntrinsic {
public:
Expand Down
4 changes: 0 additions & 4 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,6 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
llvm_metadata_ty]>;
def int_dbg_label : DefaultAttrsIntrinsic<[],
[llvm_metadata_ty]>;
def int_dbg_coroframe_entry : DefaultAttrsIntrinsic<[],
[llvm_metadata_ty,
llvm_metadata_ty,
llvm_metadata_ty]>;
}

//===------------------ Exception Handling Intrinsics----------------------===//
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ lltok::Kind LLLexer::LexIdentifier() {
DBGRECORDTYPEKEYWORD(declare);
DBGRECORDTYPEKEYWORD(assign);
DBGRECORDTYPEKEYWORD(label);
DBGRECORDTYPEKEYWORD(declare_value);
#undef DBGRECORDTYPEKEYWORD

if (Keyword.starts_with("DIFlag")) {
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7053,7 +7053,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
.Case("declare", RecordKind::ValueKind)
.Case("value", RecordKind::ValueKind)
.Case("assign", RecordKind::ValueKind)
.Case("label", RecordKind::LabelKind);
.Case("label", RecordKind::LabelKind)
.Case("declare_value", RecordKind::ValueKind);

// Parsing labels is trivial; parse here and early exit, otherwise go into the
// full DbgVariableRecord processing stage.
Expand All @@ -7078,7 +7079,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
LocType ValueType = StringSwitch<LocType>(Lex.getStrVal())
.Case("declare", LocType::Declare)
.Case("value", LocType::Value)
.Case("assign", LocType::Assign);
.Case("assign", LocType::Assign)
.Case("declare_value", LocType::DeclareValue);

Lex.Lex();
if (parseToken(lltok::lparen, "Expected '(' here"))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ GetCodeName(unsigned CodeID, unsigned BlockID,
STRINGIFY_CODE(FUNC_CODE, INST_CALLBR)
STRINGIFY_CODE(FUNC_CODE, BLOCKADDR_USERS)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_COROFRAME_ENTRY)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE_VALUE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6644,7 +6644,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
case bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY:
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
// DbgVariableRecords are placed after the Instructions that they are
// attached to.
Expand All @@ -6661,7 +6661,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
// ..., Value
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
// ..., LocationMetadata
// dbg_coroframe_entry (FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY)
// dbg_declare_value (FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE)
// ..., LocationMetadata
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
Expand Down Expand Up @@ -6704,10 +6704,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::Declare);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY:
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
DVR = new DbgVariableRecord(
RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::CoroFrameEntry);
DbgVariableRecord::LocationType::DeclareValue);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3828,10 +3828,9 @@ void ModuleBitcodeWriter::writeFunction(
} else if (DVR.isDbgDeclare()) {
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
} else if (DVR.isDbgCoroFrameEntry()) {
} else if (DVR.isDbgDeclareValue()) {
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY,
Vals);
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE, Vals);
} else {
assert(DVR.isDbgAssign() && "Unexpected DbgRecord kind");
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4877,8 +4877,8 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) {
case DbgVariableRecord::LocationType::Declare:
Out << "declare";
break;
case DbgVariableRecord::LocationType::CoroFrameEntry:
Out << "coroframe_entry";
case DbgVariableRecord::LocationType::DeclareValue:
Out << "declare_value";
break;
case DbgVariableRecord::LocationType::Assign:
Out << "assign";
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4507,11 +4507,6 @@ static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) {
DbgVariableRecord::LocationType::Declare, unwrapMAVMetadataOp(CI, 0),
unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2), nullptr, nullptr, nullptr,
getDebugLocSafe(CI));
} else if (Name == "coroframe_entry") {
DR = DbgVariableRecord::createUnresolvedDbgVariableRecord(
DbgVariableRecord::LocationType::CoroFrameEntry,
unwrapMAVMetadataOp(CI, 0), unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2),
nullptr, nullptr, nullptr, getDebugLocSafe(CI));
} else if (Name == "addr") {
// Upgrade dbg.addr to dbg.value with DW_OP_deref.
MDNode *ExprNode = unwrapMAVOp(CI, 2);
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,20 +1142,20 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
return DVR;
}

DbgInstPtr DIBuilder::insertCoroFrameEntry(Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt) {
DbgInstPtr DIBuilder::insertDeclareValue(Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt) {
assert(VarInfo &&
"empty or invalid DILocalVariable* passed to dbg.corofame_entry");
"empty or invalid DILocalVariable* passed to dbg.declare_value");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
VarInfo->getScope()->getSubprogram() &&
"Expected matching subprograms");

DbgVariableRecord *DVR =
DbgVariableRecord::createDVRCoroFrameEntry(Storage, VarInfo, Expr, DL);
DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}
Expand Down
30 changes: 5 additions & 25 deletions llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,7 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares(Value *V) {
return Declares;
}

TinyPtrVector<DbgCoroFrameEntryInst *> llvm::findDbgCoroFrameEntrys(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup. This check is a bitfield datamember lookup.
if (!V->isUsedByMetadata())
return {};
auto *L = ValueAsMetadata::getIfExists(V);
if (!L)
return {};
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
if (!MDV)
return {};

TinyPtrVector<DbgCoroFrameEntryInst *> Coros;
for (User *U : MDV->users())
if (auto *DDI = dyn_cast<DbgCoroFrameEntryInst>(U))
Coros.push_back(DDI);

return Coros;
}

TinyPtrVector<DbgVariableRecord *> llvm::findDVRCoroFrameEntrys(Value *V) {
TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclareValues(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup. This check is a bitfield datamember lookup.
if (!V->isUsedByMetadata())
Expand All @@ -110,12 +90,12 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRCoroFrameEntrys(Value *V) {
if (!L)
return {};

TinyPtrVector<DbgVariableRecord *> Coros;
TinyPtrVector<DbgVariableRecord *> DEclareValues;
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
if (DVR->getType() == DbgVariableRecord::LocationType::CoroFrameEntry)
Coros.push_back(DVR);
if (DVR->getType() == DbgVariableRecord::LocationType::DeclareValue)
DEclareValues.push_back(DVR);

return Coros;
return DEclareValues;
}

TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
Expand Down
Loading