Skip to content

Commit c3def25

Browse files
Merge pull request llvm#11902 from felipepiovezan/felipe/cherry_pick_dbgdeclarevalue_llvm
[DebugInfo] 🍒 Patches to use upstream's db.declare_value in CoroSplit
2 parents 8f9c64d + acd26d1 commit c3def25

File tree

21 files changed

+212
-161
lines changed

21 files changed

+212
-161
lines changed

llvm/docs/SourceLevelDebugging.rst

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,28 @@ directly, not its address. Note that the value operand of this intrinsic may
310310
be indirect (i.e, a pointer to the source variable), provided that interpreting
311311
the complex expression derives the direct value.
312312

313+
314+
``#dbg_declare_value``
315+
^^^^^^^^^^^^^^^^^^^^^^
316+
317+
.. code-block:: llvm
318+
319+
#dbg_declare_value([Value|MDNode], DILocalVariable, DIExpression, DILocation)
320+
321+
This record provides information about a local element (e.g., variable). The
322+
first argument is used to compute the value of the variable throughout the
323+
entire function. The second argument is a
324+
:ref:`local variable <dilocalvariable>` containing a description of the
325+
variable. The third argument is a :ref:`complex expression <diexpression>`. The
326+
foruth argument is a :ref:`source location <dilocation>`. A
327+
``#dbg_declare_value`` record describes describes the *value* of a source
328+
variable directly, not its address. The difference between a ``#dbg_value`` and
329+
a ``#dbg_declare_value`` is that, just like a ``#dbg_declare``, a frontend
330+
should generate exactly one ``#dbg_declare_value`` record. The idea is to have
331+
``#dbg_declare`` guarantees but be able to describe a value rather than the
332+
address of a value.
333+
334+
313335
``#dbg_assign``
314336
^^^^^^^^^^^^^^^^^^^
315337
.. toctree::
@@ -401,21 +423,6 @@ This intrinsic is equivalent to ``#dbg_assign``:
401423
metadata ptr %i.addr, metadata !DIExpression(), metadata !3), !dbg !3
402424
403425
404-
``llvm.dbg.coroframe_entry``
405-
^^^^^^^^^^^^^^^^^^^^
406-
407-
.. code-block:: llvm
408-
409-
void @llvm.dbg.coroframe_entry(metadata, metadata, metadata)
410-
411-
This intrinsic is equivalent to ``#dbg_coroframe_entry``:
412-
413-
.. code-block:: llvm
414-
415-
#dbg_coroframe_entry(i32 %i., !1, !DIExpression(), !2)
416-
call void @llvm.dbg.coroframe_entry(metadata i32 %i., metadata !1,
417-
metadata !DIExpression()), !dbg !2
418-
419426
Object lifetimes and scoping
420427
============================
421428

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ enum FunctionCodes {
687687
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
688688
64, // [DILocation, DILocalVariable, DIExpression, Value]
689689
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
690-
FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY =
690+
FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE =
691691
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
692692
};
693693

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,17 +1155,17 @@ namespace llvm {
11551155
DIExpression *Expr, const DILocation *DL,
11561156
InsertPosition InsertPt);
11571157

1158-
/// Insert a new llvm.dbg.coroframe_entry intrinsic call.
1158+
/// Insert a new llvm.dbg.declare_value intrinsic call.
11591159
/// \param Storage llvm::Value of the variable
11601160
/// \param VarInfo Variable's debug info descriptor.
11611161
/// \param Expr A complex location expression.
11621162
/// \param DL Debug info location.
11631163
/// \param InsertPt Location for the new intrinsic.
1164-
LLVM_ABI DbgInstPtr insertCoroFrameEntry(llvm::Value *Storage,
1165-
DILocalVariable *VarInfo,
1166-
DIExpression *Expr,
1167-
const DILocation *DL,
1168-
InsertPosition InsertPt);
1164+
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
1165+
DILocalVariable *VarInfo,
1166+
DIExpression *Expr,
1167+
const DILocation *DL,
1168+
InsertPosition InsertPt);
11691169

11701170
/// Insert a new llvm.dbg.label intrinsic call.
11711171
/// \param LabelInfo Label's debug info descriptor.

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,10 @@ class Module;
4444
LLVM_ABI TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
4545
/// As above, for DVRDeclares.
4646
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
47-
/// Finds dbg.coroframe_entry intrinsics declaring local variables as living in
48-
/// the memory that 'V' points to.
49-
// FIXME: Combine the findDbgCoroFrameEntrys and findDbgDeclares APIs into one
50-
// that can take a 'kind' parameter, do the same for findDVRCoroFrameEntrys and
51-
// findDVRCoroFrameEntrys
52-
LLVM_ABI TinyPtrVector<DbgCoroFrameEntryInst *>
53-
findDbgCoroFrameEntrys(Value *V);
54-
/// As above, for DVRCoroFrameEntrys.
55-
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRCoroFrameEntrys(Value *V);
5647
/// As above, for DVRValues.
5748
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
49+
/// As above, for DVRDeclareValues.
50+
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclareValues(Value *V);
5851

