(original) (raw)

Thanks Johannes. That makes this makes it more understandable to me. What can I do for optimization that doesn’t have flag? How should I approach disabling them.

On Sat, Mar 27, 2021 at 22:10 Johannes Doerfert <johannesdoerfert@gmail.com> wrote:
Hi Navid,

comments inlined.

On 3/27/21 9:24 PM, Navid Rahimi via llvm-dev wrote:
\> Hi everyone,
\>
\> tl;dr: I want to control which optimization and transformation can and will
\> run on my code. Does Clang/LLVM permit such an approach?

There is no unified approach to this as far as I know. The closest
I'm aware of was some research prototype:
https://compilers.cs.uni-saarland.de/projects/noise/


\>
\> I am doing this with GCC. But at first, it seems for some reason GCC does
\> not allow optimizations to run unless I am passing -Ox flag (x>=1). The
\> approach I thought would work is using -O3 and disabling all the
\> optimizations one by one with -fno-XXX, then passing each optimization I
\> want with -fXXX. Even after doing that it seems GCC does take the flags
\> seriously. Sometimes it might consider the -fXXX flags, but sometimes it
\> totally ignores.
\>
\> I was investigating this issue more recently due to a project I am involved
\> in. I realized that there are two sets of optimizations and transformation
\> can happen in Clang/LLVM. Clang can do a few optimizations itself on AST
\> and then LLVM will run its own optimizations. Please correct me if I am
\> wrong.

I'm not aware of optimizations/transformation we do on the AST,
except the things that "have to" happen on that level.


\>
\> Here is a list of few questions I am trying to find an answer for:
\> 1) I am looking for a list of optimizations that Clang might do. Where can
\> I find them?
I doubt there are "optimzations" to speak of, constant propagation
can happen though.


\> 2) I am looking for a list of optimizations that LLVM might do. Where can I
\> find them?
Most passes that exist in LLVM are listed in
llvm/lib/Passes/PassRegistry.def

There are (outdated) lists online as well.


\> 3) Is there any way to disable/enable specific Clang optimization?

Most, if not all, are mandatory.


\> 4) Is there any way to disable/enable specific LLVM optimization?

Some, not all, have command line flags to disable them, I would do:
opt -help-hidden | grep disable
opt -help-hidden | grep enable

if I needed a list.

\> 5) Would LLVM/Clang respect specific optimization flags?

I don't think you can build your own optimization pipelines via clang
but you can emit IR and do it with opt.


\>
\> I appreciate immensely any help regarding these questions.

Hope this helps, others might have more information.

\~ Johannes


\>
\> Best wishes,
\> Navid.
\>
\>
\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
\> LLVM Developers mailing list
\> llvm-dev@lists.llvm.org
\> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
--
Best wishes,
Navid.