From patchwork Tue Oct 24 06:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenxiaolong X-Patchwork-Id: 157255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1754087vqx; Mon, 23 Oct 2023 23:41:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHP7EosA4iGZUmDkxZi+8gIUjbGTh0zebCAB+aj4tCW4FiY5dxQk2e3pFHDlDBmz0Erjns5 X-Received: by 2002:ad4:5b8b:0:b0:66d:4df1:cb0b with SMTP id 11-20020ad45b8b000000b0066d4df1cb0bmr13529705qvp.50.1698129672281; Mon, 23 Oct 2023 23:41:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698129672; cv=pass; d=google.com; s=arc-20160816; b=bg1eHUtwTIPXiRS9q9YDmkbeq4W60TS5rCXJVMzjgxYLb8Uw0ixETqI6QavoK4qRRN QCBjxxspHSy05vHzEGWX/gFrjDv5HmgDokc8oGJTqgf94VeSnr0S6OHKxONrOhfbAMst CfN+WLlOtXN1J+le618Egg3JGuFvAIcHtFUCbvUqE7+GgeqpLvGwVMpDmoSd8W0MA7TS fOxgXywZmXigcN0hB043UPskRwVQELvEy0uXfxJ8be9MuYUx1iozzFBmLli97Cfne74n MJGmyyUpMrfmsmjL0lxzZleMdjZCxBqZkWcXlqMFRKdjA+nmrTVxrTJOKumokx3AnefL R8aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=3KACyOLN0uxJm1QSduwka2Y9P4oEFP0773UpsqAWaWI=; fh=FZUwle8+72fCZy+/zioADwckSVaPYtJTkTncWlIM74g=; b=NIbX+MYSzFpS6wgPbVAaFx5jX03FHnawAMPl3qozFE4p75ZeP/6IyOIY9Xg8aFdqs3 Pmm9gTzI4dyPgYgM2vYEA2XQ+uIy48jJCD6QHals2WfY8UPtjShOfCktHbG+2jszUi5Y df4tLsma5Fl9YPYew9+JtXkcIbrfdnCDh6EF87Lxfh1OO5bStw2zy714gKrUSaAXmvjK TZGjUWHD0FTQ/+JItoY2MwZbgrDNiQVQaHKixhzUDUbwxqTsYlZruYq/TeQCIZz8/vss Re6rV3xgdGmH4nlUH7yAfYSOhPan6Fr9QwpDWmcUGwR5Af/zZ1xjqXojhgfQM6mmo70C fn/g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c9-20020a0cd609000000b0066d0a9f4d0fsi6514201qvj.527.2023.10.23.23.41.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:41:12 -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; arc=pass (i=1); 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 119623857353 for ; Tue, 24 Oct 2023 06:41:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 518583858D39 for ; Tue, 24 Oct 2023 06:40:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 518583858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 518583858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698129648; cv=none; b=iz+59qM0+k7sHWBxMHu+FIUDXfqVk36hsbht9uXZQa79nOe0YiMaViIP477BTiiF0D/CU5t5rp/5ERUGqS0xM3FGFX3d2Q+64TAQM96eOg5qGDQSkPViAZJzRAB8p/Hdj/OGLNohhOBpTUO7eSdec2aC9JHpPFnjYhj5GWi4lQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698129648; c=relaxed/simple; bh=Et2oXQCq46YqFnz+qnOd0Qe7KOjyfPdVfQoTUWRGNTo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=wj7VmsaCjrMT8uRcXStF8IrDVJaVPyM6rxUNI2YfCGlhSD4mNVFYWd5X6TImKewKyXSgfBInywouwioVGef/N3W4rl8BGT4D55GyEj/GlDGIoYDjGX6LtVhO7RMJpxhrfc56fycWLqKgmOHyyZlP3y0cVr7hIUUKnUIaSvrn7hg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvB5l-0006CH-PB for gcc-patches@gcc.gnu.org; Tue, 24 Oct 2023 02:40:45 -0400 Received: from loongson.cn (unknown [10.10.130.252]) by gateway (Coremail) with SMTP id _____8DxPOvUZjdlQCY0AA--.30422S3; Tue, 24 Oct 2023 14:40:20 +0800 (CST) Received: from slurm-master.loongson.cn (unknown [10.10.130.252]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxvi_SZjdl52YwAA--.37283S4; Tue, 24 Oct 2023 14:40:18 +0800 (CST) From: chenxiaolong To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn, chenxiaolong Subject: [PATCH v1] LoongArch: Implement __builtin_thread_pointer for TLS. Date: Tue, 24 Oct 2023 14:40:14 +0800 Message-Id: <20231024064014.18734-1-chenxiaolong@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxvi_SZjdl52YwAA--.37283S4 X-CM-SenderInfo: hfkh05xldrz0tqj6z05rqj20fqof0/1tbiAQANBWU0hqYCAgACs6 X-Coremail-Antispam: 1Uk129KBj93XoWxZF1kZw1DCr1UGr4xGw1xZwc_yoW5Gr1Upa y7CryIqr48XF9rGr1ftay3Zr15CF17Way7ua43G340kw1jqry2qF95try7XF15Ja1rXryS vw4Fgw42ga1jyabCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j8yCJUUUUU= Received-SPF: pass client-ip=114.242.206.163; envelope-from=chenxiaolong@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_FAIL, SPF_HELO_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780618019356370049 X-GMAIL-MSGID: 1780618019356370049 gcc/ChangeLog: * config/loongarch/loongarch.md (get_thread_pointer):Adds the instruction template corresponding to the __builtin_thread_pointer function. * doc/extend.texi:Add the __builtin_thread_pointer function support description to the documentation. gcc/testsuite/ChangeLog: * gcc.target/loongarch/builtin_thread_pointer.c: New test. --- gcc/config/loongarch/loongarch.md | 7 +++++++ gcc/doc/extend.texi | 5 +++++ .../gcc.target/loongarch/builtin_thread_pointer.c | 10 ++++++++++ 3 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 13473472171..4dd716e1941 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -113,6 +113,7 @@ (define_c_enum "unspecv" [ (define_constants [(RETURN_ADDR_REGNUM 1) + (TP_REGNUM 2) (T0_REGNUM 12) (T1_REGNUM 13) (S0_REGNUM 23) @@ -3647,6 +3648,12 @@ (define_insn "@stack_tie" [(set_attr "length" "0") (set_attr "type" "ghost")]) +;; Named pattern for expanding thread pointer reference. +(define_expand "get_thread_pointer" + [(set (match_operand:P 0 "register_operand" "=r") + (reg:P TP_REGNUM))] + "HAVE_AS_TLS" + {}) (define_split [(match_operand 0 "small_data_pattern")] diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index bf941e6b93a..9923a18bde9 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -16749,6 +16749,11 @@ __float128 __builtin_nanq (void); __float128 __builtin_nansq (void); @end smallexample +Returns the value that is currently set in the @samp{tp} register. +@smallexample + void * __builtin_thread_pointer (void) +@end smallexample + @node MIPS DSP Built-in Functions @subsection MIPS DSP Built-in Functions diff --git a/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c new file mode 100644 index 00000000000..541e3b143bd --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target tls_native } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler "or\t\\\$r4,\\\$r2,\\\$r0" } } */ + +void * +get_tp () +{ + return __builtin_thread_pointer (); +}