summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2019-08-13 23:04:50 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2019-08-13 23:04:50 +0000
commit0b26891f3f2b75dcc8f1a0f3a34342ce27570a2c (patch)
treec3c22b7c54c51e9f7c663f63697e49bb1fc782b7
parente9e36354531e0dde20fbd7dac9749244a52e61be (diff)
downloadbcm5719-llvm-0b26891f3f2b75dcc8f1a0f3a34342ce27570a2c.tar.gz
bcm5719-llvm-0b26891f3f2b75dcc8f1a0f3a34342ce27570a2c.zip
[analyzer] exploded-graph-rewriter: NFC: Refactor explorers into trimmers.
Explorers aren't the right abstraction. For the purposes of displaying svg files we don't care in which order do we explore the nodes. We may care about this for other analyses, but we're not there yet. The function of cutting out chunks of the graph is performed poorly by the explorers, because querying predecessors/successors on the explored nodes yields original successors/predecessors even if they aren't being explored. Introduce a new entity, "trimmers", that do one thing but to it right: cut out chunks of the graph. Trimmers mutate the graph, so stale edges aren't even visible to their consumers in the pipeline. Additionally, trimmers are intrinsically composable: multiple trimmers can be applied to the graph sequentially. Refactor the single-path explorer into the single-path trimmer. Rename the test file for consistency. Differential Revision: https://reviews.llvm.org/D65344 llvm-svn: 368767
-rw-r--r--clang/test/Analysis/exploded-graph-rewriter/trimmers.dot (renamed from clang/test/Analysis/exploded-graph-rewriter/explorers.dot)0
-rwxr-xr-xclang/utils/analyzer/exploded-graph-rewriter.py59
2 files changed, 33 insertions, 26 deletions
diff --git a/clang/test/Analysis/exploded-graph-rewriter/explorers.dot b/clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
index 226c63911c5..226c63911c5 100644
--- a/clang/test/Analysis/exploded-graph-rewriter/explorers.dot
+++ b/clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index eee09f37bd2..3fa8ba0c9a2 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -882,37 +882,36 @@ class BasicExplorer(object):
visitor.visit_end_of_graph()
-# SinglePathExplorer traverses only a single path - the leftmost path
-# from the root. Useful when the trimmed graph is still too large
-# due to a large amount of equivalent reports.
-class SinglePathExplorer(object):
- def __init__(self):
- super(SinglePathExplorer, self).__init__()
+#===-----------------------------------------------------------------------===#
+# Trimmers cut out parts of the ExplodedGraph so that to focus on other parts.
+# Trimmers can be combined together by applying them sequentially.
+#===-----------------------------------------------------------------------===#
- def explore(self, graph, visitor):
- visitor.visit_begin_graph(graph)
- # Keep track of visited nodes in order to avoid loops.
- visited = set()
+# SinglePathTrimmer keeps only a single path - the leftmost path from the root.
+# Useful when the trimmed graph is still too large.
+class SinglePathTrimmer(object):
+ def __init__(self):
+ super(SinglePathTrimmer, self).__init__()
+
+ def trim(self, graph):
+ visited_nodes = set()
node_id = graph.root_id
while True:
- visited.add(node_id)
+ visited_nodes.add(node_id)
node = graph.nodes[node_id]
- logging.debug('Visiting ' + node_id)
- visitor.visit_node(node)
- if len(node.successors) == 0:
- break
-
- succ_id = node.successors[0]
- succ = graph.nodes[succ_id]
- logging.debug('Visiting edge: %s -> %s ' % (node_id, succ_id))
- visitor.visit_edge(node, succ)
- if succ_id in visited:
+ if len(node.successors) > 0:
+ succ_id = node.successors[0]
+ succ = graph.nodes[succ_id]
+ node.successors = [succ_id]
+ succ.predecessors = [node_id]
+ if succ_id in visited_nodes:
+ break
+ node_id = succ_id
+ else:
break
-
- node_id = succ_id
-
- visitor.visit_end_of_graph()
+ graph.nodes = {node_id: graph.nodes[node_id]
+ for node_id in visited_nodes}
#===-----------------------------------------------------------------------===#
@@ -960,10 +959,18 @@ def main():
raw_line = raw_line.strip()
graph.add_raw_line(raw_line)
- explorer = SinglePathExplorer() if args.single_path else BasicExplorer()
+ trimmers = []
+ if args.single_path:
+ trimmers.append(SinglePathTrimmer())
+
+ explorer = BasicExplorer()
+
visitor = DotDumpVisitor(args.diff, args.dark, args.gray, args.topology,
args.dump_dot_only)
+ for trimmer in trimmers:
+ trimmer.trim(graph)
+
explorer.explore(graph, visitor)
OpenPOWER on IntegriCloud