transformation_push_id_through_variable.h 2.8 KB

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