5952
/// Finds the llvm.dbg.value intrinsics describing a value.
6053
LLVM_ABI void findDbgValues(

llvm/include/llvm/IR/DebugProgramInstruction.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
282282
Declare,
283283
Value,
284284
Assign,
285-
CoroFrameEntry,
285+
DeclareValue,
286286

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

368368
LLVM_ABI static DbgVariableRecord *
369-
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
370-
DIExpression *Expr, const DILocation *DI);
369+
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
370+
const DILocation *DI);
371371
LLVM_ABI static DbgVariableRecord *
372-
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
373-
DIExpression *Expr, const DILocation *DI,
374-
DbgVariableRecord &InsertBefore);
372+
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
373+
const DILocation *DI, DbgVariableRecord &InsertBefore);
375374

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

424423
bool isDbgDeclare() const { return Type == LocationType::Declare; }
425424
bool isDbgValue() const { return Type == LocationType::Value; }
426-
bool isDbgCoroFrameEntry() const {
427-
return Type == LocationType::CoroFrameEntry;
428-
}
425+
bool isDbgDeclareValue() const { return Type == LocationType::DeclareValue; }
429426

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

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

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

461462
LocationType getType() const { return Type; }
462463

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
428428
case Intrinsic::dbg_declare:
429429
case Intrinsic::dbg_value:
430430
case Intrinsic::dbg_assign:
431-
case Intrinsic::dbg_coroframe_entry:
432431
return true;
433432
default:
434433
return false;
@@ -465,26 +464,6 @@ class DbgDeclareInst : public DbgVariableIntrinsic {
465464
/// @}
466465
};
467466

468-
/// This represents the llvm.dbg.coro instruction.
469-
class DbgCoroFrameEntryInst : public DbgVariableIntrinsic {
470-
public:
471-
Value *getAddress() const {
472-
assert(getNumVariableLocationOps() == 1 &&
473-
"dbg.coro must have exactly 1 location operand.");
474-
return getVariableLocationOp(0);
475-
}
476-
477-
/// \name Casting methods
478-
/// @{
479-
static bool classof(const IntrinsicInst *I) {
480-
return I->getIntrinsicID() == Intrinsic::dbg_coroframe_entry;
481-
}
482-
static bool classof(const Value *V) {
483-
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
484-
}
485-
/// @}
486-
};
487-
488467
/// This represents the llvm.dbg.value instruction.
489468
class DbgValueInst : public DbgVariableIntrinsic {
490469
public:

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,6 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
14741474
llvm_metadata_ty]>;
14751475
def int_dbg_label : DefaultAttrsIntrinsic<[],
14761476
[llvm_metadata_ty]>;
1477-
def int_dbg_coroframe_entry : DefaultAttrsIntrinsic<[],
1478-
[llvm_metadata_ty,
1479-
llvm_metadata_ty,
1480-
llvm_metadata_ty]>;
14811477
}
14821478

14831479
//===------------------ Exception Handling Intrinsics----------------------===//

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ lltok::Kind LLLexer::LexIdentifier() {
998998
DBGRECORDTYPEKEYWORD(declare);
999999
DBGRECORDTYPEKEYWORD(assign);
10001000
DBGRECORDTYPEKEYWORD(label);
1001+
DBGRECORDTYPEKEYWORD(declare_value);
10011002
#undef DBGRECORDTYPEKEYWORD
10021003

10031004
if (Keyword.starts_with("DIFlag")) {

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7053,7 +7053,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
70537053
.Case("declare", RecordKind::ValueKind)
70547054
.Case("value", RecordKind::ValueKind)
70557055
.Case("assign", RecordKind::ValueKind)
7056-
.Case("label", RecordKind::LabelKind);
7056+
.Case("label", RecordKind::LabelKind)
7057+
.Case("declare_value", RecordKind::ValueKind);
70577058

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

70837085
Lex.Lex();
70847086
if (parseToken(lltok::lparen, "Expected '(' here"))

llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ GetCodeName(unsigned CodeID, unsigned BlockID,
272272
STRINGIFY_CODE(FUNC_CODE, INST_CALLBR)
273273
STRINGIFY_CODE(FUNC_CODE, BLOCKADDR_USERS)
274274
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE)
275-
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_COROFRAME_ENTRY)
275+
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE_VALUE)
276276
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
277277
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
278278
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)

0 commit comments

Comments
 (0)