<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135764>135764</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Expose constexpr evaluation statistics
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BenBE
</td>
</tr>
</table>
<pre>
When compiling constexpr-heavy code it would be nice to receive more feedback than "constexpr evaluation hit maximum step limit" or "constexpr evaluation exceeded maximum depth of N calls". Especially when you do not reach these limits with your code quite yet, getting some feedback, e.g. via the `-ftime-trace` or some other means, how much allowed resources compilation of your code took, would be nice.
In the easiest case, this could mean to publish the evaluation counter for each `EvaluateAsInitializer` call (and similar in the generated time trace log, along-side the maximum depth and the other tracked limits.
If evaluating a constexpr triggered recursively, these sub-expressions could get their own trace too.
```cpp
template <typename T>
struct bar {
static const T v;
};
template <typename T>
const T bar<T>::v = 21*sizeof(T);
template <typename T>
struct foo {
static const T v;
};
template <typename T>
const T foo<T>::v = bar<T>::v;
int main() {
return foo<short>::v;
}
```
A time trace report for the above code would then include the following listing:
```
foo<short>::v (steps=4, depth=2, loops=0)
bar<short>::v (steps=3, depth=1, loops=0)
```
Other alternatives to produce such a report are welcome too.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVc2O4zgPfBrlQiSw5fwecnBPuoG5fN-lgT3LMm1rRxa9Eu105ukXtNM_M9M72MMCAZJIYrFYLEomJdcGxLPaPajdZWVG7iieHzA8PK4qqm_nPzoMYKkfnHehBUshMb4Mcd2hmW5gqUZwDFcafQ0VQnAWgQkiWnQTQk8RoUGsK2O_AXcmgNL6DQZwMn407ChA5xh68-L6sYfEOIB3vWOlNVD8xyB8sYg11m-RNQ7cATXwP7DG-6S03sBjGtA64_0NrlLQjUaoCQIxRDS2A-4w4ZIwwdVxJ0fiUt5fo2OEG7LSX6BFZhEiUf9el2zgpt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