From 0c2c0973775c0977fb4fca2dad2a2d640e72abcf Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 13 Jun 2022 14:16:11 +0100 Subject: [PATCH] Add -fno-merge-cond-motion option This disables code motion during V3MergeCond, for debugging. --- docs/guide/exe_verilator.rst | 2 ++ src/V3MergeCond.cpp | 6 +++-- src/V3Options.cpp | 1 + src/V3Options.h | 4 ++- test_regress/t/t_merge_cond_no_motion.pl | 34 ++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100755 test_regress/t/t_merge_cond_no_motion.pl diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index af65fe3ba..bf99a7d65 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -459,6 +459,8 @@ Summary: .. option:: -fno-merge-cond +.. option:: -fno-merge-cond-motion + .. option:: -fno-merge-const-pool .. option:: -fno-reloop diff --git a/src/V3MergeCond.cpp b/src/V3MergeCond.cpp index 3881c48df..210d34ca6 100644 --- a/src/V3MergeCond.cpp +++ b/src/V3MergeCond.cpp @@ -477,10 +477,12 @@ private: AstNode* currp = m_workQueuep->front(); m_workQueuep->pop(); - // Analyse sub-tree list for code motion + // Analyse sub-tree list for code motion and conditional merging CodeMotionAnalysisVisitor::analyze(currp, stmtProperties); // Perform the code motion within the whole sub-tree list - currp = CodeMotionOptimizeVisitor::optimize(currp, stmtProperties); + if (v3Global.opt.fMergeCondMotion()) { + currp = CodeMotionOptimizeVisitor::optimize(currp, stmtProperties); + } // Merge conditionals in the whole sub-tree list (this might create new work items) iterateAndNextNull(currp); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 7d4b1e846..6daff79bc 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1097,6 +1097,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char DECL_OPTION("-flife-post", FOnOff, &m_fLifePost); DECL_OPTION("-flocalize", FOnOff, &m_fLocalize); DECL_OPTION("-fmerge-cond", FOnOff, &m_fMergeCond); + DECL_OPTION("-fmerge-cond-motion", FOnOff, &m_fMergeCondMotion); DECL_OPTION("-fmerge-const-pool", FOnOff, &m_fMergeConstPool); DECL_OPTION("-freloop", FOnOff, &m_fReloop); DECL_OPTION("-freorder", FOnOff, &m_fReorder); diff --git a/src/V3Options.h b/src/V3Options.h index 137580c34..2c795c844 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -354,7 +354,8 @@ private: bool m_fLifePost; // main switch: -fno-life-post: delayed assignment elimination bool m_fLocalize; // main switch: -fno-localize: convert temps to local variables bool m_fMergeCond; // main switch: -fno-merge-cond: merge conditionals - bool m_fMergeConstPool = true; // main switch: --fmerge-const-pool + bool m_fMergeCondMotion = true; // main switch: -fno-merge-cond-motion: perform code motion + bool m_fMergeConstPool = true; // main switch: -fno-merge-const-pool bool m_fReloop; // main switch: -fno-reloop: reform loops bool m_fReorder; // main switch: -fno-reorder: reorder assignments in blocks bool m_fSplit; // main switch: -fno-split: always assignment splitting @@ -587,6 +588,7 @@ public: bool fLifePost() const { return m_fLifePost; } bool fLocalize() const { return m_fLocalize; } bool fMergeCond() const { return m_fMergeCond; } + bool fMergeCondMotion() const { return m_fMergeCondMotion; } bool fMergeConstPool() const { return m_fMergeConstPool; } bool fReloop() const { return m_fReloop; } bool fReorder() const { return m_fReorder; } diff --git a/test_regress/t/t_merge_cond_no_motion.pl b/test_regress/t/t_merge_cond_no_motion.pl new file mode 100755 index 000000000..113b054db --- /dev/null +++ b/test_regress/t/t_merge_cond_no_motion.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2022 by Geza Lore. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt_all => 1); + +top_filename("t/t_merge_cond.v"); + +compile( + verilator_flags2 => ["-unroll-count 64", "--stats", "-fno-merge-cond-motion"], + ); + +execute( + check_finished => 1, + ); + +if ($Self->{vlt}) { + # Note, with vltmt this might be split differently, so only checking vlt + file_grep($Self->{stats}, qr/Optimizations, MergeCond merges\s+(\d+)/i, + 10); + file_grep($Self->{stats}, qr/Optimizations, MergeCond merged items\s+(\d+)/i, + 580); + file_grep($Self->{stats}, qr/Optimizations, MergeCond longest merge\s+(\d+)/i, + 64); +} + +ok(1); +1;