Rewrites the use of |def_insn_| by the instruction |user| at the index |operand_index| in terms of phi instruction. This recursively builds new phi instructions from |user| to the loop exit blocks' phis. The use of |def_insn_| in |user| is replaced by the relevant phi instruction at the end of the operation. It is assumed that |user| does not dominates any of the loop exit basic block. This operat
| 69 | // records what needs to be updated. The actual update is performed by |
| 70 | // UpdateManagers. |
| 71 | bool RewriteUse(BasicBlock* bb, Instruction* user, uint32_t operand_index) { |
| 72 | assert( |
| 73 | (user->opcode() != spv::Op::OpPhi || bb != GetParent(user)) && |
| 74 | "The root basic block must be the incoming edge if |user| is a phi " |
| 75 | "instruction"); |
| 76 | assert((user->opcode() == spv::Op::OpPhi || bb == GetParent(user)) && |
| 77 | "The root basic block must be the instruction parent if |user| is " |
| 78 | "not " |
| 79 | "phi instruction"); |
| 80 | |
| 81 | Instruction* new_def = GetOrBuildIncoming(bb->id()); |
| 82 | if (!new_def) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | user->SetOperand(operand_index, {new_def->result_id()}); |
| 87 | rewritten_.insert(user); |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | // In-place update of some managers (avoid full invalidation). |
| 92 | inline void UpdateManagers() { |
no test coverage detected