get the "-stats" information from within the application (instead of from command line)

Hi,

I am using “llvm/ADT/Statistic.h" for recording the iteration number of a pass. However, instead of printing them with “opt -stat…” command line, I need these information from within the application. How can I do this?

For example, if I have:
STATISTIC ( HelloCounter, “Counts number of functions greeted” )
in my pass Hello.cpp, how can I retrieve the HelloCouner from other source files? Thank you.

Hi Zhoulai,

Have you tried cl::ParseCommandLineOptions (http://llvm.org/docs/doxygen/html/CommandLine_8cpp_source.html#l00831)?

You may need to write your own opt.cpp-like tool. There, you run ParseCommandLineOptions with “-stats” before you run any pass, and access these stats variables after all passes finish.

We used this approach to pass in certain optimization flags (such as -disable-machine-sink) without using opt. I hope it works for “-stats” too.

Jingyue