Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ enum FunctionCodes {
FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE =
64, // [DILocation, DILocalVariable, DIExpression, Value]
FUNC_CODE_DEBUG_RECORD_LABEL = 65, // [DILocation, DILabel]
FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE =
66, // [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]
};

enum UseListCodes {
Expand Down
12 changes: 12 additions & 0 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,18 @@ namespace llvm {
DIExpression *Expr, const DILocation *DL,
InsertPosition InsertPt);

/// Insert a new llvm.dbg.declare_value intrinsic call.
/// \param Storage llvm::Value of the variable
/// \param VarInfo Variable's debug info descriptor.
/// \param Expr A complex location expression.
/// \param DL Debug info location.
/// \param InsertPt Location for the new intrinsic.
LLVM_ABI DbgInstPtr insertDeclareValue(llvm::Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt);

/// Insert a new llvm.dbg.label intrinsic call.
/// \param LabelInfo Label's debug info descriptor.
/// \param DL Debug info location.
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Module;
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclares(Value *V);
/// As above, for DVRValues.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRValues(Value *V);
/// As above, for DVRCoroFrameEntrys.
LLVM_ABI TinyPtrVector<DbgVariableRecord *> findDVRDeclareValues(Value *V);

/// Finds the debug info records describing a value.
LLVM_ABI void
Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {
Declare,
Value,
Assign,
DeclareValue,

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

LLVM_ABI static DbgVariableRecord *
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI);
LLVM_ABI static DbgVariableRecord *
createDVRDeclareValue(Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI, DbgVariableRecord &InsertBefore);

/// Iterator for ValueAsMetadata that internally uses direct pointer iteration
/// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
/// ValueAsMetadata .
Expand Down Expand Up @@ -414,6 +422,7 @@ class DbgVariableRecord : public DbgRecord, protected DebugValueUser {

bool isDbgDeclare() const { return Type == LocationType::Declare; }
bool isDbgValue() const { return Type == LocationType::Value; }
bool isDbgDeclareValue() const { return Type == LocationType::DeclareValue; }

/// Get the locations corresponding to the variable referenced by the debug
/// info intrinsic. Depending on the intrinsic, this could be the
Expand Down
21 changes: 21 additions & 0 deletions llvm/include/llvm/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ class DbgVariableIntrinsic : public DbgInfoIntrinsic {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
case Intrinsic::dbg_assign:
case Intrinsic::dbg_declare_value:
return true;
default:
return false;
Expand Down Expand Up @@ -464,6 +465,26 @@ class DbgDeclareInst : public DbgVariableIntrinsic {
/// @}
};

/// This represents the llvm.dbg.declare_value instruction.
class DbgDeclareValueInst : public DbgVariableIntrinsic {
public:
Value *getAddress() const {
assert(getNumVariableLocationOps() == 1 &&
"dbg.declare_value must have exactly 1 location operand.");
return getVariableLocationOp(0);
}

/// \name Casting methods
/// @{
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::dbg_declare_value;
}
static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}
/// @}
};

/// This represents the llvm.dbg.value instruction.
class DbgValueInst : public DbgVariableIntrinsic {
public:
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,10 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
llvm_metadata_ty]>;
def int_dbg_label : DefaultAttrsIntrinsic<[],
[llvm_metadata_ty]>;
def int_dbg_declare_value : DefaultAttrsIntrinsic<[],
[llvm_metadata_ty,
llvm_metadata_ty,
llvm_metadata_ty]>;
}

