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:
Richard Smith
2024-05-23 00:48:49 +00:00
committed by GitHub
parent 7b4b7abc6e
commit 5c8fa6ad5c
35 changed files with 479 additions and 505 deletions
+4 -3
View File
@@ -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);
}