From patchwork Wed Nov 7 05:37:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 994099 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-489201-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fyLDh3Ys"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Sz/aVCIa"; 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 42qZtp625Pz9s8T for ; Wed, 7 Nov 2018 16:37:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=XC11O4jdUUoPWJsvj ahpJTyyvtlfh4cOz7bN+M7meF4mJjuEwJgkCa/bVJzW6IoJxKf8aHY4mQ+ck7xUn x1DuybnTOVWd2NB4KHBLhNehKxMBO+DwTwg/as/dKFUK/S7OPovt890FWXBcDbov xT21kgXRAqapwxxJPzroxfF6YQ= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=fGVxLyMPFYBlxz0vy+JCdP1 BTxA=; b=fyLDh3YsslSme3VvDw7C8xiAEY4KgE9tstk+Z/qKjeF93TJzjuJbEk2 XtkdyvgD0GnMV/5yOxi/TTR/czk7LP1IKrI9htB/ZBrsEgnkEaAeHndKzu+3ifPg UU+vEZYKycZZQc/uVbBhK/6WtqnUqc2yQX9PIc1jws5216Rdsk+E= Received: (qmail 71387 invoked by alias); 7 Nov 2018 05:37:28 -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 71213 invoked by uid 89); 7 Nov 2018 05:37:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=gg, addis, match_dup X-HELO: mail-pf1-f179.google.com Received: from mail-pf1-f179.google.com (HELO mail-pf1-f179.google.com) (209.85.210.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 05:37:22 +0000 Received: by mail-pf1-f179.google.com with SMTP id y18-v6so4835015pfn.1 for ; Tue, 06 Nov 2018 21:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HZll/NUKBzt83W98Vw80FQwr9LmoJy5sEyF0LIfUFsc=; b=Sz/aVCIaAH9CT1mZFQq8S32+LLstM67GhB18zBtK8mBzaGeIOsUgL8YT9tDmH69pas 6FUI3jb+YZLdoBA+4Ddz46v7VV5F79JdaPfwMwkhWzNgtQi8SjH7aS2WaQs4hDv/brVp rMXStFyg4VOC3Io8pDWqlR/3gBOKijbwdaHF34cBPjawhy3gLVFDPkoZXiCZkH21Ddwc SPbA9R3/IybsYVnff4fUdAL/wxVMPkr2CXHYhNOcfAJITwBmkfMVV0KEJpIwxGiYAqSn t3UdZDp62q6jnHbPmxI22r7fZr4TuP3adHRWB9WCu5/12luth+XM+j6Z7Bu9XLpzpn0L suMw== Received: from bubble.grove.modra.org ([58.175.241.133]) by smtp.gmail.com with ESMTPSA id c7-v6sm52162322pfh.25.2018.11.06.21.37.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 21:37:19 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id BCFD28033C; Wed, 7 Nov 2018 16:07:15 +1030 (ACDT) Date: Wed, 7 Nov 2018 16:07:15 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 1/6] [RS6000] rs6000_output_call for external call insn assembly output Message-ID: <20181107053715.GN29482@bubble.grove.modra.org> References: <20181107053326.GM29482@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181107053326.GM29482@bubble.grove.modra.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes This is a first step in tidying rs6000 call patterns, in preparation to support inline plt calls. * config/rs6000/rs6000-protos.h (rs6000_output_call): Declare. (macho_output_call): Rename from output_call. * config/rs6000/rs6000.c (rs6000_output_call): New function. (macho_output_call): Rename from output_call. * config/rs6000/rs6000.md (tls_gd_aix): Use rs6000_output_call to emit call. (tls_gd_sysv, tls_gd_call_aix, tls_gd_call_sysv): Likewise. (tls_ld_aix, tls_ld_sysv, tls_ld_call_aix): Likewise. (tls_ld_call_sysv, call_nonlocal_sysv): Likewise. (call_nonlocal_sysv_secure, call_value_nonlocal_sysv): Likewise. (call_value_nonlocal_sysv_secure, call_nonlocal_aix): Likewise. (call_value_nonlocal_aix, sibcall_nonlocal_sysv): Likewise. (sibcall_value_nonlocal_sysv, sibcall_aix): Likewise. (sibcall_value_aix): Likewise. diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index fb69019c47c..f1a421dde16 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -111,6 +111,7 @@ extern int ccr_bit (rtx, int); extern void rs6000_output_function_entry (FILE *, const char *); extern void print_operand (FILE *, rtx, int); extern void print_operand_address (FILE *, rtx); +extern const char *rs6000_output_call (rtx *, unsigned int, bool, const char *); extern enum rtx_code rs6000_reverse_condition (machine_mode, enum rtx_code); extern rtx rs6000_emit_eqne (machine_mode, rtx, rtx, rtx); @@ -228,7 +229,7 @@ extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT, extern void rs6000_d_target_versions (void); #if TARGET_MACHO -char *output_call (rtx_insn *, rtx *, int, int); +char *macho_output_call (rtx_insn *, rtx *, int, int); #endif #ifdef NO_DOLLAR_IN_LABEL diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 75b197f458c..b22cae55a0d 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21380,6 +21380,37 @@ rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) return default_assemble_integer (x, size, aligned_p); } +/* Return a template string for assembly to emit when making an + external call. FUN is the %z argument, ARG is either NULL or + a @TLSGD or @TLSLD __tls_get_addr argument specifier. */ + +const char * +rs6000_output_call (rtx *operands, unsigned int fun, bool sibcall, + const char *arg) +{ + /* -Wformat-overflow workaround, without which gcc thinks that %u + might produce 10 digits. FUN is 0 or 1 as of 2018-03. */ + gcc_assert (fun <= 6); + + /* The magic 32768 offset here corresponds to the offset of + r30 in .got2, as given by LCTOC1. See sysv4.h:toc_section. */ + char z[10]; + sprintf (z, "%%z%u%s", fun, + (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic == 2 + ? "+32768" : "")); + + static char str[32]; /* 5 spare */ + if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) + sprintf (str, "b%s %s%s%s", "l" + sibcall, z, arg, + sibcall ? "" : "\n\tnop"); + else if (DEFAULT_ABI == ABI_V4) + sprintf (str, "b%s %s%s%s", "l" + sibcall, z, arg, + flag_pic ? "@plt" : ""); + else + gcc_unreachable (); + return str; +} + #if defined (HAVE_GAS_HIDDEN) && !TARGET_MACHO /* Emit an assembler directive to set symbol visibility for DECL to VISIBILITY_TYPE. */ @@ -32818,8 +32849,8 @@ get_prev_label (tree function_name) CALL_DEST is the routine we are calling. */ char * -output_call (rtx_insn *insn, rtx *operands, int dest_operand_number, - int cookie_operand_number) +macho_output_call (rtx_insn *insn, rtx *operands, int dest_operand_number, + int cookie_operand_number) { static char buf[256]; if (darwin_emit_branch_islands diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 66742f66a89..52088fdfbdb 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -9454,10 +9454,11 @@ (define_insn_and_split "tls_gd_aix" "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)" { if (TARGET_CMODEL != CMODEL_SMALL) - return "addis %0,%1,%2@got@tlsgd@ha\;addi %0,%0,%2@got@tlsgd@l\;" - "bl %z3\;nop"; + output_asm_insn ("addis %0,%1,%2@got@tlsgd@ha\;" + "addi %0,%0,%2@got@tlsgd@l", operands); else - return "addi %0,%1,%2@got@tlsgd\;bl %z3\;nop"; + output_asm_insn ("addi %0,%1,%2@got@tlsgd", operands); + return rs6000_output_call (operands, 3, false, ""); } "&& TARGET_TLS_MARKERS" [(set (match_dup 0) @@ -9486,15 +9487,8 @@ (define_insn_and_split "tls_gd_sysv" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4" { - if (flag_pic) - { - if (TARGET_SECURE_PLT && flag_pic == 2) - return "addi %0,%1,%2@got@tlsgd\;bl %z3+32768@plt"; - else - return "addi %0,%1,%2@got@tlsgd\;bl %z3@plt"; - } - else - return "addi %0,%1,%2@got@tlsgd\;bl %z3"; + output_asm_insn ("addi %0,%1,%2@got@tlsgd", operands); + return rs6000_output_call (operands, 3, false, ""); } "&& TARGET_TLS_MARKERS" [(set (match_dup 0) @@ -9559,7 +9553,9 @@ (define_insn "*tls_gd_call_aix" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && TARGET_TLS_MARKERS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)" - "bl %z1(%3@tlsgd)\;nop" +{ + return rs6000_output_call (operands, 1, false, "(%3@tlsgd)"); +} [(set_attr "type" "branch") (set_attr "length" "8")]) @@ -9572,13 +9568,7 @@ (define_insn "*tls_gd_call_sysv" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS" { - if (flag_pic) - { - if (TARGET_SECURE_PLT && flag_pic == 2) - return "bl %z1+32768(%3@tlsgd)@plt"; - return "bl %z1(%3@tlsgd)@plt"; - } - return "bl %z1(%3@tlsgd)"; + return rs6000_output_call (operands, 1, false, "(%3@tlsgd)"); } [(set_attr "type" "branch")]) @@ -9592,10 +9582,11 @@ (define_insn_and_split "tls_ld_aix" "HAVE_AS_TLS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)" { if (TARGET_CMODEL != CMODEL_SMALL) - return "addis %0,%1,%&@got@tlsld@ha\;addi %0,%0,%&@got@tlsld@l\;" - "bl %z2\;nop"; + output_asm_insn ("addis %0,%1,%&@got@tlsld@ha\;" + "addi %0,%0,%&@got@tlsld@l", operands); else - return "addi %0,%1,%&@got@tlsld\;bl %z2\;nop"; + output_asm_insn ("addi %0,%1,%&@got@tlsld", operands); + return rs6000_output_call (operands, 2, false, ""); } "&& TARGET_TLS_MARKERS" [(set (match_dup 0) @@ -9622,15 +9613,8 @@ (define_insn_and_split "tls_ld_sysv" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4" { - if (flag_pic) - { - if (TARGET_SECURE_PLT && flag_pic == 2) - return "addi %0,%1,%&@got@tlsld\;bl %z2+32768@plt"; - else - return "addi %0,%1,%&@got@tlsld\;bl %z2@plt"; - } - else - return "addi %0,%1,%&@got@tlsld\;bl %z2"; + output_asm_insn ("addi %0,%1,%&@got@tlsld", operands); + return rs6000_output_call (operands, 2, false, ""); } "&& TARGET_TLS_MARKERS" [(set (match_dup 0) @@ -9691,7 +9675,9 @@ (define_insn "*tls_ld_call_aix" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && TARGET_TLS_MARKERS && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)" - "bl %z1(%&@tlsld)\;nop" +{ + return rs6000_output_call (operands, 1, false, "(%&@tlsld)"); +} [(set_attr "type" "branch") (set_attr "length" "8")]) @@ -9703,13 +9689,7 @@ (define_insn "*tls_ld_call_sysv" (clobber (reg:SI LR_REGNO))] "HAVE_AS_TLS && DEFAULT_ABI == ABI_V4 && TARGET_TLS_MARKERS" { - if (flag_pic) - { - if (TARGET_SECURE_PLT && flag_pic == 2) - return "bl %z1+32768(%&@tlsld)@plt"; - return "bl %z1(%&@tlsld)@plt"; - } - return "bl %z1(%&@tlsld)"; + return rs6000_output_call (operands, 1, false, "(%&@tlsld)"); } [(set_attr "type" "branch")]) @@ -10595,15 +10575,9 @@ (define_insn_and_split "*call_nonlocal_sysv" output_asm_insn ("creqv 6,6,6", operands); #if TARGET_MACHO - return output_call(insn, operands, 0, 2); + return macho_output_call(insn, operands, 0, 2); #else - if (DEFAULT_ABI == ABI_V4 && flag_pic) - { - gcc_assert (!TARGET_SECURE_PLT); - return "bl %z0@plt"; - } - else - return "bl %z0"; + return rs6000_output_call (operands, 0, false, ""); #endif } "DEFAULT_ABI == ABI_V4 @@ -10636,13 +10610,7 @@ (define_insn "*call_nonlocal_sysv_secure" else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (flag_pic == 2) - /* The magic 32768 offset here and in the other sysv call insns - corresponds to the offset of r30 in .got2, as given by LCTOC1. - See sysv4.h:toc_section. */ - return "bl %z0+32768@plt"; - else - return "bl %z0@plt"; + return rs6000_output_call (operands, 0, false, ""); } [(set_attr "type" "branch,branch") (set_attr "length" "4,8")]) @@ -10698,15 +10666,9 @@ (define_insn_and_split "*call_value_nonlocal_sysv" output_asm_insn ("creqv 6,6,6", operands); #if TARGET_MACHO - return output_call(insn, operands, 1, 3); + return macho_output_call(insn, operands, 1, 3); #else - if (DEFAULT_ABI == ABI_V4 && flag_pic) - { - gcc_assert (!TARGET_SECURE_PLT); - return "bl %z1@plt"; - } - else - return "bl %z1"; + return rs6000_output_call (operands, 1, false, ""); #endif } "DEFAULT_ABI == ABI_V4 @@ -10741,10 +10703,7 @@ (define_insn "*call_value_nonlocal_sysv_secure" else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (flag_pic == 2) - return "bl %z1+32768@plt"; - else - return "bl %z1@plt"; + return rs6000_output_call (operands, 1, false, ""); } [(set_attr "type" "branch,branch") (set_attr "length" "4,8")]) @@ -10777,7 +10736,9 @@ (define_insn "*call_nonlocal_aix" (match_operand 1 "" "g")) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2" - "bl %z0\;nop" +{ + return rs6000_output_call (operands, 0, false, ""); +} [(set_attr "type" "branch") (set_attr "length" "8")]) @@ -10787,7 +10748,9 @@ (define_insn "*call_value_nonlocal_aix" (match_operand 2 "" "g"))) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2" - "bl %z1\;nop" +{ + return rs6000_output_call (operands, 1, false, ""); +} [(set_attr "type" "branch") (set_attr "length" "8")]) @@ -11064,13 +11027,8 @@ (define_insn "*sibcall_nonlocal_sysv" /* Can use CR0 since it is volatile across sibcalls. */ return "crset 2\;beq%T0-\;b $"; } - else if (DEFAULT_ABI == ABI_V4 && flag_pic) - { - gcc_assert (!TARGET_SECURE_PLT); - return "b %z0@plt"; - } else - return "b %z0"; + return rs6000_output_call (operands, 0, true, ""); } [(set_attr "type" "branch") (set_attr_alternative "length" @@ -11109,13 +11067,8 @@ (define_insn "*sibcall_value_nonlocal_sysv" /* Can use CR0 since it is volatile across sibcalls. */ return "crset 2\;beq%T1-\;b $"; } - else if (DEFAULT_ABI == ABI_V4 && flag_pic) - { - gcc_assert (!TARGET_SECURE_PLT); - return "b %z1@plt"; - } else - return "b %z1"; + return rs6000_output_call (operands, 1, true, ""); } [(set_attr "type" "branch") (set_attr_alternative "length" @@ -11137,9 +11090,12 @@ (define_insn "*sibcall_aix" (match_operand 1 "" "g,g")) (simple_return)] "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2" - "@ - b %z0 - b%T0" +{ + if (which_alternative == 0) + return rs6000_output_call (operands, 0, true, ""); + else + return "b%T0"; +} [(set_attr "type" "branch")]) (define_insn "*sibcall_value_aix" @@ -11148,9 +11104,12 @@ (define_insn "*sibcall_value_aix" (match_operand 2 "" "g,g"))) (simple_return)] "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2" - "@ - b %z1 - b%T1" +{ + if (which_alternative == 0) + return rs6000_output_call (operands, 1, true, ""); + else + return "b%T1"; +} [(set_attr "type" "branch")]) (define_expand "sibcall_epilogue"