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
+6 -5
View File
@@ -6,6 +6,7 @@
#include "toolchain/check/control_flow.h"
#include "toolchain/check/convert.h"
#include "toolchain/check/handle.h"
#include "toolchain/check/inst.h"
namespace Carbon::Check {
@@ -60,7 +61,7 @@ auto HandleParseNode(Context& context, Parse::WhileStatementId node_id)
context.break_continue_stack().pop_back();
// Add the loop backedge.
context.AddInst<SemIR::Branch>(node_id, {.target_id = loop_header_id});
AddInst<SemIR::Branch>(context, node_id, {.target_id = loop_header_id});
context.inst_block_stack().Pop();
// Start emitting the loop exit block.
@@ -101,8 +102,8 @@ auto HandleParseNode(Context& context, Parse::BreakStatementStartId node_id)
"`break` can only be used in a loop");
context.emitter().Emit(node_id, BreakOutsideLoop);
} else {
context.AddInst<SemIR::Branch>(node_id,
{.target_id = stack.back().break_target});
AddInst<SemIR::Branch>(context, node_id,
{.target_id = stack.back().break_target});
}
context.inst_block_stack().Pop();
@@ -126,8 +127,8 @@ auto HandleParseNode(Context& context, Parse::ContinueStatementStartId node_id)
"`continue` can only be used in a loop");
context.emitter().Emit(node_id, ContinueOutsideLoop);
} else {
context.AddInst<SemIR::Branch>(node_id,
{.target_id = stack.back().continue_target});
AddInst<SemIR::Branch>(context, node_id,
{.target_id = stack.back().continue_target});
}
context.inst_block_stack().Pop();