# HG changeset patch # User Kaito Tokumori # Date 1436017929 -32400 # Node ID 607acd92b8ebe0eb5ef4eda8e1dedae0520a43dd # Parent 40be058f9df89424ccb01a25bf688235004d5066 fix diff -r 40be058f9df8 -r 607acd92b8eb presentation/presen.html --- a/presentation/presen.html Sat Jul 04 21:20:22 2015 +0900 +++ b/presentation/presen.html Sat Jul 04 22:52:09 2015 +0900 @@ -59,9 +59,10 @@
- Kaito Tokumori, Shinji Kono + Kaito Tokumori, Shinji Kono
+ University of the Ryukyus
@@ -72,10 +73,10 @@

Objective

Introducing new units of programming

@@ -102,7 +103,7 @@
  • Add meta computation.
  • Extract concurrency from programming units. -

    It is not easy in the traditional units.

    +

    It is not easy to do this in the traditional units.

    @@ -139,14 +140,13 @@

    Meta code / data segments

    + A thread of code segments has a context as a meta data segment
    • Execution contexts: Thread
    • Type signatures of data segments.
    • Data segment linkages: Pointer -
    • Machine code +
    • Machine code of code segments
    -

    Meta code segments are executed right after the goto.

    -

    Meta data segments are kinds of process data.

    @@ -154,14 +154,15 @@
    • An implementation of code segments.
    • CbC stands for Continuation based C. -
    • Basic syntax is the same as the C. -
    • Code segments are set of C statements with goto. +
    • Basic syntax is the same as the C, except __code and goto. +
    • __code is a type of code segment +
    • Code segments end with parameterized goto.
    • Data segments are inplemented as C structures.
    -

    CbC sample

    +

    code segment syntax

    @@ -185,19 +185,18 @@
    -

    CbC sample with data segments

    +

    code segment syntax with data segments

    @@ -175,9 +176,8 @@
                   
      -
    • Code segments like C functions. -
    • CbC transition is goto. -
    • Code segments do not return to previous. +
    • code segment transition is goto. +
    • Code segments have no return statement.
    • There are no return values.
    -__code code(struct Context* context, struct Allocate* allocate,
    +__code code1(struct Allocate* allocate,
                 struct Element* element) {
    -    allocate->after_append = Code2;
         element ->value        = 10;
    -    goto meta(context, Append);
    +    struct List* list = (struct List *)malloc(sizeof( struct List));
    +    goto append(allocate,list, element);
     }
     
    -__code append(struct Context* context, struct Allocate* allocate,
    -              struct List* list, struct Element* element) {
    +__code append(struct Allocate* allocate, struct List* list, struct Element* element) {
         if(list->head) {
             list->tail->next = element;
         } else {
    @@ -205,19 +204,12 @@
         }
         list->tail       = element;
         list->tail->next = 0;
    -    goto meta(context, allocate->after_append);
    -}
    -
    -__code meta(struct Context* context, enum Code next) {
    -    goto (context->code[next])(context);
    +    goto code2(allocate,list, element);
     }
                   
      -
    • A part of list program. -
    • Code segment transition into next one via meta code segment. -
    • Context has code segments name. -
    • Context give meta code segments next code segment pointer. +
    • data segments are arguments of a code segment and a goto statement.
    @@ -226,9 +218,9 @@

    CbC compilers

      -
    • Micro-C(one pass standalone compiler) -
    • GCC(GNU Compiler Collection) -
    • LLVM and Clang +
    • Micro-C(one pass standalone compiler) 2001 +
    • on GCC(GNU Compiler Collection) 2008 +
    • on LLVM and Clang (Compiler framework) 2014
      • The latest!
      @@ -236,64 +228,47 @@
    -

    What are LLVM and Clang?

    -
      -
    • Compiler frameworks. -
    • has a intermidiate language which is called LLVM IR, LLVM language or LLVM bitcode. -
    • Translates LLVM IR to assembly language. -
    • Many kinds of optimization. -
    • Clang is C, C++ and Obj-C compiler frontend. -
    • Clang uses LLVM for compiler backend. -
    -
    - -
    -

    Why?

    -
      -
    • Apple supported. -
    • OS X default compiler. -
    • LLVM IR has readable documents. -
    • More readable and modifiable than GCC. -
    -
    - -

    LLVM and Clang's compilation flow

      +
    • AST : Abstract Syntax Tree (C++ object) +
    • LLVM IR is Intermediate Representation (bit code).
    • Clang translate C/C++/Obj-C into LLVM IR. -
    • LLVM translate LLVM IR into assembly code. -
    • LLVM optimize all of intermidiate representation. +
    • SelectionDAG : Codegenerator internal +
    • Machine Code : LLVM Machine code
    -

    LLVM and Clang's intermidiate representations

    +

    Advantage of LLVM implementation

      -
    • clang AST -
    • LLVM IR -
    • SelectionDAG -
    • Machine Code -
    • MC Layer +
    • Apple supported (working on OS X). +
    • OS X default compiler. +
    • LLVM IR is well documented. +
    • better than GCC
    -

    Intermidiate representations are not modified.

    -

    Clang AST

    +

    CbC implementation strategy

      -
    • The first intermidiate representation. -
    • Representation of the source codes structure. -
    • Basic node type: Stmt, Decl, Expr. +
    • define special type __coee for code segments +
    • no code segment prototyping (othewise it beomes quite messy ) +
    • code segments are implemented as tail call force functions +
    • Do not modify IR (Intermidiate representations ) +
    • goto statement is actualy a function call with following return statement
      + goto f() --> { f() ; return; } +
    • allow mixing code segments and normal function calls ( goto with environment )

    LLVM IR

      -
    • The main intermidiate representation. -
    • LLVM translate it into assembly codes. -
    • Three forms: in-memory compiler IR, on-disk bitcode, assembly language. +
    • Intermediate Representation (bit code). +
    • Three forms: in-memory IR, bitcode stream, human readable language. +
    • it has precise type, data size, alignment +
    • funcion call flags : tail, fastcc, cc10, cc11, erlang, ghc
    @@ -311,54 +286,15 @@
    -

    Basic strategy of implementating

    +

    CbC implementation strategy

      -
    • Code segments are implemented by C functions. +
    • Code segments are implemented by C functions with return-type __code.
    • Data segments are implemented by C structs. -
    • Transition is implemented by tail call elimination. -
    - - -
    -

    Parser

    -
      -
    • __code type -
    • Prototype declaration generating -
    • Goto syntax for transitions -
    -
    -
    - -
    -

    __code type

    -
    - -
      -
    • Code segments are implemented __code type functions. -
    • Handled like void functions. -
    - -
    -

    Prototype declaration generating

    @@ -374,7 +310,7 @@
    original input code - Clang genarates it + Clang genarates it internaly
    @@ -404,19 +340,6 @@
     
           

    goto syntax for transition

    - - -
    -
      -
    • New goto syntax for transition. -
    • Generate normal function call. -
    • Tail call elimination is forced later. -
    -
    -
    - -
    -

    goto syntax for transition

    • Add return statement after goto transition.
    • It is one the requirement force to tail call elimination. @@ -446,8 +369,8 @@

      Forcing Tail Call Elimination

      -

      TCE is enabled at CodeGen.

      -

      TCE is act at SelectionDAGISel.

      +

      Tail call flang is set in CodeGen.

      +

      Ensure TCE in SelectionDAGISel.

      @@ -455,43 +378,20 @@

      What is tail call elimination?

        -
      • Tail call is immediately followed by return. +
      • Tail call is a function call immediately followed by return. +
      • If stack frame have to be unchanged,
      • Tail call elimination replace tail call's call instructions with jmp instructions. -
      • Transitions are implemented by forced tail call elimination. +
      • that is tail call function should have the same arguments and the same return type
    -

    Forcing Tail Call Elimination

    -
      -
    • LLVM IR has function call flags. -
    • tail mean it is tail call. -
    • Calling convention tell compiler how callee functions receive parameters from their caller. -
    - - - - -
    -
    -define fastcc void @factorial(i32 %x) #0 {
    -  entry:
    -  tail call fastcc void @factorial0(i32 1, i32 %x)
    -  ret void
    -}
    -              
    -
    -

    Use them for force to tail call elimination.

    -
    - -
    -

    Forcing Tail Call Elimination

    -

    Tail Call Elimination requirements

    +

    Tail Call Elimination requirements

    • Set tail flag at the code segments call. -
    • Tailcallopt is enabled. +
    • Tailcallopt path is enabled in the compiler.
    • The caller and calle's calling conventions must be the same and their types should be cc10, cc11 or fastcc.
    • Return value type has to be the same as the caller's.
    @@ -505,20 +405,31 @@
  • Fast cc is used consistently in code segments call.
  • All the code segments return value type is void. + This is the reason why we need __code type for code segments. +
  • + +
    +

    goto a code segment from a normal C function

    +
      +
    • Assume we have code segment g and normal funciton f +
    • simply goto g() in C function f() +
    • goto g() never returns to function f +
    + How to return to C from a code segment?

    Goto with environment

    -
      -
    • Code segments do not have return. -
    • Code segments can return C functions by Goto with environment. -
    • In the GCC, use nested functions. -
    • In the LLVM and Clang, use setjmp and longjmp. +

      + We want provide continuation of function f. + The continuation is not a simple code segment, + because code segment has not state. + We represent the continuation with a code segment (__return) and a meta data segment (__environment).

    -

    Sample code of Goto with environment

    +

    Syntax of Goto with environment

      @@ -552,9 +463,19 @@
      -

      Implementing goto with environment

      +

      Implementation of goto with environment

      + Several ways to implementation
        -
      • Include setjmp.h always. +
      • setmp/longjmp (LLVM) +
      • nested function closure with thread safe variable (GCC) +
      • direct manipulation of frame pointer and return value (Micro-C) +
      +
      + +
      +

      LLVM Implementation of goto with environment

      +
        +
      • Include setjmp.h internally.
      • Generate C struct for saving environment.
        • This struct is __environment.