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