Skip to content

Commit 4099d13

Browse files
committed
Data flow: Tweak two join-orders
Before ``` [2022-04-06 13:19:29] (96s) Tuple counts for DataFlowImpl2::Stage1::revFlowConsCand#7ad53399#ff/2@i14#aa10f2wi after 4.4s: 10681 ~0% {2} r1 = SCAN DataFlowImpl2::Stage1::revFlow#7ad53399#fff#prev_delta OUTPUT In.0, In.2 'config' 982 ~1% {3} r2 = JOIN r1 WITH DataFlowImpl2::readSet#7ad53399#ffff_2301#join_rhs ON FIRST 2 OUTPUT Rhs.3, Lhs.1 'config', Rhs.2 83691528 ~2% {3} r3 = JOIN r2 WITH DataFlowPublic::ContentSet::getAReadContent#dispred#f0820431#ff ON FIRST 1 OUTPUT Lhs.1 'config', Lhs.2, Rhs.1 'c' 83581763 ~2% {3} r4 = r3 AND NOT DataFlowImpl2::Stage1::revFlowConsCand#7ad53399#ff#prev(Lhs.2 'c', Lhs.0 'config') 83581763 ~0% {3} r5 = SCAN r4 OUTPUT In.2 'c', In.0 'config', In.1 0 ~0% {3} r6 = JOIN r5 WITH DataFlowImpl2::Stage1::fwdFlowConsCand#7ad53399#ff ON FIRST 2 OUTPUT Lhs.2, Lhs.1 'config', Lhs.0 'c' 0 ~0% {2} r7 = JOIN r6 WITH DataFlowImpl2::Stage1::fwdFlow#7ad53399#2#fff_02#join_rhs ON FIRST 2 OUTPUT Lhs.2 'c', Lhs.1 'config' return r7 ``` After ``` [2022-04-06 13:44:38] (6s) Tuple counts for DataFlowImpl2::Stage1::revFlowConsCand#7ad53399#ff/2@i14#5abbf2wn after 6ms: 10681 ~0% {2} r1 = SCAN DataFlowImpl2::Stage1::revFlow#7ad53399#fff#prev_delta OUTPUT In.0, In.2 'config' 982 ~1% {3} r2 = JOIN r1 WITH DataFlowImpl2::readSet#7ad53399#ffff_2301#join_rhs ON FIRST 2 OUTPUT Rhs.3, Lhs.1 'config', Rhs.2 109765 ~0% {3} r3 = JOIN r2 WITH DataFlowImpl2::Stage1::fwdFlowConsCandSet#7ad53399#fff#reorder_0_2_1 ON FIRST 2 OUTPUT Lhs.1 'config', Lhs.2, Rhs.2 'c' 0 ~0% {3} r4 = r3 AND NOT DataFlowImpl2::Stage1::revFlowConsCand#7ad53399#ff#prev(Lhs.2 'c', Lhs.0 'config') 0 ~0% {3} r5 = SCAN r4 OUTPUT In.1, In.0 'config', In.2 'c' 0 ~0% {2} r6 = JOIN r5 WITH DataFlowImpl2::Stage1::fwdFlow#7ad53399#2#fff_02#join_rhs ON FIRST 2 OUTPUT Lhs.2 'c', Lhs.1 'config' return r6 ```
1 parent cee527e commit 4099d13

29 files changed

