-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add DILabel functions for LLVM-C #112840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DILabel functions for LLVM-C #112840
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-debuginfo Author: None (tf2spi) ChangesAddresses #112799 Full diff: https://github.com/llvm/llvm-project/pull/112840.diff 2 Files Affected:
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 6d8891e7057722..0a3ccbb9613587 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -1415,6 +1415,52 @@ LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst);
*/
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
+/**
+ * Create a new descriptor for a label
+ *
+ * \param Builder The DIBuilder.
+ * \param Scope The scope to create the label in.
+ * \param Name Variable name.
+ * \param NameLen Length of variable name.
+ * \param File The file to create the label in.
+ * \param LineNo Line Number.
+ * \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it.
+ *
+ * @see llvm::DIBuilder::createLabel()
+ */
+LLVMMetadataRef LLVMDIBuilderCreateLabel(
+ LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context, const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve);
+
+/**
+ * Insert a new llvm.dbg.label intrinsic call
+ *
+ * \param Builder The DIBuilder.
+ * \param LabelInfo The Label's debug info descriptor
+ * \param Location The debug info location
+ * \param InsertBefore Location for the new intrinsic.
+ *
+ * @see llvm::DIBuilder::insertLabel()
+ */
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMValueRef InsertBefore);
+
+/**
+ * Insert a new llvm.dbg.label intrinsic call
+ *
+ * \param Builder The DIBuilder.
+ * \param LabelInfo The Label's debug info descriptor
+ * \param Location The debug info location
+ * \param InsertAtEnd Location for the new intrinsic.
+ *
+ * @see llvm::DIBuilder::insertLabel()
+ */
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd);
+
/**
* Obtain the enumerated type of a Metadata instance.
*
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 50b29ae4f41676..e20a0f053481ed 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1799,6 +1799,47 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
}
+LLVMMetadataRef LLVMDIBuilderCreateLabel(
+ LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context, const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
+ return wrap(unwrap(Builder)->createLabel(
+ unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
+ unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
+}
+
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
+ DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap<Instruction>(InsertBefore));
+ // This assert will fail if the module is in the old debug info format.
+ // This function should only be called if the module is in the new
+ // debug info format.
+ // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
+ // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
+ assert(isa<DbgRecord *>(DbgInst) &&
+ "Function unexpectedly in old debug info format");
+ return wrap(cast<DbgRecord *>(DbgInst));
+}
+
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
+ DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap(InsertAtEnd));
+ // This assert will fail if the module is in the old debug info format.
+ // This function should only be called if the module is in the new
+ // debug info format.
+ // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
+ // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
+ assert(isa<DbgRecord *>(DbgInst) &&
+ "Function unexpectedly in old debug info format");
+ return wrap(cast<DbgRecord *>(DbgInst));
+}
+
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
switch(unwrap(Metadata)->getMetadataID()) {
#define HANDLE_METADATA_LEAF(CLASS) \
|
@llvm/pr-subscribers-llvm-ir Author: None (tf2spi) ChangesAddresses #112799 Full diff: https://github.com/llvm/llvm-project/pull/112840.diff 2 Files Affected:
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 6d8891e7057722..0a3ccbb9613587 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -1415,6 +1415,52 @@ LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst);
*/
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
+/**
+ * Create a new descriptor for a label
+ *
+ * \param Builder The DIBuilder.
+ * \param Scope The scope to create the label in.
+ * \param Name Variable name.
+ * \param NameLen Length of variable name.
+ * \param File The file to create the label in.
+ * \param LineNo Line Number.
+ * \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it.
+ *
+ * @see llvm::DIBuilder::createLabel()
+ */
+LLVMMetadataRef LLVMDIBuilderCreateLabel(
+ LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context, const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve);
+
+/**
+ * Insert a new llvm.dbg.label intrinsic call
+ *
+ * \param Builder The DIBuilder.
+ * \param LabelInfo The Label's debug info descriptor
+ * \param Location The debug info location
+ * \param InsertBefore Location for the new intrinsic.
+ *
+ * @see llvm::DIBuilder::insertLabel()
+ */
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMValueRef InsertBefore);
+
+/**
+ * Insert a new llvm.dbg.label intrinsic call
+ *
+ * \param Builder The DIBuilder.
+ * \param LabelInfo The Label's debug info descriptor
+ * \param Location The debug info location
+ * \param InsertAtEnd Location for the new intrinsic.
+ *
+ * @see llvm::DIBuilder::insertLabel()
+ */
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd);
+
/**
* Obtain the enumerated type of a Metadata instance.
*
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 50b29ae4f41676..e20a0f053481ed 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1799,6 +1799,47 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
}
+LLVMMetadataRef LLVMDIBuilderCreateLabel(
+ LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context, const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
+ return wrap(unwrap(Builder)->createLabel(
+ unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
+ unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
+}
+
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
+ DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap<Instruction>(InsertBefore));
+ // This assert will fail if the module is in the old debug info format.
+ // This function should only be called if the module is in the new
+ // debug info format.
+ // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
+ // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
+ assert(isa<DbgRecord *>(DbgInst) &&
+ "Function unexpectedly in old debug info format");
+ return wrap(cast<DbgRecord *>(DbgInst));
+}
+
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
+ LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
+ DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap(InsertAtEnd));
+ // This assert will fail if the module is in the old debug info format.
+ // This function should only be called if the module is in the new
+ // debug info format.
+ // See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
+ // LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
+ assert(isa<DbgRecord *>(DbgInst) &&
+ "Function unexpectedly in old debug info format");
+ return wrap(cast<DbgRecord *>(DbgInst));
+}
+
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
switch(unwrap(Metadata)->getMetadataID()) {
#define HANDLE_METADATA_LEAF(CLASS) \
|
llvm/include/llvm-c/DebugInfo.h
Outdated
* \param NameLen Length of variable name. | ||
* \param File The file to create the label in. | ||
* \param LineNo Line Number. | ||
* \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed after the fact that this line is longer than 80 characters and that the rest of the lines in this file are 80 characters. I would make a change like this but I also don't want to run a pipeline right now for a simple comment change. Waiting for review then, if this is desired, I can add it in.
* \param AlwaysPreserve Preserve the label even if the optimizer wants to remove it. | |
* \param AlwaysPreserve Preserve the label regardless of optimization. |
I also noticed there's an LLVM-C DebugInfo test. Do tests for new features normally get added in the same PR or in a separate one? |
Tests should be added in the same PR as the functional change. |
@echristo Hello! I'm a new contributor in LLVM. After reading the LLVM Contributing Guide, it suggested to ping you when the code is ready to review. Any time that's convenient for you to review this I would greatly appreciate. |
@llvm/pr-subscribers-debuginfo Ping |
LGTM. |
@tf2spi Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
You can test this locally with the following command:git-clang-format --diff bbccc521c6a0de151c4d7a34e7f78ae47f3a3298 73dffdaa91a87fc0b9c0ed8385bbd17c6fb65366 --extensions h,cpp,c -- llvm/include/llvm-c/DebugInfo.h llvm/lib/IR/DebugInfo.cpp llvm/tools/llvm-c-test/debuginfo.c View the diff from clang-format here.diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index f7d81636f4..06a6ac1bc7 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -1428,10 +1428,11 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
*
* @see llvm::DIBuilder::createLabel()
*/
-LLVMMetadataRef LLVMDIBuilderCreateLabel(
- LLVMDIBuilderRef Builder,
- LLVMMetadataRef Context, const char *Name, size_t NameLen,
- LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve);
+LLVMMetadataRef LLVMDIBuilderCreateLabel(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context,
+ const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo,
+ LLVMBool AlwaysPreserve);
/**
* Insert a new llvm.dbg.label intrinsic call
@@ -1443,9 +1444,10 @@ LLVMMetadataRef LLVMDIBuilderCreateLabel(
*
* @see llvm::DIBuilder::insertLabel()
*/
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMValueRef InsertBefore);
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMValueRef InsertBefore);
/**
* Insert a new llvm.dbg.label intrinsic call
@@ -1457,9 +1459,10 @@ LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
*
* @see llvm::DIBuilder::insertLabel()
*/
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd);
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMBasicBlockRef InsertAtEnd);
/**
* Obtain the enumerated type of a Metadata instance.
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index e20a0f0534..4d05009d2c 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1799,21 +1799,23 @@ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
}
-LLVMMetadataRef LLVMDIBuilderCreateLabel(
- LLVMDIBuilderRef Builder,
- LLVMMetadataRef Context, const char *Name, size_t NameLen,
- LLVMMetadataRef File, unsigned LineNo, LLVMBool AlwaysPreserve) {
+LLVMMetadataRef LLVMDIBuilderCreateLabel(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef Context,
+ const char *Name, size_t NameLen,
+ LLVMMetadataRef File, unsigned LineNo,
+ LLVMBool AlwaysPreserve) {
return wrap(unwrap(Builder)->createLabel(
- unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
- unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
+ unwrapDI<DIScope>(Context), StringRef(Name, NameLen),
+ unwrapDI<DIFile>(File), LineNo, AlwaysPreserve));
}
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMValueRef InsertBefore) {
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMValueRef InsertBefore) {
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
- unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
- unwrap<Instruction>(InsertBefore));
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap<Instruction>(InsertBefore));
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
@@ -1824,12 +1826,13 @@ LLVMDbgRecordRef LLVMDIBuilderInsertLabelBefore(
return wrap(cast<DbgRecord *>(DbgInst));
}
-LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(
- LLVMDIBuilderRef Builder, LLVMMetadataRef LabelInfo,
- LLVMMetadataRef Location, LLVMBasicBlockRef InsertAtEnd) {
+LLVMDbgRecordRef LLVMDIBuilderInsertLabelAtEnd(LLVMDIBuilderRef Builder,
+ LLVMMetadataRef LabelInfo,
+ LLVMMetadataRef Location,
+ LLVMBasicBlockRef InsertAtEnd) {
DbgInstPtr DbgInst = unwrap(Builder)->insertLabel(
- unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
- unwrap(InsertAtEnd));
+ unwrapDI<DILabel>(LabelInfo), unwrapDI<DILocation>(Location),
+ unwrap(InsertAtEnd));
// This assert will fail if the module is in the old debug info format.
// This function should only be called if the module is in the new
// debug info format.
diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c
index baf4ddfcc9..80cf61b604 100644
--- a/llvm/tools/llvm-c-test/debuginfo.c
+++ b/llvm/tools/llvm-c-test/debuginfo.c
@@ -163,10 +163,10 @@ int llvm_test_dibuilder(void) {
LLVMSetSubprogram(FooFunction, FunctionMetadata);
- LLVMMetadataRef FooLabel1 = LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
- "label1", 6, File, 42, false);
+ LLVMMetadataRef FooLabel1 = LLVMDIBuilderCreateLabel(
+ DIB, FunctionMetadata, "label1", 6, File, 42, false);
LLVMDIBuilderInsertLabelAtEnd(DIB, FooLabel1, FooParamLocation,
- FooEntryBlock);
+ FooEntryBlock);
LLVMMetadataRef FooLexicalBlock =
LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0);
@@ -226,16 +226,14 @@ int llvm_test_dibuilder(void) {
LLVMBuildBr(Builder, FooVarBlock);
// Build another br for the sake of testing labels.
- LLVMMetadataRef FooLabel2 = LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
- "label2", 6, File, 42, false);
+ LLVMMetadataRef FooLabel2 = LLVMDIBuilderCreateLabel(
+ DIB, FunctionMetadata, "label2", 6, File, 42, false);
LLVMDIBuilderInsertLabelBefore(DIB, FooLabel2, FooParamLocation,
- LLVMBuildBr(Builder, FooVarBlock));
+ LLVMBuildBr(Builder, FooVarBlock));
// label3 will be emitted, but label4 won't be emitted
// because label3 is AlwaysPreserve and label4 is not.
- LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
- "label3", 6, File, 42, true);
- LLVMDIBuilderCreateLabel(DIB, FunctionMetadata,
- "label4", 6, File, 42, false);
+ LLVMDIBuilderCreateLabel(DIB, FunctionMetadata, "label3", 6, File, 42, true);
+ LLVMDIBuilderCreateLabel(DIB, FunctionMetadata, "label4", 6, File, 42, false);
LLVMDIBuilderFinalize(DIB);
// Build `ret i64 0` in vars.
|
Addresses #112799