From patchwork Wed Sep 13 19:22:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 112490 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1304541qgf; Wed, 13 Sep 2017 12:23:15 -0700 (PDT) X-Received: by 10.84.215.134 with SMTP id l6mr21852975pli.53.1505330595203; Wed, 13 Sep 2017 12:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505330595; cv=none; d=google.com; s=arc-20160816; b=xJszGM45juCZTWpubqcQykwXQvcICsk3I1L2Celz4rfcKwxb7JoV6gDy6qRuFUXgb+ ROzm/GkFuTMzurKN/TkopzlSi5nKCBmp8j6AVCvwQRHK8ggzoRNrOaHSbkIcTdolHqnS HmhWc371lOzmUT/gQdByeYYQTomlvT+NsS0U03MqQmTfvfJUZBd0xxrx8rEHQlA7jo3O RwPd3kAP8aL3T1jqa+Q7oYKiV3NCxl6z31r8YacYgXllxLJudJi+guCwJhdE1RiF4VUG jIiOUo3Uh5o8/uAxTKqDpEEPmiAM8W81rMqu+tSy0/T11TOMxPyMMV2G+aFgjzTO7vRp kmQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=cnDfQsJ6V8urTQGE1urvcZgP7hO4RLJpkiw53OHNlnk=; b=LPPWvnbyxUn9m/3AkBErDVV3o0lwuz+d8m84hS1r9SyrYFs2450ehMX4x6U08XAqmo OCeAr5Su+GWlBuD6258B77jwmdVGe1G5EtNHGuGEHzWOMkizoI2v2Op7kG7KVYpshuUf DqLSIgOk+d4OuG3K93JjmSgOl0FSwuz6jmJv58TjvjgRBn0mGQcdT3mbkvt/NQWjRPz8 ycJKAfcIBHVtiWPEoMtZEuXFSl0p8iNzr+nZUWEbqINRYFmZ7fxrUAPKXgVBfJrBAHAL 44XOGs+zST6EL+xy5ZGhvZJDrwHA6t1B75SpF6mSdakjU+pGPR+jACUFKchG4Tv9fVVV RBVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FY84NGOt; spf=pass (google.com: domain of gcc-patches-return-462075-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462075-patch=linaro.org@gcc.gnu.org; dmarc=fail (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 32si607136ple.704.2017.09.13.12.23.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Sep 2017 12:23:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462075-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=FY84NGOt; spf=pass (google.com: domain of gcc-patches-return-462075-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462075-patch=linaro.org@gcc.gnu.org; dmarc=fail (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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=sFMkREm8uaF7zNpxjodFApK/GmHhgTxGWQyI0HT0hOX5ojxDnlzMU rff8s5s8kbQCty5Tt2zipsI02yZR3+tvn2r6xbcgceU8eHcbf8zwB8H6mKhn4YAi tZb3rhguF+sS1yhFgiia3j3+c4/eHeEWFeGH6fJnsNrSwktfuK6egU= 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:subject:date:message-id:mime-version:content-type; s= default; bh=/KA6CCwg8n6FIexpILTIChDAvzE=; b=FY84NGOtfdfABBYNAYWy GDneA4PmGuG+woBTbzpYKF/4t1s1D7sJOqd1cJVnVV13PO3kmXjKHr27JnADaklB gL7EWVU6WrXTGMxilj2fHKvKqM31TWIzOpuLocJcdnYvPzUUDC0PESgXkOpoZLy+ 70hvPruZEtmLgrXFWcCmEKE= Received: (qmail 102742 invoked by alias); 13 Sep 2017 19:23:02 -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 101486 invoked by uid 89); 13 Sep 2017 19:23:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f43.google.com Received: from mail-wm0-f43.google.com (HELO mail-wm0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Sep 2017 19:22:59 +0000 Received: by mail-wm0-f43.google.com with SMTP id 189so237828wmh.1 for ; Wed, 13 Sep 2017 12:22:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=cnDfQsJ6V8urTQGE1urvcZgP7hO4RLJpkiw53OHNlnk=; b=Lo3IuplrLQdGH7At4AJyhkrbcl1xXmRbQhwtJutKFikx5uURg1zPD0AEPRy4n7GwFh H1MbAwmEGx5wp0Q4CDPIIuOtIlvADFJJIqSMXquT/s415SRHdbmG+waCVez0smpOfWQp oQABk6pYEp6EUHVrh7iNN5jakXw8W4DpqmrN0IgMeWIUpHyPvRhFlImFI0v+dBEPY7AC p9UJq8zZApbEx7YhsHdExggvUVtOllumpLf3YB42QSXbhFovdBLLGRVkBUOE971NJPbT 3JWwJxctROO+S2gETV3GbwQ0WAJUFh2HbMjPt4zXzki7nCdf+F2FFR88EYyO4+2e207L VZ8Q== X-Gm-Message-State: AHPjjUis6slAq2I/CA687zjK3QymJ1ElcweUlBeROQlo7n8CUyHwfglF s2J4MidOWIul118FJJeQ0eJXS8sqq8I= X-Google-Smtp-Source: AOwi7QBGnFRiyaO5N1vmSA98JviSq8F5n2deAzdThQDLyYIGjUOKQKfqQ0ybhh9KmtZuFsCaNbgPUw== X-Received: by 10.28.8.20 with SMTP id 20mr3132950wmi.96.1505330577465; Wed, 13 Sep 2017 12:22:57 -0700 (PDT) Received: from localhost ([2.25.234.0]) by smtp.gmail.com with ESMTPSA id f188sm2445327wme.21.2017.09.13.12.22.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 12:22:56 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Turn FUNCTION_ARG_OFFSET into a hook Date: Wed, 13 Sep 2017 20:22:55 +0100 Message-ID: <871snabdyo.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Nice and easy, one definition and one use :-) Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. Also tested by comparing the testsuite assembly output on at least one target per CPU directory. OK to install? Richard 2017-09-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * target.def (function_arg_offset): New hook. * targhooks.h (default_function_arg_offset): Declare. * targhooks.c (default_function_arg_offset): New function. * function.c (locate_and_pad_parm): Use targetm.calls.function_arg_offset instead of FUNCTION_ARG_OFFSET. * doc/tm.texi.in (FUNCTION_ARG_OFFSET): Replace with... (TARGET_FUNCTION_ARG_OFFSET): ...this. * doc/tm.texi: Regenerate. * config/spu/spu.h (FUNCTION_ARG_OFFSET): Delete. * config/spu/spu.c (spu_function_arg_offset): New function. (TARGET_FUNCTION_ARG_OFFSET): Redefine. * system.h (FUNCTION_ARG_OFFSET): Poison. Index: gcc/target.def =================================================================== --- gcc/target.def 2017-09-13 20:12:24.499190740 +0100 +++ gcc/target.def 2017-09-13 20:14:46.245761652 +0100 @@ -4573,6 +4573,16 @@ used for arguments without any special h default_function_arg_advance) DEFHOOK +(function_arg_offset, + "This hook returns the number of bytes to add to the offset of an\n\ +argument of type @var{type} and mode @var{mode} when passed in memory.\n\ +This is needed for the SPU, which passes @code{char} and @code{short}\n\ +arguments in the preferred slot that is in the middle of the quad word\n\ +instead of starting at the top. The default implementation returns 0.", + HOST_WIDE_INT, (machine_mode mode, const_tree type), + default_function_arg_offset) + +DEFHOOK (function_arg_padding, "This hook determines whether, and in which direction, to pad out\n\ an argument of mode @var{mode} and type @var{type}. It returns\n\ Index: gcc/targhooks.h =================================================================== --- gcc/targhooks.h 2017-09-13 18:03:51.114330107 +0100 +++ gcc/targhooks.h 2017-09-13 20:14:46.245761652 +0100 @@ -132,6 +132,7 @@ extern bool hook_bool_CUMULATIVE_ARGS_tr (const_tree, const_tree, const_tree); extern void default_function_arg_advance (cumulative_args_t, machine_mode, const_tree, bool); +extern HOST_WIDE_INT default_function_arg_offset (machine_mode, const_tree); extern pad_direction default_function_arg_padding (machine_mode, const_tree); extern rtx default_function_arg (cumulative_args_t, machine_mode, const_tree, bool); Index: gcc/targhooks.c =================================================================== --- gcc/targhooks.c 2017-09-13 18:03:51.114330107 +0100 +++ gcc/targhooks.c 2017-09-13 20:14:46.245761652 +0100 @@ -734,6 +734,14 @@ default_function_arg_advance (cumulative gcc_unreachable (); } +/* Default implementation of TARGET_FUNCTION_ARG_OFFSET. */ + +HOST_WIDE_INT +default_function_arg_offset (machine_mode, const_tree) +{ + return 0; +} + /* Default implementation of TARGET_FUNCTION_ARG_PADDING: usually pad upward, but pad short args downward on big-endian machines. */ Index: gcc/function.c =================================================================== --- gcc/function.c 2017-09-13 20:12:24.498282217 +0100 +++ gcc/function.c 2017-09-13 20:14:46.244854334 +0100 @@ -4249,9 +4249,8 @@ locate_and_pad_parm (machine_mode passed locate->size.constant -= part_size_in_regs; } -#ifdef FUNCTION_ARG_OFFSET - locate->offset.constant += FUNCTION_ARG_OFFSET (passed_mode, type); -#endif + locate->offset.constant + += targetm.calls.function_arg_offset (passed_mode, type); } /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. Index: gcc/doc/tm.texi.in =================================================================== --- gcc/doc/tm.texi.in 2017-09-13 20:12:24.496465170 +0100 +++ gcc/doc/tm.texi.in 2017-09-13 20:14:46.243947015 +0100 @@ -3281,13 +3281,7 @@ argument @var{libname} exists for symmet @hook TARGET_FUNCTION_ARG_ADVANCE -@defmac FUNCTION_ARG_OFFSET (@var{mode}, @var{type}) -If defined, a C expression that is the number of bytes to add to the -offset of the argument passed in memory. This is needed for the SPU, -which passes @code{char} and @code{short} arguments in the preferred -slot that is in the middle of the quad word instead of starting at the -top. -@end defmac +@hook TARGET_FUNCTION_ARG_OFFSET @hook TARGET_FUNCTION_ARG_PADDING Index: gcc/doc/tm.texi =================================================================== --- gcc/doc/tm.texi 2017-09-13 20:12:24.496465170 +0100 +++ gcc/doc/tm.texi 2017-09-13 20:14:46.243947015 +0100 @@ -4079,13 +4079,13 @@ on the stack. The compiler knows how to used for arguments without any special help. @end deftypefn -@defmac FUNCTION_ARG_OFFSET (@var{mode}, @var{type}) -If defined, a C expression that is the number of bytes to add to the -offset of the argument passed in memory. This is needed for the SPU, -which passes @code{char} and @code{short} arguments in the preferred -slot that is in the middle of the quad word instead of starting at the -top. -@end defmac +@deftypefn {Target Hook} HOST_WIDE_INT TARGET_FUNCTION_ARG_OFFSET (machine_mode @var{mode}, const_tree @var{type}) +This hook returns the number of bytes to add to the offset of an +argument of type @var{type} and mode @var{mode} when passed in memory. +This is needed for the SPU, which passes @code{char} and @code{short} +arguments in the preferred slot that is in the middle of the quad word +instead of starting at the top. The default implementation returns 0. +@end deftypefn @deftypefn {Target Hook} pad_direction TARGET_FUNCTION_ARG_PADDING (machine_mode @var{mode}, const_tree @var{type}) This hook determines whether, and in which direction, to pad out Index: gcc/config/spu/spu.h =================================================================== --- gcc/config/spu/spu.h 2017-09-13 20:12:24.493739600 +0100 +++ gcc/config/spu/spu.h 2017-09-13 20:14:46.241225060 +0100 @@ -309,13 +309,6 @@ #define CUMULATIVE_ARGS int #define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,FNDECL,N_NAMED_ARGS) \ ((CUM) = 0) -/* The SPU ABI wants 32/64-bit types at offset 0 in the quad-word on the - stack. 8/16-bit types should be at offsets 3/2 respectively. */ -#define FUNCTION_ARG_OFFSET(MODE, TYPE) \ -(((TYPE) && INTEGRAL_TYPE_P (TYPE) && GET_MODE_SIZE (MODE) < 4) \ - ? (4 - GET_MODE_SIZE (MODE)) \ - : 0) - #define PAD_VARARGS_DOWN 0 #define FUNCTION_ARG_REGNO_P(N) ((N) >= (FIRST_ARG_REGNUM) && (N) <= (LAST_ARG_REGNUM)) Index: gcc/config/spu/spu.c =================================================================== --- gcc/config/spu/spu.c 2017-09-13 20:12:24.493739600 +0100 +++ gcc/config/spu/spu.c 2017-09-13 20:14:46.241225060 +0100 @@ -3881,6 +3881,18 @@ spu_function_arg_advance (cumulative_arg : spu_hard_regno_nregs (FIRST_ARG_REGNUM, mode)); } +/* Implement TARGET_FUNCTION_ARG_OFFSET. The SPU ABI wants 32/64-bit + types at offset 0 in the quad-word on the stack. 8/16-bit types + should be at offsets 3/2 respectively. */ + +static HOST_WIDE_INT +spu_function_arg_offset (machine_mode mode, const_tree type) +{ + if (type && INTEGRAL_TYPE_P (type) && GET_MODE_SIZE (mode) < 4) + return 4 - GET_MODE_SIZE (mode); + return 0; +} + /* Implement TARGET_FUNCTION_ARG_PADDING. */ static pad_direction @@ -7300,6 +7312,9 @@ #define TARGET_FUNCTION_ARG spu_function #undef TARGET_FUNCTION_ARG_ADVANCE #define TARGET_FUNCTION_ARG_ADVANCE spu_function_arg_advance +#undef TARGET_FUNCTION_ARG_OFFSET +#define TARGET_FUNCTION_ARG_OFFSET spu_function_arg_offset + #undef TARGET_FUNCTION_ARG_PADDING #define TARGET_FUNCTION_ARG_PADDING spu_function_arg_padding Index: gcc/system.h =================================================================== --- gcc/system.h 2017-09-13 20:12:24.498282217 +0100 +++ gcc/system.h 2017-09-13 20:14:46.244854334 +0100 @@ -915,7 +915,7 @@ #define realloc xrealloc MODES_TIEABLE_P FUNCTION_ARG_PADDING SLOW_UNALIGNED_ACCESS \ HARD_REGNO_NREGS SECONDARY_MEMORY_NEEDED_MODE \ SECONDARY_MEMORY_NEEDED CANNOT_CHANGE_MODE_CLASS \ - TRULY_NOOP_TRUNCATION + TRULY_NOOP_TRUNCATION FUNCTION_ARG_OFFSET /* Target macros only used for code built for the target, that have moved to libgcc-tm.h or have never been present elsewhere. */