From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86076 invoked by alias); 19 Dec 2019 16:59:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 86068 invoked by uid 89); 19 Dec 2019 16:59:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=start-up, decoration, reusable, Declare X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Dec 2019 16:59:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6A0461FB for ; Thu, 19 Dec 2019 08:59:19 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 123603F718 for ; Thu, 19 Dec 2019 08:59:18 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Add a generic lhd_simulate_enum_decl Date: Thu, 19 Dec 2019 17:01:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-12/txt/msg01394.txt.bz2 Normally we only create SVE ACLE functions when arm_sve.h is included. But for LTO we need to do it at start-up, so that the functions are already defined when streaming in the LTO objects. One hitch with doing that is that LTO doesn't yet implement the simulate_enum_decl langhook. This patch adds a simple default implementation that it can use. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK for the generic bits? Richard 2019-12-19 Richard Sandiford gcc/ * langhooks-def.h (lhd_simulate_enum_decl): Declare. (LANG_HOOKS_SIMULATE_ENUM_DECL): Use it. * langhooks.c: Include stor-layout.h. (lhd_simulate_enum_decl): New function. * config/aarch64/aarch64-sve-builtins.cc (init_builtins): Call handle_arm_sve_h for the LTO frontend. (register_vector_type): Cope with null returns from pushdecl. gcc/testsuite/ * gcc.target/aarch64/sve/pcs/asm_4.c: New test. Index: gcc/langhooks-def.h =================================================================== --- gcc/langhooks-def.h 2019-11-11 19:43:29.268784653 +0000 +++ gcc/langhooks-def.h 2019-12-19 16:58:12.856690090 +0000 @@ -54,6 +54,8 @@ extern void lhd_print_error_function (di extern void lhd_set_decl_assembler_name (tree decl); extern void lhd_overwrite_decl_assembler_name (tree decl, tree name); extern bool lhd_warn_unused_global_decl (const_tree); +extern tree lhd_simulate_enum_decl (location_t, const char *, + vec); extern tree lhd_type_for_size (unsigned precision, int unsignedp); extern void lhd_incomplete_type_error (location_t, const_tree, const_tree); extern tree lhd_type_promotes_to (tree); @@ -171,7 +173,7 @@ #define LANG_HOOKS_TREE_DUMP_INITIALIZER extern tree lhd_unit_size_without_reusable_padding (tree); #define LANG_HOOKS_MAKE_TYPE lhd_make_node -#define LANG_HOOKS_SIMULATE_ENUM_DECL NULL +#define LANG_HOOKS_SIMULATE_ENUM_DECL lhd_simulate_enum_decl #define LANG_HOOKS_CLASSIFY_RECORD NULL #define LANG_HOOKS_TYPE_FOR_SIZE lhd_type_for_size #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error Index: gcc/langhooks.c =================================================================== --- gcc/langhooks.c 2019-10-29 08:39:22.576014071 +0000 +++ gcc/langhooks.c 2019-12-19 16:58:12.856690090 +0000 @@ -35,6 +35,7 @@ the Free Software Foundation; either ver #include "tree-diagnostic.h" #include "output.h" #include "timevar.h" +#include "stor-layout.h" /* Do nothing; in many cases the default hook. */ @@ -473,6 +474,44 @@ lhd_make_node (enum tree_code code) return make_node (code); } +/* Default implementation of LANG_HOOKS_SIMULATE_ENUM_DECL. Assume a + simple int-based enumerator (which is all the hook can be used for + at present) and push each decl individually without any decoration. + + This definition is suitable for LTO and is generic enough that it + might be reusable elsewhere. */ +tree +lhd_simulate_enum_decl (location_t loc, const char *name, + vec values) +{ + tree enumtype = lang_hooks.types.make_type (ENUMERAL_TYPE); + tree enumdecl = build_decl (loc, TYPE_DECL, get_identifier (name), enumtype); + TYPE_STUB_DECL (enumtype) = enumdecl; + + tree value_chain = NULL_TREE; + string_int_pair *value; + unsigned int i; + FOR_EACH_VEC_ELT (values, i, value) + { + tree value_decl = build_decl (loc, CONST_DECL, + get_identifier (value->first), enumtype); + DECL_INITIAL (value_decl) = build_int_cst (integer_type_node, + value->second); + lang_hooks.decls.pushdecl (value_decl); + value_chain = tree_cons (value_decl, DECL_INITIAL (value_decl), + value_chain); + } + + TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (integer_type_node); + TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (integer_type_node); + SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (integer_type_node)); + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + layout_type (enumtype); + lang_hooks.decls.pushdecl (enumdecl); + + return enumtype; +} + /* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE. Return an integer type with PRECISION bits of precision, that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */ Index: gcc/config/aarch64/aarch64-sve-builtins.cc =================================================================== --- gcc/config/aarch64/aarch64-sve-builtins.cc 2019-12-13 10:21:19.000000000 +0000 +++ gcc/config/aarch64/aarch64-sve-builtins.cc 2019-12-19 16:58:12.856690090 +0000 @@ -3025,6 +3025,8 @@ init_builtins () { sve_switcher sve; register_builtin_types (); + if (in_lto_p) + handle_arm_sve_h (); } /* Register vector type TYPE under its arm_sve.h name. */ @@ -3041,7 +3043,8 @@ register_vector_type (vector_type_index right form, even if it doesn't have the right name. This should give better error recovery behavior than installing error_mark_node or installing an incorrect type. */ - if (TREE_CODE (decl) == TYPE_DECL + if (decl + && TREE_CODE (decl) == TYPE_DECL && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == vectype) vectype = TREE_TYPE (decl); acle_vector_types[0][type] = vectype; Index: gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c =================================================================== --- /dev/null 2019-09-17 11:41:18.176664108 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/pcs/asm_4.c 2019-12-19 16:58:12.856690090 +0000 @@ -0,0 +1,4 @@ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-O2 -flto -ffixed-z0 -ffixed-p0" } */ + +#include "asm_3.c"