Skip to content

Commit b427b5a

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 8025302 commit b427b5a

File tree

17 files changed

+137
-2
lines changed

17 files changed

+137
-2
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
@@ -1150,6 +1150,18 @@ namespace llvm {
11501150
DIExpression *Expr, const DILocation *DL,
11511151
InsertPosition InsertPt);
11521152

1153+
/// Insert a new llvm.dbg.declare_value intrinsic call.
1154+
/// \param Storage llvm::Value of the variable
1155+
/// \param VarInfo Variable's debug info descriptor.
1156+
/// \param Expr A complex location expression.
1157+
/// \param DL Debug info location.
1158+
/// \param InsertPt Location for the new intrinsic.
1159+
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
1160+
DILocalVariable *VarInfo,
1161+
DIExpression *Expr,
1162+
const DILocation *DL,
1163+
InsertPosition InsertPt);
1164+
11531165
/// Insert a new llvm.dbg.label intrinsic call.
11541166
/// \param LabelInfo Label's debug info descriptor.
11551167
/// \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
@@ -1447,6 +1447,10 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
14471447
llvm_metadata_ty]>;
14481448
def int_dbg_label : DefaultAttrsIntrinsic<[],
14491449
[llvm_metadata_ty]>;
1450+
def int_dbg_declare_value : DefaultAttrsIntrinsic<[],
1451+
[llvm_metadata_ty,
1452+
llvm_metadata_ty,
1453+
llvm_metadata_ty]>;
14501454
}
14511455

14521456
//===------------------ Exception Handling Intrinsics----------------------===//

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ lltok::Kind LLLexer::LexIdentifier() {
10021002
DBGRECORDTYPEKEYWORD(declare);
10031003
DBGRECORDTYPEKEYWORD(assign);
10041004
DBGRECORDTYPEKEYWORD(label);
1005+
DBGRECORDTYPEKEYWORD(declare_value);
10051006
#undef DBGRECORDTYPEKEYWORD
10061007

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

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,7 +7075,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
70757075
.Case("declare", RecordKind::ValueKind)
70767076
.Case("value", RecordKind::ValueKind)
70777077
.Case("assign", RecordKind::ValueKind)
7078-
.Case("label", RecordKind::LabelKind);
7078+
.Case("label", RecordKind::LabelKind)
7079+
.Case("declare_value", RecordKind::ValueKind);
70797080

70807081
// Parsing labels is trivial; parse here and early exit, otherwise go into the
70817082
// full DbgVariableRecord processing stage.
@@ -7100,7 +7101,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
71007101
LocType ValueType = StringSwitch<LocType>(Lex.getStrVal())
71017102
.Case("declare", LocType::Declare)
71027103
.Case("value", LocType::Value)
7103-
.Case("assign", LocType::Assign);
7104+
.Case("assign", LocType::Assign)
7105+
.Case("declare_value", LocType::DeclareValue);
71047106

71057107
Lex.Lex();
71067108
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
@@ -6651,6 +6651,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66516651
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
66526652
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
66536653
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
6654+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
66546655
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
66556656
// DbgVariableRecords are placed after the Instructions that they are
66566657
// attached to.
@@ -6667,6 +6668,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
66676668
// ..., Value
66686669
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
66696670
// ..., LocationMetadata
6671+
// dbg_declare_value (FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE)
6672+
// ..., LocationMetadata
66706673
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
66716674
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
66726675
unsigned Slot = 0;
@@ -6708,6 +6711,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
67086711
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
67096712
DbgVariableRecord::LocationType::Declare);
67106713
break;
6714+
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
6715+
DVR = new DbgVariableRecord(
6716+
RawLocation, Var, Expr, DIL,
6717+
DbgVariableRecord::LocationType::DeclareValue);
6718+
break;
67116719
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
67126720
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
67136721
DIExpression *AddrExpr =

0 commit comments

Comments
 (0)