//===------------------ Exception Handling Intrinsics----------------------===//
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ lltok::Kind LLLexer::LexIdentifier() {
DBGRECORDTYPEKEYWORD(declare);
DBGRECORDTYPEKEYWORD(assign);
DBGRECORDTYPEKEYWORD(label);
DBGRECORDTYPEKEYWORD(declare_value);
#undef DBGRECORDTYPEKEYWORD

if (Keyword.starts_with("DIFlag")) {
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7148,7 +7148,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
.Case("declare", RecordKind::ValueKind)
.Case("value", RecordKind::ValueKind)
.Case("assign", RecordKind::ValueKind)
.Case("label", RecordKind::LabelKind);
.Case("label", RecordKind::LabelKind)
.Case("declare_value", RecordKind::ValueKind);

// Parsing labels is trivial; parse here and early exit, otherwise go into the
// full DbgVariableRecord processing stage.
Expand All @@ -7173,7 +7174,8 @@ bool LLParser::parseDebugRecord(DbgRecord *&DR, PerFunctionState &PFS) {
LocType ValueType = StringSwitch<LocType>(Lex.getStrVal())
.Case("declare", LocType::Declare)
.Case("value", LocType::Value)
.Case("assign", LocType::Assign);
.Case("assign", LocType::Assign)
.Case("declare_value", LocType::DeclareValue);

Lex.Lex();
if (parseToken(lltok::lparen, "Expected '(' here"))
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ GetCodeName(unsigned CodeID, unsigned BlockID,
STRINGIFY_CODE(FUNC_CODE, INST_CALLBR)
STRINGIFY_CODE(FUNC_CODE, BLOCKADDR_USERS)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE_VALUE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6653,6 +6653,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE:
case bitc::FUNC_CODE_DEBUG_RECORD_VALUE:
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE:
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
// DbgVariableRecords are placed after the Instructions that they are
// attached to.
Expand All @@ -6669,6 +6670,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
// ..., Value
// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
// ..., LocationMetadata
// dbg_declare_value (FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE)
// ..., LocationMetadata
// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
unsigned Slot = 0;
Expand Down Expand Up @@ -6710,6 +6713,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
DVR = new DbgVariableRecord(RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::Declare);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE:
DVR = new DbgVariableRecord(
RawLocation, Var, Expr, DIL,
DbgVariableRecord::LocationType::DeclareValue);
break;
case bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN: {
DIAssignID *ID = cast<DIAssignID>(getFnMetadataByID(Record[Slot++]));
DIExpression *AddrExpr =
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,9 @@ void ModuleBitcodeWriter::writeFunction(
} else if (DVR.isDbgDeclare()) {
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
} else if (DVR.isDbgDeclareValue()) {
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE_VALUE, Vals);
} else {
assert(DVR.isDbgAssign() && "Unexpected DbgRecord kind");
Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,9 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) {
case DbgVariableRecord::LocationType::Declare:
Out << "declare";
break;
case DbgVariableRecord::LocationType::DeclareValue:
Out << "declare_value";
break;
case DbgVariableRecord::LocationType::Assign:
Out << "assign";
break;
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4623,6 +4623,11 @@ static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI) {
DbgVariableRecord::LocationType::Declare, unwrapMAVMetadataOp(CI, 0),
unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2), nullptr, nullptr, nullptr,
getDebugLocSafe(CI));
} else if (Name == "declare_value") {
DR = DbgVariableRecord::createUnresolvedDbgVariableRecord(
DbgVariableRecord::LocationType::DeclareValue,
unwrapMAVMetadataOp(CI, 0), unwrapMAVOp(CI, 1), unwrapMAVOp(CI, 2),
nullptr, nullptr, nullptr, getDebugLocSafe(CI));
} else if (Name == "addr") {
// Upgrade dbg.addr to dbg.value with DW_OP_deref.
MDNode *ExprNode = unwrapMAVOp(CI, 2);
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/IR/DIBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,24 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
return DVR;
}

DbgInstPtr DIBuilder::insertDeclareValue(Value *Storage,
DILocalVariable *VarInfo,
DIExpression *Expr,
const DILocation *DL,
InsertPosition InsertPt) {
assert(VarInfo &&
"empty or invalid DILocalVariable* passed to dbg.declare_value");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
VarInfo->getScope()->getSubprogram() &&
"Expected matching subprograms");

DbgVariableRecord *DVR =
DbgVariableRecord::createDVRDeclareValue(Storage, VarInfo, Expr, DL);
insertDbgVariableRecord(DVR, InsertPt);
return DVR;
}

void DIBuilder::insertDbgVariableRecord(DbgVariableRecord *DVR,
InsertPosition InsertPt) {
assert(InsertPt.isValid());
Expand Down
17 changes: 17 additions & 0 deletions llvm/lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares(Value *V) {
return Declares;
}

TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclareValues(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup. This check is a bitfield datamember lookup.
if (!V->isUsedByMetadata())
return {};
auto *L = ValueAsMetadata::getIfExists(V);
if (!L)
return {};

TinyPtrVector<DbgVariableRecord *> Coros;
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
if (DVR->getType() == DbgVariableRecord::LocationType::DeclareValue)
Coros.push_back(DVR);

return Coros;
}

TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup. This check is a bitfield datamember lookup.
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ DbgVariableRecord::DbgVariableRecord(const DbgVariableIntrinsic *DVI)
case Intrinsic::dbg_declare:
Type = LocationType::Declare;
break;
case Intrinsic::dbg_declare_value:
Type = LocationType::DeclareValue;
break;
case Intrinsic::dbg_assign: {
Type = LocationType::Assign;
const DbgAssignIntrinsic *Assign =
Expand Down Expand Up @@ -209,6 +212,22 @@ DbgVariableRecord::createDVRDeclare(Value *Address, DILocalVariable *DV,
return NewDVRDeclare;
}

DbgVariableRecord *
DbgVariableRecord::createDVRDeclareValue(Value *Address, DILocalVariable *DV,
DIExpression *Expr,
const DILocation *DI) {
return new DbgVariableRecord(ValueAsMetadata::get(Address), DV, Expr, DI,
LocationType::DeclareValue);
}

DbgVariableRecord *DbgVariableRecord::createDVRDeclareValue(
Value *Address, DILocalVariable *DV, DIExpression *Expr,
const DILocation *DI, DbgVariableRecord &InsertBefore) {
auto *NewDVRCoro = createDVRDeclareValue(Address, DV, Expr, DI);
NewDVRCoro->insertBefore(&InsertBefore);
return NewDVRCoro;
}

DbgVariableRecord *DbgVariableRecord::createDVRAssign(
Value *Val, DILocalVariable *Variable, DIExpression *Expression,
DIAssignID *AssignID, Value *Address, DIExpression *AddressExpression,
Expand Down Expand Up @@ -416,6 +435,10 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
case DbgVariableRecord::LocationType::Declare:
IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare);
break;
case DbgVariableRecord::LocationType::DeclareValue:
IntrinsicFn =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare_value);
break;
case DbgVariableRecord::LocationType::Value:
IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_value);
break;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ struct VerifierSupport {
case DbgVariableRecord::LocationType::Declare:
*OS << "declare";
break;
case DbgVariableRecord::LocationType::DeclareValue:
*OS << "declare_value";
break;
case DbgVariableRecord::LocationType::Assign:
*OS << "assign";
break;
Expand Down Expand Up @@ -7024,6 +7027,7 @@ void Verifier::visit(DbgVariableRecord &DVR) {

CheckDI(DVR.getType() == DbgVariableRecord::LocationType::Value ||
DVR.getType() == DbgVariableRecord::LocationType::Declare ||
DVR.getType() == DbgVariableRecord::LocationType::DeclareValue ||
DVR.getType() == DbgVariableRecord::LocationType::Assign,
"invalid #dbg record type", &DVR, DVR.getType(), BB, F);

Expand Down
Loading