Skip to content

[SYCL] Improve mutation of literal address space for variadic printf #5286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions llvm/lib/SYCLLowerIR/MutatePrintfAddrspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
FunctionVecTy &FunctionsToDrop) {
size_t MutatedCallsCount = 0;
SmallVector<std::pair<CallInst *, Constant *>, 16> CallsToMutate;
FunctionVecTy WrapperFunctionsToDrop;
for (User *U : F->users()) {
if (!isa<CallInst>(U))
continue;
Expand Down Expand Up @@ -225,13 +226,14 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
}
// We're certain that the wrapper won't have any uses, since we've just
// marked all its calls for replacement with __spirv_ocl_printf.
FunctionsToDrop.emplace_back(WrapperFunc);
// Similar certainty for the generic AS version of __spirv_ocl_printf
// itself - we've determined it only gets called inside the
// soon-to-be-removed wrapper.
assert(F->hasOneUse() && "Unexpected __spirv_ocl_printf call outside of "
"SYCL wrapper function");
FunctionsToDrop.emplace_back(F);
WrapperFunctionsToDrop.emplace_back(WrapperFunc);
// __spirv_ocl_printf itself only gets called inside the
// soon-to-be-removed wrappers and will be marked for removal once these
// are removed. The builtin may only have n>1 uses in case it's variadic -
// in that scenario, all wrapper instances will be referencing it.
assert((F->hasOneUse() || F->isVarArg()) &&
"Unexpected __spirv_ocl_printf call outside of "
"SYCL wrapper function");
} else {
emitError(
F, CI,
Expand All @@ -246,6 +248,8 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
CASPrintfFunc);
++MutatedCallsCount;
}
for (Function *WF : WrapperFunctionsToDrop)
WF->eraseFromParent();
if (F->hasNUses(0))
FunctionsToDrop.emplace_back(F);
return MutatedCallsCount;
Expand Down
Loading