spirv-fuzz: Make adding equation instructions more efficient (#4190)

Avoids unnecessary invalidation of analyses.
This commit is contained in:
Alastair Donaldson 2021-03-17 09:28:46 +00:00 committed by GitHub
parent e8ab7101f6
commit db2a706467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,13 +84,19 @@ void TransformationEquationInstruction::Apply(
rhs_id.push_back(id);
}
FindInstruction(message_.instruction_to_insert_before(), ir_context)
->InsertBefore(MakeUnique<opt::Instruction>(
ir_context, static_cast<SpvOp>(message_.opcode()),
MaybeGetResultTypeId(ir_context), message_.fresh_id(),
std::move(in_operands)));
auto new_instruction = MakeUnique<opt::Instruction>(
ir_context, static_cast<SpvOp>(message_.opcode()),
MaybeGetResultTypeId(ir_context), message_.fresh_id(),
std::move(in_operands));
auto new_instruction_ptr = new_instruction.get();
ir_context->InvalidateAnalysesExceptFor(opt::IRContext::kAnalysisNone);
auto insert_before =
FindInstruction(message_.instruction_to_insert_before(), ir_context);
insert_before->InsertBefore(std::move(new_instruction));
ir_context->get_def_use_mgr()->AnalyzeInstDefUse(new_instruction_ptr);
ir_context->set_instr_block(new_instruction_ptr,
ir_context->get_instr_block(insert_before));
// Add an equation fact as long as the result id is not irrelevant (it could
// be if we are inserting into a dead block).