@@ -201,12 +201,40 @@ signature module SsaSig<
201201 * An SSA phi definition, that is, a pseudo definition for a variable at a
202202 * point in the flow graph where otherwise two or more definitions for the
203203 * variable would be visible.
204+ *
205+ * For example, in
206+ * ```rb
207+ * if b
208+ * x = 0
209+ * else
210+ * x = 1
211+ * end
212+ * puts x
213+ * ```
214+ * a phi definition for `x` is inserted just before the call `puts x`.
204215 */
205216 class SsaPhiDefinition extends SsaDefinition {
206- /** Holds if `inp` is an input to the phi definition along the edge originating in `bb`. */
217+ /** Holds if `inp` is an input to this phi definition along the edge originating in `bb`. */
207218 predicate hasInputFromBlock ( SsaDefinition inp , BasicBlock bb ) ;
208219
209- /** Gets an input of this phi definition. */
220+ /**
221+ * Gets an input of this phi definition.
222+ *
223+ * Example:
224+ *
225+ * ```rb
226+ * def m b
227+ * i = 0 # defines i_0
228+ * if b
229+ * i = 1 # defines i_1
230+ * else
231+ * i = 2 # defines i_2
232+ * end
233+ * # defines i_3 = phi(i_1, i_2); inputs are i_1 and i_2
234+ * puts i
235+ * end
236+ * ```
237+ */
210238 SsaDefinition getAnInput ( ) ;
211239 }
212240}
@@ -1516,7 +1544,7 @@ module Make<
15161544 */
15171545 Expr getValue ( ) ;
15181546
1519- /** Holds if this write is an initialization of a parameter. */
1547+ /** Holds if this write is an initialization of parameter `p` . */
15201548 predicate isParameterInit ( Parameter p ) ;
15211549
15221550 /** Gets a textual representation of this write. */
@@ -1588,6 +1616,19 @@ module Make<
15881616 predicate uncertainWriteDefinitionInputCached ( UncertainWriteDefinition def , Definition inp ) {
15891617 uncertainWriteDefinitionInput ( def , inp )
15901618 }
1619+
1620+ cached
1621+ predicate explicitWrite ( WriteDefinition def , VariableWrite write ) {
1622+ exists ( BasicBlock bb , int i , SourceVariable v |
1623+ def .definesAt ( v , bb , i ) and
1624+ explicitWrite ( write , bb , i , v )
1625+ )
1626+ }
1627+
1628+ cached
1629+ predicate parameterInit ( WriteDefinition def , Parameter p ) {
1630+ exists ( VariableWrite write | explicitWrite ( def , write ) and write .isParameterInit ( p ) )
1631+ }
15911632 }
15921633
15931634 additional predicate ssaDefReachesUncertainRead = Cached:: ssaDefReachesUncertainRead / 4 ;
@@ -1658,13 +1699,6 @@ module Make<
16581699 */
16591700 class SsaWriteDefinition extends SsaDefinition instanceof WriteDefinition { }
16601701
1661- private predicate explicitWrite ( WriteDefinition def , VariableWrite write ) {
1662- exists ( BasicBlock bb , int i , SourceVariable v |
1663- def .definesAt ( v , bb , i ) and
1664- explicitWrite ( write , bb , i , v )
1665- )
1666- }
1667-
16681702 /**
16691703 * An SSA definition that corresponds to an explicit variable update or
16701704 * declaration.
@@ -1688,10 +1722,6 @@ module Make<
16881722 Expr getValue ( ) { result = this .getDefinition ( ) .getValue ( ) }
16891723 }
16901724
1691- private predicate parameterInit ( WriteDefinition def , Parameter p ) {
1692- exists ( VariableWrite write | explicitWrite ( def , write ) and write .isParameterInit ( p ) )
1693- }
1694-
16951725 /**
16961726 * An SSA definition representing the initialization of a parameter at the
16971727 * beginning of a callable.
@@ -1743,14 +1773,42 @@ module Make<
17431773 * An SSA phi definition, that is, a pseudo definition for a variable at a
17441774 * point in the flow graph where otherwise two or more definitions for the
17451775 * variable would be visible.
1776+ *
1777+ * For example, in
1778+ * ```rb
1779+ * if b
1780+ * x = 0
1781+ * else
1782+ * x = 1
1783+ * end
1784+ * puts x
1785+ * ```
1786+ * a phi definition for `x` is inserted just before the call `puts x`.
17461787 */
17471788 class SsaPhiDefinition extends SsaDefinition {
1748- /** Holds if `inp` is an input to the phi definition along the edge originating in `bb`. */
1789+ /** Holds if `inp` is an input to this phi definition along the edge originating in `bb`. */
17491790 predicate hasInputFromBlock ( SsaDefinition inp , BasicBlock bb ) {
17501791 phiHasInputFromBlockCached ( this , inp , bb )
17511792 }
17521793
1753- /** Gets an input of this phi definition. */
1794+ /**
1795+ * Gets an input of this phi definition.
1796+ *
1797+ * Example:
1798+ *
1799+ * ```rb
1800+ * def m b
1801+ * i = 0 # defines i_0
1802+ * if b
1803+ * i = 1 # defines i_1
1804+ * else
1805+ * i = 2 # defines i_2
1806+ * end
1807+ * # defines i_3 = phi(i_1, i_2); inputs are i_1 and i_2
1808+ * puts i
1809+ * end
1810+ * ```
1811+ */
17541812 SsaDefinition getAnInput ( ) { this .hasInputFromBlock ( result , _) }
17551813 }
17561814 }
0 commit comments