mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 19:55:11 +00:00
This mostly uses a hilarious set of regular expressions to mechanically switch all but two uses, and then manually fixed the last two. There weren't too many. Also simplifies the `vlog` implementation now that it's all going through a format string. This alone has a nice impact on parse and check of about 2% and 1% respectively. The impact on lex in my timings looks like noise (no change in instruction count, unlike the other phases). ``` name old cpu/op new cpu/op delta BM_CompileAPIFileDenseDecls<Phase::Lex>/256 39.1µs ± 3% 38.1µs ± 2% -2.42% (p=0.000 n=20+19) BM_CompileAPIFileDenseDecls<Phase::Lex>/1024 187µs ± 3% 183µs ± 1% -2.30% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Lex>/4096 776µs ± 4% 756µs ± 1% -2.62% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Lex>/16384 3.36ms ± 1% 3.33ms ± 1% -0.90% (p=0.000 n=18+18) BM_CompileAPIFileDenseDecls<Phase::Lex>/65536 14.4ms ± 2% 14.2ms ± 1% -1.41% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Lex>/262144 65.7ms ± 1% 65.2ms ± 2% -0.86% (p=0.002 n=19+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/256 87.5µs ± 1% 86.3µs ± 1% -1.43% (p=0.000 n=19+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/1024 438µs ± 2% 431µs ± 1% -1.54% (p=0.000 n=19+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/4096 1.81ms ± 2% 1.77ms ± 1% -2.12% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/16384 7.54ms ± 1% 7.43ms ± 1% -1.44% (p=0.000 n=19+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/65536 31.2ms ± 1% 30.6ms ± 1% -2.03% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Parse>/262144 133ms ± 1% 130ms ± 1% -1.85% (p=0.000 n=20+20) BM_CompileAPIFileDenseDecls<Phase::Check>/256 882µs ± 1% 878µs ± 1% -0.52% (p=0.001 n=17+19) BM_CompileAPIFileDenseDecls<Phase::Check>/1024 1.90ms ± 2% 1.88ms ± 1% -1.17% (p=0.000 n=19+19) BM_CompileAPIFileDenseDecls<Phase::Check>/4096 5.85ms ± 2% 5.76ms ± 1% -1.43% (p=0.000 n=20+19) BM_CompileAPIFileDenseDecls<Phase::Check>/16384 22.2ms ± 2% 21.9ms ± 2% -1.20% (p=0.000 n=20+19) BM_CompileAPIFileDenseDecls<Phase::Check>/65536 91.2ms ± 2% 90.3ms ± 1% -1.00% (p=0.000 n=20+19) BM_CompileAPIFileDenseDecls<Phase::Check>/262144 382ms ± 1% 380ms ± 1% -0.51% (p=0.003 n=18+19) ```
52 lines
2.1 KiB
C++
52 lines
2.1 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_COMMON_VLOG_H_
|
|
#define CARBON_COMMON_VLOG_H_
|
|
|
|
#include "common/ostream.h"
|
|
#include "common/template_string.h"
|
|
#include "llvm/Support/FormatVariadic.h"
|
|
|
|
namespace Carbon::Internal {
|
|
|
|
// Implements verbose logging.
|
|
//
|
|
// This is designed to minimize the overhead in callers by being a
|
|
// forcibly-outlined routine that takes a minimal number of parameters.
|
|
//
|
|
// Internally uses `llvm::formatv` to render the format string with any value
|
|
// arguments, and streams the result to the provided stream.
|
|
template <TemplateString FormatStr, typename... Ts>
|
|
[[clang::noinline, clang::preserve_most]] auto VLogImpl(
|
|
llvm::raw_ostream* stream, Ts&&... values) -> void {
|
|
*stream << llvm::formatv(FormatStr.c_str(), std::forward<Ts>(values)...);
|
|
}
|
|
|
|
} // namespace Carbon::Internal
|
|
|
|
// Logs when verbose logging is enabled (vlog_stream_ is non-null).
|
|
//
|
|
// For example:
|
|
// CARBON_VLOG("Verbose message: {0}", "extra information");
|
|
//
|
|
// The first argument must be a string literal format string valid for passing
|
|
// to `llvm::formatv`. If it contains any substitutions, those should be passed
|
|
// as subsequent arguments.
|
|
//
|
|
// Also supports a legacy syntax where no arguments are passed and the desired
|
|
// logging is streamed into the call:
|
|
// CARBON_VLOG() << "Legacy verbose message";
|
|
//
|
|
// However, the streaming syntax has higher overhead and can inhibit inlining.
|
|
// Code should prefer the format string form, and eventually when all code has
|
|
// migrated the streaming interface will be removed.
|
|
#define CARBON_VLOG(FormatStr, ...) \
|
|
__builtin_expect(vlog_stream_ == nullptr, true) \
|
|
? (void)0 \
|
|
: Carbon::Internal::VLogImpl<"" FormatStr>(vlog_stream_ __VA_OPT__(, ) \
|
|
__VA_ARGS__)
|
|
|
|
#endif // CARBON_COMMON_VLOG_H_
|