Hello Everyone,
This patch is for the Cilkplus branch affecting both C and C++ compiler. It
implements the builtin function called "__sec_implicit_index" that is part of
the Array Notations in Cilkplus.
Thanking You,
Yours Sincerely,
Balaji V. Iyer.
diff --git a/gcc/ChangeLog.cilk b/gcc/ChangeLog.cilk
index 8e4fab9..98e0528 100644
--- a/gcc/ChangeLog.cilk
+++ b/gcc/ChangeLog.cilk
@@ -1,3 +1,14 @@
+2012-01-26 Balaji V. Iyer <balaji.v.i...@intel.com>
+
+ * array-notation-common.c (array_notation_init_builtins): Added the
+ internal array notation function "__sec_reduce_implicit_index."
+ (is_sec_implicit_index_fn): New function.
+ (extract_sec_implicit_index_arg): Likewise.
+ * c-array-notation.c (extract_array_notation_exprs): Added a check to
+ see if we encountered sec_implicit_index function.
+ (replace_array_notations): Likewise.
+ (build_array_notation_expr): Likewise.
+
2012-01-25 Balaji V. Iyer <balaji.v.i...@intel.com>
* c-array-notation.c (replace_array_notations): Added a new bool as
diff --git a/gcc/array-notation-common.c b/gcc/array-notation-common.c
index 059adc4..b06f495 100644
--- a/gcc/array-notation-common.c
+++ b/gcc/array-notation-common.c
@@ -38,6 +38,10 @@ along with GCC; see the file COPYING3. If not see
#include "output.h"
#include "dwarf2out.h"
+int extract_sec_implicit_index_arg (tree);
+bool is_sec_implicit_index_fn (tree);
+void array_notation_init_builtins (void);
+
static void
mark_cold (tree fndecl)
{
@@ -97,5 +101,62 @@ array_notation_init_builtins (void)
new_func = build_fn_decl ("__sec_reduce_max_ind", func_type);
mark_cold (new_func);
new_func = lang_hooks.decls.pushdecl (new_func);
+
+ func_type = build_function_type_list (integer_type_node, integer_type_node,
+ NULL_TREE);
+ new_func = build_fn_decl ("__sec_implicit_index", func_type);
+ mark_cold (new_func);
+ new_func = lang_hooks.decls.pushdecl (new_func);
+
return;
}
+
+bool
+is_sec_implicit_index_fn (tree func_name)
+{
+ const char *function_name = NULL;
+
+ if (!func_name)
+ return false;
+
+ if (TREE_CODE (func_name) == IDENTIFIER_NODE)
+ function_name = IDENTIFIER_POINTER (func_name);
+ else if (TREE_CODE (func_name) == ADDR_EXPR)
+ {
+ func_name = TREE_OPERAND (func_name, 0);
+ if (TREE_CODE (func_name) == FUNCTION_DECL)
+ if (DECL_NAME (func_name))
+ function_name = IDENTIFIER_POINTER (DECL_NAME (func_name));
+ }
+
+ if (!function_name)
+ return false;
+ else if (!strcmp (function_name, "__sec_implicit_index"))
+ return true;
+ else
+ return false;
+}
+
+int
+extract_sec_implicit_index_arg (tree fn)
+{
+ tree fn_arg;
+ HOST_WIDE_INT return_int = 0;
+ if (!fn)
+ return -1;
+
+ if (TREE_CODE (fn) == CALL_EXPR)
+ {
+ fn_arg = CALL_EXPR_ARG (fn, 0);
+ if (really_constant_p (fn_arg))
+ return_int = (int)int_cst_value (fn_arg);
+ else
+ {
+ error ("__sec_implicit_index parameter must be constant integer "
+ "expression");
+ error ("Bailing out due to previous error");
+ exit (ICE_EXIT_CODE);
+ }
+ }
+ return return_int;
+}
diff --git a/gcc/c-array-notation.c b/gcc/c-array-notation.c
index 1dac533..3ff52dc 100644
--- a/gcc/c-array-notation.c
+++ b/gcc/c-array-notation.c
@@ -47,7 +47,8 @@ struct c_expr fix_array_notation_expr (location_t, enum
tree_code,
static bool is_builtin_array_notation_fn (tree func_name, an_reduce_type
*type);
static tree fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var);
bool contains_array_notation_expr (tree expr);
-
+extern bool is_sec_implicit_index_fn (tree);
+extern int extract_sec_implicit_index_arg (tree fn);
/* This function is to find the rank of an array notation expression.
* For example, an array notation of A[:][:] has a rank of 2.
*/
@@ -159,6 +160,18 @@ extract_array_notation_exprs (tree node, bool
ignore_builtin_fn,
return;
}
}
+ if (is_sec_implicit_index_fn (CALL_EXPR_FN (node)))
+ {
+ ii = *list_size;
+ new_array_list = (tree *) xrealloc (*array_list, (ii + 1) *
+ sizeof (tree));
+ gcc_assert (new_array_list);
+ new_array_list[ii] = node;
+ ii++;
+ *list_size = ii;
+ *array_list = new_array_list;
+ return;
+ }
if (TREE_CODE (TREE_OPERAND (node, 0)) == INTEGER_CST)
{
int length = TREE_INT_CST_LOW (TREE_OPERAND (node, 0));
@@ -223,6 +236,15 @@ replace_array_notations (tree *orig, bool
ignore_builtin_fn, tree *list,
}
return;
}
+ if (is_sec_implicit_index_fn (CALL_EXPR_FN (*orig)))
+ {
+ for (ii = 0; ii < array_size; ii++)
+ {
+ if (*orig == list[ii])
+ *orig = array_operand[ii];
+ }
+ return;
+ }
if (TREE_CODE (TREE_OPERAND (*orig, 0)) == INTEGER_CST)
{
int length = TREE_INT_CST_LOW (TREE_OPERAND (*orig, 0));
@@ -324,19 +346,8 @@ build_array_notation_expr (location_t location, tree lhs,
tree lhs_origtype,
return NULL_TREE;
}
}
-
-
-
- /* if (TREE_CODE (rhs) == CALL_EXPR) */
- /* { */
- /* if (is_builtin_array_notation_fn (CALL_EXPR_FN (rhs), &type)) */
- /* { */
- /* loop = build_reduce_expr (location, lhs, lhs_origtype, modifycode, */
- /* rhs_loc, rhs, rhs_origtype); */
- /* return loop; */
- /* } */
- /* } */
-
+ rhs_list_size = 0;
+ rhs_list = NULL;
extract_array_notation_exprs (rhs, true, &rhs_list, &rhs_list_size);
if (lhs_rank == 0 && rhs_rank != 0)
@@ -624,12 +635,60 @@ build_array_notation_expr (location_t location, tree lhs,
tree lhs_origtype,
}
}
}
+
+ for (ii = 0; ii < rhs_list_size; ii++)
+ {
+ if (TREE_CODE (rhs_list[ii]) == CALL_EXPR)
+ {
+ int idx_value = 0;
+ tree func_name = CALL_EXPR_FN (rhs_list[ii]);
+ if (TREE_CODE (func_name) == ADDR_EXPR)
+ if (is_sec_implicit_index_fn (func_name))
+ {
+ idx_value = extract_sec_implicit_index_arg (rhs_list[ii]);
+ if (idx_value < lhs_rank && idx_value >= 0)
+ rhs_array_operand[ii] = lhs_var[idx_value];
+ else
+ {
+ error ("__sec_implicit_index parameter must be less "
+ " than the rank of the Left Hand Side expr. ");
+ error ("Bailing out due to the previous error.");
+ exit (ICE_EXIT_CODE);
+ }
+ }
+ }
+ }
+
replace_array_notations (&rhs, true, rhs_list, rhs_array_operand,
rhs_list_size);
array_expr_rhs = rhs;
}
else
{
+ for (ii = 0; ii < rhs_list_size; ii++)
+ {
+ if (TREE_CODE (rhs_list[ii]) == CALL_EXPR)
+ {
+ int idx_value = 0;
+ tree func_name = CALL_EXPR_FN (rhs_list[ii]);
+ if (TREE_CODE (func_name) == ADDR_EXPR)
+ if (is_sec_implicit_index_fn (func_name))
+ {
+ idx_value = extract_sec_implicit_index_arg (rhs_list[ii]);
+ if (idx_value < lhs_rank && idx_value >= 0)
+ rhs_array_operand[ii] = lhs_var[idx_value];
+ else
+ {
+ error ("__sec_implicit_index parameter must be less "
+ " than the rank of the Left Hand Side expr. ");
+ error ("Bailing out due to the previous error.");
+ exit (ICE_EXIT_CODE);
+ }
+ }
+ }
+ }
+ replace_array_notations (&rhs, true, rhs_list, rhs_array_operand,
+ rhs_list_size);
array_expr_rhs = rhs;
rhs_expr_incr[0] = NULL_TREE;
}
diff --git a/gcc/cp/ChangeLog.cilk b/gcc/cp/ChangeLog.cilk
index 0baad4b..cf9d993 100644
--- a/gcc/cp/ChangeLog.cilk
+++ b/gcc/cp/ChangeLog.cilk
@@ -1,3 +1,10 @@
+2012-01-26 Balaji V. Iyer <balaji.v.i...@intel.com>
+
+ * cp-array-notation.c (extract_array_notation_exprs): Added a check
+ to see if the call expr is sec_implicit_index function.
+ (replace_array_notations): Likewise.
+ (build_x_array_notation_expr): Likewise.
+
2012-01-22 Balaji V. Iyer <balaji.v.i...@intel.com>
* cp-array-notation.c (is_builtin_array_notation_fn): Initialized
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index ec5532e..2a27c62 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -53,6 +53,10 @@ static bool is_builtin_array_notation_fn (tree,
an_reduce_type *);
static tree build_x_reduce_expr (tree, enum tree_code, tree, tsubst_flags_t,
an_reduce_type);
bool contains_array_notation_expr (tree);
+extern bool is_sec_implicit_index_fn (tree);
+extern int extract_sec_implicit_index_arg (tree fn);
+void extract_array_notation_exprs (tree node, bool ignore_builtin_fn,
+ tree **array_list, int *list_size);
/* This function is to find the rank of an array notation expression.
* For example, an array notation of A[:][:] has a rank of 2.
@@ -165,6 +169,18 @@ extract_array_notation_exprs (tree node, bool
ignore_builtin_fn,
return;
}
}
+ if (is_sec_implicit_index_fn (CALL_EXPR_FN (node)))
+ {
+ ii = *list_size;
+ new_array_list = (tree *) xrealloc (*array_list, (ii + 1) *
+ sizeof (tree));
+ gcc_assert (new_array_list);
+ new_array_list[ii] = node;
+ ii++;
+ *list_size = ii;
+ *array_list = new_array_list;
+ return;
+ }
if (TREE_CODE (TREE_OPERAND (node, 0)) == INTEGER_CST)
{
int length = TREE_INT_CST_LOW (TREE_OPERAND (node, 0));
@@ -229,6 +245,15 @@ replace_array_notations (tree *orig, bool
ignore_builtin_fn, tree *list,
}
return;
}
+ if (is_sec_implicit_index_fn (CALL_EXPR_FN (*orig)))
+ {
+ for (ii = 0; ii < array_size; ii++)
+ {
+ if (*orig == list[ii])
+ *orig = array_operand[ii];
+ }
+ return;
+ }
if (TREE_CODE (TREE_OPERAND (*orig, 0)) == INTEGER_CST)
{
int length = TREE_INT_CST_LOW (TREE_OPERAND (*orig, 0));
@@ -603,12 +628,60 @@ build_x_array_notation_expr (tree lhs, enum tree_code
modifycode, tree rhs,
}
}
}
+ for (ii = 0; ii < rhs_list_size; ii++)
+ {
+ if (TREE_CODE (rhs_list[ii]) == CALL_EXPR)
+ {
+ int idx_value = 0;
+ tree func_name = CALL_EXPR_FN (rhs_list[ii]);
+ if (TREE_CODE (func_name) == ADDR_EXPR)
+ if (is_sec_implicit_index_fn (func_name))
+ {
+ idx_value = extract_sec_implicit_index_arg (rhs_list[ii]);
+ if (idx_value < lhs_rank && idx_value >= 0)
+ rhs_array_operand[ii] = lhs_var[idx_value];
+ else
+ {
+ error ("__sec_implicit_index parameter must be less "
+ " than the rank of the Left Hand Side expr. ");
+ error ("Bailing out due to the previous error.");
+ exit (ICE_EXIT_CODE);
+ }
+ }
+ }
+ }
+
replace_array_notations (&rhs, true, rhs_list, rhs_array_operand,
rhs_list_size);
array_expr_rhs = rhs;
}
else
{
+ for (ii = 0; ii < rhs_list_size; ii++)
+ {
+ if (TREE_CODE (rhs_list[ii]) == CALL_EXPR)
+ {
+ int idx_value = 0;
+ tree func_name = CALL_EXPR_FN (rhs_list[ii]);
+ if (TREE_CODE (func_name) == ADDR_EXPR)
+ if (is_sec_implicit_index_fn (func_name))
+ {
+ idx_value = extract_sec_implicit_index_arg (rhs_list[ii]);
+ if (idx_value < lhs_rank && idx_value >= 0)
+ rhs_array_operand[ii] = lhs_var[idx_value];
+ else
+ {
+ error ("__sec_implicit_index parameter must be less "
+ " than the rank of the Left Hand Side expr. ");
+ error ("Bailing out due to the previous error.");
+ exit (ICE_EXIT_CODE);
+ }
+ }
+ }
+ }
+
+ replace_array_notations (&rhs, true, rhs_list, rhs_array_operand,
+ rhs_list_size);
array_expr_rhs = rhs;
rhs_expr_incr[0] = NULL_TREE;
}
diff --git a/gcc/testsuite/ChangeLog.cilk b/gcc/testsuite/ChangeLog.cilk
index c032e14..7f67680 100644
--- a/gcc/testsuite/ChangeLog.cilk
+++ b/gcc/testsuite/ChangeLog.cilk
@@ -1,5 +1,10 @@
2012-01-25 Balaji V. Iyer <balaji.v.i...@intel.com>
+ * gcc.dg/cilk-plus/array_notation_tests/sec_implicit_ex.c: New.
+ * g++.dg/cilk-plus/array_notation_tests/sec_implicit_ex.cc: Likewise.
+
+2012-01-25 Balaji V. Iyer <balaji.v.i...@intel.com>
+
* gcc.dg/cilk-plus/array_notation_tests/builtin_func_double.c: New.
2012-01-21 Balaji V. Iyer <balaji.v.i...@intel.com>
diff --git
a/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/sec_implicit_ex.cc
b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/sec_implicit_ex.cc
new file mode 100644
index 0000000..437b264
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cilk-plus/array_notation_tests/sec_implicit_ex.cc
@@ -0,0 +1,45 @@
+#define HAVE_IO 1
+
+#if HAVE_IO
+#include <iostream>
+using namespace std;
+#endif
+#include <cstdlib>
+/* char __sec_reduce_add (int *); */
+int main(int argc, char **argv)
+{
+ int jj, kk, array_3C[10][10][10];
+ int ii,array[10], y = 0, y_int = 0, array2[10], array_3[10][10][10];
+ double x, yy, array3[10], array4[10];
+
+ array[:] = __sec_implicit_index (0);
+ array_3[:][:][:] = __sec_implicit_index (1) + __sec_implicit_index(0) +
+ __sec_implicit_index (2);
+
+ for (ii = 0; ii < 10; ii++)
+ for (jj = 0; jj < 10; jj++)
+ for (kk = 0; kk < 10; kk++)
+ {
+ array_3C[ii][jj][kk] = ii+jj+kk;
+ }
+#if HAVE_IO
+ for (ii = 0; ii < 10; ii++)
+ for (jj = 0; jj < 10; jj++)
+ for (kk = 0; kk < 10; kk++)
+ {
+ cout << "Computed: " << array_3[ii][jj][kk] << " Correct: " <<
+ array_3C[ii][jj][kk];
+ /*
+ printf("Computed: %3d\t Correct: %3d\t", array_3[ii][jj][kk],
+ array_3C[ii][jj][kk]);
+ */
+ if (array_3[ii][jj][kk] == array_3C[ii][jj][kk])
+ cout << " OK " << endl;
+ else
+ cout << " ERROR " << endl;
+ }
+#endif
+
+
+ return 0;
+}
diff --git
a/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/sec_implicit_ex.c
b/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/sec_implicit_ex.c
new file mode 100644
index 0000000..0a4d806
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cilk-plus/array_notation_tests/sec_implicit_ex.c
@@ -0,0 +1,41 @@
+#define HAVE_IO 1
+
+#if HAVE_IO
+#include <stdio.h>
+#endif
+#include <stdlib.h>
+
+/* char __sec_reduce_add (int *); */
+int main(int argc, char **argv)
+{
+ int jj, kk, array_3C[10][10][10];
+ int ii,array[10], y = 0, y_int = 0, array2[10], array_3[10][10][10];
+ double x, yy, array3[10], array4[10];
+
+ array[:] = __sec_implicit_index (0);
+ array_3[:][:][:] = __sec_implicit_index (1) + __sec_implicit_index(0) +
+ __sec_implicit_index (2);
+
+ for (ii = 0; ii < 10; ii++)
+ for (jj = 0; jj < 10; jj++)
+ for (kk = 0; kk < 10; kk++)
+ {
+ array_3C[ii][jj][kk] = ii+jj+kk;
+ }
+#if HAVE_IO
+ for (ii = 0; ii < 10; ii++)
+ for (jj = 0; jj < 10; jj++)
+ for (kk = 0; kk < 10; kk++)
+ {
+ printf("Computed: %3d\t Correct: %3d\t", array_3[ii][jj][kk],
+ array_3C[ii][jj][kk]);
+ if (array_3[ii][jj][kk] == array_3C[ii][jj][kk])
+ printf("OK\n");
+ else
+ printf("ERROR\n");
+ }
+#endif
+
+
+ return 0;
+}