通过分析汇编清单验证在gcc / g ++的编译器优化 [英] Verifying compiler optimizations in gcc/g++ by analyzing assembly listings

查看:147
本文介绍了通过分析汇编清单验证在gcc / g ++的编译器优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚才问有关编译器如何优化某些<一个问题href=\"http://stackoverflow.com/questions/2016437/does-calling-the-constructor-of-an-empty-class-actually-use-any-memory\">C++ code ,我是如此四处寻找有关如何验证编译器执行某些优化的任何问题。我想看看相克生成的汇编上市++( G ++ -c -g -O2 -Wa,-ahl = file.s file.c中)以可能看到什么是引擎盖下怎么回事,但输出是太神秘了我。人们使用哪些技术来解决这个问题,以及是否有任何好的参考如何跨preT具体到GCC工具链是谈论这个问题的最优化code或文章的汇编清单?

I just asked a question related to how the compiler optimizes certain C++ code, and I was looking around SO for any questions about how to verify that the compiler has performed certain optimizations. I was trying to look at the assembly listing generated with g++ (g++ -c -g -O2 -Wa,-ahl=file.s file.c) to possibly see what is going on under the hood, but the output is too cryptic to me. What techniques do people use to tackle this problem, and are there any good references on how to interpret the assembly listings of optimized code or articles specific to the GCC toolchain that talk about this problem?

推荐答案

GCC的优化过程在您code在一个叫做的GIMPLE

GCC's optimization passes work on an intermediary representation of your code in a format called GIMPLE.

使用<$c$c>-fdump-*家庭选项,你可以问GCC树的输出中介状态。

Using the -fdump-* family of options, you can ask GCC to output intermediary states of the tree.

例如,养活这对 GCC -c -fdump树,所有-O3

unsigned fib(unsigned n) {
    if (n < 2) return n;
    return fib(n - 2) + fib(n - 1);
}

和看着它逐渐从简单的指数算法转换成一个复杂的多项式算法。 (真的吗?)

and watch as it gradually transforms from simple exponential algorithm into a complex polynomial algorithm. (Really!)

这篇关于通过分析汇编清单验证在gcc / g ++的编译器优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