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