This is an archive of the discontinued LLVM Phabricator instance.

[FunctionAttrs] Provide a mechanism for adding function attributes from the command line
ClosedPublic

Authored by jmolloy on Nov 18 2015, 6:57 AM.

Details

Summary

I hope this won't be too controversial.

This patch provides a way to force a function to have certain attributes from the command line. This can be useful when debugging or doing workload exploration, where manually editing IR is tedious or not possible (due to build systems etc).

The syntax is -force-attribute=function_name:attribute_name

For example, a function can be force-inlined using -force-attribute myfunc:alwaysinline

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy updated this revision to Diff 40503.Nov 18 2015, 6:57 AM
jmolloy retitled this revision from to [FunctionAttrs] Provide a mechanism for adding function attributes from the command line.
jmolloy updated this object.
jmolloy added reviewers: dexonsmith, mehdi_amini.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.

Hi James, this LGTM.
One nit inline. It would be nice if you could use a StringRef in in cl::list, but that doesn't seem possible.

lib/Transforms/IPO/FunctionAttrs.cpp
1894

Think you'll want a bit of extra checking here. What if I pass -force-attribute foo: by accident? Will get a segfault.

This is awesome!

lib/Transforms/IPO/FunctionAttrs.cpp
1899

Maybe add the below before the if (!F->hasFnAtt..)

if (Kind == Attribute::None) {

DEBUG(dbgs() << "ForcedAttribute: " << KV.second << " unknown or not handled.\n";
continue;

}

I believe this will also prevent Changed from being set to true with unknown/unhandled attributes.

1904

The default case will return Attribute::Node, so is this even reachable?

Think you'll want a bit of extra checking here. What if I pass -force-attribute foo: by accident? Will get a segfault.

My mistake, that's not what will happen. Please ignore.

jmolloy updated this revision to Diff 40509.Nov 18 2015, 7:28 AM

Hi,

Thanks for the feedback. Chad, this addresses your comments.

Cheers,

James

Will this command line option be useful for llc or other tools too? Also, an option to remove the attributes from a function might be useful too.

mcrosier accepted this revision.Nov 18 2015, 11:39 AM
mcrosier added a reviewer: mcrosier.

LGTM, with a small nit.

lib/Transforms/IPO/FunctionAttrs.cpp
61

given->specified

This revision is now accepted and ready to land.Nov 18 2015, 11:39 AM