Mercurial > hg > Papers > 2015 > kaito-lola
changeset 4:20257f618ddd
slide: llvm structure
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 01 Jul 2015 22:18:59 +0900 |
parents | c50a033e6635 |
children | ac2ec4334d49 |
files | presentation/presen.html |
diffstat | 1 files changed, 57 insertions(+), 231 deletions(-) [+] |
line wrap: on
line diff
--- a/presentation/presen.html Wed Jul 01 19:06:07 2015 +0900 +++ b/presentation/presen.html Wed Jul 01 22:18:59 2015 +0900 @@ -54,7 +54,7 @@ <table width="90%" height="90%" border="0" align="center"> <tr> <td><div align="center"> - <h1><font color="#808db5">Implimentating Continuation based language in Clang and LLVM</font></h1> + <h1><font color="#808db5">Implementating Continuation based language in Clang and LLVM</font></h1> </div></td> </tr> <tr> @@ -154,124 +154,51 @@ <ul> <li>An implementation of code segments. <li>CbC stands for Continuation based C. - <li>Basic syntax is the same as the C. + <li>Basic syntax is the same as the C.CbC stands for Continuation based C. <li>Code segments are set of C statements with goto. <li>Data segments are inplemented as C structures. </ul> </div> <div class='slide'> - <h2>Continuation based C (CbC)</h2> - <ul> - <li>CbC uses goto for code segments transition. - <ul> - <li>They don't keep states. - </ul> - <li> - <ul> - <li>Compatible with the C. - </ul> - <li>The feature for return to C functions from code segments is named Continuaton with environment. - <li>CbC can use C function call but you can replace them with CbC goto by replacing roop syntax with recursive continuation. - <li>Continuation does not use a call instruction, but use a jmp instruction. - <li>CbC uses data segments for typed data structure. - <ul> - <li>They have type information for meta computing. - <li>You can use normal arguments too. - </ul> - </ul> - </div> - - <div class='slide'> - <h2>CbC sample (with normal arguments)</h2> + <h2>CbC sample</h2> <table border='1' align='center' width='80%'> <tr><td width='50%'> <pre class='small_code'> -<div class="highlight"><font color='red'>__code</font> code1(int n,__code(*exit_code)(int,void *),void *exit_env){ - printf("code1 : code entry1\n"); - <font color='red'>goto exit_code(n,exit_env);</font> -}</div> - -int caller(){ - printf("caller : main1 entry\n"); - __code (*__ret)(int, void *) = __return; - struct __CbC_env *__env = __environment; - goto code1(1, __ret, __env); - return 0; +<!-- +__code code2(struct Context* context, struct Allocate* allocate, struct Element* element) { + allocate->after_append = Code3; + element ->value = 10; + goto meta(context, Append); } - -int main(){ - int n; - n = caller(); - printf("return = %d\n",n); - return 0; -} </pre> - </td><td valign='top'> - <ul> - <li>We can write code segments like C functions. - <li>CbC transition is goto so code segments do not return to previous one. - <li>There are no return values. - </td></tr> - </table> - </div> - -<!-- - <div class='slide'> - <h2>CbC sample (continuation with environments)</h2> - <table border='1' align='center' width='80%'> - <tr><td width='50%'> - <pre class='small_code'> -__code code1(int n,__code(*exit_code)(int,void *),void *exit_env){ - printf("code1 : code entry1\n"); - goto exit_code(n,exit_env); + --> +__code code(struct Context* context, struct Allocate* allocate, struct Element* element) { + allocate->after_append = Code2; + element ->value = 10; + goto meta(context, Append); } -<div class="highlight">int caller(){ - printf("caller : main1 entry\n"); - __code (*__ret)(int, void *) = <font color='red'>__return</font>; - struct __CbC_env *__env = <font color='red'>__environment</font>; - goto code1(1, __ret, __env); - return 0; -}</div> +__code append(struct Context* context, struct Allocate* allocate, struct List* list, struct Element* element) { + if(list->head) { + list->tail->next = element; + } else { + list->head = element; + } + list->tail = element; + list->tail->next = 0; + goto meta(context, allocate->after_append); +} -int main(){ - int n; - n = caller(); - printf("return = %d\n",n); - return 0; -} </pre> +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + </pre> </td><td valign='top'> <ul> - <li>The feature for return to C functions from code segments. - <li>__return is a code segment pointer for return C functions. - <li>__environment is a envitonment for return C functions. - <li>Code1 use a continuation with environments to return main function. - </td></tr> - </table> - </div> ---> - -<div class='slide'> - <h2>CbC sample (with data segments)</h2> - <table border='1' align='center' width='80%'> - <tr><td width='50%'> - <pre class='small_code'> -__code code1(Data1 data){ - goto code2(data); -} - -__code code2(Data2 data){ - goto code3(data); -} - -int main(){ - goto start_code(context, Code1); -} </pre> - </td><td valign='top'> - <ul> - <li> - <li> - <li> + <li>Code segments like C functions. + <li>CbC transition is goto so code segments do not return to previous. + <li>There are no return values. + </ul> </td></tr> </table> </div> @@ -283,24 +210,32 @@ <li>GCC(GNU Compiler Collection) <li>LLVM and Clang <ul> - <li>The latest one! + <li><font color='red'>The latest!</font> </ul> </ul> </div> <div class='slide'> - <h2>What is LLVM and Clang?</h2> + <h2>What is LLVM?</h2> <ul> - <li>LLVM is a compiler framework. - <li>LLVM has a intermidiate language which is called LLVM IR, LLVM language or LLVM bitcode. - <li>LLVM translates LLVM IR to assembly language. - <li>LLVM has a many kinds of optimization. + <li>Compiler frameworks. + <li>has a intermidiate language which is called LLVM IR, LLVM language or LLVM bitcode. + <li>Translates LLVM IR to assembly language. + <li>Many kinds of optimization. <li>Clang is C, C++ and Obj-C compiler frontend. <li>Clang uses LLVM for compiler backend. </ul> </div> <div class='slide'> + <h2>What is Clang?</h2> + <ul> + <li>C, C++ and Obj-C compiler frontend. + <li>Uses LLVM for compiler backend. + </ul> + </div> + + <div class='slide'> <h2>Why LLVM?</h2> <ul> <li>Apple supported. @@ -313,10 +248,9 @@ <div class='slide'> <h2>LLVM and Clang's compilation flow</h2> <ul> - <li>Sorce codes are translated into clang AST by parser. - <li>clang AST is translated into LLVM IR by code generator. - <li>LLVM IR is translated into machine code by SelectionDAGISel. - <li>Machine code is optimized by optimizations and then, it is translated into assembly code. + <li>Clang translate C/C++/Obj-C into LLVM IR. + <li>LLVM translate LLVM IR into assembly code. + <li>LLVM optimize all of intermidiate representation. </ul> <div align="center"><img src="fig/clang_llvm_structure.svg" width="45%"></div> </div> @@ -356,32 +290,7 @@ </td></tr> </table> <br> - <p align='center' class='step emphasize'>LLVM's intermidiate representations are do not be modified.</p> - </div> - - <div class='slide'> - <h2>Abstract Syntax Tree</h2> - <ul> - <li>You can see it if you give clang '-Xclang -ast-dump' options. - <li>The nodes indicate Decl (declaration), Stmt (statement) or Expr (expresstion). - </ul> - <table border='1'> - <tr> - <td>source code - <td>AST - </tr> - <tr> - <td valign='top' width='20%'> - <pre class='small_code'> -__code code1(int n,__code(*exit_code)(int,void *),void *exit_env){ - printf("code1 : code entry1\n"); - goto exit_code(n,exit_env); -} -</pre> - <td><img src="fig/clangAST_char.svg" width="100%"> - </tr> - </table> - <p>We modify Clang which come to generate the AST when they get CbC syntax.</p> + <p align='center' class='step emphasize'>Intermidiate representations are not modified.</p> </div> <div class='slide'> @@ -405,21 +314,12 @@ <div class='slide'> <h2>Implementating CbC compiler in LLVM and Clang</h2> - <h3>Implemented</h3> <ul> <li>add __code type for code segment. - <li>translate Clang's __code type into LLVM's __code type. <li>add goto syntax for transition. <li>force to tail call elimination. <li>goto with environment. <li>automatically prototype declatation genarating. - <!--<li>connect code segments with meta code segments --> - </ul> - <h3>Implementing now</h3> - <ul> - <li>connect code segments with meta code segments. - <li>generate data segment automatically. - <li>Syntax for accessing to data segment type. </ul> </div> @@ -436,9 +336,6 @@ <ul> <li>Clang and LLVM handle code segments as __code type functions. <li>Code segments do not have return value so they are handled like void functions. - <li>Clang and LLVM use different class for handling type so we have to modify both. - <li>In Clang, we create type keyword, ID, and Type class. - <li>In LLVM, we create Type class and ID. <li>The following code is the place where Clang parse a __code type. <li>DS.SetTypeSpecType() set AST nodes __code type. </ul> @@ -458,38 +355,6 @@ </div> <div class='slide'> - <h2>translation Clang's __code type into LLVM's __code type</h2> - <p>Clang's types are translated in CodeGen.</p> - <div align='center'><img src="fig/clang_llvm_slide_cg.svg" width="70%"></div> - </div> - - <div class='slide'> - <h2>translation Clang's __code type into LLVM's __code type</h2> - <table width='100%'> - <tr><td> - <ul> - <li>The following code is the translation place. - <li>Code segments have no return value so __code type is handled like void type. - </ul> - </tr> - <tr> - <td style="border: double;"> - <pre class='code'> -case ABIArgInfo::Ignore: -#ifndef noCbC - if (FI.getReturnType().getTypePtr()->is__CodeType()) - resultType = llvm::Type::get__CodeTy(getLLVMContext()); - else - resultType = llvm::Type::getVoidTy(getLLVMContext()); -#else - resultType = llvm::Type::getVoidTy(getLLVMContext()); -#endif - break;</pre> - </tr> - </table> - </div> - - <div class='slide'> <h2>goto syntax for transition</h2> <p>modify parser.</p> <div align='center'><img src="fig/clang_llvm_slide_parse.svg" width="70%"></div> @@ -711,58 +576,19 @@ </div> <div class='slide'> - <h2>Connect code segments with meta code segments</h2> + <h2>Conclusion</h2> <ul> - <li>All code segments are transition to next one via meta code segments. -<!-- <li>Meta code segments calculate meta computation like a memory allocation, exception, scheduling.--> - <li>Normal level code segments don't have to know meta code segments. - <li>When code segments transition to next code segment, compiler connect it with meta code segments. - <li>Meta code segments use context which has code segments pointer and name. - <li>Context is added arguments by compiler. - <li>You can omit meta computing if you do not need it. - <ul> - <li>In this case, code segments transition to next one via default meta code segment. - <li>Default meta code segment get next code segment from context and transition to it. - </ul> + <li>CbC compiler on LLVM and Clang was implemented. + <li>LLVM IR was not modified. </ul> - <h3>code segments view</h3> - <div align='center'><img src="fig/cs_meta_csview.svg" width="35%"></div> - <h3>actual code segments transition</h3> - <div align='center'><img src="fig/cs_metacs.svg" width="35%"></div> </div> <div class='slide'> - <h2>Connect code segments with meta code segments</h2> - <table border='1' width='80%' align='center'> - <tr> - <td>original input code - <td>Clang genarates it - </tr> - <tr> - <td><pre class='small_code'> -__code code1() { - goto code2(); -} - -__code code2(){ - goto code3(); -} - </pre> - <td><pre class='small_code'> -__code code1(struct Context* context) { - <font color='red'>goto meta(context,Code2);</font> -} - -__code code2(struct Context* context){ - <font color='red'>goto meta(context,Code3);</font> -} - -__code meta(struct Context* context, enum Code next) { - goto (context->code[next])(context); -} - </pre> - </tr> - </table> + <h2>Future works</h2> + <ul> + <li>Operating system + <li>superset language + </ul> </div> </div> <!-- presentation -->