@@ -29,6 +29,15 @@ SPDX-License-Identifier: MIT
29
29
using namespace llvm ;
30
30
using namespace IGC ;
31
31
32
+ #if defined(_DEBUG) || defined(_INTERNAL)
33
+ #define REMAT_DIAG (X ) \
34
+ if (m_pStream) { \
35
+ X; \
36
+ }
37
+ #else
38
+ #define REMAT_DIAG (X )
39
+ #endif
40
+
32
41
static void rewritePHIs (BasicBlock &BB) {
33
42
// For every incoming edge we will create a block holding all
34
43
// incoming values in a single PHI nodes.
@@ -181,7 +190,16 @@ void rewriteMaterializableInstructions(const SmallVector<Spill, 8> &Spills) {
181
190
}
182
191
}
183
192
184
- RematChecker::RematChecker (CodeGenContext &Ctx, RematStage Stage) : Ctx(Ctx), Stage(Stage) {}
193
+ RematChecker::RematChecker (CodeGenContext &Ctx, RematStage Stage) : Ctx(Ctx), Stage(Stage) {
194
+ #if defined(_DEBUG) || defined(_INTERNAL)
195
+ m_pStream = nullptr ;
196
+ #endif
197
+ }
198
+
199
+ #if defined(_DEBUG) || defined(_INTERNAL)
200
+ RematChecker::RematChecker (CodeGenContext &Ctx, RematStage Stage, llvm::raw_ostream *Stream)
201
+ : Ctx(Ctx), Stage(Stage), m_pStream(Stream) {}
202
+ #endif
185
203
186
204
bool RematChecker::isReadOnly (const Value *Ptr) const {
187
205
uint32_t Addrspace = Ptr->getType ()->getPointerAddressSpace ();
@@ -191,13 +209,22 @@ bool RematChecker::isReadOnly(const Value *Ptr) const {
191
209
}
192
210
193
211
bool RematChecker::materializable (const Instruction &I) const {
212
+ REMAT_DIAG (*m_pStream << " Query materializable: " );
213
+ REMAT_DIAG (I.print (*m_pStream));
214
+ REMAT_DIAG (*m_pStream << " \n " );
215
+
194
216
if (isa<CastInst>(&I) || isa<GetElementPtrInst>(&I) || isa<BinaryOperator>(&I) || isa<CmpInst>(&I) ||
195
217
isa<SelectInst>(&I) || isa<ExtractElementInst>(&I)) {
218
+ REMAT_DIAG (*m_pStream << " true: [one of: castinst, gep, binaryoperator, cmpinst, selectinst, eei]\n " );
196
219
return true ;
197
220
}
198
221
199
- if (auto *LI = dyn_cast<LoadInst>(&I))
222
+ if (auto *LI = dyn_cast<LoadInst>(&I)) {
223
+ REMAT_DIAG (*m_pStream << ((LI->getPointerAddressSpace () == ADDRESS_SPACE_CONSTANT) ?
224
+ " true: [LOAD with constant address space]\n " :
225
+ " false: [LOAD address space not satisfying]\n " ));
200
226
return (LI->getPointerAddressSpace () == ADDRESS_SPACE_CONSTANT);
227
+ }
201
228
202
229
if (auto *GII = dyn_cast<GenIntrinsicInst>(&I)) {
203
230
switch (GII->getIntrinsicID ()) {
@@ -207,14 +234,20 @@ bool RematChecker::materializable(const Instruction &I) const {
207
234
case GenISAIntrinsic::GenISA_DispatchDimensions:
208
235
case GenISAIntrinsic::GenISA_frc:
209
236
case GenISAIntrinsic::GenISA_ROUNDNE:
237
+ REMAT_DIAG (*m_pStream << " true: [one of: accepted GenISA_* intrinsics]\n " );
210
238
return true ;
211
239
case GenISAIntrinsic::GenISA_ldraw_indexed:
212
240
case GenISAIntrinsic::GenISA_ldrawvector_indexed:
241
+ REMAT_DIAG (*m_pStream << (isReadOnly (cast<LdRawIntrinsic>(GII)->getResourceValue ()) ?
242
+ " true: [ldraw with read-only buffer]\n " :
243
+ " false: [ldraw not read-only]\n " ));
213
244
return isReadOnly (cast<LdRawIntrinsic>(GII)->getResourceValue ());
214
245
case GenISAIntrinsic::GenISA_ldptr:
215
246
case GenISAIntrinsic::GenISA_ldlptr:
247
+ REMAT_DIAG (*m_pStream << " true: [ldptr or ldlptr]\n " );
216
248
return true ;
217
249
default :
250
+ REMAT_DIAG (*m_pStream << " false: [non-supported GenISA intrinsic - missed opportunity?]\n " );
218
251
return false ;
219
252
}
220
253
}
@@ -228,24 +261,38 @@ bool RematChecker::materializable(const Instruction &I) const {
228
261
case Intrinsic::sqrt:
229
262
return true ;
230
263
default :
264
+ REMAT_DIAG (*m_pStream << " false: [non-satisfying LLVM intrinsic]\n " );
231
265
return false ;
232
266
}
233
267
}
234
268
269
+ REMAT_DIAG (*m_pStream << " false: [non-supported case: missed opportunity?]\n " );
235
270
return false ;
236
271
}
237
272
238
273
bool RematChecker::canFullyRemat (Instruction *I, std::vector<Instruction *> &Insts,
239
274
std::unordered_set<Instruction *> &Visited, unsigned StartDepth, unsigned Depth,
240
275
ValueToValueMapTy *VM) const {
276
+ REMAT_DIAG (*m_pStream << " \n " << std::string (StartDepth - Depth, ' ' ) << " canFullyRemat: " );
277
+ REMAT_DIAG (I->print (*m_pStream));
278
+ REMAT_DIAG (*m_pStream << " \n "
279
+ << std::string (StartDepth - Depth, ' ' ) << " |sd: " << StartDepth << " , depth: " << Depth
280
+ << " | " );
281
+
241
282
if (!Visited.insert (I).second )
242
283
return true ;
243
284
244
285
if (StartDepth != Depth && VM && VM->count (I) != 0 )
245
286
return true ;
246
287
247
- if (Depth == 0 || !materializable (*I))
288
+ if (Depth == 0 || !materializable (*I)) {
289
+ REMAT_DIAG (*m_pStream << " \n "
290
+ << std::string (StartDepth - Depth, ' ' )
291
+ << (Depth == 0 ? " Depth exhausted." :
292
+ " materializable false" ));
293
+
248
294
return false ;
295
+ }
249
296
250
297
for (auto &Op : I->operands ()) {
251
298
if (isa<Constant>(Op))
0 commit comments