[llvm-branch-commits] [OpenMP][MLIR] Add new arguments to map_info to help support record type maps (PR #82851)
Sergio Afonso via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 22 06:17:06 PDT 2024
================
@@ -990,6 +990,77 @@ static void printMapClause(OpAsmPrinter &p, Operation *op,
}
}
+static ParseResult parseMembersIndex(OpAsmParser &parser,
+ DenseIntElementsAttr &membersIdx) {
+ SmallVector<APInt> values;
+ int64_t value;
+ int64_t shape[2] = {0, 0};
+ unsigned shapeTmp = 0;
+ auto parseIndices = [&]() -> ParseResult {
+ if (parser.parseInteger(value))
+ return failure();
+ shapeTmp++;
+ values.push_back(APInt(32, value));
+ return success();
+ };
+
+ do {
+ if (failed(parser.parseLSquare()))
+ return failure();
+
+ if (parser.parseCommaSeparatedList(parseIndices))
+ return failure();
+
+ if (failed(parser.parseRSquare()))
+ return failure();
+
+ // Only set once, if any indices are not the same size
+ // we error out in the next check as that's unsupported
+ if (shape[1] == 0)
+ shape[1] = shapeTmp;
+
+ // Verify that the recently parsed list is equal to the
+ // first one we parsed, they must be equal lengths to
+ // keep the rectangular shape DenseIntElementsAttr
+ // requires
+ if (shapeTmp != shape[1])
+ return failure();
+
+ shapeTmp = 0;
+ shape[0]++;
+ } while (succeeded(parser.parseOptionalComma()));
+
+ if (!values.empty()) {
+ ShapedType valueType =
+ VectorType::get(shape, IntegerType::get(parser.getContext(), 32));
+ membersIdx = DenseIntElementsAttr::get(valueType, values);
+ }
+
+ return success();
+}
+
+static void printMembersIndex(OpAsmPrinter &p, MapInfoOp op,
+ DenseIntElementsAttr membersIdx) {
+ assert(membersIdx.getShapedType().getShape().size() <= 2);
----------------
skatrak wrote:
Nit: Maybe store a local reference to `membersIdx.getShapedType().getShape()` and reuse it to reduce the verbosity of the code a bit.
https://github.com/llvm/llvm-project/pull/82851
More information about the llvm-branch-commits
mailing list