-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[LLVM-C] Add Bindings for eraseNamedMetadata #82549
base: main
Are you sure you want to change the base?
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 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 If you have received no comments on your PR for a week, you can request a review 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-llvm-ir Author: nezu (dumbasPL) ChangesThere wasn't any way to remove named metadata from a module. This adds the LLVMEraseNamedMetadata binding and a test for it Full diff: https://github.com/llvm/llvm-project/pull/82549.diff 6 Files Affected:
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 09746bdaf0c94e..a1f0410846e156 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -1037,6 +1037,13 @@ LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
const char *Name,
size_t NameLen);
+/**
+ * Remove the given NamedMDNode from this module and delete it.
+ *
+ * @see llvm::Module::eraseNamedMetadata()
+ */
+void LLVMEraseNamedMetadata(LLVMModuleRef M, LLVMNamedMDNodeRef NMD);
+
/**
* Retrieve the name of a NamedMDNode.
*
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index d6d159ab8b9e83..fd83c3cc210b53 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1315,6 +1315,11 @@ LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
return wrap(unwrap(M)->getOrInsertNamedMetadata({Name, NameLen}));
}
+void LLVMEraseNamedMetadata(LLVMModuleRef M, LLVMNamedMDNodeRef NMD) {
+ NamedMDNode *NamedNode = unwrap(NMD);
+ unwrap(M)->eraseNamedMetadata(NamedNode);
+}
+
const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NMD, size_t *NameLen) {
NamedMDNode *NamedNode = unwrap(NMD);
*NameLen = NamedNode->getName().size();
diff --git a/llvm/test/Bindings/llvm-c/erase_named_metadata.ll b/llvm/test/Bindings/llvm-c/erase_named_metadata.ll
new file mode 100644
index 00000000000000..e517c48441a8d6
--- /dev/null
+++ b/llvm/test/Bindings/llvm-c/erase_named_metadata.ll
@@ -0,0 +1 @@
+; RUN: llvm-c-test --erase-named-metadata < /dev/null
\ No newline at end of file
diff --git a/llvm/tools/llvm-c-test/llvm-c-test.h b/llvm/tools/llvm-c-test/llvm-c-test.h
index 00566660257e07..daef463285cc89 100644
--- a/llvm/tools/llvm-c-test/llvm-c-test.h
+++ b/llvm/tools/llvm-c-test/llvm-c-test.h
@@ -43,6 +43,7 @@ int llvm_di_type_get_name(void);
// metadata.c
int llvm_add_named_metadata_operand(void);
int llvm_set_metadata(void);
+int llvm_erase_named_metadata(void);
int llvm_replace_md_operand(void);
int llvm_is_a_value_as_metadata(void);
diff --git a/llvm/tools/llvm-c-test/main.c b/llvm/tools/llvm-c-test/main.c
index badbe4b13b6ba5..e1a7c85d40bb66 100644
--- a/llvm/tools/llvm-c-test/main.c
+++ b/llvm/tools/llvm-c-test/main.c
@@ -44,6 +44,8 @@ static void print_usage(void) {
fprintf(stderr, " Read lines of triple, hex ascii machine code from stdin "
"- print disassembly\n\n");
fprintf(stderr, " * --calc\n");
+ fprintf(stderr, " * --erase-named-metadata\n"
+ " Run test for erasing named metadata\n");
fprintf(
stderr,
" Read lines of name, rpn from stdin - print generated module\n\n");
@@ -93,6 +95,8 @@ int main(int argc, char **argv) {
return llvm_add_named_metadata_operand();
} else if (argc == 2 && !strcmp(argv[1], "--set-metadata")) {
return llvm_set_metadata();
+ } else if (argc == 2 && !strcmp(argv[1], "--erase-named-metadata")) {
+ return llvm_erase_named_metadata();
} else if (argc == 2 && !strcmp(argv[1], "--get-di-tag")) {
return llvm_get_di_tag();
} else if (argc == 2 && !strcmp(argv[1], "--di-type-get-name")) {
diff --git a/llvm/tools/llvm-c-test/metadata.c b/llvm/tools/llvm-c-test/metadata.c
index 4fe8c00c57481b..72db9af104675b 100644
--- a/llvm/tools/llvm-c-test/metadata.c
+++ b/llvm/tools/llvm-c-test/metadata.c
@@ -47,6 +47,21 @@ int llvm_set_metadata(void) {
return 0;
}
+int llvm_erase_named_metadata(void) {
+ LLVMModuleRef M = LLVMModuleCreateWithName("Mod");
+
+ const char Name[] = "foo";
+ LLVMNamedMDNodeRef MD = LLVMGetOrInsertNamedMetadata(M, Name, strlen(Name));
+ assert(LLVMGetFirstNamedMetadata(M));
+
+ LLVMEraseNamedMetadata(M, MD);
+ assert(!LLVMGetFirstNamedMetadata(M));
+
+ LLVMDisposeModule(M);
+
+ return 0;
+}
+
int llvm_replace_md_operand(void) {
LLVMModuleRef M = LLVMModuleCreateWithName("Mod");
LLVMContextRef Context = LLVMGetModuleContext(M);
|
|
333faf0
to
276bb04
Compare
There wasn't any way to remove named metadata from a module. This adds the LLVMEraseNamedMetadata binding and a test for it
276bb04
to
ceed721
Compare
ok, the email situation seems to be sorted out, didn't know it was required |
There wasn't any way to remove named metadata from a module. This adds the LLVMEraseNamedMetadata binding and a test for it