transformation_add_local_variable.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_ADD_LOCAL_VARIABLE_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_ADD_LOCAL_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 TransformationAddLocalVariable : public Transformation {
  23. public:
  24. explicit TransformationAddLocalVariable(
  25. protobufs::TransformationAddLocalVariable message);
  26. TransformationAddLocalVariable(uint32_t fresh_id, uint32_t type_id,
  27. uint32_t function_id, uint32_t initializer_id,
  28. bool value_is_irrelevant);
  29. // - |message_.fresh_id| must not be used by the module
  30. // - |message_.type_id| must be the id of a pointer type with Function
  31. // storage class
  32. // - |message_.initializer_id| must be the id of a constant with the same
  33. // type as the pointer's pointee type
  34. // - |message_.function_id| must be the id of a function
  35. bool IsApplicable(
  36. opt::IRContext* ir_context,
  37. const TransformationContext& transformation_context) const override;
  38. // Adds an instruction to the start of |message_.function_id|, of the form:
  39. // |message_.fresh_id| = OpVariable |message_.type_id| Function
  40. // |message_.initializer_id|
  41. // If |message_.value_is_irrelevant| holds, adds a corresponding fact to the
  42. // fact manager in |transformation_context|.
  43. void Apply(opt::IRContext* ir_context,
  44. TransformationContext* transformation_context) const override;
  45. std::unordered_set<uint32_t> GetFreshIds() const override;
  46. protobufs::Transformation ToMessage() const override;
  47. private:
  48. protobufs::TransformationAddLocalVariable message_;
  49. };
  50. } // namespace fuzz
  51. } // namespace spvtools
  52. #endif // SOURCE_FUZZ_TRANSFORMATION_ADD_LOCAL_VARIABLE_H_