From patchwork Tue Oct 11 06:15:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 1901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1936259wrs; Mon, 10 Oct 2022 23:16:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nNSLXy2KkVU8yFpwqVnxzDbgzeApiAato8EQ9vw41u1wYWEy0EQIqNHZ60UuzkZN3GRDg X-Received: by 2002:a17:907:1c0b:b0:788:4c5:32d7 with SMTP id nc11-20020a1709071c0b00b0078804c532d7mr17372968ejc.223.1665468961261; Mon, 10 Oct 2022 23:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665468961; cv=none; d=google.com; s=arc-20160816; b=cF8akrIfjzbFdmfn6wI0kZWqdO02ILCpsVhF2UEvNzwJZrVE8VYgyMiTmYfoDQ7Tbs u3La6bWXVpoQneBDhmC3GcXvHyJG8ksvZRJu5cF2oroDIzDYuuqgDkwLtOoau9GodNUf tH58lID/DoC3AC2O6StSXHJwPK/RFPJh8cacaL51b21YYXE3zdr4a4JXqyNAbqod6DUc 4Y2hyDZosyuPU0J/jAqRiPQL1DqeRhNToGF8PD0kAqQ+zhgjYnj6vz90JnacFg8Zba3p eDpH13fBYHiW2vN5Tbmi5anFROLEQLtXQlZfRwKadbHeU5LHr1HmeauZY2b4U+DViZ+I Lalw== 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:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:to :from:dmarc-filter:delivered-to; bh=27v8hodEj+baLzwuR4dVytm9ZQvsxlzzGi1AknHgQes=; b=qVVjqKjUQOXZeOskmMqIO8Hm8FVmscgmrjkYLlFpRG0Vcl/3MZybZiQHXemzAhyyxK iFkrPPE4ChuHFO9/9btSTW3uk29uNLqrkM0NALQKu2V9EybcBMAh3uTqYLD9jhyIjbll zNCOG8fcDsBHnJRrlw74Wkxh2+ZNSLdb4FFzrYDXNNWsJwcFeM13alP0QktgXhplEEe7 8sIokJPl0zT7wJzA/JoAhTmab8grgoDAhZ8FokKrnsOrvlUqvJkaTX5m1B0gh/qJG+lb OWrU5KaCAc/rOQpnOGzKzoHIUMOI76jBcYa34i3bDIEkSd0fo/C2w9U2PgzeFwl1u+fh CK4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i5-20020a05640242c500b00457dfaa5d16si14306191edc.351.2022.10.10.23.16.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 23:16:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 80ACB385737C for ; Tue, 11 Oct 2022 06:15:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by sourceware.org (Postfix) with ESMTPS id 500603858437 for ; Tue, 11 Oct 2022 06:15:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 500603858437 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp79t1665468925tu2fgg9o Received: from server1.localdomain ( [42.247.22.65]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 11 Oct 2022 14:15:24 +0800 (CST) X-QQ-SSF: 01400000000000D0J000000A0000000 X-QQ-FEAT: o9GPlAUOZ4fXgEXwzyi4RmF8Lsli4DbIf76ZiREPBcmwhFYE3vwMJepC5F3Ge FuUGTSVrJH3OWvBs4wcCdKYW349iFwIPleemplQ6/jheUoYRJWkqzWc3qHFwpFcU8knw8oL k2IIz11uPxdbdF6HaNQTpRfZrhDga/wDW4i+AvX0SPZStlVndTnHPVBaeZSTiUNml9ILoqM 61B6H7Qr0TnELptOezqh2LrRRJGsUppXjWaEbKs95J43h9IGySMgobsa/iMNk5G8HsPNxtn SYJVMVWi0CQ0qC694Q6h+aiI9cGF35NUcqgbUhSVJHgmidgGEP39WfhomqL8dGuE6I9YmE+ AMX0bbb2Q+wibZuk5bMFm85vt2eqOzSfBsh/QfLeQ2nBAos8XJcSjvRXCMMWdaBS4glsRU1 X-QQ-GoodBg: 2 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Refine register_builtin_types function. Date: Tue, 11 Oct 2022 14:15:21 +0800 Message-Id: <20221011061521.65729-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kito.cheng@gmail.com, Ju-Zhe Zhong 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?1746370781217073723?= X-GMAIL-MSGID: =?utf-8?q?1746370781217073723?= From: Ju-Zhe Zhong gcc/ChangeLog: * config/riscv/riscv-vector-builtins.cc (GTY): Redefine vector types. (build_const_pointer): New function. (register_builtin_type): Ditto. (DEF_RVV_TYPE): Simplify macro. (register_vector_type): Refine implementation. * config/riscv/riscv-vector-builtins.h (struct GTY): New struct. --- gcc/config/riscv/riscv-vector-builtins.cc | 81 ++++++++++++----------- gcc/config/riscv/riscv-vector-builtins.h | 10 +++ 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc index 6fd1bb0fcb2..daf180801cc 100644 --- a/gcc/config/riscv/riscv-vector-builtins.cc +++ b/gcc/config/riscv/riscv-vector-builtins.cc @@ -73,18 +73,14 @@ static CONSTEXPR const vector_type_info vector_types[] = { #include "riscv-vector-builtins.def" }; -/* The scalar type associated with each vector type. */ -static GTY (()) tree scalar_types[NUM_VECTOR_TYPES]; -/* The machine mode associated with each vector type. */ -static GTY (()) machine_mode vector_modes[NUM_VECTOR_TYPES]; /* The RVV types, with their built-in "__rvv..._t" name. Allow an index of NUM_VECTOR_TYPES, which always yields a null tree. */ static GTY(()) tree abi_vector_types[NUM_VECTOR_TYPES + 1]; /* Same, but with the riscv_vector.h "v..._t" name. */ -extern GTY(()) tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1]; -tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1]; +extern GTY (()) rvv_builtin_types_t builtin_types[NUM_VECTOR_TYPES + 1]; +rvv_builtin_types_t builtin_types[NUM_VECTOR_TYPES + 1]; /* Add type attributes to builtin type tree, currently only the mangled name. */ static void @@ -123,6 +119,39 @@ lookup_vector_type_attribute (const_tree type) return lookup_attribute ("RVV type", TYPE_ATTRIBUTES (type)); } +/* Return a representation of "const T *". */ +static tree +build_const_pointer (tree t) +{ + return build_pointer_type (build_qualified_type (t, TYPE_QUAL_CONST)); +} + +/* Helper function for register a single built-in RVV ABI type. */ +static void +register_builtin_type (vector_type_index type, tree eltype, machine_mode mode) +{ + builtin_types[type].scalar = eltype; + builtin_types[type].scalar_ptr = build_pointer_type (eltype); + builtin_types[type].scalar_const_ptr = build_const_pointer (eltype); + if (!riscv_v_ext_enabled_vector_mode_p (mode)) + return; + + tree vectype = build_vector_type_for_mode (eltype, mode); + gcc_assert (VECTOR_MODE_P (TYPE_MODE (vectype)) && TYPE_MODE (vectype) == mode + && TYPE_MODE_RAW (vectype) == mode && TYPE_ALIGN (vectype) <= 128 + && known_eq (tree_to_poly_uint64 (TYPE_SIZE (vectype)), + GET_MODE_BITSIZE (mode))); + vectype = build_distinct_type_copy (vectype); + gcc_assert (vectype == TYPE_MAIN_VARIANT (vectype)); + SET_TYPE_STRUCTURAL_EQUALITY (vectype); + TYPE_ARTIFICIAL (vectype) = 1; + TYPE_INDIVISIBLE_P (vectype) = 1; + add_vector_type_attribute (vectype, vector_types[type].mangled_name); + make_type_sizeless (vectype); + abi_vector_types[type] = vectype; + lang_hooks.types.register_builtin_type (vectype, vector_types[type].abi_name); +} + /* Register the built-in RVV ABI types, such as __rvv_int32m1_t. */ static void register_builtin_types () @@ -137,42 +166,12 @@ register_builtin_types () = TARGET_64BIT ? unsigned_intSI_type_node : long_unsigned_type_node; machine_mode mode; -#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE, \ - VECTOR_MODE_MIN_VLEN_32) \ +#define DEF_RVV_TYPE(NAME, NCHARS, ABI_NAME, SCALAR_TYPE, VECTOR_MODE, \ + VECTOR_MODE_MIN_VLEN_32, ARGS...) \ mode = TARGET_MIN_VLEN > 32 ? VECTOR_MODE##mode \ : VECTOR_MODE_MIN_VLEN_32##mode; \ - scalar_types[VECTOR_TYPE_##NAME] \ - = riscv_v_ext_enabled_vector_mode_p (mode) ? SCALAR_TYPE##_type_node \ - : NULL_TREE; \ - vector_modes[VECTOR_TYPE_##NAME] \ - = riscv_v_ext_enabled_vector_mode_p (mode) ? mode : VOIDmode; + register_builtin_type (VECTOR_TYPE_##NAME, SCALAR_TYPE##_type_node, mode); #include "riscv-vector-builtins.def" - - for (unsigned int i = 0; i < NUM_VECTOR_TYPES; ++i) - { - tree eltype = scalar_types[i]; - mode = vector_modes[i]; - /* We disabled the datatypes according '-march'. */ - if (!eltype) - continue; - - tree vectype = build_vector_type_for_mode (eltype, mode); - gcc_assert ( - VECTOR_MODE_P (TYPE_MODE (vectype)) && TYPE_MODE (vectype) == mode - && TYPE_MODE_RAW (vectype) == mode && TYPE_ALIGN (vectype) <= 128 - && known_eq (tree_to_poly_uint64 (TYPE_SIZE (vectype)), - GET_MODE_BITSIZE (mode))); - vectype = build_distinct_type_copy (vectype); - gcc_assert (vectype == TYPE_MAIN_VARIANT (vectype)); - SET_TYPE_STRUCTURAL_EQUALITY (vectype); - TYPE_ARTIFICIAL (vectype) = 1; - TYPE_INDIVISIBLE_P (vectype) = 1; - add_vector_type_attribute (vectype, vector_types[i].mangled_name); - make_type_sizeless (vectype); - abi_vector_types[i] = vectype; - lang_hooks.types.register_builtin_type (vectype, - vector_types[i].abi_name); - } } /* Register vector type TYPE under its risv_vector.h name. */ @@ -180,6 +179,7 @@ static void register_vector_type (vector_type_index type) { tree vectype = abi_vector_types[type]; + /* When vectype is NULL, the corresponding builtin type is disabled according to '-march'. */ if (!vectype) @@ -198,7 +198,8 @@ register_vector_type (vector_type_index type) && TYPE_MAIN_VARIANT (TREE_TYPE (decl)) == vectype) vectype = TREE_TYPE (decl); - builtin_vector_types[0][type] = vectype; + builtin_types[type].vector = vectype; + builtin_types[type].vector_ptr = build_pointer_type (vectype); } /* RAII class for enabling enough RVV features to define the built-in diff --git a/gcc/config/riscv/riscv-vector-builtins.h b/gcc/config/riscv/riscv-vector-builtins.h index 5c01a760657..7d4b807f33c 100644 --- a/gcc/config/riscv/riscv-vector-builtins.h +++ b/gcc/config/riscv/riscv-vector-builtins.h @@ -36,6 +36,16 @@ enum vector_type_index NUM_VECTOR_TYPES }; +/* Builtin types that are used to register RVV intrinsics. */ +struct GTY (()) rvv_builtin_types_t +{ + tree vector; + tree scalar; + tree vector_ptr; + tree scalar_ptr; + tree scalar_const_ptr; +}; + } // end namespace riscv_vector #endif