Mercurial > hg > Papers > 2015 > kaito-lola
comparison presentation/presen.html @ 3:c50a033e6635
create presentation slide
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Jul 2015 19:06:07 +0900 |
parents | |
children | 20257f618ddd |
comparison
equal
deleted
inserted
replaced
2:771136eae970 | 3:c50a033e6635 |
---|---|
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <meta charset='utf-8'> | |
5 <title>Presen</title> | |
6 <!-- style sheet links --> | |
7 <link rel="stylesheet/less" href="themes/blank/projection.css.less" media="screen,projection"> | |
8 <link rel="stylesheet/less" href="themes/blank/screen.css.less" media="screen"> | |
9 <link rel="stylesheet/less" href="themes/blank/print.css.less" media="print"> | |
10 | |
11 <link rel="stylesheet/less" href="blank.css.less" media="screen,projection"> | |
12 | |
13 <!-- add js libs (less, jquery) --> | |
14 <script src="js/less-1.1.4.min.js"></script> | |
15 <script src="js/jquery-1.7.min.js"></script> | |
16 | |
17 <!-- S6 JS --> | |
18 <script src="js/jquery.slideshow.js"></script> | |
19 <script src="js/jquery.slideshow.counter.js"></script> | |
20 <script src="js/jquery.slideshow.controls.js"></script> | |
21 <script src="js/jquery.slideshow.footer.js"></script> | |
22 <script src="js/jquery.slideshow.autoplay.js"></script> | |
23 <script> | |
24 $(document).ready( function() { | |
25 Slideshow.init(); | |
26 | |
27 // Example 2: Start Off in Outline Mode | |
28 // Slideshow.init( { mode: 'outline' } ); | |
29 | |
30 // Example 3: Use Custom Transition | |
31 // Slideshow.transition = transitionScrollUp; | |
32 // Slideshow.init(); | |
33 | |
34 // Example 4: Start Off in Autoplay Mode with Custom Transition | |
35 // Slideshow.transition = transitionScrollUp; | |
36 // Slideshow.init( { mode: 'autoplay' } ); | |
37 } ); | |
38 </script> | |
39 </head> | |
40 <body> | |
41 | |
42 <div class="layout"> | |
43 <div id="header"></div> | |
44 <div id="footer"> | |
45 <div align="right"> | |
46 <img src="images/concurrency.png" width="200"> | |
47 </div> | |
48 </div> | |
49 </div> | |
50 | |
51 <div class="presentation"> | |
52 | |
53 <div class='slide cover'> | |
54 <table width="90%" height="90%" border="0" align="center"> | |
55 <tr> | |
56 <td><div align="center"> | |
57 <h1><font color="#808db5">Implimentating Continuation based language in Clang and LLVM</font></h1> | |
58 </div></td> | |
59 </tr> | |
60 <tr> | |
61 <td><div align="left"> | |
62 Kaito Tokumori, Shinji Kono | |
63 <script> | |
64 document.write("<br>July 4, 2015"); | |
65 </script> | |
66 <hr style="color:#ffcc00;background-color:#ffcc00;text-align:left;border:none;width:300%;height:0.2em;"> | |
67 </div></td> | |
68 </tr> | |
69 </table> | |
70 </div> | |
71 | |
72 <div class='slide'> | |
73 <h2>Objective</h2> | |
74 <ul> | |
75 <li>Reliable computation | |
76 <li>Concurrent execution | |
77 <li>Reliable improvement | |
78 <li>Reusablity | |
79 </ul> | |
80 <h3>Introducing new units of programming</h3> | |
81 </div> | |
82 | |
83 | |
84 <div class='slide'> | |
85 <h2>Traditional units of programming</h2> | |
86 <ul> | |
87 <li>Machine instruction | |
88 <li>Statements of programming language | |
89 <li>Function call / Method | |
90 <li>Module / Class / Interface | |
91 <li>Thread / Process | |
92 <li>Object | |
93 <li>Record / Table | |
94 </ul> | |
95 </div> | |
96 | |
97 <div class='slide'> | |
98 <h2>What we want to do with programming units?</h2> | |
99 <ul> | |
100 <li>Divide large functions into small parts. | |
101 <li>Add hidden arguments without code modification. | |
102 <li>Add meta computation. | |
103 <li>Extract concurrency from programming units. | |
104 </ul> | |
105 <h3>It is not easy in the traditional units.</h3> | |
106 </div> | |
107 | |
108 <div class='slide'> | |
109 <h2>New programing units</h2> | |
110 <ul> | |
111 <li>Units of programming: code segments, data segments. | |
112 <li>Code segments are units of calculation. | |
113 <li>Data segments are sets of typed data. | |
114 </ul> | |
115 </div> | |
116 | |
117 <div class='slide'> | |
118 <h2>Code segments</h2> | |
119 <ul> | |
120 <li>Function from input data segments to output data segments. | |
121 <li>Code segments have no states. | |
122 <li>Access in typed data in the data segments by name. | |
123 <li>Specify code segmnets to be executed using goto. | |
124 </ul> | |
125 <h3>It is easy to divide or combine.</h3> | |
126 </div> | |
127 | |
128 <div class='slide'> | |
129 <h2>Data segments</h2> | |
130 <ul> | |
131 <li>Set of typed data. | |
132 <li>Type signatures are in meta data segments. | |
133 <li>Variable and extendable data structure. | |
134 <li>Data segments are dominated by connected code segments. | |
135 <li>Code segments atomically access connected data segments. | |
136 </ul> | |
137 <h3>It is easy to divide or combine.</h3> | |
138 </div> | |
139 | |
140 <div class='slide'> | |
141 <h2>Meta code / data segments</h2> | |
142 <ul> | |
143 <li>Execution contexts: Thread | |
144 <li>Type signatures of data segments. | |
145 <li>Data segment linkages: Pointer | |
146 <li>Machine code | |
147 </ul> | |
148 <h3>Meta code segments are executed right after the goto.</h3> | |
149 <h3>Meta data segments are kinds of process data.</h3> | |
150 </div> | |
151 | |
152 <div class='slide'> | |
153 <h2>Continuation based C (CbC)</h2> | |
154 <ul> | |
155 <li>An implementation of code segments. | |
156 <li>CbC stands for Continuation based C. | |
157 <li>Basic syntax is the same as the C. | |
158 <li>Code segments are set of C statements with goto. | |
159 <li>Data segments are inplemented as C structures. | |
160 </ul> | |
161 </div> | |
162 | |
163 <div class='slide'> | |
164 <h2>Continuation based C (CbC)</h2> | |
165 <ul> | |
166 <li>CbC uses goto for code segments transition. | |
167 <ul> | |
168 <li>They don't keep states. | |
169 </ul> | |
170 <li> | |
171 <ul> | |
172 <li>Compatible with the C. | |
173 </ul> | |
174 <li>The feature for return to C functions from code segments is named Continuaton with environment. | |
175 <li>CbC can use C function call but you can replace them with CbC goto by replacing roop syntax with recursive continuation. | |
176 <li>Continuation does not use a call instruction, but use a jmp instruction. | |
177 <li>CbC uses data segments for typed data structure. | |
178 <ul> | |
179 <li>They have type information for meta computing. | |
180 <li>You can use normal arguments too. | |
181 </ul> | |
182 </ul> | |
183 </div> | |
184 | |
185 <div class='slide'> | |
186 <h2>CbC sample (with normal arguments)</h2> | |
187 <table border='1' align='center' width='80%'> | |
188 <tr><td width='50%'> | |
189 <pre class='small_code'> | |
190 <div class="highlight"><font color='red'>__code</font> code1(int n,__code(*exit_code)(int,void *),void *exit_env){ | |
191 printf("code1 : code entry1\n"); | |
192 <font color='red'>goto exit_code(n,exit_env);</font> | |
193 }</div> | |
194 | |
195 int caller(){ | |
196 printf("caller : main1 entry\n"); | |
197 __code (*__ret)(int, void *) = __return; | |
198 struct __CbC_env *__env = __environment; | |
199 goto code1(1, __ret, __env); | |
200 return 0; | |
201 } | |
202 | |
203 int main(){ | |
204 int n; | |
205 n = caller(); | |
206 printf("return = %d\n",n); | |
207 return 0; | |
208 } </pre> | |
209 </td><td valign='top'> | |
210 <ul> | |
211 <li>We can write code segments like C functions. | |
212 <li>CbC transition is goto so code segments do not return to previous one. | |
213 <li>There are no return values. | |
214 </td></tr> | |
215 </table> | |
216 </div> | |
217 | |
218 <!-- | |
219 <div class='slide'> | |
220 <h2>CbC sample (continuation with environments)</h2> | |
221 <table border='1' align='center' width='80%'> | |
222 <tr><td width='50%'> | |
223 <pre class='small_code'> | |
224 __code code1(int n,__code(*exit_code)(int,void *),void *exit_env){ | |
225 printf("code1 : code entry1\n"); | |
226 goto exit_code(n,exit_env); | |
227 } | |
228 | |
229 <div class="highlight">int caller(){ | |
230 printf("caller : main1 entry\n"); | |
231 __code (*__ret)(int, void *) = <font color='red'>__return</font>; | |
232 struct __CbC_env *__env = <font color='red'>__environment</font>; | |
233 goto code1(1, __ret, __env); | |
234 return 0; | |
235 }</div> | |
236 | |
237 int main(){ | |
238 int n; | |
239 n = caller(); | |
240 printf("return = %d\n",n); | |
241 return 0; | |
242 } </pre> | |
243 </td><td valign='top'> | |
244 <ul> | |
245 <li>The feature for return to C functions from code segments. | |
246 <li>__return is a code segment pointer for return C functions. | |
247 <li>__environment is a envitonment for return C functions. | |
248 <li>Code1 use a continuation with environments to return main function. | |
249 </td></tr> | |
250 </table> | |
251 </div> | |
252 --> | |
253 | |
254 <div class='slide'> | |
255 <h2>CbC sample (with data segments)</h2> | |
256 <table border='1' align='center' width='80%'> | |
257 <tr><td width='50%'> | |
258 <pre class='small_code'> | |
259 __code code1(Data1 data){ | |
260 goto code2(data); | |
261 } | |
262 | |
263 __code code2(Data2 data){ | |
264 goto code3(data); | |
265 } | |
266 | |
267 int main(){ | |
268 goto start_code(context, Code1); | |
269 } </pre> | |
270 </td><td valign='top'> | |
271 <ul> | |
272 <li> | |
273 <li> | |
274 <li> | |
275 </td></tr> | |
276 </table> | |
277 </div> | |
278 | |
279 <div class='slide'> | |
280 <h2>CbC compilers</h2> | |
281 <ul> | |
282 <li>Micro-C(one pass standalone compiler) | |
283 <li>GCC(GNU Compiler Collection) | |
284 <li>LLVM and Clang | |
285 <ul> | |
286 <li>The latest one! | |
287 </ul> | |
288 </ul> | |
289 </div> | |
290 | |
291 <div class='slide'> | |
292 <h2>What is LLVM and Clang?</h2> | |
293 <ul> | |
294 <li>LLVM is a compiler framework. | |
295 <li>LLVM has a intermidiate language which is called LLVM IR, LLVM language or LLVM bitcode. | |
296 <li>LLVM translates LLVM IR to assembly language. | |
297 <li>LLVM has a many kinds of optimization. | |
298 <li>Clang is C, C++ and Obj-C compiler frontend. | |
299 <li>Clang uses LLVM for compiler backend. | |
300 </ul> | |
301 </div> | |
302 | |
303 <div class='slide'> | |
304 <h2>Why LLVM?</h2> | |
305 <ul> | |
306 <li>Apple supported. | |
307 <li>OS X default compiler. | |
308 <li>LLVM IR's documantation is useful and readable. | |
309 <li>LLVM and Clang has readable documantation of their source codes. | |
310 </ul> | |
311 </div> | |
312 | |
313 <div class='slide'> | |
314 <h2>LLVM and Clang's compilation flow</h2> | |
315 <ul> | |
316 <li>Sorce codes are translated into clang AST by parser. | |
317 <li>clang AST is translated into LLVM IR by code generator. | |
318 <li>LLVM IR is translated into machine code by SelectionDAGISel. | |
319 <li>Machine code is optimized by optimizations and then, it is translated into assembly code. | |
320 </ul> | |
321 <div align="center"><img src="fig/clang_llvm_structure.svg" width="45%"></div> | |
322 </div> | |
323 | |
324 <div class='slide'> | |
325 <h2>LLVM and Clang's intermidiate representations</h2> | |
326 <table border='1' align='center' width='80%'> | |
327 <tr><td width='25%'> | |
328 Name | |
329 </td><td> | |
330 Desctiption | |
331 </td></tr> | |
332 <tr><td> | |
333 clang AST | |
334 </td><td> | |
335 Abstract Syntax Tree. It is a representation of the structure source codes. | |
336 </td></tr> | |
337 <tr><td> | |
338 LLVM IR | |
339 </td><td> | |
340 The main intermidiate representation of LLVM. It has three diffirent forms: as an in-memory compiler IR, as an on-disk bitcode representation, and as a human readable assembly language representation. | |
341 </td></tr> | |
342 <tr><td> | |
343 SelectionDAG | |
344 </td><td> | |
345 Directed Acyclic Graph. Its nodes indicate what operation the node performs and the operands to the operation. | |
346 </td></tr> | |
347 <tr><td> | |
348 Machine Code | |
349 </td><td> | |
350 This representation is designed to support both an SSA representation for machine code, as well as register allocated, non-SSA form. | |
351 </td></tr> | |
352 <tr><td> | |
353 MC Layer | |
354 </td><td> | |
355 It is used to represent and process code at the raw machine code level. User can some kinds of file (.s, .o, .ll, a.out) by same API. | |
356 </td></tr> | |
357 </table> | |
358 <br> | |
359 <p align='center' class='step emphasize'>LLVM's intermidiate representations are do not be modified.</p> | |
360 </div> | |
361 | |
362 <div class='slide'> | |
363 <h2>Abstract Syntax Tree</h2> | |
364 <ul> | |
365 <li>You can see it if you give clang '-Xclang -ast-dump' options. | |
366 <li>The nodes indicate Decl (declaration), Stmt (statement) or Expr (expresstion). | |
367 </ul> | |
368 <table border='1'> | |
369 <tr> | |
370 <td>source code | |
371 <td>AST | |
372 </tr> | |
373 <tr> | |
374 <td valign='top' width='20%'> | |
375 <pre class='small_code'> | |
376 __code code1(int n,__code(*exit_code)(int,void *),void *exit_env){ | |
377 printf("code1 : code entry1\n"); | |
378 goto exit_code(n,exit_env); | |
379 } | |
380 </pre> | |
381 <td><img src="fig/clangAST_char.svg" width="100%"> | |
382 </tr> | |
383 </table> | |
384 <p>We modify Clang which come to generate the AST when they get CbC syntax.</p> | |
385 </div> | |
386 | |
387 <div class='slide'> | |
388 <h2>Problems on implementating</h2> | |
389 <ul> | |
390 <li>How to implement code segments and data segments? | |
391 <li>How to implement jmp instruction based transition? | |
392 <li>How to implement goto with environment syntax? | |
393 </ul> | |
394 </div> | |
395 | |
396 <div class='slide'> | |
397 <h2>Basic strategy of implementating</h2> | |
398 <ul> | |
399 <li>Code segments are implemented by C functions. | |
400 <li>Data segments are implemented by C structs. | |
401 <li>Transition is implemented by forced tail call elimination. | |
402 <li>Goto with environment is implemented by setjmp and longjmp. | |
403 </ul> | |
404 </div> | |
405 | |
406 <div class='slide'> | |
407 <h2>Implementating CbC compiler in LLVM and Clang</h2> | |
408 <h3>Implemented</h3> | |
409 <ul> | |
410 <li>add __code type for code segment. | |
411 <li>translate Clang's __code type into LLVM's __code type. | |
412 <li>add goto syntax for transition. | |
413 <li>force to tail call elimination. | |
414 <li>goto with environment. | |
415 <li>automatically prototype declatation genarating. | |
416 <!--<li>connect code segments with meta code segments --> | |
417 </ul> | |
418 <h3>Implementing now</h3> | |
419 <ul> | |
420 <li>connect code segments with meta code segments. | |
421 <li>generate data segment automatically. | |
422 <li>Syntax for accessing to data segment type. | |
423 </ul> | |
424 </div> | |
425 | |
426 <div class='slide'> | |
427 <h2>__code type</h2> | |
428 <p>modify parser.</p> | |
429 <div align='center'><img src="fig/clang_llvm_slide_parse.svg" width="70%"></div> | |
430 </div> | |
431 | |
432 <div class='slide'> | |
433 <h2>__code type</h2> | |
434 <table width='100%'> | |
435 <tr><td> | |
436 <ul> | |
437 <li>Clang and LLVM handle code segments as __code type functions. | |
438 <li>Code segments do not have return value so they are handled like void functions. | |
439 <li>Clang and LLVM use different class for handling type so we have to modify both. | |
440 <li>In Clang, we create type keyword, ID, and Type class. | |
441 <li>In LLVM, we create Type class and ID. | |
442 <li>The following code is the place where Clang parse a __code type. | |
443 <li>DS.SetTypeSpecType() set AST nodes __code type. | |
444 </ul> | |
445 </tr> | |
446 <tr> | |
447 <td style="border: double;"> | |
448 <pre class='code'> | |
449 case tok::kw___code: { | |
450 LangOptions* LOP; | |
451 LOP = const_cast<LangOptions*>(&getLangOpts()); | |
452 LOP->HasCodeSegment = 1; | |
453 isInvalid = <font color='red'>DS.SetTypeSpecType(DeclSpec::TST___code, Loc, PrevSpec, DiagID);</font> | |
454 break; | |
455 }</pre> | |
456 </tr> | |
457 </table> | |
458 </div> | |
459 | |
460 <div class='slide'> | |
461 <h2>translation Clang's __code type into LLVM's __code type</h2> | |
462 <p>Clang's types are translated in CodeGen.</p> | |
463 <div align='center'><img src="fig/clang_llvm_slide_cg.svg" width="70%"></div> | |
464 </div> | |
465 | |
466 <div class='slide'> | |
467 <h2>translation Clang's __code type into LLVM's __code type</h2> | |
468 <table width='100%'> | |
469 <tr><td> | |
470 <ul> | |
471 <li>The following code is the translation place. | |
472 <li>Code segments have no return value so __code type is handled like void type. | |
473 </ul> | |
474 </tr> | |
475 <tr> | |
476 <td style="border: double;"> | |
477 <pre class='code'> | |
478 case ABIArgInfo::Ignore: | |
479 #ifndef noCbC | |
480 if (FI.getReturnType().getTypePtr()->is__CodeType()) | |
481 resultType = llvm::Type::get__CodeTy(getLLVMContext()); | |
482 else | |
483 resultType = llvm::Type::getVoidTy(getLLVMContext()); | |
484 #else | |
485 resultType = llvm::Type::getVoidTy(getLLVMContext()); | |
486 #endif | |
487 break;</pre> | |
488 </tr> | |
489 </table> | |
490 </div> | |
491 | |
492 <div class='slide'> | |
493 <h2>goto syntax for transition</h2> | |
494 <p>modify parser.</p> | |
495 <div align='center'><img src="fig/clang_llvm_slide_parse.svg" width="70%"></div> | |
496 </div> | |
497 | |
498 <div class='slide'> | |
499 <h2>goto syntax for transition</h2> | |
500 <table width='100%'> | |
501 <tr><td> | |
502 <ul> | |
503 <li>Add new goto syntax for transition. | |
504 <li>Jmp instraction based transition is enabled by tail call elimination. | |
505 <li>In this part, clang create AST for normal function call and force to tail call elimination later. | |
506 <li>The following code is the place where CbC goto was parsed. | |
507 <li>If the goto is not for C syntax, we judge it is for CbC syntax. | |
508 </ul> | |
509 </tr> | |
510 <tr> | |
511 <td style="border: double;"> | |
512 <pre class='code'> | |
513 case tok::kw_goto: | |
514 #ifndef noCbC | |
515 if (!(NextToken().is(tok::identifier) && PP.LookAhead(1).is(tok::semi)) && | |
516 NextToken().isNot(tok::star)) { | |
517 SemiError = "goto code segment"; | |
518 return ParseCbCGotoStatement(Attrs, Stmts); | |
519 } | |
520 #endif | |
521 Res = ParseGotoStatement(); | |
522 SemiError = "goto"; | |
523 break;</pre> | |
524 </tr> | |
525 </table> | |
526 </div> | |
527 | |
528 <div class='slide'> | |
529 <h2>goto syntax for transition</h2> | |
530 <ul> | |
531 <li>Add return statement after goto transition. | |
532 <li>It is one the requirement force to tail call elimination. | |
533 </ul> | |
534 <table border='1' width='80%' align='center'> | |
535 <tr> | |
536 <td>original input code | |
537 <td>Clang genarates it | |
538 </tr> | |
539 <tr> | |
540 <td><pre class='small_code'> | |
541 __code code1() { | |
542 : | |
543 goto code2(); | |
544 } | |
545 </pre> | |
546 <td><pre class='small_code'> | |
547 void code1() { | |
548 : | |
549 code2(); | |
550 <font color='red'>return;</font> | |
551 } | |
552 </pre> | |
553 </tr> | |
554 </table> | |
555 </div> | |
556 | |
557 <div class='slide'> | |
558 <h2>Jmp instruction based transition</h2> | |
559 <ul> | |
560 <li>It is implemented by Tail Call Elimination (TCE). | |
561 <li>TCE is one of the optimization. | |
562 <li>If the function call is immediately followed by return, it is tail call. | |
563 <li>TCE replace tail call's call instructions with jmp instructions. | |
564 <li>Code segments' transition is implemented by forced tail call elimination. | |
565 </ul> | |
566 <div align='center'><img src="fig/TCE.svg" width="40%"></div> | |
567 </div> | |
568 | |
569 <div class='slide'> | |
570 <h2>Forcing Tail Call Elimination</h2> | |
571 <p>TCE is enabled at CodeGen.</p> | |
572 <p>TCE is act at SelectionDAGISel.</p> | |
573 <div align='center'><img src="fig/clang_llvm_slide_cg_DAG.svg" width="70%"></div> | |
574 </div> | |
575 | |
576 <div class='slide'> | |
577 <h2>Forcing Tail Call Elimination</h2> | |
578 <p>LLVM IR has function call flags. We can give LLVM some information for function call by them. We use them for force to tail call elimination. | |
579 <p>We have to meet the following requirements.</p> | |
580 <ul> | |
581 <li>set tail flag at the code segments call. | |
582 <li>tailcallopt is enabled. | |
583 <li>the caller and calle's calling conventions must be the same and their types should be cc10, cc11 or fastcc. | |
584 <li>return value type has to be the same as the caller's. | |
585 </ul> | |
586 <br> | |
587 <p>We met them by following ways.</p> | |
588 <ul> | |
589 <li>Always add tail call elimination pass and set flag at the code segments call. | |
590 <li>If the input code contains code segment, tailcallopt is enabled automatically. | |
591 <li>Fast cc is used consistently in code segments call. | |
592 <li>All the code segments return value type is void. | |
593 </ul> | |
594 </div> | |
595 | |
596 <div class='slide'> | |
597 <h2>Goto with environment</h2> | |
598 <p>Goto with environment is enabled by modifying parser.</p> | |
599 <div align='center'><img src="fig/clang_llvm_slide_parse.svg" width="70%"></div> | |
600 </div> | |
601 | |
602 <div class='slide'> | |
603 <h2>What is a Goto with environment?</h2> | |
604 <ul> | |
605 <li>Code segments do not have environment cut functions have. | |
606 <li>Usually, code segments can't return to functions. | |
607 <li>Goto with environment enable to it. | |
608 <li>In the GCC, use nested functions to implementing. | |
609 <li>In the LLVM and Clang, use setjmp and longjmp to implementing. | |
610 </ul> | |
611 </div> | |
612 | |
613 <div class='slide'> | |
614 <h2>Sample code of Goto with environment</h2> | |
615 <table width='100%'> | |
616 <tr><td valign='top'> | |
617 <ul> | |
618 <li>Use new keywords __return and __environment. | |
619 <li>__return is a code segment pointer for C functions. | |
620 <li>__environment is a envitonment for C functions. | |
621 <li>Code1 use a continuation with environments to return main function. | |
622 </ul> | |
623 <td style="border: double;"> | |
624 <pre class='small_code'><div class='highlight'>__code code1(int n,__code(*exit_code)(int,void *),void *exit_env){ | |
625 printf("code1 : code entry1\n"); | |
626 goto exit_code(n,exit_env); | |
627 } | |
628 | |
629 int caller(){ | |
630 printf("caller : main1 entry\n"); | |
631 __code (*__ret)(int, void *) = <font color='red'>__return</font>; | |
632 struct __CbC_env *__env = <font color='red'>__environment</font>; | |
633 goto code1(1, __ret, __env); | |
634 return 0; | |
635 } | |
636 | |
637 int main(){ | |
638 int n; | |
639 n = caller(); | |
640 printf("return = %d\n",n); | |
641 return 0; | |
642 } </div></pre> | |
643 </tr> | |
644 </table> | |
645 </div> | |
646 | |
647 <div class='slide'> | |
648 <h2>Implementing goto with environment</h2> | |
649 <ul> | |
650 <li>Include setjmp.h always. | |
651 <li>Generate C struct for saving environment. | |
652 <ul> | |
653 <li>This struct is __environment. | |
654 </ul> | |
655 <li>Insert setjmp in C function. | |
656 <li>Generate longjmp code segment as return. | |
657 <ul> | |
658 <li>This code segment is pointed by __return. | |
659 </ul> | |
660 </ul> | |
661 </div> | |
662 | |
663 <div class='slide'> | |
664 <h2>Prototype declaration generating</h2> | |
665 <p>modify parser.</p> | |
666 <div align='center'><img src="fig/clang_llvm_slide_parse.svg" width="70%"></div> | |
667 </div> | |
668 | |
669 <div class='slide'> | |
670 <h2>Prototype declaration generating</h2> | |
671 <ul> | |
672 <li>In CbC, programmer write a lot of code segments. | |
673 <li>When function pointer's arguments are omitted, TCE was failed sometimes. | |
674 <li>Automatically prototype declaration generating saves a lot of effort. | |
675 <li>When parser meet a code segment call, it stop current parsing and search called code segment declaration. | |
676 <li>If the declaration was not found, search definision and generate declaration. | |
677 <ul> | |
678 <li>Of course you can write declaration yourself too. | |
679 </ul> | |
680 <!-- <li>This feature is important to code segment transition.--> | |
681 </ul> | |
682 <table border='1' width='80%' align='center'> | |
683 <tr> | |
684 <td>original input code | |
685 <td>Clang genarates it | |
686 </tr> | |
687 <tr> | |
688 <td><pre class='small_code'> | |
689 __code code1(int a, int b) { | |
690 : | |
691 goto code2(a,b); | |
692 } | |
693 | |
694 __code code2(int a, int b){ | |
695 : | |
696 } | |
697 </pre> | |
698 <td><pre class='small_code'> | |
699 <font color='red'>__code code2(int a, int b);</font> | |
700 __code code1(int a, int b) { | |
701 : | |
702 goto code2(a,b); | |
703 } | |
704 | |
705 __code code2(int a, int b){ | |
706 : | |
707 } | |
708 </pre> | |
709 </tr> | |
710 </table> | |
711 </div> | |
712 | |
713 <div class='slide'> | |
714 <h2>Connect code segments with meta code segments</h2> | |
715 <ul> | |
716 <li>All code segments are transition to next one via meta code segments. | |
717 <!-- <li>Meta code segments calculate meta computation like a memory allocation, exception, scheduling.--> | |
718 <li>Normal level code segments don't have to know meta code segments. | |
719 <li>When code segments transition to next code segment, compiler connect it with meta code segments. | |
720 <li>Meta code segments use context which has code segments pointer and name. | |
721 <li>Context is added arguments by compiler. | |
722 <li>You can omit meta computing if you do not need it. | |
723 <ul> | |
724 <li>In this case, code segments transition to next one via default meta code segment. | |
725 <li>Default meta code segment get next code segment from context and transition to it. | |
726 </ul> | |
727 </ul> | |
728 <h3>code segments view</h3> | |
729 <div align='center'><img src="fig/cs_meta_csview.svg" width="35%"></div> | |
730 <h3>actual code segments transition</h3> | |
731 <div align='center'><img src="fig/cs_metacs.svg" width="35%"></div> | |
732 </div> | |
733 | |
734 <div class='slide'> | |
735 <h2>Connect code segments with meta code segments</h2> | |
736 <table border='1' width='80%' align='center'> | |
737 <tr> | |
738 <td>original input code | |
739 <td>Clang genarates it | |
740 </tr> | |
741 <tr> | |
742 <td><pre class='small_code'> | |
743 __code code1() { | |
744 goto code2(); | |
745 } | |
746 | |
747 __code code2(){ | |
748 goto code3(); | |
749 } | |
750 </pre> | |
751 <td><pre class='small_code'> | |
752 __code code1(struct Context* context) { | |
753 <font color='red'>goto meta(context,Code2);</font> | |
754 } | |
755 | |
756 __code code2(struct Context* context){ | |
757 <font color='red'>goto meta(context,Code3);</font> | |
758 } | |
759 | |
760 __code meta(struct Context* context, enum Code next) { | |
761 goto (context->code[next])(context); | |
762 } | |
763 </pre> | |
764 </tr> | |
765 </table> | |
766 </div> | |
767 | |
768 </div> <!-- presentation --> | |
769 </body> | |
770 </html> |