1
1
/* ========================== begin_copyright_notice ============================
2
2
3
- Copyright (C) 2017-2021 Intel Corporation
3
+ Copyright (C) 2017-2024 Intel Corporation
4
4
5
5
SPDX-License-Identifier: MIT
6
6
@@ -1160,70 +1160,96 @@ namespace IGC
1160
1160
}
1161
1161
}
1162
1162
1163
- class DisableLICMForSpecificLoops : public llvm ::LoopPass
1163
+ // This pass disables LICM optimization by adding llvm.licm.disable
1164
+ // - when Loop depends on SIMD Lane Id and operates on local memory or
1165
+ // - when the loops are part of a large function and the number of loops
1166
+ // is sizable where a potential stack overflow from memory SSA updater
1167
+ // could occur.
1168
+
1169
+ class SpecialCasesDisableLICM : public llvm ::FunctionPass
1164
1170
{
1165
1171
public:
1166
1172
static char ID;
1167
1173
1168
- DisableLICMForSpecificLoops ();
1174
+ SpecialCasesDisableLICM ();
1169
1175
1170
1176
void getAnalysisUsage (llvm::AnalysisUsage& AU) const
1171
1177
{
1172
1178
AU.addPreservedID (LCSSAID);
1179
+ AU.addRequired <llvm::LoopInfoWrapperPass>();
1173
1180
}
1174
1181
1175
- bool runOnLoop (Loop* L, LPPassManager& LPM );
1182
+ bool runOnFunction (Function& F );
1176
1183
bool LoopHasLoadFromLocalAddressSpace (const Loop& L);
1177
1184
bool LoopDependsOnSIMDLaneId (const Loop& L);
1178
1185
bool AddLICMDisableMedatadaToSpecificLoop (Loop& L);
1179
1186
1180
1187
llvm::StringRef getPassName () const
1181
1188
{
1182
- return " IGC disable LICM for specific loops " ;
1189
+ return " IGC special cases disable LICM " ;
1183
1190
}
1184
1191
};
1192
+
1185
1193
#undef PASS_FLAG
1186
1194
#undef PASS_DESC
1187
1195
#undef PASS_CFG_ONLY
1188
1196
#undef PASS_ANALYSIS
1189
- #define PASS_FLAG " igc-disable-licm-for-specific-loops "
1190
- #define PASS_DESC " IGC disable LICM for specific loops "
1197
+ #define PASS_FLAG " igc-special-cases-disable-licm "
1198
+ #define PASS_DESC " IGC special cases disable LICM "
1191
1199
#define PASS_CFG_ONLY false
1192
1200
#define PASS_ANALYSIS false
1193
- IGC_INITIALIZE_PASS_BEGIN (DisableLICMForSpecificLoops , PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS)
1194
- IGC_INITIALIZE_PASS_END(DisableLICMForSpecificLoops, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS )
1195
-
1201
+ IGC_INITIALIZE_PASS_BEGIN (SpecialCasesDisableLICM , PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS)
1202
+ IGC_INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass )
1203
+ IGC_INITIALIZE_PASS_END(SpecialCasesDisableLICM, PASS_FLAG, PASS_DESC, PASS_CFG_ONLY, PASS_ANALYSIS)
1196
1204
1197
- char DisableLICMForSpecificLoops ::ID = 0;
1205
+ char SpecialCasesDisableLICM ::ID = 0;
1198
1206
1199
- DisableLICMForSpecificLoops::DisableLICMForSpecificLoops () : LoopPass (ID)
1207
+ SpecialCasesDisableLICM::SpecialCasesDisableLICM () : FunctionPass (ID)
1200
1208
{
1201
- initializeDisableLICMForSpecificLoopsPass (*PassRegistry::getPassRegistry ());
1209
+ initializeSpecialCasesDisableLICMPass (*PassRegistry::getPassRegistry ());
1202
1210
}
1203
1211
1204
- bool DisableLICMForSpecificLoops::runOnLoop (Loop* L, LPPassManager& LPM )
1212
+ bool SpecialCasesDisableLICM::runOnFunction (llvm::Function& F )
1205
1213
{
1206
1214
bool Changed = false ;
1215
+ LoopInfo* LI = nullptr ;
1207
1216
1208
- if (!L->getHeader () || !L->getLoopLatch ())
1209
- return false ;
1217
+ auto getLoopInfo = [&]() -> LoopInfo* {
1218
+ if (nullptr == LI)
1219
+ return &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
1220
+ return LI;
1221
+ };
1210
1222
1211
- // Disable LICM optimization by adding llvm.licm.disable
1212
- // - when Loop depends on SIMD Lane Id and operates on local memory
1213
- // - when shader contains a large number of BBs that may trigger stack overflow
1214
- // from memory SSA updater
1223
+ if (constexpr size_t HIGH_BB_THRESHOLD_FOR_LICM = 2500 ;
1224
+ F.size () > HIGH_BB_THRESHOLD_FOR_LICM)
1225
+ {
1226
+ LI = getLoopInfo ();
1227
+
1228
+ if (constexpr size_t HIGH_LOOP_THRESHOLD_FOR_LICM = 450 ;
1229
+ llvm::size (*LI) > HIGH_LOOP_THRESHOLD_FOR_LICM)
1230
+ {
1231
+ for (auto * L : *LI)
1232
+ AddLICMDisableMedatadaToSpecificLoop (*L);
1215
1233
1216
- if (constexpr size_t BB_LIMIT_FOR_LICM = 2500 ;
1217
- L->getHeader ()->getParent ()->size () > BB_LIMIT_FOR_LICM ||
1218
- (LoopHasLoadFromLocalAddressSpace (*L) && LoopDependsOnSIMDLaneId (*L)))
1234
+ Changed = true ;
1235
+ }
1236
+ }
1237
+
1238
+ if (!Changed)
1219
1239
{
1220
- Changed |= AddLICMDisableMedatadaToSpecificLoop (*L);
1240
+ LI = getLoopInfo ();
1241
+
1242
+ for (auto * L : *LI)
1243
+ {
1244
+ if (LoopHasLoadFromLocalAddressSpace (*L) && LoopDependsOnSIMDLaneId (*L))
1245
+ Changed |= AddLICMDisableMedatadaToSpecificLoop (*L);
1246
+ }
1221
1247
}
1222
1248
1223
1249
return Changed;
1224
1250
}
1225
1251
1226
- bool DisableLICMForSpecificLoops ::LoopHasLoadFromLocalAddressSpace (const Loop& L)
1252
+ bool SpecialCasesDisableLICM ::LoopHasLoadFromLocalAddressSpace (const Loop& L)
1227
1253
{
1228
1254
for (BasicBlock* BB : L.blocks ())
1229
1255
{
@@ -1236,7 +1262,7 @@ bool DisableLICMForSpecificLoops::LoopHasLoadFromLocalAddressSpace(const Loop& L
1236
1262
return false ;
1237
1263
}
1238
1264
1239
- bool DisableLICMForSpecificLoops ::LoopDependsOnSIMDLaneId (const Loop& L)
1265
+ bool SpecialCasesDisableLICM ::LoopDependsOnSIMDLaneId (const Loop& L)
1240
1266
{
1241
1267
auto ComeFromSIMDLaneID = [](Value* I)
1242
1268
{
@@ -1264,7 +1290,7 @@ bool DisableLICMForSpecificLoops::LoopDependsOnSIMDLaneId(const Loop& L)
1264
1290
return false ;
1265
1291
}
1266
1292
1267
- bool DisableLICMForSpecificLoops ::AddLICMDisableMedatadaToSpecificLoop (Loop& L)
1293
+ bool SpecialCasesDisableLICM ::AddLICMDisableMedatadaToSpecificLoop (Loop& L)
1268
1294
{
1269
1295
LLVMContext& context = L.getHeader ()->getContext ();
1270
1296
@@ -1283,9 +1309,9 @@ bool DisableLICMForSpecificLoops::AddLICMDisableMedatadaToSpecificLoop(Loop& L)
1283
1309
1284
1310
namespace IGC
1285
1311
{
1286
- LoopPass* createDisableLICMForSpecificLoops ()
1312
+ FunctionPass* createSpecialCasesDisableLICM ()
1287
1313
{
1288
- return new DisableLICMForSpecificLoops ();
1314
+ return new SpecialCasesDisableLICM ();
1289
1315
}
1290
1316
}
1291
1317
0 commit comments