Skip to content

Commit 0a29f25

Browse files
pkwasnie-inteligcbot
authored andcommitted
GEPLoopStrengthReduction pass - rerun register pressure
estimation for deleted values Rerun IGCLivenessAnalysis for all basic blocks where deleted value was tracked.
1 parent a68d603 commit 0a29f25

File tree

1 file changed

+28
-83
lines changed

1 file changed

+28
-83
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/GEPLoopStrengthReduction/GEPLoopStrengthReduction.cpp

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,10 @@ class RegisterPressureTracker
311311
bool fitsPressureThreshold(ReductionCandidateGroup &C);
312312
void updatePressure(ReductionCandidateGroup &C, SCEVExpander &E);
313313

314-
void trackDeletedInstruction(Value *V)
315-
{
316-
if (auto *I = dyn_cast<Instruction>(V))
317-
BBsToUpdate.insert(I->getParent());
318-
}
314+
void trackDeletedInstruction(Value *V);
319315

320316
private:
321317

322-
#if LLVM_VERSION_MAJOR < 14
323-
SmallVector<Instruction*, 32> getInsertedInstructions(ReductionCandidateGroup &C, SCEVExpander &E);
324-
#endif
325-
326318
unsigned MaxAllowedPressure;
327319
unsigned ExternalPressure;
328320

@@ -334,9 +326,6 @@ class RegisterPressureTracker
334326

335327
// Keep track what new instructions inserted by SCEV Expander were already added to estimation.
336328
SmallPtrSet<Instruction*, 32> VisitedNewInsts;
337-
338-
// If true, always updates all BBs.
339-
bool refreshAllBBs = true;
340329
};
341330

342331

@@ -1097,6 +1086,25 @@ RegisterPressureTracker::RegisterPressureTracker(Function &F, CodeGenContext &CG
10971086
}
10981087

10991088

1089+
void RegisterPressureTracker::trackDeletedInstruction(Value *V)
1090+
{
1091+
if (auto *I = dyn_cast<Instruction>(V))
1092+
BBsToUpdate.insert(I->getParent());
1093+
1094+
for (auto It = RPE.getInSet().begin(); It != RPE.getInSet().end(); ++It)
1095+
{
1096+
if (It->second.count(V))
1097+
BBsToUpdate.insert(It->first);
1098+
}
1099+
1100+
for (auto It = RPE.getOutSet().begin(); It != RPE.getOutSet().end(); ++It)
1101+
{
1102+
if (It->second.count(V))
1103+
BBsToUpdate.insert(It->first);
1104+
}
1105+
}
1106+
1107+
11001108
bool RegisterPressureTracker::fitsPressureThreshold(ReductionCandidateGroup &C)
11011109
{
11021110
uint SIMD = numLanes(RPE.bestGuessSIMDSize());
@@ -1119,13 +1127,13 @@ bool RegisterPressureTracker::fitsPressureThreshold(ReductionCandidateGroup &C)
11191127

11201128
void RegisterPressureTracker::updatePressure(ReductionCandidateGroup &C, SCEVExpander &E)
11211129
{
1122-
if (refreshAllBBs)
1123-
{
1124-
BBsToUpdate.clear();
1125-
Function *F = C.getLoop()->getLoopPreheader()->getParent();
1126-
RPE.rerunLivenessAnalysis(*F);
1127-
return;
1128-
}
1130+
1131+
#if LLVM_VERSION_MAJOR < 14
1132+
BBsToUpdate.clear();
1133+
Function *F = C.getLoop()->getLoopPreheader()->getParent();
1134+
RPE.rerunLivenessAnalysis(*F);
1135+
return;
1136+
#else
11291137

11301138
// Refresh all BBs in loop.
11311139
BBsToUpdate.insert(C.getLoop()->getBlocks().begin(), C.getLoop()->getBlocks().end());
@@ -1137,11 +1145,7 @@ void RegisterPressureTracker::updatePressure(ReductionCandidateGroup &C, SCEVExp
11371145
// Find outermost loop touched by SCEVExpander and refresh register estimation for it.
11381146

11391147
// Query SCEVExpander for new instructions.
1140-
#if LLVM_VERSION_MAJOR < 14
1141-
auto AllInsertedInstructions = getInsertedInstructions(C, E);
1142-
#else
11431148
auto AllInsertedInstructions = E.getAllInsertedInstructions();
1144-
#endif
11451149

11461150
// Start searching from inner loop.
11471151
Loop *TopLoop = C.getLoop();
@@ -1195,69 +1199,10 @@ void RegisterPressureTracker::updatePressure(ReductionCandidateGroup &C, SCEVExp
11951199
RPE.rerunLivenessAnalysis(*F, &BBsToUpdate);
11961200
BBsToUpdate.clear();
11971201
}
1202+
#endif // LLVM_VERSION_MAJOR
11981203
}
11991204

12001205

1201-
#if LLVM_VERSION_MAJOR < 14
1202-
SmallVector<Instruction*, 32> RegisterPressureTracker::getInsertedInstructions(ReductionCandidateGroup &C, SCEVExpander &E)
1203-
{
1204-
// Older LLVM versions doesn't have API for quering all new instructions added
1205-
// by SCEV Expander. Instead, we must manually iterate over all instructions and
1206-
// query Expander if it inserted the instruction in question.
1207-
1208-
SmallVector<Instruction*, 32> Result;
1209-
SmallPtrSet<BasicBlock*, 32> VisitedBB;
1210-
1211-
// To make it faster, only iteratate over this loop and outer loops BBs
1212-
// (don't iterate over all BBs in the function).
1213-
auto *L = C.getLoop();
1214-
do
1215-
{
1216-
for (auto BB = L->block_begin(); BB != L->block_end(); ++BB)
1217-
{
1218-
if (VisitedBB.count(*BB))
1219-
continue;
1220-
1221-
VisitedBB.insert(*BB);
1222-
1223-
// Skip subloops; expander shouldn't insert instructions there.
1224-
bool isSubloop = false;
1225-
for (auto SL = L->getSubLoops().begin(); SL != L->getSubLoops().end(); ++SL)
1226-
{
1227-
if ((*SL)->contains(*BB))
1228-
{
1229-
isSubloop = true;
1230-
break;
1231-
}
1232-
}
1233-
1234-
if (isSubloop)
1235-
continue;
1236-
1237-
for (auto I = (*BB)->begin(); I != (*BB)->end(); ++I)
1238-
{
1239-
if (E.isInsertedInstruction(&*I))
1240-
Result.push_back(&*I);
1241-
}
1242-
}
1243-
1244-
// Check preheader too.
1245-
if (L->getLoopPreheader())
1246-
{
1247-
for (auto I = L->getLoopPreheader()->begin(); I != L->getLoopPreheader()->end(); ++I)
1248-
{
1249-
if (E.isInsertedInstruction(&*I))
1250-
Result.push_back(&*I);
1251-
}
1252-
}
1253-
1254-
} while ((L = L->getParentLoop()));
1255-
1256-
return Result;
1257-
}
1258-
#endif
1259-
1260-
12611206
bool Reducer::reduce(SmallVectorImpl<ReductionCandidateGroup> &Candidates)
12621207
{
12631208
if (Candidates.empty())

0 commit comments

Comments
 (0)