Merge pull request #19147 from aschackmull/ssa/writedef-source-refactor

Ssa: Refactor data flow integration to make the input signature simpler
This commit is contained in:
Anders Schack-Mulligen
2025-03-31 10:07:09 +02:00
committed by GitHub
11 changed files with 54 additions and 112 deletions

View File

@@ -1459,20 +1459,14 @@ module Make<LocationSig Location, InputSig<Location> Input> {
)
}
/** Holds if SSA definition `def` assigns `value` to the underlying variable. */
predicate ssaDefAssigns(WriteDefinition def, Expr value);
/** A parameter. */
class Parameter {
/** Gets a textual representation of this parameter. */
string toString();
/** Gets the location of this parameter. */
Location getLocation();
}
/** Holds if SSA definition `def` initializes parameter `p` at function entry. */
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p);
/**
* Holds if `def` has some form of input flow. For example, the right-hand
* side of an assignment or a parameter of an SSA entry definition.
*
* For such definitions, a flow step is added from a synthetic node
* representing the source to the definition.
*/
default predicate ssaDefHasSource(WriteDefinition def) { any() }
/**
* Holds if flow should be allowed into uncertain SSA definition `def` from
@@ -1665,17 +1659,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
cached
private newtype TNode =
TParamNode(DfInput::Parameter p) {
exists(WriteDefinition def | DfInput::ssaDefInitializesParam(def, p))
} or
TExprNode(DfInput::Expr e, Boolean isPost) {
e = DfInput::getARead(_)
or
exists(DefinitionExt def |
DfInput::ssaDefAssigns(def, e) and
isPost = false
)
} or
TWriteDefSource(WriteDefinition def) { DfInput::ssaDefHasSource(def) } or
TExprNode(DfInput::Expr e, Boolean isPost) { e = DfInput::getARead(_) } or
TSsaDefinitionNode(DefinitionExt def) { not phiHasUniqNextNode(def) } or
TSsaInputNode(SsaPhiExt phi, BasicBlock input) { relevantPhiInputNode(phi, input) }
@@ -1696,21 +1681,21 @@ module Make<LocationSig Location, InputSig<Location> Input> {
final class Node = NodeImpl;
/** A parameter node. */
private class ParameterNodeImpl extends NodeImpl, TParamNode {
private DfInput::Parameter p;
/** A source of a write definition. */
private class WriteDefSourceNodeImpl extends NodeImpl, TWriteDefSource {
private WriteDefinition def;
ParameterNodeImpl() { this = TParamNode(p) }
WriteDefSourceNodeImpl() { this = TWriteDefSource(def) }
/** Gets the underlying parameter. */
DfInput::Parameter getParameter() { result = p }
/** Gets the underlying definition. */
WriteDefinition getDefinition() { result = def }
override string toString() { result = p.toString() }
override string toString() { result = "[source] " + def.toString() }
override Location getLocation() { result = p.getLocation() }
override Location getLocation() { result = def.getLocation() }
}
final class ParameterNode = ParameterNodeImpl;
final class WriteDefSourceNode = WriteDefSourceNodeImpl;
/** A (post-update) expression node. */
abstract private class ExprNodePreOrPostImpl extends NodeImpl, TExprNode {
@@ -1976,12 +1961,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
*/
predicate localFlowStep(SourceVariable v, Node nodeFrom, Node nodeTo, boolean isUseStep) {
exists(Definition def |
// Flow from assignment into SSA definition
DfInput::ssaDefAssigns(def, nodeFrom.(ExprNode).getExpr())
or
// Flow from parameter into entry definition
DfInput::ssaDefInitializesParam(def, nodeFrom.(ParameterNode).getParameter())
|
// Flow from write definition source into SSA definition
nodeFrom = TWriteDefSource(def) and
isUseStep = false and
if DfInput::includeWriteDefsInFlowStep()
then
@@ -2012,12 +1993,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
/** Holds if the value of `nodeTo` is given by `nodeFrom`. */
predicate localMustFlowStep(SourceVariable v, Node nodeFrom, Node nodeTo) {
exists(Definition def |
// Flow from assignment into SSA definition
DfInput::ssaDefAssigns(def, nodeFrom.(ExprNode).getExpr())
or
// Flow from parameter into entry definition
DfInput::ssaDefInitializesParam(def, nodeFrom.(ParameterNode).getParameter())
|
// Flow from write definition source into SSA definition
nodeFrom = TWriteDefSource(def) and
v = def.getSourceVariable() and
if DfInput::includeWriteDefsInFlowStep()
then nodeTo.(SsaDefinitionNode).getDefinition() = def