transformation_load.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2020 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_LOAD_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_LOAD_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 TransformationLoad : public Transformation {
  23. public:
  24. explicit TransformationLoad(protobufs::TransformationLoad message);
  25. TransformationLoad(
  26. uint32_t fresh_id, uint32_t pointer_id, bool is_atomic,
  27. uint32_t memory_scope, uint32_t memory_semantics,
  28. const protobufs::InstructionDescriptor& instruction_to_insert_before);
  29. // - |message_.fresh_id| must be fresh
  30. // - |message_.pointer_id| must be the id of a pointer
  31. // - |message_.is_atomic| must be true if want to work with OpAtomicLoad
  32. // - If |is_atomic| is true then |message_memory_scope_id| must be the id of
  33. // an OpConstant 32 bit integer instruction with the value
  34. // spv::Scope::Invocation.
  35. // - If |is_atomic| is true then |message_.memory_semantics_id| must be the id
  36. // of an OpConstant 32 bit integer instruction with the values
  37. // SpvMemorySemanticsWorkgroupMemoryMask or
  38. // SpvMemorySemanticsUniformMemoryMask.
  39. // - The pointer must not be OpConstantNull or OpUndef
  40. // - |message_.instruction_to_insert_before| must identify an instruction
  41. // before which it is valid to insert an OpLoad, and where
  42. // |message_.pointer_id| is available (according to dominance rules)
  43. bool IsApplicable(
  44. opt::IRContext* ir_context,
  45. const TransformationContext& transformation_context) const override;
  46. // Adds an instruction of the form:
  47. // |message_.fresh_id| = OpLoad %type |message_.pointer_id|
  48. // before the instruction identified by
  49. // |message_.instruction_to_insert_before|, where %type is the pointer's
  50. // pointee type.
  51. void Apply(opt::IRContext* ir_context,
  52. TransformationContext* transformation_context) const override;
  53. std::unordered_set<uint32_t> GetFreshIds() const override;
  54. protobufs::Transformation ToMessage() const override;
  55. private:
  56. protobufs::TransformationLoad message_;
  57. };
  58. } // namespace fuzz
  59. } // namespace spvtools
  60. #endif // SOURCE_FUZZ_TRANSFORMATION_LOAD_H_