Skip to content

Commit 8abc37f

Browse files
authored
Merge pull request github#5051 from hvitved/csharp/ssa/caching
C#: Reduce caching in `SsaImplCommon.qll`
2 parents 749dfe4 + bf5851f commit 8abc37f

File tree

3 files changed

+420
-420
lines changed

3 files changed

+420
-420
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ module Ssa {
176176
exists(ControlFlow::BasicBlock bb, int i | this.definesAt(_, bb, i) | result = bb.getNode(i))
177177
}
178178

179+
/**
180+
* Holds is this SSA definition is live at the end of basic block `bb`.
181+
* That is, this definition reaches the end of basic block `bb`, at which
182+
* point it is still live, without crossing another SSA definition of the
183+
* same source variable.
184+
*/
185+
final predicate isLiveAtEndOfBlock(ControlFlow::BasicBlock bb) {
186+
SsaImpl::isLiveAtEndOfBlock(this, bb)
187+
}
188+
179189
/**
180190
* Gets a read of the source variable underlying this SSA definition that
181191
* can be reached from this SSA definition without passing through any
@@ -233,12 +243,7 @@ module Ssa {
233243
* node between lines 9 and 10.
234244
*/
235245
final AssignableRead getAReadAtNode(ControlFlow::Node cfn) {
236-
exists(SourceVariable v, ControlFlow::BasicBlock bb, int i |
237-
SsaImpl::ssaDefReachesRead(v, this, bb, i) and
238-
SsaImpl::variableReadActual(bb, i, v) and
239-
cfn = bb.getNode(i) and
240-
result.getAControlFlowNode() = cfn
241-
)
246+
result = SsaImpl::getAReadAtNode(this, cfn)
242247
}
243248

244249
/**

csharp/ql/src/semmle/code/csharp/dataflow/internal/SsaImpl.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SsaImplCommon
88
/**
99
* Holds if the `i`th node of basic block `bb` reads source variable `v`.
1010
*/
11-
predicate variableReadActual(ControlFlow::BasicBlock bb, int i, Ssa::SourceVariable v) {
11+
private predicate variableReadActual(ControlFlow::BasicBlock bb, int i, Ssa::SourceVariable v) {
1212
v.getAnAccess().(AssignableRead) = bb.getNode(i).getElement()
1313
}
1414

@@ -1102,6 +1102,11 @@ private module Cached {
11021102
)
11031103
}
11041104

1105+
cached
1106+
predicate isLiveAtEndOfBlock(Definition def, ControlFlow::BasicBlock bb) {
1107+
ssaDefReachesEndOfBlock(bb, def, _)
1108+
}
1109+
11051110
private predicate adjacentDefReaches(
11061111
Definition def, ControlFlow::BasicBlock bb1, int i1, ControlFlow::BasicBlock bb2, int i2
11071112
) {
@@ -1122,6 +1127,16 @@ private module Cached {
11221127
variableReadActual(bb2, i2, _)
11231128
}
11241129

1130+
cached
1131+
AssignableRead getAReadAtNode(Definition def, ControlFlow::Node cfn) {
1132+
exists(Ssa::SourceVariable v, ControlFlow::BasicBlock bb, int i |
1133+
ssaDefReachesRead(v, def, bb, i) and
1134+
variableReadActual(bb, i, v) and
1135+
cfn = bb.getNode(i) and
1136+
result.getAControlFlowNode() = cfn
1137+
)
1138+
}
1139+
11251140
/**
11261141
* Holds if the value defined at SSA definition `def` can reach a read at `cfn`,
11271142
* without passing through any other read.

0 commit comments

Comments
 (0)