C++: Replace DefinitionExt usage with Definition.

This commit is contained in:
Anders Schack-Mulligen
2025-03-06 09:35:07 +01:00
parent 9375e571b1
commit 6ba1d2ef14
2 changed files with 15 additions and 91 deletions

View File

@@ -1764,14 +1764,14 @@ module IteratorFlow {
* Note: Unlike `def.getAnUltimateDefinition()` this predicate also * Note: Unlike `def.getAnUltimateDefinition()` this predicate also
* traverses back through iterator increment and decrement operations. * 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() result = def.getAnUltimateDefinition()
or or
exists(IRBlock bb, int i, IteratorCrementCall crementCall, Ssa::SourceVariable sv | exists(IRBlock bb, int i, IteratorCrementCall crementCall, Ssa::SourceVariable sv |
crementCall = def.getValue().asInstruction().(StoreInstruction).getSourceValue() and crementCall = def.getValue().asInstruction().(StoreInstruction).getSourceValue() and
sv = def.getSourceVariable() and sv = def.getSourceVariable() and
bb.getInstruction(i) = crementCall and bb.getInstruction(i) = crementCall and
Ssa::ssaDefReachesReadExt(sv, result, bb, i) Ssa::ssaDefReachesRead(sv, result, bb, i)
) )
} }
@@ -1799,13 +1799,13 @@ module IteratorFlow {
GetsIteratorCall beginCall, Instruction writeToDeref GetsIteratorCall beginCall, Instruction writeToDeref
) { ) {
exists( exists(
StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::DefinitionExt def, StoreInstruction beginStore, IRBlock bbStar, int iStar, Ssa::Definition def,
IteratorPointerDereferenceCall starCall, Ssa::DefinitionExt ultimate, Operand address IteratorPointerDereferenceCall starCall, Ssa::Definition ultimate, Operand address
| |
isIteratorWrite(writeToDeref, address) and isIteratorWrite(writeToDeref, address) and
operandForFullyConvertedCall(address, starCall) and operandForFullyConvertedCall(address, starCall) and
bbStar.getInstruction(iStar) = starCall and bbStar.getInstruction(iStar) = starCall and
Ssa::ssaDefReachesReadExt(_, def, bbStar, iStar) and Ssa::ssaDefReachesRead(_, def, bbStar, iStar) and
ultimate = getAnUltimateDefinition*(def) and ultimate = getAnUltimateDefinition*(def) and
beginStore = ultimate.getValue().asInstruction() and beginStore = ultimate.getValue().asInstruction() and
operandForFullyConvertedCall(beginStore.getSourceValueOperand(), beginCall) operandForFullyConvertedCall(beginStore.getSourceValueOperand(), beginCall)

View File

@@ -926,32 +926,16 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
*/ */
cached cached
module SsaCached { module SsaCached {
/**
* Holds if the node at index `i` in `bb` is a last reference to SSA definition
* `def`. The reference is last because it can reach another write `next`,
* without passing through another read or write.
*
* The path from node `i` in `bb` to `next` goes via basic block `input`,
* which is either a predecessor of the basic block of `next`, or `input` =
* `bb` in case `next` occurs in basic block `bb`.
*/
cached
predicate lastRefRedefExt(
DefinitionExt def, SourceVariable sv, IRBlock bb, int i, IRBlock input, DefinitionExt next
) {
SsaImpl::lastRefRedefExt(def, sv, bb, i, input, next)
}
cached
predicate ssaDefReachesReadExt(SourceVariable v, DefinitionExt def, IRBlock bb, int i) {
SsaImpl::ssaDefReachesReadExt(v, def, bb, i)
}
cached cached
predicate ssaDefReachesRead(SourceVariable v, Definition def, IRBlock bb, int i) { predicate ssaDefReachesRead(SourceVariable v, Definition def, IRBlock bb, int i) {
SsaImpl::ssaDefReachesRead(v, def, bb, i) SsaImpl::ssaDefReachesRead(v, def, bb, i)
} }
cached
predicate phiHasInputFromBlock(PhiNode phi, Definition inp, IRBlock bb) {
SsaImpl::phiHasInputFromBlock(phi, inp, bb)
}
predicate variableRead = SsaInput::variableRead/4; predicate variableRead = SsaInput::variableRead/4;
predicate variableWrite = SsaInput::variableWrite/4; predicate variableWrite = SsaInput::variableWrite/4;
@@ -1102,77 +1086,17 @@ predicate ssaFlow(Node nodeFrom, Node nodeTo) {
/** /**
* An static single assignment (SSA) phi node. * An static single assignment (SSA) phi node.
*
* This is either a normal phi node or a phi-read node.
*/ */
class PhiNode extends SsaImpl::DefinitionExt { class PhiNode extends Definition instanceof SsaImpl::PhiNode {
PhiNode() {
this instanceof SsaImpl::PhiNode or
this instanceof SsaImpl::PhiReadNode
}
/**
* Holds if this phi node is a phi-read node.
*
* Phi-read nodes are like normal phi nodes, but they are inserted based
* on reads instead of writes.
*/
predicate isPhiRead() { this instanceof SsaImpl::PhiReadNode }
/**
* Holds if the node at index `i` in `bb` is a last reference to SSA
* definition `def` of `sv`. The reference is last because it can reach
* this phi node, without passing through another read or write.
*
* The path from node `i` in `bb` to this phi node goes via basic block
* `input`, which is either a predecessor of the basic block of this phi
* node, or `input` = `bb` in case this phi node occurs in basic block `bb`.
*/
predicate hasInputFromBlock(DefinitionExt def, SourceVariable sv, IRBlock bb, int i, IRBlock input) {
SsaCached::lastRefRedefExt(def, sv, bb, i, input, this)
}
/** Gets a definition that is an input to this phi node. */ /** Gets a definition that is an input to this phi node. */
final DefinitionExt getAnInput() { this.hasInputFromBlock(result, _, _, _, _) } final Definition getAnInput() { phiHasInputFromBlock(this, result, _) }
} }
/** An static single assignment (SSA) definition. */ /** An static single assignment (SSA) definition. */
class Definition extends SsaImpl::Definition { class Definition extends SsaImpl::Definition {
/** // TODO: Include prior definitions of uncertain writes or rename predicate
* INTERNAL: Do not use. // i.e. the disjunct `SsaImpl::uncertainWriteDefinitionInput(this, result)`
*/ private Definition getAPhiInputOrPriorDefinition() { result = this.(PhiNode).getAnInput() }
Node0Impl getValue() { result = getDefImpl(this).getValue() }
/** Gets the indirection index of this definition. */
int getIndirectionIndex() { result = getDefImpl(this).getIndirectionIndex() }
/** Gets the indirection of this definition. */
int getIndirection() { result = getDefImpl(this).getIndirection() }
/**
* Holds if this definition is guaranteed to totally overwrite the buffer
* being written to.
*/
predicate isCertain() { getDefImpl(this).isCertain() }
/**
* Gets the enclosing declaration of this definition.
*
* Note that this may be a variable when this definition defines a global, or
* a static local, variable.
*/
Declaration getFunction() { result = getDefImpl(this).getBlock().getEnclosingFunction() }
/** Gets the underlying type of the variable being defined by this definition. */
Type getUnderlyingType() { result = this.getSourceVariable().getType() }
/** Gets the unspecified type of the variable being defined by this definition. */
Type getUnspecifiedType() { result = this.getUnderlyingType().getUnspecifiedType() }
}
/** An static single assignment (SSA) definition. */
class DefinitionExt extends SsaImpl::DefinitionExt {
private DefinitionExt getAPhiInputOrPriorDefinition() { result = this.(PhiNode).getAnInput() }
/** /**
* Gets a definition that ultimately defines this SSA definition and is * Gets a definition that ultimately defines this SSA definition and is