Skip to content

Commit 8ca72ae

Browse files
rastogishubhamfelipepiovezan
authored andcommitted
Add new llvm.dbg.declare_value intrinsic. (llvm#168132)
For swift async code, we need to use a debug intrinsic that behaves like an llvm.dbg.declare but can take any location type rather than just a pointer or integer. To solve this, a new debug instrinsic called llvm.dbg.declare_value has been created, which behaves exactly like an llvm.dbg.declare but can take non pointer and integer location types. More information here: https://discourse.llvm.org/t/rfc-introduce-new-llvm-dbg-coroframe-entry-intrinsic/88269 This is the first patch as part of a stack of patches, with the one succeeding it being: llvm#168134 (cherry picked from commit 20ebc7e)
1 parent 994fe32 commit 8ca72ae

File tree

16 files changed

+170
-5
lines changed

16 files changed

+170
-5
lines changed

llvm/docs/SourceLevelDebugging.rst

Lines changed: 22 additions & 0 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::

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,8 @@ 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_DECLARE_VALUE =
691+
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
690692
};
691693

692694
enum UseListCodes {

llvm/include/llvm/IR/DIBuilder.h

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

1158+
/// Insert a new llvm.dbg.declare_value intrinsic call.
1159+
/// \param Storage llvm::Value of the variable
1160+
/// \param VarInfo Variable's debug info descriptor.
1161+
/// \param Expr A complex location expression.
1162+
/// \param DL Debug info location.
1163+
/// \param InsertPt Location for the new intrinsic.
1164+
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
1165+
DILocalVariable *VarInfo,
1166+
DIExpression *Expr,
1167+
const DILocation *DL,
1168+
InsertPosition InsertPt);
1169+
11581170
/// Insert a new llvm.dbg.label intrinsic call.
11591171
/// \param LabelInfo Label's debug info descriptor.
11601172
/// \param DL Debug info location.

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ LLVM_ABI TinyPtrVector<DbgDeclareInst *> findDbgDeclares(Value *V);
4646
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
4747
/// As above, for DVRValues.
4848
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
49+
/// As above, for DVRDeclareValues.
50+
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclareValues(Value *V);
4951

5052
/// Finds the llvm.dbg.value intrinsics describing a value.
5153
LLVM_ABI void findDbgValues(

llvm/include/llvm/IR/DebugProgramInstruction.h

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

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

368+
LLVM_ABI static DbgVariableRecord *
369+
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
370+
const DILocation *DI);
371+
LLVM_ABI static DbgVariableRecord *
372+
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
373+
const DILocation *DI, DbgVariableRecord &InsertBefore);
374+
367375
/// Iterator for ValueAsMetadata that internally uses direct pointer iteration
368376
/// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
369377
/// ValueAsMetadata .
@@ -414,6 +422,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
414422

415423
bool isDbgDeclare() const { return Type == LocationType::Declare; }
416424
bool isDbgValue() const { return Type == LocationType::Value; }
425+
bool isDbgDeclareValue() const { return Type == LocationType::DeclareValue; }
417426

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

441450
/// Does this describe the address of a local variable. True for dbg.addr
442-
/// 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.
443453
bool isAddressOfVariable() const { return Type == LocationType::Declare; }
444454

445455
/// Determine if this describes the value of a local variable. It is false for
446-
/// dbg.declare, but true for dbg.value, which describes its value.
447-
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+
}
448461

449462
LocationType getType() const { return Type; }
450463

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +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_DECLARE_VALUE)
275276
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
276277
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
277278
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6644,6 +6644,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66446644
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
66456645
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
66466646
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
6647+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
66476648
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
66486649
// DbgVariableRecords are placed after the Instructions that they are
66496650
// attached to.
@@ -6660,6 +6661,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66606661
// ..., Value
66616662
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
66626663
// ..., LocationMetadata
6664+
// dbg_declare_value (FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE)
6665+
// ..., LocationMetadata
66636666
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
66646667
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
66656668
unsigned Slot = 0;
@@ -6701,6 +6704,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
67016704
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
67026705
DbgVariableRecord::LocationType::Declare);
67036706
break;
6707+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
6708+
DVR = new DbgVariableRecord(
6709+
RawLocation, Var, Expr, DIL,
6710+
DbgVariableRecord::LocationType::DeclareValue);
6711+
break;
67046712
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
67056713
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
67066714
DIExpression *AddrExpr =

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,9 @@ void ModuleBitcodeWriter::writeFunction(
38283828
} else if (DVR.isDbgDeclare()) {
38293829
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
38303830
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
3831+
} else if (DVR.isDbgDeclareValue()) {
3832+
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
3833+
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE, Vals);
38313834
} else {
38323835
assert(DVR.isDbgAssign() && "Unexpected DbgRecord kind");
38333836
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));

0 commit comments

Comments
 (0)