Skip to content

Commit ef71241

Browse files
committed
Reorganize RDLCompiler.elaborate() to make it easier to profile
1 parent 74318b0 commit ef71241

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/systemrdl/compiler.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ def elaborate(self, top_def_name: Optional[str]=None, inst_name: Optional[str]=N
328328
else:
329329
self.msg.fatal("Could not find any 'addrmap' components to elaborate")
330330

331+
# Create design instance
332+
root_node = self._elab_create_root_inst(top_def, inst_name, top_def_name, parameters)
333+
334+
# Elaborate the design
335+
self._elab_design(root_node)
336+
337+
# Validate design
338+
self._elab_validate(root_node)
339+
340+
if self.msg.had_error:
341+
self.msg.fatal("Elaborate aborted due to previous errors")
342+
343+
return root_node
344+
345+
def _elab_create_root_inst(self, top_def: comp.Addrmap, inst_name: Optional[str], top_def_name: Optional[str], parameters: Dict[str, 'RDLValue']) -> RootNode:
331346
# Create an instance of the root component
332347
root_inst = self.root._copy_for_inst({}, recursive=True)
333348
root_inst.is_instance = True
@@ -370,6 +385,9 @@ def elaborate(self, top_def_name: Optional[str]=None, inst_name: Optional[str]=N
370385

371386
root_node = RootNode(root_inst, self.env, None)
372387

388+
return root_node
389+
390+
def _elab_design(self, root_node: RootNode) -> None:
373391
# Resolve all expressions
374392
walker.RDLSimpleWalker(skip_not_present=False).walk(
375393
root_node,
@@ -388,14 +406,10 @@ def elaborate(self, top_def_name: Optional[str]=None, inst_name: Optional[str]=N
388406
# re-visit nodes a 2nd time as-needed to complete elaboration
389407
LateElabRevisitor(late_elab_listener.node_needs_revisit)
390408

391-
# Validate design
409+
def _elab_validate(self, root_node: RootNode) -> None:
392410
# Only need to validate nodes that are present
393411
walker.RDLSimpleWalker(skip_not_present=True).walk(root_node, ValidateListener(self.env))
394412

395-
if self.msg.had_error:
396-
self.msg.fatal("Elaborate aborted due to previous errors")
397-
398-
return root_node
399413

400414

401415
def eval(self, expression: str) ->'RDLValue':

test/benchmark/profile_rdl.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@ def code_to_profile():
2525
profiler.bind_timer("systemrdl.preprocessor", "preprocess_file", "preprocess")
2626
profiler.bind_timer("systemrdl.parser.sa_systemrdl", "parse", "lex/parse")
2727
profiler.bind_timer("systemrdl.core.ComponentVisitor", "RootVisitor.visitRoot", "compile")
28-
profiler.bind_timer("systemrdl.compiler", "RDLCompiler.elaborate", "elaborate")
29-
30-
profiler.bind_timer("systemrdl.component", "Component._copy_for_inst", "comp deepcopies")
28+
profiler.bind_timer("systemrdl.compiler", "RDLCompiler.elaborate", "elaborate total")
29+
profiler.bind_timer("systemrdl.compiler", "RDLCompiler._elab_create_root_inst", "elaborate-inst")
30+
profiler.bind_timer("systemrdl.compiler", "RDLCompiler._elab_design", "elaborate-expr")
31+
profiler.bind_timer("systemrdl.compiler", "RDLCompiler._elab_validate", "validate")
32+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_Component" , "validate:enter_Component ")
33+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_Signal" , "validate:enter_Signal ")
34+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_AddressableComponent" , "validate:enter_AddressableComponent")
35+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_Addrmap" , "validate:enter_Addrmap ")
36+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_Reg" , "validate:enter_Reg ")
37+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Reg" , "validate:exit_Reg ")
38+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.enter_Field" , "validate:enter_Field ")
39+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Field" , "validate:exit_Field ")
40+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Regfile" , "validate:exit_Regfile ")
41+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Addrmap" , "validate:exit_Addrmap ")
42+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Mem" , "validate:exit_Mem ")
43+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_AddressableComponent" , "validate:exit_AddressableComponent ")
44+
#profiler.bind_timer("systemrdl.core.validate", "ValidateListener.exit_Component" , "validate:exit_Component ")
45+
#profiler.bind_timer("systemrdl.node", "Node.get_property" , "Node.get_property")
3146

3247
# Run!
3348
code_to_profile()

0 commit comments

Comments
 (0)