instruction_descriptor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_INSTRUCTION_DESCRIPTOR_H_
  15. #define SOURCE_FUZZ_INSTRUCTION_DESCRIPTOR_H_
  16. #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
  17. #include "source/opt/basic_block.h"
  18. #include "source/opt/ir_context.h"
  19. namespace spvtools {
  20. namespace fuzz {
  21. // Looks for an instruction in |context| corresponding to |descriptor|.
  22. // Returns |nullptr| if no such instruction can be found.
  23. opt::Instruction* FindInstruction(
  24. const protobufs::InstructionDescriptor& instruction_descriptor,
  25. opt::IRContext* context);
  26. // Creates an InstructionDescriptor protobuf message from the given
  27. // components. See the protobuf definition for details of what these
  28. // components mean.
  29. protobufs::InstructionDescriptor MakeInstructionDescriptor(
  30. uint32_t base_instruction_result_id, spv::Op target_instruction_opcode,
  31. uint32_t num_opcodes_to_ignore);
  32. // Returns an instruction descriptor that describing the instruction at
  33. // |inst_it|, which must be inside |block|. The descriptor will be with
  34. // respect to the first instruction at or before |inst_it| that has a result
  35. // id.
  36. protobufs::InstructionDescriptor MakeInstructionDescriptor(
  37. const opt::BasicBlock& block,
  38. const opt::BasicBlock::const_iterator& inst_it);
  39. // Returns an InstructionDescriptor that describes the given instruction |inst|.
  40. protobufs::InstructionDescriptor MakeInstructionDescriptor(
  41. opt::IRContext* context, opt::Instruction* inst);
  42. } // namespace fuzz
  43. } // namespace spvtools
  44. #endif // SOURCE_FUZZ_INSTRUCTION_DESCRIPTOR_H_