Add a separate store for computed constant values. (#3362)

This moves the instructions generated for type values out of the block
in which they happen to first be referenced, and into shared storage.
This commit is contained in:
Richard Smith
2023-11-04 23:48:13 +00:00
committed by GitHub
parent a0bacbb26b
commit 184eafd521
130 changed files with 1075 additions and 625 deletions
+11 -4
View File
@@ -64,6 +64,13 @@ auto Context::AddInst(SemIR::Inst inst) -> SemIR::InstId {
return inst_id;
}
auto Context::AddConstantInst(SemIR::Inst inst) -> SemIR::InstId {
auto inst_id = insts().AddInNoBlock(inst);
constants().Add(inst_id);
CARBON_VLOG() << "AddConstantInst: " << inst << "\n";
return inst_id;
}
auto Context::AddInstAndPush(Parse::Node parse_node, SemIR::Inst inst) -> void {
auto inst_id = AddInst(inst);
node_stack_.Push(parse_node, inst_id);
@@ -594,7 +601,7 @@ class TypeCompleter {
if (field_value_rep.type_id != field.field_type_id) {
same_as_object_rep = false;
field.field_type_id = field_value_rep.type_id;
field_id = context_.AddInst(field);
field_id = context_.AddConstantInst(field);
}
value_rep_fields.push_back(field_id);
}
@@ -882,7 +889,7 @@ auto Context::CanonicalizeTypeAndAddInstIfNew(SemIR::Inst inst)
auto profile_node = [&](llvm::FoldingSetNodeID& canonical_id) {
ProfileType(*this, inst, canonical_id);
};
auto make_inst = [&] { return AddInst(inst); };
auto make_inst = [&] { return AddConstantInst(inst); };
return CanonicalizeTypeImpl(inst.kind(), profile_node, make_inst);
}
@@ -917,8 +924,8 @@ auto Context::CanonicalizeTupleType(Parse::Node parse_node,
ProfileTupleType(type_ids, canonical_id);
};
auto make_tuple_inst = [&] {
return AddInst(SemIR::TupleType{parse_node, SemIR::TypeId::TypeType,
type_blocks().Add(type_ids)});
return AddConstantInst(SemIR::TupleType{parse_node, SemIR::TypeId::TypeType,
type_blocks().Add(type_ids)});
};
return CanonicalizeTypeImpl(SemIR::TupleType::Kind, profile_tuple,
make_tuple_inst);