Mercurial > hg > Papers > 2011 > nobu-prosym
comparison presen/index.html @ 72:48de60dd51d1
modify explanation of TCE
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Jan 2012 07:29:15 +0900 |
parents | 64d22e65489c |
children | 9250ac87c2c7 |
comparison
equal
deleted
inserted
replaced
71:64d22e65489c | 72:48de60dd51d1 |
---|---|
7 <style type="text/css"> | 7 <style type="text/css"> |
8 tr.srctr { | 8 tr.srctr { |
9 font-size:28px; | 9 font-size:28px; |
10 } | 10 } |
11 td.srctd { | 11 td.srctd { |
12 height:20em; | 12 height:18em; |
13 } | 13 } |
14 pre.srcbox { | 14 pre.srcbox { |
15 height: 100%; | 15 height: 100%; |
16 overflow: scroll; | 16 overflow: scroll; |
17 } | 17 } |
310 <div class="slide"> | 310 <div class="slide"> |
311 <h1>GCC</h1> | 311 <h1>GCC</h1> |
312 <table border=1 width=100% height=100%> | 312 <table border=1 width=100% height=100%> |
313 <tr> | 313 <tr> |
314 <td width=50%>SSA</td> | 314 <td width=50%>SSA</td> |
315 <td width=50%>RTL</td> | 315 <td width=50%>RTL(一部)</td> |
316 </tr> | 316 </tr> |
317 <tr class="srctr"> | 317 <tr class="srctr"> |
318 <td class="srctd"> | 318 <td class="srctd"> |
319 <pre class="srcbox"> | 319 <pre class="srcbox"> |
320 factorial (int x) | 320 factorial (int x) |
346 | 346 |
347 </pre> | 347 </pre> |
348 </td> | 348 </td> |
349 <td class="srctd"> | 349 <td class="srctd"> |
350 <pre class="srcbox" style="width:25em;"> | 350 <pre class="srcbox" style="width:25em;"> |
351 (call (mem:QI (symbol_ref:DI ("print_factorial") [flags 0x403] <function_decl 0x146f6b200 print_factorial>) [0 S1 A8]) | 351 (jump_insn 20 19 21 5 (set (pc) |
352 (const_int 0 [0])) | 352 (if_then_else (le (reg:CCGC 17 flags) |
353 (const_int 0 [0])) | |
354 (label_ref 17) | |
355 (pc))) factorial.c:12 -1 | |
356 (nil) | |
357 -> 17) | |
358 | |
359 (note 21 20 22 6 [bb 6] NOTE_INSN_BASIC_BLOCK) | |
360 | |
361 (insn 22 21 23 6 (set (reg:SI 62) | |
362 (mem/c/i:SI (plus:DI (reg/f:DI 54 virtual-stack-vars) | |
363 (const_int -4 [0xfffffffffffffffc])) [0 prod+0 S4 A32])) factorial.c:15 -1 | |
364 (nil)) | |
365 | |
366 (insn 23 22 24 6 (set (reg:SI 5 di) | |
367 (reg:SI 62)) factorial.c:15 -1 | |
368 (nil)) | |
369 | |
370 (call_insn 24 23 25 6 (call (mem:QI (symbol_ref:DI ("print_factorial") [flags 0x403] <function_decl 0x146f6b200 print_factorial>) [0 S1 A8]) | |
371 (const_int 0 [0])) factorial.c:15 -1 | |
372 (nil) | |
373 (expr_list:REG_DEP_TRUE (use (reg:SI 5 di)) | |
374 (nil))) | |
375 | |
376 (code_label 25 24 26 7 2 "" [0 uses]) | |
377 | |
378 (note 26 25 0 7 [bb 7] NOTE_INSN_BASIC_BLOCK) | |
353 </pre> | 379 </pre> |
354 </td> | 380 </td> |
355 </tr> | 381 </tr> |
356 </table> | 382 </table> |
357 </div> | 383 </div> |
668 <li>スタックの領域確保、引数の格納、関数へのcall命令の発行が行わる。</li> | 694 <li>スタックの領域確保、引数の格納、関数へのcall命令の発行が行わる。</li> |
669 <li>try_taill_call(変数名)フラグがあり、TCEの条件に合わなければこのフラグが落とされる。</li> | 695 <li>try_taill_call(変数名)フラグがあり、TCEの条件に合わなければこのフラグが落とされる。</li> |
670 </ul> | 696 </ul> |
671 <li>具体的な実装</li> | 697 <li>具体的な実装</li> |
672 <ul> | 698 <ul> |
673 <li>try_tail_callフラグを落とさせない処理が追加されている。</li> | 699 <li>try_tail_callフラグを落とすif文の条件をかわす。</li> |
674 </ul> | 700 </ul> |
675 </div> | 701 </div> |
676 <!-- PAGE --> | 702 <!-- PAGE --> |
677 <!-- | 703 <!-- |
678 <div class="slide"> | 704 <div class="slide"> |
685 </div> | 711 </div> |
686 --> | 712 --> |
687 <!-- PAGE --> | 713 <!-- PAGE --> |
688 <div class="slide"> | 714 <div class="slide"> |
689 <h1>CbCの実装:TCE(末尾除去)</h1> | 715 <h1>CbCの実装:TCE(末尾除去)</h1> |
690 <li>try_tail_callフラグが落とされるif文</li> | 716 <li>try_tail_callフラグが落とされる部分</li> |
717 <table width=100%> | |
718 <tr class="srctr"> | |
719 <td> | |
691 <pre class="srcbox"> | 720 <pre class="srcbox"> |
692 if (currently_expanding_call++ != 0 | 721 if (currently_expanding_call++ != 0 |
693 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) | 722 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) |
694 && !flag_optimize_sibling_calls) | 723 && !flag_optimize_sibling_calls) |
695 || args_size.var | 724 || args_size.var |
696 || dbg_cnt (tail_call) == false) | 725 || dbg_cnt (tail_call) == false) |
697 try_tail_call = 0; | 726 try_tail_call = 0; |
698 </pre> | 727 </pre> |
699 </div> | 728 </td> |
700 <!-- PAGE --> | 729 </tr> |
701 <div class="slide"> | 730 </table> |
731 <li><string>!CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)により条件を回避</string></li> | |
732 </div> | |
733 <!-- PAGE --> | |
734 <div class="slide"> | |
735 <h1>CbCの実装:TCE(末尾除去)</h1> | |
702 <li>try_tail_callフラグが落とされる部分</li> | 736 <li>try_tail_callフラグが落とされる部分</li> |
703 <table> | 737 <table width=100%> |
704 <tr class="srctr"> | 738 <tr class="srctr"> |
705 <td class="srctd"> | 739 <td class="srctd"> |
706 <pre class="srcbox"> | 740 <pre class="srcbox"> |
707 if ( | 741 if ( |
708 #ifdef HAVE_sibcall_epilogue | 742 #ifdef HAVE_sibcall_epilogue |
731 try_tail_call = 0; | 765 try_tail_call = 0; |
732 </pre> | 766 </pre> |
733 </td> | 767 </td> |
734 </tr> | 768 </tr> |
735 </table> | 769 </table> |
736 | 770 <li><small>引数のスタックサイズ、関数の型のチェックが行われる。</small></li> |
771 </div> | |
772 <!-- PAGE --> | |
773 <div class="slide"> | |
774 <h1>CbCの実装:TCE(末尾除去)</h1> | |
775 <li>try_tail_callフラグが落とされる部分</li> | |
776 <table width=100% > | |
777 <tr class="srctr"> | |
778 <td class="srctd"> | |
779 <pre class="srcbox" style=""> | |
780 /* Check if caller and callee disagree in promotion of function | |
781 return value. */ | |
782 #ifndef noCbC | |
783 if (try_tail_call && (!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)))) | |
784 #else | |
785 if (try_tail_call) | |
786 #endif | |
787 { | |
788 enum machine_mode caller_mode, caller_promoted_mode; | |
789 enum machine_mode callee_mode, callee_promoted_mode; | |
790 int caller_unsignedp, callee_unsignedp; | |
791 tree caller_res = DECL_RESULT (current_function_decl); | |
792 | |
793 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res)); | |
794 caller_mode = DECL_MODE (caller_res); | |
795 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype)); | |
796 callee_mode = TYPE_MODE (TREE_TYPE (funtype)); | |
797 caller_promoted_mode | |
798 = promote_function_mode (TREE_TYPE (caller_res), caller_mode, | |
799 &caller_unsignedp, | |
800 TREE_TYPE (current_function_decl), 1); | |
801 callee_promoted_mode | |
802 = promote_function_mode (TREE_TYPE (funtype), callee_mode, | |
803 &callee_unsignedp, | |
804 funtype, 1); | |
805 if (caller_mode != VOIDmode | |
806 && (caller_promoted_mode != callee_promoted_mode | |
807 || ((caller_mode != caller_promoted_mode | |
808 || callee_mode != callee_promoted_mode) | |
809 && (caller_unsignedp != callee_unsignedp | |
810 || GET_MODE_BITSIZE (caller_mode) | |
811 < GET_MODE_BITSIZE (callee_mode))))) | |
812 try_tail_call = 0; | |
813 } | |
814 </pre> | |
815 </td> | |
816 </tr> | |
817 </table> | |
818 <li>関数の型のチェックが行われる。</li> | |
819 </div> | |
820 <!-- PAGE --> | |
821 <div class="slide"> | |
822 <h1>CbCの実装:TCE(末尾除去)</h1> | |
823 <li>try_tail_callフラグ矯正付与のソースコード</li> | |
824 <table width=100%> | |
825 <tr class="srctr"> | |
826 <td> | |
827 <pre> | |
828 #ifndef noCbC | |
829 if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) | |
830 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) | |
831 && try_tail_call == 0) | |
832 { | |
833 location_t loc = EXPR_LOCATION (exp); | |
834 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); | |
835 warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.", | |
836 name_callee); | |
837 try_tail_call = 1; | |
838 } | |
839 #endif | |
840 </pre> | |
841 </td> | |
842 </tr> | |
843 </table> | |
844 </div> | |
845 <!-- PAGE --> | |
846 <div class="slide"> | |
847 <h1>CbCの実装:TCE(末尾除去)</h1> | |
848 <ul> | |
849 <li>以前はexpand_call関数を元にしたexpand_cbc_goto関数を作って条件を回避させていた。</li> | |
850 <li>だがその方法だとexpand_call関数の修正にも合わせていく必要もあり管理も面倒であった。</li> | |
851 <li>しかしtry_tail_callフラグを落とさせない方法にすることでexpand_cbc_goto関数はいらなくなり、管理が容易くなった。</li> | |
852 </ul> | |
737 </div> | 853 </div> |
738 <!-- PAGE --> | 854 <!-- PAGE --> |
739 <!-- | 855 <!-- |
740 <div class="slide"> | 856 <div class="slide"> |
741 <h1>CbCの実装:環境付き継続</h1> | 857 <h1>CbCの実装:環境付き継続</h1> |
1022 その為に明らかに遅くなっていることが分かる。</li> | 1138 その為に明らかに遅くなっていることが分かる。</li> |
1023 <li>だがGCCの最適化有りの場合はMicro-C版よりも早い。</li> | 1139 <li>だがGCCの最適化有りの場合はMicro-C版よりも早い。</li> |
1024 </div> | 1140 </div> |
1025 <!-- PAGE --> | 1141 <!-- PAGE --> |
1026 <div class="slide"> | 1142 <div class="slide"> |
1027 <h1></h1> | |
1028 <li></li> | |
1029 </div> | |
1030 <!-- PAGE --> | |
1031 <div class="slide"> | |
1032 <h1>まとめ</h1> | 1143 <h1>まとめ</h1> |
1033 <ul> | 1144 <ul> |
1034 <li>今回GCC版CbCコンパイラのアップデートを行った。</li> | 1145 <li>今回GCC版CbCコンパイラのアップデートを行った。</li> |
1035 <li>TCEにかかる判定の部分と環境付き継続の実装の修正を行った。 | 1146 <li>TCEにかかる判定の部分と環境付き継続の実装の修正を行った。 |
1036 <br>おかげで、以前より楽な管理ができる実装にすることができた。</li> | 1147 <br>おかげで、以前より楽な管理ができる実装にすることができた。</li> |