Skip to content

Commit 80ec5c1

Browse files
author
Robert Marsh
authored
Merge pull request #2983 from jbj/definitionReachesRank-perf
C++: IR: faster definitionReachesRank
2 parents c5d3903 + 6b2fd17 commit 80ec5c1

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,18 @@ module DefUse {
665665
private predicate definitionReachesRank(
666666
Alias::MemoryLocation useLocation, OldBlock block, int defRank, int reachesRank
667667
) {
668+
// The def always reaches the next use, even if there is also a def on the
669+
// use instruction.
668670
hasDefinitionAtRank(useLocation, _, block, defRank, _) and
669-
reachesRank <= exitRank(useLocation, block) and // Without this, the predicate would be infinite.
670-
(
671-
// The def always reaches the next use, even if there is also a def on the
672-
// use instruction.
673-
reachesRank = defRank + 1
674-
or
675-
// If the def reached the previous rank, it also reaches the current rank,
676-
// unless there was another def at the previous rank.
677-
definitionReachesRank(useLocation, block, defRank, reachesRank - 1) and
678-
not hasDefinitionAtRank(useLocation, _, block, reachesRank - 1, _)
671+
reachesRank = defRank + 1
672+
or
673+
// If the def reached the previous rank, it also reaches the current rank,
674+
// unless there was another def at the previous rank.
675+
exists(int prevRank |
676+
reachesRank = prevRank + 1 and
677+
definitionReachesRank(useLocation, block, defRank, prevRank) and
678+
not prevRank = exitRank(useLocation, block) and
679+
not hasDefinitionAtRank(useLocation, _, block, prevRank, _)
679680
)
680681
}
681682

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,18 @@ module DefUse {
665665
private predicate definitionReachesRank(
666666
Alias::MemoryLocation useLocation, OldBlock block, int defRank, int reachesRank
667667
) {
668+
// The def always reaches the next use, even if there is also a def on the
669+
// use instruction.
668670
hasDefinitionAtRank(useLocation, _, block, defRank, _) and
669-
reachesRank <= exitRank(useLocation, block) and // Without this, the predicate would be infinite.
670-
(
671-
// The def always reaches the next use, even if there is also a def on the
672-
// use instruction.
673-
reachesRank = defRank + 1
674-
or
675-
// If the def reached the previous rank, it also reaches the current rank,
676-
// unless there was another def at the previous rank.
677-
definitionReachesRank(useLocation, block, defRank, reachesRank - 1) and
678-
not hasDefinitionAtRank(useLocation, _, block, reachesRank - 1, _)
671+
reachesRank = defRank + 1
672+
or
673+
// If the def reached the previous rank, it also reaches the current rank,
674+
// unless there was another def at the previous rank.
675+
exists(int prevRank |
676+
reachesRank = prevRank + 1 and
677+
definitionReachesRank(useLocation, block, defRank, prevRank) and
678+
not prevRank = exitRank(useLocation, block) and
679+
not hasDefinitionAtRank(useLocation, _, block, prevRank, _)
679680
)
680681
}
681682

csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,18 @@ module DefUse {
665665
private predicate definitionReachesRank(
666666
Alias::MemoryLocation useLocation, OldBlock block, int defRank, int reachesRank
667667
) {
668+
// The def always reaches the next use, even if there is also a def on the
669+
// use instruction.
668670
hasDefinitionAtRank(useLocation, _, block, defRank, _) and
669-
reachesRank <= exitRank(useLocation, block) and // Without this, the predicate would be infinite.
670-
(
671-
// The def always reaches the next use, even if there is also a def on the
672-
// use instruction.
673-
reachesRank = defRank + 1
674-
or
675-
// If the def reached the previous rank, it also reaches the current rank,
676-
// unless there was another def at the previous rank.
677-
definitionReachesRank(useLocation, block, defRank, reachesRank - 1) and
678-
not hasDefinitionAtRank(useLocation, _, block, reachesRank - 1, _)
671+
reachesRank = defRank + 1
672+
or
673+
// If the def reached the previous rank, it also reaches the current rank,
674+
// unless there was another def at the previous rank.
675+
exists(int prevRank |
676+
reachesRank = prevRank + 1 and
677+
definitionReachesRank(useLocation, block, defRank, prevRank) and
678+
not prevRank = exitRank(useLocation, block) and
679+
not hasDefinitionAtRank(useLocation, _, block, prevRank, _)
679680
)
680681
}
681682

0 commit comments

Comments
 (0)