Refactor AddInst-family functions to their own file (#4941)

This in particular uses free functions because it's likely to end up
more consistent with types (versus a wrapper object for InstStore).
Note, this is unlikely to have a performance impact, but if it does, we
can look into related approaches (and we've already discussed using
LTO).

Renames `PendingBlock::AddInst` to `PendingBlock::Add` because
`MakeElementAccessInst` expects the matching name to exist.
This commit is contained in:
Jon Ross-Perkins
2025-02-14 19:44:36 +00:00
committed by GitHub
parent dd7c64bad0
commit 311b4ff03d
44 changed files with 875 additions and 695 deletions
+7 -6
View File
@@ -4,6 +4,7 @@
#include "toolchain/check/control_flow.h"
#include "toolchain/check/inst.h"
#include "toolchain/sem_ir/typed_insts.h"
namespace Carbon::Check {
@@ -16,7 +17,7 @@ static auto AddDominatedBlockAndBranchImpl(Context& context,
return SemIR::InstBlockId::Unreachable;
}
auto block_id = context.inst_blocks().AddDefaultValue();
context.AddInst<BranchNode>(node_id, {block_id, args...});
AddInst<BranchNode>(context, node_id, {block_id, args...});
return block_id;
}
@@ -49,7 +50,7 @@ auto AddConvergenceBlockAndPush(Context& context, Parse::NodeId node_id,
new_block_id = context.inst_blocks().AddDefaultValue();
}
CARBON_CHECK(node_id.has_value());
context.AddInst<SemIR::Branch>(node_id, {.target_id = new_block_id});
AddInst<SemIR::Branch>(context, node_id, {.target_id = new_block_id});
}
context.inst_block_stack().Pop();
}
@@ -68,8 +69,8 @@ auto AddConvergenceBlockWithArgAndPush(
if (new_block_id == SemIR::InstBlockId::Unreachable) {
new_block_id = context.inst_blocks().AddDefaultValue();
}
context.AddInst<SemIR::BranchWithArg>(
node_id, {.target_id = new_block_id, .arg_id = arg_id});
AddInst<SemIR::BranchWithArg>(
context, node_id, {.target_id = new_block_id, .arg_id = arg_id});
}
context.inst_block_stack().Pop();
}
@@ -79,8 +80,8 @@ auto AddConvergenceBlockWithArgAndPush(
// Acquire the result value.
SemIR::TypeId result_type_id =
context.insts().Get(*block_args.begin()).type_id();
return context.AddInst<SemIR::BlockArg>(
node_id, {.type_id = result_type_id, .block_id = new_block_id});
return AddInst<SemIR::BlockArg>(
context, node_id, {.type_id = result_type_id, .block_id = new_block_id});
}
auto SetBlockArgResultBeforeConstantUse(Context& context,