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