@@ -29,6 +29,15 @@ SPDX-License-Identifier: MIT
2929using namespace llvm ;
3030using namespace IGC ;
3131
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+
3241static void rewritePHIs (BasicBlock &BB) {
3342 // For every incoming edge we will create a block holding all
3443 // incoming values in a single PHI nodes.
@@ -181,7 +190,16 @@ void rewriteMaterializableInstructions(const SmallVector<Spill, 8> &Spills) {
181190 }
182191}
183192
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
185203
186204bool RematChecker::isReadOnly (const Value *Ptr) const {
187205 uint32_t Addrspace = Ptr->getType ()->getPointerAddressSpace ();
@@ -191,13 +209,22 @@ bool RematChecker::isReadOnly(const Value *Ptr) const {
191209}
192210
193211bool 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+
194216 if (isa<CastInst>(&I) || isa<GetElementPtrInst>(&I) || isa<BinaryOperator>(&I) || isa<CmpInst>(&I) ||
195217 isa<SelectInst>(&I) || isa<ExtractElementInst>(&I)) {
218+ REMAT_DIAG (*m_pStream << " true: [one of: castinst, gep, binaryoperator, cmpinst, selectinst, eei]\n " );
196219 return true ;
197220 }
198221
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 " ));
200226 return (LI->getPointerAddressSpace () == ADDRESS_SPACE_CONSTANT);
227+ }
201228
202229 if (auto *GII = dyn_cast<GenIntrinsicInst>(&I)) {
203230 switch (GII->getIntrinsicID ()) {
@@ -207,14 +234,20 @@ bool RematChecker::materializable(const Instruction &I) const {
207234 case GenISAIntrinsic::GenISA_DispatchDimensions:
208235 case GenISAIntrinsic::GenISA_frc:
209236 case GenISAIntrinsic::GenISA_ROUNDNE:
237+ REMAT_DIAG (*m_pStream << " true: [one of: accepted GenISA_* intrinsics]\n " );
210238 return true ;
211239 case GenISAIntrinsic::GenISA_ldraw_indexed:
212240 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 " ));
213244 return isReadOnly (cast<LdRawIntrinsic>(GII)->getResourceValue ());
214245 case GenISAIntrinsic::GenISA_ldptr:
215246 case GenISAIntrinsic::GenISA_ldlptr:
247+ REMAT_DIAG (*m_pStream << " true: [ldptr or ldlptr]\n " );
216248 return true ;
217249 default :
250+ REMAT_DIAG (*m_pStream << " false: [non-supported GenISA intrinsic - missed opportunity?]\n " );
218251 return false ;
219252 }
220253 }
@@ -228,24 +261,38 @@ bool RematChecker::materializable(const Instruction &I) const {
228261 case Intrinsic::sqrt:
229262 return true ;
230263 default :
264+ REMAT_DIAG (*m_pStream << " false: [non-satisfying LLVM intrinsic]\n " );
231265 return false ;
232266 }
233267 }
234268
269+ REMAT_DIAG (*m_pStream << " false: [non-supported case: missed opportunity?]\n " );
235270 return false ;
236271}
237272
238273bool RematChecker::canFullyRemat (Instruction *I, std::vector<Instruction *> &Insts,
239274 std::unordered_set<Instruction *> &Visited, unsigned StartDepth, unsigned Depth,
240275 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+
241282 if (!Visited.insert (I).second )
242283 return true ;
243284
244285 if (StartDepth != Depth && VM && VM->count (I) != 0 )
245286 return true ;
246287
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+
248294 return false ;
295+ }
249296
250297 for (auto &Op : I->operands ()) {
251298 if (isa<Constant>(Op))
0 commit comments