From d29eac95aaa6edcb7daf6a651c78b57e318c47a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Perez?= Date: Thu, 6 Aug 2020 09:00:17 -0300 Subject: [PATCH] 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.). --- ...ss_replace_linear_algebra_instructions.cpp | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/source/fuzz/fuzzer_pass_replace_linear_algebra_instructions.cpp b/source/fuzz/fuzzer_pass_replace_linear_algebra_instructions.cpp index 984b7c342..c3e65789e 100644 --- a/source/fuzz/fuzzer_pass_replace_linear_algebra_instructions.cpp +++ b/source/fuzz/fuzzer_pass_replace_linear_algebra_instructions.cpp @@ -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