| 1365 | } |
| 1366 | |
| 1367 | void apply(module& m, const match::matcher_result& r) const |
| 1368 | { |
| 1369 | auto ins = r.result; |
| 1370 | auto splits = get_splits(ins); |
| 1371 | if(splits.empty()) |
| 1372 | return; |
| 1373 | auto split_groups = get_split_groups(m, ins, splits); |
| 1374 | if(split_groups_are_dependent(m, ins, split_groups)) |
| 1375 | { |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | for(const auto& group : split_groups) |
| 1380 | { |
| 1381 | auto start = group.front(); |
| 1382 | auto split_front = splits.front(); |
| 1383 | auto op = start->get_operator(); |
| 1384 | if(not is_fusable(start, split_front)) |
| 1385 | { |
| 1386 | continue; |
| 1387 | } |
| 1388 | |
| 1389 | // Make sure there are no duplicates |
| 1390 | assert(std::none_of( |
| 1391 | std::next(group.begin()), group.end(), [&](auto i) { return i == start; })); |
| 1392 | |
| 1393 | auto split_idx = 0; |
| 1394 | instruction_ref c = m.end(); |
| 1395 | if(start->inputs().size() == 1) |
| 1396 | { |
| 1397 | c = m.insert_instruction(std::next(ins), op, {ins}, start->module_inputs()); |
| 1398 | } |
| 1399 | else if(start->inputs().size() == 2) |
| 1400 | { |
| 1401 | assert(not std::none_of(start->inputs().begin(), start->inputs().end(), [](auto i) { |
| 1402 | return i->name() == "slice"; |
| 1403 | }) and "one argument must be a split"); |
| 1404 | |
| 1405 | auto slice_op = any_cast<op::slice>(splits.front()->get_operator()); |
| 1406 | assert(not slice_op.axes.empty()); |
| 1407 | if(slice_op.axes.size() > 1) |
| 1408 | return; |
| 1409 | auto concat_axis = slice_op.axes.front(); |
| 1410 | if(not concat_const_foldable(group.begin(), group.end(), concat_axis)) |
| 1411 | return; |
| 1412 | |
| 1413 | split_idx = get_binary_op_split_idx(group, splits); |
| 1414 | assert(split_idx < 2); |
| 1415 | size_t data_idx; |
| 1416 | if(split_idx < 0 and op.attributes().contains("commutative")) |
| 1417 | { |
| 1418 | split_idx = 0; |
| 1419 | data_idx = 1; |
| 1420 | align_commutative_op_args(m, group, splits, split_idx); |
| 1421 | } |
| 1422 | else if(split_idx < 0) |
| 1423 | { |
| 1424 | return; |
nothing calls this directly
no test coverage detected