forked from M-Labs/artiq
1
0
Fork 0

compiler: reduce calls to TypedTreeHasher

We need to check if our inference reached a fixed point. This is checked
using hash of the types in the AST, which is very slow. This patch
avoids computing the hash if we can make sure that the AST is definitely
changed, which is when we parse a new function.

For some simple programs with many functions, this can significantly
reduce the compile time by up to ~30%.
This commit is contained in:
pca006132 2021-07-06 15:23:24 +08:00 committed by Sébastien Bourdeauducq
parent 51d2861e63
commit 4ede58e44b
1 changed files with 15 additions and 5 deletions

View File

@ -737,6 +737,7 @@ class Stitcher:
self.embedding_map = EmbeddingMap() self.embedding_map = EmbeddingMap()
self.value_map = defaultdict(lambda: []) self.value_map = defaultdict(lambda: [])
self.definitely_changed = False
def stitch_call(self, function, args, kwargs, callback=None): def stitch_call(self, function, args, kwargs, callback=None):
# We synthesize source code for the initial call so that # We synthesize source code for the initial call so that
@ -757,14 +758,20 @@ class Stitcher:
old_attr_count = None old_attr_count = None
while True: while True:
inferencer.visit(self.typedtree) inferencer.visit(self.typedtree)
if self.definitely_changed:
changed = True
self.definitely_changed = False
else:
typedtree_hash = typedtree_hasher.visit(self.typedtree) typedtree_hash = typedtree_hasher.visit(self.typedtree)
attr_count = self.embedding_map.attribute_count() attr_count = self.embedding_map.attribute_count()
changed = old_attr_count != attr_count or \
if old_typedtree_hash == typedtree_hash and old_attr_count == attr_count: old_typedtree_hash != typedtree_hash
break
old_typedtree_hash = typedtree_hash old_typedtree_hash = typedtree_hash
old_attr_count = attr_count old_attr_count = attr_count
if not changed:
break
# After we've discovered every referenced attribute, check if any kernel_invariant # After we've discovered every referenced attribute, check if any kernel_invariant
# specifications refers to ones we didn't encounter. # specifications refers to ones we didn't encounter.
for host_type in self.embedding_map.type_map: for host_type in self.embedding_map.type_map:
@ -891,6 +898,9 @@ class Stitcher:
return types.TVar() return types.TVar()
def _quote_embedded_function(self, function, flags): def _quote_embedded_function(self, function, flags):
# we are now parsing new functions... definitely changed the type
self.definitely_changed = True
if isinstance(function, SpecializedFunction): if isinstance(function, SpecializedFunction):
host_function = function.host_function host_function = function.host_function
else: else: