jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith. Herald added a subscriber: mgorny. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This patch adds a micro-benchmark for command line round-tripping. The hard-coded arguments come from the longest record in LLVM's `compile_commands.json` on Linux. Results for release build with assertions: ------------------------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------------------------ BM_CompilerInvocationNoRoundTrip 2653056 ns 2652398 ns 269 BM_CompilerInvocationDoRoundTrip 2932063 ns 2931050 ns 239 Results for release build without assertions: ------------------------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------------------------ BM_CompilerInvocationNoRoundTrip 2474006 ns 2473101 ns 276 BM_CompilerInvocationDoRoundTrip 2741366 ns 2740046 ns 259 This is a 10% increase in run-time in both scenarios. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D95516 Files: clang/CMakeLists.txt clang/benchmarks/CMakeLists.txt clang/benchmarks/CompilerInvocationBench.cpp
Index: clang/benchmarks/CompilerInvocationBench.cpp =================================================================== --- /dev/null +++ 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<const char *> 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<DiagnosticsEngine> 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(); Index: clang/benchmarks/CMakeLists.txt =================================================================== --- /dev/null +++ clang/benchmarks/CMakeLists.txt @@ -0,0 +1,7 @@ +add_benchmark(CompilerInvocationBench CompilerInvocationBench.cpp) + +target_link_libraries(CompilerInvocationBench + PRIVATE + clangFrontend + LLVMSupport + ) Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ 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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits