#include "source/fuzz/fuzzer_pass_propagate_instructions_down.h"
#include "source/fuzz/fuzzer_context.h"
#include "source/fuzz/transformation_propagate_instruction_down.h"
namespace spvtools {
namespace fuzz {
FuzzerPassPropagateInstructionsDown::FuzzerPassPropagateInstructionsDown(
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 FuzzerPassPropagateInstructionsDown::Apply() {
for (const auto& function : *GetIRContext()->module()) {
std::vector<const opt::BasicBlock*> reachable_blocks;
for (const auto& block : function) {
if (GetIRContext()->IsReachable(block)) {
reachable_blocks.push_back(&block);
}
}
for (const auto* block : reachable_blocks) {
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()->GetChanceOfPropagatingInstructionsDown())) {
continue;
}
if (TransformationPropagateInstructionDown::IsApplicableToBlock(
GetIRContext(), block->id())) {
std::map<uint32_t, uint32_t> fresh_ids;
for (auto id :
TransformationPropagateInstructionDown::GetAcceptableSuccessors(
GetIRContext(), block->id())) {
fresh_ids[id] = GetFuzzerContext()->GetFreshId();
}
ApplyTransformation(TransformationPropagateInstructionDown(
block->id(), GetFuzzerContext()->GetFreshId(), fresh_ids));
}
}
}
}
}
}