[PATCH] D126984: [clang] Add initial support for gcc's optimize function attribute
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 13 12:06:34 PDT 2022
aaron.ballman added a comment.
In D126984#3578950 <https://reviews.llvm.org/D126984#3578950>, @steplong wrote:
>>> and even for the MSVC pragma `#pragma optimize("t", on)`, what are we supporting if the user compiles their code with `-O0`? because right now we won't optimize anything with `-O0`
>>
>> @steplong -- what are your thoughts on this?
>
> Hmm, I think I'm ok with ignoring the pragma when "-O0". In the case of "t", at the moment, we are just going to honor whatever is passed on the commandline. I think with what the patch looks like now, we'll be supporting the pragma optimize like:
>
> | Parameter | On | Off |
> | --------- | -------------------- | |
> | g | Deprecated | Deprecated |
> | s | Add OptimizeAttr::Os | Add Optnone (Not sure if this makes sense) |
> | t | Do nothing | Add Optnone |
> | y | Do nothing | Do nothing |
> |
I think that works for me.
================
Comment at: clang/docs/ReleaseNotes.rst:331-333
+- Added preliminary support for GCC's attribute ``optimize``, which allows
+ functions to be compiled with different optimization options than what was
+ specified on the command line.
----------------
And we can clarify in the release note that we're not intending to fully support this attribute.
================
Comment at: clang/include/clang/Basic/Attr.td:2267-2268
+ EnumArgument<"OptLevel", "OptLevelKind",
+ ["Ofast", "Og", "Oz", "Os", "O0", "O1", "O2", "O3", "O4"],
+ ["Ofast", "Og", "Oz", "Os", "O0", "O1", "O2", "O3", "O4"],
+ /*optional*/0, /*fake*/1>];
----------------
Assuming this also addresses @aeubanks 's concerns, I think we should remove O1 through O4 and maybe consider renaming the other enumerations to be less about the command line option and more about the effects. e.g., `Fast`, `MinSize`, `NoOpts` etc. We'll still do the mapping from O0 and whatnot to these values (within SemaDeclAttr.cpp) but this should hopefully clarify that the semantics we're after are not really pipeline semantics.
================
Comment at: clang/include/clang/Basic/AttrDocs.td:3462
+ let Content = [{
+The ``optimize`` attribute, when attached to a function, indicates that the
+function should be compiled with a different optimization level than specified
----------------
And we can add to the documentation that we don't intend to fully support the GCC semantics and further comment about ignoring O1 through O4, etc.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126984/new/
https://reviews.llvm.org/D126984
More information about the cfe-commits
mailing list