annotate slide.tex @ 9:5915da9d55db default tip

finish
author kent
date Wed, 23 Apr 2008 14:43:35 +0900
parents 0cca1c3a062d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
1 % File: slide.tex
bfb290984b07 create slide.tex
kent
parents:
diff changeset
2 % Created: 月 4 21 08:00 PM 2008 J
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
3 % Last Change: 月 4 22 17:18 PM 2008 J
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
4 %
bfb290984b07 create slide.tex
kent
parents:
diff changeset
5 \documentclass[mathserif]{beamer}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
6 \usepackage{graphicx}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
7 \usepackage{verbatim}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
8 %\usepackage{beamerthemesplit}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
9 %manual% open /usr/local/ptetex/share/texmf-dist/doc/latex/beamer/beameruserguide.pdf
bfb290984b07 create slide.tex
kent
parents:
diff changeset
10
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
11 \title[CbC on GCC]{Continuation based CコンパイラのGCC-4.2による実装}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
12 \author{与儀 健人 \and 河野真治}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
13 \institute[IE Ryukyu Univ]{琉球大学大学院理工学研究科情報工学専攻}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
14 \date{\today}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
15
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
16 \usetheme{Boadilla}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
17 %\usetheme{default}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
18 %\useoutertheme[subsection=false]{smoothbars}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
19 %\useoutertheme{infolines}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
20 \renewcommand{\kanjifamilydefault}{gt}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
21
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
22 \begin{document}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
23
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
24 \begin{frame}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
25 \titlepage
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
26 \end{frame}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
27
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
28 \section{背景}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
29 \begin{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
30 \frametitle{研究背景}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
31 \begin{itemize}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
32 \item Continuation based C (CbC)
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
33 \item Micro-CによるCbCコンパイラの実装
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
34 \item GCCでCbCコンパイラを実装する方法が分かっている
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
35 \end{itemize}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
36 \end{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
37 \begin{comment}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
38 私たちの研究室ではCbCという言語を提案しています。
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
39 CbCはCから関数の概念を取り払って、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
40 代わりにコードセグメントという処理単位を追加したものです。詳しくは
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
41
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
42 CbCはこれまでMicro-Cというコンパイラを本研究室で独自に改良したもの
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
43 つかってコンパイルしていました。
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
44 このMicro-CもGCCとくらべて遜色ないほど、良いコードをはくのですが
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
45 はやり、UNIXの標準的なコンパイラであるGCCでコンパイルしたい
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
46
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
47 また、以前の論文によりTail callを使ったGCCへの実装方法がしめされた。
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
48 そこで、本研究ではCbCのGCCへの実装を行いましたので、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
49 その評価と合わせて報告したいと思います
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
50 \end{comment}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
51
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
52
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
53 \section{CbC}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
54 \begin{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
55 \frametitle{Continuation based Cについて}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
56 \begin{exampleblock}{What is it?}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
57 \begin{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
58 \item 琉球大学 並列信頼研究室で開発
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
59 \item 構文はC言語とほぼ同じ
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
60 \item 関数の除去、コードセグメントの追加
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
61 \item コードセグメントを繋ぐ``継続''を導入
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
62 \end{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
63 \end{exampleblock}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
64 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
65 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
66 まずは、本研究室が提案しているCbCについて少し説明します
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
67 構文はC言語とほぼ同じです
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
68 ただし Cから関数や、while,forなどのloopを除去し
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
69 code segmentという処理の単位を追加しています
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
70 また、code segmentどうしの移動(これを継続と呼びます)
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
71 をgotoを使って表します
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
72 ...聴いても分かりにくいと思うので、コード例をみましょう
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
73 \end{comment}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
74
bfb290984b07 create slide.tex
kent
parents:
diff changeset
75 \begin{frame}[fragile]
bfb290984b07 create slide.tex
kent
parents:
diff changeset
76 \frametitle{CbCコード例}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
77 \begin{columns}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
78 \column{.4\textwidth}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
79 \flushleft \small
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
80 \begin{verbatim}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
81 __code while_process(int total,int count){
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
82 total += count;
bfb290984b07 create slide.tex
kent
parents:
diff changeset
83 count++;
bfb290984b07 create slide.tex
kent
parents:
diff changeset
84 goto while_cond(total, count);
bfb290984b07 create slide.tex
kent
parents:
diff changeset
85 }
bfb290984b07 create slide.tex
kent
parents:
diff changeset
86 __code while_cond(int total, int count){
bfb290984b07 create slide.tex
kent
parents:
diff changeset
87 if ( count <= 100 ){
bfb290984b07 create slide.tex
kent
parents:
diff changeset
88 goto while_process(total, count);
bfb290984b07 create slide.tex
kent
parents:
diff changeset
89 }else{
bfb290984b07 create slide.tex
kent
parents:
diff changeset
90 goto while_end(total);
bfb290984b07 create slide.tex
kent
parents:
diff changeset
91 }
bfb290984b07 create slide.tex
kent
parents:
diff changeset
92 }
bfb290984b07 create slide.tex
kent
parents:
diff changeset
93 __code while_end(int total){
bfb290984b07 create slide.tex
kent
parents:
diff changeset
94 goto cs_exit(0);
bfb290984b07 create slide.tex
kent
parents:
diff changeset
95 }
bfb290984b07 create slide.tex
kent
parents:
diff changeset
96 \end{verbatim}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
97 \column{.1\textwidth}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
98 \column{.3\textwidth}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
99 \flushright
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
100 \includegraphics[width=\textwidth]{figures/CbC-loop.eps}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
101 \end{columns}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
102 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
103 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
104 見にくい?
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
105 これはCのwhile文をcode segmentにしたものです
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
106 みての通り、_ _codeという関数の様なものが三つあります
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
107 この一つずつがコードセグメントです
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
108 最初に while_condが実行されます これは条件判定ですね
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
109 .. .
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
110 簡単でしたが、少し分かっていただけたでしょうか?
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
111 \end{comment}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
112
bfb290984b07 create slide.tex
kent
parents:
diff changeset
113 \begin{frame}[fragile]
bfb290984b07 create slide.tex
kent
parents:
diff changeset
114 \frametitle{実装に必要な構文}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
115 \begin{itemize}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
116 \large
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
117 \item \verb|__code cs(int a, char *b)|
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
118 \item \verb|goto cs(10, "abc");|
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
119 \end{itemize}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
120 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
121 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
122 実装に必要な構文を説明します
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
123 まずはcode segmentの定義です コード例にもあったように、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
124 コードセグメントの定義や宣言、コードセグメントポインタの宣言などをこの構文で行えます
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
125 つぎにgoto.
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
126 この二つを実装することでCbCを動作させることができます
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
127 \end{comment}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
128
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
129 \section{GCC}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
130 \begin{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
131 \frametitle{GNU Compiler Collection}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
132 \begin{itemize}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
133 \item UNIXにおける標準的なコンパイラ
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
134 \item C, C++, java, FORTRAN, Ada ..
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
135 \item i386, PowerPC, MIPS, SPARC ..
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
136 \item 強力な最適化機構
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
137 \item コンパイルだけでなくas, ldなどの統合環境
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
138 \end{itemize}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
139 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
140 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
141 GNU Compiler Collection
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
142 .. . ですが、皆さん良くご存知だと思いますので、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
143 ここではGCCの内部構造について簡単に説明します
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
144 \end{comment}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
145
bfb290984b07 create slide.tex
kent
parents:
diff changeset
146 \begin{frame}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
147 \frametitle{GCCコンパイルパス}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
148 \begin{columns}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
149 \column{.5\textwidth}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
150 \includegraphics[width=\textwidth]{figures/GCC-pass-slide.eps}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
151 \column{.4\textwidth}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
152 \begin{description}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
153 \item[Generic Tree] 構文木
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
154 \item[GIMPLE] SSA
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
155 \item[RTL] 中間コード
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
156 \end{description}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
157 \end{columns}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
158 \end{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
159 \begin{comment}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
160 図は GCCがどのようにコンパイルを進めるかを表したものです
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
161 パーサによってGenericに変換
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
162 一般的にいう構文木、言語の構造をそのままツリーにしている
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
163
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
164 次にGEnericはGimplifyというpassによってGIMPLEに変換されます
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
165 Static Single Assignment
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
166 データ構造自体はGenericとかわりまりませんが、いろいろ制約が加わります
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
167
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
168 RTLに変換
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
169 アーキテクチャに依存しないアセンブラ
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
170
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
171 * 実装の際にはParserにのみ変更を加えることで、アーキテクチャへの依存がなくなる
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
172 今回の実装でどの部分を変更したのか
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
173 コードセグメントや継続のパースのためにParserを修正
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
174 それらの構文を表すGeneric Treeを作る
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
175 そのTreeをRTLに変換するRTLGenerator を修正
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
176
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
177 そこで、Tailcalleliminationについて説明します
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
178 \end{comment}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
179
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
180
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
181 \section{Tail call}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
182 \begin{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
183 \frametitle{Tail call elimination}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
184 \includegraphics[width=.9\textwidth]{figures/GCC-TailCall.eps}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
185 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
186 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
187 このTail call EliminationはGCCの最適化の一つで、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
188 「関数の最後に別の関数を呼び出してる場合は、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
189 callじゃなくてjmpでいいじゃないか」
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
190 というアイデアをもとに設計されてます
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
191
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
192 図を見ていただくと分かるとおり、ここでは関数main, A, B
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
193 を定義しています
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
194 そして関数Aでは最後に関数Bを呼び出しています
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
195 この場合、mainからAをよび、AからBをよび、
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
196 Bが終わるとAに戻り、すぐにret命令でmainにもどるという処理になります
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
197
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
198 ですが、明らかにAに戻るのは無駄でしょう
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
199 この無駄はAからBを呼ぶ際にcallでなくjmpを使うことで回避できます
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
200 これが単純なTail callの例です
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
201
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
202 ですが、たった1命令で最適化と言えるのか?
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
203 \end{comment}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
204
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
205 \begin{frame}[fragile]
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
206 \begin{columns}[t]
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
207 \column{.5\textwidth}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
208 \begin{verbatim}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
209 A:
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
210 pushl %ebp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
211 movl %esp, %ebp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
212 subl $24, %esp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
213 movl 20(%ebp), %eax
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
214 addl 16(%ebp), %eax
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
215 movl %eax, 8(%esp)
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
216 movl 12(%ebp), %eax
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
217 movl %eax, 4(%esp)
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
218 movl 8(%ebp), %eax
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
219 movl %eax, (%esp)
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
220 call B
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
221 leave
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
222 ret
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
223 \end{verbatim}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
224 \column{.5\textwidth}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
225 \begin{verbatim}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
226 A:
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
227 pushl %ebp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
228 movl %esp, %ebp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
229 movl 20(%ebp), %eax
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
230 addl %eax, 16(%ebp)
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
231 popl %ebp
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
232 jmp B
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
233 \end{verbatim}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
234 \end{columns}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
235 \end{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
236
bfb290984b07 create slide.tex
kent
parents:
diff changeset
237 \begin{frame}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
238 \frametitle{Tail callの条件}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
239 \begin{enumerate}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
240 \item 関数コールがreturnの直前にある
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
241 \item 関数の返す型がcallerとcalleeで一致している
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
242 \item caller側の引数サイズがcallee側の引数サイズより大きいもしくは等しい
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
243 \item 書き込んだ引数が、その後書き込む引数を上書きしてはならない
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
244 \end{enumerate}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
245 \center
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
246 \visible<2>{引数をすべて固定数とすることで対応}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
247 \end{frame}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
248
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
249 \section{実装}
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
250 \begin{frame}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
251 \frametitle{実装}
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
252 \begin{itemize}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
253 \item \_\_code トークンの追加
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
254 \item code segmentのパース \hfill Parser \hspace{5em}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
255 \item gotoのパース \hfill Parser \hspace{5em}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
256 \item code segment/goto を表すGeneric Tree
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
257 \item \alert<2>{tree/RTL変換 (expand\_call)} \hfill RTL Generator \hspace{5em}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
258 \item その他(エラー検出など)
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
259 \end{itemize}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
260 \end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
261 \begin{comment}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
262 トークン
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
263 パーサ recursive Decent
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
264 expand_call
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
265 expand_cbc_goto
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
266 \end{comment}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
267
bfb290984b07 create slide.tex
kent
parents:
diff changeset
268 \begin{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
269 \frametitle{expand\_call}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
270 \begin{exampleblock}{What is the function?}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
271 \begin{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
272 \item 関数呼び出しのtreeからRTLへ変換する
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
273 \item Tail callが可能ならその最適化を行う
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
274 \item この関数のみで1200行もある
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
275 \item そのほとんどがTail call可否の判定
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
276 \item そして読みづらい
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
277 \end{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
278 \end{exampleblock}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
279 \end{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
280
bfb290984b07 create slide.tex
kent
parents:
diff changeset
281 \begin{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
282 \frametitle{expand\_cbc\_goto}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
283 \begin{exampleblock}{What is it doing?}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
284 \begin{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
285 \item code segmentへのgotoを表したtreeをRTLに変換
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
286 \item 無駄なTail call可否判定を削除
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
287 \item Tail callの条件を強制
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
288 \item 確実にTail callを適用
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
289 \item 500行程度
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
290 \end{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
291 \end{exampleblock}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
292 \end{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
293
bfb290984b07 create slide.tex
kent
parents:
diff changeset
294
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
295 \section{評価}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
296 \begin{frame}[fragile]
bfb290984b07 create slide.tex
kent
parents:
diff changeset
297 \frametitle{評価(ベンチマーク)}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
298 \begin{itemize}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
299 \item 環境 i386 fedora core
bfb290984b07 create slide.tex
kent
parents:
diff changeset
300 \item 使用したプログラム conv1
7
f8cf4a3ac7a8 $B$R$H$^$:(Bslide.tex$B40@.(B
kent
parents: 6
diff changeset
301 \end{itemize}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
302 \centering
bfb290984b07 create slide.tex
kent
parents:
diff changeset
303 \begin{tabular}{|l|r|r|r|r|} \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
304 & ./conv1 0 & ./conv1 1 & ./conv1 2 & ./conv1 3 \\ \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
305 Micro-C & 5.25 & 8.97 & 2.19 & 2.73 \\ \hline \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
306 GCC & 3.69 & 4.87 & 3.08 & 3.65 \\ \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
307 GCC (+omit) & 2.74 & 4.20 & 2.25 & 2.76 \\ \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
308 GCC (+fastcall) & 2.70 & 3.44 & 1.76 & 2.34 \\ \hline \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
309 TCC & 4.15 &122.28& 84.91&102.59\\ \hline
bfb290984b07 create slide.tex
kent
parents:
diff changeset
310 \end{tabular}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
311 \begin{description}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
312 \item[+omit] -fomit-frame-pointerオプションを付加
bfb290984b07 create slide.tex
kent
parents:
diff changeset
313 \item[+fastcall] \verb|__attribute__ ((fastcall))|を付加
bfb290984b07 create slide.tex
kent
parents:
diff changeset
314 \end{description}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
315 \end{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
316
9
kent
parents: 8
diff changeset
317 %\begin{frame}
kent
parents: 8
diff changeset
318 %\frametitle{考察}
kent
parents: 8
diff changeset
319 %\end{frame}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
320
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
321 \begin{frame}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
322 \frametitle{まとめ}
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
323 \begin{block}{まとめ}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
324 \begin{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
325 \item GCCにCbCコンパイラを実装
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
326 \item そのベンチマーク
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
327 \item 性能向上を確認
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
328 \end{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
329 \end{block}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
330
8
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
331 \begin{block}{TO DO}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
332 \begin{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
333 \item environment
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
334 \item PPCのRTL変換不能
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
335 \item オプションの強制
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
336 \item SPU対応とGCCのversion
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
337 \end{itemize}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
338 \end{block}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
339 \end{frame}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
340
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
341 \appendix
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
342 \begin{frame}
0cca1c3a062d slide $B40@.(B?
kent
parents: 7
diff changeset
343 \includegraphics[width=.9\textwidth]{figures/stack-tailcall.eps}
6
bfb290984b07 create slide.tex
kent
parents:
diff changeset
344 \end{frame}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
345
bfb290984b07 create slide.tex
kent
parents:
diff changeset
346 \end{document}
bfb290984b07 create slide.tex
kent
parents:
diff changeset
347
bfb290984b07 create slide.tex
kent
parents:
diff changeset
348
bfb290984b07 create slide.tex
kent
parents:
diff changeset
349
bfb290984b07 create slide.tex
kent
parents:
diff changeset
350