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

Class AddedFunctionReducer

source/fuzz/added_function_reducer.h:31–188  ·  view source on GitHub ↗

An auxiliary class used by Shrinker, this class takes care of using spirv-reduce to reduce the body of a function encoded in an AddFunction transformation, in case a smaller, simpler function can be added instead.

Source from the content-addressed store, hash-verified

29// spirv-reduce to reduce the body of a function encoded in an AddFunction
30// transformation, in case a smaller, simpler function can be added instead.
31class AddedFunctionReducer {
32 public:
33 // Possible statuses that can result from running the shrinker.
34 enum class AddedFunctionReducerResultStatus {
35 kComplete,
36 kReductionFailed,
37 };
38
39 struct AddedFunctionReducerResult {
40 AddedFunctionReducerResultStatus status;
41 std::vector<uint32_t> transformed_binary;
42 protobufs::TransformationSequence applied_transformations;
43 uint32_t num_reduction_attempts;
44 };
45
46 AddedFunctionReducer(
47 spv_target_env target_env, MessageConsumer consumer,
48 const std::vector<uint32_t>& binary_in,
49 const protobufs::FactSequence& initial_facts,
50 const protobufs::TransformationSequence& transformation_sequence_in,
51 uint32_t index_of_add_function_transformation,
52 const Shrinker::InterestingnessFunction&
53 shrinker_interestingness_function,
54 bool validate_during_replay, spv_validator_options validator_options,
55 uint32_t shrinker_step_limit, uint32_t num_existing_shrink_attempts);
56
57 // Disables copy/move constructor/assignment operations.
58 AddedFunctionReducer(const AddedFunctionReducer&) = delete;
59 AddedFunctionReducer(AddedFunctionReducer&&) = delete;
60 AddedFunctionReducer& operator=(const AddedFunctionReducer&) = delete;
61 AddedFunctionReducer& operator=(AddedFunctionReducer&&) = delete;
62
63 ~AddedFunctionReducer();
64
65 // Invokes spirv-reduce on the function in the AddFunction transformation
66 // identified by |index_of_add_function_transformation|. Returns a sequence
67 // of transformations identical to |transformation_sequence_in|, except that
68 // the AddFunction transformation at |index_of_add_function_transformation|
69 // might have been simplified. The binary associated with applying the
70 // resulting sequence of transformations to |binary_in| is also returned, as
71 // well as the number of reduction steps that spirv-reduce made.
72 //
73 // On failure, an empty transformation sequence and binary are returned,
74 // with a placeholder value of 0 for the number of reduction attempts.
75 AddedFunctionReducerResult Run();
76
77 private:
78 // Yields, via |binary_out|, the binary obtained by applying transformations
79 // [0, |index_of_added_function_| - 1] from |transformations_in_| to
80 // |binary_in_|, and then adding the raw function encoded in
81 // |transformations_in_[index_of_added_function_]| (without adapting that
82 // function to make it livesafe). This function has |added_function_id_| as
83 // its result id.
84 //
85 // The ids associated with all global variables in |binary_out| that had the
86 // "irrelevant pointee value" fact are also returned via
87 // |irrelevant_pointee_global_variables|.
88 //

Callers 1

RunMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected