[clang] [CIR] Annotate AMDGPU printf ops with constant strings before lowering (PR #242111)

Steffen Larsen via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 00:17:06 PST 2026


================
@@ -199,6 +287,40 @@ class AMDGPUPrintfLowering {
 
 } // namespace
 
+bool isAMDGPUPrintfModule(mlir::ModuleOp module) {
+  llvm::StringRef tripleStr;
+  if (auto tripleAttr = module->getAttrOfType<mlir::StringAttr>(
+          cir::CIRDialect::getTripleAttrName()))
+    tripleStr = tripleAttr.getValue();
+  llvm::Triple triple(tripleStr);
+  return triple.isAMDGCN() ||
+         (triple.isSPIRV() && triple.getVendor() == llvm::Triple::AMD);
+}
+
+void annotateAMDGPUPrintfStrings(mlir::ModuleOp module,
+                                 mlir::SymbolTableCollection &symbolTables) {
+  mlir::MLIRContext *ctx = module.getContext();
+  module.walk([&](cir::OffloadPrintfOp op) {
+    mlir::ModuleOp opModule = op->getParentOfType<mlir::ModuleOp>();
+    if (!isAMDGPUPrintfModule(opModule))
+      return;
+    mlir::DataLayout opLayout(opModule);
+    llvm::SmallVector<mlir::Attribute> entries;
----------------
steffenlarsen wrote:

```suggestion
    llvm::SmallVector<mlir::Attribute> entries;
    entries.reserve(op.getArgs().size() + 1);
```

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


More information about the cfe-commits mailing list