mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Replace FoldingSet with DenseMap for instruction canonicalization. (#3979)
Switch from recursing into non-canonical instruction fields to separately canonicalizing those fields. This means we now form canonical `InstBlockId`s, `TypeBlockId`s, `IntId`s, `FloatId`s, and `BindNameId`s at least in the cases when they're referenced by a constant instruction. This reduces the overall runtime for @chandlerc's 10MLoC example by 27.5% on my machine.
This commit is contained in:
@@ -141,9 +141,9 @@ static auto GetConstantValue(Context& context, SemIR::InstBlockId inst_block_id,
|
||||
|
||||
const_insts.push_back(const_inst_id);
|
||||
}
|
||||
// TODO: If the new block is identical to the original block, return the
|
||||
// original ID.
|
||||
return context.inst_blocks().Add(const_insts);
|
||||
// TODO: If the new block is identical to the original block, and we know the
|
||||
// old ID was canonical, return the original ID.
|
||||
return context.inst_blocks().AddCanonical(const_insts);
|
||||
}
|
||||
|
||||
// The constant value of a type block is that type block, but we still need to
|
||||
@@ -1054,6 +1054,7 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst)
|
||||
case CARBON_KIND(SemIR::BindSymbolicName bind): {
|
||||
// The constant form of a symbolic binding is an idealized form of the
|
||||
// original, with no equivalent value.
|
||||
bind.bind_name_id = context.bind_names().MakeCanonical(bind.bind_name_id);
|
||||
bind.value_id = SemIR::InstId::Invalid;
|
||||
return MakeConstantResult(context, bind, Phase::Symbolic);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user