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

Method Apply

source/fuzz/fuzzer_pass_adjust_function_controls.cpp:30–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 transformations, ignore_inapplicable_transformations) {}
29
30void FuzzerPassAdjustFunctionControls::Apply() {
31 // Consider every function in the module.
32 for (auto& function : *GetIRContext()->module()) {
33 // Randomly decide whether to adjust this function's controls.
34 if (GetFuzzerContext()->ChoosePercentage(
35 GetFuzzerContext()->GetChanceOfAdjustingFunctionControl())) {
36 // Grab the function control mask for the function in its present form.
37 uint32_t existing_function_control_mask =
38 function.DefInst().GetSingleWordInOperand(0);
39
40 // For the new mask, we first randomly select one of three basic masks:
41 // None, Inline or DontInline. These are always valid (and are mutually
42 // exclusive).
43 std::vector<spv::FunctionControlMask> basic_function_control_masks = {
44 spv::FunctionControlMask::MaskNone, spv::FunctionControlMask::Inline,
45 spv::FunctionControlMask::DontInline};
46 uint32_t new_function_control_mask =
47 uint32_t(basic_function_control_masks[GetFuzzerContext()->RandomIndex(
48 basic_function_control_masks)]);
49
50 // We now consider the Pure and Const mask bits. If these are already
51 // set on the function then it's OK to keep them, but also interesting
52 // to consider dropping them, so we decide randomly in each case.
53 for (auto mask_bit :
54 {spv::FunctionControlMask::Pure, spv::FunctionControlMask::Const}) {
55 if ((existing_function_control_mask & uint32_t(mask_bit)) &&
56 GetFuzzerContext()->ChooseEven()) {
57 new_function_control_mask |= uint32_t(mask_bit);
58 }
59 }
60
61 // Create and add a transformation.
62 TransformationSetFunctionControl transformation(
63 function.DefInst().result_id(), new_function_control_mask);
64 ApplyTransformation(transformation);
65 }
66 }
67}
68
69} // namespace fuzz
70} // namespace spvtools

Callers

nothing calls this directly

Calls 7

ChoosePercentageMethod · 0.80
RandomIndexMethod · 0.80
ChooseEvenMethod · 0.80
moduleMethod · 0.45
result_idMethod · 0.45

Tested by

no test coverage detected