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

Method ReplayPrefixAndAddFunction

source/fuzz/added_function_reducer.cpp:182–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180}
181
182void AddedFunctionReducer::ReplayPrefixAndAddFunction(
183 std::vector<uint32_t>* binary_out,
184 std::unordered_set<uint32_t>* irrelevant_pointee_global_variables) const {
185 assert(transformation_sequence_in_
186 .transformation(index_of_add_function_transformation_)
187 .has_add_function() &&
188 "A TransformationAddFunction is required at the given index.");
189
190 auto replay_result = Replayer(target_env_, consumer_, binary_in_,
191 initial_facts_, transformation_sequence_in_,
192 index_of_add_function_transformation_,
193 validate_during_replay_, validator_options_)
194 .Run();
195 assert(replay_result.status == Replayer::ReplayerResultStatus::kComplete &&
196 "Replay should succeed");
197 assert(static_cast<uint32_t>(
198 replay_result.applied_transformations.transformation_size()) ==
199 index_of_add_function_transformation_ &&
200 "All requested transformations should have applied.");
201
202 auto* ir_context = replay_result.transformed_module.get();
203
204 for (auto& type_or_value : ir_context->module()->types_values()) {
205 if (type_or_value.opcode() != spv::Op::OpVariable) {
206 continue;
207 }
208 if (replay_result.transformation_context->GetFactManager()
209 ->PointeeValueIsIrrelevant(type_or_value.result_id())) {
210 irrelevant_pointee_global_variables->insert(type_or_value.result_id());
211 }
212 }
213
214 // Add the function associated with the transformation at
215 // |index_of_add_function_transformation| to the module. By construction this
216 // should succeed.
217 const protobufs::TransformationAddFunction&
218 transformation_add_function_message =
219 transformation_sequence_in_
220 .transformation(index_of_add_function_transformation_)
221 .add_function();
222 bool success = TransformationAddFunction(transformation_add_function_message)
223 .TryToAddFunction(ir_context);
224 (void)success; // Keep release mode compilers happy.
225 assert(success && "Addition of the function should have succeeded.");
226
227 // Get the binary representation of the module with this function added.
228 ir_context->module()->ToBinary(binary_out, false);
229}
230
231void AddedFunctionReducer::ReplayAdaptedTransformations(
232 const std::vector<uint32_t>& binary_under_reduction,

Callers

nothing calls this directly

Calls 13

ReplayerClass · 0.85
getMethod · 0.80
GetFactManagerMethod · 0.80
TryToAddFunctionMethod · 0.80
RunMethod · 0.45
types_valuesMethod · 0.45
moduleMethod · 0.45
opcodeMethod · 0.45
result_idMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected