Skip to content

Commit 70c9f1a

Browse files
Add new llvm.dbg.declare_value intrinsic.
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.
1 parent b9c769b commit 70c9f1a

File tree

18 files changed

+157
-3
lines changed

18 files changed

+157
-3
lines changed

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ enum FunctionCodes {
688688
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
689689
64, // [DILocation, DILocalVariable, DIExpression, Value]
690690
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
691+
FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE =
692+
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
691693
};
692694

693695
enum UseListCodes {

llvm/include/llvm/IR/DIBuilder.h

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

1159+
/// Insert a new llvm.dbg.declare_value intrinsic call.
1160+
/// \param Storage llvm::Value of the variable
1161+
/// \param VarInfo Variable's debug info descriptor.
1162+
/// \param Expr A complex location expression.
1163+
/// \param DL Debug info location.
1164+
/// \param InsertPt Location for the new intrinsic.
1165+
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
1166+
DILocalVariable *VarInfo,
1167+
DIExpression *Expr,
1168+
const DILocation *DL,
1169+
InsertPosition InsertPt);
1170+
11591171
/// Insert a new llvm.dbg.label intrinsic call.
11601172
/// \param LabelInfo Label's debug info descriptor.
11611173
/// \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
@@ -44,6 +44,8 @@ class Module;
4444
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
4545
/// As above, for DVRValues.
4646
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
47+
/// As above, for DVRCoroFrameEntrys.
48+
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclareValues(Value *V);
4749

4850
/// Finds the debug info records describing a value.
4951
LLVM_ABI void

llvm/include/llvm/IR/DebugProgramInstruction.h

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

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
428428
case Intrinsic::dbg_declare:
429429
case Intrinsic::dbg_value:
430430
case Intrinsic::dbg_assign:
431+
case Intrinsic::dbg_declare_value:
431432
return true;
432433
default:
433434
return false;
@@ -464,6 +465,26 @@ class DbgDeclareInst : public DbgVariableIntrinsic {
464465
/// @}
465466
};
466467

468+
/// This represents the llvm.dbg.declare_value instruction.
469+
class DbgDeclareValueInst : public DbgVariableIntrinsic {
470+
public:
471+
Value *getAddress() const {
472+
assert(getNumVariableLocationOps() == 1 &&
473+
"dbg.declare_value 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_declare_value;
481+
}
482+
static bool classof(const Value *V) {
483+
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
484+
}
485+
/// @}
486+
};
487+
467488
/// This represents the llvm.dbg.value instruction.
468489
class DbgValueInst : public DbgVariableIntrinsic {
469490
public:

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,10 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
14601460
llvm_metadata_ty]>;
14611461
def int_dbg_label : DefaultAttrsIntrinsic<[],
14621462
[llvm_metadata_ty]>;
1463+
def int_dbg_declare_value : DefaultAttrsIntrinsic<[],
1464+
[llvm_metadata_ty,
1465+
llvm_metadata_ty,
1466+
llvm_metadata_ty]>;
14631467
}
14641468

14651469
//===------------------ Exception Handling Intrinsics----------------------===//

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ lltok::Kind LLLexer::LexIdentifier() {
10051005
DBGRECORDTYPEKEYWORD(declare);
10061006
DBGRECORDTYPEKEYWORD(assign);
10071007
DBGRECORDTYPEKEYWORD(label);
1008+
DBGRECORDTYPEKEYWORD(declare_value);
10081009
#undef DBGRECORDTYPEKEYWORD
10091010

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

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7152,7 +7152,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
71527152
.Case("declare", RecordKind::ValueKind)
71537153
.Case("value", RecordKind::ValueKind)
71547154
.Case("assign", RecordKind::ValueKind)
7155-
.Case("label", RecordKind::LabelKind);
7155+
.Case("label", RecordKind::LabelKind)
7156+
.Case("declare_value", RecordKind::ValueKind);
71567157

71577158
// Parsing labels is trivial; parse here and early exit, otherwise go into the
71587159
// full DbgVariableRecord processing stage.
@@ -7177,7 +7178,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
71777178
LocType ValueType = StringSwitch<LocType>(Lex.getStrVal())
71787179
.Case("declare", LocType::Declare)
71797180
.Case("value", LocType::Value)
7180-
.Case("assign", LocType::Assign);
7181+
.Case("assign", LocType::Assign)
7182+
.Case("declare_value", LocType::DeclareValue);
71817183

71827184
Lex.Lex();
71837185
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
@@ -6655,6 +6655,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66556655
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
66566656
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
66576657
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
6658+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
66586659
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
66596660
// DbgVariableRecords are placed after the Instructions that they are
66606661
// attached to.
@@ -6671,6 +6672,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66716672
// ..., Value
66726673
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
66736674
// ..., LocationMetadata
6675+
// dbg_declare_value (FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE)
6676+
// ..., LocationMetadata
66746677
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
66756678
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
66766679
unsigned Slot = 0;
@@ -6712,6 +6715,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
67126715
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
67136716
DbgVariableRecord::LocationType::Declare);
67146717
break;
6718+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
6719+
DVR = new DbgVariableRecord(
6720+
RawLocation, Var, Expr, DIL,
6721+
DbgVariableRecord::LocationType::DeclareValue);
6722+
break;
67156723
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
67166724
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
67176725
DIExpression *AddrExpr =

0 commit comments

Comments
 (0)