Skip to content

Commit 2b1b933

Browse files
ktrifunovicigcbot
authored andcommitted
Changes in code.
1 parent e64fdad commit 2b1b933

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

IGC/AdaptorCommon/RayTracing/SplitAsyncUtils.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ SPDX-License-Identifier: MIT
2929
using namespace llvm;
3030
using 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+
3241
static 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

186204
bool 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

193211
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+
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

238273
bool 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))

IGC/AdaptorCommon/RayTracing/SplitAsyncUtils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SPDX-License-Identifier: MIT
2424
#include <llvm/IR/ValueHandle.h>
2525
#include <llvm/Transforms/Utils/ValueMapper.h>
2626
#include "common/LLVMWarningsPop.hpp"
27-
27+
#include <llvm/Support/raw_ostream.h>
2828
#include <optional>
2929

3030
namespace IGC {
@@ -52,6 +52,11 @@ enum class RematStage { MID, LATE };
5252
class RematChecker {
5353
public:
5454
RematChecker(CodeGenContext &Ctx, RematStage Stage);
55+
56+
#if defined(_DEBUG) || defined(_INTERNAL)
57+
RematChecker(CodeGenContext &Ctx, RematStage Stage, llvm::raw_ostream *Stream);
58+
#endif
59+
5560
std::optional<std::vector<llvm::Instruction *>> canFullyRemat(llvm::Instruction *I, uint32_t Threshold,
5661
llvm::ValueToValueMapTy *VM = nullptr) const;
5762

@@ -64,6 +69,9 @@ class RematChecker {
6469

6570
CodeGenContext &Ctx;
6671
RematStage Stage;
72+
#if defined(_DEBUG) || defined(_INTERNAL)
73+
llvm::raw_ostream *m_pStream;
74+
#endif
6775
};
6876

6977
} // namespace IGC

0 commit comments

Comments
 (0)