GNU Compiler Collection (GCC) Internals: Cilk Plus Transformation

Next: Gimplification pass, Previous: Parsing pass, Up: Passes   [Contents][Index]


9.2 Cilk Plus Transformation

If Cilk Plus generation (flag -fcilkplus) is enabled, all the Cilk Plus code is transformed into equivalent C and C++ functions. Majority of this transformation occurs toward the end of the parsing and right before the gimplification pass.

These are the major components to the Cilk Plus language extension:

  • Array Notations: During parsing phase, all the array notation specific information is stored in ARRAY_NOTATION_REF tree using the function c_parser_array_notation. During the end of parsing, we check the entire function to see if there are any array notation specific code (using the function contains_array_notation_expr). If this function returns true, then we expand them using either expand_array_notation_exprs or build_array_notation_expr. For the cases where array notations are inside conditions, they are transformed using the function fix_conditional_array_notations. The C language-specific routines are located in c/c-array-notation.c and the equivalent C++ routines are in the file cp/cp-array-notation.c. Common routines such as functions to initialize built-in functions are stored in array-notation-common.c.
  • Cilk keywords:
    • _Cilk_spawn: The _Cilk_spawn keyword is parsed and the function it contains is marked as a spawning function. The spawning function is called the spawner. At the end of the parsing phase, appropriate built-in functions are added to the spawner that are defined in the Cilk runtime. The appropriate locations of these functions, and the internal structures are detailed in cilk_init_builtins in the file cilk-common.c. The pointers to Cilk functions and fields of internal structures are described in cilk.h. The built-in functions are described in cilk-builtins.def.

      During gimplification, a new "spawn-helper" function is created. The spawned function is replaced with a spawn helper function in the spawner. The spawned function-call is moved into the spawn helper. The main function that does these transformations is gimplify_cilk_spawn in c-family/cilk.c. In the spawn-helper, the gimplification function gimplify_call_expr, inserts a function call __cilkrts_detach. This function is expanded by builtin_expand_cilk_detach located in c-family/cilk.c.

    • _Cilk_sync: _Cilk_sync is parsed like a keyword. During gimplification, the function gimplify_cilk_sync in c-family/cilk.c, will replace this keyword with a set of functions that are stored in the Cilk runtime. One of the internal functions inserted during gimplification, __cilkrts_pop_frame must be expanded by the compiler and is done by builtin_expand_cilk_pop_frame in cilk-common.c.

Documentation about Cilk Plus and language specification is provided under the "Learn" section in https://www.cilkplus.org . It is worth mentioning that the current implementation follows ABI 1.1.


Next: Gimplification pass, Previous: Parsing pass, Up: Passes   [Contents][Index]