Skip to content

Commit 26a12a8

Browse files
dmitryryinteligcbot
authored andcommitted
skip printf strings in constant encoding
1 parent cfbe6f8 commit 26a12a8

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,16 +2668,10 @@ bool GenXKernelBuilder::buildMainInst(Instruction *Inst, BaleInfo BI,
26682668
} else if (auto LI = dyn_cast<LoadInst>(Inst)) {
26692669
(void)LI; // no code generated
26702670
} else if (auto GEPI = dyn_cast<GetElementPtrInst>(Inst)) {
2671-
// check if gepi def is used in intrinsic, otherwise report error
2672-
auto GepiChecker = [](Use &ui) {
2673-
auto ci = cast<CallInst>(ui.getUser());
2674-
Function *Callee = ci->getCalledFunction();
2675-
unsigned IntrinID = GenXIntrinsic::getAnyIntrinsicID(Callee);
2676-
return (IntrinID == GenXIntrinsic::genx_print_format_index);
2677-
};
2678-
if (!std::all_of(GEPI->use_begin(), GEPI->use_end(), GepiChecker)) {
2679-
report_fatal_error("gep is supported only for printf");
2680-
}
2671+
// Skip genx.print.format.index GEP here.
2672+
IGC_ASSERT_MESSAGE(isPrintFormatIndexGEP(*GEPI),
2673+
"only genx.print.format.index src GEP can still be "
2674+
"present at this stage");
26812675
#if (LLVM_VERSION_MAJOR > 8)
26822676
} else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(Inst)) {
26832677
buildUnaryOperator(UO, BI, Mod, DstDesc);

IGC/VectorCompiler/lib/GenXCodeGen/GenXOCLRuntimeInfo.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,22 @@ static void appendGlobalVariableData(
531531
Accumulator.append(&GV, Data.begin(), Data.end());
532532
}
533533

534-
ModuleDataT getModuleData(const Module &M) {
534+
// Not every global variable is a real global variable and should be encoded
535+
// as a global variable.
536+
// GenX volatile and printf strings are exclusion for now.
537+
static bool isRealGlobalVariable(const GlobalVariable &GV) {
538+
if (GV.hasAttribute("genx_volatile"))
539+
return false;
540+
return std::any_of(GV.user_begin(), GV.user_end(), [](const User *Usr) {
541+
return !genx::isPrintFormatIndexGEP(*Usr);
542+
});
543+
}
544+
545+
static ModuleDataT getModuleData(const Module &M) {
535546
genx::BinaryDataAccumulator<const GlobalVariable *> ConstantData;
536547
genx::BinaryDataAccumulator<const GlobalVariable *> GlobalData;
537548
for (auto &GV : M.globals()) {
538-
if (GV.hasAttribute("genx_volatile"))
549+
if (!isRealGlobalVariable(GV))
539550
continue;
540551
if (GV.isConstant())
541552
appendGlobalVariableData(ConstantData, GV);

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,3 +1988,22 @@ unsigned genx::getNumGRFsPerIndirectForRegion(const genx::Region &R,
19881988
}
19891989
return 1;
19901990
}
1991+
1992+
bool genx::isPrintFormatIndexGEP(const GetElementPtrInst &GEP) {
1993+
return std::all_of(GEP.user_begin(), GEP.user_end(), [](const User *Usr) {
1994+
if (!isa<CallInst>(Usr))
1995+
return false;
1996+
const Function *Callee = cast<CallInst>(Usr)->getCalledFunction();
1997+
if (!Callee)
1998+
return false;
1999+
auto IntrinID = GenXIntrinsic::getAnyIntrinsicID(Callee);
2000+
return (IntrinID == GenXIntrinsic::genx_print_format_index);
2001+
});
2002+
}
2003+
2004+
// Just for convenience.
2005+
bool genx::isPrintFormatIndexGEP(const Value &V) {
2006+
if (!isa<GetElementPtrInst>(V))
2007+
return false;
2008+
return isPrintFormatIndexGEP(cast<GetElementPtrInst>(V));
2009+
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,13 @@ template <typename KeyT> class BinaryDataAccumulator {
637637
std::vector<char> emitConsolidatedData() && { return std::move(Data); }
638638
};
639639

640+
// There's a special case of GEP when all its users are genx.print.format.index
641+
// intrinsics. Such GEPs live until CisaBuilder and then handled as part of
642+
// genx.print.format.index intrinsic.
643+
// This function checks whether \p GEP is a such GEP.
644+
bool isPrintFormatIndexGEP(const GetElementPtrInst &GEP);
645+
bool isPrintFormatIndexGEP(const Value &V);
646+
640647
} // namespace genx
641648
} // namespace llvm
642649

0 commit comments

Comments
 (0)