Skip to content

Commit 046b766

Browse files
dlei6gigcbot
authored andcommitted
Library compilations cannot use scratch space for private memory
SS Private memory is disabled for when stackcalls are enabled, including indirect calls. However when a module is compiled as a library, i.e. there is no kernel function, only external-linkage library functions, we fail to detect that module as having a stackcall. In this case we need to disable SS private memory as well since the dynamically linked callers will also have it disabled.
1 parent 714885d commit 046b766

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

IGC/Compiler/CISACodeGen/GenCodeGenModule.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,9 @@ void GenXFunctionGroupAnalysis::setGroupAttributes()
654654
void GenXFunctionGroupAnalysis::addIndirectFuncsToKernelGroup(llvm::Module* pModule)
655655
{
656656
auto pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
657-
auto IFG = getOrCreateIndirectCallGroup(pModule);
658-
659-
if (!IFG) return;
660657

661658
// Find all indirectly called functions that require a symbol
659+
SmallVector<Function*, 16> indirectFunctions;
662660
for (auto I = pModule->begin(), E = pModule->end(); I != E; ++I)
663661
{
664662
Function* F = &(*I);
@@ -667,6 +665,16 @@ void GenXFunctionGroupAnalysis::addIndirectFuncsToKernelGroup(llvm::Module* pMod
667665
if (F->hasFnAttribute("referenced-indirectly"))
668666
{
669667
IGC_ASSERT(getGroup(F) == nullptr);
668+
indirectFunctions.push_back(F);
669+
}
670+
}
671+
// Add them to the indirect call group
672+
if (!indirectFunctions.empty())
673+
{
674+
auto IFG = getOrCreateIndirectCallGroup(pModule);
675+
IGC_ASSERT(IFG);
676+
for (auto F : indirectFunctions)
677+
{
670678
addToFunctionGroup(F, IFG, F);
671679
}
672680
}

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,14 @@ bool PrivateMemoryResolution::safeToUseScratchSpace(llvm::Module& M) const
277277

278278
//
279279
// Do not use scratch space if module has any stack call.
280-
// Do not use scratch space if modeule has any variable length alloca
280+
// Do not use scratch space if module has any variable length alloca
281+
// Do not use scratch space if module has indirectly called functions
281282
//
282283
if (bOCLLegacyStatelessCheck) {
283284
if (auto * FGA = getAnalysisIfAvailable<GenXFunctionGroupAnalysis>()) {
284285
if (FGA->getModule() == &M) {
286+
if (FGA->getIndirectCallGroup() != nullptr)
287+
return false;
285288
for (auto& I : *FGA) {
286289
if (I->hasStackCall())
287290
return false;

0 commit comments

Comments
 (0)