Skip to content

Commit

Permalink
Verilator: Enable passing arguments to the make
Browse files Browse the repository at this point in the history
The verilator-generated Makefiles use documented variables to configure
the build process. The most important ones are OPT/OPT_FAST/OPT_SLOW to
influence the compiler flags for the individual parts of the build.

With verilator_options, one can already set compiler options globally
(such as "-O2"). However, compiling larger designs with such high
optimization settings leads to long build times with no real benefit,
especially if tracing is enabled. In those cases, setting OPT_FAST="-O2"
and not setting any global optimization flags can cut down the build
time by multiple times.
  • Loading branch information
imphil authored and olofk committed Jun 26, 2019
1 parent 997a35c commit 4887cdc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions edalize/verilator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
TOP_MODULE := {top_module}
VC_FILE := {vc_file}
VERILATOR_OPTIONS := {verilator_options}
MAKE_OPTIONS := {make_options}
"""

MAKEFILE_TEMPLATE = """#Auto generated by Edalize
Expand All @@ -25,7 +26,7 @@
endif
V$(TOP_MODULE): V$(TOP_MODULE).mk
$(MAKE) -f $<
$(MAKE) $(MAKE_OPTIONS) -f $<
V$(TOP_MODULE).mk:
$(VERILATOR) -f $(VC_FILE) $(VERILATOR_OPTIONS)
Expand All @@ -37,7 +38,8 @@ class Verilator(Edatool):
tool_options = {'members' : {'mode' : 'String',
'cli_parser' : 'String'},
'lists' : {'libs' : 'String',
'verilator_options' : 'String'}}
'verilator_options' : 'String'},
'make_options': 'String'}

argtypes = ['cmdlinearg', 'plusarg', 'vlogdefine', 'vlogparam']

Expand All @@ -59,6 +61,9 @@ def get_doc(cls, api_ver):
{'name' : 'verilator_options',
'type' : 'String',
'desc' : 'Additional options for verilator'},
{'name' : 'make_options',
'type' : 'String',
'desc' : 'Additional arguments passed to make when compiling the simulation. This is commonly used to set OPT/OPT_FAST/OPT_SLOW.'},
]}

def _managed_parser(self):
Expand Down Expand Up @@ -125,11 +130,18 @@ def _write_config_files(self):
verilator_options = ' '.join(self.tool_options['verilator_options'])
else:
verilator_options = ''

if 'make_options' in self.tool_options:
make_options = ' '.join(self.tool_options['make_options'])
else:
make_options = ''

with open(os.path.join(self.work_root, 'config.mk'), 'w') as config_mk:
config_mk.write(CONFIG_MK_TEMPLATE.format(
top_module = self.toplevel,
vc_file = self.verilator_file,
verilator_options = verilator_options))
verilator_options = verilator_options,
make_options = make_options))

def build_main(self):
logger.info("Building simulation model")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_verilator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VERILATOR ?= $(VERILATOR_ROOT)/bin/verilator
endif

V$(TOP_MODULE): V$(TOP_MODULE).mk
$(MAKE) -f $<
$(MAKE) $(MAKE_OPTIONS) -f $<

V$(TOP_MODULE).mk:
$(VERILATOR) -f $(VC_FILE) $(VERILATOR_OPTIONS)
1 change: 1 addition & 0 deletions tests/test_verilator/cc/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
TOP_MODULE := orpsoc_top
VC_FILE := mor1kx-generic_0.vc
VERILATOR_OPTIONS := -Wno-fatal --trace
MAKE_OPTIONS := OPT_FAST=-O2
1 change: 1 addition & 0 deletions tests/test_verilator/cc/mor1kx-generic_0.eda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ tool_options:
mode: cc
top_module: orpsoc_top
verilator_options: [-Wno-fatal, --trace]
make_options: ['OPT_FAST=-O2']
toplevel: orpsoc_top
version: 0.1.1
vpi:
Expand Down
1 change: 1 addition & 0 deletions tests/test_verilator/lint-only/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
TOP_MODULE := orpsoc_top
VC_FILE := mor1kx-generic_0.vc
VERILATOR_OPTIONS :=
MAKE_OPTIONS :=
1 change: 1 addition & 0 deletions tests/test_verilator/sc/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
TOP_MODULE := orpsoc_top
VC_FILE := mor1kx-generic_0.vc
VERILATOR_OPTIONS :=
MAKE_OPTIONS :=

0 comments on commit 4887cdc

Please sign in to comment.