transformation_add_constant_composite.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_COMPOSITE_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_ADD_CONSTANT_COMPOSITE_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 TransformationAddConstantComposite : public Transformation {
  24. public:
  25. explicit TransformationAddConstantComposite(
  26. protobufs::TransformationAddConstantComposite message);
  27. TransformationAddConstantComposite(
  28. uint32_t fresh_id, uint32_t type_id,
  29. const std::vector<uint32_t>& constituent_ids, bool is_irrelevant);
  30. // - |message_.fresh_id| must be a fresh id
  31. // - |message_.type_id| must be the id of a composite type
  32. // - |message_.constituent_id| must refer to ids that match the constituent
  33. // types of this composite type
  34. // - If |message_.type_id| is a struct type, it must not have the Block or
  35. // BufferBlock decoration
  36. bool IsApplicable(
  37. opt::IRContext* ir_context,
  38. const TransformationContext& transformation_context) const override;
  39. // - Adds an OpConstantComposite instruction defining a constant of type
  40. // |message_.type_id|, using |message_.constituent_id| as constituents, with
  41. // result id |message_.fresh_id|.
  42. // - Creates an IdIsIrrelevant fact about |fresh_id| if |is_irrelevant| is
  43. // true.
  44. void Apply(opt::IRContext* ir_context,
  45. TransformationContext* transformation_context) const override;
  46. std::unordered_set<uint32_t> GetFreshIds() const override;
  47. protobufs::Transformation ToMessage() const override;
  48. private:
  49. protobufs::TransformationAddConstantComposite message_;
  50. };
  51. } // namespace fuzz
  52. } // namespace spvtools
  53. #endif // SOURCE_FUZZ_TRANSFORMATION_ADD_CONSTANT_COMPOSITE_H_