mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01: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) ```
79 lines
2.4 KiB
C++
79 lines
2.4 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
|
|
|
|
#include "toolchain/check/inst_block_stack.h"
|
|
|
|
#include "common/vlog.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
auto InstBlockStack::Push(SemIR::InstBlockId id) -> void {
|
|
CARBON_VLOG("{0} Push {1}\n", name_, id_stack_.size());
|
|
CARBON_CHECK(id_stack_.size() < (1 << 20))
|
|
<< "Excessive stack size: likely infinite loop";
|
|
id_stack_.push_back(id);
|
|
insts_stack_.PushArray();
|
|
}
|
|
|
|
auto InstBlockStack::Push(SemIR::InstBlockId id,
|
|
llvm::ArrayRef<SemIR::InstId> inst_ids) -> void {
|
|
Push(id);
|
|
insts_stack_.AppendToTop(inst_ids);
|
|
}
|
|
|
|
auto InstBlockStack::PeekOrAdd(int depth) -> SemIR::InstBlockId {
|
|
CARBON_CHECK(static_cast<int>(id_stack_.size()) > depth) << "no such block";
|
|
int index = id_stack_.size() - depth - 1;
|
|
auto& slot = id_stack_[index];
|
|
if (!slot.is_valid()) {
|
|
slot = sem_ir_->inst_blocks().AddDefaultValue();
|
|
}
|
|
return slot;
|
|
}
|
|
|
|
auto InstBlockStack::Pop() -> SemIR::InstBlockId {
|
|
CARBON_CHECK(!empty()) << "no current block";
|
|
auto id = id_stack_.pop_back_val();
|
|
auto insts = insts_stack_.PeekArray();
|
|
|
|
// Finalize the block.
|
|
if (!insts.empty() && id != SemIR::InstBlockId::Unreachable) {
|
|
if (id.is_valid()) {
|
|
sem_ir_->inst_blocks().Set(id, insts);
|
|
} else {
|
|
id = sem_ir_->inst_blocks().Add(insts);
|
|
}
|
|
}
|
|
|
|
insts_stack_.PopArray();
|
|
|
|
CARBON_VLOG("{0} Pop {1}: {2}\n", name_, id_stack_.size(), id);
|
|
return id.is_valid() ? id : SemIR::InstBlockId::Empty;
|
|
}
|
|
|
|
auto InstBlockStack::PopAndDiscard() -> void {
|
|
CARBON_CHECK(!empty()) << "no current block";
|
|
id_stack_.pop_back();
|
|
insts_stack_.PopArray();
|
|
CARBON_VLOG("{0} PopAndDiscard {1}\n", name_, id_stack_.size());
|
|
}
|
|
|
|
auto InstBlockStack::PrintForStackDump(SemIR::Formatter& formatter, int indent,
|
|
llvm::raw_ostream& output) const
|
|
-> void {
|
|
output.indent(indent);
|
|
output << name_ << ":\n";
|
|
for (const auto& [i, id] : llvm::enumerate(id_stack_)) {
|
|
output.indent(indent + 2);
|
|
output << i << ". " << id;
|
|
formatter.PrintPartialTrailingCodeBlock(insts_stack_.PeekArrayAt(i),
|
|
indent + 4, output);
|
|
output << "\n";
|
|
}
|
|
}
|
|
|
|
} // namespace Carbon::Check
|