@@ -2263,15 +2263,16 @@ void ModuloScheduleExpanderMVE::generatePipelinedLoop() {
2263
2263
2264
2264
SmallVector<MachineOperand, 4 > Cond;
2265
2265
LoopInfo->createRemainingIterationsGreaterCondition (
2266
- Schedule.getNumStages () + NumUnroll - 2 , *Check, Cond, ValueMapTy ());
2266
+ Schedule.getNumStages () + NumUnroll - 2 , *Check, Cond, InstrMapTy ());
2267
2267
TII->insertBranch (*Check, Prolog, NewPreheader, Cond, DebugLoc ());
2268
2268
2269
2269
// VRMaps map (prolog/kernel/epilog phase#, original register#) to new
2270
2270
// register#
2271
2271
SmallVector<ValueMapTy> PrologVRMap, KernelVRMap, EpilogVRMap;
2272
+ InstrMapTy LastStage0Insts;
2272
2273
generateProlog (PrologVRMap);
2273
- generateKernel (PrologVRMap, KernelVRMap);
2274
- generateEpilog (KernelVRMap, EpilogVRMap);
2274
+ generateKernel (PrologVRMap, KernelVRMap, LastStage0Insts );
2275
+ generateEpilog (KernelVRMap, EpilogVRMap, LastStage0Insts );
2275
2276
}
2276
2277
2277
2278
// / Replace MI's use operands according to the maps.
@@ -2522,18 +2523,21 @@ void ModuloScheduleExpanderMVE::generateProlog(
2522
2523
2523
2524
void ModuloScheduleExpanderMVE::generateKernel (
2524
2525
SmallVectorImpl<ValueMapTy> &PrologVRMap,
2525
- SmallVectorImpl<ValueMapTy> &KernelVRMap) {
2526
+ SmallVectorImpl<ValueMapTy> &KernelVRMap, InstrMapTy &LastStage0Insts ) {
2526
2527
KernelVRMap.clear ();
2527
2528
KernelVRMap.resize (NumUnroll);
2528
2529
SmallVector<ValueMapTy> PhiVRMap;
2529
2530
PhiVRMap.resize (NumUnroll);
2530
2531
DenseMap<MachineInstr *, std::pair<int , int >> NewMIMap;
2532
+ DenseMap<MachineInstr *, MachineInstr *> MIMapLastStage0;
2531
2533
for (int UnrollNum = 0 ; UnrollNum < NumUnroll; ++UnrollNum) {
2532
2534
for (MachineInstr *MI : Schedule.getInstructions ()) {
2533
2535
if (MI->isPHI ())
2534
2536
continue ;
2535
2537
int StageNum = Schedule.getStage (MI);
2536
2538
MachineInstr *NewMI = cloneInstr (MI);
2539
+ if (UnrollNum == NumUnroll - 1 )
2540
+ LastStage0Insts[MI] = NewMI;
2537
2541
updateInstrDef (NewMI, KernelVRMap[UnrollNum],
2538
2542
(UnrollNum == NumUnroll - 1 && StageNum == 0 ));
2539
2543
generatePhi (MI, UnrollNum, PrologVRMap, KernelVRMap, PhiVRMap);
@@ -2551,8 +2555,8 @@ void ModuloScheduleExpanderMVE::generateKernel(
2551
2555
2552
2556
// If remaining trip count is greater than NumUnroll-1, loop continues
2553
2557
SmallVector<MachineOperand, 4 > Cond;
2554
- LoopInfo->createRemainingIterationsGreaterCondition (
2555
- NumUnroll - 1 , *NewKernel, Cond, KernelVRMap[NumUnroll - 1 ] );
2558
+ LoopInfo->createRemainingIterationsGreaterCondition (NumUnroll - 1 , *NewKernel,
2559
+ Cond, LastStage0Insts );
2556
2560
TII->insertBranch (*NewKernel, NewKernel, Epilog, Cond, DebugLoc ());
2557
2561
2558
2562
LLVM_DEBUG ({
@@ -2563,7 +2567,7 @@ void ModuloScheduleExpanderMVE::generateKernel(
2563
2567
2564
2568
void ModuloScheduleExpanderMVE::generateEpilog (
2565
2569
SmallVectorImpl<ValueMapTy> &KernelVRMap,
2566
- SmallVectorImpl<ValueMapTy> &EpilogVRMap) {
2570
+ SmallVectorImpl<ValueMapTy> &EpilogVRMap, InstrMapTy &LastStage0Insts ) {
2567
2571
EpilogVRMap.clear ();
2568
2572
EpilogVRMap.resize (Schedule.getNumStages () - 1 );
2569
2573
DenseMap<MachineInstr *, std::pair<int , int >> NewMIMap;
@@ -2594,8 +2598,8 @@ void ModuloScheduleExpanderMVE::generateEpilog(
2594
2598
// are indicated by shouldIgnoreForPipelining() and are assumed to be placed
2595
2599
// in stage 0. Thus, the map is for the last one in the kernel.
2596
2600
SmallVector<MachineOperand, 4 > Cond;
2597
- LoopInfo->createRemainingIterationsGreaterCondition (
2598
- 0 , *Epilog, Cond, KernelVRMap[NumUnroll - 1 ] );
2601
+ LoopInfo->createRemainingIterationsGreaterCondition (0 , *Epilog, Cond,
2602
+ LastStage0Insts );
2599
2603
TII->insertBranch (*Epilog, NewPreheader, NewExit, Cond, DebugLoc ());
2600
2604
2601
2605
LLVM_DEBUG ({
@@ -2670,7 +2674,8 @@ void ModuloScheduleExpanderMVE::expand() {
2670
2674
// / Check if ModuloScheduleExpanderMVE can be applied to L
2671
2675
bool ModuloScheduleExpanderMVE::canApply (MachineLoop &L) {
2672
2676
if (!L.getExitBlock ()) {
2673
- LLVM_DEBUG (dbgs () << " Can not apply MVE expander: No single exit block.\n " ;);
2677
+ LLVM_DEBUG (
2678
+ dbgs () << " Can not apply MVE expander: No single exit block.\n " ;);
2674
2679
return false ;
2675
2680
}
2676
2681
@@ -2687,8 +2692,9 @@ bool ModuloScheduleExpanderMVE::canApply(MachineLoop &L) {
2687
2692
if (MO.isReg ())
2688
2693
for (MachineInstr &Ref : MRI.use_instructions (MO.getReg ()))
2689
2694
if (Ref.getParent () != BB || Ref.isPHI ()) {
2690
- LLVM_DEBUG (dbgs () << " Can not apply MVE expander: A phi result is "
2691
- " referenced outside of the loop or by phi.\n " ;);
2695
+ LLVM_DEBUG (dbgs ()
2696
+ << " Can not apply MVE expander: A phi result is "
2697
+ " referenced outside of the loop or by phi.\n " ;);
2692
2698
return false ;
2693
2699
}
2694
2700
0 commit comments