This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Construct option's prefixed name at compile-time
ClosedPublic

Authored by jansvoboda11 on Aug 3 2023, 1:24 PM.

Details

Summary

Some Clang command-line handling code could benefit from the option's prefixed name being a StringLiteral. This patch changes the llvm::opt TableGen backend to generate and emit that into the .inc file.

Depends on D157028.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Aug 3 2023, 1:24 PM
jansvoboda11 requested review of this revision.Aug 3 2023, 1:24 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptAug 3 2023, 1:24 PM

Rebase on top of D157028.

benlangmuir added inline comments.
llvm/include/llvm/Option/Option.h
103

This could use a doc comment to differentiate it from other string representations.

How does this compare with Arg::getSpelling? With Arg, IIUC the "spelling" is how it was actually written rather than a canonical form. That might be confusing if this one is canonical; so we should at least clearly document it or maybe put "canonical" in the API name?

Improve Option::getPrefixedName() instead of introducing new Option::getSpelling().

jansvoboda11 retitled this revision from [llvm] Construct option spelling at compile-time to [llvm] Construct option's prefixed name at compile-time.Aug 4 2023, 11:57 AM
jansvoboda11 edited the summary of this revision. (Show Details)
jansvoboda11 added inline comments.
llvm/include/llvm/Option/Option.h
103

You're right Arg::getSpelling() is the as-written prefix and name, while Option::getSpelling() was the canonical prefix and name. I noticed there's also Option::getPrefixedName() which used to return std::string. I decided to reuse that and return StringLiteral instead. Thanks!

This increases the size of Info (static data size and static relocations). In return, some dynamic relocations are saved. Is this a net win?

This increases the size of Info (static data size and static relocations). In return, some dynamic relocations are saved. Is this a net win?

If that's a concern, I can remove Info::Name and replace its usages with a function call that drops the prefix from prefixed name.

Remove OptTable::Info::Name.

This increases the size of Info (static data size and static relocations). In return, some dynamic relocations are saved. Is this a net win?

If that's a concern, I can remove Info::Name and replace its usages with a function call that drops the prefix from prefixed name.

Done.

jansvoboda11 marked an inline comment as done.Aug 4 2023, 12:58 PM

Rebase, remove unnecessary changes

MaskRay accepted this revision.Aug 9 2023, 9:21 AM

LG! LLVMOption has users in llvm/ clang/ lldb/ lld/ clang-tools-extra/ flang/. You'll need to check that all the affected users are migrated...

This revision is now accepted and ready to land.Aug 9 2023, 9:21 AM