| 394 | } |
| 395 | |
| 396 | bool 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 | |
| 428 | std::unordered_set<uint32_t> TransformationAccessChain::GetFreshIds() const { |
| 429 | std::unordered_set<uint32_t> result = {message_.fresh_id()}; |
nothing calls this directly
no test coverage detected