OSDN Git Service

Re-commit: Make STATISTIC() values available programmatically
authorDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 5 Mar 2018 19:38:16 +0000 (19:38 +0000)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 5 Mar 2018 19:38:16 +0000 (19:38 +0000)
commita3170b6798cb3554fdf48adfe934ed08cbc54165
tree25ccf7e849cdc96e1888abd0e7a4957373dbeb27
parent21cc5d93b2a26abaf14ec000eccae398f7b26d29
Re-commit: Make STATISTIC() values available programmatically

Summary:
It can be useful for tools to be able to retrieve the values of variables
declared via STATISTIC() directly without having to emit them and parse
them back. Use cases include:
* Needing to report specific statistics to a test harness
* Wanting to post-process statistics. For example, to produce a percentage of
  functions that were fully selected by GlobalISel

Make this possible by adding llvm::GetStatistics() which returns an
iterator_range that can be used to inspect the statistics that have been
touched during execution. When statistics are disabled (NDEBUG and not
LLVM_ENABLE_STATISTICS) this method will return an empty range.

This patch doesn't address the effect of multiple compilations within the same
process. In such situations, the statistics will be cumulative for all
compilations up to the GetStatistics() call.

Reviewers: qcolombet, rtereshin, aditya_nandakumar, bogner

Reviewed By: rtereshin, bogner

Subscribers: llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D43901

This re-commit fixes a missing include of <vector> which it seems clang didn't
mind but G++ and MSVC objected to. It seems that, clang was ok with std::vector
only being forward declared at the point of use since it was fully defined
eventually but G++/MSVC both rejected it at the point of use.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326738 91177308-0d34-0410-b5e6-96231b3b80d8
cmake/modules/HandleLLVMOptions.cmake
include/llvm/ADT/Statistic.h
include/llvm/Config/llvm-config.h.cmake
lib/Support/Statistic.cpp
unittests/ADT/CMakeLists.txt
unittests/ADT/StatisticTest.cpp [new file with mode: 0644]