Reputation: 71
I am using an individual LLVM optimization pass 'mem2reg' on a simple c-program.
opt <test>.bc -mem2reg -instcount -o <test>.bc -stats
after executing I see the stats option not showing the statistics collected, and it seems that in order to use the ‘-stats‘ option, LLVM must be compiled with assertions enabled. I don't get this, can any one please help me on this.
Upvotes: 3
Views: 2035
Reputation: 33116
There is nothing special about it. It was a design decision to only collect statistics in +Assert builds. If you have a look to llvm/ADT/Statistic.h
, the Statistic
class looks like this:
class Statistic {
public:
// Initialization stuff
#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)
// Actually keeping track of the stat
#else
// Dummy ops that will be optimized away
#endif
};
As you can see, the statistic is collected either when NDEBUG
is not defined (i.e. when building with asserts, e.g. in Release+Assers or Debug+Asserts mode) or when LLVM_ENABLE_STATS
is defined, regardless of the build type.
The same structure is mirrored in the code which prints the statistics.
You can re-enable stats only by rebuilding. If you don't need or want the overhead of a +Asserts build, just add -DLLVM_ENABLE_STATS
to CFLAGS
or equivalent when (re)generating the Makefile. You can find more info about enabling asserts in the How To Release LLVM documentation page.
As of why statistics are disabled in release builds, this behaviour was introduced in commit fa785cb22d (March 2013, it landed in 3.3), probably to eliminate the memory and performance overhead introduced by a feature which is rarely interesting unless you are working on LLVM itself.
That is, most users of LLVM-based compilers like Clang just want to turn their source code into an executable and possibly receive meaningful diagnostics, and they definitely want the compiler to be as fast as possible while doing that. They are less concerned with the exact way LLVM accomplishes this goal, and that's totally understandable. However, this is just a speculation, since I couldn't find any relevant discussion in the mailing list archives.
Upvotes: 4