This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hello Everyone, Attached, please find the 1st of ~22 patches that implements Cilk Plus. This patch will implement Elemental Functions into the C compiler. Please check it in to the trunk if it looks OK. Below, I will give you a small example about what elemental function is and how it can be useful. Details about elemental function can be found in the following link (http://software.intel.com/en-us/articles/elemental-functions-writing-data-parallel-code-in-cc-using-intel-cilk-plus) Let's say we have two for loops like this: int my_func (int x, int y); For (ii = 0; ii < 10000; ii++) X[ii] = my_func (Y[ii], Z[ii]); For (jj = 1; jj < 10000; jj++) { A[jj] = my_func (B[ii], A[jj-1]) + A[jj-1]; Assume that my_func's body is not visible during this compilation (e.g it is in some library). If a vectorized version for my_func is available, then the first for loop can be vectorized. However, even if such a version of my_func is available, the 2nd for loop cannot be vectorized. It would be beneficial if there is a vectorized version and a scalar version of my_func. This is where an elemental function comes to play. If we annotate *both* the function declaration and the function with the following attribute, the compiler will create a vector and scalar version of the function. __attribute__((vector)) my_func (int x, int y); __attribute__((vector)) my_func (int x, int y) { ... /* Body of the function. */ } If the architecture allows, the vector version will accept the parameters through vector registers and return the result through a vector register. There are several clauses that can be used to convey information about function parameters. The vector version of the function follows a mangling format that is based on the clauses provided and the vectorlength. All these changes are transparent to the user. A great application for elemental functions is writing libraries and reusable functions. Detailed explanations and syntax about these can be found in the Cilk Plus language specification document: http://software.intel.com/sites/default/files/m/6/3/1/cilk_plus_language_specification.pdf Here are the Changelog Entries: ============================================================================================ gcc/Changelog 2012-09-05 Balaji V. Iyer <balaji.v.iyer@intel.com> * attribs.c (is_elem_fn_attribute_p): New function. (decl_attributes): Added a check for Elemental function attribute when Cilk Plus is enabled. * cgraphunit.c (cgraph_decide_is_function_needed): Added a check for cloned elemental function when Cilk Plus is enabled. (cgraph_add_new_function): When Cilk Plus is enabled we call cgraph_get_create_node. (cgraph_analyze_functions): Added a check if the function call is a cloned elemental function when Cilk Plus is enabled. * elem-function-common.c (find_processor_code): New function. (find_vlength_code): Likewise. (rename_elem_fn): Likewise. (find_suffix): Likewise. (find_elem_fn_parm_type_1): Likewise. (find_elem_fn_parm_type): Likewise. (find_elem_fn_name): Likewise. (extract_elem_fn_values): Likewise. (is_elem_fn): Likewise. * expr.c (expand_expr_real_1): Added a check if Cilk Plus is enabled. * function.h (struct function): Added elem_fn_already_cloned field. * gimplify.c (gimplify_function_tree): Added a check if Cilk Plus is enabled and if the function is an elemental function. If so, then call the function to clone elemental function. * langhooks.c (lhd_elem_fn_create_fn): New function. * langhooks-def.h (LANG_HOOKS_CILKPLUS): New define. (LANG_HOOK_DECLS): Added LANG_HOOKS_CILKPLUS field. * langhooks.h (struct lang_hooks_for_cilkplus): New struct. (struct lang_hooks): Added a field called cilkplus. * tree.h (tree_function_decl): Added a new field called elem_fn_already_cloned. (DECL_ELEM_FN_ALREADY_CLONED): New define. * tree-data-ref.c (find_data_references_in_stmt): Added a check for an elemental function call when Cilk Plus is enabled. * tree-inline.c (elem_fn_copy_arguments_for_versioning): New function. (initialize_elem_fn_cfun): Likewise. (tree_elem_fn_versioning): Likewise. * tree-vect-stmts.c (vect_get_vec_def_for_operand): Check parm type for an elemental function when Cilk Plus is enabled and set data definition accordingly. (elem_fn_vect_get_vec_def_for_operand): New function. (vect_finish_stmt_generation): Added a check for elemental function. (vectorizable_function): Check if the function call is a Cilk Plus elemental function. If so, then insert the appopriate mangled name. (vectorizable_call): Eliminate the argument requirement when Cilk Plus is enabled for vectorization. Also, set thee appropriate data def. for an elemental function call. (elem_fn_linear_init_vector): New function. * tree.c (build_elem_fn_linear_vector): Likewise. gcc/c-family/ChangeLog 2012-09-05 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-common.c (struct c_common_attribute_table): Added vector attribute for Cilk Plus elemental function. (handle_vector_atribute): New function. * c-cpp-elem-function.c (create_processor_attribute): Likewise. (create_optimize_attribute): Likewise. (replace_return_with_new_var): Likewise. (elem_fn_build_array): Likewise. (replace_array_ref_for_vec): Likewise. (fix_elem_fn_return_value): Likewise. (add_elem_fn_loop): Likewise. (add_elem_fn_mask): Likewise. (call_graph_add_fn): Likewise. (elem_fn_create_fn): Likewise. * c.opt (-fcilkplus): Added new flag. gcc/c/ChangeLog 2012-09-05 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-decl.c (bind): Added a check for non NULL scope. * c-parser.c (c_parser_declaration_or_fndef): Added a check if Cilk Plus defined. If so, then we save the arguments for a function declaration. (c_parser_attributes): Added a check if Cilk Plus is enabled and if elemental function vector attribute is given. If so, then call the function c_parser_elem_fn_expr_list (). (c_parser_elem_fn_processor_clause): New function. (c_parser_elem_fn_uniform_clause): Likewise. (c_parser_elem_fn_linear_clause): Likewise. (c_parser_elem_fn_vlength_clause): Likewise. (c_parser_elem_fn_expr_list): Likewise. =========================================================================================== Thanking You, Yours Sincerely, Balaji V. Iyer.
Attachment:
elem_fn_c_patch.txt
Description: elem_fn_c_patch.txt
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |