From patchwork Tue Oct 17 11:34:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 154094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4069056vqb; Tue, 17 Oct 2023 04:37:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgvCbM02FYgEadkOpAYho+QwlMO9baetYm3u/Bdn19jly0IJf7QI69OA4CZ7kyZDvjzmO6 X-Received: by 2002:ad4:5746:0:b0:66d:2e59:4fc2 with SMTP id q6-20020ad45746000000b0066d2e594fc2mr2338726qvx.40.1697542658673; Tue, 17 Oct 2023 04:37:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542658; cv=pass; d=google.com; s=arc-20160816; b=yrYEME0dFgZKtqAVQHzMm57PoyjWS3SHHmCu/6CgLivxg2sS3yLX/J//IHHwVf0TRq qlVUsFgQkVh4vrI9bDWsgGKFES8LpybFbgOObELouxvlMIGdiFHqYTWge4oGKMtI+nKU bQdBMCcwdTrx0n/NYyWB25Jx/KFXvF35GkHihUZoW0kcrGVSM2p74KvIxtMQEWZI8Hpq +1VXcrJgorzXBedJAeWHyWfqD3h2EKr07IbWoFEwWRzI+v5IoZvkJxLBkXiKjBhN9D2R aDgB40HpSbEomgG00B8OVfqnoyQiXpDkObwhWkLVH6TVPUoZPKmSfuKpil/3oKgfBMTW pmWw== 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=owDL3Eb6PMq5ESUIZhH9vEdW1m7Txc/LS4wz2GsEIEI=; fh=x/Q0OlwHuvCZ3FpkiZPiUSvevOYVxUAi4aNnf76mUPQ=; b=rhT8mgqztOulN5BQS90D9brNdhord9f1pOCsXMjcsO/RfdjGDK2NDBRcUMSfT5a8Af aQxMdRNS5Z3k55PL7JuROSPu2U9EMD0BbYoCh6yx2nye0WdTyBdFWnHSPhgkt7rNJp3k Boov6JNXUSLbWLtJqXemN3gj34/OXkj2oNjN3Fho8smxBvsfh+gEosEkbmz4XBZ4oMZw DzsGn+ssSe8OahvaiW56TLlf18A7NzQZtTD3n077PfB8m8Wx/auXlPMFYa+ZjYFd5P72 IasAwsKVm7LDhxVSRGwmtwjst4wPlA71eXqB7h3dHEomj2HoO7kZfyvNHmmzDMLXY+LO QRuA== 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 eh6-20020a056214186600b0064c84ce3e14si813096qvb.72.2023.10.17.04.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37:38 -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 553153871034 for ; Tue, 17 Oct 2023 11:37:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by sourceware.org (Postfix) with ESMTPS id E54B43857724 for ; Tue, 17 Oct 2023 11:35:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E54B43857724 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 E54B43857724 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.207.22.56 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542530; cv=none; b=qRayFT+pecrqGqg8c4VHXAWCjZ5O6dzHsaNo1xotaTGVqskI4F6Z6+yD5lLBVvJ+sf6swdk+x/VthlXWbjMUWloh4e4niUc9b40yDzebneotPHLWQjmFKNXs7NRBwxDPJs08WwgmNxquSG9FJMHkwCzdGvQX6cK9kJdLUHfrQBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542530; c=relaxed/simple; bh=s9EGM3A2aeLst0+zibYkRHVIQaR5PLSZMEBHbGAt81g=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=aFe2j5UXtCCg+CAe9bNjv0zUuTdi44Y2M47OUDRSEcdJ8WPrLh96MHUhKRWVIBGe8rA6EfkkPU1poRShIiMu5KXnib08wEPvYUKQH/NyiBwgLovgZXWOlPpSDcM5bFDCyi/5GstMKGjw/ojRglVcBKf05/k/5C/F6tjd9io8VyA= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp62t1697542519tp5nl53r Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 17 Oct 2023 19:35:18 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: +oIWmpEafD/3Ed5jWF/DYUmUuW+W5qHu9VYSACxlc+nLkjsrrPoQN5ZO/yTv7 uLjNQegnRUW8tW0jjwSgdhR83NfvXY8rby9mFClQTym+5S4ZMFbtoKbMvzO6Sz/gY3WAWHb oAQ5LSDDTuIwhDvDSnmKcAINBxn9n6tVs/TghzNXcBOP3juPJtROKio6y22Z2b24c5B8OCt t+8LEfXgAGFVT8NFfaJ5FmrAEoshJrA0aRzPUZmS4K3KeS+H6cjHlzfMxkHPcNfB3aY7E25 HCK4DL/fyokDnsnReweV/OL/bwvPI1qpwXI3OBMvJ49gh7Siu8/+Dh78/eTonpREGcMeOLM oFS4r4Pfqybt7dhjhWU3IC08QCvrHFpbnIYlHTAGJ9PPJgBEiM8LzPC/nQQvdqDGFtmp4kc X-QQ-GoodBg: 2 X-BIZMAIL-ID: 14594604050613391881 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 04/14] RISC-V: P4: move method from pass_vsetvl to pre_vsetvl Date: Tue, 17 Oct 2023 19:34:50 +0800 Message-Id: <20231017113500.1160997-5-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: 1780002491040790539 X-GMAIL-MSGID: 1780002491040790539 This sub-patch remove the method about optimize vsetvl infos into class pre_vsetvl. 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 | 228 ++++++++++++------------------- 1 file changed, 87 insertions(+), 141 deletions(-) -- 2.36.3 diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index c219ad178bb..3f07fde782f 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2684,54 +2684,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) {} @@ -2741,69 +2695,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; @@ -2815,7 +2711,7 @@ pass_vsetvl::simple_vsetvl (void) const continue; if (has_vtype_op (rinsn)) { - const auto info = get_vector_info (rinsn); + const auto info = vsetvl_info (rinsn); emit_vsetvl_insn (VSETVL_DISCARD_RESULT, EMIT_BEFORE, info, NULL_RTX, rinsn); } @@ -2823,6 +2719,88 @@ pass_vsetvl::simple_vsetvl (void) const } } +/* 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) @@ -4253,35 +4231,3 @@ pass_vsetvl::lazy_vsetvl (void) df_post_optimization (); } -/* 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; - - init (); - - if (!optimize) - simple_vsetvl (); - else - lazy_vsetvl (); - - done (); - return 0; -} - -rtl_opt_pass * -make_pass_vsetvl (gcc::context *ctxt) -{ - return new pass_vsetvl (ctxt); -}