This is an archive of the discontinued LLVM Phabricator instance.

[ForceFunctionAttrs] Make options additionally work over entire module
ClosedPublic

Authored by aidengrossman on Aug 24 2023, 10:36 PM.

Details

Summary

This patch makes the -force-attribute and -force-remove-attribute flags in the forceattrs pass additionally work over all the functions in a module rather than on specific functions. I often find myself dealing with bitcode from projects with arbitrary build systems that have applied the optnone attribute for various reasons and having the ability to do this in opt would be quite convenient. It's possible to remove the attribute by disassembling to textual IR, running sed, and then running opt over the result, but this option makes things just a bit easier.

Diff Detail

Event Timeline

aidengrossman created this revision.Aug 24 2023, 10:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 10:36 PM
aidengrossman requested review of this revision.Aug 24 2023, 10:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 10:36 PM
aidengrossman added a subscriber: jdoerfert.

@jdoerfert also suggested doing this in an IPO pass (like FunctionAttrs) but it seemed simple enough to implement this way. I couldn't think of any benefit of doing it within an IPO pass, but definitely could be missing something. Also wondering if there are reasons for not doing this as I thought there would've been something like this already.

It seems like -force-remove-attribute should be able to do this, but apparently it doesn't allow removing an attribute from all functions currently, only explicitly named ones. Maybe we should extend that?

It seems like -force-remove-attribute should be able to do this, but apparently it doesn't allow removing an attribute from all functions currently, only explicitly named ones. Maybe we should extend that?

^ seems reasonable and more generic. You often want to remove noinline as well, so there is the use case already

Switch to modifying ForceFunctionAttrs rather than adding an opt option.

aidengrossman retitled this revision from [opt] Add option to strip optnone attribute to [ForceFunctionAttrs] Make options additionally work over entire module.Aug 25 2023, 1:20 PM
aidengrossman edited the summary of this revision. (Show Details)
nikic accepted this revision.Aug 25 2023, 1:28 PM

LGTM

This revision is now accepted and ready to land.Aug 25 2023, 1:28 PM
This revision was landed with ongoing or failed builds.Aug 25 2023, 2:06 PM
This revision was automatically updated to reflect the committed changes.