#include "source/fuzz/fuzzer_pass_swap_commutable_operands.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "source/fuzz/transformation_swap_commutable_operands.h"
namespace spvtools {
namespace fuzz {
FuzzerPassSwapCommutableOperands::FuzzerPassSwapCommutableOperands(
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 FuzzerPassSwapCommutableOperands::Apply() {
auto context = GetIRContext();
context->module()->ForEachInst(
[this, context](opt::Instruction* instruction) {
if (spvOpcodeIsCommutativeBinaryOperator(instruction->opcode()) &&
GetFuzzerContext()->ChooseEven()) {
auto instructionDescriptor =
MakeInstructionDescriptor(context, instruction);
auto transformation =
TransformationSwapCommutableOperands(instructionDescriptor);
ApplyTransformation(transformation);
}
});
}
}
}