summaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorBalaji V. Iyer <balaji.v.iyer@intel.com>2013-05-28 19:55:10 +0000
committerBalaji V. Iyer <bviyer@gcc.gnu.org>2013-05-28 12:55:10 -0700
commit36536d79af79b5a252356e79e62b851f3f2bedf9 (patch)
tree7bd32114bcd1a25d4a1caa95b66d2894e6e75dc7 /gcc/c-family
parent6d2bee95d82dcf40d115a3ba3a793a9b71a17a64 (diff)
downloadgcc-36536d79af79b5a252356e79e62b851f3f2bedf9.tar.gz
Implemented Cilk Plus Array Notation for C Compiler.
gcc/ChangeLog 2013-05-28 Balaji V. Iyer <balaji.v.iyer@intel.com> * doc/extend.texi (C Extensions): Added documentation about Cilk Plus array notation built-in reduction functions. * doc/passes.texi (Passes): Added documentation about changes done for Cilk Plus. * doc/invoke.texi (C Dialect Options): Added documentation about the -fcilkplus flag. * Makefile.in (C_COMMON_OBJS): Added c-family/array-notation-common.o. (BUILTINS_DEF): Depend on cilkplus.def. * builtins.def: Include cilkplus.def. Define DEF_CILKPLUS_BUILTIN. * builtin-types.def: Define BT_FN_INT_PTR_PTR_PTR. * cilkplus.def: New file. gcc/c-family/ChangeLog 2013-05-28 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-common.c (c_define_builtins): When cilkplus is enabled, the function array_notation_init_builtins is called. (c_common_init_ts): Added ARRAY_NOTATION_REF as typed. * c-common.def (ARRAY_NOTATION_REF): New tree. * c-common.h (build_array_notation_expr): New function declaration. (build_array_notation_ref): Likewise. (extract_sec_implicit_index_arg): New extern declaration. (is_sec_implicit_index_fn): Likewise. (ARRAY_NOTATION_CHECK): New define. (ARRAY_NOTATION_ARRAY): Likewise. (ARRAY_NOTATION_START): Likewise. (ARRAY_NOTATION_LENGTH): Likewise. (ARRAY_NOTATION_STRIDE): Likewise. * c-pretty-print.c (pp_c_postifix_expression): Added a new case for ARRAY_NOTATION_REF. (pp_c_expression): Likewise. * c.opt (flag_enable_cilkplus): New flag. * array-notation-common.c: New file. gcc/c/ChangeLog 2013-05-28 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-typeck.c (build_array_ref): Added a check to see if array's index is greater than one. If true, then emit an error. (build_function_call_vec): Exclude error reporting and checking for builtin array-notation functions. (convert_arguments): Likewise. (c_finish_return): Added a check for array notations as a return expression. If true, then emit an error. (c_finish_loop): Added a check for array notations in a loop condition. If true then emit an error. (lvalue_p): Added a ARRAY_NOTATION_REF case. (build_binary_op): Added a check for array notation expr inside op1 and op0. If present, we call another function to find correct type. * Make-lang.in (C_AND_OBJC_OBJS): Added c-array-notation.o. * c-parser.c (c_parser_compound_statement): Check if array notation code is used in tree, if so, then transform them into appropriate C code. (c_parser_expr_no_commas): Check if array notation is used in LHS or RHS, if so, then build array notation expression instead of regular modify. (c_parser_postfix_expression_after_primary): Added a check for colon(s) after square braces, if so then handle it like an array notation. Also, break up array notations in unary op if found. (c_parser_direct_declarator_inner): Added a check for array notation. (c_parser_compound_statement): Added a check for array notation in a stmt. If one is present, then expand array notation expr. (c_parser_if_statement): Likewise. (c_parser_switch_statement): Added a check for array notations in a switch statement's condition. If true, then output an error. (c_parser_while_statement): Similarly, but for a while. (c_parser_do_statement): Similarly, but for a do-while. (c_parser_for_statement): Similarly, but for a for-loop. (c_parser_unary_expression): Check if array notation is used in a pre-increment or pre-decrement expression. If true, then expand them. (c_parser_array_notation): New function. * c-array-notation.c: New file. * c-tree.h (is_cilkplus_reduce_builtin): Protoize. gcc/testsuite/ChangeLog 2013-05-28 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-c++-common/cilk-plus/AN/array_test1.c: New test. * c-c++-common/cilk-plus/AN/array_test2.c: Likewise. * c-c++-common/cilk-plus/AN/array_test_ND.c: Likewise. * c-c++-common/cilk-plus/AN/builtin_func_double.c: Likewise. * c-c++-common/cilk-plus/AN/builtin_func_double2.c: Likewise. * c-c++-common/cilk-plus/AN/gather-scatter-errors.c: Likewise. * c-c++-common/cilk-plus/AN/if_test.c: Likewise. * c-c++-common/cilk-plus/AN/sec_implicit_ex.c: Likewise. * c-c++-common/cilk-plus/AN/decl-ptr-colon.c: Likewise. * c-c++-common/cilk-plus/AN/dimensionless-arrays.c: Likewise. * c-c++-common/cilk-plus/AN/fn_ptr.c: Likewise. * c-c++-common/cilk-plus/AN/fp_triplet_values.c: Likewise. * c-c++-common/cilk-plus/AN/gather-scatter.c: Likewise. * c-c++-common/cilk-plus/AN/misc.c: Likewise. * c-c++-common/cilk-plus/AN/parser_errors.c: Likewise. * c-c++-common/cilk-plus/AN/parser_errors2.c: Likewise. * c-c++-common/cilk-plus/AN/parser_errors3.c: Likewise. * c-c++-common/cilk-plus/AN/parser_errors4.c: Likewise. * c-c++-common/cilk-plus/AN/rank_mismatch.c: Likewise. * c-c++-common/cilk-plus/AN/rank_mismatch2.c: Likewise. * c-c++-common/cilk-plus/AN/rank_mismatch3.c: Likewise. * c-c++-common/cilk-plus/AN/sec_implicit.c: Likewise. * c-c++-common/cilk-plus/AN/sec_implicit2.c: Likewise. * c-c++-common/cilk-plus/AN/sec_reduce_max_min_ind.c: Likewise. * c-c++-common/cilk-plus/AN/tst_lngth.c: Likewise. * c-c++-common/cilk-plus/AN/vla.c: Likewise. * c-c++-common/cilk-plus/AN/an-if.c: Likewise. * c-c++-common/cilk-plus/AN/builtin_fn_custom.c: Likewise. * c-c++-common/cilk-plus/AN/builtin_fn_mutating.c: Likewise. * c-c++-common/cilk-plus/AN/comma_exp.c: Likewise. * c-c++-common/cilk-plus/AN/conditional.c: Likewise. * c-c++-common/cilk-plus/AN/exec-once.c: Likewise. * c-c++-common/cilk-plus/AN/exec-once2.c: Likewise. * c-c++-common/cilk-plus/AN/gather_scatter.c: Likewise. * c-c++-common/cilk-plus/AN/n-ptr-test.c: Likewise. * c-c++-common/cilk-plus/AN/side-effects-1.c: Likewise. * c-c++-common/cilk-plus/AN/test_builtin_return.c: Likewise. * c-c++-common/cilk-plus/AN/test_sec_limits.c: Likewise. * gcc.dg/cilk-plus/cilk-plus.exp: New script. From-SVN: r199389
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog21
-rw-r--r--gcc/c-family/array-notation-common.c76
-rw-r--r--gcc/c-family/c-common.c1
-rw-r--r--gcc/c-family/c-common.def7
-rw-r--r--gcc/c-family/c-common.h26
-rw-r--r--gcc/c-family/c-pretty-print.c12
-rw-r--r--gcc/c-family/c.opt4
7 files changed, 147 insertions, 0 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 840a10e973f..d434a2f8ad6 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,24 @@
+2013-05-28 Balaji V. Iyer <balaji.v.iyer@intel.com>
+
+ * c-common.c (c_define_builtins): When cilkplus is enabled, the
+ function array_notation_init_builtins is called.
+ (c_common_init_ts): Added ARRAY_NOTATION_REF as typed.
+ * c-common.def (ARRAY_NOTATION_REF): New tree.
+ * c-common.h (build_array_notation_expr): New function declaration.
+ (build_array_notation_ref): Likewise.
+ (extract_sec_implicit_index_arg): New extern declaration.
+ (is_sec_implicit_index_fn): Likewise.
+ (ARRAY_NOTATION_CHECK): New define.
+ (ARRAY_NOTATION_ARRAY): Likewise.
+ (ARRAY_NOTATION_START): Likewise.
+ (ARRAY_NOTATION_LENGTH): Likewise.
+ (ARRAY_NOTATION_STRIDE): Likewise.
+ * c-pretty-print.c (pp_c_postifix_expression): Added a new case for
+ ARRAY_NOTATION_REF.
+ (pp_c_expression): Likewise.
+ * c.opt (flag_enable_cilkplus): New flag.
+ * array-notation-common.c: New file.
+
2013-05-14 Jakub Jelinek <jakub@redhat.com>
PR c++/57274
diff --git a/gcc/c-family/array-notation-common.c b/gcc/c-family/array-notation-common.c
new file mode 100644
index 00000000000..1d288464eee
--- /dev/null
+++ b/gcc/c-family/array-notation-common.c
@@ -0,0 +1,76 @@
+/* This file is part of the Intel(R) Cilk(TM) Plus support
+ This file contains the builtin functions for Array
+ notations.
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ Contributed by Balaji V. Iyer <balaji.v.iyer@intel.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/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree.h"
+#include "langhooks.h"
+#include "tree-iterator.h"
+#include "diagnostic-core.h"
+
+
+/* Returns true if the function call in FNDECL is __sec_implicit_index. */
+
+bool
+is_sec_implicit_index_fn (tree fndecl)
+{
+ if (TREE_CODE (fndecl) == ADDR_EXPR)
+ fndecl = TREE_OPERAND (fndecl, 0);
+
+ return
+ (TREE_CODE (fndecl) == FUNCTION_DECL
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CILKPLUS_SEC_IMPLICIT_INDEX);
+}
+
+/* Returns the first and only argument for FN, which should be a
+ sec_implicit_index function. FN's location in the source file is as
+ indicated by LOCATION. The argument to FN must be a constant integer
+ expression, otherwise returns -1. */
+
+HOST_WIDE_INT
+extract_sec_implicit_index_arg (location_t location, tree fn)
+{
+ tree fn_arg;
+ HOST_WIDE_INT return_int = 0;
+
+ if (TREE_CODE (fn) == CALL_EXPR)
+ {
+ fn_arg = CALL_EXPR_ARG (fn, 0);
+ if (TREE_CODE (fn_arg) == INTEGER_CST)
+ return_int = int_cst_value (fn_arg);
+ else
+ {
+ /* If the location is unknown, and if fn has a location, then use that
+ information so that the user has a better idea where the error
+ could be. */
+ if (location == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (fn))
+ location = EXPR_LOCATION (fn);
+ error_at (location, "__sec_implicit_index parameter must be an "
+ "integer constant expression");
+ return -1;
+ }
+ }
+ return return_int;
+}
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 7f5d3165b8b..dec887fb4c0 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -11424,6 +11424,7 @@ c_common_init_ts (void)
{
MARK_TS_TYPED (C_MAYBE_CONST_EXPR);
MARK_TS_TYPED (EXCESS_PRECISION_EXPR);
+ MARK_TS_TYPED (ARRAY_NOTATION_REF);
}
/* Build a user-defined numeric literal out of an integer constant type VALUE
diff --git a/gcc/c-family/c-common.def b/gcc/c-family/c-common.def
index 13113afe587..fac50e23777 100644
--- a/gcc/c-family/c-common.def
+++ b/gcc/c-family/c-common.def
@@ -55,6 +55,13 @@ DEFTREECODE (USERDEF_LITERAL, "userdef_literal", tcc_exceptional, 3)
or for the purpose of -Wsizeof-pointer-memaccess warning. */
DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", tcc_expression, 1)
+/* Array Notation expression.
+ Operand 0 is the array.
+ Operand 1 is the starting array index.
+ Operand 2 contains the number of elements you need to access.
+ Operand 3 is the stride. */
+DEFTREECODE (ARRAY_NOTATION_REF, "array_notation_ref", tcc_reference, 4)
+
/*
Local variables:
mode:c
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 4014651b876..d89982174bb 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -538,6 +538,10 @@ extern tree pushdecl_top_level (tree);
extern tree pushdecl (tree);
extern tree build_modify_expr (location_t, tree, tree, enum tree_code,
location_t, tree, tree);
+extern tree build_array_notation_expr (location_t, tree, tree, enum tree_code,
+ location_t, tree, tree);
+extern tree build_array_notation_ref (location_t, tree, tree, tree, tree, tree);
+extern bool find_rank (location_t, tree, tree, bool, size_t *);
extern tree build_indirect_ref (location_t, tree, ref_operator);
extern int field_decl_cmp (const void *, const void *);
@@ -1133,4 +1137,26 @@ enum stv_conv {
extern enum stv_conv scalar_to_vector (location_t loc, enum tree_code code,
tree op0, tree op1, bool);
+/* These #defines allow users to access different operands of the
+ array notation tree. */
+
+#define ARRAY_NOTATION_CHECK(NODE) TREE_CHECK (NODE, ARRAY_NOTATION_REF)
+#define ARRAY_NOTATION_ARRAY(NODE) \
+ TREE_OPERAND (ARRAY_NOTATION_CHECK (NODE), 0)
+#define ARRAY_NOTATION_START(NODE) \
+ TREE_OPERAND (ARRAY_NOTATION_CHECK (NODE), 1)
+#define ARRAY_NOTATION_LENGTH(NODE) \
+ TREE_OPERAND (ARRAY_NOTATION_CHECK (NODE), 2)
+#define ARRAY_NOTATION_STRIDE(NODE) \
+ TREE_OPERAND (ARRAY_NOTATION_CHECK (NODE), 3)
+
+extern int extract_sec_implicit_index_arg (location_t, tree);
+extern bool is_sec_implicit_index_fn (tree);
+extern void array_notation_init_builtins (void);
+extern struct c_expr fix_array_notation_expr (location_t, enum tree_code,
+ struct c_expr);
+extern bool contains_array_notation_expr (tree);
+extern tree expand_array_notation_exprs (tree);
+extern tree fix_conditional_array_notations (tree);
+extern tree find_correct_array_notation_type (tree);
#endif /* ! GCC_C_COMMON_H */
diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 13dd613d84e..b8af90c053c 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -1476,6 +1476,17 @@ pp_c_postfix_expression (c_pretty_printer *pp, tree e)
pp_c_right_bracket (pp);
break;
+ case ARRAY_NOTATION_REF:
+ pp_postfix_expression (pp, ARRAY_NOTATION_ARRAY (e));
+ pp_c_left_bracket (pp);
+ pp_expression (pp, ARRAY_NOTATION_START (e));
+ pp_colon (pp);
+ pp_expression (pp, ARRAY_NOTATION_LENGTH (e));
+ pp_colon (pp);
+ pp_expression (pp, ARRAY_NOTATION_STRIDE (e));
+ pp_c_right_bracket (pp);
+ break;
+
case CALL_EXPR:
{
call_expr_arg_iterator iter;
@@ -2150,6 +2161,7 @@ pp_c_expression (c_pretty_printer *pp, tree e)
case POSTINCREMENT_EXPR:
case POSTDECREMENT_EXPR:
case ARRAY_REF:
+ case ARRAY_NOTATION_REF:
case CALL_EXPR:
case COMPONENT_REF:
case BIT_FIELD_REF:
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 124c13986a8..857813474c9 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -843,6 +843,10 @@ fcanonical-system-headers
C ObjC C++ ObjC++
Where shorter, use canonicalized paths to systems headers.
+fcilkplus
+C ObjC C++ ObjC++ LTO Report Var(flag_enable_cilkplus) Init(0)
+Enable Cilk Plus
+
fcheck-new
C++ ObjC++ Var(flag_check_new)
Check the return value of new