From patchwork Fri Dec 8 11:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 121147 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp522806qgn; Fri, 8 Dec 2017 03:15:51 -0800 (PST) X-Google-Smtp-Source: AGs4zMap1+Ig2dFiXAjVjeCJtC0YxdGYsvO47dieFJrGAXXTogCzzS3Ib8zFHR4TlbD+i7CBCoPh X-Received: by 10.84.149.139 with SMTP id m11mr29605680pla.36.1512731751264; Fri, 08 Dec 2017 03:15:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512731751; cv=none; d=google.com; s=arc-20160816; b=d0pbdVcrBPkxzu2AtmQmHhjb2IQt3YY29FdziWjtgYG3l44fak0Kk1hyB3y5/EN8z9 TpdWjOar8y8crykKbryAyibNT+tC4SNP+/YeeWJV3Fq68Ei+CxLRFuf1tDujCBvm8OmI OtEPXlDSFWxKPi7QNKFqQ05BG29LSJTz1/oehb7MsjFYop7Q0K6I8tgK/vnkLM6dVQVh OcKRic3v5jfpoMzq8+vXQQFC64z0vBZ/5RyntKC1cjqTIBiWJWyTWv68R2fI3bJ6W8gn 6TOjybnzFERQbSzR+En4IqYD5EW6cwLD0Wi5aNjapN8ItMWWJxPjr9VaFS/uazRMuw57 BwHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:subject:from:to :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=bfE8CMue82byvYBjQV9UcKJ90zTFndnCngaptwM+/OA=; b=w925X07izoFgSE21TZAWNUb1BI+4bCIxdmKdEbSZL7/uLrZg82LGY1enQXozyuPubk Lh9mjW6htlEshoBwbwiNWf3yr3VDr2+199xZVF1fiOKxg9lfVW/RIslimSUsypb7YbzF LWo3ndzlIx3SZcDjN++vqnZjGu6lIodHrtR+ND291maVX2PurDgm9gAEyvY5j/ULCNTp tbxRm72fuUcC4gYcP63EoolAmQtPp02KAvMRO6mFxP7LW4e0R3kSK10pyR9Vpu/Ly+U/ EJ/Bfi5I/coxMBaeoe9TL91OXCy8LQY2gOJxVYie+ClpLnFHZr73YXvx0lGV0wrOoy8m LpOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WDl/fWA5; spf=pass (google.com: domain of gcc-patches-return-468761-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-468761-patch=linaro.org@gcc.gnu.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id z1si5330550pgu.390.2017.12.08.03.15.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Dec 2017 03:15:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-468761-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WDl/fWA5; spf=pass (google.com: domain of gcc-patches-return-468761-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-468761-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=RshGYW8DSDlarR6hrGahbru2vvtX+uUBt9lBzKhUTP91IUrmsY wLiQGTxqz4jZMIFV5m22zeFhGjQ6/A+9PLFUfD2Uu//bhx6yXkYH6+wCPRao6FOH rUCcvztD8B+nv9zE8gBtWCHneYAdPS7QHD0g5ICqwFKGNPg8IiMHLUIrU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=p9G8iSQ0HYdFvDv2KlLx6gkgu8w=; b=WDl/fWA59qEkdBmJbHbi yu/HhkykucfUEGNwIKLlNenBSzShqnIS3McFt3aEHs92U0AgixEgdNrOCNAx1liG NqRF9w060ST111gQbviFzhV0sQrXTVuiFs0GXRcvu+OyNBGsgFrB7H0O3VqWq4f4 XmJ570sLXi8Em+FRY5qlhKQ= Received: (qmail 11116 invoked by alias); 8 Dec 2017 11:15:38 -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 4944 invoked by uid 89); 8 Dec 2017 11:15:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Dec 2017 11:15:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A13511529; Fri, 8 Dec 2017 03:15:06 -0800 (PST) Received: from e105689-lin.cambridge.arm.com (e105689-lin.cambridge.arm.com [10.2.207.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 152F23F24A; Fri, 8 Dec 2017 03:15:05 -0800 (PST) To: gcc-patches From: "Richard Earnshaw (lists)" Subject: [arm] Don't strip off all architecture features from -march passed to assembler Message-ID: <7b71dfdd-68c7-b011-de0f-17ee549f61ff@arm.com> Date: Fri, 8 Dec 2017 11:15:04 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 When GCC invokes the assembler it generates a sanitized version of the user-specified -march option to pass through, since the assembler does not understand all the new FPU-related architectural options. Unfortunately it goes too far and strips off all the architectural extensions, including some that are unrelated to the -mfpu variant selected. Again, this doesn't really matter when compiling C code because the compiler will override the command-line specified architecture with directives in the assembly file itself, but when using the compiler driver to invoke the assembler the only indiciation of the desired architecture might come from the command line. We fix this by adjusting the canonicalization pass to remove any option that only specifies features that can be expressed by -mfpu (any that go beyond that are already supported by the assembler). We do have to take care to re-order the options, though as the assembler expects feature options to be in a canonical order (unlike the compiler, where ordering is handled left-to-right: there's only a difference if there are negation options, but a canonicalized architecture string shouldn't have any of those). We do this by recording which options we need and then sorting the final list alphabetically. * common/config/arm/arm-common.c: Include . (INCLUDE_VECTOR): Define. (compare_opt_names): New function. (arm_rewrite_selected_arch): Only strip out extensions that can be expressed through -mfpu. Sort the remaining extensions alphabetically. diff --git a/gcc/common/config/arm/arm-common.c b/gcc/common/config/arm/arm-common.c index 90b04f1618e39441c2e7395bbea2487f49a3170c..d6374276a109cb8bc0dbe8640af4accc57a81496 100644 --- a/gcc/common/config/arm/arm-common.c +++ b/gcc/common/config/arm/arm-common.c @@ -18,6 +18,7 @@ . */ #define INCLUDE_LIST +#define INCLUDE_VECTOR #include "config.h" #include "system.h" #include "coretypes.h" @@ -30,6 +31,7 @@ #include "flags.h" #include "sbitmap.h" #include "diagnostic.h" +#include /* Set default optimization options. */ static const struct default_options arm_option_optimization_table[] = @@ -114,26 +116,99 @@ arm_rewrite_mcpu (int argc, const char **argv) return arm_rewrite_selected_cpu (argv[argc - 1]); } -/* Truncate NAME at the first '+' character seen, or return - NAME unmodified. Similar to arm_rewrite_selected_cpu, but we must - preserve '.' as that is part of some architecture names. */ +static bool +compare_opt_names (const char *first, const char *second) +{ + for (int i = 0; ; i++) + if (first[i] == 0 + || first[i] < second[i]) + return true; + return false; +} +/* Rewrite the architecture string for passing to the assembler. + Although the syntax is similar we cannot assume that it supports + the newer FP related options. So strip any option that only + defines features in the standard -mfpu options out. We'll generate + a suitable -mfpu option elsewhere to carry that information. NAME + should already have been canonicalized, so we do not expect to + encounter +no.. options that remove features. A final problem is + that the assembler expects the feature extensions to be listed + alphabetically, so we build a list of required options and then + sort them into canonical order in the resulting string. */ const char * arm_rewrite_selected_arch (const char *name) { - static char output_buf[ARM_CPU_NAME_LENGTH + 1] = {0}; - char *arg_pos; + /* The result we return needs to be semi persistent, so handle being + re-invoked. */ + static char *asm_arch = NULL; - strncpy (output_buf, name, ARM_CPU_NAME_LENGTH); - output_buf[ARM_CPU_NAME_LENGTH] = 0; + if (asm_arch) + { + free (asm_arch); + asm_arch = NULL; + } - arg_pos = strchr (output_buf, '+'); + const char *arg_pos = strchr (name, '+'); - /* If we found a '+' truncate the entry at that point. */ - if (arg_pos) - *arg_pos = '\0'; + /* No extension options? just return the original string. */ + if (arg_pos == NULL) + return name; - return output_buf; + const arch_option *arch_opt + = arm_parse_arch_option_name (all_architectures, "-march", name); + + auto_sbitmap fpu_bits (isa_num_bits); + static const enum isa_feature fpu_bitlist[] + = { ISA_ALL_FPU_INTERNAL, isa_nobit }; + + arm_initialize_isa (fpu_bits, fpu_bitlist); + + auto_sbitmap opt_bits (isa_num_bits); + + /* Ensure that the resulting string is large enough for the result. We + never add options, so using strdup here will ensure that. */ + asm_arch = xstrdup (name); + asm_arch[arg_pos - name] = '\0'; + + std::vectoroptlist; + + while (arg_pos) + { + const char *end = strchr (arg_pos + 1, '+'); + size_t len = end ? end - arg_pos : strlen (arg_pos); + + for (const cpu_arch_extension *entry = arch_opt->common.extensions; + entry->name != NULL; + entry++) + { + if (strncmp (entry->name, arg_pos + 1, len - 1) == 0 + && entry->name[len - 1] == '\0') + { + /* Don't expect removal options. */ + gcc_assert (!entry->remove); + arm_initialize_isa (opt_bits, entry->isa_bits); + if (!bitmap_subset_p (opt_bits, fpu_bits)) + optlist.push_back (entry->name); + bitmap_clear (opt_bits); + break; + } + } + + arg_pos = end; + } + + std::sort (optlist.begin (), optlist.end (), compare_opt_names); + + for (std::vector::iterator opt_iter = optlist.begin (); + opt_iter != optlist.end (); + ++opt_iter) + { + strcat (asm_arch, "+"); + strcat (asm_arch, (*opt_iter)); + } + + return asm_arch; } /* Called by the driver to rewrite a name passed to the -march