Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some trivial check-phase inlining. #4362

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion toolchain/base/value_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ class ValueStore
// Stores the value and returns an ID to reference it.
auto Add(ValueType value) -> IdT {
IdT id(values_.size());
CARBON_CHECK(id.index >= 0, "Id overflow");
// This routine is especially hot and the check here relatively expensive
// for the value provided, so only do this in debug builds to make tracking
// down issues easier.
CARBON_DCHECK(id.index >= 0, "Id overflow");
values_.push_back(std::move(value));
return id;
}
Expand Down
28 changes: 0 additions & 28 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ auto Context::CheckCompatibleImportedNodeKind(
kind, imported_kind);
}

auto Context::AddInstInNoBlock(SemIR::LocIdAndInst loc_id_and_inst)
-> SemIR::InstId {
auto inst_id = sem_ir().insts().AddInNoBlock(loc_id_and_inst);
CARBON_VLOG("AddInst: {0}\n", loc_id_and_inst.inst);
FinishInst(inst_id, loc_id_and_inst.inst);
return inst_id;
}

auto Context::AddInst(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId {
auto inst_id = AddInstInNoBlock(loc_id_and_inst);
inst_block_stack_.AddInstId(inst_id);
return inst_id;
}

auto Context::AddPlaceholderInstInNoBlock(SemIR::LocIdAndInst loc_id_and_inst)
-> SemIR::InstId {
auto inst_id = sem_ir().insts().AddInNoBlock(loc_id_and_inst);
Expand All @@ -179,20 +165,6 @@ auto Context::AddPlaceholderInst(SemIR::LocIdAndInst loc_id_and_inst)
return inst_id;
}

auto Context::AddPatternInst(SemIR::LocIdAndInst loc_id_and_inst)
-> SemIR::InstId {
auto inst_id = AddInstInNoBlock(loc_id_and_inst);
pattern_block_stack_.AddInstId(inst_id);
return inst_id;
}

auto Context::AddConstant(SemIR::Inst inst, bool is_symbolic)
-> SemIR::ConstantId {
auto const_id = constants().GetOrAdd(inst, is_symbolic);
CARBON_VLOG("AddConstant: {0}\n", inst);
return const_id;
}

auto Context::ReplaceLocIdAndInstBeforeConstantUse(
SemIR::InstId inst_id, SemIR::LocIdAndInst loc_id_and_inst) -> void {
sem_ir().insts().SetLocIdAndInst(inst_id, loc_id_and_inst);
Expand Down
25 changes: 21 additions & 4 deletions toolchain/check/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class Context {
auto VerifyOnFinish() -> void;

// Adds an instruction to the current block, returning the produced ID.
auto AddInst(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId;
auto AddInst(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId {
auto inst_id = AddInstInNoBlock(loc_id_and_inst);
inst_block_stack_.AddInstId(inst_id);
return inst_id;
}

// Convenience for AddInst with typed nodes.
template <typename InstT, typename LocT>
Expand All @@ -106,7 +110,12 @@ class Context {

// Adds an instruction in no block, returning the produced ID. Should be used
// rarely.
auto AddInstInNoBlock(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId;
auto AddInstInNoBlock(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId {
auto inst_id = sem_ir().insts().AddInNoBlock(loc_id_and_inst);
CARBON_VLOG("AddInst: {0}\n", loc_id_and_inst.inst);
FinishInst(inst_id, loc_id_and_inst.inst);
return inst_id;
}

// Convenience for AddInstInNoBlock with typed nodes.
template <typename InstT, typename LocT>
Expand All @@ -128,7 +137,11 @@ class Context {

// Adds an instruction to the current pattern block, returning the produced
// ID.
auto AddPatternInst(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId;
auto AddPatternInst(SemIR::LocIdAndInst loc_id_and_inst) -> SemIR::InstId {
auto inst_id = AddInstInNoBlock(loc_id_and_inst);
pattern_block_stack_.AddInstId(inst_id);
return inst_id;
}

// Convenience for AddPatternInst with typed nodes.
template <typename InstT>
Expand All @@ -139,7 +152,11 @@ class Context {
}

// Adds an instruction to the constants block, returning the produced ID.
auto AddConstant(SemIR::Inst inst, bool is_symbolic) -> SemIR::ConstantId;
auto AddConstant(SemIR::Inst inst, bool is_symbolic) -> SemIR::ConstantId {
auto const_id = constants().GetOrAdd(inst, is_symbolic);
CARBON_VLOG("AddConstant: {0}\n", inst);
return const_id;
}

// Pushes a parse tree node onto the stack, storing the SemIR::Inst as the
// result.
Expand Down
Loading