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

Method Apply

source/fuzz/fuzzer_pass_add_loop_preheaders.cpp:31–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 transformations, ignore_inapplicable_transformations) {}
30
31void FuzzerPassAddLoopPreheaders::Apply() {
32 for (auto& function : *GetIRContext()->module()) {
33 // Keep track of all the loop headers we want to add a preheader to.
34 std::vector<uint32_t> loop_header_ids_to_consider;
35 for (auto& block : function) {
36 // We only care about loop headers.
37 if (!block.IsLoopHeader()) {
38 continue;
39 }
40
41 // Randomly decide whether to consider this header.
42 if (!GetFuzzerContext()->ChoosePercentage(
43 GetFuzzerContext()->GetChanceOfAddingLoopPreheader())) {
44 continue;
45 }
46
47 // We exclude loop headers with just one predecessor (the back-edge block)
48 // because they are unreachable.
49 if (GetIRContext()->cfg()->preds(block.id()).size() < 2) {
50 continue;
51 }
52
53 loop_header_ids_to_consider.push_back(block.id());
54 }
55
56 for (uint32_t header_id : loop_header_ids_to_consider) {
57 // If not already present, add a preheader which is not also a loop
58 // header.
59 GetOrCreateSimpleLoopPreheader(header_id);
60 }
61 }
62}
63
64} // namespace fuzz
65} // namespace spvtools

Callers

nothing calls this directly

Calls 8

IsLoopHeaderMethod · 0.80
ChoosePercentageMethod · 0.80
moduleMethod · 0.45
sizeMethod · 0.45
cfgMethod · 0.45
idMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected