Skip to content

Commit 82644bc

Browse files
committed
M14-6-3: Address perf problems
Performance issues occurred because we are trying to find pairs of functions or variables which have the same name but are not the same. The join orderer is very keen on joining two copies of the function/ variable table early on which, on large databases like openpilot with a lot of name duplication, can cause signficant blow-up. The workaround is to provide helper predicates that ensure the restricted set of functions/variables we care about (targets of accesses or calls in templates with dependent base types) are computed first, then the name is joined with a member on the dependent base type.
1 parent 8d89f17 commit 82644bc

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,98 @@ TemplateClass getADependentBaseType(TemplateClass t) {
1717
)
1818
}
1919

20+
/**
21+
* Helper predicate that ensures we do not join on function pairs by name early on, as that creates
22+
* a large dataset on big databases with lots of name duplication.
23+
*/
24+
pragma[noinline, nomagic]
25+
private FunctionCall helper_functioncall(
26+
TemplateClass t, TemplateClass dependentBaseType, Function target, string name
27+
) {
28+
dependentBaseType = getADependentBaseType(t) and
29+
// The target of the call is not declared in the dependent base type
30+
not target.getDeclaringType() = dependentBaseType and
31+
result = target.getACallToThisFunction() and
32+
result.getEnclosingFunction() = t.getAMemberFunction() and
33+
name = target.getName()
34+
}
35+
2036
/**
2137
* Gets a function call in `TemplateClass` `t` where the target function name exists in a dependent
2238
* base type and the call is to a function that is not declared in the dependent base type.
2339
*/
2440
FunctionCall parentMemberFunctionCall(TemplateClass t) {
25-
exists(TemplateClass dependentBaseType, MemberFunction dependentTypeFunction, Function target |
26-
dependentBaseType = getADependentBaseType(t) and
27-
// The target of the call is not declared in the dependent base type
28-
not target.getDeclaringType() = dependentBaseType and
41+
exists(
42+
string name, TemplateClass dependentBaseType, MemberFunction dependentTypeFunction,
43+
Function target
44+
|
45+
result = helper_functioncall(t, dependentBaseType, target, name) and
46+
// The dependentTypeFunction is declared on the dependent base type
2947
dependentBaseType.getAMember() = dependentTypeFunction and
30-
target.getName() = dependentTypeFunction.getName() and
31-
result = target.getACallToThisFunction() and
32-
result.getEnclosingFunction() = t.getAMemberFunction()
48+
// And has the same name as the target of the function call in the child
49+
name = dependentTypeFunction.getName()
3350
)
3451
}
3552

53+
/**
54+
* Helper predicate that ensures we do not join on function pairs by name early on, as that creates
55+
* a large dataset on big databases with lots of name duplication.
56+
*/
57+
pragma[noinline, nomagic]
58+
private FunctionAccess helper_functionaccess(
59+
TemplateClass t, TemplateClass dependentBaseType, Function target, string name
60+
) {
61+
dependentBaseType = getADependentBaseType(t) and
62+
// The target of the access is not declared in the dependent base type
63+
not target.getDeclaringType() = dependentBaseType and
64+
result = target.getAnAccess() and
65+
result.getEnclosingFunction() = t.getAMemberFunction() and
66+
name = target.getName()
67+
}
68+
3669
/**
3770
* Gets a function access in `TemplateClass` `t` where the target function name exists in a dependent
3871
* base type and the access is to a function declared outside the dependent base type.
3972
*/
4073
FunctionAccess parentMemberFunctionAccess(TemplateClass t) {
41-
exists(TemplateClass dependentBaseType, MemberFunction dependentTypeFunction, Function target |
42-
dependentBaseType = getADependentBaseType(t) and
43-
// The target of the access is not declared in the dependent base type
44-
not target.getDeclaringType() = dependentBaseType and
74+
exists(
75+
string name, TemplateClass dependentBaseType, MemberFunction dependentTypeFunction,
76+
Function target
77+
|
78+
result = helper_functionaccess(t, dependentBaseType, target, name) and
4579
dependentBaseType.getAMember() = dependentTypeFunction and
46-
target.getName() = dependentTypeFunction.getName() and
47-
result = target.getAnAccess() and
48-
result.getEnclosingFunction() = t.getAMemberFunction()
80+
name = dependentTypeFunction.getName()
4981
)
5082
}
5183

84+
/**
85+
* Helper predicate that ensures we do not join on variable pairs by name early on, as that creates
86+
* a large dataset on big databases with lots of name duplication.
87+
*/
88+
pragma[noinline, nomagic]
89+
private VariableAccess helper_memberaccess(
90+
TemplateClass t, TemplateClass dependentBaseType, Variable target, string name
91+
) {
92+
dependentBaseType = getADependentBaseType(t) and
93+
// The target of the access is not declared in the dependent base type
94+
not target.getDeclaringType() = dependentBaseType and
95+
result = target.getAnAccess() and
96+
result.getEnclosingFunction() = t.getAMemberFunction() and
97+
name = target.getName()
98+
}
99+
52100
/**
53101
* Gets a memmber access in `TemplateClass` `t` where the target member name exists in a dependent
54102
* base type and the access is to a variable declared outside the dependent base type.
55103
*/
56-
Access parentMemberAccess(TemplateClass t) {
104+
VariableAccess parentMemberAccess(TemplateClass t) {
57105
exists(
58-
TemplateClass dependentBaseType, MemberVariable dependentTypeMemberVariable, Variable target
106+
string name, TemplateClass dependentBaseType, MemberVariable dependentTypeMemberVariable,
107+
Variable target
59108
|
60-
dependentBaseType = getADependentBaseType(t) and
61-
// The target of the access is not declared in the dependent base type
62-
not target.getDeclaringType() = dependentBaseType and
109+
result = helper_memberaccess(t, dependentBaseType, target, name) and
63110
dependentBaseType.getAMemberVariable() = dependentTypeMemberVariable and
64-
target.getName() = dependentTypeMemberVariable.getName() and
65-
result = target.getAnAccess() and
66-
result.getEnclosingFunction() = t.getAMemberFunction()
111+
name = dependentTypeMemberVariable.getName()
67112
)
68113
}
69114

0 commit comments

Comments
 (0)