changeset 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
files presen/index.html
diffstat 1 files changed, 123 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/presen/index.html	Mon Jan 02 05:34:11 2012 +0900
+++ b/presen/index.html	Mon Jan 02 07:29:15 2012 +0900
@@ -9,7 +9,7 @@
 font-size:28px;
 }
 td.srctd {
-height:20em;
+height:18em;
 }
 pre.srcbox {
 height: 100%;
@@ -312,7 +312,7 @@
 	<table border=1 width=100% height=100%>
 	  <tr>
 	    <td width=50%>SSA</td>
-	    <td width=50%>RTL</td>
+	    <td width=50%>RTL(一部)</td>
 	  </tr>
 	  <tr class="srctr">
 	    <td class="srctd">
@@ -348,8 +348,34 @@
 	    </td>
 	    <td class="srctd">
 		<pre class="srcbox" style="width:25em;">
-(call (mem:QI (symbol_ref:DI ("print_factorial") [flags 0x403]  &lt;function_decl 0x146f6b200 print_factorial&gt;) [0 S1 A8])
-        (const_int 0 [0]))
+(jump_insn 20 19 21 5 (set (pc)
+        (if_then_else (le (reg:CCGC 17 flags)
+                (const_int 0 [0]))
+            (label_ref 17)
+            (pc))) factorial.c:12 -1
+     (nil)
+ -> 17)
+
+(note 21 20 22 6 [bb 6] NOTE_INSN_BASIC_BLOCK)
+
+(insn 22 21 23 6 (set (reg:SI 62)
+        (mem/c/i:SI (plus:DI (reg/f:DI 54 virtual-stack-vars)
+                (const_int -4 [0xfffffffffffffffc])) [0 prod+0 S4 A32])) factorial.c:15 -1
+     (nil))
+
+(insn 23 22 24 6 (set (reg:SI 5 di)
+        (reg:SI 62)) factorial.c:15 -1
+     (nil))
+
+(call_insn 24 23 25 6 (call (mem:QI (symbol_ref:DI ("print_factorial") [flags 0x403]  <function_decl 0x146f6b200 print_factorial>) [0 S1 A8])
+        (const_int 0 [0])) factorial.c:15 -1
+     (nil)
+    (expr_list:REG_DEP_TRUE (use (reg:SI 5 di))
+        (nil)))
+
+(code_label 25 24 26 7 2 "" [0 uses])
+
+(note 26 25 0 7 [bb 7] NOTE_INSN_BASIC_BLOCK)
               </pre>
 	    </td>
 	  </tr>
@@ -670,7 +696,7 @@
 	</ul>
 	<li>具体的な実装</li>
 	<ul>
-	  <li>try_tail_callフラグを落とさせない処理が追加されている。</li>
+	  <li>try_tail_callフラグを落とすif文の条件をかわす。</li>
 	</ul>
       </div>
       <!-- PAGE -->
@@ -687,7 +713,10 @@
       <!-- PAGE -->
       <div class="slide">
 	<h1>CbCの実装:TCE(末尾除去)</h1>
-	<li>try_tail_callフラグが落とされるif文</li>
+	<li>try_tail_callフラグが落とされる部分</li>
+	<table width=100%>
+	  <tr class="srctr">
+	    <td>
 	<pre class="srcbox">
   if (currently_expanding_call++ != 0
       || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) 
@@ -696,11 +725,16 @@
       || dbg_cnt (tail_call) == false)
     try_tail_call = 0;
 	</pre>
+	    </td>
+	  </tr>
+	</table>
+	<li><string>!CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)により条件を回避</string></li>
       </div>
       <!-- PAGE -->
       <div class="slide">
+	<h1>CbCの実装:TCE(末尾除去)</h1>
 	<li>try_tail_callフラグが落とされる部分</li>
-	<table>
+	<table width=100%>
 	  <tr class="srctr">
 	    <td class="srctd">
 	<pre class="srcbox">
@@ -733,7 +767,89 @@
 	    </td>
 	    </tr>
 	  </table>
+	<li><small>引数のスタックサイズ、関数の型のチェックが行われる。</small></li>
+      </div>
+      <!-- PAGE -->
+      <div class="slide">
+	<h1>CbCの実装:TCE(末尾除去)</h1>
+	<li>try_tail_callフラグが落とされる部分</li>
+	<table width=100% >
+	  <tr class="srctr">
+	    <td class="srctd">
+	  <pre class="srcbox" style="">
+  /* Check if caller and callee disagree in promotion of function                                                                                                                      
+     return value.  */
+#ifndef noCbC
+  if (try_tail_call && (!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))))
+#else
+    if (try_tail_call)
+#endif
+    {
+      enum machine_mode caller_mode, caller_promoted_mode;
+      enum machine_mode callee_mode, callee_promoted_mode;
+      int caller_unsignedp, callee_unsignedp;
+      tree caller_res = DECL_RESULT (current_function_decl);
 
+      caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
+      caller_mode = DECL_MODE (caller_res);
+      callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
+      callee_mode = TYPE_MODE (TREE_TYPE (funtype));
+      caller_promoted_mode
+        = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
+                                 &caller_unsignedp,
+                                 TREE_TYPE (current_function_decl), 1);
+      callee_promoted_mode
+        = promote_function_mode (TREE_TYPE (funtype), callee_mode,
+                                 &callee_unsignedp,
+                                 funtype, 1);
+      if (caller_mode != VOIDmode
+          && (caller_promoted_mode != callee_promoted_mode
+              || ((caller_mode != caller_promoted_mode
+                   || callee_mode != callee_promoted_mode)
+                  && (caller_unsignedp != callee_unsignedp
+                      || GET_MODE_BITSIZE (caller_mode)
+                         < GET_MODE_BITSIZE (callee_mode)))))
+        try_tail_call = 0;
+    }
+	</pre>
+	  </td>
+	  </tr>
+	</table>
+	<li>関数の型のチェックが行われる。</li>
+      </div>
+      <!-- PAGE -->
+      <div class="slide">
+	<h1>CbCの実装:TCE(末尾除去)</h1>
+	<li>try_tail_callフラグ矯正付与のソースコード</li>
+	<table width=100%>
+	  <tr class="srctr">
+	    <td>
+	  <pre>
+#ifndef noCbC
+  if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))
+      && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl))
+      && try_tail_call == 0)
+    {
+      location_t loc = EXPR_LOCATION (exp);
+      char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl));
+      warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.",
+                        name_callee);
+      try_tail_call = 1;
+    }
+#endif
+	</pre>
+	  </td>
+	  </tr>
+	  </table>
+      </div>
+      <!-- PAGE -->
+      <div class="slide">
+	<h1>CbCの実装:TCE(末尾除去)</h1>
+	<ul>
+	  <li>以前はexpand_call関数を元にしたexpand_cbc_goto関数を作って条件を回避させていた。</li>
+	  <li>だがその方法だとexpand_call関数の修正にも合わせていく必要もあり管理も面倒であった。</li>
+	  <li>しかしtry_tail_callフラグを落とさせない方法にすることでexpand_cbc_goto関数はいらなくなり、管理が容易くなった。</li>
+	</ul>
       </div>
       <!-- PAGE -->
 <!--
@@ -1024,11 +1140,6 @@
       </div>
       <!-- PAGE -->
       <div class="slide">
-	<h1></h1>
-	<li></li>
-      </div>
-      <!-- PAGE -->
-      <div class="slide">
 	<h1>まとめ</h1>
 	<ul>
 	  <li>今回GCC版CbCコンパイラのアップデートを行った。</li>