forked from M-Labs/artiq
1
0
Fork 0

Fix accidentally quadratic code in compiler.ir.Function._add_name.

This commit is contained in:
whitequark 2015-07-29 21:36:31 +03:00
parent 6d8d0ff3f5
commit d7f9af4bb5
1 changed files with 9 additions and 7 deletions

View File

@ -396,6 +396,7 @@ class Function:
def __init__(self, typ, name, arguments): def __init__(self, typ, name, arguments):
self.type, self.name = typ, name self.type, self.name = typ, name
self.names, self.arguments, self.basic_blocks = set(), [], [] self.names, self.arguments, self.basic_blocks = set(), [], []
self.next_name = 1
self.set_arguments(arguments) self.set_arguments(arguments)
self.is_internal = False self.is_internal = False
@ -403,13 +404,14 @@ class Function:
self.names.remove(name) self.names.remove(name)
def _add_name(self, base_name): def _add_name(self, base_name):
name, counter = base_name, 1
while name in self.names or name == "":
if base_name == "": if base_name == "":
name = "v.{}".format(str(counter)) name = "v.{}".format(self.next_name)
self.next_name += 1
elif base_name in self.names:
name = "{}.{}".format(base_name, self.next_name)
self.next_name += 1
else: else:
name = "{}.{}".format(name, counter) name = base_name
counter += 1
self.names.add(name) self.names.add(name)
return name return name