From patchwork Thu Jul 27 12:41:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 794372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-459159-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fIt835Nb"; dkim-atps=neutral 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 3xJBS72qTwz9s5L for ; Thu, 27 Jul 2017 22:41:43 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=EudUK6U+SoY3DjP1B n0xUZ6UWlOD8BTcNqvzkI7gcSXQQ0GwdJx6534T0g8Ed2xhulDDQm/KrFryxOwW/ UCWEdj+AiaV6rplbxMzgoycLIdGYb8tOZLnrhJ/oyXS0kKOkPVfsERc88bFdtEDZ xFc3Emmaxqw0LzNTsq4NXMausU= 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 :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=flE/UcNhw34jEV0OdnDbaqA 7F0g=; b=fIt835Nbonmi3ExbbkEI2DwmBjrRTJIQgDh/Vz7fHYLT6F6dRtxQky0 ifPHLKoghDoJXmS1ole27ZA7sNkM/DMiV2iWqccP6FpIpg5k0R7jGa8x7gqzIUI4 HzaqwRlgIW4+4TyCmLMVB/5eB7pHxKVed7ef6ndP5PDKEPsrYP8I= Received: (qmail 112262 invoked by alias); 27 Jul 2017 12:41:35 -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 111922 invoked by uid 89); 27 Jul 2017 12:41:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=co X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.163) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 12:41:31 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwTPLBCxG2NAI0FdGO X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (ip5f585828.dynamic.kabel-deutschland.de [95.88.88.40]) by smtp.strato.de (RZmta 41.1 DYNA|AUTH) with ESMTPSA id 40624ft6RCfRKtE (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 27 Jul 2017 14:41:27 +0200 (CEST) Subject: Re: [patch 1/2] PR49847: Add hook to place read-only lookup-tables in named address-space From: Georg-Johann Lay To: gcc-patches Cc: Denis Chertykov References: <0c3f3987-38d4-6723-4c54-d183d2e65106@gjlay.de> Message-ID: <9706f7c7-c427-4e64-af62-4cecf52cbe02@gjlay.de> Date: Thu, 27 Jul 2017 14:41:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <0c3f3987-38d4-6723-4c54-d183d2e65106@gjlay.de> X-IsSubscribed: yes On 27.07.2017 14:29, Georg-Johann Lay wrote: > For some targets, the best place to put read-only lookup tables as > generated by -ftree-switch-conversion is not the generic address space > but some target specific address space. > > This is the case for AVR, where for most devices .rodata must be > located in RAM. > > Part #1 adds a new, optional target hook that queries the back-end > about the desired address space. There is currently only one user: > tree-switch-conversion.c::build_one_array() which re-builds value_type > and array_type if the address space returned by the backend is not > the generic one. > > Part #2 is the AVR part that implements the new hook and adds some > sugar around it. This is the gcc part which adds the new hook TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA resp. targetm.addr_space.for_artificial_rodata(). The default implementation returns ADDR_SPACE_GENERIC which represents a no-op. Only if !ADDR_SPACE_GENERIC_P, the array and value type are re-built. The accesses must be in such a way that any access to the newly created array matches the address space. This is the reason for why the back-end cannot do it on its own: Just putting the stuff in a specific section does *not* do the trick. Bootstrapped ok on x86_64. Johann PR 49857 * doc/tm.texi.in (Named Address Spaces) [TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA]: Add hook anchor. * doc/tm.texi: Regenerate. * target.def (addr_space) [for_artificial_rodata]: New optional hook. * targhooks.c (default_addr_space_for_artificial_rodata): New function. * targhooks.h (default_addr_space_for_artificial_rodata): New proto. * tree-switch-conversion.c (target.h): Include it. (build_one_array): Set address space of value_type according to targetm.addr_space.for_artificial_rodata() and rebuild array_type if needed. Index: target.def =================================================================== --- target.def (revision 250302) +++ target.def (working copy) @@ -3285,6 +3285,25 @@ The default implementation does nothing. void, (addr_space_t as, location_t loc), default_addr_space_diagnose_usage) +/* Function to get the address space of some compiler-generated + read-only data. Used for optimization purposes only. */ +DEFHOOK +(for_artificial_rodata, + "Define this hook to return an address space to be used for @var{type},\n\ +usually an artificial lookup-table that would reside in @code{.rodata}.\n\ +It is always safe not to implement this hook or to return\n\ +@code{ADDR_SPACE_GENERIC}.\n\ +\n\ +The hook can be used to put compiler-generated, artificial data in\n\ +static stzorage into a specific address space when this is better suited\n\ +than the generic address space.\n\ +The compiler will also generate all accesses to the respective data\n\ +so that all associated accesses will also use the desired address space.\n\ +An example for such data are the @code{CSWTCH} lookup tables as generated\n\ +by @option{-ftree-switch-conversion}.", + addr_space_t, (tree type), + default_addr_space_for_artificial_rodata) + HOOK_VECTOR_END (addr_space) #undef HOOK_PREFIX Index: targhooks.c =================================================================== --- targhooks.c (revision 250302) +++ targhooks.c (working copy) @@ -1397,6 +1397,14 @@ default_addr_space_convert (rtx op ATTRI gcc_unreachable (); } +/* The default hook for TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA. */ + +addr_space_t +default_addr_space_for_artificial_rodata (tree) +{ + return ADDR_SPACE_GENERIC; +} + bool default_hard_regno_scratch_ok (unsigned int regno ATTRIBUTE_UNUSED) { Index: targhooks.h =================================================================== --- targhooks.h (revision 250302) +++ targhooks.h (working copy) @@ -184,6 +184,7 @@ extern bool default_addr_space_zero_addr extern int default_addr_space_debug (addr_space_t); extern void default_addr_space_diagnose_usage (addr_space_t, location_t); extern rtx default_addr_space_convert (rtx, tree, tree); +extern addr_space_t default_addr_space_for_artificial_rodata (tree); extern unsigned int default_case_values_threshold (void); extern bool default_have_conditional_execution (void); Index: tree-switch-conversion.c =================================================================== --- tree-switch-conversion.c (revision 250302) +++ tree-switch-conversion.c (working copy) @@ -46,6 +46,7 @@ Software Foundation, 51 Franklin Street, #include "gimplify-me.h" #include "tree-cfg.h" #include "cfgloop.h" +#include "target.h" /* ??? For lang_hooks.types.type_for_mode, but is there a word_mode type in the GIMPLE type system that is language-independent? */ @@ -1136,6 +1137,16 @@ build_one_array (gswitch *swtch, int num default_type = TREE_TYPE (info->default_values[num]); value_type = array_value_type (swtch, default_type, num, info); array_type = build_array_type (value_type, arr_index_type); + // Run the following hook on the complete array so the back-end + // can inspect details of it. + addr_space_t as = targetm.addr_space.for_artificial_rodata (array_type); + if (!ADDR_SPACE_GENERIC_P (as)) + { + int quals = (TYPE_QUALS_NO_ADDR_SPACE (value_type) + | ENCODE_QUAL_ADDR_SPACE (as)); + value_type = build_qualified_type (value_type, quals); + array_type = build_array_type (value_type, arr_index_type); + } if (default_type != value_type) { unsigned int i; Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 250302) +++ doc/tm.texi (working copy) @@ -10595,6 +10595,21 @@ the address space as registered with @co The default implementation does nothing. @end deftypefn +@deftypefn {Target Hook} addr_space_t TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA (tree @var{type}) +Define this hook to return an address space to be used for @var{type}, +usually an artificial lookup-table that would reside in @code{.rodata}. +It is always safe not to implement this hook or to return +@code{ADDR_SPACE_GENERIC}. + +The hook can be used to put compiler-generated, artificial data in +static stzorage into a specific address space when this is better suited +than the generic address space. +The compiler will also generate all accesses to the respective data +so that all associated accesses will also use the desired address space. +An example for such data are the @code{CSWTCH} lookup tables as generated +by @option{-ftree-switch-conversion}. +@end deftypefn + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous Index: doc/tm.texi.in =================================================================== --- doc/tm.texi.in (revision 250302) +++ doc/tm.texi.in (working copy) @@ -7529,6 +7529,8 @@ c_register_addr_space ("__ea", ADDR_SPAC @hook TARGET_ADDR_SPACE_DIAGNOSE_USAGE +@hook TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA + @node Misc @section Miscellaneous Parameters @cindex parameters, miscellaneous