| 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_ID_USE_DESCRIPTOR_H_ |
| 16 |
#define SOURCE_FUZZ_ID_USE_DESCRIPTOR_H_ |
| 17 |
|
| 18 |
#include "source/fuzz/protobufs/spirvfuzz_protobufs.h" |
| 19 |
#include "source/opt/ir_context.h" |
| 20 |
|
| 21 |
namespace spvtools { |
| 22 |
namespace fuzz { |
| 23 |
|
| 24 |
// Looks for an instruction in |context| that contains a use |
| 25 |
// identified by |id_use_descriptor|. |
| 26 |
// Returns |nullptr| if no such instruction can be found. |
| 27 |
opt::Instruction* FindInstructionContainingUse( |
| 28 |
const protobufs::IdUseDescriptor& id_use_descriptor, |
| 29 |
opt::IRContext* context); |
| 30 |
|
| 31 |
// Creates an IdUseDescriptor protobuf message from the given components. |
| 32 |
// See the protobuf definition for details of what these components mean. |
| 33 |
protobufs::IdUseDescriptor MakeIdUseDescriptor( |
| 34 |
uint32_t id_of_interest, |
| 35 |
const protobufs::InstructionDescriptor& enclosing_instruction, |
| 36 |
uint32_t in_operand_index); |
| 37 |
|
| 38 |
// Given an id use, represented by the instruction |inst| that uses the id, and |
| 39 |
// the input operand index |in_operand_index| associated with the usage, returns |
| 40 |
// an IdUseDescriptor that represents the use. |
| 41 |
protobufs::IdUseDescriptor MakeIdUseDescriptorFromUse( |
| 42 |
opt::IRContext* context, opt::Instruction* inst, uint32_t in_operand_index); |
| 43 |
|
| 44 |
} // namespace fuzz |
| 45 |
} // namespace spvtools |
| 46 |
|
| 47 |
#endif // SOURCE_FUZZ_ID_USE_DESCRIPTOR_H_ |