MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / IsApplicable

Method IsApplicable

source/fuzz/transformation_permute_phi_operands.cpp:37–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37bool 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
68void TransformationPermutePhiOperands::Apply(
69 opt::IRContext* ir_context, TransformationContext* /*unused*/) const {

Callers

nothing calls this directly

Calls 11

HasDuplicatesFunction · 0.85
IsPermutationOfRangeFunction · 0.85
NumInOperandsMethod · 0.80
GetDefMethod · 0.45
get_def_use_mgrMethod · 0.45
result_idMethod · 0.45
opcodeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected