@@ -311,18 +311,10 @@ class RegisterPressureTracker
311
311
bool fitsPressureThreshold (ReductionCandidateGroup &C);
312
312
void updatePressure (ReductionCandidateGroup &C, SCEVExpander &E);
313
313
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);
319
315
320
316
private:
321
317
322
- #if LLVM_VERSION_MAJOR < 14
323
- SmallVector<Instruction*, 32 > getInsertedInstructions (ReductionCandidateGroup &C, SCEVExpander &E);
324
- #endif
325
-
326
318
unsigned MaxAllowedPressure;
327
319
unsigned ExternalPressure;
328
320
@@ -334,9 +326,6 @@ class RegisterPressureTracker
334
326
335
327
// Keep track what new instructions inserted by SCEV Expander were already added to estimation.
336
328
SmallPtrSet<Instruction*, 32 > VisitedNewInsts;
337
-
338
- // If true, always updates all BBs.
339
- bool refreshAllBBs = true ;
340
329
};
341
330
342
331
@@ -1097,6 +1086,25 @@ RegisterPressureTracker::RegisterPressureTracker(Function &F, CodeGenContext &CG
1097
1086
}
1098
1087
1099
1088
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
+
1100
1108
bool RegisterPressureTracker::fitsPressureThreshold (ReductionCandidateGroup &C)
1101
1109
{
1102
1110
uint SIMD = numLanes (RPE.bestGuessSIMDSize ());
@@ -1119,13 +1127,13 @@ bool RegisterPressureTracker::fitsPressureThreshold(ReductionCandidateGroup &C)
1119
1127
1120
1128
void RegisterPressureTracker::updatePressure (ReductionCandidateGroup &C, SCEVExpander &E)
1121
1129
{
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
1129
1137
1130
1138
// Refresh all BBs in loop.
1131
1139
BBsToUpdate.insert (C.getLoop ()->getBlocks ().begin (), C.getLoop ()->getBlocks ().end ());
@@ -1137,11 +1145,7 @@ void RegisterPressureTracker::updatePressure(ReductionCandidateGroup &C, SCEVExp
1137
1145
// Find outermost loop touched by SCEVExpander and refresh register estimation for it.
1138
1146
1139
1147
// Query SCEVExpander for new instructions.
1140
- #if LLVM_VERSION_MAJOR < 14
1141
- auto AllInsertedInstructions = getInsertedInstructions (C, E);
1142
- #else
1143
1148
auto AllInsertedInstructions = E.getAllInsertedInstructions ();
1144
- #endif
1145
1149
1146
1150
// Start searching from inner loop.
1147
1151
Loop *TopLoop = C.getLoop ();
@@ -1195,69 +1199,10 @@ void RegisterPressureTracker::updatePressure(ReductionCandidateGroup &C, SCEVExp
1195
1199
RPE.rerunLivenessAnalysis (*F, &BBsToUpdate);
1196
1200
BBsToUpdate.clear ();
1197
1201
}
1202
+ #endif // LLVM_VERSION_MAJOR
1198
1203
}
1199
1204
1200
1205
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
-
1261
1206
bool Reducer::reduce (SmallVectorImpl<ReductionCandidateGroup> &Candidates)
1262
1207
{
1263
1208
if (Candidates.empty ())
0 commit comments