mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:21:04 +01:00
Migrate all CARBON_VLOG to the format string variant. (#4284)
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) ```
This commit is contained in:
+13
-14
@@ -547,8 +547,7 @@ class Driver::CompilationUnit {
|
||||
success_ = false;
|
||||
return;
|
||||
}
|
||||
CARBON_VLOG() << "*** SourceBuffer ***\n```\n"
|
||||
<< source_->text() << "\n```\n";
|
||||
CARBON_VLOG("*** SourceBuffer ***\n```\n{0}\n```\n", source_->text());
|
||||
|
||||
LogCall("Lex::Lex",
|
||||
[&] { tokens_ = Lex::Lex(value_stores_, *source_, *consumer_); });
|
||||
@@ -559,7 +558,7 @@ class Driver::CompilationUnit {
|
||||
if (mem_usage_) {
|
||||
mem_usage_->Collect("tokens_", *tokens_);
|
||||
}
|
||||
CARBON_VLOG() << "*** Lex::TokenizedBuffer ***\n" << tokens_;
|
||||
CARBON_VLOG("*** Lex::TokenizedBuffer ***\n{0}", tokens_);
|
||||
if (tokens_->has_errors()) {
|
||||
success_ = false;
|
||||
}
|
||||
@@ -584,7 +583,7 @@ class Driver::CompilationUnit {
|
||||
if (mem_usage_) {
|
||||
mem_usage_->Collect("parse_tree_", *parse_tree_);
|
||||
}
|
||||
CARBON_VLOG() << "*** Parse::Tree ***\n" << parse_tree_;
|
||||
CARBON_VLOG("*** Parse::Tree ***\n{0}", parse_tree_);
|
||||
if (parse_tree_->has_errors()) {
|
||||
success_ = false;
|
||||
}
|
||||
@@ -618,7 +617,7 @@ class Driver::CompilationUnit {
|
||||
}
|
||||
|
||||
if (options_.dump_raw_sem_ir && IncludeInDumps()) {
|
||||
CARBON_VLOG() << "*** Raw SemIR::File ***\n" << *sem_ir_ << "\n";
|
||||
CARBON_VLOG("*** Raw SemIR::File ***\n{0}\n", *sem_ir_);
|
||||
sem_ir_->Print(driver_->output_stream_, options_.builtin_sem_ir);
|
||||
if (options_.dump_sem_ir) {
|
||||
driver_->output_stream_ << "\n";
|
||||
@@ -629,7 +628,7 @@ class Driver::CompilationUnit {
|
||||
if (vlog_stream_ || print) {
|
||||
SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_);
|
||||
if (vlog_stream_) {
|
||||
CARBON_VLOG() << "*** SemIR::File ***\n";
|
||||
CARBON_VLOG("*** SemIR::File ***\n");
|
||||
formatter.Print(*vlog_stream_);
|
||||
}
|
||||
if (print) {
|
||||
@@ -655,7 +654,7 @@ class Driver::CompilationUnit {
|
||||
&inst_namer, vlog_stream_);
|
||||
});
|
||||
if (vlog_stream_) {
|
||||
CARBON_VLOG() << "*** llvm::Module ***\n";
|
||||
CARBON_VLOG("*** llvm::Module ***\n");
|
||||
module_->print(*vlog_stream_, /*AAW=*/nullptr,
|
||||
/*ShouldPreserveUseListOrder=*/false,
|
||||
/*IsForDebug=*/true);
|
||||
@@ -702,7 +701,7 @@ class Driver::CompilationUnit {
|
||||
return false;
|
||||
}
|
||||
if (vlog_stream_) {
|
||||
CARBON_VLOG() << "*** Assembly ***\n";
|
||||
CARBON_VLOG("*** Assembly ***\n");
|
||||
codegen->EmitAssembly(*vlog_stream_);
|
||||
}
|
||||
|
||||
@@ -739,7 +738,7 @@ class Driver::CompilationUnit {
|
||||
// Currently each unit overwrites the output from the previous one in
|
||||
// this case.
|
||||
}
|
||||
CARBON_VLOG() << "Writing output to: " << output_filename << "\n";
|
||||
CARBON_VLOG("Writing output to: {0}\n", output_filename);
|
||||
|
||||
std::error_code ec;
|
||||
llvm::raw_fd_ostream output_file(output_filename, ec,
|
||||
@@ -779,9 +778,9 @@ class Driver::CompilationUnit {
|
||||
// Wraps a call with log statements to indicate start and end.
|
||||
auto LogCall(llvm::StringLiteral label, llvm::function_ref<void()> fn)
|
||||
-> void {
|
||||
CARBON_VLOG() << "*** " << label << ": " << input_filename_ << " ***\n";
|
||||
CARBON_VLOG("*** {0}: {1} ***\n", label, input_filename_);
|
||||
fn();
|
||||
CARBON_VLOG() << "*** " << label << " done ***\n";
|
||||
CARBON_VLOG("*** {0} done ***\n", label);
|
||||
}
|
||||
|
||||
// Returns true if the file can be dumped.
|
||||
@@ -910,10 +909,10 @@ auto Driver::Compile(const CompileOptions& options,
|
||||
node_converters.emplace_back(unit.tokens, unit.tokens->source().filename(),
|
||||
unit.get_parse_tree_and_subtrees);
|
||||
}
|
||||
CARBON_VLOG() << "*** Check::CheckParseTrees ***\n";
|
||||
CARBON_VLOG("*** Check::CheckParseTrees ***\n");
|
||||
Check::CheckParseTrees(check_units, node_converters, options.prelude_import,
|
||||
vlog_stream_);
|
||||
CARBON_VLOG() << "*** Check::CheckParseTrees done ***\n";
|
||||
CARBON_VLOG("*** Check::CheckParseTrees done ***\n");
|
||||
for (auto& unit : units) {
|
||||
if (unit->has_source()) {
|
||||
unit->PostCheck();
|
||||
@@ -926,7 +925,7 @@ auto Driver::Compile(const CompileOptions& options,
|
||||
// Unlike previous steps, errors block further progress.
|
||||
if (std::any_of(units.begin(), units.end(),
|
||||
[&](const auto& unit) { return !unit->success(); })) {
|
||||
CARBON_VLOG() << "*** Stopping before lowering due to errors ***";
|
||||
CARBON_VLOG("*** Stopping before lowering due to errors ***");
|
||||
return make_result();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user