Returns true if the loop can be unswitched. Can be unswitch if: - The loop has no instructions that prevents it (such as barrier); - The loop has one conditional branch or switch that do not depends on the loop; - The loop invariant condition is uniform;
| 58 | // loop; |
| 59 | // - The loop invariant condition is uniform; |
| 60 | bool CanUnswitchLoop() { |
| 61 | if (switch_block_) return true; |
| 62 | if (loop_->IsSafeToClone()) return false; |
| 63 | |
| 64 | CFG& cfg = *context_->cfg(); |
| 65 | |
| 66 | for (uint32_t bb_id : loop_->GetBlocks()) { |
| 67 | BasicBlock* bb = cfg.block(bb_id); |
| 68 | if (loop_->GetLatchBlock() == bb) { |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | if (bb->terminator()->IsBranch() && |
| 73 | bb->terminator()->opcode() != spv::Op::OpBranch) { |
| 74 | if (IsConditionNonConstantLoopInvariant(bb->terminator())) { |
| 75 | switch_block_ = bb; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return switch_block_; |
| 82 | } |
| 83 | |
| 84 | // Return the iterator to the basic block |bb|. |
| 85 | Function::iterator FindBasicBlockPosition(BasicBlock* bb_to_find) { |
no test coverage detected