diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -879,6 +879,10 @@ process_llvm_pass_plugins() endif() +if (LLVM_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + configure_file( ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake ${CLANG_BINARY_DIR}/include/clang/Config/config.h) diff --git a/clang/benchmarks/CMakeLists.txt b/clang/benchmarks/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/clang/benchmarks/CMakeLists.txt @@ -0,0 +1,7 @@ +add_benchmark(CompilerInvocationBench CompilerInvocationBench.cpp) + +target_link_libraries(CompilerInvocationBench + PRIVATE + clangFrontend + LLVMSupport + ) diff --git a/clang/benchmarks/CompilerInvocationBench.cpp b/clang/benchmarks/CompilerInvocationBench.cpp new file mode 100644 --- /dev/null +++ b/clang/benchmarks/CompilerInvocationBench.cpp @@ -0,0 +1,115 @@ +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/CompilerInvocation.h" +#include "clang/Frontend/TextDiagnosticBuffer.h" + +#include "benchmark/benchmark.h" + +using namespace llvm; +using namespace clang; + +static std::vector GetArgs() { + return {"-DHAVE___CXA_THREAD_ATEXIT_IMPL", + "-D_GNU_SOURCE", + "-D_LIBCPP_BUILDING_LIBRARY", + "-D_LIBCPP_DISABLE_EXTERN_TEMPLATE", + "-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS", + "-D_LIBCXXABI_BUILDING_LIBRARY", + "-D_LIBCXXABI_LINK_PTHREAD_LIB", + "-D__STDC_CONSTANT_MACROS", + "-D__STDC_FORMAT_MACROS", + "-D__STDC_LIMIT_MACROS", + "-Iprojects/libcxxabi/src", + "-I/home/user/llvm-project/libcxxabi/src", + "-Iinclude", + "-I/home/user/llvm-project/llvm/include", + "-I/home/user/llvm-project/libcxxabi/include", + "-I/home/user/llvm-project/libcxxabi/../libcxx/include", + "-fPIC", + "-fvisibility-inlines-hidden", + "-Werror=date-time", + "-Werror=unguarded-availability-new", + "-Wall", + "-Wextra", + "-Wno-unused-parameter", + "-Wwrite-strings", + "-Wcast-qual", + "-Wmissing-field-initializers", + "-pedantic", + "-Wno-long-long", + "-Wimplicit-fallthrough", + "-Wcovered-switch-default", + "-Wno-noexcept-type", + "-Wnon-virtual-dtor", + "-Wdelete-non-virtual-dtor", + "-Wsuggest-override", + "-Wstring-conversion", + "-fdiagnostics-color", + "-ffunction-sections", + "-fdata-sections", + "-O2", + "-DNDEBUG", + "-fPIC", + "-nostdinc++", + "-Werror=return-type", + "-W", + "-Wall", + "-Wchar-subscripts", + "-Wconversion", + "-Wmismatched-tags", + "-Wmissing-braces", + "-Wnewline-eof", + "-Wunused-function", + "-Wshadow", + "-Wshorten-64-to-32", + "-Wsign-compare", + "-Wsign-conversion", + "-Wstrict-aliasing=2", + "-Wstrict-overflow=4", + "-Wunused-parameter", + "-Wunused-variable", + "-Wwrite-strings", + "-Wundef", + "-Wno-suggest-override", + "-Wno-error", + "-pedantic", + "-fstrict-aliasing", + "-funwind-tables", + "-D_DEBUG", + "-UNDEBUG", + "-std=c++20", + "-o", + "/dev/null", + "-c", + "/home/user/llvm-project/libcxxabi/src/cxa_exception_storage.cpp"}; +} + +static IntrusiveRefCntPtr GetDiags() { + return CompilerInstance::createDiagnostics(new DiagnosticOptions(), + new TextDiagnosticBuffer()); +} + +static void BM_CompilerInvocationNoRoundTrip(benchmark::State &State) { + auto Args = GetArgs(); + auto Diags = GetDiags(); + + for (auto _ : State) { + CompilerInvocation Invocation; + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + } +} + +static void BM_CompilerInvocationDoRoundTrip(benchmark::State &State) { + auto Args = GetArgs(); + Args.push_back("-round-trip-args"); + auto Diags = GetDiags(); + + for (auto _ : State) { + CompilerInvocation Invocation; + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + } +} + +BENCHMARK(BM_CompilerInvocationNoRoundTrip); +BENCHMARK(BM_CompilerInvocationDoRoundTrip); + +BENCHMARK_MAIN();