[llvm-dev] Question about GlobalOpt
Sanjin Sijaric via llvm-dev
llvm-dev at lists.llvm.org
Mon Mar 21 15:57:24 PDT 2016
Hi,
GlobalOpt may not consider demoting globals to locals in the "main" function
when C is used. It used to consider "main" specifically prior to commit
r253168 , for both C and C++. Since r253168, the check for the norecurse
attribute may prevent "main" from being considered. This happens because
the Function Attributes pass will not add the norecurse attribute to
functions that have calls to library functions that aren't themselves marked
with the norecurse attribute, such as putchar. Even a call to
llvm.lifetime.start, for example, will prevent a function from being
considered as non-recursive as llvm.lifetime.start isn't marked with the
"norecurse" attribute.
We have a C workload that benefits from this demotion with LTO, as some hot
functions get inlined into main.
The comment in tools/clang/lib/CodeGen/CodeGenFunctions.cpp explains the
reason for marking "main" with the norecurse attribute in C++:
// If we're in C++ mode and the function name is "main", it is guaranteed
// to be norecurse by the standard (3.6.1.3 "The function main shall not be
// used within a program").
No such restriction exists in the C standard, as far as I can tell.
Is there anything that can be done to alleviate this restriction in C? Can
we make the Function Attributes pass more aggressive, for example? Or mark
certain library functions as "norecurse", although I don't see how this can
be guaranteed.
Thanks,
Sanjin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160321/68c69055/attachment.html>
More information about the llvm-dev
mailing list