#include "source/fuzz/transformation_set_selection_control.h"
namespace spvtools {
namespace fuzz {
TransformationSetSelectionControl::TransformationSetSelectionControl(
protobufs::TransformationSetSelectionControl message)
: message_(std::move(message)) {}
TransformationSetSelectionControl::TransformationSetSelectionControl(
uint32_t block_id, uint32_t selection_control) {
message_.set_block_id(block_id);
message_.set_selection_control(selection_control);
}
bool TransformationSetSelectionControl::IsApplicable(
opt::IRContext* ir_context, const TransformationContext& ) const {
assert((spv::SelectionControlMask(message_.selection_control()) ==
spv::SelectionControlMask::MaskNone ||
spv::SelectionControlMask(message_.selection_control()) ==
spv::SelectionControlMask::Flatten ||
spv::SelectionControlMask(message_.selection_control()) ==
spv::SelectionControlMask::DontFlatten) &&
"Selection control should never be set to something other than "
"'None', 'Flatten' or 'DontFlatten'");
if (auto block = ir_context->get_instr_block(message_.block_id())) {
if (auto merge_inst = block->GetMergeInst()) {
return merge_inst->opcode() == spv::Op::OpSelectionMerge;
}
}
return false;
}
void TransformationSetSelectionControl::Apply(
opt::IRContext* ir_context, TransformationContext* ) const {
ir_context->get_instr_block(message_.block_id())
->GetMergeInst()
->SetInOperand(1, {message_.selection_control()});
}
protobufs::Transformation TransformationSetSelectionControl::ToMessage() const {
protobufs::Transformation result;
*result.mutable_set_selection_control() = message_;
return result;
}
std::unordered_set<uint32_t> TransformationSetSelectionControl::GetFreshIds()
const {
return std::unordered_set<uint32_t>();
}
}
}