| 100 | } |
| 101 | |
| 102 | Instruction* MemPass::GetPtr(uint32_t ptrId, uint32_t* varId) { |
| 103 | *varId = ptrId; |
| 104 | Instruction* ptrInst = get_def_use_mgr()->GetDef(*varId); |
| 105 | Instruction* varInst; |
| 106 | |
| 107 | switch (ptrInst->opcode()) { |
| 108 | case spv::Op::OpVariable: |
| 109 | case spv::Op::OpUntypedVariableKHR: |
| 110 | case spv::Op::OpFunctionParameter: |
| 111 | varInst = ptrInst; |
| 112 | break; |
| 113 | case spv::Op::OpAccessChain: |
| 114 | case spv::Op::OpInBoundsAccessChain: |
| 115 | case spv::Op::OpUntypedAccessChainKHR: |
| 116 | case spv::Op::OpPtrAccessChain: |
| 117 | case spv::Op::OpInBoundsPtrAccessChain: |
| 118 | case spv::Op::OpImageTexelPointer: |
| 119 | case spv::Op::OpCopyObject: |
| 120 | varInst = ptrInst->GetBaseAddress(); |
| 121 | break; |
| 122 | default: |
| 123 | *varId = 0; |
| 124 | return ptrInst; |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | if (varInst->opcode() == spv::Op::OpVariable || |
| 129 | varInst->opcode() == spv::Op::OpUntypedVariableKHR) { |
| 130 | *varId = varInst->result_id(); |
| 131 | } else { |
| 132 | *varId = 0; |
| 133 | } |
| 134 | |
| 135 | while (ptrInst->opcode() == spv::Op::OpCopyObject) { |
| 136 | uint32_t temp = ptrInst->GetSingleWordInOperand(0); |
| 137 | ptrInst = get_def_use_mgr()->GetDef(temp); |
| 138 | } |
| 139 | |
| 140 | return ptrInst; |
| 141 | } |
| 142 | |
| 143 | Instruction* MemPass::GetPtr(Instruction* ip, uint32_t* varId) { |
| 144 | assert(ip->opcode() == spv::Op::OpStore || ip->opcode() == spv::Op::OpLoad || |
no test coverage detected