diff --git a/Changes b/Changes index 889f493b0..b1b2bc8f6 100644 --- a/Changes +++ b/Changes @@ -33,6 +33,8 @@ The contributors that suggested a given feature are shown in []. Thanks! medium and large designs with default options. User makefiles may require changes. +**** The run-time library is now compiled with -Os by default. (#2369, #2373) + * Verilator 4.034 2020-05-03 diff --git a/bin/verilator b/bin/verilator index e3de112cc..3700ea166 100755 --- a/bin/verilator +++ b/bin/verilator @@ -2103,13 +2103,21 @@ OPT_FAST specifies optimizations for those parts of the program that are on the fast path. This is mostly code that is executed every cycle. OPT_SLOW specifies optimizations for slow-path files, which execute only rarely, yet take a long time to compile with optimization on. OPT_SLOW is ignored if -VM_PARALLEL_BUILDS is not 1, in which case all code is compliled with OPT_FAST. +VM_PARALLEL_BUILDS is not 1, in which case all code is compiled with OPT_FAST. See also the C<--output-split> option. OPT specifies overall optimization and affects all compiles, including those OPT_FAST and OPT_SLOW control. For best results, use OPT="-Os -march=native", and link with "-static". Nearly the same results can be had with much better compile times with OPT_FAST="-O1 -fstrict-aliasing". Higher optimization such as "-O2" or "-O3" may help, but gcc compile times may be excessive under O3 on even medium sized designs. +There is a third variable, OPT_GLOBAL, which applies to common code in the +run-time library used by verilated models. This is set to "-Os" by default +and there should rarely be a need to change it. As the run-time library is +small in comparison to a lot of verilated models, disabling optimization on +the run-time library should not have a serious effect on overall compilation +time, but can have highly detrimental effect on run-time performance, +especially with tracing. The OPT variable also applies to files that are +controlled by OPT_GLOBAL. Unfortunately, using the optimizer with SystemC files can result in compiles taking several minutes. (The SystemC libraries have many little @@ -2670,7 +2678,7 @@ Verilator and add the generated C++ sources to the target specified. verilate(target SOURCES source ... [TOP_MODULE top] [PREFIX name] [TRACE] [TRACE_FST] [SYSTEMC] [COVERAGE] [INCLUDE_DIRS dir ...] [OPT_SLOW ...] [OPT_FAST ...] - [DIRECTORY dir] [VERILATOR_ARGS ...]) + [OPT_GLOBAL ..] [DIRECTORY dir] [VERILATOR_ARGS ...]) Lowercase and ... should be replaced with arguments, the uppercase parts delimit the arguments and can be passed in any order, or left out entirely @@ -2761,6 +2769,11 @@ optimization level to improve compile times with large designs. Optional. Set compiler flags for the fast path. +=item OPT_GLOBAL + +Optional. Set compiler flags for the common run-time library used by verilated +models. + =item DIRECTORY Optional. Set the verilator output directory. It is preferable to use the diff --git a/include/verilated.mk.in b/include/verilated.mk.in index 9c583b083..ac8ebfb69 100644 --- a/include/verilated.mk.in +++ b/include/verilated.mk.in @@ -92,6 +92,11 @@ LDLIBS += $(VM_USER_LDLIBS) #OPT_FAST = -Os -fstrict-aliasing #OPT_FAST = -O #OPT_FAST = +# Optimization applied to the common run-time library used by verilated models. +# For compatibility this is called OPT_GLOBAL even though it only applies to +# files in the run-time library. Normally there should be no need for the user +# to change this. +OPT_GLOBAL = -Os ####################################################################### ##### SystemC builds @@ -170,6 +175,9 @@ VK_SLOW_OBJS = $(addsuffix .o, $(VM_SLOW)) VK_USER_OBJS = $(addsuffix .o, $(VM_USER_CLASSES)) +# Note VM_GLOBAL_FAST and VM_GLOBAL_SLOW holds the files required from the +# run-time library. In practice everything is actually in VM_GLOBAL_FAST, +# but keeping the distinction for compatibility for now. VK_GLOBAL_OBJS = $(addsuffix .o, $(VM_GLOBAL_FAST) $(VM_GLOBAL_SLOW)) ifneq ($(VM_PARALLEL_BUILDS),1) @@ -197,15 +205,16 @@ $(VM_PREFIX)__ALL.a: $(VK_OBJS) ### Compile rules ifneq ($(VM_DEFAULT_RULES),0) -$(VM_PREFIX)__ALL.o: $(VM_PREFIX)__ALL.cpp - $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $< - -# Anything not in $(VK_SLOW_OBJS), including verilated.o use this rule +# Anything not in $(VK_SLOW_OBJS) or $(VK_GLOBAL_OBJS), including verilated.o +# and user files passed on the Verilator command line use this rule. %.o: %.cpp $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $< $(VK_SLOW_OBJS): %.o: %.cpp $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_SLOW) -c -o $@ $< + +$(VK_GLOBAL_OBJS): %.o: %.cpp + $(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_GLOBAL) -c -o $@ $< endif #Default rule embedded in make: diff --git a/test_regress/CMakeLists.txt b/test_regress/CMakeLists.txt index e07568e89..0cb22c4b7 100644 --- a/test_regress/CMakeLists.txt +++ b/test_regress/CMakeLists.txt @@ -13,7 +13,8 @@ ###################################################################### cmake_minimum_required(VERSION 3.8) -set(TEST_REQUIRED_VARS NAME CSOURCES OPT_FAST VERILATOR_ROOT VERILATOR_ARGS +set(TEST_REQUIRED_VARS NAME CSOURCES OPT_FAST OPT_GLOBAL + VERILATOR_ROOT VERILATOR_ARGS VERILATOR_SOURCES SYSTEMC VERBOSE VERILATION) foreach(var ${TEST_REQUIRED_VARS}) if (NOT DEFINED TEST_${var}) @@ -74,6 +75,9 @@ endif() if(TEST_OPT_FAST) list(APPEND verilate_ARGS OPT_FAST ${TEST_OPT_FAST}) endif() +if(TEST_OPT_GLOBAL) + list(APPEND verilate_ARGS OPT_GLOBAL ${TEST_OPT_GLOBAL}) +endif() if(TEST_THREADS) list(APPEND verilate_ARGS THREADS ${TEST_THREADS}) endif() diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 570a9ecaa..a8465552f 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -1112,6 +1112,7 @@ sub compile { "-DTEST_SYSTEMC=\"" .($self->sc ? 1 : 0). "\"", "-DCMAKE_PREFIX_PATH=\"".(($ENV{SYSTEMC_INCLUDE}||$ENV{SYSTEMC}||'')."/..\""), "-DTEST_OPT_FAST=\"" . ($param{benchmark} ? "-Os" : "") . "\"", + "-DTEST_OPT_GLOBAL=\"" . ($param{benchmark} ? "-Os" : "-O0") . "\"", "-DTEST_VERILATION=\"" . $::Opt_Verilation . "\"", ]); return 1 if $self->errors || $self->skips || $self->unsupporteds; @@ -1130,6 +1131,7 @@ sub compile { "CPPFLAGS_DRIVER=-D".uc($self->{name}), ($self->{verbose} ? "CPPFLAGS_DRIVER2=-DTEST_VERBOSE=1":""), ($param{benchmark} ? "OPT_FAST=-Os" : ""), + ($param{benchmark} ? "" : "OPT_GLOBAL=-O0"), "$self->{VM_PREFIX}", # bypass default rule, as we don't need archive ($param{make_flags}||""), ]); diff --git a/test_regress/t/t_flag_csplit.pl b/test_regress/t/t_flag_csplit.pl index 8ca9c6f43..1e126525c 100755 --- a/test_regress/t/t_flag_csplit.pl +++ b/test_regress/t/t_flag_csplit.pl @@ -38,6 +38,7 @@ while (1) { ($opt_verbose ? "CPPFLAGS_DRIVER2=-DTEST_VERBOSE=1":""), "OPT_FAST=-O2", "OPT_SLOW=-O0", + "OPT_GLOBAL=-Os", ($param{make_flags}||""), ]); @@ -111,13 +112,15 @@ sub check_gcc_flags { while (defined (my $line = $fh->getline)) { chomp $line; print ":log: $line\n" if $Self->{verbose}; - if ($line =~ /\.cpp/) { + if ($line =~ /$Self->{VM_PREFIX}\S*\.cpp/) { my $filetype = ($line =~ /Slow|Syms/) ? "slow":"fast"; my $opt = ($line !~ /-O2/) ? "slow":"fast"; print "$filetype, $opt, $line\n" if $Self->{verbose}; if ($filetype ne $opt) { error("${filetype} file compiled as if was ${opt}: $line"); } + } elsif ($line =~ /\.cpp/ and $line !~ /-Os/) { + error("library file not compiled with OPT_GLOBAL: $line"); } } } diff --git a/verilator-config.cmake.in b/verilator-config.cmake.in index 50edfdcd9..b13b32301 100644 --- a/verilator-config.cmake.in +++ b/verilator-config.cmake.in @@ -116,7 +116,7 @@ define_property(TARGET function(verilate TARGET) cmake_parse_arguments(VERILATE "COVERAGE;TRACE;TRACE_FST;SYSTEMC" "PREFIX;TOP_MODULE;THREADS;DIRECTORY" - "SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST" + "SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST;OPT_GLOBAL" ${ARGN}) if (NOT VERILATE_SOURCES) message(FATAL_ERROR "Need at least one source") @@ -290,6 +290,11 @@ function(verilate TARGET) set_property(SOURCE "${VFAST}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_FAST}") endforeach() endforeach() + foreach(VGLOBAL ${${VERILATE_PREFIX}_GLOBAL}) + foreach(OPT_GLOBAL ${VERILATE_OPT_GLOBAL} ${${VERILATE_PREFIX}_USER_CFLAGS}) + set_property(SOURCE "${VGLOBAL}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_GLOBAL}") + endforeach() + endforeach() target_include_directories(${TARGET} PUBLIC "${VERILATOR_ROOT}/include" "${VERILATOR_ROOT}/include/vltstd")