@@ -2168,3 +2168,56 @@ module SimpleRangeAnalysisInternal {
21682168 /** Gets the estimate of the number of bounds for `e`. */
21692169 float estimateNrOfBounds ( Expr e ) { result = BoundsEstimate:: nrOfBoundsExpr ( e ) }
21702170}
2171+
2172+ /** Provides predicates for debugging the simple range analysis library. */
2173+ private module Debug {
2174+ Locatable getRelevantLocatable ( ) {
2175+ exists ( string filepath , int startline |
2176+ result .getLocation ( ) .hasLocationInfo ( filepath , startline , _, _, _) and
2177+ filepath .matches ( "%/test.c" ) and
2178+ startline = [ 621 .. 639 ]
2179+ )
2180+ }
2181+
2182+ float debugGetLowerBoundsImpl ( Expr e ) {
2183+ e = getRelevantLocatable ( ) and
2184+ result = getLowerBoundsImpl ( e )
2185+ }
2186+
2187+ float debugGetUpperBoundsImpl ( Expr e ) {
2188+ e = getRelevantLocatable ( ) and
2189+ result = getUpperBoundsImpl ( e )
2190+ }
2191+
2192+ /**
2193+ * Counts the number of lower bounds for a given expression. This predicate is
2194+ * useful for identifying performance issues in the range analysis.
2195+ */
2196+ predicate countGetLowerBoundsImpl ( Expr e , int n ) {
2197+ e = getRelevantLocatable ( ) and
2198+ n = strictcount ( float lb | lb = getLowerBoundsImpl ( e ) | lb )
2199+ }
2200+
2201+ float debugNrOfBounds ( Expr e ) {
2202+ e = getRelevantLocatable ( ) and
2203+ result = BoundsEstimate:: nrOfBoundsExpr ( e )
2204+ }
2205+
2206+ /**
2207+ * Finds any expressions for which `nrOfBounds` is not functional. The result
2208+ * should be empty, so this predicate is useful to debug non-functional cases.
2209+ */
2210+ int nonFunctionalNrOfBounds ( Expr e ) {
2211+ strictcount ( BoundsEstimate:: nrOfBoundsExpr ( e ) ) > 1 and
2212+ result = BoundsEstimate:: nrOfBoundsExpr ( e )
2213+ }
2214+
2215+ /**
2216+ * Holds if `e` is an expression that has a lower bound, but where
2217+ * `nrOfBounds` does not compute an estimate.
2218+ */
2219+ predicate missingNrOfBounds ( Expr e , float n ) {
2220+ n = lowerBound ( e ) and
2221+ not exists ( BoundsEstimate:: nrOfBoundsExpr ( e ) )
2222+ }
2223+ }
0 commit comments