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

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

问题描述

我刚刚问了一个问题,关于编译器如何优化某些 C ++代码,我正在围绕SO有关如何验证编译器已执行某些优化的任何问题。我试图查看使用g ++( g ++ -c -g -O2 -Wa,-ahl = file.s file.c )生成的汇编列表,是在引擎盖下,但输出对我来说太神秘。人们使用什么技术来解决这个问题,并且有关于如何解释特定于GCC工具链的优化代码或文章的汇编列表的任何好的参考,谈论这个问题吗?

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的优化以一种称为 GIMPLE

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

使用 -fdump - * 系列选项,您可以询问GCC输出树的中间状态。

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

例如,将此输入到 gcc -c -fdump-tree-all -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天全站免登陆