Mesa (main): gallium/tools: improve pointer type tracking in parse.py

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 7 15:57:52 UTC 2021


Module: Mesa
Branch: main
Commit: 118e8a505a00817a7276b05469c481886091548c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=118e8a505a00817a7276b05469c481886091548c

Author: Matti Hamalainen <ccr at tnsp.org>
Date:   Thu Apr 22 12:49:58 2021 +0300

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 <ccr at tnsp.org>
Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10648>

---

 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 aedad1218f4..275ad183a13 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)
 



More information about the mesa-commit mailing list