[PATCH] D125723: [MSVC] Add support for MSVC pragma optimize
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 31 11:53:17 PDT 2022
aaron.ballman added inline comments.
================
Comment at: clang/lib/Sema/SemaAttr.cpp:1207-1213
+ FD->addAttr(FramePointerAttr::CreateImplicit(Context, Kind));
+}
+
+void Sema::AddOptsize(FunctionDecl *FD, SourceLocation Loc) {
+ FD->dropAttr<OptimizeSizeAttr>();
+ OptimizeSizeAttr::Kind Kind = OptimizeSizeAttr::On;
+ FD->addAttr(OptimizeSizeAttr::CreateImplicit(Context, Kind));
----------------
steplong wrote:
> aaron.ballman wrote:
> > Rather than creating two new, implicit attributes for this, why not add support for `__attribute__((optimize(...)))` from GCC and reuse that one?
> >
> > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
> >
> > It seems like that serves the same function as these implicit attributes, but then users would get two features for the price of one.
> Hmm that makes sense. So, `pragma optimize(on, "s")` would be equivalent to `__attribute__((optimize("-Os"))`. Could you give me a brief description of what I would have to do to implement the attribute? I'm new to this
> Hmm that makes sense. So, pragma optimize(on, "s") would be equivalent to __attribute__((optimize("-Os")).
Yup, effectively! And in terms of the AST, your pragma can implicitly create an `OptimizeAttr` with the appropriate arguments; then everything works off the same machinery.
> Could you give me a brief description of what I would have to do to implement the attribute? I'm new to this
Absolutely! https://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute has most of the information you need. I'm happy to give you more information if you'd like it, though.
================
Comment at: clang/lib/Sema/SemaAttr.cpp:1224
+ FD->dropAttr<OptimizeNoneAttr>();
+ FD->addAttr(NeverOptimizeNoneAttr::CreateImplicit(Context));
+}
----------------
steplong wrote:
> aaron.ballman wrote:
> > Can you explain why this is needed?
> I added this attr, so we can remove the attr optnone even if -O0 was passed on the cmdline
I think if you add an `OptimizeAttr`, that could be used to carry this information instead of using a dedicated attribute for just the "never optnone" part.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125723/new/
https://reviews.llvm.org/D125723
More information about the cfe-commits
mailing list