| 57 | } |
| 58 | |
| 59 | bool WrapOpKill::ReplaceWithFunctionCall(Instruction* inst) { |
| 60 | assert((inst->opcode() == spv::Op::OpKill || |
| 61 | inst->opcode() == spv::Op::OpTerminateInvocation) && |
| 62 | "|inst| must be an OpKill or OpTerminateInvocation instruction."); |
| 63 | InstructionBuilder ir_builder( |
| 64 | context(), inst, |
| 65 | IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); |
| 66 | uint32_t func_id = GetKillingFuncId(inst->opcode()); |
| 67 | if (func_id == 0) { |
| 68 | return false; |
| 69 | } |
| 70 | Instruction* call_inst = |
| 71 | ir_builder.AddFunctionCall(GetVoidTypeId(), func_id, {}); |
| 72 | if (call_inst == nullptr) { |
| 73 | return false; |
| 74 | } |
| 75 | call_inst->UpdateDebugInfoFrom(inst); |
| 76 | |
| 77 | Instruction* return_inst = nullptr; |
| 78 | uint32_t return_type_id = GetOwningFunctionsReturnType(inst); |
| 79 | if (return_type_id != GetVoidTypeId()) { |
| 80 | Instruction* undef = |
| 81 | ir_builder.AddNullaryOp(return_type_id, spv::Op::OpUndef); |
| 82 | if (undef == nullptr) { |
| 83 | return false; |
| 84 | } |
| 85 | return_inst = |
| 86 | ir_builder.AddUnaryOp(0, spv::Op::OpReturnValue, undef->result_id()); |
| 87 | } else { |
| 88 | return_inst = ir_builder.AddNullaryOp(0, spv::Op::OpReturn); |
| 89 | } |
| 90 | |
| 91 | if (return_inst == nullptr) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | context()->KillInst(inst); |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | uint32_t WrapOpKill::GetVoidTypeId() { |
| 100 | if (void_type_id_ != 0) { |
nothing calls this directly
no test coverage detected