@@ -1942,3 +1942,134 @@ StackEntry* BasicBlock::bbStackOnEntry() const
1942
1942
assert (bbEntryState);
1943
1943
return bbEntryState->esStack ;
1944
1944
}
1945
+
1946
+ // ------------------------------------------------------------------------
1947
+ // StatementCount: number of statements in the block.
1948
+ //
1949
+ // Returns:
1950
+ // count of statements
1951
+ //
1952
+ // Notes:
1953
+ // If you are calling this in order to compare the statement count
1954
+ // against a limit, use StatementCountExceeds as it may do less work.
1955
+ //
1956
+ unsigned BasicBlock::StatementCount ()
1957
+ {
1958
+ unsigned count = 0 ;
1959
+
1960
+ for (Statement* const stmt : Statements ())
1961
+ {
1962
+ count++;
1963
+ }
1964
+
1965
+ return count;
1966
+ }
1967
+
1968
+ // ------------------------------------------------------------------------
1969
+ // StatementCountExceeds: check if the number of statements in the block
1970
+ // exceeds some limit
1971
+ //
1972
+ // Arguments:
1973
+ // limit - limit on the number of statements
1974
+ // count - [out, optional] actual number of statements (if less than or equal to limit)
1975
+ //
1976
+ // Returns:
1977
+ // true if the number of statements is greater than limit
1978
+ //
1979
+ bool BasicBlock::StatementCountExceeds (unsigned limit, unsigned * count /* = nullptr */ )
1980
+ {
1981
+ unsigned localCount = 0 ;
1982
+ bool overLimit = false ;
1983
+
1984
+ for (Statement* const stmt : Statements ())
1985
+ {
1986
+ if (++localCount > limit)
1987
+ {
1988
+ overLimit = true ;
1989
+ break ;
1990
+ }
1991
+ }
1992
+
1993
+ if (count != nullptr )
1994
+ {
1995
+ *count = localCount;
1996
+ }
1997
+
1998
+ return overLimit;
1999
+ }
2000
+
2001
+ // ------------------------------------------------------------------------
2002
+ // ComplexityExceeds: check if the number of nodes in the trees in the block
2003
+ // exceeds some limit
2004
+ //
2005
+ // Arguments:
2006
+ // comp - compiler instance
2007
+ // limit - limit on the number of nodes
2008
+ // count - [out, optional] actual number of nodes (if less than or equal to limit)
2009
+ //
2010
+ // Returns:
2011
+ // true if the number of nodes is greater than limit
2012
+ //
2013
+ bool BasicBlock::ComplexityExceeds (Compiler* comp, unsigned limit, unsigned * count /* = nullptr */ )
2014
+ {
2015
+ unsigned localCount = 0 ;
2016
+ bool overLimit = false ;
2017
+
2018
+ for (Statement* const stmt : Statements ())
2019
+ {
2020
+ unsigned slack = limit - localCount;
2021
+ unsigned actual = 0 ;
2022
+ if (comp->gtComplexityExceeds (stmt->GetRootNode (), slack, &actual))
2023
+ {
2024
+ overLimit = true ;
2025
+ break ;
2026
+ }
2027
+
2028
+ localCount += actual;
2029
+ }
2030
+
2031
+ if (count != nullptr )
2032
+ {
2033
+ *count = localCount;
2034
+ }
2035
+
2036
+ return overLimit;
2037
+ }
2038
+
2039
+ // ------------------------------------------------------------------------
2040
+ // ComplexityExceeds: check if the number of nodes in the trees in the blocks
2041
+ // in the range exceeds some limit
2042
+ //
2043
+ // Arguments:
2044
+ // comp - compiler instance
2045
+ // limit - limit on the number of nodes
2046
+ // count - [out, optional] actual number of nodes (if less than or equal to limit)
2047
+ //
2048
+ // Returns:
2049
+ // true if the number of nodes is greater than limit
2050
+ //
2051
+ bool BasicBlockRangeList::ComplexityExceeds (Compiler* comp, unsigned limit, unsigned * count /* = nullptr */ )
2052
+ {
2053
+ unsigned localCount = 0 ;
2054
+ bool overLimit = false ;
2055
+
2056
+ for (BasicBlock* const block : *this )
2057
+ {
2058
+ unsigned slack = limit - localCount;
2059
+ unsigned actual = 0 ;
2060
+ if (block->ComplexityExceeds (comp, slack, &actual))
2061
+ {
2062
+ overLimit = true ;
2063
+ break ;
2064
+ }
2065
+
2066
+ localCount += actual;
2067
+ }
2068
+
2069
+ if (count != nullptr )
2070
+ {
2071
+ *count = localCount;
2072
+ }
2073
+
2074
+ return overLimit;
2075
+ }
0 commit comments