Mercurial > hg > Papers > 2011 > nobu-prosym
annotate presen/index.html @ 80:923dd8de7be2
modify
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 04 Jan 2012 23:41:05 +0900 |
parents | 6465e96ba272 |
children | efe2e6806c26 |
rev | line source |
---|---|
54 | 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
3 | |
4 <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | |
6 <head> | |
71 | 7 <style type="text/css"> |
8 tr.srctr { | |
9 font-size:28px; | |
10 } | |
11 td.srctd { | |
74 | 12 height:17em; |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
13 } |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
14 pre.srcbox { |
71 | 15 height: 100%; |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
16 overflow: scroll; |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
17 } |
64 | 18 .src{ |
19 overflow: scroll; | |
20 width: 90%; | |
21 height: 60%; | |
22 } | |
54 | 23 .center { |
24 margin-left: auto; | |
25 margin-right: auto; | |
26 text-align: center; | |
27 } | |
28 .textcenter { | |
29 text-align: center; | |
30 } | |
31 .taninaritop { | |
32 margin: auto; | |
33 width: 95%; | |
34 font-weight: bold; | |
35 } | |
36 </style> | |
37 <title>2012/ 1/ 7</title> | |
38 <!-- metadata --> | |
39 <meta name="generator" content="S5" /> | |
40 <meta name="version" content="S5 1.1" /> | |
41 <meta name="presdate" content="20120107" /> | |
42 <meta name="author" content="Nobuyasu Oshiro" /> | |
43 <meta name="company" content="University of the Ryukyu" /> | |
44 <!-- meta temporary --> | |
45 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
46 <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
47 <meta http-equiv="Content-Style-Type" content="text/css" /> | |
48 <!-- configuration parameters --> | |
49 <meta name="defaultView" content="slideshow" /> | |
50 <meta name="controlVis" content="hidden" /> | |
51 <!-- configuration extensions --> | |
52 <meta name="tranSitions" content="true" /> | |
53 <meta name="fadeDuration" content="500" /> | |
54 <meta name="incrDuration" content="250" /> | |
55 <!-- configuration autoplay extension --> | |
56 <meta name="autoMatic" content="false" /> | |
57 <meta name="playLoop" content="true" /> | |
58 <meta name="playDelay" content="10" /> | |
59 <!-- configuration audio extension --> | |
60 <meta name="audioSupport" content="false" /> | |
61 <meta name="audioVolume" content="100" /> | |
62 <meta name="audioError" content="false" /> | |
63 <!-- configuration audio debug --> | |
64 <meta name="audioDebug" content="false" /> | |
65 <!-- style sheet links --> | |
66 <link rel="stylesheet" href="ui/default_utf/slides.css" type="text/css" media="projection" id="slideProj" /> | |
67 <link rel="stylesheet" href="ui/default_utf/outline.css" type="text/css" media="screen" id="outlineStyle" /> | |
68 <link rel="stylesheet" href="ui/default_utf/print.css" type="text/css" media="print" id="slidePrint" /> | |
69 <link rel="stylesheet" href="ui/default_utf/opera.css" type="text/css" media="projection" id="operaFix" /> | |
70 <!-- embedded styles --> | |
71 <style type="text/css" media="all"> | |
72 .imgcon {width: 100%; margin: 0 auto; padding: 0; text-align: center;} | |
73 #anim {width: 33%; height: 320px; position: relative;} | |
74 #anim img {position: absolute; top: 0px; left: 0px;} | |
75 </style> | |
76 <!-- S5 JS --> | |
77 <script src="ui/default_utf/slides.js" type="text/javascript"></script> | |
78 </head> | |
79 <body> | |
80 | |
81 <div class="layout"> | |
82 <div id="controls"><!-- DO NOT EDIT --></div> | |
83 <div id="currentSlide"><!-- DO NOT EDIT --></div> | |
84 <div id="header"></div> | |
85 <div id="footer"> | |
86 <h1>プログラミングシンポジウム: 2012/ 1/ 7</h1> | |
87 <h2>並列信頼研</h2> | |
88 </div> | |
89 </div> | |
90 | |
91 <div class="presentation"> | |
92 | |
93 <div class="slide"> | |
94 <h1>Continuation based Cの GCC 4.6 上の実装について</li> | |
95 <h3></h3> | |
96 <li>大城 信康</li> | |
97 <h4><a href="http://ie.u-ryukyu.ac.jp/" rel="external">琉球大学 並列信頼研究室</a></h4> | |
98 <div class="handout"></div> | |
99 </div> | |
100 <!-- PAGE --> | |
101 <div class="slide"> | |
102 <h1>目的と背景(1)</h1> | |
73 | 103 <li>当研究室ではコードセグメント単位で記述するプログラミング言語Continuation based C (以下CbC)を開発している。</li> |
54 | 104 <li>コードセグメントは並列実行の単位として使うことができ、プログラムの正しさを示す単位としても使用することができる。</li> |
63
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
105 <li>Many Core での並列実行を高い性能と高い信頼性で実現することができると考えている。</li> |
54 | 106 </div> |
107 <!-- PAGE --> | |
108 <div class="slide"> | |
109 <h1>目的と背景(2)</h1> | |
80 | 110 <li>CbCのコンパイラは2001年に Micro-C版、2008年にはGCC-4.2をベースとしたコンパイラが開発された。</li> |
111 <li>GCC上のCbCコンパイラは、GCCで修正・追加されていく最適化の機能を使用する為に、アップデートに合わせ変更する必要がある。</li> | |
112 <li>本研究ではCbCコンパイラをGCC-4.6へとアップデートを行った。 </li> | |
54 | 113 </div> |
114 <!-- PAGE --> | |
115 <div class="slide"> | |
116 <h1>発表内容</h1> | |
117 <ol> | |
118 <li>CbC の紹介</li> | |
119 <li>GCC でのコンパイルの流れ</li> | |
58 | 120 <font color="red"> |
121 <li>CbC の実装</li> | |
122 </font> | |
54 | 123 <li>Micro-C との性能比較</li> |
124 <li>まとめ</li> | |
125 <ol> | |
126 </div> | |
127 <!-- PAGE --> | |
128 <div class="slide"> | |
129 <h1>Continuation based C </h1> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
130 <h2>コードセグメント単位での記述と継続を基本としたプログラミング言語。</h2> |
63
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
131 <ul> |
73 | 132 <li>コードセグメント:CbCにおけるプログラムの基本単位</li> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
133 <ul> |
80 | 134 <li>Cから関数コールとループ制御が取り除かれた形</li> |
73 | 135 <li>C の関数よりも細かい単位になる。</li> |
136 <li>コードセグメントの末尾処理で別のコードセグメントへ継続(goto)することでCbCのプログラムは続いていく。</li> | |
137 </ul> | |
138 <p class="center"> | |
139 <img src="./pix/codesegment.png" style="height:6em;"> | |
140 </p> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
141 </ul> |
54 | 142 </div> |
143 <!-- PAGE --> | |
144 <div class="slide"> | |
73 | 145 <h1>Continuation based C </h1> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
146 <h2>継続:現在の処理を実行していく為の情報</h2> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
147 |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
148 <table width=100% border=1> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
149 <tr> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
150 <td><small>Cの継続</small></td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
151 <td><small>CbCの継続(軽量継続)</small></td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
152 </tr> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
153 <tr style="font-size:30px"> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
154 <td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
155 <ul> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
156 <li>続く命令のアドレス</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
157 <li>命令に必要なデータ</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
158 <li>スタックに積まれている値(環境)</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
159 </ul> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
160 </td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
161 <td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
162 <ul> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
163 <li>Cの継続から環境を除外</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
164 <li>続く命令とその命令に必要なデータのみ</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
165 </ul> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
166 </td> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
167 </tr> |
66
26a3713b2989
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
64
diff
changeset
|
168 <tr> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
169 <td style="margin-left:auto; margin-right: auto; text-align: center;"> |
66
26a3713b2989
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
64
diff
changeset
|
170 <img class="scale" src="./pix/func_call.png" style="height: 6em;"> |
26a3713b2989
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
64
diff
changeset
|
171 </td> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
172 <td style="margin-left:auto; margin-right: auto; text-align: center;"> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
173 <img class="scale" src="./pix/cs_stack.png" style="height: 6em;"> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
174 </td> |
66
26a3713b2989
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
64
diff
changeset
|
175 </tr> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
176 </table> |
73 | 177 <li>コードセグメントへの継続はcallではなくjmp命令で行われる</li> |
59
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
178 </div> |
6ef99d3e66b2
modify light-weight continuation
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
58
diff
changeset
|
179 <!-- PAGE --> |
58 | 180 <div class="slide"> |
54 | 181 <h1>Continuation based C </h1> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
182 <table width=100% border=1> |
73 | 183 <caption><small>階乗を求めるCbCのプログラム</small></caption> |
71 | 184 <tr class="srctr"> |
54 | 185 <td width=50%> |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
186 <pre class="srcbox"> |
73 | 187 |
54 | 188 __code print_factorial(int prod) { |
189 printf("factorial = %d\n",prod); | |
190 exit(0); | |
191 } | |
58 | 192 |
54 | 193 __code factorial0(int prod, int x) { |
194 if ( x >= 1) { | |
195 goto factorial0(prod*x, x-1); | |
196 }else{ | |
197 goto print_factorial(prod); | |
198 } | |
199 } | |
200 </pre> | |
201 </td> | |
202 <td> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
203 <pre class="srcbox"> |
73 | 204 |
54 | 205 __code factorial(int x) { |
206 goto factorial0(1, x); | |
207 } | |
58 | 208 |
54 | 209 int main(int argc, char **argv) { |
210 int i; | |
211 i = atoi(argv[1]); | |
212 goto factorial(i); | |
213 return 0; | |
214 } | |
215 </pre> | |
216 </td> | |
217 </tr> | |
218 </table> | |
73 | 219 <ul> |
220 <li><small>__code キーワードによるコードセグメントの宣言</small></li> | |
221 <li><small>goto によるコードセグメントへの継続(Cの関数呼び出しと同等)</small></li> | |
222 </ul> | |
223 <li class="incremental"><small>以上がCbCについての紹介となる。</small></li> | |
54 | 224 </div> |
225 <!-- PAGE --> | |
226 <div class="slide"> | |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
227 <h1>GCC</h1> |
80 | 228 <li>GCC:Gnu Compiler Collection</li> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
229 <ul> |
80 | 230 <li><small>GCCの中でも変更を加えた部分はソースコードをアセンブラに変換するcc1になる。</small></li> |
231 <li><small>cc1ではアセンブラ言語を出力するまでに読み込まれたソースコードは次の4つの中間言語へと変換される。</small></li> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
232 <ul> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
233 <li>Generic Tree</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
234 <li>GIMPLE</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
235 <li>Tree SSA</li> |
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
236 <li>RTL</li> |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
237 </ul> |
80 | 238 <!-- |
73 | 239 <li class="incremental">CbCの実装においてはGeneric Tree生成部分とRTLへの変換部分に修正が加えられている。</li> |
80 | 240 --> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
241 <li class="incremental">Generic Tree生成部分について詳しく触れてみる。</li> |
75
454ddda8d306
modify explanation of CbC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
74
diff
changeset
|
242 </ul> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
243 </div> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
244 <!-- PAGE --> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
245 <!-- |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
246 <div class="slide"> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
247 <h1>GCC:Generic Tree</h1> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
248 <li>Generic Treeではソースコードの内容が FUNCTION_TYPE, CALL_EXPR, MODIFY_EXPR 等と言った形で表される。</li> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
249 <table class="center" width=100% border=1> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
250 <tr> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
251 <td></td> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
252 <td><small>値の代入:MODIFY_EXPR</small></td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
253 <td><small>関数呼び出し:CALL_EXPR</small></td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
254 </t> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
255 <tr> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
256 <td>命令</td> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
257 <td>b = a * 10</td> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
258 <td>func(a,10)</td> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
259 </t> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
260 <tr> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
261 <td><small>Generic<br>Tree</small></td> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
262 <td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
263 <img src="./pix/MODIFY_EXPR.png" style="height: 6em;"> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
264 </td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
265 <td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
266 <img src="./pix/CALL_EXPR.png" style="height: 7em;"> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
267 </td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
268 </tr> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
269 </table> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
270 <p class="center"><small>Generic Treeでの表現</small></p> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
271 </div> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
272 --> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
273 <!-- PAGE --> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
274 <div class="slide"> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
275 <h1>GCC:Generic Tree</h1> |
80 | 276 <li><small>CALL_EXPRE、MODIFY_EXPR、RETURN_EXPR等といった表現で扱われる。</small></li> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
277 <table width=100% border=1> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
278 <tr> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
279 <td class="center"><small>ソースコード</small></td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
280 <td class="center"><small>Generic Treeでの表現</small></td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
281 </tr> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
282 <tr> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
283 <td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
284 <small> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
285 <pre> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
286 int main() { |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
287 int a, b; |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
288 a = 3; |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
289 b = func(a, 10); |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
290 return b; |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
291 } |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
292 </pre> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
293 </small> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
294 </td> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
295 <td style="margin-left:auto; margin-right:auto; text-align: center;"> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
296 <img src="./pix/STATEMENT_LIST.png" style="height: 7em;"> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
297 </td> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
298 </tr> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
299 </table> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
300 <li class="incremental">CbCの実装においてこのGeneric Treeの生成を意識していくことになる。</li> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
301 </div> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
302 <!-- PAGE --> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
303 <!-- |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
304 <div class="slide"> |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
305 <h1>GCC</h1> |
54 | 306 <li>GCC についての簡単な説明を行う...</li> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
307 <li>TODO: NEXT_PASS() の把握</li> |
54 | 308 <img src="./pix/ir.png" style="height: 6em;"> |
309 <li>CbCの実装は主に Parser の部分と RTL を生成する部分に行われる。</li> | |
310 </div> | |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
311 --> |
54 | 312 <!-- PAGE --> |
313 <div class="slide"> | |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
314 <h1>CbCの実装</h1> |
54 | 315 <ul> |
316 <li>シンタックスの追加</li> | |
80 | 317 <li>継続処理の実装</li> |
318 <!-- | |
73 | 319 <li>末尾除去:Tail Call Elimination(TCE)</li> |
80 | 320 --> |
61
2c543a47737b
modify explanation of fastcall
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
321 <li>レジスタによる引数渡し(fastcall属性の付与)</li> |
54 | 322 <li>環境付き継続</li> |
323 </ul> | |
324 </div> | |
325 <!-- PAGE --> | |
326 <div class="slide"> | |
77 | 327 <h1>CbCの実装:__codeシンタックスの追加</h1> |
54 | 328 <ul> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
329 <li>__code キーワードでのコードセグメントの宣言</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
330 <ul> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
331 <li>__code 用idとkeywordを作成。</li> |
80 | 332 <li>通常の関数作成と基本同じだが、コードセグメント判定用のフラグを立てる。</li> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
333 </ul> |
73 | 334 </ul> |
335 <table width=100% border=1> | |
336 <tr class="srctr"> | |
337 <td> | |
80 | 338 <pre class="srcbox" style="height:13em"> |
339 tree | |
340 build_code_segment_type (tree value_type, tree arg_types) | |
341 { | |
342 tree t; | |
343 hashval_t hashcode = 0; | |
344 | |
345 gcc_assert (TREE_CODE (value_type) == VOID_TYPE); | |
346 | |
347 /* Make a node of the sort we want. */ | |
348 t = make_node (FUNCTION_TYPE); | |
349 TREE_TYPE (t) = value_type; | |
350 TYPE_ARG_TYPES (t) = arg_types; | |
351 | |
352 CbC_IS_CODE_SEGMENT (t) = 1; | |
353 | |
354 if (!COMPLETE_TYPE_P (t)) | |
355 layout_type (t); | |
356 return t; | |
357 } | |
358 </pre> | |
359 </td> | |
360 </tr> | |
361 </table> | |
362 <li><small>コードセグメントはGCC内部では関数として扱われる。</small></li> | |
363 </div> | |
364 | |
365 <!-- SOURCE --> | |
366 <!-- | |
73 | 367 const struct c_common_resword c_common_reswords[] = |
368 { | |
369 { "_Bool", RID_BOOL, D_CONLY }, | |
370 : | |
371 { "__code", RID_CbC_CODE, 0 }, | |
80 | 372 ... |
373 | |
73 | 374 case RID_CbC_CODE: |
375 : | |
376 specs->typespec_word = cts_CbC_code; | |
80 | 377 ... |
378 | |
73 | 379 case cts_CbC_code: |
380 : | |
381 specs->type = void_type_node; | |
382 break; | |
80 | 383 --> |
384 <!--PAGE--> | |
73 | 385 <div class="slide"> |
77 | 386 <h1>CbCの実装:gotoシンタックスの追加</h1> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
387 <li>goto によるコードセグメントへの継続</li> |
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
388 <ul> |
80 | 389 <li>通常の goto の構文にコードセグメントへ継続する処理を追加。</li> |
390 <!-- | |
63
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
391 <li>コードセグメントへのgotoの後に、returnの処理を自動で追加。</li> |
80 | 392 --> |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
393 </ul> |
80 | 394 <table width=100% border=1> |
395 <tr> | |
396 <td> | |
397 <pre class="srcbox" style="font-size:25px; height:20em;" > | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
398 case RID_GOTO: |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
399 c_parser_consume_token (parser); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
400 if ( c_parser_next_token_is (parser, CPP_NAME) |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
401 && c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON ) |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
402 { |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
403 stmt = c_finish_goto_label (loc, |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
404 c_parser_peek_token (parser)->value); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
405 c_parser_consume_token (parser); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
406 } |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
407 else if (c_parser_next_token_is (parser, CPP_MULT)) |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
408 { |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
409 tree val; |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
410 |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
411 c_parser_consume_token (parser); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
412 val = c_parser_expression (parser).value; |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
413 mark_exp_read (val); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
414 stmt = c_finish_goto_ptr (loc, val); |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
415 } |
80 | 416 #ifndef noCbC |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
417 else |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
418 { |
80 | 419 if (c_parser_next_token_is (parser, CPP_NAME)) |
420 { | |
421 tree id = c_parser_peek_token (parser)->value; | |
422 location_t loc = c_parser_peek_token (parser)->location; | |
423 /** build_external_ref (id,RID_CbC_CODE , loc); **/ | |
424 build_external_ref (loc, id, RID_CbC_CODE, &expr.original_type); | |
425 } | |
426 expr = c_parser_expr_no_commas (parser, NULL); | |
427 if (TREE_CODE(expr.value) == CALL_EXPR ) | |
428 { | |
429 location_t loc = c_parser_peek_token (parser)->location; | |
430 cbc_replace_arguments (loc, expr.value); | |
431 TREE_TYPE(expr.value) = void_type_node; | |
432 CbC_IS_CbC_GOTO (expr.value) = 1; | |
433 CALL_EXPR_TAILCALL (expr.value) = 1; | |
434 add_stmt(expr.value); | |
435 stmt = c_finish_return(loc, NULL_TREE, NULL_TREE); | |
436 } | |
437 else | |
438 c_parser_error (parser, "expected code segment jump or %<*%>"); | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
439 } |
80 | 440 #else |
60
a21d16da431a
modify addition of goto syntax
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
59
diff
changeset
|
441 </pre> |
80 | 442 </td> |
443 </tr> | |
444 </table> | |
54 | 445 </div> |
446 <!-- PAGE --> | |
447 <div class="slide"> | |
77 | 448 <h1>CbCの実装:gotoシンタックスの追加</h1> |
73 | 449 <ul> |
77 | 450 <small> |
451 <li>cbc_replace_arguments関数は引数のデータを一時的な変数へ避難させる。</li> | |
452 <li>CALL_EXPR_TAILCALLマクロでtail callフラグを立てる。</li> | |
453 <li>最後にc_finish_return関数によりreturn文を生成している。</li> | |
454 </small> | |
73 | 455 </ul> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
456 <table border=1 width=100%> |
73 | 457 <!-- |
458 <caption><small>return 自動生成</small></caption> | |
459 --> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
460 <tr class="center"> |
77 | 461 <td><small>実際のコード</small></td> |
462 <td><small>GCC内で処理されるコード</small></td> | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
463 </tr> |
73 | 464 <tr class="srctr"> |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
465 <td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
466 <pre> |
73 | 467 |
468 __code test() { | |
469 : | |
470 goto factorial0(1, x); | |
471 } | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
472 </pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
473 </td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
474 <td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
475 <pre> |
73 | 476 |
477 void test() { | |
478 : | |
479 factorial0(1, x); | |
480 return; | |
481 } | |
55
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
482 </pre> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
483 </td> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
484 </tr> |
06ce8fb8e278
modify presen/index.html
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
54
diff
changeset
|
485 </table> |
77 | 486 <ul> |
80 | 487 <li><small>これで__codeによるコードセグメントの宣言と、gotoによる関数呼び出しが行われるようになった。</small></li> |
488 <li class="incremental"><small>次に、コードセグメントへの関数呼び出しは軽量継続で行わせる処理がいる。</small></li> | |
489 <!-- | |
77 | 490 <li><small>tail callフラグを立てることで、関数呼び出しに末尾除去(末尾最適化)をかけることができる。</small></li> |
491 <li><small>最後のリターン文生成も、末尾除去にかける為に必要な処理。</small></li> | |
80 | 492 --> |
77 | 493 </ul> |
63
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
494 </div> |
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
495 <!-- PAGE --> |
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
496 <div class="slide"> |
80 | 497 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
498 <h2>軽量継続は<font color=red>末尾除去(Tail Call elimination)</font>によって実装される。</h2> | |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
499 <ul> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
500 <li>関数呼び出しをcallではなくjmp命令で行う最適化。</li> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
501 </ul> |
73 | 502 <li><small>以下のソースの場合 関数g から関数f へjmp命令で処理が移る。</small></li> |
71 | 503 <br> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
504 <table width=100%> |
71 | 505 <tr class="srctr"> |
506 <td width=50%> | |
73 | 507 <!-- |
71 | 508 <pre class="srcbox"> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
509 int main() { |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
510 int num = a(2); |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
511 printf("main:num=%d\n",num); |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
512 return 0; |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
513 } |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
514 int a(int num) { |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
515 return b(num+5); |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
516 } |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
517 int b(int num) { |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
518 printf("b:a = %d\n",num); |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
519 return num+3; |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
520 } |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
521 </pre> |
73 | 522 --> |
523 <pre class="srcbox"> | |
524 | |
525 void f(int a, int b) { | |
526 printf("f: a=%d b=%d\n",a,b); | |
527 return ; | |
528 } | |
529 void g(int a, int b){ | |
530 printf("g: a=%d b=%d\n",a,b); | |
531 f(a,b); | |
532 return; | |
533 } | |
534 | |
535 int main() { | |
536 g(3,4); | |
537 return 0; | |
538 } | |
539 | |
540 </pre> | |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
541 </td> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
542 <td class="center"> |
80 | 543 <img src="./pix/continuation.png" style="height:90%;"> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
544 </td> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
545 </tr> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
546 </table> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
547 </div> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
548 <!-- PAGE --> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
549 <div class="slide"> |
80 | 550 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
551 <ul> |
80 | 552 <li>末尾除去にかかる条件</li> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
553 <ul> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
554 <li>caller側とcallee側の戻値の型の一致している。</li> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
555 <li>関数呼び出しがリターン直前に行われている。</li> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
556 <li>呼出先関数の引数に用いられるスタックサイズが呼出元のそれより少ない。</li> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
557 <li>引数の並びのコピーに上書きがない。</li> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
558 </ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
559 <li class="incremental">条件を回避する為以下の実装にする。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
560 <ul class="incremental"> |
80 | 561 <li>コードセグメントの型はvoid型で統一する。</li> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
562 <li>gotoの直後にreturnを置く。</li> |
73 | 563 <li>スタックサイズは固定にする。</li> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
564 <li>引数は一旦、一時変数にコピーする。</li> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
565 </ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
566 </ul> |
69
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
567 </div> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
568 <!-- PAGE --> |
9dc6013b0559
modify explanation of tce
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
68
diff
changeset
|
569 <div class="slide"> |
80 | 570 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
571 <li>末尾除去の条件はexpand_call関数で調べられる。</li> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
572 <ul> |
73 | 573 <li>expand_call関数</li> |
574 <ul> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
575 <li>Treeで表された関数からRTLを生成する関数</li> |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
576 <li>スタックの領域確保、引数の格納、関数へのcall命令の発行が行わる。</li> |
80 | 577 <li>try_taill_call(変数名)フラグがあり、末尾除去の条件に合わなければこのフラグが落とされる。</li> |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
578 </ul> |
73 | 579 <li class="incremental">具体的な実装内容</li> |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
580 <ul> |
73 | 581 <li class="incremental">try_tail_callフラグを落とすif文の条件をかわすようにする。</li> |
582 <li class="incremental">try_tail_callフラグを立たせる処理の追加。</li> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
583 </ul> |
73 | 584 <ul> |
585 | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
586 </div> |
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
587 <!-- PAGE --> |
71 | 588 <div class="slide"> |
80 | 589 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
71 | 590 <li>try_tail_callフラグが落とされる部分</li> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
591 <table width=100%> |
71 | 592 <tr class="srctr"> |
593 <td class="srctd"> | |
594 <pre class="srcbox"> | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
595 |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
596 if (currently_expanding_call++ != 0 |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
597 || ((!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl))) |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
598 && !flag_optimize_sibling_calls) |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
599 || args_size.var |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
600 || dbg_cnt (tail_call) == false) |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
601 try_tail_call = 0; |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
602 |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
603 : |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
604 |
71 | 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; | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
630 |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
631 : |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
632 |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
633 /* Check if caller and callee disagree in promotion of function |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
634 return value. */ |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
635 #ifndef noCbC |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
636 if (try_tail_call && (!fndecl || !CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)))) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
637 #else |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
638 if (try_tail_call) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
639 #endif |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
640 { |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
641 enum machine_mode caller_mode, caller_promoted_mode; |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
642 enum machine_mode callee_mode, callee_promoted_mode; |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
643 int caller_unsignedp, callee_unsignedp; |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
644 tree caller_res = DECL_RESULT (current_function_decl); |
71 | 645 |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
646 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res)); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
647 caller_mode = DECL_MODE (caller_res); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
648 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype)); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
649 callee_mode = TYPE_MODE (TREE_TYPE (funtype)); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
650 caller_promoted_mode |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
651 = promote_function_mode (TREE_TYPE (caller_res), caller_mode, |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
652 &caller_unsignedp, |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
653 TREE_TYPE (current_function_decl), 1); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
654 callee_promoted_mode |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
655 = promote_function_mode (TREE_TYPE (funtype), callee_mode, |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
656 &callee_unsignedp, |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
657 funtype, 1); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
658 if (caller_mode != VOIDmode |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
659 && (caller_promoted_mode != callee_promoted_mode |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
660 || ((caller_mode != caller_promoted_mode |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
661 || callee_mode != callee_promoted_mode) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
662 && (caller_unsignedp != callee_unsignedp |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
663 || GET_MODE_BITSIZE (caller_mode) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
664 < GET_MODE_BITSIZE (callee_mode))))) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
665 try_tail_call = 0; |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
666 } |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
667 </pre> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
668 </td> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
669 </tr> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
670 </table> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
671 <li><string>!CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)により条件を回避</string></li> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
672 </div> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
673 <!-- PAGE --> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
674 <div class="slide"> |
80 | 675 <h1>CbCの実装:軽量継続(末尾除去)</h1> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
676 <li>try_tail_callフラグ矯正付与のソースコード</li> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
677 <table width=100%> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
678 <tr class="srctr"> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
679 <td> |
73 | 680 <pre class="srcbox"> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
681 #ifndef noCbC |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
682 if (fndecl && CbC_IS_CODE_SEGMENT (TREE_TYPE (fndecl)) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
683 && CbC_IS_CODE_SEGMENT (TREE_TYPE (current_function_decl)) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
684 && try_tail_call == 0) |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
685 { |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
686 location_t loc = EXPR_LOCATION (exp); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
687 char *name_callee = IDENTIFIER_POINTER(DECL_NAME(fndecl)); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
688 warning_at (loc, 0, "transition to code segment \"%s\" with CbC goto, but tail call optimization was cut.", |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
689 name_callee); |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
690 try_tail_call = 1; |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
691 } |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
692 #endif |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
693 </pre> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
694 </td> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
695 </tr> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
696 </table> |
73 | 697 <ul> |
80 | 698 <li>try_tail_callフラグが落とされた場合warningを出してフラグを立たせる。<small>(最適化の矯正付与)</small></li> |
73 | 699 </ul> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
700 </div> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
701 <!-- PAGE --> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
702 <div class="slide"> |
80 | 703 <h1>CbCの実装:軽量継続(末尾除去)の実装について</h1> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
704 <ul> |
74 | 705 <li>以前はexpand_call関数を元にしたexpand_cbc_goto関数を作り条件を回避させていた。</li> |
72
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
706 <li>だがその方法だとexpand_call関数の修正にも合わせていく必要もあり管理も面倒であった。</li> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
707 <li>しかしtry_tail_callフラグを落とさせない方法にすることでexpand_cbc_goto関数はいらなくなり、管理が容易くなった。</li> |
48de60dd51d1
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
71
diff
changeset
|
708 </ul> |
63
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
709 </div> |
3cc4a8603489
modify explanation of TCE
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
62
diff
changeset
|
710 <!-- PAGE --> |
77 | 711 <!-- |
73 | 712 <div class="slide"> |
64 | 713 <h1>環境付き継続:論文におけるクロージャの問題の訂正</h1> |
714 <p><small>『GCC 4.6とLionの組み合わせではclosureは正しく動作してないことが分かった。』<br> | |
715 とあるが、これはCbCの実装でTCEを強制的に立てることが原因であったことを訂正させて頂きます。</small></p> | |
716 </div> | |
717 --> | |
718 <!-- PAGE --> | |
719 <div class="slide"> | |
73 | 720 <h1>CbCの実装:引数渡し</h1> |
721 <li>GCC版コンパイラー開発当初、コンパイルしたCbCのプログラムはMicro-C版に速度面で勝てなかった。</li> | |
722 <ul> | |
723 <li class="incremental">Micro-Cでは関数呼び出しの際にできるだけレジスタを使うようにしていた。</li> | |
724 </ul> | |
725 <li class="incremental">そこで、GCC版CbCコンパイラの引数渡しもできるだけレジスタで行うことに。</li> | |
726 </div> | |
727 <!-- PAGE --> | |
728 <div class="slide"> | |
729 <h1>CbCの実装:引数渡し(fastcall)</h1> | |
730 <h2>fastcall</h2> | |
731 <ul> | |
732 <li>i386 において関数呼び出しの際、引数渡しをできるだけレジスタを用いるGCCの拡張機能。</li> | |
733 <li>関数に『__attribute__ ((fastcall))』をつけることで使えるようになる。</li> | |
734 </ul> | |
735 <li>__codeで宣言された関数は自動でfastcall属性が付与されるように以下のコードを追加。</li> | |
736 <small> | |
737 <pre> | |
738 if(!TARGET_64BIT) { | |
739 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); | |
740 declspecs_add_attrs(specs, attrs); | |
741 } | |
742 </pre> | |
743 </small> | |
744 <p><small>Intel64 ではレジスタが増えている為、fastcallは標準でつくようになっている。</small></p> | |
745 </div> | |
746 <!-- PAGE --> | |
747 <div class="slide"> | |
748 <h1>CbCの実装:引数渡し</h1> | |
749 <ul> | |
750 <li>fastcall属性の付与によりMicro-C版に速度で勝るようになった。</li> | |
751 </ul> | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
752 <br> |
73 | 753 <table width=100% border=1 class="center"> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
754 <caption><small>引数渡しに使われるレジスタの数(gcc)</small></caption> |
73 | 755 <tr> |
756 <td>arch</td> | |
757 <td>int(整数型)</td> | |
758 <td>float(浮動小数点型)</td> | |
759 <td>double(浮動小数点型)</td> | |
760 </tr> | |
761 <tr> | |
762 <td>i386</td> | |
763 <td>2</td> | |
764 <td>0<br>(stackを使用)</td> | |
765 <td>0<br>(stackを使用)</td> | |
766 </tr> | |
767 <tr> | |
77 | 768 <td>x64</td> |
73 | 769 <td>6</td> |
770 <td>8</td> | |
771 <td>8</td> | |
772 </tr> | |
773 </table> | |
774 </div> | |
775 <!-- PAGE --> | |
776 <div class="slide"> | |
64 | 777 <h1>CbCの実装:環境付き継続</h1> |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
778 <ul> |
64 | 779 <li>CbCにおけるCとの互換性を保つための機能。コードセグメントを呼び出したCの関数に戻ることができる。</li> |
780 <li>__returnキーワードを引数に渡すことで使うことができる。</li> | |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
781 </ul> |
64 | 782 <li>以下の使い方の場合は1を返す。</li> |
71 | 783 <table border=1 width=100%> |
784 <td> | |
64 | 785 <small> |
71 | 786 <pre class="srcbox"> |
64 | 787 __code c1(__code ret(int,void *),void *env) { |
788 goto ret(1,env); | |
789 } | |
790 int main() { | |
791 goto c1(__return, __environment); | |
792 } | |
793 </pre> | |
71 | 794 </small> |
795 </td> | |
796 </table> | |
77 | 797 <p><small>__environmentキーワードは関数の環境を保持する(Micro-Cの場合)。</small></p> |
54 | 798 </div> |
799 <!-- PAGE --> | |
800 <div class="slide"> | |
64 | 801 <h1>CbCの実装:環境付き継続</h1> |
74 | 802 <!-- |
73 | 803 <li><small>生成しているコードと生成する為のコード</small></li> |
74 | 804 --> |
73 | 805 <table border=1 width=100%> |
806 <tr> | |
807 <td><small>生成しているコード</small></td> | |
80 | 808 <td><small>生成するコード(GCC内部)</small></td> |
73 | 809 </tr> |
810 <tr class="srctr"> | |
811 <td width=50% class="srctd"> | |
812 <pre class="srcbox" style="width:25em;"> | |
64 | 813 |
74 | 814 //goto c1(__return, __environment); |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
815 goto c1(({ |
64 | 816 __label__ _cbc_exit0; |
817 static int retval; | |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
818 void _cbc_internal_return(int retval_, void *_envp) { |
64 | 819 retval = retval_; |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
820 goto _cbc_exit0; |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
821 } |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
822 if (0) { |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
823 _cbc_exit0: |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
824 return retval; |
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
825 } |
64 | 826 _cbc_internal_return; |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
827 }), __environment); |
64 | 828 </pre> |
73 | 829 </td> |
74 | 830 <td class="srctd"> |
73 | 831 <pre class="srcbox" style="width:25em;"> |
74 | 832 |
73 | 833 case RID_CbC_RET: |
64 | 834 { |
835 tree value, stmt, label, tlab, decl; | |
836 c_parser_consume_token (parser); | |
837 | |
838 stmt = c_begin_stmt_expr (); | |
839 cbc_return_f = c_parser_peek_token (parser)->value; | |
840 location_t location = c_parser_peek_token (parser)->location; | |
841 | |
842 /* create label. (__label__ _cbc_exit0;) */ | |
843 label = get_identifier ("_cbc_exit0"); | |
844 tlab = declare_label (label); | |
845 C_DECLARED_LABEL_FLAG (tlab) = 1; | |
846 add_stmt (build_stmt (location, DECL_EXPR, tlab)); | |
847 | |
848 /* declare retval. (int retval;) */ | |
849 tree decl_cond = | |
850 build_decl (location, VAR_DECL, get_identifier ("retval"), | |
851 TREE_TYPE (TREE_TYPE (current_function_decl))); | |
852 TREE_STATIC (decl_cond) = 1; | |
853 TREE_USED (decl_cond) = 1; | |
854 | |
855 /* Use thread-local */ | |
856 DECL_TLS_MODEL (decl_cond) = decl_default_tls_model (decl_cond); | |
857 DECL_NONLOCAL (decl_cond) = 1; | |
858 add_stmt (build_stmt(location, DECL_EXPR, pushdecl (decl_cond))); | |
859 | |
860 /* define nested function. */ | |
861 decl = | |
862 cbc_finish_nested_function (location, label, decl_cond); | |
863 TREE_USED(decl) = 1; | |
864 | |
865 /* define if-ed goto label and return statement. */ | |
866 cbc_finish_labeled_goto (location, label, decl_cond); | |
867 | |
868 /* get pointer to nested function. */ | |
869 value = build_addr (decl , current_function_decl); | |
870 TREE_USED (current_function_decl) = 1; | |
871 SET_EXPR_LOCATION (value, location); | |
872 add_stmt (value); | |
873 | |
874 TREE_SIDE_EFFECTS (stmt) = 1; | |
875 expr.value = c_finish_stmt_expr (location, stmt); | |
876 expr.original_code = ERROR_MARK; | |
877 } | |
74 | 878 </pre> |
73 | 879 </td> |
80 | 880 </td> |
881 </tr> | |
882 </table> | |
883 <li><small>retval変数の型は継続を行った関数と同じ戻値の型となる。</small></li> | |
884 <!-- | |
885 <li class="incremental">上記のコードをGCC内で生成すると次のようなTreeができる。</li> | |
886 --> | |
887 </div> | |
888 <!-- PAGE --> | |
889 <!-- | |
890 <div class="slide"> | |
891 <h1>CbCの実装:環境付き継続</h1> | |
892 <table border=1 width=100%> | |
893 <tr> | |
894 <td width=50%><small>生成されるTree</small></td> | |
895 <td width=50%><small>生成する為のコード</small></td> | |
896 </tr> | |
897 <tr class="srctr"> | |
898 <td class="srctd"> | |
899 <img src="./pix/STATEMENT_LIST_1.png" style="height: 10em;"> | |
900 </td> | |
73 | 901 </tr> |
74 | 902 </table> |
80 | 903 </div> |
64 | 904 --> |
905 <!-- PAGE --> | |
906 <div class="slide"> | |
907 <h1>環境付き継続:実装の問題</h1> | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
908 <li>重要な部分</li> |
64 | 909 <ul> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
910 <li>リターンするretval変数のメモリ確保</li> |
64 | 911 </ul> |
912 <li>次の方法が考えられる。</li> | |
913 <ul> | |
914 <li>クロージャでの確保</li> | |
915 <li>staticでの確保</li> | |
80 | 916 <li>static thread local storage(tls)を用いての確保</li> |
917 <!-- | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
918 <li>setjmpを用いての実装</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
919 <li>戻り値を入れるレジスタを明示的に指定</li> |
80 | 920 --> |
64 | 921 </ul> |
922 </div> | |
923 <!-- PAGE --> | |
924 <div class="slide"> | |
925 <h1>環境付き継続:実装の問題</h1> | |
54 | 926 <ul> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
927 <li>クロージャでの実装の問題点:</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
928 <!-- <ul><li>クロージャにしてスタックに値を確保する。</li></ul> --> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
929 <ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
930 <li >CbCでは継続によりスタックの値は破棄されていく。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
931 <li >クロージャにしたコードが破棄される可能性がある。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
932 </ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
933 |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
934 <li>staticでの実装の問題点:</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
935 <!-- <ul><li>静的に値を確保することでスタック破棄の影響を受けない。</li></ul> --> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
936 <ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
937 <li >マルチスレッドのプログラムに対応できない。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
938 <li >値を返し切る前に別スレッドによって値が書き換えられる可能性がある。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
939 </ul> |
80 | 940 <li class="incremental">static tlsでの実装</li> |
941 <!-- <ul> <li>スレッド毎に静的に値を確保する。</li></ul>--> | |
942 <ul class="incremental"> | |
943 <li>現在はこの方法で実装を行なっている。</li> | |
944 <li>しかし、最適化にかけると正しい値が返ってこない。 | |
945 <br>(最適化によりコードが削除されている...?)</li> | |
946 </ul> | |
947 </div> | |
948 <!-- PAGE --> | |
949 <div class="slide"> | |
950 <h1>クロージャの動作について</h1> | |
951 <li>予稿における訂正</li> | |
952 <li>『GCC 4.6 と Lion の組合せでは Closure は正しく動作していないことが分かった.』</li> | |
953 <ul> | |
954 <li>CbCの末尾除去矯正付与のせいでクロージャが破壊されていたことが判明。</li> | |
955 <li>GCC 4.6 と Lion でのクロージャは特に問題はなかった。</li> | |
956 </ul> | |
957 </div> | |
958 <!-- PAGE --> | |
959 <!-- | |
960 <div class="slide"> | |
961 <h1>環境付き継続:実装の問題</h1> | |
962 <ul> | |
963 <li>setjmpでの実装の問題点:</li> | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
964 <ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
965 <li>setjmpを行うTreeを生成するのが少し手間になる。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
966 <li>int型の戻値しか得られない。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
967 </ul> |
80 | 968 |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
969 </ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
970 <li>戻値を入れるレジスタを明示的に指定する。</li> |
64 | 971 <ul> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
972 <li>まだ実装を試していない。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
973 </ul> |
64 | 974 </ul> |
54 | 975 </div> |
80 | 976 --> |
54 | 977 <!-- PAGE --> |
978 <div class="slide"> | |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
979 <h1>Micro-Cとの比較</h1> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
980 <table width=100% class="center"> |
80 | 981 <caption><small>Micro-C,GCC-4.4とGCC-4.6のCbCコンパイラでコンパイルしたプログラムの実行の速度</small></caption> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
982 <td> |
80 | 983 <img src="./pix/mac_conv.png" style="height:10em"> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
984 </td> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
985 <td> |
80 | 986 <img src="./pix/linux_conv.png" style="height:10em"> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
987 </td> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
988 </table> |
80 | 989 <li><small>GCC版の最適化無しの場合、引数を全て一時変数に代入するという処理が入る。 |
990 その為に明らかに遅くなっていることが分かる。</small></li> | |
991 <li><small>だがGCCの最適化有りの場合はMicro-C版よりも早い。</small></li> | |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
992 </div> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
993 <!-- PAGE --> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
994 <div class="slide"> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
995 <h1>まとめ</h1> |
77 | 996 <ul> |
997 <li>今回GCC版CbCコンパイラのアップデートを行った。</li> | |
80 | 998 <li>末尾除去にかかる判定の部分の実装の修正を行った。 |
999 <br>それにより、以前より楽な管理ができる実装にすることができた。</li> | |
1000 <li>後は環境付き継続の最適化の問題の修正とselftypeといった新しい実装を行う。</li> | |
77 | 1001 <li>全ての実装を終えたらGCC版CbCコンパイラの実装はアップデートを行なっていくだけとなる。</li> |
1002 </ul> | |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1003 </div> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1004 <!-- PAGE --> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1005 <div class="slide"> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1006 <h1>今後の予定</h1> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1007 <ul> |
77 | 1008 <li>CbCを用いたプログラムの作成</li> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1009 <ul> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1010 <li>CbCによるタスクマネージャの作成</li> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1011 </ul> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1012 <li>llvmへのCbCの実装</li> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1013 </ul> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1014 <br> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1015 <h2 class="incremental" style="font-weight: bold;">ご清聴ありがとうございました。</h2> |
77 | 1016 </div> |
76
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1017 <!-- PAGE --> |
a4d16779fd1e
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
75
diff
changeset
|
1018 <div class="slide"> |
80 | 1019 <h1>CbCの引数渡し</h1> |
1020 <table border=1 width=100%> | |
1021 <caption><small>fastcall属性有・無の実行速度</small></caption> | |
1022 <tr class="center"> | |
1023 <td width=50%><small>fastcall有り</small></td> | |
1024 <td width=50%><small>fastcall無し</small></td> | |
1025 </tr> | |
1026 <tr class="center"> | |
1027 <td> | |
1028 <img src="./pix/linux_conv_fastcall.png"> | |
1029 </td> | |
1030 <td> | |
1031 <img src="./pix/linux_conv_nofastcall.png"> | |
1032 </td> | |
1033 </tr> | |
1034 </table> | |
1035 </div> | |
1036 <!-- PAGE --> | |
1037 <div class="slide"> | |
1038 <h1>CbCの実装:軽量継続(末尾除去)の動作</h1> | |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1039 <li>スタック:呼び出し元関数と同じ範囲を使うことになる。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1040 <table width=100% border=1> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1041 <td> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1042 <p class="center"> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1043 <img src="./pix/tce.png" style="height: 6em;"> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1044 </p> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1045 </td> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1046 <td> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1047 <ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1048 <li><small>func_bの引数はfunc_aのスタックに上書する</small></li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1049 <li><small>func_bの為にスタックポインタは伸ばされない</small></li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1050 </ul> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1051 </td> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1052 </table> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1053 <li>CbCにおけるコードセグメントへの継続はこのTCEを用いて実装されている。</li> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1054 </div> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1055 <!-- PAGE --> |
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1056 <div class="slide"> |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
1057 <h1>CbCの機能の拡張:__rectype の実装</h1> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1058 <ul> |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1059 <li>通常、関数の引数に関数ポインタを渡した際は以下の様に使われる。</li> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1060 <pre style="font-size:28px;"> |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1061 void factorial(int n, int result, void(*print)()){ |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1062 : |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1063 (*print)(n,result,print,exit1, envp); |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1064 } |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1065 </pre> |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1066 <li>そこで、__rectype という予約後を作り、以下の宣言を行えるようにした。</li> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1067 <pre style="font-size:28px;"> |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1068 __code factorial(int n, int result, __rectype *print) { |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1069 : |
70
79894ca66a9a
modify explanation of GCC
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
1070 goto (*print)(n,result,print,exit1, envp); |
57
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1071 } |
ce844f6c504d
modify __rectype
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1072 </pre> |
78
6465e96ba272
modify explanation of continuation with environment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
1073 </ul> |
54 | 1074 </div> |
1075 <!-- PAGE --> | |
1076 <div class="slide"> | |
68
1399414ea3f6
modify explanation of Generic Tree
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
66
diff
changeset
|
1077 <h1>CbCの機能の拡張:selftype</h1> |
64 | 1078 <h2>selftypeの実装</h2> |
1079 <li>以下の宣言が行えるようにしたい。</li> | |
1080 <small> | |
1081 <pre> | |
1082 typedef sturct node { | |
1083 selftype *left; | |
1084 selftype *right; | |
1085 int num; | |
1086 }*NODE | |
1087 </pre> | |
1088 <p>selftype は struct node を指す。</p> | |
1089 </small> | |
1090 <ul> | |
1091 <li>上記の構文は実装を行う予定である。</li> | |
1092 </ul> | |
1093 </div> | |
1094 <!-- PAGE --> | |
54 | 1095 </div> |
1096 </body> | |
1097 </html> |