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

Method ValidIndexToComposite

source/fuzz/transformation_access_chain.cpp:396–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394}
395
396bool TransformationAccessChain::ValidIndexToComposite(
397 opt::IRContext* ir_context, uint32_t index_id, uint32_t object_type_id) {
398 auto object_type_def = ir_context->get_def_use_mgr()->GetDef(object_type_id);
399 // The object being indexed must be a composite.
400 if (!spvOpcodeIsComposite(object_type_def->opcode())) {
401 return false;
402 }
403
404 // Get the defining instruction of the index.
405 auto index_instruction = ir_context->get_def_use_mgr()->GetDef(index_id);
406 if (!index_instruction) {
407 return false;
408 }
409
410 // The index type must be 32-bit integer.
411 auto index_type =
412 ir_context->get_def_use_mgr()->GetDef(index_instruction->type_id());
413 if (index_type->opcode() != spv::Op::OpTypeInt ||
414 index_type->GetSingleWordInOperand(0) != 32) {
415 return false;
416 }
417
418 // If the object being traversed is a struct, the id must correspond to an
419 // in-bound constant.
420 if (object_type_def->opcode() == spv::Op::OpTypeStruct) {
421 if (!spvOpcodeIsConstant(index_instruction->opcode())) {
422 return false;
423 }
424 }
425 return true;
426}
427
428std::unordered_set<uint32_t> TransformationAccessChain::GetFreshIds() const {
429 std::unordered_set<uint32_t> result = {message_.fresh_id()};

Callers

nothing calls this directly

Calls 7

spvOpcodeIsCompositeFunction · 0.85
spvOpcodeIsConstantFunction · 0.85
GetDefMethod · 0.45
get_def_use_mgrMethod · 0.45
opcodeMethod · 0.45
type_idMethod · 0.45

Tested by

no test coverage detected