[flang-commits] [flang] [mlir] [openacc][flang] Support two type bindName representation in acc routine (PR #149147)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Jul 16 10:31:49 PDT 2025
================
@@ -3461,40 +3462,89 @@ LogicalResult acc::RoutineOp::verify() {
return success();
}
-static ParseResult parseBindName(OpAsmParser &parser, mlir::ArrayAttr &bindName,
- mlir::ArrayAttr &deviceTypes) {
- llvm::SmallVector<mlir::Attribute> bindNameAttrs;
- llvm::SmallVector<mlir::Attribute> deviceTypeAttrs;
+static ParseResult parseBindName(OpAsmParser &parser,
+ mlir::ArrayAttr &bindIdName,
+ mlir::ArrayAttr &bindStrName,
+ mlir::ArrayAttr &deviceIdTypes,
+ mlir::ArrayAttr &deviceStrTypes) {
+ llvm::SmallVector<mlir::Attribute> bindIdNameAttrs;
+ llvm::SmallVector<mlir::Attribute> bindStrNameAttrs;
+ llvm::SmallVector<mlir::Attribute> deviceIdTypeAttrs;
+ llvm::SmallVector<mlir::Attribute> deviceStrTypeAttrs;
if (failed(parser.parseCommaSeparatedList([&]() {
- if (parser.parseAttribute(bindNameAttrs.emplace_back()))
+ mlir::Attribute newAttr;
+ bool isSymbolRefAttr;
+ auto parseResult = parser.parseAttribute(newAttr);
+ if (auto symbolRefAttr = dyn_cast<mlir::SymbolRefAttr>(newAttr)) {
+ bindIdNameAttrs.push_back(symbolRefAttr);
+ isSymbolRefAttr = true;
+ } else if (auto stringAttr = dyn_cast<mlir::StringAttr>(newAttr)) {
+ bindStrNameAttrs.push_back(stringAttr);
+ isSymbolRefAttr = false;
+ }
+ if (parseResult)
return failure();
if (failed(parser.parseOptionalLSquare())) {
- deviceTypeAttrs.push_back(mlir::acc::DeviceTypeAttr::get(
- parser.getContext(), mlir::acc::DeviceType::None));
+ if (isSymbolRefAttr) {
+ deviceIdTypeAttrs.push_back(mlir::acc::DeviceTypeAttr::get(
+ parser.getContext(), mlir::acc::DeviceType::None));
+ } else {
+ deviceStrTypeAttrs.push_back(mlir::acc::DeviceTypeAttr::get(
+ parser.getContext(), mlir::acc::DeviceType::None));
+ }
} else {
- if (parser.parseAttribute(deviceTypeAttrs.emplace_back()) ||
- parser.parseRSquare())
- return failure();
+ if (isSymbolRefAttr) {
+ if (parser.parseAttribute(deviceIdTypeAttrs.emplace_back()) ||
+ parser.parseRSquare())
+ return failure();
+ } else {
+ if (parser.parseAttribute(deviceStrTypeAttrs.emplace_back()) ||
+ parser.parseRSquare())
+ return failure();
+ }
}
return success();
})))
return failure();
- bindName = ArrayAttr::get(parser.getContext(), bindNameAttrs);
- deviceTypes = ArrayAttr::get(parser.getContext(), deviceTypeAttrs);
+ bindIdName = ArrayAttr::get(parser.getContext(), bindIdNameAttrs);
+ bindStrName = ArrayAttr::get(parser.getContext(), bindStrNameAttrs);
+ deviceIdTypes = ArrayAttr::get(parser.getContext(), deviceIdTypeAttrs);
+ deviceStrTypes = ArrayAttr::get(parser.getContext(), deviceStrTypeAttrs);
return success();
}
static void printBindName(mlir::OpAsmPrinter &p, mlir::Operation *op,
- std::optional<mlir::ArrayAttr> bindName,
- std::optional<mlir::ArrayAttr> deviceTypes) {
- llvm::interleaveComma(llvm::zip(*bindName, *deviceTypes), p,
- [&](const auto &pair) {
- p << std::get<0>(pair);
- printSingleDeviceType(p, std::get<1>(pair));
- });
+ std::optional<mlir::ArrayAttr> bindIdName,
+ std::optional<mlir::ArrayAttr> bindStrName,
+ std::optional<mlir::ArrayAttr> deviceIdTypes,
+ std::optional<mlir::ArrayAttr> deviceStrTypes) {
+ // Create combined vectors for all bind names and device types
+ llvm::SmallVector<mlir::Attribute> allBindNames;
+ llvm::SmallVector<mlir::Attribute> allDeviceTypes;
+
+ // Append bindIdName and deviceIdTypes
+ if (hasDeviceTypeValues(deviceIdTypes)) {
+ allBindNames.append(bindIdName->begin(), bindIdName->end());
+ allDeviceTypes.append(deviceIdTypes->begin(), deviceIdTypes->end());
+ }
+
+ // Append bindStrName and deviceStrTypes
+ if (hasDeviceTypeValues(deviceStrTypes)) {
+ allBindNames.append(bindStrName->begin(), bindStrName->end());
+ allDeviceTypes.append(deviceStrTypes->begin(), deviceStrTypes->end());
+ }
+
+ // Print the combined sequence
+ if (!allBindNames.empty()) {
+ llvm::interleaveComma(llvm::zip(allBindNames, allDeviceTypes), p,
+ [&](const auto &pair) {
+ p << std::get<0>(pair);
+ printSingleDeviceType(p, std::get<1>(pair));
+ });
+ }
----------------
clementval wrote:
No brace
https://github.com/llvm/llvm-project/pull/149147
More information about the flang-commits
mailing list