[Mlir-commits] [mlir] [mlir][GPU] gpu.printf: Do not emit duplicate format strings (PR #110504)

Guray Ozen llvmlistbot at llvm.org
Mon Sep 30 06:43:04 PDT 2024


================
@@ -340,6 +340,34 @@ static SmallString<16> getUniqueFormatGlobalName(gpu::GPUModuleOp moduleOp) {
   return stringConstName;
 }
 
+/// Create an global that contains the given format string. If a global with
+/// the same format string exists already in the module, return that global.
+static LLVM::GlobalOp getOrCreateFormatStringConstant(
+    OpBuilder &b, Location loc, gpu::GPUModuleOp moduleOp, Type llvmI8,
+    StringRef str, uint64_t alignment = 0, unsigned addrSpace = 0) {
+  llvm::SmallString<20> formatString(str);
+  formatString.push_back('\0'); // Null terminate for C
+  auto globalType =
+      LLVM::LLVMArrayType::get(llvmI8, formatString.size_in_bytes());
+  StringAttr attr = b.getStringAttr(formatString);
+
+  // Try to find existing global.
+  for (auto globalOp : moduleOp.getOps<LLVM::GlobalOp>())
----------------
grypp wrote:

if you look at the ` getDynamicSharedMemorySymbol` below, it does something very similar. Can we unify them?

https://github.com/llvm/llvm-project/pull/110504


More information about the Mlir-commits mailing list