This is an archive of the discontinued LLVM Phabricator instance.

[C API]: Add getters for inline assembly template string, constraints, and flags
ClosedPublic

Authored by Benjins on Jun 16 2023, 4:55 PM.

Details

Summary

This change adds support for accessing information about inline assembly calls through the C API, enough to be able to round-trip the information. This partially addresses https://github.com/llvm/llvm-project/issues/42037 which points out gaps in the C API

Getters for each of the parameters to LLVMGetInlineAsm/InlineAsm::get have been added, such that the C API now has enough surface to clone inline assembly calls

NB: LLVMGetInlineAsm has been changed to accept a const char* for its assembly and constraint strings. This isn't strictly needed, but does make using the API a bit easier to use since the results of LLVMGetInlineAsmAsmString/LLVMGetInlineAsmConstraintString can be passed to LLVMGetInlineAsm without having to make an explicit mutable copy. As far as I understand, changing this from char* to const char* shouldn't break existing users, but if it's something we want to avoid I can leave it

This API currently only returns the raw constraint string via LLVMGetInlineAsmConstraintString: it may be prudent to also expose the parsed constraints via InlineAsm::ParseConstraints, but I wasn't sure how that should look like. This at least exposes the information for clients

This is my first patch sent to LLVM, so if there's anything I've missed please let me know

Diff Detail

Event Timeline

Benjins created this revision.Jun 16 2023, 4:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 4:55 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Benjins requested review of this revision.Jun 16 2023, 4:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 4:55 PM

Apologies for bumping this: not sure who I should assign it to for review, since I couldn't find many recent C API diffs. Just want to make sure it doesn't get lost

bogner accepted this revision.Aug 15 2023, 4:58 PM

Apologies for bumping this: not sure who I should assign it to for review, since I couldn't find many recent C API diffs. Just want to make sure it doesn't get lost

No need to apologize for bumping the thread - it's perfectly reasonable to ping a review every couple of weeks if nobody's responding. Sorry that I didn't get to this sooner!

I'm not necessarily the best reviewer for the C API, but this all looks fairly obviously correct. Do you need me to commit it for you?

This revision is now accepted and ready to land.Aug 15 2023, 4:58 PM

@bogner Yes, if you could commit it for me that'd be great. And thank you for reviewing this! 🙏
And I guess as a side-note: it was a bit unclear to me who would be best for reviewing C-API changes, looking at previous reviews in that area and CODE_OWNERS. I don't have any follow-up changes planned, but if there's a good person to mention on C-API changes that'd be good to know

it was a bit unclear to me who would be best for reviewing C-API changes, looking at previous reviews in that area and CODE_OWNERS. I don't have any follow-up changes planned, but if there's a good person to mention on C-API changes that'd be good to know

Unfortunately the C API doesn't currently seem to have a particular owner, per se. It's an area that's very much driven by need at this point.