Influencing function cloning/duplication/constant propagation in gcc

会有一股神秘感。 提交于 2019-12-07 06:40:18

问题


When running gcc with optimizations-on, it clones (duplicates) C functions when it considers that the function is in a hot path or there's constants propagating to the function arguments.

More specifically, this seems to be controlled by the fipa-cp-clone option.

Is there any way to influence this? For instance mark one parameter with some attribute, as a compile-time constant (like you can do in C++ with a template parameter) which will cause the function to be cloned?


回答1:


What matters is whether the function is called with a constant argument (either an actual constant expression, or something determined to be constant by the compiler via constant propagation). In this case, GCC will clone the function unless it determines doing so would be too costly or have too little benefit; I don't know a way to influence that metric. Be aware that constant propagation happens only within a single translation unit (source file) unless you're compiling the whole program at once or using link-time optimization, and I'm not sure whether cloning can still happen at that point or not.

My best guess, if cloning isn't happening when you expect that it should, is that GCC is never seeing a constant argument where the function is called. Even if you know it will be constant, the compiler might not be able to prove it is.



来源:https://stackoverflow.com/questions/15439890/influencing-function-cloning-duplication-constant-propagation-in-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!