Skip to content

Commit 474b8a5

Browse files
authored
Merge pull request #18942 from aschackmull/cpp/refactor-ssa
C++: Refactor SSA usage in data flow.
2 parents 60f96ee + c230944 commit 474b8a5

File tree

15 files changed

+386
-505
lines changed

15 files changed

+386
-505
lines changed

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

+9-55
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ predicate nodeIsHidden(Node n) {
13181318
or
13191319
n instanceof InitialGlobalValue
13201320
or
1321-
n instanceof SsaPhiInputNode
1321+
n instanceof SsaSynthNode
13221322
}
13231323

13241324
predicate neverSkipInPathGraph(Node n) {
@@ -1632,9 +1632,7 @@ private Instruction getAnInstruction(Node n) {
16321632
not n instanceof InstructionNode and
16331633
result = n.asOperand().getUse()
16341634
or
1635-
result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction()
1636-
or
1637-
result = n.(SsaPhiInputNode).getBasicBlock().getFirstInstruction()
1635+
result = n.(SsaSynthNode).getBasicBlock().getFirstInstruction()
16381636
or
16391637
n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _)
16401638
or
@@ -1766,14 +1764,14 @@ module IteratorFlow {
17661764
* Note: Unlike `def.getAnUltimateDefinition()` this predicate also
17671765
* traverses back through iterator increment and decrement operations.
17681766
*/
1769-
private Ssa::DefinitionExt getAnUltimateDefinition(Ssa::DefinitionExt def) {
1767+
private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
17701768
result = def.getAnUltimateDefinition()
17711769
or
17721770
exists(IRBlock bb, int i, IteratorCrementCall crementCall, Ssa::SourceVariable sv |
17731771
crementCall = def.getValue().asInstruction().(StoreInstruction).getSourceValue() and
17741772
sv = def.getSourceVariable() and
17751773
bb.getInstruction(i) = crementCall and
1776-
Ssa::ssaDefReachesReadExt(sv, result, bb, i)
1774+
Ssa::ssaDefReachesRead(sv, result, bb, i)
17771775
)
17781776
}
17791777

@@ -1801,13 +1799,13 @@ module IteratorFlow {
18011799
GetsIteratorCall beginCall, Instruction writeToDeref
18021800
) {
18031801
exists(
1804-
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::DefinitionExt def,
1805-
IteratorPointerDereferenceCall starCall, Ssa::DefinitionExt ultimate, Operand address
1802+
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::Definition def,
1803+
IteratorPointerDereferenceCall starCall, Ssa::Definition ultimate, Operand address
18061804
|
18071805
isIteratorWrite(writeToDeref, address) and
18081806
operandForFullyConvertedCall(address, starCall) and
18091807
bbStar.getInstruction(iStar) = starCall and
1810-
Ssa::ssaDefReachesReadExt(_, def, bbStar, iStar) and
1808+
Ssa::ssaDefReachesRead(_, def, bbStar, iStar) and
18111809
ultimate = getAnUltimateDefinition*(def) and
18121810
beginStore = ultimate.getValue().asInstruction() and
18131811
operandForFullyConvertedCall(beginStore.getSourceValueOperand(), beginCall)
@@ -1836,45 +1834,15 @@ module IteratorFlow {
18361834

18371835
private module IteratorSsa = SsaImpl::Make<Location, SsaInput>;
18381836

1839-
cached
1840-
private newtype TSsaDef =
1841-
TDef(IteratorSsa::DefinitionExt def) or
1842-
TPhi(PhiNode phi)
1843-
1844-
abstract private class SsaDef extends TSsaDef {
1845-
/** Gets a textual representation of this element. */
1846-
string toString() { none() }
1847-
1848-
/** Gets the underlying non-phi definition or use. */
1849-
IteratorSsa::DefinitionExt asDef() { none() }
1850-
1851-
/** Gets the underlying phi node. */
1852-
PhiNode asPhi() { none() }
1853-
1854-
/** Gets the location of this element. */
1855-
abstract Location getLocation();
1856-
}
1857-
1858-
private class Def extends TDef, SsaDef {
1859-
IteratorSsa::DefinitionExt def;
1860-
1861-
Def() { this = TDef(def) }
1862-
1863-
final override IteratorSsa::DefinitionExt asDef() { result = def }
1864-
1837+
private class Def extends IteratorSsa::DefinitionExt {
18651838
final override Location getLocation() { result = this.getImpl().getLocation() }
18661839

1867-
/** Gets the variable written to by this definition. */
1868-
final SourceVariable getSourceVariable() { result = def.getSourceVariable() }
1869-
1870-
override string toString() { result = def.toString() }
1871-
18721840
/**
18731841
* Holds if this definition (or use) has index `index` in block `block`,
18741842
* and is a definition (or use) of the variable `sv`.
18751843
*/
18761844
predicate hasIndexInBlock(IRBlock block, int index, SourceVariable sv) {
1877-
def.definesAt(sv, block, index, _)
1845+
super.definesAt(sv, block, index, _)
18781846
}
18791847

18801848
private Ssa::DefImpl getImpl() {
@@ -1891,20 +1859,6 @@ module IteratorFlow {
18911859
int getIndirectionIndex() { result = this.getImpl().getIndirectionIndex() }
18921860
}
18931861

1894-
private class Phi extends TPhi, SsaDef {
1895-
PhiNode phi;
1896-
1897-
Phi() { this = TPhi(phi) }
1898-
1899-
final override PhiNode asPhi() { result = phi }
1900-
1901-
final override Location getLocation() { result = phi.getBasicBlock().getLocation() }
1902-
1903-
override string toString() { result = phi.toString() }
1904-
1905-
SsaIteratorNode getNode() { result.getIteratorFlowNode() = phi }
1906-
}
1907-
19081862
private class PhiNode extends IteratorSsa::DefinitionExt {
19091863
PhiNode() {
19101864
this instanceof IteratorSsa::PhiNode or

0 commit comments

Comments
 (0)