| 777 | } |
| 778 | |
| 779 | void UpgradeMemoryModel::UpgradeExtInst(Instruction* ext_inst) { |
| 780 | const bool is_modf = ext_inst->GetSingleWordInOperand(1u) == GLSLstd450Modf; |
| 781 | auto ptr_id = ext_inst->GetSingleWordInOperand(3u); |
| 782 | auto ptr_type_id = get_def_use_mgr()->GetDef(ptr_id)->type_id(); |
| 783 | auto pointee_type_id = |
| 784 | get_def_use_mgr()->GetDef(ptr_type_id)->GetSingleWordInOperand(1u); |
| 785 | auto element_type_id = ext_inst->type_id(); |
| 786 | std::vector<const analysis::Type*> element_types(2); |
| 787 | element_types[0] = context()->get_type_mgr()->GetType(element_type_id); |
| 788 | element_types[1] = context()->get_type_mgr()->GetType(pointee_type_id); |
| 789 | analysis::Struct struct_type(element_types); |
| 790 | uint32_t struct_id = |
| 791 | context()->get_type_mgr()->GetTypeInstruction(&struct_type); |
| 792 | // Change the operation |
| 793 | GLSLstd450 new_op = is_modf ? GLSLstd450ModfStruct : GLSLstd450FrexpStruct; |
| 794 | ext_inst->SetOperand(3u, {static_cast<uint32_t>(new_op)}); |
| 795 | // Remove the pointer argument |
| 796 | ext_inst->RemoveOperand(5u); |
| 797 | // Set the type id to the new struct. |
| 798 | ext_inst->SetResultType(struct_id); |
| 799 | |
| 800 | // The result is now a struct of the original result. The zero'th element is |
| 801 | // old result and should replace the old result. The one'th element needs to |
| 802 | // be stored via a new instruction. |
| 803 | auto where = ext_inst->NextNode(); |
| 804 | InstructionBuilder builder( |
| 805 | context(), where, |
| 806 | IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); |
| 807 | // TODO(1841): Handle id overflow. |
| 808 | auto extract_0 = |
| 809 | builder.AddCompositeExtract(element_type_id, ext_inst->result_id(), {0}); |
| 810 | context()->ReplaceAllUsesWith(ext_inst->result_id(), extract_0->result_id()); |
| 811 | // The extract's input was just changed to itself, so fix that. |
| 812 | extract_0->SetInOperand(0u, {ext_inst->result_id()}); |
| 813 | // TODO(1841): Handle id overflow. |
| 814 | auto extract_1 = |
| 815 | builder.AddCompositeExtract(pointee_type_id, ext_inst->result_id(), {1}); |
| 816 | builder.AddStore(ptr_id, extract_1->result_id()); |
| 817 | } |
| 818 | |
| 819 | uint32_t UpgradeMemoryModel::MemoryAccessNumWords(uint32_t mask) { |
| 820 | uint32_t result = 1; |
nothing calls this directly
no test coverage detected