From 118e8a505a00817a7276b05469c481886091548c Mon Sep 17 00:00:00 2001 From: Matti Hamalainen Date: Thu, 22 Apr 2021 12:49:58 +0300 Subject: [PATCH] gallium/tools: improve pointer type tracking in parse.py In our simplistic model of assigning types to pointer, we treat return values specially because their "type" can't be known easily before their first use. Improve the "ret" handling by removing one from their count when we reassign the type to something else. Signed-off-by: Matti Hamalainen Acked-By: Mike Blumenkrantz Part-of: --- src/gallium/tools/trace/model.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gallium/tools/trace/model.py b/src/gallium/tools/trace/model.py index aedad12..275ad18 100755 --- a/src/gallium/tools/trace/model.py +++ b/src/gallium/tools/trace/model.py @@ -112,16 +112,31 @@ class Pointer(Node): def __init__(self, address, pname): self.address = address - if address not in self.ptr_list or (self.ptr_type_list[address] == "ret" and pname != "ret"): - if pname not in self.ptr_types_list: - self.ptr_types_list[pname] = 1 - else: - self.ptr_types_list[pname] += 1 + # Check if address exists in list and if it is a return value address + t1 = address in self.ptr_list + if t1: + t2 = self.ptr_type_list[address] == "ret" and pname != "ret" + else: + t2 = False + + # If address does NOT exist (add it), OR IS a ret value (update with new type) + if not t1 or t2: + # If previously set to ret value, remove one from count + if t1 and t2: + self.adjust_ptr_type_count("ret", -1) + # Add / update + self.adjust_ptr_type_count(pname, 1) tmp = "{}_{}".format(pname, self.ptr_types_list[pname]) self.ptr_list[address] = tmp self.ptr_type_list[address] = pname + def adjust_ptr_type_count(self, pname, delta): + if pname not in self.ptr_types_list: + self.ptr_types_list[pname] = 0 + + self.ptr_types_list[pname] += delta + def visit(self, visitor): visitor.visit_pointer(self) -- 2.7.4