Skip to content
Open
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
15 changes: 15 additions & 0 deletions llvm/docs/SourceLevelDebugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,21 @@ 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: 2 additions & 0 deletions llvm/include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ 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 =
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
};

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

/// Insert a new llvm.dbg.coroframe_entry 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);

/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
/// \param DL Debug info location.
Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should (upstream) replace this with one API that lets you pass a kind parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a FIXME comment

/// As above, for DVRValues.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);

Expand Down
12 changes: 12 additions & 0 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
Declare,
Value,
Assign,
CoroFrameEntry,

End, ///< Marks the end of the concrete types.
Any, ///< To indicate all LocationTypes in searches.
Expand Down Expand Up @@ -364,6 +365,14 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
createDVRDeclare(Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI, DbgVariableRecord &InsertBefore);

LLVM_ABI static DbgVariableRecord *
createDVRCoroFrameEntry(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);

/// Iterator for ValueAsMetadata that internally uses direct pointer iteration
/// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
/// ValueAsMetadata .
Expand Down Expand Up @@ -414,6 +423,9 @@ 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;
}

/// Get the locations corresponding to the variable referenced by the debug
/// info intrinsic. Depending on the intrinsic, this could be the
Expand Down
21 changes: 21 additions & 0 deletions llvm/include/llvm/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ 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 @@ -464,6 +465,26 @@ 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: 4 additions & 0 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@ 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/Bitcode/Reader/BitcodeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +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_VALUE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6644,6 +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_ASSIGN: {
// DbgVariableRecords are placed after the Instructions that they are
// attached to.
Expand All @@ -6660,6 +6661,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
// ..., Value
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
// ..., LocationMetadata
// dbg_coroframe_entry (FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY)
// ..., LocationMetadata
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
unsigned Slot = 0;
Expand Down Expand Up @@ -6701,6 +6704,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::Declare);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY:
DVR = new DbgVariableRecord(
RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::CoroFrameEntry);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
DIExpression *AddrExpr =
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3827,6 +3827,10 @@ 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()) {
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY,
Vals);
} else {
assert(DVR.isDbgAssign() && "Unexpected DbgRecord kind");
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4876,6 +4876,9 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) {
case DbgVariableRecord::LocationType::Declare:
Out << "declare";
break;
case DbgVariableRecord::LocationType::CoroFrameEntry:
Out << "coroframe_entry";
break;
case DbgVariableRecord::LocationType::Assign:
Out << "assign";
break;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,11 @@ 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
18 changes: 18 additions & 0 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,24 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
return DVR;
}

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

DbgVariableRecord *DVR =
DbgVariableRecord::createDVRCoroFrameEntry(Storage, VarInfo, Expr, DL);
insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}

void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
InsertPosition InsertPt) {
assert(InsertPt.isValid());
Expand Down
37 changes: 37 additions & 0 deletions llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ 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) {
// 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 {};

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

return Coros;
}

TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(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.
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ DbgVariableRecord::DbgVariableRecord(const DbgVariableIntrinsic *DVI)
case Intrinsic::dbg_declare:
Type = LocationType::Declare;
break;
case Intrinsic::dbg_coroframe_entry:
Type = LocationType::CoroFrameEntry;
break;
case Intrinsic::dbg_assign: {
Type = LocationType::Assign;
const DbgAssignIntrinsic *Assign =
Expand Down Expand Up @@ -209,6 +212,22 @@ DbgVariableRecord::createDVRDeclare(Value *Address, DILocalVariable *DV,
return NewDVRDeclare;
}

DbgVariableRecord *
DbgVariableRecord::createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
DIExpression *Expr,
const DILocation *DI) {
return new DbgVariableRecord(ValueAsMetadata::get(Address), DV, Expr, DI,
LocationType::CoroFrameEntry);
}

DbgVariableRecord *DbgVariableRecord::createDVRCoroFrameEntry(
Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI, DbgVariableRecord &InsertBefore) {
auto *NewDVRCoro = createDVRCoroFrameEntry(Address, DV, Expr, DI);
NewDVRCoro->insertBefore(&InsertBefore);
return NewDVRCoro;
}

DbgVariableRecord *DbgVariableRecord::createDVRAssign(
Value *Val, DILocalVariable *Variable, DIExpression *Expression,
DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression,
Expand Down Expand Up @@ -416,6 +435,10 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
case DbgVariableRecord::LocationType::Declare:
IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare);
break;
case DbgVariableRecord::LocationType::CoroFrameEntry:
IntrinsicFn =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_coroframe_entry);
break;
case DbgVariableRecord::LocationType::Value:
IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_value);
break;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ struct VerifierSupport {
case DbgVariableRecord::LocationType::Declare:
*OS << "declare";
break;
case DbgVariableRecord::LocationType::CoroFrameEntry:
*OS << "coroframe_entry";
break;
case DbgVariableRecord::LocationType::Assign:
*OS << "assign";
break;
Expand Down Expand Up @@ -6885,6 +6888,8 @@ void Verifier::visit(DbgVariableRecord &DVR) {

CheckDI(DVR.getType() == DbgVariableRecord::LocationType::Value ||
DVR.getType() == DbgVariableRecord::LocationType::Declare ||
DVR.getType() ==
DbgVariableRecord::LocationType::CoroFrameEntry ||
DVR.getType() == DbgVariableRecord::LocationType::Assign,
"invalid #dbg record type", &DVR, DVR.getType(), BB, F);

Expand Down
Loading