From patchwork Mon Jul 28 14:14:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Gribov X-Patchwork-Id: 374206 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1E74E140077 for ; Tue, 29 Jul 2014 00:14:25 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=ugeBDJK6ne4SJcK88 yGEUWA0BNo8VQU+jeepqIX5NDjymZ14oPubtYy1gXuCts1Ej0kxR+khL8WPtttJN /tQnsPdMwodByZWQdDzBVFNt0CF5NsGdO1nT41+8TrYCpdtPa7OBWDDCP1Eu39ev 4ZKZESMGpZigRiCcz0cw2TYqqE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=EKecCKDDcbQcr5x0sP9jVvz jZBA=; b=ZJDaUswG7eS5KK17CZ9PwTap1RQD2kBh9b+eSmwPtt15Jw/zUcB3mra 7/S7oxF0s4KH2jm74mhe4ggV8y67NWC5p0Mchgs1PFZnFyyzXN8kaPjUDBkzNoPP PvRpTLV9ZkadD260sqPnMmZr/Q8iqpabi8fvATX5skVdpnagNQew= Received: (qmail 470 invoked by alias); 28 Jul 2014 14:14:17 -0000 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 Received: (qmail 452 invoked by uid 89); 28 Jul 2014 14:14:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mailout4.w1.samsung.com Received: from mailout4.w1.samsung.com (HELO mailout4.w1.samsung.com) (210.118.77.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (DES-CBC3-SHA encrypted) ESMTPS; Mon, 28 Jul 2014 14:14:13 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9F00M8VE7BD5A0@mailout4.w1.samsung.com>; Mon, 28 Jul 2014 15:13:59 +0100 (BST) Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 99.98.15956.0BA56D35; Mon, 28 Jul 2014 15:14:08 +0100 (BST) Received: from [106.109.9.145] by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9F00MX1E7JRX60@eusync1.samsung.com>; Mon, 28 Jul 2014 15:14:08 +0100 (BST) Message-id: <53D65AB0.4090807@samsung.com> Date: Mon, 28 Jul 2014 18:14:08 +0400 From: Yury Gribov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-version: 1.0 To: Jakub Jelinek Cc: Richard Biener , GCC Patches , Konstantin Serebryany , Dmitry Vyukov , Viacheslav Garbuzov , Marek Polacek Subject: Re: [PATCH] Move Asan instrumentation to sanopt pass References: <53C922DE.6020000@samsung.com> <53CE720A.4030002@samsung.com> <20140723200935.GB2397@laptop.redhat.com> <53D0A5DA.4020301@samsung.com> <20140724074851.GD2397@laptop.redhat.com> In-reply-to: <20140724074851.GD2397@laptop.redhat.com> Content-type: multipart/mixed; boundary=------------020009030707080609060504 X-IsSubscribed: yes On 07/24/2014 11:48 AM, Jakub Jelinek wrote: > So, either support for just EAF*, or perhaps support for DECL_ATTRIBUTES > for internal-fns, say by having some tree array where you'd store what you > stick into DECL_ATTRIBUTES normally. I'd prefer to avoid attributes. Would something like this be enough? (not yet fully tested, just ran asan.exp tests). -Y diff --git a/gcc/gimple.c b/gcc/gimple.c index 4a9d379..aa0caab 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1348,6 +1348,9 @@ gimple_call_fnspec (const_gimple stmt) int gimple_call_arg_flags (const_gimple stmt, unsigned arg) { + if (gimple_call_internal_p (stmt)) + return internal_fn_arg_flags (gimple_call_internal_fn (stmt), arg); + tree attr = gimple_call_fnspec (stmt); if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr)) diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 7fb54ea..3f9b448 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see /* The names of each internal function, indexed by function number. */ const char *const internal_fn_name_array[] = { -#define DEF_INTERNAL_FN(CODE, FLAGS) #CODE, +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) #CODE, #include "internal-fn.def" #undef DEF_INTERNAL_FN "" @@ -48,12 +48,63 @@ const char *const internal_fn_name_array[] = { /* The ECF_* flags of each internal function, indexed by function number. */ const int internal_fn_flags_array[] = { -#define DEF_INTERNAL_FN(CODE, FLAGS) FLAGS, +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) FLAGS, #include "internal-fn.def" #undef DEF_INTERNAL_FN 0 }; +/* The EAF_* flags for arguments of internal functions, + indexed indirectly via INTERNAL_FN_ARG_FLAGS_ARRAY. */ +static GTY(()) int *internal_fn_arg_flags_array; + +/* Maps internal function to offset in internal_fn_arg_flags_array. */ +static size_t internal_fn_arg_flags_offsets[IFN_LAST]; +static size_t max_arg_offset; + +void +init_internal_fns () +{ + max_arg_offset = 0; +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) max_arg_offset += NARGS; +#include "internal-fn.def" +#undef DEF_INTERNAL_FN + internal_fn_arg_flags_array + = (int *) xmalloc (max_arg_offset * sizeof (internal_fn_arg_flags_array[0])); + + size_t offset = 0; +#define APPEND_ARG_FLAGS0() ; +#define APPEND_ARG_FLAGS1(F1) \ + internal_fn_arg_flags_array[offset++] = F1; +#define APPEND_ARG_FLAGS2(F1, F2) \ + internal_fn_arg_flags_array[offset++] = F1; \ + internal_fn_arg_flags_array[offset++] = F2; +#define APPEND_ARG_FLAGS3(F1, F2, F3) \ + internal_fn_arg_flags_array[offset++] = F1; \ + internal_fn_arg_flags_array[offset++] = F2; \ + internal_fn_arg_flags_array[offset++] = F3; +#define APPEND_ARG_FLAGS4(F1, F2, F3, F4) \ + internal_fn_arg_flags_array[offset++] = F1; \ + internal_fn_arg_flags_array[offset++] = F2; \ + internal_fn_arg_flags_array[offset++] = F3; \ + internal_fn_arg_flags_array[offset++] = F4; +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) \ + internal_fn_arg_flags_offsets[(int) IFN_##CODE] = offset; \ + APPEND_ARG_FLAGS##NARGS ARG_FLAGS +#include "internal-fn.def" +#undef DEF_INTERNAL_FN +} + +/* Return the EAF_* flags for N-th argument of function FN. */ + +int +internal_fn_arg_flags (enum internal_fn fn, int arg) +{ + size_t offset = internal_fn_arg_flags_offsets[(int) fn] + arg; + gcc_assert (offset < max_arg_offset); + return internal_fn_arg_flags_array[offset]; +} + /* ARRAY_TYPE is an array of vector modes. Return the associated insn for load-lanes-style optab OPTAB. The insn must exist. */ @@ -905,7 +956,7 @@ expand_BUILTIN_EXPECT (gimple stmt) where STMT is the statement that performs the call. */ static void (*const internal_fn_expanders[]) (gimple) = { -#define DEF_INTERNAL_FN(CODE, FLAGS) expand_##CODE, +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) expand_##CODE, #include "internal-fn.def" #undef DEF_INTERNAL_FN 0 diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index f0aa1b4..a2861a6 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -28,30 +28,34 @@ along with GCC; see the file COPYING3. If not see Each entry in this file has the form: - DEF_INTERNAL_FN (NAME, FLAGS) + DEF_INTERNAL_FN (NAME, FLAGS, NARGS, ARG_FLAGS) - where NAME is the name of the function and FLAGS is a set of - ECF_* flags. Each entry must have a corresponding expander - of the form: + where NAME is the name of the function, FLAGS is a set of + ECF_* flags and ARG_FLAGS holds comma-separated list of sets + of EAF_* flags. + + Each entry must have a corresponding expander of the form: void expand_NAME (gimple stmt) where STMT is the statement that performs the call. */ -DEF_INTERNAL_FN (LOAD_LANES, ECF_CONST | ECF_LEAF) -DEF_INTERNAL_FN (STORE_LANES, ECF_CONST | ECF_LEAF) -DEF_INTERNAL_FN (GOMP_SIMD_LANE, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (GOMP_SIMD_VF, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (GOMP_SIMD_LAST_LANE, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (LOOP_VECTORIZED, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (MASK_LOAD, ECF_PURE | ECF_LEAF) -DEF_INTERNAL_FN (MASK_STORE, ECF_LEAF) -DEF_INTERNAL_FN (ANNOTATE, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (UBSAN_NULL, ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (UBSAN_BOUNDS, ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (UBSAN_CHECK_ADD, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (UBSAN_CHECK_SUB, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (UBSAN_CHECK_MUL, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (ABNORMAL_DISPATCHER, ECF_NORETURN) -DEF_INTERNAL_FN (BUILTIN_EXPECT, ECF_CONST | ECF_LEAF | ECF_NOTHROW) -DEF_INTERNAL_FN (ASAN_CHECK, ECF_TM_PURE | ECF_LEAF | ECF_NOTHROW) +DEF_INTERNAL_FN (LOAD_LANES, ECF_CONST | ECF_LEAF, 1, (0)) +DEF_INTERNAL_FN (STORE_LANES, ECF_CONST | ECF_LEAF, 1, (0)) +DEF_INTERNAL_FN (GOMP_SIMD_LANE, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, 1, (0)) +DEF_INTERNAL_FN (GOMP_SIMD_VF, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 1, (0)) +DEF_INTERNAL_FN (GOMP_SIMD_LAST_LANE, ECF_CONST | ECF_LEAF | ECF_NOTHROW, \ + 2, (0, 0)) +DEF_INTERNAL_FN (LOOP_VECTORIZED, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (MASK_LOAD, ECF_PURE | ECF_LEAF, 3, (0, 0, 0)) +DEF_INTERNAL_FN (MASK_STORE, ECF_LEAF, 4, (0, 0, 0, 0)) +DEF_INTERNAL_FN (ANNOTATE, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (UBSAN_NULL, ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (UBSAN_BOUNDS, ECF_LEAF | ECF_NOTHROW, 3, (0, 0, 0)) +DEF_INTERNAL_FN (UBSAN_CHECK_ADD, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (UBSAN_CHECK_SUB, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (UBSAN_CHECK_MUL, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 2, (0, 0)) +DEF_INTERNAL_FN (ABNORMAL_DISPATCHER, ECF_NORETURN, 1, (0)) +DEF_INTERNAL_FN (BUILTIN_EXPECT, ECF_CONST | ECF_LEAF | ECF_NOTHROW, 1, (0)) +DEF_INTERNAL_FN (ASAN_CHECK, ECF_TM_PURE | ECF_LEAF | ECF_NOTHROW, \ + 3, (EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE, 0, 0)) diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h index 2dcf44e..e476aac 100644 --- a/gcc/internal-fn.h +++ b/gcc/internal-fn.h @@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_INTERNAL_FN_H #define GCC_INTERNAL_FN_H +extern void init_internal_fns (); + /* Return the name of internal function FN. The name is only meaningful for dumps; it has no linkage. */ @@ -41,6 +43,8 @@ internal_fn_flags (enum internal_fn fn) return internal_fn_flags_array[(int) fn]; } +int internal_fn_arg_flags (enum internal_fn, int); + extern void expand_internal_call (gimple); #endif diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 34c48fa..cc46b81 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -667,7 +667,7 @@ enum annot_expr_kind { /* Internal functions. */ enum internal_fn { -#define DEF_INTERNAL_FN(CODE, FLAGS) IFN_##CODE, +#define DEF_INTERNAL_FN(CODE, FLAGS, NARGS, ARG_FLAGS) IFN_##CODE, #include "internal-fn.def" #undef DEF_INTERNAL_FN IFN_LAST diff --git a/gcc/tree.c b/gcc/tree.c index 10063a4..5520b8b 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -9920,8 +9920,9 @@ local_define_builtin (const char *name, tree type, enum built_in_function code, } /* Call this function after instantiating all builtins that the language - front end cares about. This will build the rest of the builtins that - are relied upon by the tree optimizers and the middle-end. */ + front end cares about. This will build the rest of the builtins + and internal function that are relied upon by the tree optimizers and + the middle-end. */ void build_common_builtin_nodes (void) @@ -10154,6 +10155,8 @@ build_common_builtin_nodes (void) ECF_CONST | ECF_NOTHROW | ECF_LEAF); } } + + init_internal_fns (); } /* HACK. GROSS. This is absolutely disgusting. I wish there was a