Skip to content

C++: Refactor SSA usage in data flow. #18942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ predicate nodeIsHidden(Node n) {
or
n instanceof InitialGlobalValue
or
n instanceof SsaPhiInputNode
n instanceof SsaSynthNode
}

predicate neverSkipInPathGraph(Node n) {
Expand Down Expand Up @@ -1632,9 +1632,7 @@ private Instruction getAnInstruction(Node n) {
not n instanceof InstructionNode and
result = n.asOperand().getUse()
or
result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction()
or
result = n.(SsaPhiInputNode).getBasicBlock().getFirstInstruction()
result = n.(SsaSynthNode).getBasicBlock().getFirstInstruction()
or
n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _)
or
Expand Down Expand Up @@ -1766,14 +1764,14 @@ module IteratorFlow {
* Note: Unlike `def.getAnUltimateDefinition()` this predicate also
* traverses back through iterator increment and decrement operations.
*/
private Ssa::DefinitionExt getAnUltimateDefinition(Ssa::DefinitionExt def) {
private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
result = def.getAnUltimateDefinition()
or
exists(IRBlock bb, int i, IteratorCrementCall crementCall, Ssa::SourceVariable sv |
crementCall = def.getValue().asInstruction().(StoreInstruction).getSourceValue() and
sv = def.getSourceVariable() and
bb.getInstruction(i) = crementCall and
Ssa::ssaDefReachesReadExt(sv, result, bb, i)
Ssa::ssaDefReachesRead(sv, result, bb, i)
)
}

Expand Down Expand Up @@ -1801,13 +1799,13 @@ module IteratorFlow {
GetsIteratorCall beginCall, Instruction writeToDeref
) {
exists(
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::DefinitionExt def,
IteratorPointerDereferenceCall starCall, Ssa::DefinitionExt ultimate, Operand address
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::Definition def,
IteratorPointerDereferenceCall starCall, Ssa::Definition ultimate, Operand address
|
isIteratorWrite(writeToDeref, address) and
operandForFullyConvertedCall(address, starCall) and
bbStar.getInstruction(iStar) = starCall and
Ssa::ssaDefReachesReadExt(_, def, bbStar, iStar) and
Ssa::ssaDefReachesRead(_, def, bbStar, iStar) and
ultimate = getAnUltimateDefinition*(def) and
beginStore = ultimate.getValue().asInstruction() and
operandForFullyConvertedCall(beginStore.getSourceValueOperand(), beginCall)
Expand Down Expand Up @@ -1836,45 +1834,15 @@ module IteratorFlow {

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

cached
private newtype TSsaDef =
TDef(IteratorSsa::DefinitionExt def) or
TPhi(PhiNode phi)

abstract private class SsaDef extends TSsaDef {
/** Gets a textual representation of this element. */
string toString() { none() }

/** Gets the underlying non-phi definition or use. */
IteratorSsa::DefinitionExt asDef() { none() }

/** Gets the underlying phi node. */
PhiNode asPhi() { none() }

/** Gets the location of this element. */
abstract Location getLocation();
}

private class Def extends TDef, SsaDef {
IteratorSsa::DefinitionExt def;

Def() { this = TDef(def) }

final override IteratorSsa::DefinitionExt asDef() { result = def }

private class Def extends IteratorSsa::DefinitionExt {
final override Location getLocation() { result = this.getImpl().getLocation() }

/** Gets the variable written to by this definition. */
final SourceVariable getSourceVariable() { result = def.getSourceVariable() }

override string toString() { result = def.toString() }

/**
* Holds if this definition (or use) has index `index` in block `block`,
* and is a definition (or use) of the variable `sv`.
*/
predicate hasIndexInBlock(IRBlock block, int index, SourceVariable sv) {
def.definesAt(sv, block, index, _)
super.definesAt(sv, block, index, _)
}

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

private class Phi extends TPhi, SsaDef {
PhiNode phi;

Phi() { this = TPhi(phi) }

final override PhiNode asPhi() { result = phi }

final override Location getLocation() { result = phi.getBasicBlock().getLocation() }

override string toString() { result = phi.toString() }

SsaIteratorNode getNode() { result.getIteratorFlowNode() = phi }
}

private class PhiNode extends IteratorSsa::DefinitionExt {
PhiNode() {
this instanceof IteratorSsa::PhiNode or
Expand Down
Loading