Skip to content

Commit 4026ba1

Browse files
Track only immediate dependencies in variable sensitivity dependence graph.
Previously the variable sensitivity dependence graph would track both immediate and transitive dependencies. Transitive dependencies are not needed and can be calculated by other means. This change brings variable sensitivity dependence graph into line with the behaviour of the old dependence graph code.
1 parent 9d4693a commit 4026ba1

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

regression/goto-analyzer/sensitivity-test-data-dependency-context/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ EXIT=0
77
SIGNAL=0
88
st \(\) -> \{.a=.* @ \[2, 47\]\[Data dependencies: 47, 2\]\[Data dominators: \], .b=.* @ \[5, 47\]\[Data dependencies: 47, 5\]\[Data dominators: \]\} @ \[2, 5, 47\]\[Data dependencies: 47, 5, 2\]\[Data dominators: 47\]
99
ar \(\) -> \{\[0\] = .* @ \[11, 42\]\[Data dependencies: 42, 11\]\[Data dominators: \]\n\[1\] = .* @ \[14, 42\]\[Data dependencies: 42, 14\]\[Data dominators: \]\n\} @ \[11, 14, 42\]\[Data dependencies: 42, 14, 11\]\[Data dominators: 42\]
10-
arr \(\) -> \{\[0\] = .* @ \[19\]\[Data dependencies: 19\]\[Data dominators: 19\]\n\[1\] = .* @ \[20\]\[Data dependencies: 20\]\[Data dominators: 20\]\n\[2\] = .* @ \[21, 23\]\[Data dependencies: 23, 21, 20\]\[Data dominators: \]\n\} @ \[21, 23\]\[Data dependencies: 43, 23, 21, 20, 19\]\[Data dominators: 43\]
10+
arr \(\) -> \{\[0\] = .* @ \[19\]\[Data dependencies: 19\]\[Data dominators: 19\]\n\[1\] = .* @ \[20\]\[Data dependencies: 20\]\[Data dominators: 20\]\n\[2\] = .* @ \[21, 23\]\[Data dependencies: 23, 21\]\[Data dominators: \]\n\} @ \[21, 23\]\[Data dependencies: 23, 21\]\[Data dominators: 43\]
1111
--
1212
^warning: ignoring

