| 35 | } |
| 36 | |
| 37 | bool TransformationPermutePhiOperands::IsApplicable( |
| 38 | opt::IRContext* ir_context, const TransformationContext& /*unused*/) const { |
| 39 | // Check that |message_.result_id| is valid. |
| 40 | const auto* inst = |
| 41 | ir_context->get_def_use_mgr()->GetDef(message_.result_id()); |
| 42 | if (!inst || inst->opcode() != spv::Op::OpPhi) { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | // Check that |message_.permutation| has expected size. |
| 47 | auto expected_permutation_size = inst->NumInOperands() / 2; |
| 48 | if (static_cast<uint32_t>(message_.permutation().size()) != |
| 49 | expected_permutation_size) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // Check that |message_.permutation| has elements in range |
| 54 | // [0, expected_permutation_size - 1]. |
| 55 | std::vector<uint32_t> permutation(message_.permutation().begin(), |
| 56 | message_.permutation().end()); |
| 57 | assert(!fuzzerutil::HasDuplicates(permutation) && |
| 58 | "Permutation has duplicates"); |
| 59 | |
| 60 | // We must check whether the permutation is empty first because in that case |
| 61 | // |expected_permutation_size - 1| will produce |
| 62 | // |std::numeric_limits<uint32_t>::max()| since it's an unsigned integer. |
| 63 | return permutation.empty() || |
| 64 | fuzzerutil::IsPermutationOfRange(permutation, 0, |
| 65 | expected_permutation_size - 1); |
| 66 | } |
| 67 | |
| 68 | void TransformationPermutePhiOperands::Apply( |
| 69 | opt::IRContext* ir_context, TransformationContext* /*unused*/) const { |
nothing calls this directly
no test coverage detected