From patchwork Thu Oct 19 08:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 155371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp238723vqb; Thu, 19 Oct 2023 01:34:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDd8OClE4JwukixMVroODwuvjvuUPQy/74guGuoxzpBArbZE8NGCwiX/5BltgSghDhQZoW X-Received: by 2002:a05:6214:509b:b0:65b:21bf:8fb0 with SMTP id kk27-20020a056214509b00b0065b21bf8fb0mr1794178qvb.34.1697704498774; Thu, 19 Oct 2023 01:34:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697704498; cv=pass; d=google.com; s=arc-20160816; b=UGgJxqAQ5LxheEHAC/USwlyKONbNLHV1YA3DDbctLpz3Bgt8PL78kffFY8x/9DRuzK RRpJJ9snEscoWaJw8mRu27mWPGjuN/ZRmvHYrJ7ikpDPF0klK22roDsXzNVNvEHj36F6 9PTFJQw3bKrOjcogPDOJMYTwGmFo/dM65d3CgGv9wJaVmlc7Uh6M/tbnMJqUIik0naXu DY7IXfOTJFyJPK/6ve4MHMbr+HFaTXOc9uz2r2dCEcks/9OHR8yiu0tInbYdh9DsVTWm CCE25E0gC/wYB1QVest+o/swrbNf8dXrWw4D7b+h04oCt4ppLTeiHLVK6krXg7WeEAf7 GS2A== 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=HXu6vScsnqmjeQ1yNPTGx82otiULrPqYdqRPW3pHH2w=; fh=x/Q0OlwHuvCZ3FpkiZPiUSvevOYVxUAi4aNnf76mUPQ=; b=bQIimYKlP6n0LU6PVMErhHH/7ciJjSiWpSRXyVHSV1d2W6aj0JUcsC4l6G/ItHM0jh jvrcp8SBOPbUfg0bbOvuK308V3Z5ptmS/itMzPbXvl2fV4k/kqkLpeOSVW3s7FmE0O3z +8JlZxeWTgwvGwDZIEa9NbHGaC95PAcm3osHcGbSoZGelOaYgH5/8LtAhFk0TnXwnlf3 hEkeN2jYumVoFoVAYxnMhCNNyKcAjHAju2EI6KpOZBjJVBc6SECl1aqDOlFDCIdQCHzH RWl35QhLxn19H9ymsUB8ZjiipgvIBLbQocJuVWOibT/pk5TXQ/6DXZ+9EvtfOeBfROqo 46Ew== 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 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ng6-20020a0562143bc600b0066d11e63ba3si1276005qvb.84.2023.10.19.01.34.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:34:58 -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; arc=pass (i=1); 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 52E35385DC11 for ; Thu, 19 Oct 2023 08:34:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgsg1.qq.com (smtpbgsg1.qq.com [54.254.200.92]) by sourceware.org (Postfix) with ESMTPS id 1CF843858430 for ; Thu, 19 Oct 2023 08:33:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CF843858430 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 1CF843858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.254.200.92 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697704439; cv=none; b=lmjIJHsl1mQIK0fF+pXcPbDS6wvLbOr+z26EOpE5dRKQDEqmYASV3OBE76ENmG55qhT/5awSqis/UgEIpd/pS/4sOzFb2E4mL0n5WXGva2iHqwQ2/wZHBVy6SYgPvbpEee0pd8SpnJ7HmO6YW6IaXmp3q4TvFmsgjs1mhn9w5PE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697704439; c=relaxed/simple; bh=zmIGnjhEtiD/Ejl1uLtYJdiRtTh/+vW0HtKcLUM8IgE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=E59k93w9jDAgEfXTwtlJGKDNGt1p8ACvRd+AZYhkGW22fO7VQOB9I3bBc5nrxUVyRr0iDYGOx9hVvBEG5ZIXhXVpFMLlwjPYDkQyoJD6iXyXvQe/e/EiUQ7jx9vYs21Aj5mXK+8wnlc4YzifCslZHGCclIwA9zHeRpZtDH85F00= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp65t1697704429tih0p27f Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 19 Oct 2023 16:33:48 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: r/cTxDoDoiFgTcdsb/M0jL4mvuRRDhXGrqLW39w8G391jzVay5ePQgJHGKzZg H8HxekfMZBx6gOHK+vfQu7liwd6TCmk6lPDUSA23T4XKvNO2wprZZM+zzD1TsJa6+5D12j2 YSGKvgioGLP4PdqbaMDlE+iLQUgXQqEHrcnmaSCoCk3NqZ4Tfr6Of+k9mI7zdtlJXIU358X BJjDoEeOj8p4vepulitkSS/kva0r2oBIt3yIOulBttPZFv05/lB56XFyEDR6hiWbv/QTGBy BT6ZtCMC+QfzWT3JD+QD3KRDjn9G3pEXF2mce6jdNoiYgxdSOy6yZWTYKHbaZqOKTjdFkvS pWdk4Bxbh93zXhDXoRZkRMFtVx8CclXs9+/opYhN9EuEylJ4+racWUWv0iEDA== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 15983058150500287739 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 V3 04/11] RISC-V: P4: move method from pass_vsetvl to pre_vsetvl Date: Thu, 19 Oct 2023 16:33:26 +0800 Message-Id: <20231019083333.2052340-5-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20231019083333.2052340-1-lehua.ding@rivai.ai> References: <20231019083333.2052340-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.6 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: 1780172192503498285 X-GMAIL-MSGID: 1780172192503498285 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (pass_vsetvl::get_vector_info): Removed. (pass_vsetvl::get_block_info): Removed. (pass_vsetvl::update_vector_info): Removed. (pass_vsetvl::update_block_info): Removed. (pass_vsetvl::simple_vsetvl): Removed. (pass_vsetvl::lazy_vsetvl): Removed. (pass_vsetvl::execute): Removed. (make_pass_vsetvl): Removed. --- gcc/config/riscv/riscv-vsetvl.cc | 207 ++++++++++++++----------------- 1 file changed, 96 insertions(+), 111 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index c73a84cb6bd..f8b708c248a 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2721,6 +2721,7 @@ public: } }; + const pass_data pass_data_vsetvl = { RTL_PASS, /* type */ "vsetvl", /* name */ @@ -2736,54 +2737,8 @@ const pass_data pass_data_vsetvl = { class pass_vsetvl : public rtl_opt_pass { private: - vector_infos_manager *m_vector_manager; - - const vector_insn_info &get_vector_info (const rtx_insn *) const; - const vector_insn_info &get_vector_info (const insn_info *) const; - const vector_block_info &get_block_info (const basic_block) const; - const vector_block_info &get_block_info (const bb_info *) const; - vector_block_info &get_block_info (const basic_block); - vector_block_info &get_block_info (const bb_info *); - void update_vector_info (const insn_info *, const vector_insn_info &); - void update_block_info (int, profile_probability, const vector_insn_info &); - - void simple_vsetvl (void) const; - void lazy_vsetvl (void); - - /* Phase 1. */ - void compute_local_backward_infos (const bb_info *); - - /* Phase 2. */ - bool need_vsetvl (const vector_insn_info &, const vector_insn_info &) const; - void transfer_before (vector_insn_info &, insn_info *) const; - void transfer_after (vector_insn_info &, insn_info *) const; - void emit_local_forward_vsetvls (const bb_info *); - - /* Phase 3. */ - bool earliest_fusion (void); - void vsetvl_fusion (void); - - /* Phase 4. */ - void prune_expressions (void); - void compute_local_properties (void); - bool can_refine_vsetvl_p (const basic_block, const vector_insn_info &) const; - void refine_vsetvls (void) const; - void cleanup_vsetvls (void); - bool commit_vsetvls (void); - void pre_vsetvl (void); - - /* Phase 5. */ - rtx_insn *get_vsetvl_at_end (const bb_info *, vector_insn_info *) const; - void local_eliminate_vsetvl_insn (const bb_info *) const; - bool global_eliminate_vsetvl_insn (const bb_info *) const; - void ssa_post_optimization (void) const; - - /* Phase 6. */ - void df_post_optimization (void) const; - - void init (void); - void done (void); - void compute_probabilities (void); + void simple_vsetvl (); + void lazy_vsetvl (); public: pass_vsetvl (gcc::context *ctxt) : rtl_opt_pass (pass_data_vsetvl, ctxt) {} @@ -2793,69 +2748,11 @@ public: virtual unsigned int execute (function *) final override; }; // class pass_vsetvl -const vector_insn_info & -pass_vsetvl::get_vector_info (const rtx_insn *i) const -{ - return m_vector_manager->vector_insn_infos[INSN_UID (i)]; -} - -const vector_insn_info & -pass_vsetvl::get_vector_info (const insn_info *i) const -{ - return m_vector_manager->vector_insn_infos[i->uid ()]; -} - -const vector_block_info & -pass_vsetvl::get_block_info (const basic_block bb) const -{ - return m_vector_manager->vector_block_infos[bb->index]; -} - -const vector_block_info & -pass_vsetvl::get_block_info (const bb_info *bb) const -{ - return m_vector_manager->vector_block_infos[bb->index ()]; -} - -vector_block_info & -pass_vsetvl::get_block_info (const basic_block bb) -{ - return m_vector_manager->vector_block_infos[bb->index]; -} - -vector_block_info & -pass_vsetvl::get_block_info (const bb_info *bb) -{ - return m_vector_manager->vector_block_infos[bb->index ()]; -} - -void -pass_vsetvl::update_vector_info (const insn_info *i, - const vector_insn_info &new_info) -{ - m_vector_manager->vector_insn_infos[i->uid ()] = new_info; -} - -void -pass_vsetvl::update_block_info (int index, profile_probability prob, - const vector_insn_info &new_info) -{ - m_vector_manager->vector_block_infos[index].probability = prob; - if (m_vector_manager->vector_block_infos[index].local_dem - == m_vector_manager->vector_block_infos[index].reaching_out) - m_vector_manager->vector_block_infos[index].local_dem = new_info; - m_vector_manager->vector_block_infos[index].reaching_out = new_info; -} - -/* Simple m_vsetvl_insert vsetvl for optimize == 0. */ void -pass_vsetvl::simple_vsetvl (void) const +pass_vsetvl::simple_vsetvl () { if (dump_file) - fprintf (dump_file, - "\nEntering Simple VSETVL PASS and Handling %d basic blocks for " - "function:%s\n", - n_basic_blocks_for_fn (cfun), function_name (cfun)); + fprintf (dump_file, "\nEntering Simple VSETVL PASS\n"); basic_block cfg_bb; rtx_insn *rinsn; @@ -2867,14 +2764,102 @@ pass_vsetvl::simple_vsetvl (void) const continue; if (has_vtype_op (rinsn)) { - const auto info = get_vector_info (rinsn); - emit_vsetvl_insn (VSETVL_DISCARD_RESULT, EMIT_BEFORE, info, - NULL_RTX, rinsn); + const auto &info = vsetvl_info (rinsn); + rtx pat = info.get_vsetvl_pat (); + emit_insn_before (pat, rinsn); + if (dump_file) + { + fprintf (dump_file, " Insert vsetvl insn before insn %d:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, PREV_INSN (rinsn)); + } } } } } +/* Lazy vsetvl insertion for optimize > 0. */ +void +pass_vsetvl::lazy_vsetvl () +{ + if (dump_file) + fprintf (dump_file, "\nEntering Lazy VSETVL PASS\n\n"); + + pre_vsetvl pre = pre_vsetvl (); + + if (dump_file) + fprintf (dump_file, "\nPhase 1: Fuse local vsetvl infos.\n\n"); + pre.fuse_local_vsetvl_info (); + if (dump_file && (dump_flags & TDF_DETAILS)) + pre.dump (dump_file, "phase 1"); + + /* Phase 2: Fuse header and footer vsetvl infos between basic blocks. */ + if (dump_file) + fprintf (dump_file, "\nPhase 2: Lift up vsetvl info.\n\n"); + bool changed; + int fused_count = 0; + do + { + if (dump_file) + fprintf (dump_file, " Try lift up %d.\n\n", fused_count); + changed = pre.earliest_fuse_vsetvl_info (); + fused_count += 1; + } while (changed); + + if (dump_file && (dump_flags & TDF_DETAILS)) + pre.dump (dump_file, "phase 2"); + + /* Phase 3: Reducing redundant vsetvl infos using LCM. */ + if (dump_file) + fprintf (dump_file, "\nPhase 3: Reduce global vsetvl infos.\n\n"); + pre.pre_global_vsetvl_info (); + if (dump_file && (dump_flags & TDF_DETAILS)) + pre.dump (dump_file, "phase 3"); + + /* Phase 4: Insert, modify and remove vsetvl insns. */ + if (dump_file) + fprintf (dump_file, + "\nPhase 4: Insert, modify and remove vsetvl insns.\n\n"); + pre.emit_vsetvl (); + + /* Phase 5: Cleaup */ + if (dump_file) + fprintf (dump_file, "\nPhase 5: Cleaup\n\n"); + pre.cleaup (); + + pre.finish (); +} + +/* Main entry point for this pass. */ +unsigned int +pass_vsetvl::execute (function *) +{ + if (n_basic_blocks_for_fn (cfun) <= 0) + return 0; + + /* The RVV instruction may change after split which is not a stable + instruction. We need to split it here to avoid potential issue + since the VSETVL PASS is insert before split PASS. */ + split_all_insns (); + + /* Early return for there is no vector instructions. */ + if (!has_vector_insn (cfun)) + return 0; + + if (!optimize) + simple_vsetvl (); + else + lazy_vsetvl (); + + return 0; +} + +rtl_opt_pass * +make_pass_vsetvl (gcc::context *ctxt) +{ + return new pass_vsetvl (ctxt); +} + /* Compute demanded information by backward data-flow analysis. */ void pass_vsetvl::compute_local_backward_infos (const bb_info *bb)