regression/goto-analyzer/variable-sensitivity-dependence-graph-toyota/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Data dependencies: 10 \[ar\[\(signed long int\)0\]\], 13 \[ar\[\(signed long int
1616
Data dependencies: 19 \[arr\[\(signed long int\)1\]\]
1717
Data dependencies: 18 \[arr\[\(signed long int\)0\]\]
1818
Data dependencies: 19 \[arr\[\(signed long int\)1\]\]
19-
Data dependencies: 19 \[arr\[\(signed long int\)2\]\], 20 \[arr\[\(signed long int\)2\]\], 22 \[arr\[\(signed long int\)2\]\]
19+
Data dependencies: 20 \[arr\[\(signed long int\)2\]\], 22 \[arr\[\(signed long int\)2\]\]
2020
Data dependencies: 1 \[st.a\], 53 \[st.a\], 57 \[st.a\]
2121
Data dependencies: 4 \[st.b\], 53 \[st.b\], 60 \[st.b\]
2222
Data dependencies: 1 \[st.a\], 4 \[st.b\], 53 \[st.a, st.b\], 57 \[st.a\], 60 \[st.b\]

regression/goto-analyzer/variable-sensitivity-dependence-graph/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ SIGNAL=0
99
^Data dependencies: 4 \[st.b\], 53 \[st.b\]$
1010
^Data dependencies: 1 \[st.a\], 4 \[st.b\], 53 \[st.a, st.b\]$
1111
^Data dependencies: 48 \[ar\[\(signed long int\)0\]\]$
12-
^Data dependencies: 1 \[out1\], 6 \[out1\], 53 \[out1\]$
12+
^Data dependencies: 6 \[out1\]$
1313
^Data dependencies: 48 \[ar\[\(signed long int\)1\]\]$
1414
^Data dependencies: 10 \[ar\[\(signed long int\)0\]\], 48 \[ar\[\(signed long int\)0\]\]$
1515
^Data dependencies: 13 \[ar\[\(signed long int\)1\]\], 48 \[ar\[\(signed long int\)1\]\]$
1616
^Data dependencies: 10 \[ar\[\(signed long int\)0\]\], 13 \[ar\[\(signed long int\)1\]\], 48 \[ar\[\(signed long int\)0\], ar\[\(signed long int\)1\]\]$
1717
^Data dependencies: 19 \[arr\[\(signed long int\)1\]\]$
1818
^Data dependencies: 18 \[arr\[\(signed long int\)0\]\]$
1919
^Data dependencies: 19 \[arr\[\(signed long int\)1\]\]$
20-
^Data dependencies: 19 \[arr\[\(signed long int\)2\]\], 20 \[arr\[\(signed long int\)2\]\], 22 \[arr\[\(signed long int\)2\]\]$
20+
^Data dependencies: 20 \[arr\[\(signed long int\)2\]\], 22 \[arr\[\(signed long int\)2\]\]$
2121
^Data dependencies: 1 \[st.a\], 53 \[st.a\], 57 \[st.a\]$
2222
^Data dependencies: 4 \[st.b\], 53 \[st.b\], 60 \[st.b\]$
2323
^Data dependencies: 1 \[st.a\], 4 \[st.b\], 53 \[st.a, st.b\], 57 \[st.a\], 60 \[st.b\]$

src/analyses/variable-sensitivity/data_dependency_context.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,35 @@ abstract_object_pointert data_dependency_contextt::insert_data_deps(
129129
return result;
130130
}
131131

132+
/**
133+
* Set the given set of data dependencies for this data_dependency_context
134+
* object.
135+
*
136+
* \param dependencies the set of dependencies to set
137+
* \return a new data_dependency_context if new dependencies were set,
138+
* or 'this' if the dependencies were not changed.
139+
*/
140+
abstract_object_pointert data_dependency_contextt::set_data_deps(
141+
const dependencest &dependencies) const
142+
{
143+
// If the dependencies will not change, just return 'this'
144+
if(data_deps == dependencies)
145+
return shared_from_this();
146+
147+
const auto &result=
148+
std::dynamic_pointer_cast<data_dependency_contextt>(mutable_clone());
149+
150+
result->data_deps = dependencies;
151+
152+
// If this is the first write to the context then it is also used as
153+
// the initial set of data dependency dominators as well.
154+
if(data_deps.empty())
155+
{
156+
result->data_dominators = dependencies;
157+
}
158+
return result;
159+
}
160+
132161
/**
133162
* A helper function to evaluate writing to a component of an
134163
* abstract object. More precise abstractions may override this to
@@ -161,7 +190,7 @@ abstract_object_pointert data_dependency_contextt::write(
161190
const auto cast_value=
162191
std::dynamic_pointer_cast<const data_dependency_contextt>(value);
163192

164-
return updated_parent->insert_data_deps(cast_value->data_deps);
193+
return updated_parent->set_data_deps(cast_value->data_deps);
165194
}
166195

167196
/**
@@ -185,7 +214,7 @@ data_dependency_contextt::update_location_context(
185214
this->write_location_contextt::update_location_context(
186215
locations, update_sub_elements));
187216

188-
return updated_parent->insert_data_deps(locations);
217+
return updated_parent->set_data_deps(locations);
189218
}
190219

191220
/**

src/analyses/variable-sensitivity/data_dependency_context.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,25 @@ class data_dependency_contextt:
9797
abstract_object_pointert insert_data_deps(
9898
const dependencest &dependencies) const;
9999

100+
abstract_object_pointert set_data_deps(
101+
const dependencest &dependencies) const;
102+
100103
abstract_object_pointert insert_data_deps(const locationst &locations) const
101104
{
102105
// `locationst` is unsorted, so convert this to a sorted `dependenciest`
103-
dependencest dependencies;
104-
105-
for(const auto l : locations)
106-
dependencies.insert(l);
106+
dependencest dependencies(locations.begin(), locations.end());
107107

108108
return insert_data_deps(dependencies);
109109
}
110110

111+
abstract_object_pointert set_data_deps(const locationst &locations) const
112+
{
113+
// `locationst` is unsorted, so convert this to a sorted `dependenciest`
114+
dependencest dependencies(locations.begin(), locations.end());
115+
116+
return set_data_deps(dependencies);
117+
}
118+
111119
};
112120

113121
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_DATA_DEPENDENCY_CONTEXT_H

0 commit comments

Comments
 (0)