[Mlir-commits] [flang] [mlir] [mlir][OpenMP] Add copyprivate support to omp.single (PR #80477)
Kareem Ergawy
llvmlistbot at llvm.org
Thu Feb 8 06:06:47 PST 2024
================
@@ -505,6 +505,108 @@ static LogicalResult verifyReductionVarList(Operation *op,
return success();
}
+//===----------------------------------------------------------------------===//
+// Parser, printer and verifier for CopyPrivateVarList
+//===----------------------------------------------------------------------===//
+
+/// copyprivate-entry-list ::= copyprivate-entry
+/// | copyprivate-entry-list `,` copyprivate-entry
+/// copyprivate-entry ::= ssa-id `->` symbol-ref `:` type
+static ParseResult parseCopyPrivateVarList(
+ OpAsmParser &parser,
+ SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands,
+ SmallVectorImpl<Type> &types, ArrayAttr ©PrivateSymbols) {
+ SmallVector<SymbolRefAttr> copyPrivateFuncsVec;
+ if (failed(parser.parseCommaSeparatedList([&]() {
+ if (parser.parseOperand(operands.emplace_back()) ||
+ parser.parseArrow() ||
+ parser.parseAttribute(copyPrivateFuncsVec.emplace_back()) ||
+ parser.parseColonType(types.emplace_back()))
+ return failure();
+ return success();
+ })))
+ return failure();
+ SmallVector<Attribute> copyPrivateFuncs(copyPrivateFuncsVec.begin(),
+ copyPrivateFuncsVec.end());
+ copyPrivateSymbols = ArrayAttr::get(parser.getContext(), copyPrivateFuncs);
+ return success();
+}
+
+/// Print CopyPrivate clause
+static void printCopyPrivateVarList(OpAsmPrinter &p, Operation *op,
+ OperandRange copyPrivateVars,
+ TypeRange copyPrivateTypes,
+ std::optional<ArrayAttr> copyPrivateFuncs) {
+ if (!copyPrivateFuncs.has_value())
+ return;
+ llvm::interleaveComma(
+ llvm::zip(copyPrivateVars, *copyPrivateFuncs, copyPrivateTypes), p,
+ [&](const auto &args) {
+ p << std::get<0>(args) << " -> " << std::get<1>(args) << " : "
+ << std::get<2>(args);
+ });
+}
+
+/// Verifies CopyPrivate Clause
+static LogicalResult
+verifyCopyPrivateVarList(Operation *op, OperandRange copyPrivateVars,
+ std::optional<ArrayAttr> copyPrivateFuncs) {
+ if (!copyPrivateVars.empty()) {
+ if (!copyPrivateFuncs || copyPrivateFuncs->size() != copyPrivateVars.size())
+ return op->emitOpError() << "expected as many copyPrivate functions as "
+ "copyPrivate variables";
+ } else {
+ if (copyPrivateFuncs)
+ return op->emitOpError() << "unexpected copyPrivate functions";
+ return success();
+ }
----------------
ergawy wrote:
I think this block can be simplified as such:
```
if (copyPrivateFuncs->size() != copyPrivateVars.size())
return op->emitOpError() << "inconsistent number of copyPrivate vars (= "
<< copyPrivateVars.size() << ") and functions (= "
<< copyPrivateFuncs->size() << "), both must be equal";
```
I think this would make the code easier to read and also convey the proper amount of information about the op error.
https://github.com/llvm/llvm-project/pull/80477
More information about the Mlir-commits
mailing list