From patchwork Thu Nov 10 10:20:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 18046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp60157wru; Thu, 10 Nov 2022 02:22:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+9ydfNKo/YA0/eMN+rbioreQujEVYHTvoBrs6F3TU+97tlaGqCcfB/u6bevFU9BdlBpMT X-Received: by 2002:a05:6402:530d:b0:463:b0cb:50e5 with SMTP id eo13-20020a056402530d00b00463b0cb50e5mr10023788edb.45.1668075728009; Thu, 10 Nov 2022 02:22:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668075728; cv=none; d=google.com; s=arc-20160816; b=tMFZGXuQtrVz0MFQsuIPhkMnEFUtD+4+s1dBQydcBCWbOPIQE1qsjpUewBRlc6kcyK /ix0teh1IlF3PzxuW+41Ou8LNL7tgWR8JiiBkw/Dx6+uu7x1kvYDjdasQ5Cg75jyXz5a U6WdgZf16JGUVyAawQZQWg3UiGPAAHQhJddi80rHhZtIVQEkv+CfMCzNydxxnGD3uXLs i2RAPd0J5LxK9apfgRhhl4huxwDI9IamYP95MkeTJuUcJPgjb3hyIyWWhR7bI9xZ2Cwd 0b6Z4t7FOmrmoygraHWpPfs+xHuaeBSWP8gj2ZJ80Sg9nxWh9G+ME63FPcDa29JiTuq9 AggA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5i5BTzKeyOa3UuSSj/kcRyLd2TCw5a9A24XYNdmxbZY=; b=Sw5/L2MkHKfj/A3vbLEeCTTzPyh7RuInHy3eNykoQOGKzpYO3zllVLuGoKCH0P8XAr mlccmPkMTV3gCvTkGcPWmh3/OdB0D8j+dhrzOjFQBg0yRj56wg1ZDj8S1q7mGfWE4VOr oD/Id091MoAr6jW4KcudZObadj2ALc42DWqfAZ/5vzj5S5OdtiTZoEYXh2WwhmeAyq+M mz1PJUIbUM9s72bSTf8s6bK0/4rjZuew7oQLz544QPISmVAQZpI5ENMTzLjf1AwjeuAS 8rMcdTXtWSfPQI/Ftnv1xfwSWbPmdOZRs6O8gkqg+etjFTOv9BXxDzhzPUzkxDaL978J I2rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=swopYILF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gt16-20020a1709072d9000b0078e1d1d6005si19482068ejc.23.2022.11.10.02.22.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 02:22:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=swopYILF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54C413889E18 for ; Thu, 10 Nov 2022 10:21:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54C413889E18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668075690; bh=5i5BTzKeyOa3UuSSj/kcRyLd2TCw5a9A24XYNdmxbZY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=swopYILFljps+3Y+zrM4DDVFx05SkOT5oHj3ehTodiL+npxlviP+8eJNi97/nVaNU 9hNreY8LcmWS8P4o/eDKaYhcs2gM35Z1acpVOsZSLfyWIlYIgziesXMxejWGiFxwYt OVB5emOy1/6/BOpq1hncZa7nr0gT3W88U3tFuktA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id B9B853858C5E; Thu, 10 Nov 2022 10:20:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9B853858C5E Received: by mail-ej1-x633.google.com with SMTP id ft34so3671626ejc.12; Thu, 10 Nov 2022 02:20:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5i5BTzKeyOa3UuSSj/kcRyLd2TCw5a9A24XYNdmxbZY=; b=hnV1TA6Efr1DVm5DAQ6HEcdudi9I9u7Cm1vBP37eKHE3p8b3EeHKOSNhYo+xP0gWgM IaADOii2jHId13qLwaG4a2Sud2rh9nXS8/m0tAOgVbcCmYW7aLP4n2FSmOmUGpzE4e4w FxQdaNHn/J0wAtBJ1iDXqFKDBckcLISpfCgmUnPmzIjHuTlAWZe5StUyXfm9MasmbrL0 hFsQnVC95BzWFdQomZK06J99DXIQwRldaxlKiAN6jgNhW/s1MuhHI4ljsnQ9zzwbxBqe /27f1APt4R7X0nqpWxjMf4NhO6sgxouszxRFPbILMp0PpEoj+6dg8CzLzJn9RL6uPBov 7D4Q== X-Gm-Message-State: ACrzQf1pFL5Lb0jlJJj08aWpk+RoHGfH+pVNrhodUADhMk6Vk9RjJ6Tl yZs/JUtYYlezGAHC5yDcyDA= X-Received: by 2002:a17:906:2681:b0:783:6a92:4c38 with SMTP id t1-20020a170906268100b007836a924c38mr58872969ejc.75.1668075633896; Thu, 10 Nov 2022 02:20:33 -0800 (PST) Received: from nbbrfq (80-110-214-113.static.upcbusiness.at. [80.110.214.113]) by smtp.gmail.com with ESMTPSA id 18-20020a170906211200b00781ea761407sm6990895ejt.161.2022.11.10.02.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 02:20:33 -0800 (PST) X-Google-Original-From: Bernhard Reutner-Fischer Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1ot4fg-005jMr-2J; Thu, 10 Nov 2022 11:20:32 +0100 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer , gfortran ML Subject: [PATCH 1/2] Fortran: Cleanup struct ext_attr_t Date: Thu, 10 Nov 2022 11:20:30 +0100 Message-Id: <20221110102031.1366016-2-aldot@gcc.gnu.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110102031.1366016-1-aldot@gcc.gnu.org> References: <20221110102031.1366016-1-aldot@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749104174602046358?= X-GMAIL-MSGID: =?utf-8?q?1749104174602046358?= Tiny cleanup opportunity since we now have ext_attr_args in struct symbol_attribute. Bootstrapped and regtested on x86_64-unknown-linux with no new regressions. Ok for trunk if the prerequisite was approved ([PATCH 2/2] Fortran: add attribute target_clones) ? gcc/fortran/ChangeLog: * gfortran.h (struct ext_attr_t): Remove middle_end_name. * trans-decl.cc (add_attributes_to_decl): Move building tree_list to ... * decl.cc (gfc_match_gcc_attributes): ... here. Add the attribute to the tree_list for the middle end. Cc: gfortran ML --- gcc/fortran/decl.cc | 35 +++++++++++++++++++++++------------ gcc/fortran/gfortran.h | 1 - gcc/fortran/trans-decl.cc | 13 +------------ 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 3a619dbdd34..d312d4812b6 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -11802,15 +11802,15 @@ gfc_match_gcc_attribute_args (bool require_string, bool allow_multiple) } const ext_attr_t ext_attr_list[] = { - { "dllimport", EXT_ATTR_DLLIMPORT, "dllimport" }, - { "dllexport", EXT_ATTR_DLLEXPORT, "dllexport" }, - { "cdecl", EXT_ATTR_CDECL, "cdecl" }, - { "stdcall", EXT_ATTR_STDCALL, "stdcall" }, - { "fastcall", EXT_ATTR_FASTCALL, "fastcall" }, - { "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL }, - { "deprecated", EXT_ATTR_DEPRECATED, NULL }, - { "target_clones",EXT_ATTR_TARGET_CLONES,NULL }, - { NULL, EXT_ATTR_LAST, NULL } + { "dllimport", EXT_ATTR_DLLIMPORT }, + { "dllexport", EXT_ATTR_DLLEXPORT }, + { "cdecl", EXT_ATTR_CDECL }, + { "stdcall", EXT_ATTR_STDCALL }, + { "fastcall", EXT_ATTR_FASTCALL, }, + { "no_arg_check", EXT_ATTR_NO_ARG_CHECK }, + { "deprecated", EXT_ATTR_DEPRECATED }, + { "target_clones",EXT_ATTR_TARGET_CLONES }, + { NULL, EXT_ATTR_LAST } }; /* Match a !GCC$ ATTRIBUTES statement of the form: @@ -11854,6 +11854,20 @@ gfc_match_gcc_attributes (void) gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C"); return MATCH_ERROR; } + + /* Check for errors. + If everything is fine, add attributes the middle-end has to know about. + */ + if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus)) + return MATCH_ERROR; + else if (id == EXT_ATTR_DLLIMPORT + || id == EXT_ATTR_DLLEXPORT + || id == EXT_ATTR_CDECL + || id == EXT_ATTR_STDCALL + || id == EXT_ATTR_FASTCALL) + attr.ext_attr_args + = chainon (attr.ext_attr_args, + build_tree_list (get_identifier (name), NULL_TREE)); else if (id == EXT_ATTR_TARGET_CLONES) { attr_args @@ -11864,9 +11878,6 @@ gfc_match_gcc_attributes (void) build_tree_list (get_identifier (name), attr_args)); } - if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus)) - return MATCH_ERROR; - gfc_gobble_whitespace (); ch = gfc_next_ascii_char (); if (ch == ':') diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index ce0cb61e647..c4deec0d5b8 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -847,7 +847,6 @@ typedef struct { const char *name; unsigned id; - const char *middle_end_name; } ext_attr_t; diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index 24cbd4cda28..7d5d2bdbb37 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -1436,18 +1436,7 @@ gfc_add_assign_aux_vars (gfc_symbol * sym) static tree add_attributes_to_decl (symbol_attribute sym_attr, tree list) { - unsigned id; - tree attr; - - for (id = 0; id < EXT_ATTR_NUM; id++) - if (sym_attr.ext_attr & (1 << id) && ext_attr_list[id].middle_end_name) - { - attr = build_tree_list ( - get_identifier (ext_attr_list[id].middle_end_name), - NULL_TREE); - list = chainon (list, attr); - } - /* Add attribute args. */ + /* Add attributes and their arguments. */ if (sym_attr.ext_attr_args != NULL_TREE) list = chainon (list, sym_attr.ext_attr_args); From patchwork Thu Nov 10 10:20:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 18047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp60305wru; Thu, 10 Nov 2022 02:22:28 -0800 (PST) X-Google-Smtp-Source: AMsMyM7cSBdT/x4HXxnQIiyKzqhr5NZCcRWMhDLEYlbiGgWPa6zcCkf4FMaVOjbdBomoSKubSKvh X-Received: by 2002:a17:906:c0c:b0:78d:4b9f:c32 with SMTP id s12-20020a1709060c0c00b0078d4b9f0c32mr2412623ejf.499.1668075748703; Thu, 10 Nov 2022 02:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668075748; cv=none; d=google.com; s=arc-20160816; b=jooU0jM3UGTbLvFVHRvWZDgzg1jSDv+zca5SaoWz7K6RksqRP5tZOJMWGGgPjkU1Ud oxZQeV+bNWuTXodm3IE/W3oZcMMWYHPVPkZZJMSGZ1X18aJzkMii76nU8ek5HcUaGPBh q8f5XL4JCzDHkwIHU23c8LOzW/iapW4KZp12TIrcWHCUozDbHr/gEZ+fWydtdrk3I3Xn 4blix+9eekMqE6XVJOJlSmoyjzmuSO/++sx/A6RBoEtKgprp3GX8nfMUKSdqSN2AA4xF S4MSKYOLoUInaFPC8UxICgj15p8m5XseuUlxinZM7UdyWPV6RhxwmMMXKcma5t/qz7SD pGoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5mu9Uoiom0oNh4eH756LF74gTWUGFrSz2ltnFgIv70k=; b=uda5x54cqHuDsdtVb8htNdTcXKNrSgHdqkjsjyi7F+zYmYHCnG2Whn0GcbKjhmwz3i r80ng9VrGv8W4iGsn0S4FPxcSG4hgc4VKXZVqyI+QjuNQkJTbr+t8Wgi/rtlTL7l3yBc +P7bZLC1UYX+1lI4/ffir+sQ5Slh8pyadT2lfO3zyOHWTMRcWFamwgo/QNPe5lYpY+vx dSuauRt1MYqb29bci2o/CgnvUlXgxFsNE+qRHDSq0rKIdPLjD7miaFoFK2BexCvxH0N2 Ydaaw2GdJLAkdmqYgiNhXr+sjwQeD1YTJPNTWpNx7+WNRF2A6jnH2Hw9m0us8KWeGFoO WNtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l7WyIcvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lv24-20020a170906bc9800b0078e1cd71067si13796829ejb.205.2022.11.10.02.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 02:22:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l7WyIcvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3408A3887F77 for ; Thu, 10 Nov 2022 10:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3408A3887F77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668075704; bh=5mu9Uoiom0oNh4eH756LF74gTWUGFrSz2ltnFgIv70k=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=l7WyIcvSwnpiDhGY0NQgcoByekljcNfCeL5sXyJ1vKulb9u07W9KMdEl5zwbDzTE6 IjQikTXTkGogB6Ecsbjwt5B8X9m6R7AO/l5aTqu1bpucbP0mnER7tmsYIxTcssNBU7 T/qyr91PP6wTQo8zYrgNOb712qRLSspos02rCqLk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id E1E623858C62; Thu, 10 Nov 2022 10:20:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1E623858C62 Received: by mail-ej1-x62b.google.com with SMTP id k2so3817659ejr.2; Thu, 10 Nov 2022 02:20:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5mu9Uoiom0oNh4eH756LF74gTWUGFrSz2ltnFgIv70k=; b=l20UWZSA5j6Qy7tz1urksZln8kbJW7PFGl0/TI9MR1YN1TEjT07F0pEZY93OqfjZN5 dN0bQWRIZYQUNtK67nQMnTknknGTDuEtsGdRKnuIU7BYwK+kulG5zGfL1a+qxJYtMcNc AQJqCRpypE3hBHCZmkOQPpdwPFZCTvMvNzbjRajTSppXBH/Rfdb0f7gDXcPKFnMV1sa2 O7Uaqx+8bPLu+1ppKt+d7EFxLGBjiBeK2/NG2C4ZwS0cIjGduR7h/7KYnNxJdfRA9Duv l00uX0Z5ig/CkVm36bKRK+FWhiUFNz2Lv7xuG07BY/Buh4kJazzHb7GNdVzzFOXgBrq2 +2tg== X-Gm-Message-State: ANoB5pnStVy7CM6YBdagqCEH5VvbfwX+pkOpSbxof6uzLfw1+pDt2FSZ SxryDc1omwTc90CRqSMPIb05BdegIEU= X-Received: by 2002:a17:906:24d7:b0:7ae:4ed4:eede with SMTP id f23-20020a17090624d700b007ae4ed4eedemr2165624ejb.240.1668075634665; Thu, 10 Nov 2022 02:20:34 -0800 (PST) Received: from nbbrfq (80-110-214-113.static.upcbusiness.at. [80.110.214.113]) by smtp.gmail.com with ESMTPSA id q6-20020a1709064cc600b0078d793e7927sm6956624ejt.4.2022.11.10.02.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 02:20:33 -0800 (PST) X-Google-Original-From: Bernhard Reutner-Fischer Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1ot4fg-005jMu-2L; Thu, 10 Nov 2022 11:20:32 +0100 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer , gfortran ML Subject: [PATCH 2/2] Fortran: Add attribute flatten Date: Thu, 10 Nov 2022 11:20:31 +0100 Message-Id: <20221110102031.1366016-3-aldot@gcc.gnu.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110102031.1366016-1-aldot@gcc.gnu.org> References: <20221110102031.1366016-1-aldot@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749104167499971652?= X-GMAIL-MSGID: =?utf-8?q?1749104196058686539?= Bootstrapped and regtested cleanly on x86_unknown-linux. The document bits will be rewritten for rst. Ok for trunk if the prerequisite target_clones patch is approved? gcc/fortran/ChangeLog: * decl.cc (gfc_match_gcc_attributes): Handle flatten. * f95-lang.cc (gfc_attribute_table): Add flatten. * gfortran.texi: Document attribute flatten. gcc/testsuite/ChangeLog: * gfortran.dg/attr_flatten-1.f90: New test. --- gcc/fortran/decl.cc | 8 +++- gcc/fortran/f95-lang.cc | 2 + gcc/fortran/gfortran.texi | 8 ++++ gcc/testsuite/gfortran.dg/attr_flatten-1.f90 | 41 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/attr_flatten-1.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index d312d4812b6..3d210c26eb5 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -11841,6 +11841,7 @@ gfc_match_gcc_attributes (void) for(;;) { char ch; + bool known_attr0args = false; if (gfc_match_name (name) != MATCH_YES) return MATCH_ERROR; @@ -11849,7 +11850,9 @@ gfc_match_gcc_attributes (void) if (strcmp (name, ext_attr_list[id].name) == 0) break; - if (id == EXT_ATTR_LAST) + if (strcmp (name, "flatten") == 0) + known_attr0args = true; /* Handled below. We do not need a bit. */ + else if (id == EXT_ATTR_LAST) { gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C"); return MATCH_ERROR; @@ -11864,7 +11867,8 @@ gfc_match_gcc_attributes (void) || id == EXT_ATTR_DLLEXPORT || id == EXT_ATTR_CDECL || id == EXT_ATTR_STDCALL - || id == EXT_ATTR_FASTCALL) + || id == EXT_ATTR_FASTCALL + || known_attr0args) attr.ext_attr_args = chainon (attr.ext_attr_args, build_tree_list (get_identifier (name), NULL_TREE)); diff --git a/gcc/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc index 7154568aec5..ddb5b686cf6 100644 --- a/gcc/fortran/f95-lang.cc +++ b/gcc/fortran/f95-lang.cc @@ -101,6 +101,8 @@ static const struct attribute_spec gfc_attribute_table[] = gfc_handle_omp_declare_target_attribute, NULL }, { "target_clones", 1, -1, true, false, false, false, gfc_handle_omp_declare_target_attribute, NULL }, + { "flatten", 0, 0, true, false, false, false, + gfc_handle_omp_declare_target_attribute, NULL }, { NULL, 0, 0, false, false, false, false, NULL, NULL } }; diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 06e4c8c00a1..be650f28b62 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -3280,6 +3280,14 @@ contains end module mymod @end smallexample +@node flatten + +Procedures annotated with the @code{flatten} attribute have their +callees inlined, if possible. +Please refer to +@ref{Top,,Common Function Attributes,gcc,Using the GNU Compiler Collection (GCC)} +for details about the respective attribute. + The attributes are specified using the syntax @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list} diff --git a/gcc/testsuite/gfortran.dg/attr_flatten-1.f90 b/gcc/testsuite/gfortran.dg/attr_flatten-1.f90 new file mode 100644 index 00000000000..0b72f1ba17c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/attr_flatten-1.f90 @@ -0,0 +1,41 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-optimized" } +! Test __attribute__((flatten)) +! +module attr_flttn_1_a + implicit none +contains + subroutine sub1(i) + integer, intent(in) :: i + integer :: n + do n = 1, i + print *, "marker1 ", i, i+n; + enddo + end + subroutine sub2(i) + integer, intent(in) :: i + integer :: n + do n = 1, i + print *, "marker2 ", i, i*i-n; + enddo + end +end module +module attr_flttn_1_b + use attr_flttn_1_a +contains + subroutine sub3 +!GCC$ ATTRIBUTES flatten :: sub3 + print *, "marker3 " + call sub2(4711) + call sub1(42) + end +end module +! Without the attribute flatten we would have 1 character write for each marker. +! That would be 3 _gfortran_transfer_character_write.*marker +! With the attribute, we have one for each sub plus marker1 and marker2 +! which were inlined into sub3. +! So this gives 5 _gfortran_transfer_character_write.*marker +! and there should be no calls to sub1 (); nor sub2 (); +! { dg-final { scan-tree-dump-times { _gfortran_transfer_character_write .*?marker} 5 "optimized" } } +! { dg-final { scan-tree-dump-not { sub1 \([^\)][^\)]*\);} "optimized" } } +! { dg-final { scan-tree-dump-not { sub2 \([^\)][^\)]*\);} "optimized" } }