-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Interprocedural escape/alias analysis in IR construction #792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
As I mentioned in the meeting yesterday, let's remember to add sound handling of virtual dispatch. |
|
@jbj @dave-bartolomeo I've added sound handling of virtual dispatch; is there anything else this PR is waiting on? |
|
I didn't know this was ready for review. Can you please describe what problem is being solved, what your solution is, and what problems remain? Ideally this should be as code or commit comments, but PR comments will also do. As always, I'd like to see performance numbers on Wireshark and other large databases. You can find an up-to-date Wireshark snapshot in https://drive.google.com/drive/folders/0B5VJBNgK-GjvREQ4Y2ZicmM2VEk. Before evaluating performance, please rebase on |
|
Briefly, this improves our escape analysis for variable addresses such that It may also result in improvements to alias analysis in cases where the return value of a function is always a particular argument, but this is less common. |
|
Benchmarked it today; it looks like about a 10% slowdown in IR construction (2526 seconds vs 2798 seconds on a Wireshark snapshot). I'll fix the conflicts and rebase |
79fa09f to
8dc8d1c
Compare
jbj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I talked about in the meeting, I think performance of this can be good if we avoid recursion through forall.
| ) | ||
| ) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace
| * escapes outside the domain of the analysis. | ||
| */ | ||
| predicate operandEscapes(Operand operand) { | ||
| predicate operandEscapes(Operand operand) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace
|
I've done a big performance refactor; it looks like this PR is now a slowdown of about 2.5% on Wireshark. |
|
The test failures look like it's now considering pointers passed as parameters to be non-escaping in the callee by default. @dave-bartolomeo and I have discussed this as something we might want to do anyways, but I don't think we've done the work to show that it actually improves results. @jbj what do you think? |
|
I misunderstood the test change; it's actually due to adding models, and we're still assuming the addresses of parameters are escaped. |
|
I've opened rdmarsh2#1 (a PR against this PR) to fix the last performance problem. When that's merged, performance LGTM. Then there's just the test failures left to fix before we can merge this. |
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll
Show resolved
Hide resolved
39bfce8 to
6ca9ace
Compare
jbj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few review comments and a failing test.
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll
Outdated
Show resolved
Hide resolved
507c949 to
6aa8944
Compare
The `automaticVariableAddressEscapes` predicate got join-ordered badly
in its `unaliased_ssa` version. These are the tuple counts on Wireshark,
where one pipeline step is seen to have 716 million tuples:
```
[2019-03-02 11:29:41] (42s) Starting to evaluate predicate AliasAnalysis::automaticVariableAddressEscapes#2#f
[2019-03-02 11:30:06] (67s) Tuple counts:
353419 ~0% {1} r1 = JOIN project#Instruction::VariableAddressInstruction#class#2#ff WITH AliasAnalysis::resultEscapesNonReturn#2#f ON project#Instruction::VariableAddressInstruction#class#2#ff.<0>=AliasAnalysis::resultEscapesNonReturn#2#f.<0> OUTPUT FIELDS {AliasAnalysis::resultEscapesNonReturn#2#f.<0>}
353419 ~0% {2} r2 = JOIN r1 WITH IRConstruction::Cached::getInstructionEnclosingFunctionIR#ff@staged_ext ON r1.<0>=IRConstruction::Cached::getInstructionEnclosingFunctionIR#ff@staged_ext.<0> OUTPUT FIELDS {IRConstruction::Cached::getInstructionEnclosingFunctionIR#ff@staged_ext.<1>,r1.<0>}
353419 ~0% {2} r3 = JOIN r2 WITH FunctionIR::FunctionIR::getFunction_dispred#3#ff ON r2.<0>=FunctionIR::FunctionIR::getFunction_dispred#3#ff.<0> OUTPUT FIELDS {FunctionIR::FunctionIR::getFunction_dispred#3#ff.<1>,r2.<1>}
716040298 ~0% {2} r4 = JOIN r3 WITH IRVariable::IRVariable#class#3#ff_10#join_rhs ON r3.<0>=IRVariable::IRVariable#class#3#ff_10#join_rhs.<0> OUTPUT FIELDS {IRVariable::IRVariable#class#3#ff_10#join_rhs.<1>,r3.<1>}
4480139 ~0% {2} r5 = JOIN r4 WITH IRVariable::IRAutomaticVariable#class#3#ff ON r4.<0>=IRVariable::IRAutomaticVariable#class#3#ff.<0> OUTPUT FIELDS {r4.<1>,r4.<0>}
66760 ~91% {1} r6 = JOIN r5 WITH Instruction::VariableInstruction::getVariable_dispred#2#ff ON r5.<0>=Instruction::VariableInstruction::getVariable_dispred#2#ff.<0> AND r5.<1>=Instruction::VariableInstruction::getVariable_dispred#2#ff.<1> OUTPUT FIELDS {r5.<1>}
return r6
[2019-03-02 11:30:06] (67s) >>> Relation AliasAnalysis::automaticVariableAddressEscapes#2#f: 35531 rows using 0 MB
```
The predicate contained a cyclic join, which is always hard to optimize.
I couldn't see a reason to join the `FunctionIR`, so I removed that
part. The predicate is now fast, and there are no changes in the tests.
92600e9 to
07bc9ca
Compare
jbj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR isn't quite finished; I'm going to need to add support for
thisparameters. I'm opening it early to see test results for IR-based libraries and to get discussion started.