[PATCH] Implement ‘optnone’ attribute semantics

Robinson, Paul Paul_Robinson at playstation.sony.com
Wed Nov 13 16:09:36 PST 2013

I am energized by positive discussions of the 'optnone' attribute
during the dev meeting last week, so here we go.

Some time ago Andrea Di Biagio committed a patch to define an 'optnone'
attribute in the LLVM IR; he has since passed the torch to me on this
one, so I'm attaching 3 patches to implement the semantics we want.

While the patches all address semantics of 'optnone' I should point
out that (I'm pretty sure) they are independent of each other and
don't have to be reviewed sequentially, or anything like that.

Patch #1 tweaks the description of 'optnone' to require 'noinline',
and updates the verifier and two existing tests accordingly.  The
requirement means an 'optnone' function won't be inlined into any
caller.  The patch also makes the inliner not inline any calls made by
an 'optnone' function, with one exception: an 'always_inline' function
will be inlined into an 'optnone' function.

Patch #2 deals with skipping optimization passes for 'optnone'
functions.  This is probably the piece that has caused the most angst.
We tried to minimize the fiddling with the dreaded Pass Manager, and
made as straightforward and simple a change as we could come up with
that got the job done.  That is:

We introduce a 'bool mustAlwaysRun()' method on passes, and say that
an 'optnone' function doesn't run any function IR, loop, or basic
block pass, unless that pass is marked 'mustAlwaysRun.'  The default
for 'mustAlwaysRun' is true, so we explicitly turn it off for all the
Transform passes that we do not want to run on an 'optnone' function.
This is kind of tedious but is a mostly mechanical change.

Note that module-level passes will still consider 'optnone' functions.

Patch #3 deals with the codegen stuff.  Basically, an 'optnone'
function will be treated as if it were compiled at -O0; this is a
little easier to accomplish than it is for IR-level passes.

All 3 patches have relevant tests to go with them.

I'll get the Clang piece of this ready to go pretty soon, so that
people writing C++ can use it, and not just people writing IR. :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1-optnone-Inline.patch
Type: application/octet-stream
Size: 5342 bytes
Desc: 1-optnone-Inline.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131114/036dbc2b/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2-optnone-Passes.patch
Type: application/octet-stream
Size: 22462 bytes
Desc: 2-optnone-Passes.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131114/036dbc2b/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3-optnone-CodeGen.patch
Type: application/octet-stream
Size: 7459 bytes
Desc: 3-optnone-CodeGen.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131114/036dbc2b/attachment-0002.obj>

More information about the llvm-commits mailing list