[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
Fri Jun 10 11:14:05 PDT 2022


steplong added a comment.

In D126984#3574077 <https://reviews.llvm.org/D126984#3574077>, @aeubanks wrote:

> In D126984#3574046 <https://reviews.llvm.org/D126984#3574046>, @aaron.ballman wrote:
>
>> In D126984#3571573 <https://reviews.llvm.org/D126984#3571573>, @aeubanks wrote:
>>
>>> IIRC in the past there was a strong preference to not have the pass manager support this sort of thing
>>> if you want to support this, there should be an RFC for how the optimization part of this will work as it may require invasive changes to the LLVM pass manager
>>>
>>> (if this is purely a clang frontend thing then ignore me)
>>
>> Hmm, does the pass manager have to support anything here? The only Clang codegen changes are for emitting IR attributes that we already emitted based on command line flags/other attributes, so I had the impression this would not be invasive for the backend at all.
>
> if we're allowing individual functions to specify that they want the `-O1` pipeline when everything else in the module should be compiled with `-O2`, that's a huge change in the pass manager. but perhaps I'm misunderstanding the point of this patch

That makes sense. The MSVC pragma allows 4 options, "stgy":

| Parameter | On                                                                                                          | Off                                                                                    |
| --------- | ----------------------------------------------------------------------------------------------------------- |                                                                                        |
| g         | Deprecated                                                                                                  | Deprecated                                                                             |
| s         | Add MinSize                                                                                                 | Remove MinSize (I think this would be difficult to do if -Os is passed on the cmdline) |
| t         | Add -O2 (We can't support -O2 with this attribute so ignore)                                                | Add Optnone                                                                            |
| y         | Add frame-pointers (We can't support -f arguments with the attribute in this patch so we are ignoring this) | No frame-pointers (Same thing as on)                                                   |
|

For our use case, I think we only really see `#pragma optimize("", off)` and `#pragma optimize("", on)`, so I'm not opposed to abandoning this patch and just supporting the common use case for now. I think `#pragma optimize("", on)` would just mean do nothing and apply whatever is on the command line and `#pragma optimize("", off)` would mean add optnone to the functions below it


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