From 340cc0217154a50081b530c11a2bd5ab2baceb0b Mon Sep 17 00:00:00 2001 From: Johan Bjork Date: Wed, 6 Jan 2016 20:47:44 -0500 Subject: [PATCH] Avoid dynamic_cast for classes with no children, bug1021. Signed-off-by: Wilson Snyder --- Changes | 5 +++++ src/astgen | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 8775fbe6e..c16748deb 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,11 @@ Revision history for Verilator The contributors that suggested a given feature are shown in []. [by ...] indicates the contributor was also the author of the fix; Thanks! +* Verilator 3.881 devel + +**** Internal Verilation-time performance enhancements, bug1021. [Johan Bjork] + + * Verilator 3.880 2015-12-19 *** Support display %u, %v, %p, %z, bug989. [Johan Bjork] diff --git a/src/astgen b/src/astgen index 33bfcca3f..8aba5b352 100755 --- a/src/astgen +++ b/src/astgen @@ -248,8 +248,15 @@ sub write_impl { my $fh = open_file(@_); foreach my $type (sort (keys %Classes)) { next if $type eq "Node"; # Special, just a return (this); - printf $fh "inline Ast%-16s AstNode::cast${type}() { return (dynamic_cast(this)); }\n" - ,$type."*"; + # For performance, prefer static_cast where we can + if (children_of($type)) { + printf $fh "inline Ast%-16s AstNode::cast${type}() { return (dynamic_cast(this)); }\n" + ,$type."*"; + } else { + my $ucType = uc $type; + printf $fh "inline Ast%-16s AstNode::cast${type}() { return (this && this->type() == AstType::at${ucType}) ? static_cast(this) : NULL; }\n" + ,$type."*"; + } } $fh->close(); }