From patchwork Tue Oct 17 11:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 154092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4068634vqb; Tue, 17 Oct 2023 04:36:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKHUMFtXPPZpPhuuQRC6h3vbarqZzgg488sIhu/9lVfiACzmwVq+WiQoZUYTcDWSWslRT3 X-Received: by 2002:a05:690c:10c:b0:571:11ea:b2dd with SMTP id bd12-20020a05690c010c00b0057111eab2ddmr2037564ywb.32.1697542598099; Tue, 17 Oct 2023 04:36:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542598; cv=pass; d=google.com; s=arc-20160816; b=bar2mR9FEvMEtK9mgyjUtLvrKqZ2+/ES2pSeIfinVhCu451WgmEfBj1ycw9fULo8Ap o1WH0BOLuCd2F+1Cw+Ggg+uwP4lMub0JzByD7FnG1CyN00L/JyqXezLmS906IegF5bPt 6JhpUtaH0vm6ALScHFwyrLAmeVhmt9UcKK0Kz5lxNICNM+dS9UfMIsXgDFy0gL1wgJyK E60qoGiFXvZKCUjvWDWMswm6TforT1np6mAmwXUju5yPMSXRfnKIFI/DAR+M1owujdix UliC6Bn0nOK7KKROvDJyo290Cl8rcLY+7wPvkRDCR03HGGXpwbPHh9NTCnprrg/fXC6G +dEQ== 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:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=qX1Vlbv+GrXGFiEAndyRZOKhcGA+it+T2qfJyun+iG0=; fh=x/Q0OlwHuvCZ3FpkiZPiUSvevOYVxUAi4aNnf76mUPQ=; b=M+kGZ+YtgbBzN87I2TbJ2tzC5+Dse5RukRQYufuVRdQYgMhT6gaDhs2e+tKQylS9/8 iR/UVKSmaI/kRhNeSUibr1EuAF9NWgMJ/C0L4zGIWL0wv5rkWoOQMKFmdk7iWvXeaGEh hCVvNXoLFu66yjrvvgTqcsgV/si1EmMkcWiavJ8mrO/W0BIUbshVEmT3ZOwgyh+Y9bUo /W7JTVkVCgV0eS4ALrQvFHcNZqnkwmNXJCRyX0162O030Kp4Pijo5nJ+x9JsmvIENLDm F76svz55v5ZfYFHVtPG+roQP2q2+2Crm2whwX1ax657jQKSeFJv5B0ZpXgB0+MkaOC5q +jlQ== 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 i16-20020a05620a249000b007756e8eae0asi944671qkn.444.2023.10.17.04.36.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:36:38 -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 ACCE2385DC07 for ; Tue, 17 Oct 2023 11:36:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) by sourceware.org (Postfix) with ESMTPS id 8216F3858416 for ; Tue, 17 Oct 2023 11:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8216F3858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8216F3858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.92.39.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542525; cv=none; b=HrpQzdqppSIEbGNyUw+hMPcpuHE7TLecC7s6c5G00zVJPOtYZY0uz35CCPo9477bEBVBI7UEuX3Eb0ft9YU1RUZCLggvmwyh1ja42XqQoCrDMrfHwEcFj8AD7gVd3zKQqxQhPrMk8FvjSyaUzs55MslmWwthNBlSgj6eSDLgTxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542525; c=relaxed/simple; bh=gBgjp2Xwp3F5jpr3/8r39HUq6N5g8bzIzRsavXK4WOI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=YAb4vvXYZRqjCOLC/xhZ96ARmX7a13f4E7O9iKzElds2hSGp9LJ64qMm/09s3LReibmHaJcvFSgeVRvfTjJS6AV2LRHbMspgB7jo5NwG5xdBQiH98cyioEFRBpzwv40ptlIXcMt8rRf9or2MbT0GQHxs8avr0K1WHbVvW9pmj4A= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp62t1697542515tg7rgp5b Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 17 Oct 2023 19:35:14 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: lkL5M32tl2DK5d8v0mpBMdwePrBq9um1JFPHpdSMExMqNonFMwmfynud2nLsv p1czGJhZUud08AlbmSERS1ep4KSM8bguKlMEM3V7LtRpi6Gd5Rjd+l8RtSKcM7hw18o0hgI ZuTjQt7/2/8nEvTdl81oLLwRdJbBJ/q/N88vjUY1GCFbkM9PMY7rK/i6ip4gBcBDxQigD1P SSUxGUowbcobWNGvFm2wEvfVyLrIvTLKm5vZTzFNCHlbxWyotjbCe7NtDKmSGz3NS/st3ui JmibYAoYynMaymQDbt1+z3k466ZZRzMqUTkdlKOFlF+2MJ2YwU/Ff36MM6EzZaoRXU6RFRt rxanPa/NTXXweDkVJ8eTehSDgoP3++OxMMamNknldpMQ3IaOUhzv99IhePJbTmNyPjjeNkV YZNVdasDi4c= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10832152116283760800 From: Lehua Ding To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, rdapp.gcc@gmail.com, palmer@rivosinc.com, jeffreyalaw@gmail.com, lehua.ding@rivai.ai Subject: [PATCH V2 03/14] RISC-V: P3: Refactor vector_infos_manager Date: Tue, 17 Oct 2023 19:34:49 +0800 Message-Id: <20231017113500.1160997-4-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20231017113500.1160997-1-lehua.ding@rivai.ai> References: <20231017113500.1160997-1-lehua.ding@rivai.ai> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.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: 1780002427009859582 X-GMAIL-MSGID: 1780002427009859582 This sub-patch refactor vector_infos_manager to a pre_vsetvl class which is responsible for the entire lazy vsetvl jobs. There is no need to introduce a separate vsetvl infos manager, because vsetvl infos are modified by the optimization code. gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (vector_infos_manager::vector_infos_manager): Removed. (class pre_vsetvl): New class. (vector_infos_manager::create_expr): Removed. (vector_infos_manager::get_expr_id): Removed. (vector_infos_manager::all_same_ratio_p): Removed. (vector_infos_manager::all_avail_in_compatible_p): Removed. (vector_infos_manager::all_same_avl_p): Removed. (vector_infos_manager::expr_set_num): Removed. (vector_infos_manager::release): Removed. (vector_infos_manager::create_bitmap_vectors): Removed. (vector_infos_manager::free_bitmap_vectors): Removed. (vector_infos_manager::dump): Removed. * config/riscv/riscv-vsetvl.h (class vector_infos_manager): Removed. --- gcc/config/riscv/riscv-vsetvl.cc | 632 +++++++++++++------------------ gcc/config/riscv/riscv-vsetvl.h | 75 ---- 2 files changed, 257 insertions(+), 450 deletions(-) -- 2.36.3 diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index be40b6fdf4c..c219ad178bb 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2390,402 +2390,284 @@ public: } }; -vector_infos_manager::vector_infos_manager () +class pre_vsetvl { - vector_edge_list = nullptr; - vector_kill = nullptr; - vector_del = nullptr; - vector_insert = nullptr; - vector_antic = nullptr; - vector_transp = nullptr; - vector_comp = nullptr; - vector_avin = nullptr; - vector_avout = nullptr; - vector_antin = nullptr; - vector_antout = nullptr; - vector_earliest = nullptr; - vector_insn_infos.safe_grow_cleared (get_max_uid ()); - vector_block_infos.safe_grow_cleared (last_basic_block_for_fn (cfun)); - if (!optimize) - { - basic_block cfg_bb; - rtx_insn *rinsn; - FOR_ALL_BB_FN (cfg_bb, cfun) - { - vector_block_infos[cfg_bb->index].local_dem = vector_insn_info (); - vector_block_infos[cfg_bb->index].reaching_out = vector_insn_info (); - FOR_BB_INSNS (cfg_bb, rinsn) - vector_insn_infos[INSN_UID (rinsn)].parse_insn (rinsn); - } - } - else - { - for (const bb_info *bb : crtl->ssa->bbs ()) - { - vector_block_infos[bb->index ()].local_dem = vector_insn_info (); - vector_block_infos[bb->index ()].reaching_out = vector_insn_info (); - for (insn_info *insn : bb->real_insns ()) - vector_insn_infos[insn->uid ()].parse_insn (insn); - vector_block_infos[bb->index ()].probability = profile_probability (); - } - } -} - -void -vector_infos_manager::create_expr (vector_insn_info &info) -{ - for (size_t i = 0; i < vector_exprs.length (); i++) - if (*vector_exprs[i] == info) - return; - vector_exprs.safe_push (&info); -} - -size_t -vector_infos_manager::get_expr_id (const vector_insn_info &info) const -{ - for (size_t i = 0; i < vector_exprs.length (); i++) - if (*vector_exprs[i] == info) - return i; - gcc_unreachable (); -} - -auto_vec -vector_infos_manager::get_all_available_exprs ( - const vector_insn_info &info) const -{ - auto_vec available_list; - for (size_t i = 0; i < vector_exprs.length (); i++) - if (info.available_p (*vector_exprs[i])) - available_list.safe_push (i); - return available_list; -} - -bool -vector_infos_manager::all_same_ratio_p (sbitmap bitdata) const -{ - if (bitmap_empty_p (bitdata)) - return false; - - int ratio = -1; - unsigned int bb_index; - sbitmap_iterator sbi; - - EXECUTE_IF_SET_IN_BITMAP (bitdata, 0, bb_index, sbi) - { - if (ratio == -1) - ratio = vector_exprs[bb_index]->get_ratio (); - else if (vector_exprs[bb_index]->get_ratio () != ratio) - return false; - } - return true; -} - -/* Return TRUE if the incoming vector configuration state - to CFG_BB is compatible with the vector configuration - state in CFG_BB, FALSE otherwise. */ -bool -vector_infos_manager::all_avail_in_compatible_p (const basic_block cfg_bb) const -{ - const auto &info = vector_block_infos[cfg_bb->index].local_dem; - sbitmap avin = vector_avin[cfg_bb->index]; - unsigned int bb_index; - sbitmap_iterator sbi; - EXECUTE_IF_SET_IN_BITMAP (avin, 0, bb_index, sbi) - { - const auto &avin_info - = static_cast (*vector_exprs[bb_index]); - if (!info.compatible_p (avin_info)) - return false; - } - return true; -} - -bool -vector_infos_manager::all_same_avl_p (const basic_block cfg_bb, - sbitmap bitdata) const -{ - if (bitmap_empty_p (bitdata)) - return false; - - const auto &block_info = vector_block_infos[cfg_bb->index]; - if (!block_info.local_dem.demand_p (DEMAND_AVL)) - return true; - - avl_info avl = block_info.local_dem.get_avl_info (); - unsigned int bb_index; - sbitmap_iterator sbi; - - EXECUTE_IF_SET_IN_BITMAP (bitdata, 0, bb_index, sbi) - { - if (vector_exprs[bb_index]->get_avl_info () != avl) - return false; - } - return true; -} +private: + demand_system dem; + auto_vec vector_block_infos; + + /* data for avl reaching defintion. */ + sbitmap avl_regs; + sbitmap *avl_def_in; + sbitmap *avl_def_out; + sbitmap *reg_def_loc; + + /* data for vsetvl info reaching defintion. */ + vsetvl_info unknow_info; + auto_vec vsetvl_def_exprs; + sbitmap *vsetvl_def_in; + sbitmap *vsetvl_def_out; + + /* data for lcm */ + auto_vec exprs; + sbitmap *avloc; + sbitmap *avin; + sbitmap *avout; + sbitmap *kill; + sbitmap *antloc; + sbitmap *transp; + sbitmap *insert; + sbitmap *del; + struct edge_list *edges; + + auto_vec delete_list; + + vsetvl_block_info &get_block_info (const bb_info *bb) + { + return vector_block_infos[bb->index ()]; + } + const vsetvl_block_info &get_block_info (const basic_block bb) const + { + return vector_block_infos[bb->index]; + } -bool -vector_infos_manager::earliest_fusion_worthwhile_p ( - const basic_block cfg_bb) const -{ - edge e; - edge_iterator ei; - profile_probability prob = profile_probability::uninitialized (); - FOR_EACH_EDGE (e, ei, cfg_bb->succs) - { - if (prob == profile_probability::uninitialized ()) - prob = vector_block_infos[e->dest->index].probability; - else if (prob == vector_block_infos[e->dest->index].probability) - continue; - else - /* We pick the highest probability among those incompatible VSETVL - infos. When all incompatible VSTEVL infos have same probability, we - don't pick any of them. */ - return true; - } - return false; -} + vsetvl_block_info &get_block_info (const basic_block bb) + { + return vector_block_infos[bb->index]; + } -bool -vector_infos_manager::vsetvl_dominated_by_all_preds_p ( - const basic_block cfg_bb, const vector_insn_info &info) const -{ - edge e; - edge_iterator ei; - FOR_EACH_EDGE (e, ei, cfg_bb->preds) - { - const auto &reaching_out = vector_block_infos[e->src->index].reaching_out; - if (e->src->index == cfg_bb->index && reaching_out.compatible_p (info)) - continue; - if (!vsetvl_dominated_by_p (e->src, info, reaching_out, false)) - return false; - } - return true; -} + void add_expr (auto_vec &exprs, vsetvl_info &info) + { + for (vsetvl_info *item : exprs) + { + if (*item == info) + return; + } + exprs.safe_push (&info); + } -size_t -vector_infos_manager::expr_set_num (sbitmap bitdata) const -{ - size_t count = 0; - for (size_t i = 0; i < vector_exprs.length (); i++) - if (bitmap_bit_p (bitdata, i)) - count++; - return count; -} + unsigned get_expr_index (auto_vec &exprs, + const vsetvl_info &info) + { + for (size_t i = 0; i < exprs.length (); i += 1) + { + if (*exprs[i] == info) + return i; + } + gcc_unreachable (); + } -void -vector_infos_manager::release (void) -{ - if (!vector_insn_infos.is_empty ()) - vector_insn_infos.release (); - if (!vector_block_infos.is_empty ()) - vector_block_infos.release (); - if (!vector_exprs.is_empty ()) - vector_exprs.release (); - - gcc_assert (to_refine_vsetvls.is_empty ()); - gcc_assert (to_delete_vsetvls.is_empty ()); - if (optimize > 0) - free_bitmap_vectors (); -} + bool anticpatable_exp_p (const vsetvl_info &header_info) + { + if (!header_info.has_reg_avl () && !header_info.has_reg_vl ()) + return true; -void -vector_infos_manager::create_bitmap_vectors (void) -{ - /* Create the bitmap vectors. */ - vector_antic = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_transp = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_comp = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_avin = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_avout = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_kill = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_antin = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - vector_antout = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), - vector_exprs.length ()); - - bitmap_vector_ones (vector_transp, last_basic_block_for_fn (cfun)); - bitmap_vector_clear (vector_antic, last_basic_block_for_fn (cfun)); - bitmap_vector_clear (vector_comp, last_basic_block_for_fn (cfun)); - vector_edge_list = create_edge_list (); - vector_earliest = sbitmap_vector_alloc (NUM_EDGES (vector_edge_list), - vector_exprs.length ()); -} + bb_info *bb = header_info.get_bb (); + insn_info *prev_insn = bb->head_insn (); + insn_info *next_insn = header_info.get_insn (); + if (bb != next_insn->bb ()) + next_insn = bb->end_insn (); -void -vector_infos_manager::free_bitmap_vectors (void) -{ - /* Finished. Free up all the things we've allocated. */ - free_edge_list (vector_edge_list); - if (vector_del) - sbitmap_vector_free (vector_del); - if (vector_insert) - sbitmap_vector_free (vector_insert); - if (vector_kill) - sbitmap_vector_free (vector_kill); - if (vector_antic) - sbitmap_vector_free (vector_antic); - if (vector_transp) - sbitmap_vector_free (vector_transp); - if (vector_comp) - sbitmap_vector_free (vector_comp); - if (vector_avin) - sbitmap_vector_free (vector_avin); - if (vector_avout) - sbitmap_vector_free (vector_avout); - if (vector_antin) - sbitmap_vector_free (vector_antin); - if (vector_antout) - sbitmap_vector_free (vector_antout); - if (vector_earliest) - sbitmap_vector_free (vector_earliest); - - vector_edge_list = nullptr; - vector_kill = nullptr; - vector_del = nullptr; - vector_insert = nullptr; - vector_antic = nullptr; - vector_transp = nullptr; - vector_comp = nullptr; - vector_avin = nullptr; - vector_avout = nullptr; - vector_antin = nullptr; - vector_antout = nullptr; - vector_earliest = nullptr; -} + return dem.safe_move_avl_vl_p (prev_insn, next_insn, header_info); + } -void -vector_infos_manager::dump (FILE *file) const -{ - basic_block cfg_bb; - rtx_insn *rinsn; + bool available_exp_p (const vsetvl_info &prev_info, + const vsetvl_info &next_info) + { + return dem.available_with (prev_info, next_info); + } - fprintf (file, "\n"); - FOR_ALL_BB_FN (cfg_bb, cfun) - { - fprintf (file, "Local vector info of :\n", cfg_bb->index); - fprintf (file, "
="); - vector_block_infos[cfg_bb->index].local_dem.dump (file); - FOR_BB_INSNS (cfg_bb, rinsn) - { - if (!NONDEBUG_INSN_P (rinsn) || !has_vtype_op (rinsn)) - continue; - fprintf (file, "=", INSN_UID (rinsn)); - const auto &info = vector_insn_infos[INSN_UID (rinsn)]; - info.dump (file); - } - fprintf (file, "