[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
Fri Jun 10 12:30:57 PDT 2022


aaron.ballman added a comment.

In D126984#3574288 <https://reviews.llvm.org/D126984#3574288>, @xbolva00 wrote:

> [[gnu::optimize("O0")]] is okay but [[gnu::optimize("O3 <https://reviews.llvm.org/owners/package/3/>")]] is not gonna work without major changes. Not sure why we should deliver half-broken new attribute.

I don't see it as half-broken given that it's explicitly documented by GCC as "The optimize attribute should be used for debugging purposes only. It is not suitable in production code."

> Some strong motivation/use cases why somebody needs to compile some functions with -O2 and some with -O3?

This patch leaves O1 <https://reviews.llvm.org/owners/package/1/>-O4 as noops, and really only does anything with O0 and the letter-based ones, so I don't know that we need to do that exercise until we want to make them actually do something. Similarly, we don't allow any of the `-f` flags like GCC does.

I don't insist on keeping this attribute specifically, but I like the fact that it gives us *one* attribute that we can use as a basis for all these various other ways of spelling optimization hints (optnone, #pragma optimize, minsize, etc). I think I'd ultimately like to see all of those other attributes as alternate spellings of this one and they just map to the appropriate internal "level".

(I'm totally fine with us not supporting optimization hints that the backend would struggle with, this is more about how we model the notion of a per-function user-provided optimization hint without adding a new attribute every time.)


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