mirror of
https://github.com/github/codeql.git
synced 2026-04-22 23:35:14 +02:00
C++: Drive-by join order fix. Before:
```
Evaluated relational algebra for predicate SsaInternals::getDefImpl/1#1ed4f567@65628fbv with tuple counts:
4935102 ~5% {4} r1 = SCAN `SsaInternals::SsaImpl::Definition.definesAt/3#dispred#7eea4c8f` OUTPUT In.2, In.3, In.0, In.1
104274503 ~1% {3} | JOIN WITH `SsaInternals::DefImpl.hasIndexInBlock/2#dispred#30a6c29f_120#join_rhs` ON FIRST 2 OUTPUT Rhs.2, Lhs.3, Lhs.2
4921319 ~2% {2} | JOIN WITH `SsaInternals::DefImpl.getSourceVariable/0#dispred#72437659` ON FIRST 2 OUTPUT Lhs.2, Lhs.0
return r1
```
After:
```
Evaluated relational algebra for predicate SsaInternals::SsaImpl::Definition.definesAt/3#dispred#7eea4c8f_1230#join_rhs@b280fb5h with tuple counts:
4935102 ~3% {4} r1 = SCAN `SsaInternals::SsaImpl::Definition.definesAt/3#dispred#7eea4c8f` OUTPUT In.1, In.2, In.3, In.0
return r1
Evaluated relational algebra for predicate SsaInternals::DefImpl.hasIndexInBlock/3#dispred#31d295aa_1230#join_rhs@2be655s4 with tuple counts:
5634706 ~1% {4} r1 = SCAN `SsaInternals::DefImpl.hasIndexInBlock/3#dispred#31d295aa` OUTPUT In.1, In.2, In.3, In.0
return r1
Evaluated relational algebra for predicate SsaInternals::getDefImpl/1#1ed4f567@8afa36uu with tuple counts:
4921319 ~2% {2} r1 = JOIN `SsaInternals::SsaImpl::Definition.definesAt/3#dispred#7eea4c8f_1230#join_rhs` WITH `SsaInternals::DefImpl.hasIndexInBlock/3#dispred#31d295aa_1230#join_rhs` ON FIRST 3 OUTPUT Lhs.3, Rhs.3
return r1
```
This commit is contained in:
@@ -1567,7 +1567,7 @@ private int countNumberOfBranchesUsingParameter(SwitchInstruction switch, Parame
|
||||
|
|
||||
exists(Ssa::UseImpl use | use.hasIndexInBlock(useblock, _, sv))
|
||||
or
|
||||
exists(Ssa::DefImpl def | def.hasIndexInBlock(useblock, _, sv))
|
||||
exists(Ssa::DefImpl def | def.hasIndexInBlock(sv, useblock, _))
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -1814,7 +1814,7 @@ module IteratorFlow {
|
||||
*/
|
||||
private predicate isIteratorWrite(Instruction write, Operand address) {
|
||||
exists(Ssa::DefImpl writeDef, IRBlock bb, int i |
|
||||
writeDef.hasIndexInBlock(bb, i, _) and
|
||||
writeDef.hasIndexInBlock(_, bb, i) and
|
||||
bb.getInstruction(i) = write and
|
||||
address = writeDef.getAddressOperand()
|
||||
)
|
||||
|
||||
@@ -191,7 +191,7 @@ abstract class DefImpl extends TDefImpl {
|
||||
* Holds if this definition (or use) has index `index` in block `block`,
|
||||
* and is a definition (or use) of the variable `sv`
|
||||
*/
|
||||
final predicate hasIndexInBlock(IRBlock block, int index, SourceVariable sv) {
|
||||
final predicate hasIndexInBlock(SourceVariable sv, IRBlock block, int index) {
|
||||
this.hasIndexInBlock(block, index) and
|
||||
sv = this.getSourceVariable()
|
||||
}
|
||||
@@ -891,12 +891,12 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
|
||||
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
|
||||
DataFlowImplCommon::forceCachingInSameStage() and
|
||||
(
|
||||
exists(DefImpl def | def.hasIndexInBlock(bb, i, v) |
|
||||
exists(DefImpl def | def.hasIndexInBlock(v, bb, i) |
|
||||
if def.isCertain() then certain = true else certain = false
|
||||
)
|
||||
or
|
||||
exists(GlobalDefImpl global |
|
||||
global.hasIndexInBlock(bb, i, v) and
|
||||
global.hasIndexInBlock(v, bb, i) and
|
||||
certain = true
|
||||
)
|
||||
)
|
||||
@@ -934,10 +934,11 @@ module SsaCached {
|
||||
}
|
||||
|
||||
/** Gets the `DefImpl` corresponding to `def`. */
|
||||
pragma[nomagic]
|
||||
private DefImpl getDefImpl(SsaImpl::Definition def) {
|
||||
exists(SourceVariable sv, IRBlock bb, int i |
|
||||
def.definesAt(sv, bb, i) and
|
||||
result.hasIndexInBlock(bb, i, sv)
|
||||
result.hasIndexInBlock(sv, bb, i)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user