Mercurial > hg > Papers > 2011 > nobu-prosym
comparison presen/index.html @ 83:07c5304622ac
modify
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Jan 2012 08:27:46 +0900 |
parents | efe2e6806c26 |
children | fb5994f49abd |
comparison
equal
deleted
inserted
replaced
82:b63a95cfb3ba | 83:07c5304622ac |
---|---|
110 <li>CbCのコンパイラは2001年に Micro-C版、2008年にはGCC-4.2をベースとしたコンパイラが開発された。</li> | 110 <li>CbCのコンパイラは2001年に Micro-C版、2008年にはGCC-4.2をベースとしたコンパイラが開発された。</li> |
111 <li>GCC上のCbCコンパイラは、GCCで修正・追加されていく最適化の機能を使用する為に、アップデートに合わせ変更する必要がある。</li> | 111 <li>GCC上のCbCコンパイラは、GCCで修正・追加されていく最適化の機能を使用する為に、アップデートに合わせ変更する必要がある。</li> |
112 <li>本研究ではCbCコンパイラをGCC-4.6へとアップデートを行った。 </li> | 112 <li>本研究ではCbCコンパイラをGCC-4.6へとアップデートを行った。 </li> |
113 </div> | 113 </div> |
114 <!-- PAGE --> | 114 <!-- PAGE --> |
115 <!-- | |
116 <div class=""> | |
117 <h1>先行研究</h1> | |
118 <li>Continuation based c コン パイラの gcc-4.2 による実装</li> | |
119 <li></li> | |
120 </div> | |
121 --> | |
122 <!-- PAGE --> | |
115 <div class="slide"> | 123 <div class="slide"> |
116 <h1>発表内容</h1> | 124 <h1>発表内容</h1> |
117 <ol> | 125 <ol> |
118 <li>CbC の紹介</li> | 126 <li>CbC の紹介</li> |
119 <li>GCC でのコンパイルの流れ</li> | 127 <li>GCC でのコンパイルの流れ</li> |
398 case RID_GOTO: | 406 case RID_GOTO: |
399 c_parser_consume_token (parser); | 407 c_parser_consume_token (parser); |
400 if ( c_parser_next_token_is (parser, CPP_NAME) | 408 if ( c_parser_next_token_is (parser, CPP_NAME) |
401 && c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON ) | 409 && c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON ) |
402 { | 410 { |
403 stmt = c_finish_goto_label (loc, | 411 : |
404 c_parser_peek_token (parser)->value); | |
405 c_parser_consume_token (parser); | |
406 } | |
407 else if (c_parser_next_token_is (parser, CPP_MULT)) | |
408 { | |
409 tree val; | |
410 | |
411 c_parser_consume_token (parser); | |
412 val = c_parser_expression (parser).value; | |
413 mark_exp_read (val); | |
414 stmt = c_finish_goto_ptr (loc, val); | |
415 } | 412 } |
416 #ifndef noCbC | 413 #ifndef noCbC |
417 else | 414 else |
418 { | 415 { |
419 if (c_parser_next_token_is (parser, CPP_NAME)) | 416 if (c_parser_next_token_is (parser, CPP_NAME)) |
570 <h1>CbCの実装:軽量継続(末尾除去)</h1> | 567 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
571 <li>末尾除去の条件はexpand_call関数で調べられる。</li> | 568 <li>末尾除去の条件はexpand_call関数で調べられる。</li> |
572 <ul> | 569 <ul> |
573 <li>expand_call関数</li> | 570 <li>expand_call関数</li> |
574 <ul> | 571 <ul> |
575 <li>Treeで表された関数からRTLを生成する関数</li> | 572 <li>SSAへの変換を終えたGIMPLEからとり出されたCALL_EXPREのTreeからRTLを生成する関数</li> |
576 <li>スタックの領域確保、引数の格納、関数へのcall命令の発行が行わる。</li> | 573 <li>スタックの領域確保、引数の格納、関数へのcall命令の発行が行わる。</li> |
577 <li>try_taill_call(変数名)フラグがあり、末尾除去の条件に合わなければこのフラグが落とされる。</li> | 574 <li>try_taill_call(局所変数)フラグがあり、末尾除去の条件に合わなければこのフラグが落とされる。</li> |
578 </ul> | 575 </ul> |
579 <li class="incremental">具体的な実装内容</li> | 576 <li class="incremental">具体的な実装内容</li> |
580 <ul> | 577 <ul> |
581 <li class="incremental">try_tail_callフラグを落とすif文の条件をかわすようにする。</li> | 578 <li class="incremental">try_tail_callフラグを落とすif文の条件をかわすようにする。</li> |
582 <li class="incremental">try_tail_callフラグを立たせる処理の追加。</li> | 579 <li class="incremental">try_tail_callフラグを立たせる処理の追加。</li> |
585 | 582 |
586 </div> | 583 </div> |
587 <!-- PAGE --> | 584 <!-- PAGE --> |
588 <div class="slide"> | 585 <div class="slide"> |
589 <h1>CbCの実装:軽量継続(末尾除去)</h1> | 586 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
590 <li>try_tail_callフラグが落とされる部分</li> | 587 <ul> |
591 <table width=100%> | 588 <li><small>try_tail_callフラグを落とさせない。</small></li> |
592 <tr class="srctr"> | 589 <pre class="srcbox" style="font-size:28px;"> |
593 <td class="srctd"> | |
594 <pre class="srcbox"> | |
595 | |
596 if (currently_expanding_call++ != 0 | 590 if (currently_expanding_call++ != 0 |
597 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) | 591 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) |
598 && !flag_optimize_sibling_calls) | 592 && !flag_optimize_sibling_calls) |
599 || args_size.var | 593 || args_size.var |
600 || dbg_cnt (tail_call) == false) | 594 || dbg_cnt (tail_call) == false) |
601 try_tail_call = 0; | 595 try_tail_call = 0; |
602 | |
603 : | |
604 | |
605 if ( | |
606 #ifdef HAVE_sibcall_epilogue | |
607 !HAVE_sibcall_epilogue | |
608 #else | |
609 1 | |
610 #endif | |
611 || !try_tail_call | |
612 || structure_value_addr != NULL_RTX | |
613 #ifdef REG_PARM_STACK_SPACE | |
614 || (OUTGOING_REG_PARM_STACK_SPACE (funtype) | |
615 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl))) | |
616 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (fndecl)) | |
617 #endif | |
618 || !targetm.function_ok_for_sibcall (fndecl, exp) | |
619 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN)) | |
620 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr))) | |
621 || (fndecl && decl_function_context (fndecl) == current_function_decl) | |
622 || args_size.constant > (crtl->args.size | |
623 - crtl->args.pretend_args_size) | |
624 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant) | |
625 != targetm.calls.return_pops_args (current_function_decl, | |
626 TREE_TYPE (current_function_decl), | |
627 crtl->args.size)) | |
628 || !lang_hooks.decls.ok_for_sibcall (fndecl)) | |
629 try_tail_call = 0; | |
630 | |
631 : | |
632 | |
633 /* Check if caller and callee disagree in promotion of function | |
634 return value. */ | |
635 #ifndef noCbC | |
636 if (try_tail_call && (!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)))) | |
637 #else | |
638 if (try_tail_call) | |
639 #endif | |
640 { | |
641 enum machine_mode caller_mode, caller_promoted_mode; | |
642 enum machine_mode callee_mode, callee_promoted_mode; | |
643 int caller_unsignedp, callee_unsignedp; | |
644 tree caller_res = DECL_RESULT (current_function_decl); | |
645 | |
646 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res)); | |
647 caller_mode = DECL_MODE (caller_res); | |
648 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype)); | |
649 callee_mode = TYPE_MODE (TREE_TYPE (funtype)); | |
650 caller_promoted_mode | |
651 = promote_function_mode (TREE_TYPE (caller_res), caller_mode, | |
652 &caller_unsignedp, | |
653 TREE_TYPE (current_function_decl), 1); | |
654 callee_promoted_mode | |
655 = promote_function_mode (TREE_TYPE (funtype), callee_mode, | |
656 &callee_unsignedp, | |
657 funtype, 1); | |
658 if (caller_mode != VOIDmode | |
659 && (caller_promoted_mode != callee_promoted_mode | |
660 || ((caller_mode != caller_promoted_mode | |
661 || callee_mode != callee_promoted_mode) | |
662 && (caller_unsignedp != callee_unsignedp | |
663 || GET_MODE_BITSIZE (caller_mode) | |
664 < GET_MODE_BITSIZE (callee_mode))))) | |
665 try_tail_call = 0; | |
666 } | |
667 </pre> | 596 </pre> |
668 </td> | 597 <ul> |
669 </tr> | 598 <!-- |
670 </table> | 599 <li>!CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)により条件を回避</li> |
671 <li><string>!CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)により条件を回避</string></li> | 600 --> |
672 </div> | 601 </ul> |
673 <!-- PAGE --> | 602 <li><small>try_tail_callフラグ矯正付与のソースコード</small></li> |
674 <div class="slide"> | 603 <pre class="srcbox" style="font-size:28px;"> |
675 <h1>CbCの実装:軽量継続(末尾除去)</h1> | |
676 <li>try_tail_callフラグ矯正付与のソースコード</li> | |
677 <table width=100%> | |
678 <tr class="srctr"> | |
679 <td> | |
680 <pre class="srcbox"> | |
681 #ifndef noCbC | |
682 if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) | 604 if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) |
683 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) | 605 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) |
684 && try_tail_call == 0) | 606 && try_tail_call == 0) |
685 { | 607 { |
686 location_t loc = EXPR_LOCATION (exp); | 608 location_t loc = EXPR_LOCATION (exp); |
687 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); | 609 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); |
688 warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.", | 610 warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.", |
689 name_callee); | 611 name_callee); |
690 try_tail_call = 1; | 612 try_tail_call = 1; |
691 } | 613 } |
692 #endif | |
693 </pre> | 614 </pre> |
694 </td> | |
695 </tr> | |
696 </table> | |
697 <ul> | |
698 <li>try_tail_callフラグが落とされた場合warningを出してフラグを立たせる。<small>(最適化の矯正付与)</small></li> | |
699 </ul> | |
700 </div> | 615 </div> |
701 <!-- PAGE --> | 616 <!-- PAGE --> |
702 <div class="slide"> | 617 <div class="slide"> |
703 <h1>CbCの実装:軽量継続(末尾除去)の実装について</h1> | 618 <h1>CbCの実装:軽量継続(末尾除去)の実装について</h1> |
704 <ul> | 619 <ul> |
739 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); | 654 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); |
740 declspecs_add_attrs(specs, attrs); | 655 declspecs_add_attrs(specs, attrs); |
741 } | 656 } |
742 </pre> | 657 </pre> |
743 </small> | 658 </small> |
744 <p><small>Intel64 ではレジスタが増えている為、fastcallは標準でつくようになっている。</small></p> | 659 <p><small>Intel64 ではレジスタが増えていてfastcallは標準でつくようになっている。</small></p> |
745 </div> | 660 </div> |
746 <!-- PAGE --> | 661 <!-- PAGE --> |
747 <div class="slide"> | 662 <div class="slide"> |
748 <h1>CbCの実装:引数渡し</h1> | 663 <h1>CbCの実装:引数渡し</h1> |
749 <ul> | 664 <ul> |
1001 <li>全ての実装を終えたらGCC版CbCコンパイラの実装はアップデートを行なっていくだけとなる。</li> | 916 <li>全ての実装を終えたらGCC版CbCコンパイラの実装はアップデートを行なっていくだけとなる。</li> |
1002 </ul> | 917 </ul> |
1003 </div> | 918 </div> |
1004 <!-- PAGE --> | 919 <!-- PAGE --> |
1005 <div class="slide"> | 920 <div class="slide"> |
1006 <h1>今後の予定</h1> | 921 <h1>今後の課題</h1> |
1007 <ul> | 922 <ul> |
1008 <li>CbCを用いたプログラムの作成</li> | 923 <li>CbCを用いたプログラムの作成</li> |
1009 <ul> | 924 <ul> |
1010 <li>CbCによるタスクマネージャの作成</li> | 925 <li>CbCによるタスクマネージャの作成</li> |
1011 </ul> | 926 </ul> |
1051 </td> | 966 </td> |
1052 </table> | 967 </table> |
1053 </div> | 968 </div> |
1054 <!-- PAGE --> | 969 <!-- PAGE --> |
1055 <div class="slide"> | 970 <div class="slide"> |
971 <h1>call_insn</h1> | |
972 <li>expand_callより作成されたRTLのTreeは以下のS式となる。</li> | |
973 <pre class="srcbox" style="font-size:28px; width:45em;"> | |
974 | |
975 (call_insn/j 18 17 19 3 (call (mem:QI (symbol_ref:DI ("factorial") [flags 0x403] <function_decl 0x1443b4400 factorial>) [0 S1 A8]) | |
976 (const_int 1024 [0x400])) factorial.cbc:30 -1 | |
977 (expr_list:REG_EH_REGION (const_int 0 [0]) | |
978 (nil)) | |
979 (expr_list:REG_DEP_TRUE (use (reg:SI 5 di)) | |
980 (nil))) | |
981 </pre> | |
982 <li></li> | |
983 </div> | |
984 <!-- PAGE --> | |
985 <div class="slide"> | |
1056 <h1>__rectype の実装</h1> | 986 <h1>__rectype の実装</h1> |
1057 <ul> | 987 <ul> |
1058 <li>通常、関数の引数に関数ポインタを渡した際は以下の様に使われる。</li> | 988 <li>通常、関数の引数に関数ポインタを渡した際は以下の様に使われる。</li> |
1059 <pre style="font-size:28px;"> | 989 <pre style="font-size:28px;"> |
1060 void factorial(int n, int result, void(*print)()){ | 990 void factorial(int n, int result, void(*print)()){ |