#include "source/fuzz/fuzzer_pass_expand_vector_reductions.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "source/fuzz/transformation_expand_vector_reduction.h"
namespace spvtools {
namespace fuzz {
FuzzerPassExpandVectorReductions::FuzzerPassExpandVectorReductions(
opt::IRContext* ir_context, TransformationContext* transformation_context,
FuzzerContext* fuzzer_context,
protobufs::TransformationSequence* transformations,
bool ignore_inapplicable_transformations)
: FuzzerPass(ir_context, transformation_context, fuzzer_context,
transformations, ignore_inapplicable_transformations) {}
void FuzzerPassExpandVectorReductions::Apply() {
for (auto& function : *GetIRContext()->module()) {
for (auto& block : function) {
for (auto& instruction : block) {
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()->GetChanceOfExpandingVectorReduction())) {
continue;
}
if (instruction.opcode() != spv::Op::OpAny &&
instruction.opcode() != spv::Op::OpAll) {
continue;
}
if (!fuzzerutil::CanMakeSynonymOf(
GetIRContext(), *GetTransformationContext(), instruction)) {
continue;
}
ApplyTransformation(TransformationExpandVectorReduction(
instruction.result_id(),
GetFuzzerContext()->GetFreshIds(
TransformationExpandVectorReduction::GetRequiredFreshIdCount(
GetIRContext(), &instruction))));
}
}
}
}
}
}