• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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       protobufs::TransformationReplaceOpSelectWithConditionalBranch message);
28 
29   TransformationReplaceOpSelectWithConditionalBranch(uint32_t select_id,
30                                                      uint32_t true_block_id,
31                                                      uint32_t false_block_id);
32 
33   // - |message_.select_id| is the result id of an OpSelect instruction.
34   // - The condition of the OpSelect must be a scalar boolean.
35   // - The OpSelect instruction is the first instruction in its block.
36   // - The block containing the instruction is not a merge block, and it has a
37   //   single predecessor, which is not a header and whose last instruction is
38   //   OpBranch.
39   // - Each of |message_.true_block_id| and |message_.false_block_id| is either
40   //   0 or a valid fresh id, and at most one of them is 0. They must be
41   //   distinct.
42   bool IsApplicable(
43       opt::IRContext* ir_context,
44       const TransformationContext& transformation_context) const override;
45 
46   // Replaces the OpSelect instruction with id |message_.select_id| with a
47   // conditional branch and an OpPhi instruction.
48   void Apply(opt::IRContext* ir_context,
49              TransformationContext* transformation_context) const override;
50 
51   std::unordered_set<uint32_t> GetFreshIds() const override;
52 
53   protobufs::Transformation ToMessage() const override;
54 
55  private:
56   protobufs::TransformationReplaceOpSelectWithConditionalBranch message_;
57 };
58 
59 }  // namespace fuzz
60 }  // namespace spvtools
61 
62 #endif  // SOURCE_FUZZ_TRANSFORMATION_REPLACE_OPSELECT_WITH_CONDITIONAL_BRANCH_H
63