@@ -1459,20 +1459,14 @@ module Make<LocationSig Location, InputSig<Location> Input> {
1459
1459
)
1460
1460
}
1461
1461
1462
- /** Holds if SSA definition `def` assigns `value` to the underlying variable. */
1463
- predicate ssaDefAssigns ( WriteDefinition def , Expr value ) ;
1464
-
1465
- /** A parameter. */
1466
- class Parameter {
1467
- /** Gets a textual representation of this parameter. */
1468
- string toString ( ) ;
1469
-
1470
- /** Gets the location of this parameter. */
1471
- Location getLocation ( ) ;
1472
- }
1473
-
1474
- /** Holds if SSA definition `def` initializes parameter `p` at function entry. */
1475
- predicate ssaDefInitializesParam ( WriteDefinition def , Parameter p ) ;
1462
+ /**
1463
+ * Holds if `def` has some form of input flow. For example, the right-hand
1464
+ * side of an assignment or a parameter of an SSA entry definition.
1465
+ *
1466
+ * For such definitions, a flow step is added from a synthetic node
1467
+ * representing the source to the definition.
1468
+ */
1469
+ default predicate ssaDefHasSource ( WriteDefinition def ) { any ( ) }
1476
1470
1477
1471
/**
1478
1472
* Holds if flow should be allowed into uncertain SSA definition `def` from
@@ -1665,17 +1659,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
1665
1659
1666
1660
cached
1667
1661
private newtype TNode =
1668
- TParamNode ( DfInput:: Parameter p ) {
1669
- exists ( WriteDefinition def | DfInput:: ssaDefInitializesParam ( def , p ) )
1670
- } or
1671
- TExprNode ( DfInput:: Expr e , Boolean isPost ) {
1672
- e = DfInput:: getARead ( _)
1673
- or
1674
- exists ( DefinitionExt def |
1675
- DfInput:: ssaDefAssigns ( def , e ) and
1676
- isPost = false
1677
- )
1678
- } or
1662
+ TWriteDefSource ( WriteDefinition def ) { DfInput:: ssaDefHasSource ( def ) } or
1663
+ TExprNode ( DfInput:: Expr e , Boolean isPost ) { e = DfInput:: getARead ( _) } or
1679
1664
TSsaDefinitionNode ( DefinitionExt def ) { not phiHasUniqNextNode ( def ) } or
1680
1665
TSsaInputNode ( SsaPhiExt phi , BasicBlock input ) { relevantPhiInputNode ( phi , input ) }
1681
1666
@@ -1696,21 +1681,21 @@ module Make<LocationSig Location, InputSig<Location> Input> {
1696
1681
1697
1682
final class Node = NodeImpl ;
1698
1683
1699
- /** A parameter node . */
1700
- private class ParameterNodeImpl extends NodeImpl , TParamNode {
1701
- private DfInput :: Parameter p ;
1684
+ /** A source of a write definition . */
1685
+ private class WriteDefSourceNodeImpl extends NodeImpl , TWriteDefSource {
1686
+ private WriteDefinition def ;
1702
1687
1703
- ParameterNodeImpl ( ) { this = TParamNode ( p ) }
1688
+ WriteDefSourceNodeImpl ( ) { this = TWriteDefSource ( def ) }
1704
1689
1705
- /** Gets the underlying parameter . */
1706
- DfInput :: Parameter getParameter ( ) { result = p }
1690
+ /** Gets the underlying definition . */
1691
+ WriteDefinition getDefinition ( ) { result = def }
1707
1692
1708
- override string toString ( ) { result = p .toString ( ) }
1693
+ override string toString ( ) { result = "[source] " + def .toString ( ) }
1709
1694
1710
- override Location getLocation ( ) { result = p .getLocation ( ) }
1695
+ override Location getLocation ( ) { result = def .getLocation ( ) }
1711
1696
}
1712
1697
1713
- final class ParameterNode = ParameterNodeImpl ;
1698
+ final class WriteDefSourceNode = WriteDefSourceNodeImpl ;
1714
1699
1715
1700
/** A (post-update) expression node. */
1716
1701
abstract private class ExprNodePreOrPostImpl extends NodeImpl , TExprNode {
@@ -1976,12 +1961,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
1976
1961
*/
1977
1962
predicate localFlowStep ( SourceVariable v , Node nodeFrom , Node nodeTo , boolean isUseStep ) {
1978
1963
exists ( Definition def |
1979
- // Flow from assignment into SSA definition
1980
- DfInput:: ssaDefAssigns ( def , nodeFrom .( ExprNode ) .getExpr ( ) )
1981
- or
1982
- // Flow from parameter into entry definition
1983
- DfInput:: ssaDefInitializesParam ( def , nodeFrom .( ParameterNode ) .getParameter ( ) )
1984
- |
1964
+ // Flow from write definition source into SSA definition
1965
+ nodeFrom = TWriteDefSource ( def ) and
1985
1966
isUseStep = false and
1986
1967
if DfInput:: includeWriteDefsInFlowStep ( )
1987
1968
then
@@ -2012,12 +1993,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
2012
1993
/** Holds if the value of `nodeTo` is given by `nodeFrom`. */
2013
1994
predicate localMustFlowStep ( SourceVariable v , Node nodeFrom , Node nodeTo ) {
2014
1995
exists ( Definition def |
2015
- // Flow from assignment into SSA definition
2016
- DfInput:: ssaDefAssigns ( def , nodeFrom .( ExprNode ) .getExpr ( ) )
2017
- or
2018
- // Flow from parameter into entry definition
2019
- DfInput:: ssaDefInitializesParam ( def , nodeFrom .( ParameterNode ) .getParameter ( ) )
2020
- |
1996
+ // Flow from write definition source into SSA definition
1997
+ nodeFrom = TWriteDefSource ( def ) and
2021
1998
v = def .getSourceVariable ( ) and
2022
1999
if DfInput:: includeWriteDefsInFlowStep ( )
2023
2000
then nodeTo .( SsaDefinitionNode ) .getDefinition ( ) = def
0 commit comments