Skip to content

Commit d6484cf

Browse files
Add new llvm.dbg.coroframe_entry 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.coroframe_entry has been created, which behaves exactly like an llvm.dbg.declare but can take non pointer and integer location types.
1 parent 74320d1 commit d6484cf

15 files changed

+163
-2
lines changed

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,14 @@ enum FunctionCodes {
681681
61, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
682682
FUNC_CODE_DEBUG_RECORD_DECLARE =
683683
62, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
684+
FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY =
685+
64, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
684686
FUNC_CODE_DEBUG_RECORD_ASSIGN =
685687
63, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata,
686688
// DIAssignID, DIExpression (addr), ValueAsMetadata (addr)]
687689
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
688-
64, // [DILocation, DILocalVariable, DIExpression, Value]
689-
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
690+
65, // [DILocation, DILocalVariable, DIExpression, Value]
691+
FUNC_CODE_DEBUG_RECORD_LABEL = 66, // [DILocation, DILabel]
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
@@ -1150,6 +1150,18 @@ namespace llvm {
11501150
DIExpression *Expr, const DILocation *DL,
11511151
InsertPosition InsertPt);
11521152

1153+
/// Insert a new llvm.dbg.coroframe_entry 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 insertCoroFrameEntry(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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ 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+
LLVM_ABI TinyPtrVector<DbgCoroFrameEntryInst *>
50+
findDbgCoroFrameEntrys(Value *V);
51+
/// As above, for DVRCoroFrameEntrys.
52+
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRCoroFrameEntrys(Value *V);
4753
/// As above, for DVRValues.
4854
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
4955

llvm/include/llvm/IR/DebugProgramInstruction.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
281281
enum class LocationType : uint8_t {
282282
Declare,
283283
Value,
284+
CoroFrameEntry,
284285
Assign,
285286

286287
End, ///< Marks the end of the concrete types.
@@ -364,6 +365,14 @@ 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+
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
370+
DIExpression *Expr, const DILocation *DI);
371+
LLVM_ABI static DbgVariableRecord *
372+
createDVRCoroFrameEntry(Value *Address, DILocalVariable *DV,
373+
DIExpression *Expr, const DILocation *DI,
374+
DbgVariableRecord &InsertBefore);
375+
367376
/// Iterator for ValueAsMetadata that internally uses direct pointer iteration
368377
/// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
369378
/// ValueAsMetadata .
@@ -414,6 +423,9 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
414423

415424
bool isDbgDeclare() const { return Type == LocationType::Declare; }
416425
bool isDbgValue() const { return Type == LocationType::Value; }
426+
bool isDbgCoroFrameEntry() const {
427+
return Type == LocationType::CoroFrameEntry;
428+
}
417429

418430
/// Get the locations corresponding to the variable referenced by the debug
419431
/// 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_coroframe_entry:
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.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+
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
@@ -1474,6 +1474,10 @@ 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]>;
14771481
}
14781482

14791483
//===------------------ Exception Handling Intrinsics----------------------===//

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_COROFRAME_ENTRY)
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_COROFRAME_ENTRY:
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_coroframe_entry (FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY)
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_COROFRAME_ENTRY:
6708+
DVR = new DbgVariableRecord(
6709+
RawLocation, Var, Expr, DIL,
6710+
DbgVariableRecord::LocationType::CoroFrameEntry);
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,10 @@ void ModuleBitcodeWriter::writeFunction(
38273827
} else if (DVR.isDbgDeclare()) {
38283828
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
38293829
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
3830+
} else if (DVR.isDbgCoroFrameEntry()) {
3831+
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
3832+
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_COROFRAME_ENTRY,
3833+
Vals);
38303834
} else {
38313835
assert(DVR.isDbgAssign() && "Unexpected DbgRecord kind");
38323836
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));

llvm/lib/IR/AsmWriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,6 +4876,9 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) {
48764876
case DbgVariableRecord::LocationType::Declare:
48774877
Out << "declare";
48784878
break;
4879+
case DbgVariableRecord::LocationType::CoroFrameEntry:
4880+
Out << "coroframe_entry";
4881+
break;
48794882
case DbgVariableRecord::LocationType::Assign:
48804883
Out << "assign";
48814884
break;

0 commit comments

Comments
 (0)