#include "source/fuzz/fuzzer_pass_merge_blocks.h"
#include <vector>
#include "source/fuzz/transformation_merge_blocks.h"
namespace spvtools {
namespace fuzz {
FuzzerPassMergeBlocks::FuzzerPassMergeBlocks(
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 FuzzerPassMergeBlocks::Apply() {
std::vector<TransformationMergeBlocks> potential_transformations;
for (auto& function : *GetIRContext()->module()) {
for (auto& block : function) {
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()->GetChanceOfMergingBlocks())) {
continue;
}
TransformationMergeBlocks transformation(block.id());
if (transformation.IsApplicable(GetIRContext(),
*GetTransformationContext())) {
potential_transformations.push_back(transformation);
}
}
}
while (!potential_transformations.empty()) {
auto transformation =
GetFuzzerContext()->RemoveAtRandomIndex(&potential_transformations);
MaybeApplyTransformation(transformation);
}
}
}
}