| 149 | namespace { |
| 150 | |
| 151 | LogicalResult Verify(ParallelExecuteOp op) { |
| 152 | const auto& regions = op.getOperation()->getRegions(); |
| 153 | if (regions.size() < 2) { |
| 154 | return op.emitOpError() << "must have at least two regions."; |
| 155 | } |
| 156 | |
| 157 | int output_index = 0; |
| 158 | for (auto& region_and_index : llvm::enumerate(regions)) { |
| 159 | auto& region = region_and_index.value(); |
| 160 | auto region_index = region_and_index.index(); |
| 161 | |
| 162 | // Each region must include a single block of ops and must not be empty. |
| 163 | if (region.empty()) { |
| 164 | return op.emitOpError() |
| 165 | << "regions must not be empty. " |
| 166 | << "Found an empty region (" << region_index << ")."; |
| 167 | } |
| 168 | |
| 169 | if (!has_single_element(region)) { |
| 170 | return op.emitOpError() |
| 171 | << "regions must be composed of a single block of operations." |
| 172 | << "Expected region (" << region_index << ") with 1 block."; |
| 173 | } |
| 174 | |
| 175 | auto* region_terminator = region.front().getTerminator(); |
| 176 | // Check that output types of regions match return operand types. |
| 177 | for (auto result_type : region_terminator->getOperandTypes()) { |
| 178 | if (result_type != |
| 179 | op.getOperation()->getResult(output_index++).getType()) { |
| 180 | return op.emitOpError() << "output types must be a concatenated " |
| 181 | << "list of output types for each regions."; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Check that total number of outputs from regions match the output types of |
| 187 | // the parallel_execute op. |
| 188 | const int num_output_types = op.getOperation()->getNumResults(); |
| 189 | if (num_output_types != output_index) { |
| 190 | return op.emitOpError() |
| 191 | << "number of output types (" << num_output_types << ") " |
| 192 | << "must match the total number of outputs from all " |
| 193 | << "regions (" << output_index << ")."; |
| 194 | } |
| 195 | |
| 196 | return success(); |
| 197 | } |
| 198 | |
| 199 | } // namespace |
| 200 | |