Debian Codegraph @

third_party/spirv-tools/source/fuzz/transformation_replace_opselect_with_conditional_branch.h

raw
1 // Copyright (c) 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef SOURCE_FUZZ_TRANSFORMATION_REPLACE_OPSELECT_WITH_CONDITIONAL_BRANCH_H
16 #define SOURCE_FUZZ_TRANSFORMATION_REPLACE_OPSELECT_WITH_CONDITIONAL_BRANCH_H
17
18 #include "source/fuzz/transformation.h"
19
20 namespace spvtools {
21 namespace fuzz {
22
23 class TransformationReplaceOpSelectWithConditionalBranch
24 : public Transformation {
25 public:
26 explicit TransformationReplaceOpSelectWithConditionalBranch(
27 const protobufs::TransformationReplaceOpSelectWithConditionalBranch&
28 message);
29
30 TransformationReplaceOpSelectWithConditionalBranch(uint32_t select_id,
31 uint32_t true_block_id,
32 uint32_t false_block_id);
33
34 // - |message_.select_id| is the result id of an OpSelect instruction.
35 // - The condition of the OpSelect must be a scalar boolean.
36 // - The OpSelect instruction is the first instruction in its block.
37 // - The block containing the instruction is not a merge block, and it has a
38 // single predecessor, which is not a header and whose last instruction is
39 // OpBranch.
40 // - Each of |message_.true_block_id| and |message_.false_block_id| is either
41 // 0 or a valid fresh id, and at most one of them is 0. They must be
42 // distinct.
43 bool IsApplicable(
44 opt::IRContext* ir_context,
45 const TransformationContext& transformation_context) const override;
46
47 // Replaces the OpSelect instruction with id |message_.select_id| with a
48 // conditional branch and an OpPhi instruction.
49 void Apply(opt::IRContext* ir_context,
50 TransformationContext* transformation_context) const override;
51
52 std::unordered_set<uint32_t> GetFreshIds() const override;
53
54 protobufs::Transformation ToMessage() const override;
55
56 private:
57 protobufs::TransformationReplaceOpSelectWithConditionalBranch message_;
58 };
59
60 } // namespace fuzz
61 } // namespace spvtools
62
63 #endif // SOURCE_FUZZ_TRANSFORMATION_REPLACE_OPSELECT_WITH_CONDITIONAL_BRANCH_H