mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-01 21:04:04 -04:00
18c6fab107
This patch pulls google/benchmark v1.4.1 into the LLVM tree so that any project could use it for benchmark generation. A dummy benchmark is added to `llvm/benchmarks/DummyYAML.cpp` to validate the correctness of the build process. The current version does not utilize LLVM LNT and LLVM CMake infrastructure, but that might be sufficient for most users. Two introduced CMake variables: * `LLVM_INCLUDE_BENCHMARKS` (`ON` by default) generates benchmark targets * `LLVM_BUILD_BENCHMARKS` (`OFF` by default) adds generated benchmark targets to the list of default LLVM targets (i.e. if `ON` benchmarks will be built upon standard build invocation, e.g. `ninja` or `make` with no specific targets) List of modifications: * `BENCHMARK_ENABLE_TESTING` is disabled * `BENCHMARK_ENABLE_EXCEPTIONS` is disabled * `BENCHMARK_ENABLE_INSTALL` is disabled * `BENCHMARK_ENABLE_GTEST_TESTS` is disabled * `BENCHMARK_DOWNLOAD_DEPENDENCIES` is disabled Original discussion can be found here: http://lists.llvm.org/pipermail/llvm-dev/2018-August/125023.html Reviewed by: dberris, lebedev.ri Subscribers: ilya-biryukov, ioeric, EricWF, lebedev.ri, srhines, dschuff, mgorny, krytarowski, fedor.sergeev, mgrang, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D50894 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340809 91177308-0d34-0410-b5e6-96231b3b80d8
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
#ifndef CHECK_H_
|
|
#define CHECK_H_
|
|
|
|
#include <cstdlib>
|
|
#include <ostream>
|
|
#include <cmath>
|
|
|
|
#include "internal_macros.h"
|
|
#include "log.h"
|
|
|
|
namespace benchmark {
|
|
namespace internal {
|
|
|
|
typedef void(AbortHandlerT)();
|
|
|
|
inline AbortHandlerT*& GetAbortHandler() {
|
|
static AbortHandlerT* handler = &std::abort;
|
|
return handler;
|
|
}
|
|
|
|
BENCHMARK_NORETURN inline void CallAbortHandler() {
|
|
GetAbortHandler()();
|
|
std::abort(); // fallback to enforce noreturn
|
|
}
|
|
|
|
// CheckHandler is the class constructed by failing CHECK macros. CheckHandler
|
|
// will log information about the failures and abort when it is destructed.
|
|
class CheckHandler {
|
|
public:
|
|
CheckHandler(const char* check, const char* file, const char* func, int line)
|
|
: log_(GetErrorLogInstance()) {
|
|
log_ << file << ":" << line << ": " << func << ": Check `" << check
|
|
<< "' failed. ";
|
|
}
|
|
|
|
LogType& GetLog() { return log_; }
|
|
|
|
BENCHMARK_NORETURN ~CheckHandler() BENCHMARK_NOEXCEPT_OP(false) {
|
|
log_ << std::endl;
|
|
CallAbortHandler();
|
|
}
|
|
|
|
CheckHandler& operator=(const CheckHandler&) = delete;
|
|
CheckHandler(const CheckHandler&) = delete;
|
|
CheckHandler() = delete;
|
|
|
|
private:
|
|
LogType& log_;
|
|
};
|
|
|
|
} // end namespace internal
|
|
} // end namespace benchmark
|
|
|
|
// The CHECK macro returns a std::ostream object that can have extra information
|
|
// written to it.
|
|
#ifndef NDEBUG
|
|
#define CHECK(b) \
|
|
(b ? ::benchmark::internal::GetNullLogInstance() \
|
|
: ::benchmark::internal::CheckHandler(#b, __FILE__, __func__, __LINE__) \
|
|
.GetLog())
|
|
#else
|
|
#define CHECK(b) ::benchmark::internal::GetNullLogInstance()
|
|
#endif
|
|
|
|
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
|
#define CHECK_NE(a, b) CHECK((a) != (b))
|
|
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
|
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
|
#define CHECK_GT(a, b) CHECK((a) > (b))
|
|
#define CHECK_LT(a, b) CHECK((a) < (b))
|
|
|
|
#define CHECK_FLOAT_EQ(a, b, eps) CHECK(std::fabs((a) - (b)) < (eps))
|
|
#define CHECK_FLOAT_NE(a, b, eps) CHECK(std::fabs((a) - (b)) >= (eps))
|
|
#define CHECK_FLOAT_GE(a, b, eps) CHECK((a) - (b) > -(eps))
|
|
#define CHECK_FLOAT_LE(a, b, eps) CHECK((b) - (a) > -(eps))
|
|
#define CHECK_FLOAT_GT(a, b, eps) CHECK((a) - (b) > (eps))
|
|
#define CHECK_FLOAT_LT(a, b, eps) CHECK((b) - (a) > (eps))
|
|
|
|
#endif // CHECK_H_
|