Page MenuHomePhabricator

[llvm-c] add LLVMReplaceMDNodeOperandWith
AcceptedPublic

Authored by davibe on Oct 24 2022, 1:37 PM.

Details

Summary

Hello!

I'm working on a tool that visits debug info and massages it using the llvm-c API. I noticed that LLVMGetOperand special cases MDNodes so I can get their operands, but I can't replace them. This patch adds LLVMReplaceMDNodeOperandWith which boils down to MDNode::replaceOperandWith.

The name was chosen for consistency with LLVMGetMDNodeOperands and LLVMGetMDNodeNumOperands.

Diff Detail

Event Timeline

davibe created this revision.Oct 24 2022, 1:37 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
davibe requested review of this revision.Oct 24 2022, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2022, 1:37 PM

I can see that this is useful. Can you add a unit test for it?

Seems fine to me, but I don't work on the C API so I can't advise on it.

davibe updated this revision to Diff 471422.EditedOct 28 2022, 12:30 AM

I added the tests as requested.

I also added LLVMIsAValueAsMetadata, since LLVMIsAMDNode is a bit of a lier and returns true for ValueAsMetadata values as well, so the way to know if something is truly a mdnode is to call LLVMIsAMDNode(v) && !LLVMIsAValueAsMetadata(v)

davibe updated this revision to Diff 471542.Oct 28 2022, 7:10 AM
  • Fixed formatting
  • Added .ll files to trigger tests
aprantl accepted this revision.Nov 4 2022, 1:32 PM
aprantl added inline comments.
llvm/test/Bindings/llvm-c/replace_md_operand.ll
1

This seems to be an incredibly complicated way to invoke the function, but it's consistent with the existing tests...

This revision is now accepted and ready to land.Nov 4 2022, 1:32 PM
This comment was removed by davibe.
llvm/test/Bindings/llvm-c/replace_md_operand.ll
1

Agree. I may propose another "pr"

I don't have commit access, could someone please commit this for me?