From patchwork Thu Jan 26 17:27:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iyer, Balaji V" X-Patchwork-Id: 138000 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A53B3B6EF7 for ; Fri, 27 Jan 2012 04:34:08 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1328204051; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:References: In-Reply-To:Content-Type:MIME-Version:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=uvWoyM8rW2MGcHiyQCWm3xZ8n4o=; b=SPcKBfYaVCOX4/H EEjll1exO9N0HsBADDxe9OqtyNMCnuzpOUrDlH7NGPknjyRHqDEj3gUHDeA2/794 RdZbE4DK3RNjvEncCspV8xJ+xpHZVtakkVkgMN3MMNx55V8k2QFASuzA33Yzi0By BHHM0WzruHpi/RrlYv+/5Pf+AO1I= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:Received:Received:From:To:Subject:Date:Message-ID:References:In-Reply-To:Content-Type:MIME-Version:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=X3o+6z73iQ7OR5Yxkzx2qF3PtoiiQeuIDK5JZRJBJetr+KXhooFCMYuWHQI0wA ndqbID9s/faFxRDwWroMb/Im8Y/UBFPfZDgE4b0xB5SjzjHk8D8AiMg72IxMiRFe P7Sp8SC07Do5OAwH4XBkvzfAliWesDnKVtO0J9BQbvh7Y=; Received: (qmail 17156 invoked by alias); 26 Jan 2012 17:34:05 -0000 Received: (qmail 16671 invoked by uid 22791); 26 Jan 2012 17:34:02 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga03.intel.com (HELO mga03.intel.com) (143.182.124.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Jan 2012 17:33:49 +0000 Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga101.ch.intel.com with ESMTP; 26 Jan 2012 09:27:34 -0800 X-ExtLoop1: 1 Received: from azsmsx603.amr.corp.intel.com ([10.2.161.23]) by AZSMGA002.ch.intel.com with ESMTP; 26 Jan 2012 09:27:34 -0800 Received: from fmsmsx105.amr.corp.intel.com (10.19.9.36) by azsmsx603.amr.corp.intel.com (10.2.161.23) with Microsoft SMTP Server (TLS) id 8.2.255.0; Thu, 26 Jan 2012 10:27:34 -0700 Received: from fmsmsx101.amr.corp.intel.com ([169.254.1.197]) by FMSMSX105.amr.corp.intel.com ([169.254.5.58]) with mapi id 14.01.0355.002; Thu, 26 Jan 2012 09:27:34 -0800 From: "Iyer, Balaji V" To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][Cilkplus] Sec Implicit Index Builtin function Implementation Date: Thu, 26 Jan 2012 17:27:33 +0000 Message-ID: References: In-Reply-To: MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 + + * 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 * 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 + + * 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 * 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 + * 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 + * gcc.dg/cilk-plus/array_notation_tests/builtin_func_double.c: New. 2012-01-21 Balaji V. Iyer 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 +using namespace std; +#endif +#include +/* 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 +#endif +#include + +/* 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; +}