1 // Copyright (c) 2020 Vasyl Teliman
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef SOURCE_FUZZ_TRANSFORMATION_REPLACE_PARAMETER_WITH_GLOBAL_H_
16 #define SOURCE_FUZZ_TRANSFORMATION_REPLACE_PARAMETER_WITH_GLOBAL_H_
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"
26 class TransformationReplaceParameterWithGlobal
: public Transformation
{
28 explicit TransformationReplaceParameterWithGlobal(
29 protobufs::TransformationReplaceParameterWithGlobal message
);
31 TransformationReplaceParameterWithGlobal(uint32_t function_type_fresh_id
,
32 uint32_t parameter_id
,
33 uint32_t global_variable_fresh_id
);
35 // - |function_type_fresh_id| is a fresh id.
36 // - |parameter_id| is the result id of the parameter to replace.
37 // - |global_variable_fresh_id| is a fresh id.
38 // - |function_type_fresh_id| is not equal to |global_variable_fresh_id|.
39 // - the function that contains |parameter_id| may not be an entry-point
42 opt::IRContext
* ir_context
,
43 const TransformationContext
& transformation_context
) const override
;
45 // - Removes parameter with result id |parameter_id| from its function
46 // - Adds a global variable to store the value for the parameter
47 // - Add an OpStore instruction before each function call to
48 // store parameter's value into the variable
49 // - Adds OpLoad at the beginning of the function to load the
50 // value from the variable into the old parameter's id
51 void Apply(opt::IRContext
* ir_context
,
52 TransformationContext
* transformation_context
) const override
;
54 std::unordered_set
<uint32_t> GetFreshIds() const override
;
56 protobufs::Transformation
ToMessage() const override
;
58 // Returns true if the type of the parameter is supported by this
60 static bool IsParameterTypeSupported(opt::IRContext
* ir_context
,
61 uint32_t param_type_id
);
64 protobufs::TransformationReplaceParameterWithGlobal message_
;
68 } // namespace spvtools
70 #endif // SOURCE_FUZZ_TRANSFORMATION_REPLACE_PARAMETER_WITH_GLOBAL_H_