+377
-348
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private module Stage1 {
648648
// read
649649
exists(ContentSet c |
650650
fwdFlowReadSet(c, node, cc, config) and
651-
fwdFlowConsCandSet(c, config)
651+
fwdFlowConsCandSet(c, _, config)
652652
)
653653
or
654654
// flow into a callable
@@ -693,12 +693,13 @@ private module Stage1 {
693693
}
694694

695695
/**
696-
* Holds if `c` may be interpreted in a read as the target of some store,
697-
* in the flow covered by `fwdFlow`.
696+
* Holds if `cs` may be interpreted in a read as the target of some store
697+
* into `c`, in the flow covered by `fwdFlow`.
698698
*/
699699
pragma[nomagic]
700-
private predicate fwdFlowConsCandSet(ContentSet c, Configuration config) {
701-
fwdFlowConsCand(c.getAReadContent(), config)
700+
private predicate fwdFlowConsCandSet(ContentSet cs, Content c, Configuration config) {
701+
fwdFlowConsCand(c, config) and
702+
c = cs.getAReadContent()
702703
}
703704

704705
pragma[nomagic]
@@ -795,7 +796,7 @@ private module Stage1 {
795796
// read
796797
exists(NodeEx mid, ContentSet c |
797798
readSet(node, c, mid, config) and
798-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
799+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
799800
revFlow(mid, toReturn, pragma[only_bind_into](config))
800801
)
801802
or
@@ -821,10 +822,10 @@ private module Stage1 {
821822
*/
822823
pragma[nomagic]
823824
private predicate revFlowConsCand(Content c, Configuration config) {
824-
exists(NodeEx mid, NodeEx node |
825+
exists(NodeEx mid, NodeEx node, ContentSet cs |
825826
fwdFlow(node, pragma[only_bind_into](config)) and
826-
read(node, c, mid, config) and
827-
fwdFlowConsCand(c, pragma[only_bind_into](config)) and
827+
readSet(node, cs, mid, config) and
828+
fwdFlowConsCandSet(cs, c, pragma[only_bind_into](config)) and
828829
revFlow(pragma[only_bind_into](mid), _, pragma[only_bind_into](config))
829830
)
830831
}
@@ -840,7 +841,7 @@ private module Stage1 {
840841
) {
841842
exists(NodeEx mid |
842843
revFlow(mid, toReturn, pragma[only_bind_into](config)) and
843-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
844+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
844845
storeSet(node, c, mid, _, _, config)
845846
)
846847
}
@@ -851,9 +852,9 @@ private module Stage1 {
851852
*/
852853
pragma[nomagic]
853854
private predicate revFlowIsReadAndStored(Content c, Configuration conf) {
854-
revFlowConsCand(c, conf) and
855+
revFlowConsCand(c, pragma[only_bind_into](conf)) and
855856
exists(ContentSet cs |
856-
revFlowStoreSet(cs, _, _, conf) and
857+
revFlowStoreSet(cs, _, _, pragma[only_bind_into](conf)) and
857858
c = cs.getAStoreContent()
858859
)
859860
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private module Stage1 {
648648
// read
649649
exists(ContentSet c |
650650
fwdFlowReadSet(c, node, cc, config) and
651-
fwdFlowConsCandSet(c, config)
651+
fwdFlowConsCandSet(c, _, config)
652652
)
653653
or
654654
// flow into a callable
@@ -693,12 +693,13 @@ private module Stage1 {
693693
}
694694

695695
/**
696-
* Holds if `c` may be interpreted in a read as the target of some store,
697-
* in the flow covered by `fwdFlow`.
696+
* Holds if `cs` may be interpreted in a read as the target of some store
697+
* into `c`, in the flow covered by `fwdFlow`.
698698
*/
699699
pragma[nomagic]
700-
private predicate fwdFlowConsCandSet(ContentSet c, Configuration config) {
701-
fwdFlowConsCand(c.getAReadContent(), config)
700+
private predicate fwdFlowConsCandSet(ContentSet cs, Content c, Configuration config) {
701+
fwdFlowConsCand(c, config) and
702+
c = cs.getAReadContent()
702703
}
703704

704705
pragma[nomagic]
@@ -795,7 +796,7 @@ private module Stage1 {
795796
// read
796797
exists(NodeEx mid, ContentSet c |
797798
readSet(node, c, mid, config) and
798-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
799+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
799800
revFlow(mid, toReturn, pragma[only_bind_into](config))
800801
)
801802
or
@@ -821,10 +822,10 @@ private module Stage1 {
821822
*/
822823
pragma[nomagic]
823824
private predicate revFlowConsCand(Content c, Configuration config) {
824-
exists(NodeEx mid, NodeEx node |
825+
exists(NodeEx mid, NodeEx node, ContentSet cs |
825826
fwdFlow(node, pragma[only_bind_into](config)) and
826-
read(node, c, mid, config) and
827-
fwdFlowConsCand(c, pragma[only_bind_into](config)) and
827+
readSet(node, cs, mid, config) and
828+
fwdFlowConsCandSet(cs, c, pragma[only_bind_into](config)) and
828829
revFlow(pragma[only_bind_into](mid), _, pragma[only_bind_into](config))
829830
)
830831
}
@@ -840,7 +841,7 @@ private module Stage1 {
840841
) {
841842
exists(NodeEx mid |
842843
revFlow(mid, toReturn, pragma[only_bind_into](config)) and
843-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
844+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
844845
storeSet(node, c, mid, _, _, config)
845846
)
846847
}
@@ -851,9 +852,9 @@ private module Stage1 {
851852
*/
852853
pragma[nomagic]
853854
private predicate revFlowIsReadAndStored(Content c, Configuration conf) {
854-
revFlowConsCand(c, conf) and
855+
revFlowConsCand(c, pragma[only_bind_into](conf)) and
855856
exists(ContentSet cs |
856-
revFlowStoreSet(cs, _, _, conf) and
857+
revFlowStoreSet(cs, _, _, pragma[only_bind_into](conf)) and
857858
c = cs.getAStoreContent()
858859
)
859860
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private module Stage1 {
648648
// read
649649
exists(ContentSet c |
650650
fwdFlowReadSet(c, node, cc, config) and
651-
fwdFlowConsCandSet(c, config)
651+
fwdFlowConsCandSet(c, _, config)
652652
)
653653
or
654654
// flow into a callable
@@ -693,12 +693,13 @@ private module Stage1 {
693693
}
694694

695695
/**
696-
* Holds if `c` may be interpreted in a read as the target of some store,
697-
* in the flow covered by `fwdFlow`.
696+
* Holds if `cs` may be interpreted in a read as the target of some store
697+
* into `c`, in the flow covered by `fwdFlow`.
698698
*/
699699
pragma[nomagic]
700-
private predicate fwdFlowConsCandSet(ContentSet c, Configuration config) {
701-
fwdFlowConsCand(c.getAReadContent(), config)
700+
private predicate fwdFlowConsCandSet(ContentSet cs, Content c, Configuration config) {
701+
fwdFlowConsCand(c, config) and
702+
c = cs.getAReadContent()
702703
}
703704

704705
pragma[nomagic]
@@ -795,7 +796,7 @@ private module Stage1 {
795796
// read
796797
exists(NodeEx mid, ContentSet c |
797798
readSet(node, c, mid, config) and
798-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
799+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
799800
revFlow(mid, toReturn, pragma[only_bind_into](config))
800801
)
801802
or
@@ -821,10 +822,10 @@ private module Stage1 {
821822
*/
822823
pragma[nomagic]
823824
private predicate revFlowConsCand(Content c, Configuration config) {
824-
exists(NodeEx mid, NodeEx node |
825+
exists(NodeEx mid, NodeEx node, ContentSet cs |
825826
fwdFlow(node, pragma[only_bind_into](config)) and
826-
read(node, c, mid, config) and
827-
fwdFlowConsCand(c, pragma[only_bind_into](config)) and
827+
readSet(node, cs, mid, config) and
828+
fwdFlowConsCandSet(cs, c, pragma[only_bind_into](config)) and
828829
revFlow(pragma[only_bind_into](mid), _, pragma[only_bind_into](config))
829830
)
830831
}
@@ -840,7 +841,7 @@ private module Stage1 {
840841
) {
841842
exists(NodeEx mid |
842843
revFlow(mid, toReturn, pragma[only_bind_into](config)) and
843-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
844+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
844845
storeSet(node, c, mid, _, _, config)
845846
)
846847
}
@@ -851,9 +852,9 @@ private module Stage1 {
851852
*/
852853
pragma[nomagic]
853854
private predicate revFlowIsReadAndStored(Content c, Configuration conf) {
854-
revFlowConsCand(c, conf) and
855+
revFlowConsCand(c, pragma[only_bind_into](conf)) and
855856
exists(ContentSet cs |
856-
revFlowStoreSet(cs, _, _, conf) and
857+
revFlowStoreSet(cs, _, _, pragma[only_bind_into](conf)) and
857858
c = cs.getAStoreContent()
858859
)
859860
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private module Stage1 {
648648
// read
649649
exists(ContentSet c |
650650
fwdFlowReadSet(c, node, cc, config) and
651-
fwdFlowConsCandSet(c, config)
651+
fwdFlowConsCandSet(c, _, config)
652652
)
653653
or
654654
// flow into a callable
@@ -693,12 +693,13 @@ private module Stage1 {
693693
}
694694

695695
/**
696-
* Holds if `c` may be interpreted in a read as the target of some store,
697-
* in the flow covered by `fwdFlow`.
696+
* Holds if `cs` may be interpreted in a read as the target of some store
697+
* into `c`, in the flow covered by `fwdFlow`.
698698
*/
699699
pragma[nomagic]
700-
private predicate fwdFlowConsCandSet(ContentSet c, Configuration config) {
701-
fwdFlowConsCand(c.getAReadContent(), config)
700+
private predicate fwdFlowConsCandSet(ContentSet cs, Content c, Configuration config) {
701+
fwdFlowConsCand(c, config) and
702+
c = cs.getAReadContent()
702703
}
703704

704705
pragma[nomagic]
@@ -795,7 +796,7 @@ private module Stage1 {
795796
// read
796797
exists(NodeEx mid, ContentSet c |
797798
readSet(node, c, mid, config) and
798-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
799+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
799800
revFlow(mid, toReturn, pragma[only_bind_into](config))
800801
)
801802
or
@@ -821,10 +822,10 @@ private module Stage1 {
821822
*/
822823
pragma[nomagic]
823824
private predicate revFlowConsCand(Content c, Configuration config) {
824-
exists(NodeEx mid, NodeEx node |
825+
exists(NodeEx mid, NodeEx node, ContentSet cs |
825826
fwdFlow(node, pragma[only_bind_into](config)) and
826-
read(node, c, mid, config) and
827-
fwdFlowConsCand(c, pragma[only_bind_into](config)) and
827+
readSet(node, cs, mid, config) and
828+
fwdFlowConsCandSet(cs, c, pragma[only_bind_into](config)) and
828829
revFlow(pragma[only_bind_into](mid), _, pragma[only_bind_into](config))
829830
)
830831
}
@@ -840,7 +841,7 @@ private module Stage1 {
840841
) {
841842
exists(NodeEx mid |
842843
revFlow(mid, toReturn, pragma[only_bind_into](config)) and
843-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
844+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
844845
storeSet(node, c, mid, _, _, config)
845846
)
846847
}
@@ -851,9 +852,9 @@ private module Stage1 {
851852
*/
852853
pragma[nomagic]
853854
private predicate revFlowIsReadAndStored(Content c, Configuration conf) {
854-
revFlowConsCand(c, conf) and
855+
revFlowConsCand(c, pragma[only_bind_into](conf)) and
855856
exists(ContentSet cs |
856-
revFlowStoreSet(cs, _, _, conf) and
857+
revFlowStoreSet(cs, _, _, pragma[only_bind_into](conf)) and
857858
c = cs.getAStoreContent()
858859
)
859860
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private module Stage1 {
648648
// read
649649
exists(ContentSet c |
650650
fwdFlowReadSet(c, node, cc, config) and
651-
fwdFlowConsCandSet(c, config)
651+
fwdFlowConsCandSet(c, _, config)
652652
)
653653
or
654654
// flow into a callable
@@ -693,12 +693,13 @@ private module Stage1 {
693693
}
694694

695695
/**
696-
* Holds if `c` may be interpreted in a read as the target of some store,
697-
* in the flow covered by `fwdFlow`.
696+
* Holds if `cs` may be interpreted in a read as the target of some store
697+
* into `c`, in the flow covered by `fwdFlow`.
698698
*/
699699
pragma[nomagic]
700-
private predicate fwdFlowConsCandSet(ContentSet c, Configuration config) {
701-
fwdFlowConsCand(c.getAReadContent(), config)
700+
private predicate fwdFlowConsCandSet(ContentSet cs, Content c, Configuration config) {
701+
fwdFlowConsCand(c, config) and
702+
c = cs.getAReadContent()
702703
}
703704

704705
pragma[nomagic]
@@ -795,7 +796,7 @@ private module Stage1 {
795796
// read
796797
exists(NodeEx mid, ContentSet c |
797798
readSet(node, c, mid, config) and
798-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
799+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
799800
revFlow(mid, toReturn, pragma[only_bind_into](config))
800801
)
801802
or
@@ -821,10 +822,10 @@ private module Stage1 {
821822
*/
822823
pragma[nomagic]
823824
private predicate revFlowConsCand(Content c, Configuration config) {
824-
exists(NodeEx mid, NodeEx node |
825+
exists(NodeEx mid, NodeEx node, ContentSet cs |
825826
fwdFlow(node, pragma[only_bind_into](config)) and
826-
read(node, c, mid, config) and
827-
fwdFlowConsCand(c, pragma[only_bind_into](config)) and
827+
readSet(node, cs, mid, config) and
828+
fwdFlowConsCandSet(cs, c, pragma[only_bind_into](config)) and
828829
revFlow(pragma[only_bind_into](mid), _, pragma[only_bind_into](config))
829830
)
830831
}
@@ -840,7 +841,7 @@ private module Stage1 {
840841
) {
841842
exists(NodeEx mid |
842843
revFlow(mid, toReturn, pragma[only_bind_into](config)) and
843-
fwdFlowConsCandSet(c, pragma[only_bind_into](config)) and
844+
fwdFlowConsCandSet(c, _, pragma[only_bind_into](config)) and
844845
storeSet(node, c, mid, _, _, config)
845846
)
846847
}
@@ -851,9 +852,9 @@ private module Stage1 {
851852
*/
852853
pragma[nomagic]
853854
private predicate revFlowIsReadAndStored(Content c, Configuration conf) {
854-
revFlowConsCand(c, conf) and
855+
revFlowConsCand(c, pragma[only_bind_into](conf)) and
855856
exists(ContentSet cs |
856-
revFlowStoreSet(cs, _, _, conf) and
857+
revFlowStoreSet(cs, _, _, pragma[only_bind_into](conf)) and
857858
c = cs.getAStoreContent()
858859
)
859860
}

0 commit comments

Comments
 (0)