mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Disable InstNamer in lowering unless we're emitting textual llvm IR (#7878)
`InstNamer` takes O(N^2) time to resolve N colliding inst names, so it should be limited to textual dumps (where we can presumably prioritize readability over performance). Without this change, compiling 200,000 destructor calls took hours. With this change, compiling 1,000,000 destructor calls takes about 30 seconds.
This commit is contained in:
@@ -191,6 +191,8 @@ auto CompilationUnit::RunLower() -> void {
|
||||
options.vlog_stream = vlog_stream_;
|
||||
options.opt_level = options_->opt_level;
|
||||
options.mangle_string_fingerprint = options_->mangle_string_fingerprint;
|
||||
// Only generate inst names if the llvm IR needs to be human-readable.
|
||||
options.generate_inst_names = options_->dump_llvm_ir;
|
||||
module_ = Lower::LowerToLLVM(*llvm_context_, driver_env_->fs,
|
||||
cache_->tree_and_subtrees_getters(), *sem_ir_,
|
||||
total_ir_count_, options);
|
||||
|
||||
@@ -27,10 +27,13 @@ auto LowerToLLVM(
|
||||
sem_ir.filename(), total_ir_count, options.opt_level,
|
||||
options.mangle_string_fingerprint, options.vlog_stream);
|
||||
|
||||
// TODO: Consider disabling instruction naming by default if we're not
|
||||
// producing textual LLVM IR.
|
||||
SemIR::InstNamer inst_namer(&sem_ir, total_ir_count);
|
||||
context.GetFileContext(&sem_ir, &inst_namer).LowerDefinitions();
|
||||
std::optional<SemIR::InstNamer> inst_namer;
|
||||
if (options.generate_inst_names) {
|
||||
inst_namer.emplace(&sem_ir, total_ir_count);
|
||||
}
|
||||
context
|
||||
.GetFileContext(&sem_ir, inst_namer.has_value() ? &*inst_namer : nullptr)
|
||||
.LowerDefinitions();
|
||||
|
||||
std::unique_ptr<llvm::Module> module = std::move(context).Finalize();
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ struct LowerToLLVMOptions {
|
||||
|
||||
// Whether to use the string form of the fingerprint for mangling.
|
||||
bool mangle_string_fingerprint = false;
|
||||
|
||||
// Whether to generate names for LLVM instructions.
|
||||
bool generate_inst_names = false;
|
||||
};
|
||||
|
||||
} // namespace Carbon::Lower
|
||||
|
||||
Reference in New Issue
Block a user