Skip to content

Commit 01f2dab

Browse files
committed
Add DILabel functions for LLVM-C
1 parent bbccc52 commit 01f2dab

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,52 @@ LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst);
14151415
*/
14161416
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
14171417

1418+
/**
1419+
* Create a new descriptor for a label
1420+
*
1421+
* \param Builder The DIBuilder.
1422+
* \param Scope The scope to create the label in.
1423+
* \param Name Variable name.
1424+
* \param NameLen Length of variable name.
1425+
* \param File The file to create the label in.
1426+
* \param LineNo Line Number.
1427+
* \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it.
1428+
*
1429+
* @see llvm::DIBuilder::createLabel()
1430+
*/
1431+
LLVMMetadataRef LLVMDIBuilderCreateLabel(
1432+
LLVMDIBuilderRef Builder,
1433+
LLVMMetadataRef Context, const char *Name, size_t NameLen,
1434+
LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve);
1435+
1436+
/**
1437+
* Insert a new llvm.dbg.label intrinsic call
1438+
*
1439+
* \param Builder The DIBuilder.
1440+
* \param LabelInfo The Label's debug info descriptor
1441+
* \param Location The debug info location
1442+
* \param InsertBefore Location for the new intrinsic.
1443+
*
1444+
* @see llvm::DIBuilder::insertLabel()
1445+
*/
1446+
LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
1447+
LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1448+
LLVMMetadataRef Location, LLVMValueRef InsertBefore);
1449+
1450+
/**
1451+
* Insert a new llvm.dbg.label intrinsic call
1452+
*
1453+
* \param Builder The DIBuilder.
1454+
* \param LabelInfo The Label's debug info descriptor
1455+
* \param Location The debug info location
1456+
* \param InsertAtEnd Location for the new intrinsic.
1457+
*
1458+
* @see llvm::DIBuilder::insertLabel()
1459+
*/
1460+
LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
1461+
LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1462+
LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd);
1463+
14181464
/**
14191465
* Obtain the enumerated type of a Metadata instance.
14201466
*

llvm/lib/IR/DebugInfo.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,47 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
17991799
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
18001800
}
18011801

1802+
LLVMMetadataRef LLVMDIBuilderCreateLabel(
1803+
LLVMDIBuilderRef Builder,
1804+
LLVMMetadataRef Context, const char *Name, size_t NameLen,
1805+
LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
1806+
return wrap(unwrap(Builder)->createLabel(
1807+
unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
1808+
unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
1809+
}
1810+
1811+
LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
1812+
LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1813+
LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
1814+
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1815+
unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1816+
unwrap<Instruction>(InsertBefore));
1817+
// This assert will fail if the module is in the old debug info format.
1818+
// This function should only be called if the module is in the new
1819+
// debug info format.
1820+
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1821+
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1822+
assert(isa<DbgRecord *>(DbgInst) &&
1823+
"Function unexpectedly in old debug info format");
1824+
return wrap(cast<DbgRecord *>(DbgInst));
1825+
}
1826+
1827+
LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
1828+
LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
1829+
LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
1830+
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
1831+
unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
1832+
unwrap(InsertAtEnd));
1833+
// This assert will fail if the module is in the old debug info format.
1834+
// This function should only be called if the module is in the new
1835+
// debug info format.
1836+
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
1837+
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
1838+
assert(isa<DbgRecord *>(DbgInst) &&
1839+
"Function unexpectedly in old debug info format");
1840+
return wrap(cast<DbgRecord *>(DbgInst));
1841+
}
1842+
18021843
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
18031844
switch(unwrap(Metadata)->getMetadataID()) {
18041845
#define HANDLE_METADATA_LEAF(CLASS) \

0 commit comments

Comments
 (0)