================
@@ -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;
+ auto resolve = [&](mlir::Value value) {
+ std::string str;
+ if (getConstantStringInfo(value, opModule, opLayout, symbolTables, str))
+ entries.push_back(mlir::StringAttr::get(ctx, str));
+ else
+ entries.push_back(mlir::UnitAttr::get(ctx));
+ };
+ resolve(op.getFormat());
+ for (mlir::Value arg : op.getArgs())
+ resolve(arg);
----------------
steffenlarsen wrote:
Slight personal preference, so please stick with your version if you prefer:
```suggestion
auto resolve = [&](mlir::Value value) -> mlir::Attribute {
std::string str;
if (getConstantStringInfo(value, opModule, opLayout, symbolTables, str))
return mlir::StringAttr::get(ctx, str);
return mlir::UnitAttr::get(ctx);
};
llvm::SmallVector<mlir::Attribute> entries;
entries.reserve(op.getArgs().size() + 1);
entries.push_back(resolve(op.getFormat()));
for (mlir::Value arg : op.getArgs())
entries.push_back(resolve(arg));
```
https://github.com/llvm/llvm-project/pull/242111
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits