GCC Middle and Back End API Reference
cilk-common.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "langhooks.h"
#include "expr.h"
#include "optabs.h"
#include "recog.h"
#include "tree-iterator.h"
#include "gimple.h"
#include "cilk.h"
Include dependency graph for cilk-common.c:

Functions

tree cilk_dot ()
tree cilk_arrow ()
static tree add_field ()
static tree install_builtin (const char *name, tree fntype, enum built_in_function code, bool publish)
void cilk_init_builtins ()
static tree get_frame_arg ()
void expand_builtin_cilk_pop_frame ()
void expand_builtin_cilk_detach ()
tree cilk_call_setjmp ()
static tree expand_cilk_sync ()
void gimplify_cilk_sync ()

Variables

tree cilk_trees [(int) CILK_TI_MAX]

Function Documentation

static tree add_field ( )
static

This function will add FIELD of type TYPE to a defined built-in structure. *NAME is the name of the field to be added.

tree cilk_arrow ( )

Returns the address of a field in FRAME_PTR, pointed by FIELD_NUMBER. (e.g. (&X)->y). Please see cilk_dot function for explanation of the FIELD_NUMBER. Returns a tree that is the type of the field represented by FIELD_NUMBER. If VOLATIL parameter is set to true then the returning field is set as volatile.

tree cilk_call_setjmp ( )

Returns a setjmp CALL_EXPR with FRAME->context as its parameter.

tree cilk_dot ( )

Returns the value in structure FRAME pointed by the FIELD_NUMBER (e.g. X.y). FIELD_NUMBER is an index to the structure FRAME_PTR. For details about these fields, refer to cilk_trees structure in cilk.h and cilk_init_builtins function in this file. Returns a TREE that is the type of the field represented by FIELD_NUMBER. If VOLATIL parameter is set to true then the returning field is set as volatile.

Referenced by get_frame_arg().

void cilk_init_builtins ( void  )

Creates and initializes all the built-in Cilk keywords functions and three structures: __cilkrts_stack_frame, __cilkrts_pedigree and __cilkrts_worker. Detailed information about __cilkrts_stack_frame and __cilkrts_worker structures are given in libcilkrts/include/internal/abi.h. __cilkrts_pedigree is described in libcilkrts/include/cilk/common.h.

 Now build the following __cilkrts_pedigree struct:
 struct __cilkrts_pedigree {
    uint64_t rank;
    struct __cilkrts_pedigree *parent;
  }   
 Build the Cilk Stack Frame:
 struct __cilkrts_stack_frame {
   uint32_t flags;
   uint32_t size;
   struct __cilkrts_stack_frame *call_parent;
   __cilkrts_worker *worker;
   void *except_data;
   void *ctx[4];
   uint32_t mxcsr;
   uint16_t fpcsr;
   uint16_t reserved;
   __cilkrts_pedigree pedigree;
 };   
 Now add them to a common structure whose fields are #defined to something
 that is used at a later stage.   
 We don't care about reserved, so no need to store it in cilk_trees.   
 Now let's do the following worker struct:

 struct __cilkrts_worker {
   __cilkrts_stack_frame *volatile *volatile tail;
   __cilkrts_stack_frame *volatile *volatile head;
   __cilkrts_stack_frame *volatile *volatile exc;
   __cilkrts_stack_frame *volatile *volatile protected_tail;
   __cilkrts_stack_frame *volatile *ltq_limit;
   int32_t self;
   global_state_t *g;
   local_state *l;
   cilkred_map *reducer_map;
   __cilkrts_stack_frame *current_stack_frame;
   void *reserved;
   __cilkrts_worker_sysdep_state *sysdep;
   __cilkrts_pedigree pedigree;
}    
 void __cilkrts_enter_frame_1 (__cilkrts_stack_frame *);   
 void __cilkrts_enter_frame_fast_1 (__cilkrts_stack_frame *);   
 void __cilkrts_pop_frame (__cilkrts_stack_frame *);   
 void __cilkrts_leave_frame (__cilkrts_stack_frame *);   
 void __cilkrts_sync (__cilkrts_stack_frame *);   
 void __cilkrts_detach (__cilkrts_stack_frame *);   
 __cilkrts_rethrow (struct stack_frame *);   
 __cilkrts_save_fp_ctrl_state (__cilkrts_stack_frame *);   
void expand_builtin_cilk_detach ( )

Expands the cilk_detach function call stored in EXP.

 TMP <- WORKER.TAIL
*TMP <- PARENT
 TMP <- TMP + 1
 WORKER.TAIL <- TMP    
 There is a release barrier (st8.rel, membar #StoreStore,
 sfence, lwsync, etc.) between the two stores.  On x86
 normal volatile stores have proper semantics; the sfence
 would only be needed for nontemporal stores (which we
 could generate using the storent optab, for no benefit
 in this case).

 The predicate may return false even for a REG if this is
 the limited release operation that only stores 0.   
 The memory barrier inserted above should not prevent
 the load of flags from being moved before the stores,
 but in practice it does because it is implemented with
 unspec_volatile.  In-order RISC machines should
 explicitly load flags earlier.   
void expand_builtin_cilk_pop_frame ( )

Expands the __cilkrts_pop_frame function call stored in EXP.

During LTO, the is_cilk_function flag gets cleared. If __cilkrts_pop_frame is called, then this definitely must be a cilk function.

static tree expand_cilk_sync ( )
static

This function will expand the _Cilk_sync keyword.

 Cilk_sync is converted to the following code:

 sf.pedigree = sf.worker->pedigree;
 if (frame.flags & CILK_FRAME_UNSYNCHED)
 {
    __cilkrts_save_fp_state (&sf);
    if (!builtin_setjmp (sf.ctx) 
        __cilkrts_sync (&sf); 
    else 
       if (sf.flags & CILK_FRAME_EXCEPTING) 
         __cilkrts_rethrow (&sf); 
  }
  sf.worker->pedigree.rank = sf.worker->pedigree.rank + 1;   
 Check if exception (0x10) bit is set in the sf->flags.   
 If the exception flag is set then call the __cilkrts_rethrow (&sf).   
static tree get_frame_arg ( )
static

Get the appropriate frame arguments for CALL that is of type CALL_EXPR.

If it is passed in as an address, then just use the value directly since the function is inlined.

References build2, build_int_cst(), cfun, cilk_dot(), CILK_TI_FRAME_PARENT, const0_rtx, expand_expr(), EXPAND_NORMAL, TREE_TYPE, and void_type_node.

void gimplify_cilk_sync ( )

Gimplifies the cilk_sync expression passed in *EXPR_P. Returns GS_ALL_DONE when finished.

static tree install_builtin ( const char *  name,
tree  fntype,
enum built_in_function  code,
bool  publish 
)
static

This function will define a built-in function of NAME, of type FNTYPE and register it under the built-in function code CODE. If PUBLISH is set then the declaration is pushed into the declaration list. CODE is the index to the cilk_trees array. *NAME is the name of the function to be added.

References lang_hooks::decls, and lang_hooks_for_decls::pushdecl.


Variable Documentation

tree cilk_trees[(int) CILK_TI_MAX]

This file is part of the Intel(R) Cilk(TM) Plus support This file contains the CilkPlus Intrinsics Copyright (C) 2013 Free Software Foundation, Inc. Contributed by Balaji V. Iyer balaj.nosp@m.i.v..nosp@m.iyer@.nosp@m.inte.nosp@m.l.com, Intel Corporation

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. This structure holds all the important fields of the internal structures, internal built-in functions, and Cilk-specific data types. Explanation of all the these fielsd are given in cilk.h.