• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2020 André Perez Maselco
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_PUSH_ID_THROUGH_VARIABLE_H_
16 #define SOURCE_FUZZ_TRANSFORMATION_PUSH_ID_THROUGH_VARIABLE_H_
17 
18 #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
19 #include "source/fuzz/transformation.h"
20 #include "source/fuzz/transformation_context.h"
21 #include "source/opt/ir_context.h"
22 
23 namespace spvtools {
24 namespace fuzz {
25 
26 class TransformationPushIdThroughVariable : public Transformation {
27  public:
28   explicit TransformationPushIdThroughVariable(
29       protobufs::TransformationPushIdThroughVariable message);
30 
31   TransformationPushIdThroughVariable(
32       uint32_t value_id, uint32_t value_synonym_fresh_id,
33       uint32_t variable_fresh_id, uint32_t variable_storage_class,
34       uint32_t initializer_id,
35       const protobufs::InstructionDescriptor& instruction_descriptor);
36 
37   // - |message_.value_id| must be an instruction result id that has the same
38   //   type as the pointee type of |message_.pointer_id|
39   // - |message_.value_synonym_id| must be fresh
40   // - |message_.variable_id| must be fresh
41   // - |message_.variable_storage_class| must be either StorageClassPrivate or
42   //   StorageClassFunction
43   // - |message_.initializer_id| must be a result id of some constant in the
44   //   module. Its type must be equal to the pointee type of the variable that
45   //   will be created.
46   // - |message_.instruction_descriptor| must identify an instruction
47   //   which it is valid to insert the OpStore and OpLoad instructions before it
48   //   and must be belongs to a reachable block.
49   bool IsApplicable(
50       opt::IRContext* ir_context,
51       const TransformationContext& transformation_context) const override;
52 
53   // Stores |value_id| to |variable_id|, loads |variable_id| to
54   // |value_synonym_id|. Adds the fact that |value_synonym_id| and |value_id|
55   // are synonymous if |value_id| and |value_synonym_id| are not irrelevant.
56   void Apply(opt::IRContext* ir_context,
57              TransformationContext* transformation_context) const override;
58 
59   std::unordered_set<uint32_t> GetFreshIds() const override;
60 
61   protobufs::Transformation ToMessage() const override;
62 
63  private:
64   protobufs::TransformationPushIdThroughVariable message_;
65 };
66 
67 }  // namespace fuzz
68 }  // namespace spvtools
69 
70 #endif  // SOURCE_FUZZ_TRANSFORMATION_PUSH_ID_THROUGH_VARIABLE_H_
71