spirv-fuzz: iterate over blocks in replace linear algebra pass (#3654)

This PR changes the way FuzzerPassReplaceLinearAlgebraInstructions iterates over the module instructions. It avoids iterating over non-relevant instructions (globals, types, etc.).
This commit is contained in:
André Perez 2020-08-06 09:00:17 -03:00 committed by GitHub
parent efc85ff661
commit d29eac95aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,23 +36,27 @@ FuzzerPassReplaceLinearAlgebraInstructions::
void FuzzerPassReplaceLinearAlgebraInstructions::Apply() {
// For each instruction, checks whether it is a linear algebra instruction. In
// this case, the transformation is randomly applied.
GetIRContext()->module()->ForEachInst([this](opt::Instruction* instruction) {
if (!spvOpcodeIsLinearAlgebra(instruction->opcode())) {
return;
}
for (auto& function : *GetIRContext()->module()) {
for (auto& block : function) {
for (auto& instruction : block) {
if (!spvOpcodeIsLinearAlgebra(instruction.opcode())) {
continue;
}
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()
->GetChanceOfReplacingLinearAlgebraInstructions())) {
return;
}
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()
->GetChanceOfReplacingLinearAlgebraInstructions())) {
continue;
}
ApplyTransformation(TransformationReplaceLinearAlgebraInstruction(
GetFuzzerContext()->GetFreshIds(
TransformationReplaceLinearAlgebraInstruction::
GetRequiredFreshIdCount(GetIRContext(), instruction)),
MakeInstructionDescriptor(GetIRContext(), instruction)));
});
ApplyTransformation(TransformationReplaceLinearAlgebraInstruction(
GetFuzzerContext()->GetFreshIds(
TransformationReplaceLinearAlgebraInstruction::
GetRequiredFreshIdCount(GetIRContext(), &instruction)),
MakeInstructionDescriptor(GetIRContext(), &instruction)));
}
}
}
}
} // namespace fuzz