• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 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_COPY_OBJECT_H_
16 #define SOURCE_FUZZ_TRANSFORMATION_COPY_OBJECT_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 TransformationCopyObject : public Transformation {
27  public:
28   explicit TransformationCopyObject(
29       const protobufs::TransformationCopyObject& message);
30 
31   TransformationCopyObject(
32       uint32_t object,
33       const protobufs::InstructionDescriptor& instruction_to_insert_before,
34       uint32_t fresh_id);
35 
36   // - |message_.fresh_id| must not be used by the module.
37   // - |message_.object| must be a result id that is a legitimate operand for
38   //   OpCopyObject.  In particular, it must be the id of an instruction that
39   //   has a result type
40   // - |message_.object| must not be the target of any decoration.
41   //   TODO(afd): consider copying decorations along with objects.
42   // - |message_.base_instruction_id| must be the result id of an instruction
43   //   'base' in some block 'blk'.
44   // - 'blk' must contain an instruction 'inst' located |message_.offset|
45   //   instructions after 'base' (if |message_.offset| = 0 then 'inst' =
46   //   'base').
47   // - It must be legal to insert an OpCopyObject instruction directly
48   //   before 'inst'.
49   // - |message_.object| must be available directly before 'inst'.
50   // - |message_.object| must not be a null pointer or undefined pointer (so as
51   //   to make it legal to load from copied pointers).
52   bool IsApplicable(
53       opt::IRContext* ir_context,
54       const TransformationContext& transformation_context) const override;
55 
56   // - A new instruction,
57   //     %|message_.fresh_id| = OpCopyObject %ty %|message_.object|
58   //   is added directly before the instruction at |message_.insert_after_id| +
59   //   |message_|.offset, where %ty is the type of |message_.object|.
60   // - The fact that |message_.fresh_id| and |message_.object| are synonyms
61   //   is added to the fact manager in |transformation_context|.
62   // - If |message_.object| is a pointer whose pointee value is known to be
63   //   irrelevant, the analogous fact is added to the fact manager in
64   //   |transformation_context| about |message_.fresh_id|.
65   void Apply(opt::IRContext* ir_context,
66              TransformationContext* transformation_context) const override;
67 
68   protobufs::Transformation ToMessage() const override;
69 
70  private:
71   protobufs::TransformationCopyObject message_;
72 };
73 
74 }  // namespace fuzz
75 }  // namespace spvtools
76 
77 #endif  // SOURCE_FUZZ_TRANSFORMATION_COPY_OBJECT_H_
78