| 24 | const uint32_t kFalseBranchOperandIndex = 2; |
| 25 | |
| 26 | uint32_t FindOrCreateGlobalVariable(opt::IRContext* context, |
| 27 | uint32_t pointer_type_id) { |
| 28 | for (auto& inst : context->module()->types_values()) { |
| 29 | if (inst.opcode() != spv::Op::OpVariable) { |
| 30 | continue; |
| 31 | } |
| 32 | if (inst.type_id() == pointer_type_id) { |
| 33 | return inst.result_id(); |
| 34 | } |
| 35 | } |
| 36 | const uint32_t variable_id = context->TakeNextId(); |
| 37 | auto variable_inst = MakeUnique<opt::Instruction>( |
| 38 | context, spv::Op::OpVariable, pointer_type_id, variable_id, |
| 39 | opt::Instruction::OperandList( |
| 40 | {{SPV_OPERAND_TYPE_STORAGE_CLASS, |
| 41 | {static_cast<uint32_t>(context->get_type_mgr() |
| 42 | ->GetType(pointer_type_id) |
| 43 | ->AsPointer() |
| 44 | ->storage_class())}}})); |
| 45 | context->module()->AddGlobalValue(std::move(variable_inst)); |
| 46 | return variable_id; |
| 47 | } |
| 48 | |
| 49 | uint32_t FindOrCreateFunctionVariable(opt::IRContext* context, |
| 50 | opt::Function* function, |
no test coverage detected