how does clang control whether the unroll-loop pass work or not by default?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

how does clang control whether the unroll-loop pass work or not by default?

Fangrui Song via cfe-dev
Hi, there.

I want to figure out how the unroll-loop pass is controlled by clang. which option or struct in the source code tell the unroll-loop pass to work or not to work?
include/clang/Basic/CodeGenOptions.def
----------------------------------------------------------------------------------------
CODEGENOPT(UnrollLoops       , 1, 1) ///< Control whether loops are unrolled.
-----------------------------------------------------------------------------------------
I tried to modify the above option. The second "1" is "0" initially. I modified the original "0" to "1". But clang would do the unroll-loop pass whether it is "0" or "1".
I wonder how clang instructs the unroll-loop pass to work or not to work?

Thanks,
Jerry



 


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: how does clang control whether the unroll-loop pass work or not by default?

Fangrui Song via cfe-dev
For the legacy pass manager (the default), the code can be found in
lib/Transforms/IPO/PassManagerBuilder.cpp, function
PassManagerBuilder::populateModulePassManager

Michael

Am Do., 26. März 2020 um 08:03 Uhr schrieb 林政宗 via cfe-dev
<[hidden email]>:

>
> Hi, there.
>
> I want to figure out how the unroll-loop pass is controlled by clang. which option or struct in the source code tell the unroll-loop pass to work or not to work?
> include/clang/Basic/CodeGenOptions.def
> ----------------------------------------------------------------------------------------
> CODEGENOPT(UnrollLoops       , 1, 1) ///< Control whether loops are unrolled.
> -----------------------------------------------------------------------------------------
> I tried to modify the above option. The second "1" is "0" initially. I modified the original "0" to "1". But clang would do the unroll-loop pass whether it is "0" or "1".
> I wonder how clang instructs the unroll-loop pass to work or not to work?
>
> Thanks,
> Jerry
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: how does clang control whether the unroll-loop pass work or not by default?

Fangrui Song via cfe-dev
Hi, 
Thanks, I think the option in PassManagerBuilder.cpp controls the loop-unroll pass in llvm. Is there a loop-unroll pass or loop-unroll function in clang that will unroll loops in frontend and the generated llvm IR by clang is the unrolled version? and if there is one, how does clang control it? Thanks in advance. Best regards, Jerry







At 2020-03-26 22:02:41, "Michael Kruse" <[hidden email]> wrote: >For the legacy pass manager (the default), the code can be found in >lib/Transforms/IPO/PassManagerBuilder.cpp, function >PassManagerBuilder::populateModulePassManager > >Michael > >Am Do., 26. März 2020 um 08:03 Uhr schrieb 林政宗 via cfe-dev ><[hidden email]>: >> >> Hi, there. >> >> I want to figure out how the unroll-loop pass is controlled by clang. which option or struct in the source code tell the unroll-loop pass to work or not to work? >> include/clang/Basic/CodeGenOptions.def >> ---------------------------------------------------------------------------------------- >> CODEGENOPT(UnrollLoops , 1, 1) ///< Control whether loops are unrolled. >> ----------------------------------------------------------------------------------------- >> I tried to modify the above option. The second "1" is "0" initially. I modified the original "0" to "1". But clang would do the unroll-loop pass whether it is "0" or "1". >> I wonder how clang instructs the unroll-loop pass to work or not to work? >> >> Thanks, >> Jerry >> >> >> >> >> >> _______________________________________________ >> cfe-dev mailing list >> [hidden email] >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: how does clang control whether the unroll-loop pass work or not by default?

Fangrui Song via cfe-dev
Am Do., 26. März 2020 um 21:44 Uhr schrieb 林政宗 via cfe-dev
<[hidden email]>:
> Thanks, I think the option in PassManagerBuilder.cpp controls the loop-unroll pass in llvm. Is there a loop-unroll pass or loop-unroll function in clang that will unroll loops in frontend and the generated llvm IR by clang is the unrolled version? and if there is one, how does clang control it? Thanks in advance. Best regards, Jerry

There is no such "pre-unrolling" in clang. That would be redundant.

clang's -funroll-loops -fno-unroll-loops is translated to the value of
PassManagerBuilder::DisableUnrollLoops

Loop hints such as `#pragma unroll` is translated to metadata:
https://llvm.org/docs/LangRef.html#llvm-loop-unroll

Michael
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

and how does clang control inliner?

Fangrui Song via cfe-dev
Hi,

besides unroll, I wonder how clang controls inliner. The inliner computes the Cost and Threshold and makes decision whether to inline.
I modified the OptimizeSize into 100 in CodeGenOptions.def:
-----------------------------------------------------------------------------------------
VALUE_CODEGENOPT(OptimizeSize, 2, 100) ///< If -Os (==1) or -Oz (==2) is specified.
-----------------------------------------------------------------------------------------
the original value is 0. But I found that it doesn't affect the threshold. And even the value of CodeGenOpts.OptimizeSize (BackendUtil.cpp:575) is 0.
How could I control the initial value of threshold of inliner ?  And how could I control the value of CodeGenOpts.OptimizeSize . 
Is it possible to control the initial threshold value by passing arguments or options to clang?

Thanks!
Jerry







At 2020-03-28 17:39:50, "Michael Kruse" <[hidden email]> wrote: >Am Do., 26. März 2020 um 21:44 Uhr schrieb 林政宗 via cfe-dev ><[hidden email]>: >> Thanks, I think the option in PassManagerBuilder.cpp controls the loop-unroll pass in llvm. Is there a loop-unroll pass or loop-unroll function in clang that will unroll loops in frontend and the generated llvm IR by clang is the unrolled version? and if there is one, how does clang control it? Thanks in advance. Best regards, Jerry > >There is no such "pre-unrolling" in clang. That would be redundant. > >clang's -funroll-loops -fno-unroll-loops is translated to the value of >PassManagerBuilder::DisableUnrollLoops > >Loop hints such as `#pragma unroll` is translated to metadata: >https://llvm.org/docs/LangRef.html#llvm-loop-unroll > >Michael


 


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev