操屁眼的视频在线免费看,日本在线综合一区二区,久久在线观看免费视频,欧美日韩精品久久综

新聞資訊

    除了支持Jame 提到的鏈接時(shí)間代碼生成(LTCG)外,GCC工具鏈還支持鏈接時(shí)間優(yōu)化。 從版本4.5開(kāi)始,GCC支持啟用鏈接時(shí)間優(yōu)化(LTO)的-flto開(kāi)關(guān),LTO是一種整體程序優(yōu)化的forms,它允許從單獨(dú)的目標(biāo)文件內(nèi)聯(lián)函數(shù)(以及編譯器可能能夠做出的任何其他優(yōu)化編譯所有的目標(biāo)文件就好像它們來(lái)自單個(gè)C源文件)。

    這是一個(gè)簡(jiǎn)單的例子:

    test.c :

     void print_int(int x); int main(){ print_int(1); print_int(42); print_int(-1); return 0; } 

    .c :

     #include  void print_int( int x) { printf( "the int is %d\n", x); } 

    首先使用GCC4.5.x編譯它們 – GCC文檔中的示例使用了-O2 ,但為了在我的簡(jiǎn)單中獲得可見(jiàn)的結(jié)果,我必須使用-O3 :

     C:\temp>gcc --version gcc (GCC) 4.5.2 # compile with preparation for LTO C:\temp>gcc -c -O3 -flto test.c C:\temp>gcc -c -O3 -flto print_int.c # link without LTO C:\temp>gcc -o test-nolto.exe print_int.o test.o 

    為了得到LTO的效果,即使在鏈接階段,也應(yīng)該使用優(yōu)化選項(xiàng) – 鏈接器實(shí)際上會(huì)調(diào)用編譯器來(lái)編譯上面第一步中編譯器放入對(duì)象文件的中間代碼段。 如果您在這個(gè)階段沒(méi)有通過(guò)優(yōu)化選項(xiàng),編譯器將不會(huì)執(zhí)行您要查找的內(nèi)聯(lián)。

     # link using LTO C:\temp>gcc -o test-lto.exe -flto -O3 print_int.o test.o 

    反匯編版本沒(méi)有鏈接時(shí)間優(yōu)化。 請(qǐng)注意,調(diào)用()函數(shù):

     C:\temp>gdb test-nolto.exe GNU gdb (GDB) 7.2 (gdb) start Temporary breakpoint 1 at 0x401373 Starting program: C:\temp/test-nolto.exe [New Thread 3324.0xdc0] Temporary breakpoint 1, 0x00401373 in main () (gdb) disassem Dump of assembler code for function main: 0x00401370 <+0>: push %ebp 0x00401371 <+1>: mov %esp,%ebp => 0x00401373 <+3>: and $0xfffffff0,%esp 0x00401376 <+6>: sub $0x10,%esp 0x00401379 <+9>: call 0x4018ca <__main> 0x0040137e <+14>: movl $0x1,(%esp) 0x00401385 <+21>: call 0x401350  0x0040138a <+26>: movl $0x2a,(%esp) 0x00401391 <+33>: call 0x401350  0x00401396 <+38>: movl $0xffffffff,(%esp) 0x0040139d <+45>: call 0x401350  0x004013a2 <+50>: xor %eax,%eax 0x004013a4 <+52>: leave 0x004013a5 <+53>: ret 

    通過(guò)鏈接時(shí)間優(yōu)化對(duì)版本進(jìn)行反匯編。 請(qǐng)注意,對(duì)()的調(diào)用是直接進(jìn)行的:

     C:\temp>gdb test-lto.exe GNU gdb (GDB) 7.2 (gdb) start Temporary breakpoint 1 at 0x401373 Starting program: C:\temp/test-lto.exe [New Thread 1768.0x126c] Temporary breakpoint 1, 0x00401373 in main () (gdb) disassem Dump of assembler code for function main: 0x00401370 <+0>: push %ebp 0x00401371 <+1>: mov %esp,%ebp => 0x00401373 <+3>: and $0xfffffff0,%esp 0x00401376 <+6>: sub $0x10,%esp 0x00401379 <+9>: call 0x4018da <__main> 0x0040137e <+14>: movl $0x1,0x4(%esp) 0x00401386 <+22>: movl $0x403064,(%esp) 0x0040138d <+29>: call 0x401acc  0x00401392 <+34>: movl $0x2a,0x4(%esp) 0x0040139a <+42>: movl $0x403064,(%esp) 0x004013a1 <+49>: call 0x401acc  0x004013a6 <+54>: movl $0xffffffff,0x4(%esp) 0x004013ae <+62>: movl $0x403064,(%esp) 0x004013b5 <+69>: call 0x401acc  0x004013ba <+74>: xor %eax,%eax 0x004013bc <+76>: leave 0x004013bd <+77>: ret End of assembler dump. 

    這里是與MSVC(首先與LTCG)相同的實(shí)驗(yàn):

     C:\temp>cl -c /GL /Zi /Ox test.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. test.c C:\temp>cl -c /GL /Zi /Ox print_int.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. print_int.c C:\temp>link /LTCG test.obj print_int.obj /out:test-ltcg.exe /debug Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. Generating code Finished generating code C:\temp>"\Program Files (x86)\Debugging Tools for Windows (x86)"\cdb test-ltcg.exe Microsoft (R) Windows Debugger Version 6.12.0002.633 X86 Copyright (c) Microsoft Corporation. All rights reserved. CommandLine: test-ltcg.exe // ... 0:000> u main *** WARNING: Unable to verify checksum for test-ltcg.exe test_ltcg!main: 00cd1c20 6a01 push 1 00cd1c22 68d05dcd00 push offset test_ltcg!__decimal_point_length+0x10 (00cd5dd0) 00cd1c27 e8e3f3feff call test_ltcg!printf (00cc100f) 00cd1c2c 6a2a push 2Ah 00cd1c2e 68d05dcd00 push offset test_ltcg!__decimal_point_length+0x10 (00cd5dd0) 00cd1c33 e8d7f3feff call test_ltcg!printf (00cc100f) 00cd1c38 6aff push 0FFFFFFFFh 00cd1c3a 68d05dcd00 push offset test_ltcg!__decimal_point_length+0x10 (00cd5dd0) 00cd1c3f e8cbf3feff call test_ltcg!printf (00cc100f) 00cd1c44 83c418 add esp,18h 00cd1c47 33c0 xor eax,eax 00cd1c49 c3 ret 0:000> 

    現(xiàn)在沒(méi)有LTCG。 請(qǐng)注意,使用MSVC,您必須編譯沒(méi)有/GL的.c文件,以阻止鏈接器執(zhí)行LTCG內(nèi)聯(lián)函數(shù) 內(nèi)部鏈接,否則鏈接器會(huì)檢測(cè)到/GL已被指定,并強(qiáng)制執(zhí)行/LTCG選項(xiàng)(嘿,這就是您所說(shuō)的你想第一次與/GL ):

     C:\temp>cl -c /Zi /Ox test.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. test.c C:\temp>cl -c /Zi /Ox print_int.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. print_int.c C:\temp>link test.obj print_int.obj /out:test-noltcg.exe /debug Microsoft (R) Incremental Linker Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. C:\temp>"\Program Files (x86)\Debugging Tools for Windows (x86)"\cdb test-noltcg.exe Microsoft (R) Windows Debugger Version 6.12.0002.633 X86 Copyright (c) Microsoft Corporation. All rights reserved. CommandLine: test-noltcg.exe // ... 0:000> u main test_noltcg!main: 00c41020 6a01 push 1 00c41022 e8e3ffffff call test_noltcg!ILT+5(_print_int) (00c4100a) 00c41027 6a2a push 2Ah 00c41029 e8dcffffff call test_noltcg!ILT+5(_print_int) (00c4100a) 00c4102e 6aff push 0FFFFFFFFh 00c41030 e8d5ffffff call test_noltcg!ILT+5(_print_int) (00c4100a) 00c41035 83c40c add esp,0Ch 00c41038 33c0 xor eax,eax 00c4103a c3 ret 0:000> 

    微軟的鏈接器在LTCG 中支持的一個(gè)不被GCC支持的事情(就我所知)就是簡(jiǎn)檔引導(dǎo)優(yōu)化(PGO)。 該技術(shù)允許微軟的鏈接器根據(jù)從以前的程序運(yùn)行中收集的分析數(shù)據(jù)進(jìn)行優(yōu)化。 這允許鏈接器執(zhí)行諸如將“熱”聚集到相同的內(nèi)存頁(yè)面上以及很less使用在其他內(nèi)存頁(yè)面上的代碼序列來(lái)減less程序的工作集。

    編輯(2011年8月28日):GCC支持文件指導(dǎo)優(yōu)化使用--和--use這樣的選項(xiàng)內(nèi)聯(lián)函數(shù) 內(nèi)部鏈接,但我完全不了解它們。

    感謝 向我指出這一點(diǎn)。

網(wǎng)站首頁(yè)   |    關(guān)于我們   |    公司新聞   |    產(chǎn)品方案   |    用戶案例   |    售后服務(wù)   |    合作伙伴   |    人才招聘   |   

友情鏈接: 餐飲加盟

地址:北京市海淀區(qū)    電話:010-     郵箱:@126.com

備案號(hào):冀ICP備2024067069號(hào)-3 北京科技有限公司版權(quán)所有