C++ :编译器以多少种方式优化我们的代码?
。
我想知道编译器可以/确实优化用 C++ 编写的代码的所有可能方法(或至少是流行的方法)?我还想知道优化是如何完成的(在每种情况下)!
到目前为止,我知道两个优化,即。空基优化 (EBO) 和返回值优化 (RVO)。还有什么?我听说过“const”优化、“未使用的变量”优化。这些是什么?
。
.
I would like to know all the possible ways (or atleast the popular ones) in which compilers can/do optimize away our code written in C++? I also would like to know how exactly the optimization is done (in each case)!
So far, I'm aware of two optimizations, viz. Empty Base Optimization (EBO) and Return Value Optimization (RVO). What else are there? I've heard of "const" optimization,"unused variable" optimization. What are they?
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所有可能的方式?你肯定是在开玩笑。为此,请回顾多年的编译器研究和实践。
有关具体示例,请在此处查找每个选项: http://gcc.gnu .org/onlinedocs/gcc/Optimize-Options.html
All possible ways? Surely you're joking. For that, look through years of compiler research and practice.
For concrete examples, look up each of the options here: http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
来自标准文档,第 1.9 节,
因此,实际上符合标准的编译器可以执行任何类型的优化,只要它产生所需的结果即可。
From Standard docs., Section 1.9,
So actually the standard compliant compiler can perform any kind of optimizations as long as it produces the desired result.
范围之广令人难以置信,因为有很多优化,而且编译器编写者总是想出更多。它们有很多,一些针对运行时间进行优化,另一些针对二进制大小进行优化。许多也不是专门针对 C++ 的,通用编译器优化技术是为许多不同语言的许多编译器/解释器实现的。
只是少数:
更多信息:
Incredibly broad, because there are many optimizations and compiler writers are always thinking up more. There are tons of them, some optimizing for run time, others optimizing for binary size. Many aren't specifically C++ either, the general compiler optimization techniques are implemented for many compilers/interpreters for many different languages.
Just a handful:
More info: