From patchwork Fri Nov 8 10:54:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 178871 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp2505552ilf; Fri, 8 Nov 2019 02:55:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzfVtEKGiWdSYFsYqd7OiR7nI54UnpXbNlSt+7ObbSovIKgrbapY2l3CAJtho2+sD4cNcdu X-Received: by 2002:a05:6402:1a4f:: with SMTP id bf15mr9443007edb.160.1573210521073; Fri, 08 Nov 2019 02:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573210521; cv=none; d=google.com; s=arc-20160816; b=dMxcm4htXE8f5IaHfbyIi1DTLzA0ze8wkXKQrAgYwDMSfiFyW/UfyvFhlJuTo+Yhkr HbVu+Vq/2VnPAdiHXmluPu43a06+mBI71y+QlHcz7Jle7RjzjbJCCg26Tfk7f9xh8j6c j/YMxQB8zDIhHj6dfWYT/x0YEepp5SEo1V66nUklrahsyc1UhjF9A7I8jarB3MWdLOGu MEiBpkrc4ofkD32kdy90GkgGsRxCre3t4aEjgHpTEpC/pSewXz8gYE2GucQZzU3eQMp0 svzKq4QnrpDaw54+K8sZ7skI4Xj3e3SVOq2mC9caSeG/I/QnID+0PEyyR0GbObqpYFjx IDTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=PUT+0WnXdm0K/nbIr/1I8fPsqSDSLyEIdNb78UAiEAw=; b=03yZQOzoZwkmTpGd2DKBLkUZVdM7qU5muetRhkSW/E1IjGqp2kGaV4rhSvWdXCezuU V82vjzp6TULDc52o6aBNgH21Go43MOIGD3eGosDJCa/Rj3GpvK//V+j5pwb7bBsZeC9s zEtnxLMnqQNjMTCAL+pVZVWTuLdji0VZDtqoaBHnaSAUDlj4E+0U8z5KLDdDsritJISU wKoAsyObyB31RYsVhpsZxQQGhAdpc5z4MQ2sSSUWep0Y7UGf31fEY95npkuU0VlH+mW5 zEw6I4y9/tl/+JSZ3OC+m1BOzRpJhxJ4bcc7DQbWDuDjJpw2OcfYMZ2YIHIEKfam8xUz LwfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mfsWizmW; dkim=pass header.i=@linaro.org header.s=google header.b=fXxPbmJk; spf=pass (google.com: domain of gcc-patches-return-512804-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-512804-patch=linaro.org@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id s1si3848338edx.188.2019.11.08.02.55.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Nov 2019 02:55:21 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-512804-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=mfsWizmW; dkim=pass header.i=@linaro.org header.s=google header.b=fXxPbmJk; spf=pass (google.com: domain of gcc-patches-return-512804-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-512804-patch=linaro.org@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=uo6CerCEGEvMmJOo364UnXnoinlGqYY2p9ubZZog4OVjXIWSkgEri Flb6Wsg5wMptRf9BWZ+HeLbk7agM26eAb3M3mevXvpAgkBdbIS+G+x+jj61TxYDR RvuIzp9z+hUT2h/4q8oCvjHP0JnceZS+eOLxJsdFfAhNn7Ezj724hA= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=chy6jpMpbuR1+Re1z1b0LmMZZnw=; b=mfsWizmWy60myJ5LsjuT XBxITNvIyZ0x/iIQeqlbZEFYpVZEKjHlKVDHtDUCSCUfvpKiscnhOV7LT+NLtLni PLXXzbK3PMtbDEntqbENLc7B3WrkiJooSkv/dd9ZLd7hAzEmFFRc5r5PSp8Jr2cv 8gNfMG1qqBCHdf33q4KKfOc= Received: (qmail 106498 invoked by alias); 8 Nov 2019 10:54:34 -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 106407 invoked by uid 89); 8 Nov 2019 10:54:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=geu, GEU, LEU, leu X-HELO: mail-wr1-f44.google.com Received: from mail-wr1-f44.google.com (HELO mail-wr1-f44.google.com) (209.85.221.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Nov 2019 10:54:30 +0000 Received: by mail-wr1-f44.google.com with SMTP id f2so6452835wrs.11 for ; Fri, 08 Nov 2019 02:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PUT+0WnXdm0K/nbIr/1I8fPsqSDSLyEIdNb78UAiEAw=; b=fXxPbmJkpa+rIsjyNUsajGYaUL7+qZr6/POIf7acdqYCRU4accv9VYqtVPaOONFyNB qO36uDrL1cKPrLiplqsyjbEWlU8rkIdLawLuyWMbP1uG/TP3XkKh5Ai9DFifLIFtv2Cf teocQNkuF3fgLJekRQRDUVaxSCSQ05PraPQSjJ7/VgPatsyNR0ds52jdlkGW2/if8GtF +eyto6SQ8VkOIMBuaKPcmZCEa8EfhfgxefEejmtoi6FHYAo+agxKKgATWMNUjn81Oan/ YXFYXak9aWPEPtSX+FKjchkCq3tEgjLW7i1MgDNpD8xHEBdqy/0xc2/eou3rWaD1l3E3 QnYg== Return-Path: Received: from localhost.localdomain (212.red-213-99-162.dynamicip.rima-tde.net. [213.99.162.212]) by smtp.gmail.com with ESMTPSA id 19sm8046565wrc.47.2019.11.08.02.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 02:54:27 -0800 (PST) From: Richard Henderson To: gcc-patches@gcc.gnu.org Cc: richard.earnshaw@arm.com, james.greenhalgh@arm.com, richard.sandiford@arm.com, marcus.shawcroft@arm.com, kyrylo.tkachov@arm.com Subject: [PATCH 4/6] arm, aarch64: Add support for __GCC_ASM_FLAG_OUTPUTS__ Date: Fri, 8 Nov 2019 11:54:06 +0100 Message-Id: <20191108105408.27584-5-richard.henderson@linaro.org> In-Reply-To: <20191108105408.27584-1-richard.henderson@linaro.org> References: <20191108105408.27584-1-richard.henderson@linaro.org> Since all but a couple of lines is shared between the two targets, enable them both at once. * config/arm/aarch-common-protos.h (arm_md_asm_adjust): Declare. * config/arm/aarch-common.c (arm_md_asm_adjust): New. * config/arm/arm-c.c (arm_cpu_builtins): Define __GCC_ASM_FLAG_OUTPUTS__. * config/arm/arm.c (TARGET_MD_ASM_ADJUST): New. * config/aarch64/aarch64-c.c (aarch64_define_unconditional_macros): Define __GCC_ASM_FLAG_OUTPUTS__. * config/aarch64/aarch64.c (TARGET_MD_ASM_ADJUST): New. * doc/extend.texi (FlagOutputOperands): Add documentation for ARM and AArch64. --- gcc/config/arm/aarch-common-protos.h | 6 ++ gcc/config/aarch64/aarch64-c.c | 2 + gcc/config/aarch64/aarch64.c | 3 + gcc/config/arm/aarch-common.c | 131 +++++++++++++++++++++++++++ gcc/config/arm/arm-c.c | 1 + gcc/config/arm/arm.c | 3 + gcc/doc/extend.texi | 33 +++++++ 7 files changed, 179 insertions(+) -- 2.17.1 diff --git a/gcc/config/arm/aarch-common-protos.h b/gcc/config/arm/aarch-common-protos.h index 3bf38a104f6..f15cf336e9d 100644 --- a/gcc/config/arm/aarch-common-protos.h +++ b/gcc/config/arm/aarch-common-protos.h @@ -23,6 +23,8 @@ #ifndef GCC_AARCH_COMMON_PROTOS_H #define GCC_AARCH_COMMON_PROTOS_H +#include "hard-reg-set.h" + extern int aarch_accumulator_forwarding (rtx_insn *, rtx_insn *); extern bool aarch_rev16_p (rtx); extern bool aarch_rev16_shleft_mask_imm_p (rtx, machine_mode); @@ -141,5 +143,9 @@ struct cpu_cost_table const struct vector_cost_table vect; }; +rtx_insn * +arm_md_asm_adjust (vec &outputs, vec &/*inputs*/, + vec &constraints, + vec &clobbers, HARD_REG_SET &clobbered_regs); #endif /* GCC_AARCH_COMMON_PROTOS_H */ diff --git a/gcc/config/aarch64/aarch64-c.c b/gcc/config/aarch64/aarch64-c.c index 7c322ca0813..0af859f1c14 100644 --- a/gcc/config/aarch64/aarch64-c.c +++ b/gcc/config/aarch64/aarch64-c.c @@ -69,6 +69,8 @@ aarch64_define_unconditional_macros (cpp_reader *pfile) builtin_define ("__ARM_FEATURE_UNALIGNED"); builtin_define ("__ARM_PCS_AAPCS64"); builtin_define_with_int_value ("__ARM_SIZEOF_WCHAR_T", WCHAR_TYPE_SIZE / 8); + + builtin_define ("__GCC_ASM_FLAG_OUTPUTS__"); } /* Undefine/redefine macros that depend on the current backend state and may diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 1dfff331a5a..26de9879bc7 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -21947,6 +21947,9 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_STRICT_ARGUMENT_NAMING #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true +#undef TARGET_MD_ASM_ADJUST +#define TARGET_MD_ASM_ADJUST arm_md_asm_adjust + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-aarch64.h" diff --git a/gcc/config/arm/aarch-common.c b/gcc/config/arm/aarch-common.c index 965a07a43e3..8b98c8d3802 100644 --- a/gcc/config/arm/aarch-common.c +++ b/gcc/config/arm/aarch-common.c @@ -26,10 +26,16 @@ #include "config.h" #include "system.h" #include "coretypes.h" +#include "insn-modes.h" #include "tm.h" #include "rtl.h" #include "rtl-iter.h" #include "memmodel.h" +#include "errors.h" +#include "tree.h" +#include "expr.h" +#include "function.h" +#include "emit-rtl.h" /* Return TRUE if X is either an arithmetic shift left, or is a multiplication by a power of two. */ @@ -520,3 +526,128 @@ arm_mac_accumulator_is_mul_result (rtx producer, rtx consumer) && !reg_overlap_mentioned_p (mul_result, mac_op0) && !reg_overlap_mentioned_p (mul_result, mac_op1)); } + +/* Worker function for TARGET_MD_ASM_ADJUST. + We implement asm flag outputs. */ + +rtx_insn * +arm_md_asm_adjust (vec &outputs, vec &/*inputs*/, + vec &constraints, + vec &/*clobbers*/, HARD_REG_SET &/*clobbered_regs*/) +{ + bool saw_asm_flag = false; + + start_sequence (); + for (unsigned i = 0, n = outputs.length (); i < n; ++i) + { + const char *con = constraints[i]; + if (strncmp (con, "=@cc", 4) != 0) + continue; + con += 4; + if (strchr (con, ',') != NULL) + { + error ("alternatives not allowed in % flag output"); + continue; + } + + machine_mode mode = CCmode; + rtx_code code = UNKNOWN; + + switch (con[0]) + { + case 'c': + if (con[1] == 'c' && con[2] == 0) + mode = CC_Cmode, code = GEU; + else if (con[1] == 's' && con[2] == 0) + mode = CC_Cmode, code = LTU; + break; + case 'e': + if (con[1] == 'q' && con[2] == 0) + mode = CC_NZmode, code = EQ; + break; + case 'g': + if (con[1] == 'e' && con[2] == 0) + mode = CCmode, code = GE; + else if (con[1] == 't' && con[2] == 0) + mode = CCmode, code = GT; + break; + case 'h': + if (con[1] == 'i' && con[2] == 0) + mode = CCmode, code = GTU; + break; + case 'l': + if (con[1] == 'e' && con[2] == 0) + mode = CCmode, code = LE; + else if (con[1] == 't' && con[2] == 0) + mode = CCmode, code = LT; + else if (con[1] == 's' && con[2] == 0) + mode = CCmode, code = LEU; + break; + case 'm': + if (con[1] == 'i' && con[2] == 0) + mode = CC_NZmode, code = LT; + break; + case 'n': + if (con[1] == 'e' && con[2] == 0) + mode = CC_NZmode, code = NE; + break; + case 'p': + if (con[1] == 'l' && con[2] == 0) + mode = CC_NZmode, code = GE; + break; + case 'v': + if (con[1] == 'c' && con[2] == 0) + mode = CC_Vmode, code = EQ; + else if (con[1] == 's' && con[2] == 0) + mode = CC_Vmode, code = NE; + break; + } + if (code == UNKNOWN) + { + error ("unknown % flag output %qs", constraints[i]); + continue; + } + + rtx dest = outputs[i]; + machine_mode dest_mode = GET_MODE (dest); + if (!SCALAR_INT_MODE_P (dest_mode)) + { + error ("invalid type for % flag output"); + continue; + } + + if (!saw_asm_flag) + { + /* This is the first asm flag output. Here we put the flags + register in as the real output and adjust the condition to + allow it. */ + constraints[i] = "=c"; + outputs[i] = gen_rtx_REG (CCmode, CC_REGNUM); + saw_asm_flag = true; + } + else + { + /* We don't need the flags register as output twice. */ + constraints[i] = "=X"; + outputs[i] = gen_rtx_SCRATCH (word_mode); + } + + rtx x = gen_rtx_REG (mode, CC_REGNUM); + x = gen_rtx_fmt_ee (code, word_mode, x, const0_rtx); + + if (dest_mode == word_mode) + emit_insn (gen_rtx_SET (dest, x)); + else + { + rtx tmp = gen_reg_rtx (word_mode); + emit_insn (gen_rtx_SET (tmp, x)); + + tmp = convert_modes (dest_mode, word_mode, tmp, true); + emit_move_insn (dest, tmp); + } + } + rtx_insn *seq = get_insns (); + end_sequence (); + + return saw_asm_flag ? seq : NULL; +} diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c index 34695fa0112..c4485ce7af1 100644 --- a/gcc/config/arm/arm-c.c +++ b/gcc/config/arm/arm-c.c @@ -122,6 +122,7 @@ arm_cpu_builtins (struct cpp_reader* pfile) if (arm_arch_notm) builtin_define ("__ARM_ARCH_ISA_ARM"); builtin_define ("__APCS_32__"); + builtin_define ("__GCC_ASM_FLAG_OUTPUTS__"); def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB); def_or_undef_macro (pfile, "__thumb2__", TARGET_THUMB2); diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index b620322318b..d889e8ddc60 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -814,6 +814,9 @@ static const struct attribute_spec arm_attribute_table[] = #undef TARGET_CONSTANT_ALIGNMENT #define TARGET_CONSTANT_ALIGNMENT arm_constant_alignment + +#undef TARGET_MD_ASM_ADJUST +#define TARGET_MD_ASM_ADJUST arm_md_asm_adjust /* Obstack for minipool constant handling. */ static struct obstack minipool_obstack; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 9db4f9b1d29..a26b8b976fa 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9771,6 +9771,39 @@ referenced within the assembler template via @code{%0} etc, as there's no corresponding text in the assembly language. @table @asis +@item ARM +@itemx AArch64 +The flag output constraints for the ARM family are of the form +@samp{=@@cc@var{cond}} where @var{cond} is one of the standard +conditions defined in the ARM ARM for @code{ConditionHolds}. + +@table @code +@item eq +``equal'' or Z flag set +@item ne +``not equal'' or Z flag clear +@item cs +``carry'' or C flag set +@item cc +C flag clear +@item mi +``minus'' or N flag set +@item pl +``plus'' or N flag clear +@item hi +unsigned greater than +@item ls +unsigned less than or equal +@item ge +signed greater than or equal +@item lt +signed less than +@item gt +signed greater than +@item le +signed less than or equal +@end table + @item x86 family The flag output constraints for the x86 family are of the form @samp{=@@cc@var{cond}} where @var{cond} is one of the standard