MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateGraphInput

Function ValidateGraphInput

source/val/validate_graph.cpp:216–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216spv_result_t ValidateGraphInput(ValidationState_t& _, const Instruction* inst) {
217 // Check type of InputIndex
218 auto input_index_inst = _.FindDef(inst->GetOperandAs<uint32_t>(2));
219 if (!input_index_inst ||
220 !_.IsIntScalarType(input_index_inst->type_id(), 32)) {
221 return _.diag(SPV_ERROR_INVALID_DATA, inst)
222 << spvOpcodeString(inst->opcode())
223 << " InputIndex must be a 32-bit integer.";
224 }
225
226 bool has_element_index = inst->operands().size() > 3;
227
228 // Check type of ElementIndex
229 if (has_element_index) {
230 auto element_index_inst = _.FindDef(inst->GetOperandAs<uint32_t>(3));
231 if (!element_index_inst ||
232 !_.IsIntScalarType(element_index_inst->type_id(), 32)) {
233 return _.diag(SPV_ERROR_INVALID_DATA, inst)
234 << spvOpcodeString(inst->opcode())
235 << " ElementIndex must be a 32-bit integer.";
236 }
237 }
238
239 // Find graph definition
240 size_t inst_num = inst->LineNum() - 1;
241 auto graph_inst = &_.ordered_instructions()[inst_num];
242 while (--inst_num) {
243 graph_inst = &_.ordered_instructions()[inst_num];
244 if (graph_inst->opcode() == spv::Op::OpGraphARM) {
245 break;
246 }
247 }
248
249 // Can the InputIndex be evaluated?
250 // If not, there's nothing more we can validate here.
251 uint64_t input_index;
252 if (!_.EvalConstantValUint64(inst->GetOperandAs<uint32_t>(2), &input_index)) {
253 return SPV_SUCCESS;
254 }
255
256 auto const graph_type_inst = _.FindDef(graph_inst->type_id());
257 size_t graph_type_num_inputs = graph_type_inst->GetOperandAs<uint32_t>(1);
258
259 // Check InputIndex is in range
260 if (input_index >= graph_type_num_inputs) {
261 std::string disassembly = _.Disassemble(*inst);
262 return _.diag(SPV_ERROR_INVALID_DATA, nullptr)
263 << "Type " << _.getIdName(graph_type_inst->id()) << " for graph "
264 << _.getIdName(graph_inst->id()) << " has " << graph_type_num_inputs
265 << " inputs but found an OpGraphInputARM instruction with an "
266 "InputIndex that is "
267 << input_index << ": " << disassembly;
268 }
269
270 uint32_t graph_type_input_type =
271 GraphTypeInstGetInputAtIndex(graph_type_inst, input_index);
272
273 if (has_element_index) {

Callers 1

GraphPassFunction · 0.85

Calls 15

spvOpcodeStringFunction · 0.85
IsTensorArrayFunction · 0.85
FindDefMethod · 0.80
IsIntScalarTypeMethod · 0.80
diagMethod · 0.80
operandsMethod · 0.80
LineNumMethod · 0.80
EvalConstantValUint64Method · 0.80
getIdNameMethod · 0.80
IsArrayTypeMethod · 0.80
type_idMethod · 0.45

Tested by

no test coverage detected