Skip to content

Commit f400228

Browse files
committed
C++: Remove the pruning stage from SSA.
1 parent 331f308 commit f400228

File tree

2 files changed

+13
-384
lines changed

2 files changed

+13
-384
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as FIO
1010
private import semmle.code.cpp.ir.internal.IRCppLanguage
1111
private import semmle.code.cpp.ir.dataflow.internal.ModelUtil
1212
private import DataFlowPrivate
13-
private import ssa0.SsaInternals as SsaInternals0
1413
import SsaInternalsCommon
1514

1615
private module SourceVariables {
1716
cached
1817
private newtype TSourceVariable =
19-
TMkSourceVariable(SsaInternals0::SourceVariable base, int ind) {
18+
TMkSourceVariable(BaseSourceVariable base, int ind) {
2019
ind = [0 .. countIndirectionsForCppType(base.getLanguageType()) + 1]
2120
}
2221

@@ -30,7 +29,7 @@ private module SourceVariables {
3029
}
3130

3231
class SourceVariable extends TSourceVariable {
33-
SsaInternals0::SourceVariable base;
32+
BaseSourceVariable base;
3433
int ind;
3534

3635
SourceVariable() { this = TMkSourceVariable(base, ind) }
@@ -42,7 +41,7 @@ private module SourceVariables {
4241
* Gets the base source variable (i.e., the variable without any
4342
* indirections) of this source variable.
4443
*/
45-
SsaInternals0::SourceVariable getBaseVariable() { result = base }
44+
BaseSourceVariable getBaseVariable() { result = base }
4645

4746
/** Gets a textual representation of this element. */
4847
string toString() { result = repeatStars(this.getIndirection()) + base.toString() }
@@ -105,16 +104,7 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
105104
cached
106105
private newtype TDefOrUseImpl =
107106
TDefImpl(BaseSourceVariableInstruction base, Operand address, int indirectionIndex) {
108-
isDef(_, _, address, base, _, indirectionIndex) and
109-
(
110-
// We only include the definition if the SSA pruning stage
111-
// concluded that the definition is live after the write.
112-
any(SsaInternals0::Def def).getAddressOperand() = address
113-
or
114-
// Since the pruning stage doesn't know about global variables we can't use the above check to
115-
// rule out dead assignments to globals.
116-
base.(VariableAddressInstruction).getAstVariable() instanceof GlobalLikeVariable
117-
)
107+
isDef(_, _, address, base, _, indirectionIndex)
118108
} or
119109
TUseImpl(BaseSourceVariableInstruction base, Operand operand, int indirectionIndex) {
120110
isUse(_, operand, base, _, indirectionIndex) and
@@ -133,8 +123,7 @@ private newtype TDefOrUseImpl =
133123
TIteratorDef(
134124
Operand iteratorDerefAddress, BaseSourceVariableInstruction container, int indirectionIndex
135125
) {
136-
isIteratorDef(container, iteratorDerefAddress, _, _, indirectionIndex) and
137-
any(SsaInternals0::Def def | def.isIteratorDef()).getAddressOperand() = iteratorDerefAddress
126+
isIteratorDef(container, iteratorDerefAddress, _, _, indirectionIndex)
138127
} or
139128
TIteratorUse(
140129
Operand iteratorAddress, BaseSourceVariableInstruction container, int indirectionIndex
@@ -984,17 +973,6 @@ predicate fromPhiNode(SsaPhiNode nodeFrom, Node nodeTo) {
984973
)
985974
}
986975

987-
/**
988-
* Holds if there is a write at index `i` in basic block `bb` to variable `v` that's
989-
* subsequently read (as determined by the SSA pruning stage).
990-
*/
991-
private predicate variableWriteCand(IRBlock bb, int i, SourceVariable v) {
992-
exists(SsaInternals0::Def def, SsaInternals0::SourceVariable v0 |
993-
def.asDefOrUse().hasIndexInBlock(bb, i, v0) and
994-
v0 = v.getBaseVariable()
995-
)
996-
}
997-
998976
private predicate sourceVariableIsGlobal(
999977
SourceVariable sv, GlobalLikeVariable global, IRFunction func, int indirectionIndex
1000978
) {
@@ -1018,16 +996,14 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
1018996
predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) {
1019997
DataFlowImplCommon::forceCachingInSameStage() and
1020998
(
1021-
variableWriteCand(bb, i, v) or
1022-
sourceVariableIsGlobal(v, _, _, _)
1023-
) and
1024-
exists(DefImpl def | def.hasIndexInBlock(bb, i, v) |
1025-
if def.isCertain() then certain = true else certain = false
1026-
)
1027-
or
1028-
exists(GlobalDefImpl global |
1029-
global.hasIndexInBlock(bb, i, v) and
1030-
certain = true
999+
exists(DefImpl def | def.hasIndexInBlock(bb, i, v) |
1000+
if def.isCertain() then certain = true else certain = false
1001+
)
1002+
or
1003+
exists(GlobalDefImpl global |
1004+
global.hasIndexInBlock(bb, i, v) and
1005+
certain = true
1006+
)
10311007
)
10321008
}
10331009

0 commit comments

Comments
 (0)