From patchwork Fri Aug 19 01:56:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp644772pxh; Thu, 18 Aug 2022 19:00:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7mkMQtnM7aFrWayDtM/eOFl4/FQ6KnlrNYxNn264XkXOjX0v4cJIKwjjbUpwKxrQwknVfn X-Received: by 2002:a17:906:b2d4:b0:731:4594:8ba1 with SMTP id cf20-20020a170906b2d400b0073145948ba1mr3487653ejb.288.1660874447615; Thu, 18 Aug 2022 19:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660874447; cv=none; d=google.com; s=arc-20160816; b=s7CChFCGudRZ5R+blus4fvllW7DKgCECkHYLLEhghhgSOaf8yvFPeWcIcJX9HBCq8K /y8A0UKwrAji6lS3aN4KMH9IR5LAOW5zSYaLCF4o1zgmPik449POvagiDIQBKv+JVsMd HrvdfuGFEe1gjNUjZaSwpkkEIEMam8XZEg59AOBzIx56mL/HLiw7GiH124n7LDGoDnbm NmFZkQSISJ4h7v0uvywINeSdAdny2lZQONfgXOhP8WSwrRrVFLakk3qirLB8ocD+kTKE Zy4wIL93IRXWgjjGmzRDQ7Hd3LYbOIL6pS8ZG75CcrvmOH9ZCRgXOTKnPrjRrzSmB6iT 7YqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dmarc-filter :delivered-to; bh=oX/DY4pHGURwUsOVs0/ma09CDe8LiUSH7tFkMlp/Cnc=; b=yRwsfN3QoPT9w1TJCSfIzDrgPFWZqBj6H60ZjZAhPYCIgvWYw4axUgf9K6pDE9mbGv c4gYV7E6AR64K1MTC8tahLJubhsXLbMvzfjVih02hFvGu1bxujbMk/Yu4jY+FepGMPrh HjmIlCcKbWml3Y2LEnr/W+PipXPqOm3Tr5+KEpZOinMWVj/j+4yvzImj5+07XADErkQz kR9GQ/IeiMR7hyaM7fNCiZnkFzwzpucGKgzTYsTg4y/mjlG6RMMfql5e6ASF6HJf1yBb BovOMgw1w9n/h+TceqphOKYgK6JT9WG8GnOq+SwbZXC1bw4FdgRTDEPtAlWwWy405VWx MyLQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h10-20020a05640250ca00b004461cf28d0dsi1902615edb.441.2022.08.18.19.00.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 19:00:47 -0700 (PDT) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FE853858016 for ; Fri, 19 Aug 2022 02:00:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 032953858D39 for ; Fri, 19 Aug 2022 02:00:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 032953858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_2uf7v5iIksEAA--.19368S2; Fri, 19 Aug 2022 10:00:05 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] LoongArch: Add support code model extreme. Date: Fri, 19 Aug 2022 09:56:25 +0800 Message-Id: <20220819015624.2449297-1-chenglulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_2uf7v5iIksEAA--.19368S2 X-Coremail-Antispam: 1UD129KBjvAXoWfWF1xGryDGFy7Ww4UtFW3GFg_yoW5AFyrto Z5AF4DJw48Wr1akwsrKrnxWw18Zr10yrWrAa9Fvr1rGF4Iyry5ZryxKw45ur9xJr97X345 uas7Za9rAasrJF98n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYe7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2 x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8 Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI 0_Cr1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm -wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr 0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbrMaUUUUUU== X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Cc: xuchenghua@loongson.cn, Lulu Cheng , i@xen0n.name 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?1741553084783361773?= X-GMAIL-MSGID: =?utf-8?q?1741553084783361773?= v1 -> v2: - Modify some description information. - Add options -W[no]extreme-plt, warn about code model extreme not support plt mode, and then disable plt. ------------------------------------------- Use five instructions to calculate a signed 64-bit offset relative to the pc. gcc/ChangeLog: * config/loongarch/genopts/loongarch.opt.in: Add new option W[no-]extreme-plt. * config/loongarch/loongarch.opt: Update file. * config/loongarch/loongarch-opts.cc: Allow cmodel to be extreme. * config/loongarch/loongarch.cc (loongarch_call_tls_get_addr): Add extreme support for TLS GD and LD types. (loongarch_legitimize_tls_address): Add extreme support for TLS LE and IE. (loongarch_split_symbol): When compiling with -mcmodel=extreme, the symbol address will be obtained through five instructions. (loongarch_print_operand_reloc): Add support. (loongarch_print_operand): Add support. (loongarch_print_operand_address): Add support. (loongarch_option_override_internal): Set '-mcmodel=extreme' option incompatible with '-mno-explicit-relocs'. * config/loongarch/loongarch.md (@lui_l_hi20): Loads bits 12-31 of data into registers. (lui_h_lo20): Load bits 32-51 of the data and spell bits 0-31 of the source register. (lui_h_hi12): Load bits 52-63 of the data and spell bits 0-51 of the source register. * config/loongarch/predicates.md: Symbols need to be decomposed when defining the macro TARGET_CMODEL_EXTREME * doc/invoke.texi: Modify the description information of cmodel in the document. Document -W[no-]extreme-plt. gcc/testsuite/ChangeLog: * gcc.target/loongarch/func-call-1.c: Add option '-mcmodel=normal'. * gcc.target/loongarch/func-call-2.c: Likewise. * gcc.target/loongarch/func-call-3.c: Likewise. * gcc.target/loongarch/func-call-4.c: Likewise. * gcc.target/loongarch/func-call-5.c: Likewise. * gcc.target/loongarch/func-call-6.c: Likewise. * gcc.target/loongarch/func-call-7.c: Likewise. * gcc.target/loongarch/func-call-8.c: Likewise. * gcc.target/loongarch/relocs-symbol-noaddend.c: Likewise. * gcc.target/loongarch/func-call-extreme-1.c: New test. * gcc.target/loongarch/func-call-extreme-2.c: New test. --- gcc/config/loongarch/genopts/loongarch.opt.in | 3 + gcc/config/loongarch/loongarch-opts.cc | 3 +- gcc/config/loongarch/loongarch.cc | 189 +++++++++++++++--- gcc/config/loongarch/loongarch.md | 34 +++- gcc/config/loongarch/loongarch.opt | 3 + gcc/config/loongarch/predicates.md | 9 +- gcc/doc/invoke.texi | 59 ++---- .../gcc.target/loongarch/func-call-1.c | 2 +- .../gcc.target/loongarch/func-call-2.c | 2 +- .../gcc.target/loongarch/func-call-3.c | 2 +- .../gcc.target/loongarch/func-call-4.c | 2 +- .../gcc.target/loongarch/func-call-5.c | 2 +- .../gcc.target/loongarch/func-call-6.c | 2 +- .../gcc.target/loongarch/func-call-7.c | 2 +- .../gcc.target/loongarch/func-call-8.c | 2 +- .../loongarch/func-call-extreme-1.c | 32 +++ .../loongarch/func-call-extreme-2.c | 32 +++ .../loongarch/relocs-symbol-noaddend.c | 2 +- 18 files changed, 303 insertions(+), 79 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index a571b6b7524..86fd80fc7a2 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -158,6 +158,9 @@ mexplicit-relocs Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) Use %reloc() assembly operators. +Wextreme-plt +Target Var(warn_extreme_plt) Init(1) Warning code model extreme not support plt mode. + ; The code model option names for -mcmodel. Enum Name(cmodel) Type(int) diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc index 3f70943ded6..2ae89f23443 100644 --- a/gcc/config/loongarch/loongarch-opts.cc +++ b/gcc/config/loongarch/loongarch-opts.cc @@ -376,14 +376,13 @@ fallback: /* 5. Target code model */ t.cmodel = constrained.cmodel ? opt_cmodel : CMODEL_NORMAL; - if (t.cmodel != CMODEL_NORMAL) + if (t.cmodel != CMODEL_NORMAL && t.cmodel != CMODEL_EXTREME) { warning (0, "%qs is not supported, now cmodel is set to %qs", loongarch_cmodel_strings[t.cmodel], "normal"); t.cmodel = CMODEL_NORMAL; } - /* Cleanup and return. */ obstack_free (&msg_obstack, NULL); *target = t; diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 24378143641..114ff8ec836 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -2436,7 +2436,17 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) /* Split tls symbol to high and low. */ rtx high = gen_rtx_HIGH (Pmode, copy_rtx (loc)); high = loongarch_force_temporary (tmp, high); - emit_insn (gen_tls_low (Pmode, a0, high, loc)); + + if (TARGET_CMODEL_EXTREME) + { + rtx tmp1 = gen_reg_rtx (Pmode); + emit_insn (gen_tls_low (Pmode, tmp1, gen_rtx_REG (Pmode, 0), loc)); + emit_insn (gen_lui_h_lo20 (tmp1, tmp1, loc)); + emit_insn (gen_lui_h_hi12 (tmp1, tmp1, loc)); + emit_move_insn (a0, gen_rtx_PLUS (Pmode, high, tmp1)); + } + else + emit_insn (gen_tls_low (Pmode, a0, high, loc)); } else { @@ -2456,7 +2466,21 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) rtx dest = gen_reg_rtx (Pmode); rtx high = gen_reg_rtx (Pmode); loongarch_emit_move (high, gen_rtx_HIGH (Pmode, loongarch_tls_symbol)); - emit_insn (gen_ld_from_got (Pmode, dest, high, loongarch_tls_symbol)); + + if (TARGET_CMODEL_EXTREME) + { + rtx tmp1 = gen_reg_rtx (Pmode); + loongarch_emit_move (tmp1, gen_rtx_LO_SUM (Pmode, + gen_rtx_REG (Pmode, 0), + loongarch_tls_symbol)); + emit_insn (gen_lui_h_lo20 (tmp1, tmp1, loongarch_tls_symbol)); + emit_insn (gen_lui_h_hi12 (tmp1, tmp1, loongarch_tls_symbol)); + loongarch_emit_move (dest, + gen_rtx_MEM (Pmode, + gen_rtx_PLUS (Pmode, high, tmp1))); + } + else + emit_insn (gen_ld_from_got (Pmode, dest, high, loongarch_tls_symbol)); insn = emit_call_insn (gen_call_value_internal (v0, dest, const0_rtx)); } @@ -2508,7 +2532,21 @@ loongarch_legitimize_tls_address (rtx loc) tmp3 = gen_reg_rtx (Pmode); rtx high = gen_rtx_HIGH (Pmode, copy_rtx (tmp2)); high = loongarch_force_temporary (tmp3, high); - emit_insn (gen_ld_from_got (Pmode, tmp1, high, tmp2)); + + if (TARGET_CMODEL_EXTREME) + { + rtx tmp3 = gen_reg_rtx (Pmode); + emit_insn (gen_tls_low (Pmode, tmp3, + gen_rtx_REG (Pmode, 0), tmp2)); + emit_insn (gen_lui_h_lo20 (tmp3, tmp3, tmp2)); + emit_insn (gen_lui_h_hi12 (tmp3, tmp3, tmp2)); + emit_move_insn (tmp1, + gen_rtx_MEM (Pmode, + gen_rtx_PLUS (Pmode, + high, tmp3))); + } + else + emit_insn (gen_ld_from_got (Pmode, tmp1, high, tmp2)); } else emit_insn (loongarch_got_load_tls_ie (tmp1, loc)); @@ -2530,11 +2568,16 @@ loongarch_legitimize_tls_address (rtx loc) rtx high = gen_rtx_HIGH (Pmode, copy_rtx (tmp2)); high = loongarch_force_temporary (tmp3, high); emit_insn (gen_ori_l_lo12 (Pmode, tmp1, high, tmp2)); + + if (TARGET_CMODEL_EXTREME) + { + emit_insn (gen_lui_h_lo20 (tmp1, tmp1, tmp2)); + emit_insn (gen_lui_h_hi12 (tmp1, tmp1, tmp2)); + } } else emit_insn (loongarch_got_load_tls_le (tmp1, loc)); emit_insn (gen_add3_insn (dest, tmp1, tp)); - } break; @@ -2603,7 +2646,6 @@ bool loongarch_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) { enum loongarch_symbol_type symbol_type; - rtx high; /* If build with '-mno-explicit-relocs', don't split symbol. */ if (!TARGET_EXPLICIT_RELOCS) @@ -2615,6 +2657,8 @@ loongarch_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) || !loongarch_split_symbol_type (symbol_type)) return false; + rtx high, temp1 = NULL; + if (temp == NULL) temp = gen_reg_rtx (Pmode); @@ -2622,20 +2666,40 @@ loongarch_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) high = gen_rtx_HIGH (Pmode, copy_rtx (addr)); high = loongarch_force_temporary (temp, high); + if (TARGET_CMODEL_EXTREME && can_create_pseudo_p ()) + { + temp1 = gen_reg_rtx (Pmode); + emit_move_insn (temp1, gen_rtx_LO_SUM (Pmode, gen_rtx_REG (Pmode, 0), + addr)); + emit_insn (gen_lui_h_lo20 (temp1, temp1, addr)); + emit_insn (gen_lui_h_hi12 (temp1, temp1, addr)); + } + if (low_out) switch (symbol_type) { case SYMBOL_PCREL: - *low_out = gen_rtx_LO_SUM (Pmode, high, addr); - break; + { + if (TARGET_CMODEL_EXTREME && can_create_pseudo_p ()) + *low_out = gen_rtx_PLUS (Pmode, high, temp1); + else + *low_out = gen_rtx_LO_SUM (Pmode, high, addr); + break; + } case SYMBOL_GOT_DISP: /* SYMBOL_GOT_DISP symbols are loaded from the GOT. */ { - rtx low = gen_rtx_LO_SUM (Pmode, high, addr); - rtx mem = gen_rtx_MEM (Pmode, low); - *low_out = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, mem), - UNSPEC_LOAD_FROM_GOT); + if (TARGET_CMODEL_EXTREME && can_create_pseudo_p ()) + *low_out = gen_rtx_MEM (Pmode, gen_rtx_PLUS (Pmode, high, temp1)); + else + { + rtx low = gen_rtx_LO_SUM (Pmode, high, addr); + rtx mem = gen_rtx_MEM (Pmode, low); + *low_out = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, mem), + UNSPEC_LOAD_FROM_GOT); + } + break; } @@ -4584,34 +4648,83 @@ loongarch_memmodel_needs_release_fence (enum memmodel model) in context CONTEXT. HI_RELOC indicates a high-part reloc. */ static void -loongarch_print_operand_reloc (FILE *file, rtx op, bool hi_reloc) +loongarch_print_operand_reloc (FILE *file, rtx op, bool hi64_part, + bool hi_reloc) { const char *reloc; switch (loongarch_classify_symbolic_expression (op)) { case SYMBOL_PCREL: - reloc = hi_reloc ? "%pc_hi20" : "%pc_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%pc64_hi12" : "%pc64_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%pc_hi20" : "%pc_lo12"; break; case SYMBOL_GOT_DISP: - reloc = hi_reloc ? "%got_pc_hi20" : "%got_pc_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%got64_pc_hi12" : "%got64_pc_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%got_pc_hi20" : "%got_pc_lo12"; break; case SYMBOL_TLS_IE: - reloc = hi_reloc ? "%ie_pc_hi20" : "%ie_pc_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%ie64_pc_hi12" : "%ie64_pc_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%ie_pc_hi20" : "%ie_pc_lo12"; break; case SYMBOL_TLS_LE: - reloc = hi_reloc ? "%le_hi20" : "%le_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%le64_hi12" : "%le64_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%le_hi20" : "%le_lo12"; break; case SYMBOL_TLSGD: - reloc = hi_reloc ? "%gd_pc_hi20" : "%got_pc_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%got64_pc_hi12" : "%got64_pc_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%gd_pc_hi20" : "%got_pc_lo12"; break; case SYMBOL_TLSLDM: - reloc = hi_reloc ? "%ld_pc_hi20" : "%got_pc_lo12"; + if (hi64_part) + { + if (TARGET_CMODEL_EXTREME) + reloc = hi_reloc ? "%got64_pc_hi12" : "%got64_pc_lo20"; + else + gcc_unreachable (); + } + else + reloc = hi_reloc ? "%ld_pc_hi20" : "%got_pc_lo12"; break; default: @@ -4637,6 +4750,8 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool hi_reloc) 'L' Print the low-part relocation associated with OP. 'm' Print one less than CONST_INT OP in decimal. 'N' Print the inverse of the integer branch condition for comparison OP. + 'r' Print address 12-31bit relocation associated with OP. + 'R' Print address 32-51bit relocation associated with OP. 'T' Print 'f' for (eq:CC ...), 't' for (ne:CC ...), 'z' for (eq:?I ...), 'n' for (ne:?I ...). 't' Like 'T', but with the EQ/NE cases reversed @@ -4694,7 +4809,13 @@ loongarch_print_operand (FILE *file, rtx op, int letter) case 'h': if (code == HIGH) op = XEXP (op, 0); - loongarch_print_operand_reloc (file, op, true /* hi_reloc */); + loongarch_print_operand_reloc (file, op, false /* hi64_part */, + true /* hi_reloc */); + break; + + case 'H': + loongarch_print_operand_reloc (file, op, true /* hi64_part */, + true /* hi_reloc */); break; case 'i': @@ -4703,7 +4824,8 @@ loongarch_print_operand (FILE *file, rtx op, int letter) break; case 'L': - loongarch_print_operand_reloc (file, op, false /* lo_reloc */); + loongarch_print_operand_reloc (file, op, false /* hi64_part*/, + false /* lo_reloc */); break; case 'm': @@ -4718,6 +4840,16 @@ loongarch_print_operand (FILE *file, rtx op, int letter) letter); break; + case 'r': + loongarch_print_operand_reloc (file, op, false /* hi64_part */, + true /* lo_reloc */); + break; + + case 'R': + loongarch_print_operand_reloc (file, op, true /* hi64_part */, + false /* lo_reloc */); + break; + case 't': case 'T': { @@ -4848,7 +4980,8 @@ loongarch_print_operand_address (FILE *file, machine_mode /* mode */, rtx x) case ADDRESS_LO_SUM: fprintf (file, "%s,", reg_names[REGNO (addr.reg)]); - loongarch_print_operand_reloc (file, addr.offset, false /* hi_reloc */); + loongarch_print_operand_reloc (file, addr.offset, false /* hi64_part */, + false /* hi_reloc */); return; case ADDRESS_CONST_INT: @@ -5821,13 +5954,21 @@ loongarch_option_override_internal (struct gcc_options *opts) switch (la_target.cmodel) { - case CMODEL_TINY_STATIC: case CMODEL_EXTREME: + if (!TARGET_EXPLICIT_RELOCS) + error ("code model %qs needs %s", + "extreme", "-mexplicit-relocs"); + if (opts->x_flag_plt) - error ("code model %qs and %qs not support %s mode", - "tiny-static", "extreme", "plt"); + { + warning (OPT_Wextreme_plt, "code model %qs not support %s mode," + "now set to %s", + "extreme", "plt", "noplt"); + opts->x_flag_plt = 0; + } break; + case CMODEL_TINY_STATIC: case CMODEL_NORMAL: case CMODEL_TINY: case CMODEL_LARGE: diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 8e8868de9f5..8fc10444c2a 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -60,6 +60,9 @@ (define_c_enum "unspec" [ UNSPEC_LOAD_FROM_GOT UNSPEC_ORI_L_LO12 + UNSPEC_LUI_L_HI20 + UNSPEC_LUI_H_LO20 + UNSPEC_LUI_H_HI12 UNSPEC_TLS_LOW ]) @@ -1934,16 +1937,45 @@ (define_insn "@ld_from_got" [(set_attr "type" "move")] ) +(define_insn "@lui_l_hi20" + [(set (match_operand:P 0 "register_operand" "=r") + (unspec:P [(match_operand:P 1 "symbolic_operand")] + UNSPEC_LUI_L_HI20))] + "" + "lu12i.w\t%0,%r1" + [(set_attr "type" "move")] +) + (define_insn "@ori_l_lo12" [(set (match_operand:P 0 "register_operand" "=r") (unspec:P [(match_operand:P 1 "register_operand" "r") - (match_operand:P 2 "symbolic_operand")] + (match_operand:P 2 "symbolic_operand")] UNSPEC_ORI_L_LO12))] "" "ori\t%0,%1,%L2" [(set_attr "type" "move")] ) +(define_insn "lui_h_lo20" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "0") + (match_operand:DI 2 "symbolic_operand")] + UNSPEC_LUI_H_LO20))] + "TARGET_64BIT" + "lu32i.d\t%0,%R2" + [(set_attr "type" "move")] +) + +(define_insn "lui_h_hi12" + [(set (match_operand:DI 0 "register_operand" "=r") + (unspec:DI [(match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "symbolic_operand")] + UNSPEC_LUI_H_HI12))] + "TARGET_64BIT" + "lu52i.d\t%0,%1,%H2" + [(set_attr "type" "move")] +) + ;; Convert floating-point numbers to integers (define_insn "frint_" [(set (match_operand:ANYF 0 "register_operand" "=f") diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt index 9df7e187283..1759b783db9 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -165,6 +165,9 @@ mexplicit-relocs Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) Use %reloc() assembly operators. +Wextreme-plt +Target Var(warn_extreme_plt) Init(1) Warning code model extreme not support plt mode. + ; The code model option names for -mcmodel. Enum Name(cmodel) Type(int) diff --git a/gcc/config/loongarch/predicates.md b/gcc/config/loongarch/predicates.md index cd3528c7c97..e38c6fbdd5f 100644 --- a/gcc/config/loongarch/predicates.md +++ b/gcc/config/loongarch/predicates.md @@ -111,7 +111,7 @@ (define_predicate "const_call_insn_operand" (match_code "const,symbol_ref,label_ref") { /* Split symbol to high and low if return false. - If defined TARGET_CMODEL_LARGE, all symbol would be splited, + If defined TARGET_CMODEL_EXTREME, all symbol would be splited, else if offset is not zero, the symbol would be splited. */ enum loongarch_symbol_type symbol_type; @@ -126,10 +126,13 @@ (define_predicate "const_call_insn_operand" switch (symbol_type) { case SYMBOL_PCREL: - return 1; + if (TARGET_CMODEL_EXTREME) + return false; + else + return 1; case SYMBOL_GOT_DISP: - if (TARGET_CMODEL_LARGE || !flag_plt) + if (TARGET_CMODEL_EXTREME || !flag_plt) return false; else return 1; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1ac81ad0bb4..ab7aa25973d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1020,6 +1020,8 @@ Objective-C and Objective-C++ Dialects}. -mcond-move-float -mno-cond-move-float @gol -memcpy -mno-memcpy -mstrict-align -mno-strict-align @gol -mmax-inline-memcpy-size=@var{n} @gol +-mexplicit-relocs -mno-explicit-relocs @gol +-Wextreme-plt -Wno-extreme-plt @gol -mcmodel=@var{code-model}} @emph{M32R/D Options} @@ -25076,50 +25078,19 @@ less than or equal to @var{n} bytes. The default value of @var{n} is 1024. @item -mcmodel=@var{code-model} Set the code model to one of: @table @samp -@item tiny-static -@itemize @bullet -@item -local symbol and global strong symbol: The data section must be within +/-2MiB addressing space. -The text section must be within +/-128MiB addressing space. -@item -global weak symbol: The got table must be within +/-2GiB addressing space. -@end itemize - -@item tiny -@itemize @bullet -@item -local symbol: The data section must be within +/-2MiB addressing space. -The text section must be within +/-128MiB -addressing space. -@item -global symbol: The got table must be within +/-2GiB addressing space. -@end itemize +@item tiny-static (Not implemented yet) +@item tiny (Not implemented yet) @item normal -@itemize @bullet -@item -local symbol: The data section must be within +/-2GiB addressing space. -The text section must be within +/-128MiB addressing space. -@item -global symbol: The got table must be within +/-2GiB addressing space. -@end itemize +The text segment must be within 128MB addressing space. The data segment must +be within 2GB addressing space. -@item large -@itemize @bullet -@item -local symbol: The data section must be within +/-2GiB addressing space. -The text section must be within +/-128GiB addressing space. -@item -global symbol: The got table must be within +/-2GiB addressing space. -@end itemize +@item large (Not implemented yet) -@item extreme(Not implemented yet) -@itemize @bullet -@item -local symbol: The data and text section must be within +/-8EiB addressing space. -@item -global symbol: The data got table must be within +/-8EiB addressing space. -@end itemize +@item extreme +This mode does not limit the size of the code segment and data segment. +The @option{-mcmodel=extreme} option is incompatible with @option{-fplt} and +@option{-mno-explicit-relocs}. @end table The default code model is @code{normal}. @@ -25135,6 +25106,14 @@ GCC build-time by detecting corresponding assembler support: @code{-mno-explicit-relocs} otherwise. This option is mostly useful for debugging, or interoperation with assemblers different from the build-time one. + +@item -Wextreme-plt +@opindex Wextreme-plt +Warn about code model extreme not support plt mode, and then disable plt. +@item -mno-extreme-plt +@opindex Wno-extreme-plt +Disable @option{-Wextreme-plt} warnings. +This warning is enabled by default. @end table @node M32C Options diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-1.c b/gcc/testsuite/gcc.target/loongarch/func-call-1.c index 01b8ea23fb9..76bf11b0c03 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-1.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fpic -fplt -mno-explicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fplt -mno-explicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*bl\t%plt\\(g\\)\n" } } */ /* { dg-final { scan-assembler "test1:.*bl\t%plt\\(f\\)\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-2.c b/gcc/testsuite/gcc.target/loongarch/func-call-2.c index 4565baaec9e..4b468fef8b4 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-2.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fno-pic -fplt -mno-explicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fplt -mno-explicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*bl\t%plt\\(g\\)\n" } } */ /* { dg-final { scan-assembler "test1:.*bl\tf\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-3.c b/gcc/testsuite/gcc.target/loongarch/func-call-3.c index 4f669a029e7..dd3a4882d60 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-3.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mno-explicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mno-explicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*la\.global\t.*g\n\tjirl" } } */ /* { dg-final { scan-assembler "test1:.*la\.global\t.*f\n\tjirl" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-4.c b/gcc/testsuite/gcc.target/loongarch/func-call-4.c index 943adb6403f..f8158ec349f 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-4.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mno-explicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mno-explicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*la\.global\t.*g\n\tjirl" } } */ /* { dg-final { scan-assembler "test1:.*bl\tf\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-5.c b/gcc/testsuite/gcc.target/loongarch/func-call-5.c index 2c2a1c8a1b6..37994af430d 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-5.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-5.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fpic -fplt -mexplicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fplt -mexplicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*bl\t%plt\\(g\\)\n" } } */ /* { dg-final { scan-assembler "test1:.*bl\t%plt\\(f\\)\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-6.c b/gcc/testsuite/gcc.target/loongarch/func-call-6.c index 4b0e4266ec8..8e366e376e7 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-6.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-6.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fno-pic -fplt -mexplicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fplt -mexplicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*bl\t%plt\\(g\\)\n" } } */ /* { dg-final { scan-assembler "test1:.*bl\tf\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-7.c b/gcc/testsuite/gcc.target/loongarch/func-call-7.c index 51792711f72..4177c3d962e 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-7.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-7.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*pcalau12i\t.*%got_pc_hi20\\(g\\)\n\tld\.d\t.*%got_pc_lo12\\(g\\)\n\tjirl" } } */ /* { dg-final { scan-assembler "test1:.*pcalau12i\t.*%got_pc_hi20\\(f\\)\n\tld\.d\t.*%got_pc_lo12\\(f\\)\n\tjirl" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-8.c b/gcc/testsuite/gcc.target/loongarch/func-call-8.c index 330140d883d..4254eaa16d4 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-8.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-8.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs" } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs -mcmodel=normal" } */ /* { dg-final { scan-assembler "test:.*pcalau12i\t.*%got_pc_hi20\\(g\\)\n\tld\.d\t.*%got_pc_lo12\\(g\\)\n\tjirl" } } */ /* { dg-final { scan-assembler "test1:.*bl\tf\n" } } */ /* { dg-final { scan-assembler "test2:.*bl\tl\n" } } */ diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c new file mode 100644 index 00000000000..db1e0f85396 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test1:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ + +extern void g (void); +void +f (void) +{} + +static void +l (void) +{} + +void +test (void) +{ + g (); +} + +void +test1 (void) +{ + f (); +} + +void +test2 (void) +{ + l (); +} diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c new file mode 100644 index 00000000000..21bf81ae837 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test1:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ + +extern void g (void); +void +f (void) +{} + +static void +l (void) +{} + +void +test (void) +{ + g (); +} + +void +test1 (void) +{ + f (); +} + +void +test2 (void) +{ + l (); +} diff --git a/gcc/testsuite/gcc.target/loongarch/relocs-symbol-noaddend.c b/gcc/testsuite/gcc.target/loongarch/relocs-symbol-noaddend.c index bfcc9bc338f..3ec8bd229fd 100644 --- a/gcc/testsuite/gcc.target/loongarch/relocs-symbol-noaddend.c +++ b/gcc/testsuite/gcc.target/loongarch/relocs-symbol-noaddend.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mabi=lp64d -mexplicit-relocs -fno-pic -O2" } */ +/* { dg-options "-mabi=lp64d -mexplicit-relocs -fno-pic -O2 -mcmodel=normal" } */ /* { dg-final { scan-assembler "pcalau12i.*%pc_hi20\\(\.LANCHOR0\\)\n" } } */ /* { dg-final { scan-assembler "addi\.d.*%pc_lo12\\(\.LANCHOR0\\)\n" } } */ /* { dg-final { scan-assembler "ldptr.d\t\\\$r4,.*,0\n" } } */