[Mlir-commits] [mlir] [mlir][spirv] Add gpu printf op lowering to spirv.CL.printf op (PR #78510)
Jakub Kuderski
llvmlistbot at llvm.org
Wed Jan 17 21:08:42 PST 2024
================
@@ -607,6 +616,108 @@ class GPUSubgroupReduceConversion final
}
};
+LogicalResult GPUPrintfConversion::matchAndRewrite(
+ gpu::PrintfOp gpuPrintfOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const {
+
+ auto loc = gpuPrintfOp.getLoc();
+
+ auto funcOp =
+ rewriter.getBlock()->getParent()->getParentOfType<mlir::spirv::FuncOp>();
+
+ auto moduleOp = funcOp->getParentOfType<mlir::spirv::ModuleOp>();
+
+ const char formatStringPrefix[] = "printfMsg";
+ unsigned stringNumber = 0;
+ mlir::SmallString<16> globalVarName;
+ mlir::spirv::GlobalVariableOp globalVar;
+
+ // formulate spirv global variable name
+ do {
+ globalVarName.clear();
+ (formatStringPrefix + llvm::Twine(stringNumber++))
+ .toStringRef(globalVarName);
+ } while (moduleOp.lookupSymbol(globalVarName));
----------------
kuhar wrote:
I don't understand what this is trying to do. Can we simplify this and/or add some comment with an example?
https://github.com/llvm/llvm-project/pull/78510
More information about the Mlir-commits
mailing list