|
21 | 21 | #include <memory> |
22 | 22 | #include <vector> |
23 | 23 |
|
| 24 | +#define ENABLE_NEW_RT_PATH 0 |
| 25 | + |
24 | 26 | namespace IR { |
25 | 27 |
|
26 | 28 | unsigned LoopUnrollPass::name_idx = 0; |
@@ -362,12 +364,21 @@ void LoopUnrollPass::analyze(const pLoop &loop, UnrollOption &option, Function & |
362 | 364 | } |
363 | 365 | auto stepMremV = std::make_shared<BinaryInst>("rtunroll.stepMrem." + std::to_string(name_idx), OP::MUL, stepV, remainderV); |
364 | 366 | prolog->addInst(stepMremV); |
| 367 | + // new_boundary = raw_boundary - step * remainder |
365 | 368 | auto new_boundaryV = std::make_shared<BinaryInst>("rtunroll.new_boundary." + std::to_string(name_idx), OP::SUB, raw_boundary_value, stepMremV); |
366 | 369 | prolog->addInst(new_boundaryV); |
367 | | - auto trip_count_less_than_unroll_factorV = std::make_shared<ICMPInst>("rtunroll.tcLTuf." + std::to_string(name_idx), |
368 | | - ICMPOP::slt, trip_countV, unroll_factorV); |
369 | | - trip_count_less_than_unroll_factorV->appendDbgData("trip_count_less_than_unroll_factor"); |
370 | | - prolog->addInst(trip_count_less_than_unroll_factorV); |
| 370 | + |
| 371 | + // tcLTuf and epilog (for dowhile) |
| 372 | +#if ENABLE_NEW_RT_PATH |
| 373 | + if (is_dowhile) { |
| 374 | +#endif |
| 375 | + auto trip_count_less_than_unroll_factorV = std::make_shared<ICMPInst>("rtunroll.tcLTuf." + std::to_string(name_idx), |
| 376 | + ICMPOP::slt, trip_countV, unroll_factorV); |
| 377 | + trip_count_less_than_unroll_factorV->appendDbgData("trip_count_less_than_unroll_factor"); |
| 378 | + prolog->addInst(trip_count_less_than_unroll_factorV); |
| 379 | +#if ENABLE_NEW_RT_PATH |
| 380 | + } |
| 381 | +#endif |
371 | 382 |
|
372 | 383 | // epilog (for dowhile) |
373 | 384 | if (is_dowhile) { |
@@ -986,17 +997,33 @@ bool LoopUnrollPass::unroll(const pLoop &loop, const UnrollOption &option, Funct |
986 | 997 | auto prolog = option.prologue; |
987 | 998 | auto epilog = option.epilogue; |
988 | 999 | Err::gassert(prolog != nullptr && epilog != nullptr, "LoopUnroll: Runtime unroll prolog or epilog is nullptr."); |
989 | | - |
990 | | - // Add branch inst to prolog |
991 | | - pIcmp prolog_icmp = prolog->getTerminator()->as<ICMPInst>(); |
| 1000 | + |
992 | 1001 | pB rem_header = BMap[header][count]; |
993 | | - pBr prolog_br = std::make_shared<BRInst>(prolog_icmp, rem_header, header); |
994 | | - prolog->addInst(prolog_br); |
| 1002 | + |
| 1003 | + // Add branch inst to prolog |
| 1004 | +#if ENABLE_NEW_RT_PATH |
| 1005 | + if (!is_dowhile) { |
| 1006 | + pBr prolog_br = std::make_shared<BRInst>(header); |
| 1007 | + prolog->addInst(prolog_br); |
| 1008 | + } else { |
| 1009 | +#endif |
| 1010 | + pIcmp prolog_icmp = prolog->getTerminator()->as<ICMPInst>(); |
| 1011 | + pBr prolog_br = std::make_shared<BRInst>(prolog_icmp, rem_header, header); |
| 1012 | + prolog->addInst(prolog_br); |
| 1013 | +#if ENABLE_NEW_RT_PATH |
| 1014 | + } |
| 1015 | +#endif |
995 | 1016 |
|
996 | 1017 | // Link prolog |
997 | 1018 | pre_header->getBRInst()->replaceAllOperands(header, prolog); |
998 | 1019 | for (auto &phi : header->phis()) { |
999 | | - IMap[phi][count]->as<PHIInst>()->addPhiOper(phi->getValueForBlock(pre_header), prolog); |
| 1020 | +#if ENABLE_NEW_RT_PATH |
| 1021 | + if (is_dowhile) { |
| 1022 | +#endif |
| 1023 | + IMap[phi][count]->as<PHIInst>()->addPhiOper(phi->getValueForBlock(pre_header), prolog); |
| 1024 | +#if ENABLE_NEW_RT_PATH |
| 1025 | + } |
| 1026 | +#endif |
1000 | 1027 | phi->replaceAllOperands(pre_header, prolog); |
1001 | 1028 | } |
1002 | 1029 |
|
|
0 commit comments