Skip to content

Commit 8734a3d

Browse files
author
Artem Gindinson
authored
[SYCL] Improve mutation of literal address space for variadic printf (#5286)
The initial implementation of address space mutation assumed that in presence of `experimental::printf` wrappers at the IR level, each wrapper would use its dedicated signature of the `__spirv_ocl_printf` builtin. However, this is not the case when the variadic signature of the builtin is employed - in that scenario, the wrapper does not become variadic, so `__spirv_ocl_printf` may have multiple wrapper instances using it. Adjust the algorithm for removing generic AS functions accordingly and add LIT coverage for the non-inline variadic case. In addition, minimize the IR for the non-variadic O0 test. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 934f73a commit 8734a3d

File tree

3 files changed

+144
-263
lines changed

3 files changed

+144
-263
lines changed

llvm/lib/SYCLLowerIR/MutatePrintfAddrspace.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
186186
FunctionVecTy &FunctionsToDrop) {
187187
size_t MutatedCallsCount = 0;
188188
SmallVector<std::pair<CallInst *, Constant *>, 16> CallsToMutate;
189+
FunctionVecTy WrapperFunctionsToDrop;
189190
for (User *U : F->users()) {
190191
if (!isa<CallInst>(U))
191192
continue;
@@ -225,13 +226,14 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
225226
}
226227
// We're certain that the wrapper won't have any uses, since we've just
227228
// marked all its calls for replacement with __spirv_ocl_printf.
228-
FunctionsToDrop.emplace_back(WrapperFunc);
229-
// Similar certainty for the generic AS version of __spirv_ocl_printf
230-
// itself - we've determined it only gets called inside the
231-
// soon-to-be-removed wrapper.
232-
assert(F->hasOneUse() && "Unexpected __spirv_ocl_printf call outside of "
233-
"SYCL wrapper function");
234-
FunctionsToDrop.emplace_back(F);
229+
WrapperFunctionsToDrop.emplace_back(WrapperFunc);
230+
// __spirv_ocl_printf itself only gets called inside the
231+
// soon-to-be-removed wrappers and will be marked for removal once these
232+
// are removed. The builtin may only have n>1 uses in case it's variadic -
233+
// in that scenario, all wrapper instances will be referencing it.
234+
assert((F->hasOneUse() || F->isVarArg()) &&
235+
"Unexpected __spirv_ocl_printf call outside of "
236+
"SYCL wrapper function");
235237
} else {
236238
emitError(
237239
F, CI,
@@ -246,6 +248,8 @@ size_t setFuncCallsOntoCASPrintf(Function *F, Function *CASPrintfFunc,
246248
CASPrintfFunc);
247249
++MutatedCallsCount;
248250
}
251+
for (Function *WF : WrapperFunctionsToDrop)
252+
WF->eraseFromParent();
249253
if (F->hasNUses(0))
250254
FunctionsToDrop.emplace_back(F);
251255
return MutatedCallsCount;

0 commit comments

Comments
 (0)