2
0

transformation_add_constant_scalar.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef SOURCE_FUZZ_TRANSFORMATION_ADD_CONSTANT_SCALAR_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_ADD_CONSTANT_SCALAR_H_
  16. #include <vector>
  17. #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
  18. #include "source/fuzz/transformation.h"
  19. #include "source/fuzz/transformation_context.h"
  20. #include "source/opt/ir_context.h"
  21. namespace spvtools {
  22. namespace fuzz {
  23. class TransformationAddConstantScalar : public Transformation {
  24. public:
  25. explicit TransformationAddConstantScalar(
  26. protobufs::TransformationAddConstantScalar message);
  27. TransformationAddConstantScalar(uint32_t fresh_id, uint32_t type_id,
  28. const std::vector<uint32_t>& words,
  29. bool is_irrelevant);
  30. // - |message_.fresh_id| must not be used by the module
  31. // - |message_.type_id| must be the id of a floating-point or integer type
  32. // - The size of |message_.word| must be compatible with the width of this
  33. // type
  34. bool IsApplicable(
  35. opt::IRContext* ir_context,
  36. const TransformationContext& transformation_context) const override;
  37. // Adds a new OpConstant instruction with the given type and words.
  38. // Creates an IdIsIrrelevant fact about |fresh_id| if |is_irrelevant| is true.
  39. void Apply(opt::IRContext* ir_context,
  40. TransformationContext* transformation_context) const override;
  41. std::unordered_set<uint32_t> GetFreshIds() const override;
  42. protobufs::Transformation ToMessage() const override;
  43. private:
  44. protobufs::TransformationAddConstantScalar message_;
  45. };
  46. } // namespace fuzz
  47. } // namespace spvtools
  48. #endif // SOURCE_FUZZ_TRANSFORMATION_ADD_CONSTANT_SCALAR_H_