Mercurial > hg > Papers > 2015 > kaito-lola
annotate cfopm.tex @ 3:c50a033e6635
create presentation slide
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Jul 2015 19:06:07 +0900 |
parents | 771136eae970 |
children | 117760bfcae9 |
rev | line source |
---|---|
0 | 1 \documentclass[conference]{IEEEtran} |
2 | |
3 \usepackage[cmex10]{amsmath} | |
4 \usepackage{url} | |
5 \usepackage{listings} | |
6 \usepackage[dvipdfmx]{graphicx} | |
7 | |
8 \lstset{ | |
9 frame=single, | |
10 keepspaces=true, | |
11 stringstyle={\ttfamily}, | |
12 commentstyle={\ttfamily}, | |
13 identifierstyle={\ttfamily}, | |
14 keywordstyle={\ttfamily}, | |
15 basicstyle={\ttfamily}, | |
16 breaklines=true, | |
17 xleftmargin=0zw, | |
18 xrightmargin=0zw, | |
19 framerule=.2pt, | |
20 columns=[l]{fullflexible}, | |
21 numbers=left, | |
22 stepnumber=1, | |
23 numberstyle={\scriptsize}, | |
24 numbersep=1em, | |
25 language=c, | |
26 tabsize=4, | |
27 lineskip=-0.5zw, | |
28 escapechar={@}, | |
29 } | |
30 | |
31 \ifCLASSINFOpdf | |
32 % \usepackage[pdftex]{graphicx} | |
33 % declare the path(s) where your graphic files are | |
34 % \graphicspath{{../pdf/}{../jpeg/}} | |
35 % and their extensions so you won't have to specify these with | |
36 % every instance of \includegraphics | |
37 % \DeclareGraphicsExtensions{.pdf,.jpeg,.png} | |
38 \else | |
39 % or other class option (dvipsone, dvipdf, if not using dvips). graphicx | |
40 % will default to the driver specified in the system graphics.cfg if no | |
41 % driver is specified. | |
42 % \usepackage[dvips]{graphicx} | |
43 % declare the path(s) where your graphic files are | |
44 % \graphicspath{{../eps/}} | |
45 % and their extensions so you won't have to specify these with | |
46 % every instance of \includegraphics | |
47 % \DeclareGraphicsExtensions{.eps} | |
48 \fi | |
49 | |
50 | |
51 % correct bad hyphenation here | |
52 \hyphenation{op-tical net-works semi-conduc-tor} | |
53 | |
54 | |
55 \begin{document} | |
56 % | |
57 % paper title | |
58 % Titles are generally capitalized except for words such as a, an, and, as, | |
59 % at, but, by, for, in, nor, of, on, or, the, to and up, which are usually | |
60 % not capitalized unless they are the first or last word of the title. | |
61 % Linebreaks \\ can be used within to get better formatting as desired. | |
62 % Do not put math or special symbols in the title. | |
63 \title{Implementing Continuation based language in LLVM and Clang} | |
64 | |
65 | |
66 % author names and affiliations | |
67 % use a multiple column layout for up to three different | |
68 % affiliations | |
69 \author{ | |
70 \IEEEauthorblockN{Kaito TOKUMORI} | |
71 \IEEEauthorblockA{University of the Ryukyus \\ Email: kaito@cr.ie.u-ryukyu.ac.jp} | |
72 \and | |
73 \IEEEauthorblockN{Shinji KONO} | |
74 \IEEEauthorblockA{University of the Ryukyus \\ Email: kono@ie.u-ryukyu.ac.jp} | |
75 } | |
76 | |
77 % make the title area | |
78 \maketitle | |
79 | |
80 % As a general rule, do not put math, special symbols or citations | |
81 % in the abstract | |
82 \begin{abstract} | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
83 The programming paradigm which use data segments and code segments are proposed. CbC is a slight modified C for this paradigm. CbC has standalone compiler and GCC(GNU Compiler Collection) version. GCC based CbC compiler is developed in 2008\cite{DBLP:journals/corr/abs-1109-4048} and nested function based goto with environment is implemented in 2011\cite{CbC2011}. In this study, we report a latest CbC compiler which is inplemented in LLVM and Clang 3.7. The detail of implementation and evaluation are shown. |
0 | 84 \end{abstract} |
85 | |
86 % no keywords | |
87 | |
88 | |
89 | |
90 | |
91 % For peer review papers, you can put extra information on the cover | |
92 % page as needed: | |
93 % \ifCLASSOPTIONpeerreview | |
94 % \begin{center} \bfseries EDICS Category: 3-BBND \end{center} | |
95 % \fi | |
96 % | |
97 % For peerreview papers, this IEEEtran command inserts a page break and | |
98 % creates the second title. It will be ignored for other modes. | |
99 \IEEEpeerreviewmaketitle | |
100 | |
101 \section{A Practical Continuation based Language} | |
2 | 102 The proposed units of programming are named code segments and data segments. |
103 Code segments are units of calculation which have no state. | |
104 Data segments are sets of typed data. | |
105 Code segments are connected to data segments by a meta data segment called a context. | |
106 After the execution of a code segment and its context, the next code segment (continuation) is executed. | |
0 | 107 |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
108 Continuation based C (CbC) \cite{DBLP:journals/corr/abs-1109-4048}, hereafter referred to as CbC, is a slight modified C which supports code segments. It is compatible with C and has continuation as a goto statement. |
0 | 109 |
2 | 110 Code segments and data segments are low level enough to represent computational details, |
111 and are architecture independent. They can be used as architecture independent assemblers. | |
0 | 112 |
113 CbC has standalone compiler and GCC version. Here we report new partial implementation of CbC compiler based on LLVM and Clang 3.7. | |
114 | |
115 \section{Continuation based C} | |
2 | 116 CbC's basic programming unit is the code segment. These are not subroutines, but they look like functions because they take input and produce output. Both input and output should be data segments. Table \ref{src:example} details the definition of the data segment. |
0 | 117 |
118 \begin{table}[html] | |
119 \begin{lstlisting} | |
120 __code f(Allocate allocate){ | |
121 allocate.size = 0; | |
122 goto g(allocate); | |
123 } | |
124 | |
125 // data segment definition | |
126 // (generated automatically) | |
127 union Data { | |
128 struct Allocate { | |
129 long size; | |
130 } allocate; | |
131 }; | |
132 \end{lstlisting} | |
133 \caption{CbC Example} | |
134 \label{src:example} | |
135 \end{table} | |
136 | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
137 In this example, the code segment {\bf f} takes the input data segment {\bf allocate} (allocate is the data segments identifier) and sends f's outuput to the code segment {\bf g}. The CbC compiler generates the data segment definition automatically, so writing it is unnecessary. There is no return from code segment {\bf g}. {\bf G} should call another continuation using {\bf goto}. Code segments have input data segments and output data segments. Data segments have two kind of dependency with code segments. |
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
138 First, Code segments access the contents of data segments using field names. So data segments should have the named fields. |
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
139 The second dependency is a data dependency, that is all input data segments should be ready before their execution. |
2 | 140 |
0 | 141 \begin{figure}[htp] |
142 \begin{center} | |
143 \scalebox{0.5}{\includegraphics{fig/csds.pdf}} | |
144 \end{center} | |
1 | 145 \caption{Code Segments and Data Segments on CbC} |
0 | 146 \label{fig:csds} |
147 \end{figure} | |
148 | |
2 | 149 Shifting completely, from C to CbC is unnecessary as in CbC we can go to code segments from C functions and call C functions in code segments The latter is straightforward but the former needs further extensions. |
0 | 150 |
151 \begin{table}[html] | |
152 \begin{lstlisting} | |
153 int main() { | |
154 goto hello("Hello World\n", __return, __environment); | |
155 } | |
156 | |
157 __code hello(char *s, __code(*ret)(int, void*), void *env) { | |
158 printf(s); | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
159 goto (*ret)(123); |
0 | 160 } |
161 \end{lstlisting} | |
162 \caption{Call C Functions in a Code Segment} | |
163 \label{src:example} | |
164 \end{table} | |
165 | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
166 In this hello world example, the environment of {\bf main}() and its continuation is kept in the variable {\bf \_\_environment}. The environment and the continuation can be accessed using {\bf \_\_environment} and {\bf \_\_return}.The arbitrary mixing of code segments and functions is allowed. The continuation of a {\bf goto} statement never returns to the original function, but goes to the caller or the original function. In that case, it returns the result 123 to the operating system. This continuation is called {\bf goto with environment}. |
0 | 167 |
168 \section{LLVM and Clang} | |
2 | 169 The LLVM Project is a collection of modular and reusable compilers and toolchain technologies, and the LLVM Core libraries provide a modern source and target independent optimizer, along with code generation support for many popular CPUs. Clang is an LLVM native C/C++/Objective-C compiler. Figure \ref{fig:structure} shows Clang and LLVM's compilation flow. |
0 | 170 |
171 \begin{figure}[htp] | |
172 \begin{center} | |
173 \scalebox{0.25}{\includegraphics{fig/clang_llvm_structure.pdf}} | |
174 \end{center} | |
175 \caption{LLVM and Clang structure} | |
176 \label{fig:structure} | |
177 \end{figure} | |
178 | |
2 | 179 LLVM has an intermediate representation which is called LLVM IR\cite{LLVMIR}. This part remains unmodified so that the optimization part does not need to be modified. |
0 | 180 |
181 \section{Implementation in LLVM and Clang} | |
2 | 182 The CbC compiler is implemented in LLVM and Clang using the following ideas. |
0 | 183 |
184 \begin{itemize} | |
185 \item Code segments are implemented by C functions. | |
186 \item Transition is implemented by forced tail call. | |
187 \item Goto with environment is implemented by setjmp and longjmp. | |
188 \end{itemize} | |
189 | |
2 | 190 {\bf \_\_code} is implemented as a new type keyword in LLVM and Clang. {\bf \_\_code} is similar to an attribute of a function, which means that the function can only be called in tail call elimination. Because of this implementation, code segments can actually be called as C function calls. |
0 | 191 |
2 | 192 Forcing a tail call requires many conditions be met. For example, there should not be a statement after a tail call, the caller and callee's calling conventions must be the same and their types should be cc10, cc11 or fastcc and the callee's return value type has to be the same as the caller's. |
0 | 193 |
2 | 194 All code segments have the void return type and writing statements after continuation is not allowed. As a result, type problems and after statement problems are solved. |
0 | 195 |
2 | 196 Tail call elimination passes are enabled in {\bf BackendUtil.cpp}. In Clang, when the optimization level is two or more, tail call elimination passing is enable. Here it has been modified to be enabled anytime, however if the optimization level is one or less, tail call elimination passes only work for code segments. |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
197 A calling convention problem was also solved. fastcc was selected for a code segment's calling convention. In Clang, calling conventions are managed by the CGFunctionInfo class and its information is set in {\bf CGCall.ccp} ( a part of CodeGen ), which is where code segments calling conventions were set to fastcc. |
0 | 198 |
2 | 199 Goto with environment is implemented by code rearranging. If the {\bf \_\_environment} or {\bf \_\_return} is declared, the CbC compiler rearranges the code for goto with environment. Setjmp and longjmp are used to do this. setjmp to save the environment before continuation and longjmp to restore it. |
0 | 200 |
201 \section{Result} | |
2 | 202 Table \ref{src:example} shows the benchmark program. |
0 | 203 |
204 \begin{table}[html] | |
205 \begin{lstlisting} | |
206 int f0(int i) { | |
207 int k,j; | |
208 k = 3+i; | |
209 j = g0(i+3); | |
210 return k+4+j; | |
211 } | |
212 | |
213 int g0(int i) { | |
214 return h0(i+4)+i; | |
215 } | |
216 | |
217 int h0(int i) { | |
218 return i+4; | |
219 } | |
220 \end{lstlisting} | |
1 | 221 \caption{benchmark program conv1} |
0 | 222 \label{src:example} |
223 \end{table} | |
224 | |
2 | 225 It is written in C and CbC and there are several optimizations possible. |
226 When the argument is 1, CbC continuation is used. When the argument is 2 or 3, optimization is enabled. | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
227 In this benchmark, inline optimization was omitted. |
2 | 228 The benchmark results are shown in TABLE \ref{result}. |
0 | 229 |
230 \begin{table}[htpb] | |
231 \centering | |
232 \begin{tabular}{|l|r|r|r|} \hline | |
233 & ./conv1 1 & ./conv1 2 & ./conv1 3 \\ \hline | |
234 Micro-C & 6.875 & 2.4562 & 3.105 \\ \hline | |
235 GCC -O2 & 2.9438 & 0.955 & 1.265 \\ \hline | |
236 LLVM/clang -O0 & 5.835 & 4.1887 & 5.0625 \\ \hline | |
237 LLVM/clang -O2 & 3.3875 & 2.29 & 2.5087 \\ \hline | |
238 \end{tabular} | |
239 \caption{Execution time(s)} | |
240 \label{result} | |
241 \end{table} | |
242 | |
3
c50a033e6635
create presentation slide
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
2
diff
changeset
|
243 LLVM and Clang compilers are faster than Micro-C when optimization is enabled. This means CbC get benefits from LLVM optimizations. The LLVM and Clang complier is slower than GCC, but GCC cannot compile safely without optimization. This means LLVM can compile more reliably than GCC. |
0 | 244 |
245 \section{Conclusion} | |
2 | 246 This Continuation based language has been designed and implemented for practical use. CbC has been partially implemented using LLVM and Clang 3.7. |
247 CbC can use LLVM's optimization. LLVM IR was not modified to implement CbC's compiler. | |
0 | 248 |
2 | 249 In the future, data segments, meta code segments and meta data segments for meta computation will be designed and implemented. |
0 | 250 \nocite{opac-b1092711, LLVMIR, LLVM, clang} |
251 \bibliographystyle{IEEEtran} | |
252 \bibliography{IEEEabrv,reference} | |
253 | |
254 | |
255 | |
256 % that's all folks | |
257 \end{document} |