[PATCH] D126984: [clang] Add initial support for gcc's optimize function attribute
Stephen Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 6 16:14:22 PDT 2022
steplong added inline comments.
================
Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4841-4850
+ StringRef Level;
+ // Check if argument is prefixed with "-O" or "O"
+ if (Arg.str().rfind("-O", 0) == 0)
+ Level = Arg.substr(2);
+ else if (Arg.str().rfind("O", 0) == 0)
+ Level = Arg.substr(1);
+ else
----------------
aaron.ballman wrote:
> Then, in here, you can parse the `-O<whatever>` the user passed as a string, and convert it to an `OptimizeAttr::OptLevelKind` enumerator and store that in the semantic attribute.
>
> This allows you to map things like `-Og` to whatever -O level that actually represents, or do any other kind of mapping that works for you.
>
> One question we should probably figure out is whether we also want to support clang-cl optimization strings or not. e.g., `__attribute__((optimize("/O0")))` with a slash instead of a dash. Since we're already going to be doing parsing from here anyway, I feel like it might not be a bad idea to also support those. FWIW, here's the list from the user's manual:
> ```
> /O0 Disable optimization
> /O1 Optimize for size (same as /Og /Os /Oy /Ob2 /GF /Gy)
> /O2 Optimize for speed (same as /Og /Oi /Ot /Oy /Ob2 /GF /Gy)
> /Ob0 Disable function inlining
> /Ob1 Only inline functions which are (explicitly or implicitly) marked inline
> /Ob2 Inline functions as deemed beneficial by the compiler
> /Od Disable optimization
> /Og No effect
> /Oi- Disable use of builtin functions
> /Oi Enable use of builtin functions
> /Os Optimize for size
> /Ot Optimize for speed
> /Ox Deprecated (same as /Og /Oi /Ot /Oy /Ob2); use /O2 instead
> /Oy- Disable frame pointer omission (x86 only, default)
> /Oy Enable frame pointer omission (x86 only)
> /O<flags> Set multiple /O flags at once; e.g. '/O2y-' for '/O2 /Oy-'
> ```
> (Not all of these would be supported, like enable use of builtin functions, etc.) WDYT?
Hmm I don't think it's necessary to get pragma optimize to work, but it shouldn't be hard to add the parsing logic for some of these strings
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