[GCC学习]get the optimized function call graph
2009-05-20 23:59
267 查看
当GCC以优化方式编译代码的时候,它会执行Dead Code Elimiation(DCE), 就是把那些源代码中定义但是却从未调用到的函数从中间目标文件中去掉.(.o文件)
例如下面这段代码:
#include <stdio.h>
static void test() {
printf ("this code is never called.");
}
int main() {
printf("this is main function.");
return 0;
}
这里我们定义了一个static函数和一个main函数.按照C语言的约定,static 函数是只在当前模块可见, 非static函数则可被其它模块所包含.
然后我们通过检查使用和不使用DCE时,GCC的汇编输出来观察DCE的作用.
不使用DCE:
gcc -S -fno-builtin -fdump-ipa-cgraph test.c -o test.S
这里生成汇编结果说明了DCE的过程是在编译阶段已经完成, 命令中
-fdump-ipa-cgraph, 这是个调试输出选项,会生成一个.cgraph文件,我们后面会进一步查看这个文件.
查看test.S可以发现_test这个函数的定义出现在汇编代码中,
cgraph
1 Initial entry points: main
2 Unit entry points: main
3
4 Initial callgraph:
5
6 main/4: 16 insns needed tree inlinable
7 called by:
8 calls: printf/3
9 printf/3:
called by: main/4
calls:
test/2: tree
called by:
calls:
__sputc/1: tree
called by:
calls:
__swbuf/0:
called by:
calls:
Reclaiming functions: test __sputc
Reclaimed callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
__swbuf/0:
called by:
calls:
Marking local functions:
Marked callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
__swbuf/0:
called by:
calls:
Deciding on inlining. Starting with 16 insns.
Inlining always_inline functions:
Deciding on smaller functions:
Deciding on functions called once:
Reclaiming functions: __swbuf
Reclaimed 0 insns
Inlined 0 calls, eliminated 0 functions, 16 insns turned to 16 insns.
Optimized callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
Final callgraph:
main/4: 16 insns needed inlinable asm_written
called by:
calls:
printf/3:
called by:
calls:
例如下面这段代码:
#include <stdio.h>
static void test() {
printf ("this code is never called.");
}
int main() {
printf("this is main function.");
return 0;
}
这里我们定义了一个static函数和一个main函数.按照C语言的约定,static 函数是只在当前模块可见, 非static函数则可被其它模块所包含.
然后我们通过检查使用和不使用DCE时,GCC的汇编输出来观察DCE的作用.
不使用DCE:
gcc -S -fno-builtin -fdump-ipa-cgraph test.c -o test.S
这里生成汇编结果说明了DCE的过程是在编译阶段已经完成, 命令中
-fdump-ipa-cgraph, 这是个调试输出选项,会生成一个.cgraph文件,我们后面会进一步查看这个文件.
查看test.S可以发现_test这个函数的定义出现在汇编代码中,
cgraph
1 Initial entry points: main
2 Unit entry points: main
3
4 Initial callgraph:
5
6 main/4: 16 insns needed tree inlinable
7 called by:
8 calls: printf/3
9 printf/3:
called by: main/4
calls:
test/2: tree
called by:
calls:
__sputc/1: tree
called by:
calls:
__swbuf/0:
called by:
calls:
Reclaiming functions: test __sputc
Reclaimed callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
__swbuf/0:
called by:
calls:
Marking local functions:
Marked callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
__swbuf/0:
called by:
calls:
Deciding on inlining. Starting with 16 insns.
Inlining always_inline functions:
Deciding on smaller functions:
Deciding on functions called once:
Reclaiming functions: __swbuf
Reclaimed 0 insns
Inlined 0 calls, eliminated 0 functions, 16 insns turned to 16 insns.
Optimized callgraph:
main/4: 16 insns needed tree inlinable
called by:
calls: printf/3
printf/3:
called by: main/4
calls:
Final callgraph:
main/4: 16 insns needed inlinable asm_written
called by:
calls:
printf/3:
called by:
calls:
相关文章推荐
- Web_PHP_织梦更新列表页提示Fatal error: Call to a member function GetInnerText() on a non-object in ...
- ABAP CALL FUNCTION 'DATE_GET_MONTH_LASTDAY' 取每月最后一天 'DATE_GET_WEEK'取周
- Get the Call Stack back when met UnhandledExceptionFilter
- 浅谈深度学习中的激活函数 - The Activation Function in Deep Learning
- The value of ESP was not properly saved across a function call解决方案
- gcc下编译出现warning:implicit declaration of function 'strdup'和warning:implicit declaration of function 'gethostname'
- C# 调用c++错误A call to PInvoke function has unbalanced the stack
- DedeCMS提示Call to a member function GetInnerText()的解决办
- dedecms自定义模型提示:Call to a member function GetInnerText()的解决方法
- Why do we get error "Call to undefined function: ora_logon()/ ocilogon()"?
- DedeCMS提示"Call to a member function GetInnerText()"解决办法
- Ruby: Call the system and get system information.
- Run-time function call tree with gcc
- Fatal error: Call to a member function getSource() on a non-object in G:\wamp\www\ChinaMagicCube\ap
- Fatal error: Call to a member function getSource() on a non-object in G:\wamp\www\ChinaMagicCube\ap
- Fatal error: Call to a member function getSource() on a non-object in G:\wamp\www\ChinaMagicCube\ap
- Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. 错误解决
- dynamic DLL 调用错误 -The value of ESP was not properly saved across a function call
- Call to a member function GetInnerText() on a non-object dede 添加自定义字段后 文章列表页生成失败 list
- how to get the function back trace in php