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

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?

For the legacy pass manager (the default), the code can be found in
lib/Transforms/IPO/PassManagerBuilder.cpp, function


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

Loop hints such as `#pragma unroll` is translated to metadata:



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: