[llvm-branch-commits] [OpenMP][MLIR] Descriptor explicit member map lowering changes (PR #111191)

Sergio Afonso via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Oct 22 04:44:50 PDT 2024


================
@@ -1415,51 +1414,32 @@ static ParseResult parseMembersIndex(OpAsmParser &parser,
     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]++;
+    memberIdxs.push_back(ArrayAttr::get(parser.getContext(), values));
+    values.clear();
   } while (succeeded(parser.parseOptionalComma()));
 
-  if (!values.empty()) {
-    ShapedType valueType =
-        VectorType::get(shape, IntegerType::get(parser.getContext(), 32));
-    membersIdx = DenseIntElementsAttr::get(valueType, values);
-  }
+  if (!memberIdxs.empty())
+    membersIdx = ArrayAttr::get(parser.getContext(), memberIdxs);
 
   return success();
 }
 
 static void printMembersIndex(OpAsmPrinter &p, MapInfoOp op,
-                              DenseIntElementsAttr membersIdx) {
-  llvm::ArrayRef<int64_t> shape = membersIdx.getShapedType().getShape();
-  assert(shape.size() <= 2);
-
+                              ArrayAttr membersIdx) {
   if (!membersIdx)
     return;
 
-  for (int i = 0; i < shape[0]; ++i) {
+  SmallVector<std::string> idxs;
+  for (auto [i, v] : llvm::enumerate(membersIdx)) {
+    auto memberIdx = mlir::cast<mlir::ArrayAttr>(v);
     p << "[";
-    int rowOffset = i * shape[1];
-    for (int j = 0; j < shape[1]; ++j) {
-      p << membersIdx.getValues<int32_t>()[rowOffset + j];
-      if ((j + 1) < shape[1])
-        p << ",";
-    }
-    p << "]";
-
-    if ((i + 1) < shape[0])
+    for (auto v2 : memberIdx.getValue())
+      idxs.push_back(
+          std::to_string(mlir::cast<mlir::IntegerAttr>(v2).getInt()));
+    p << llvm::join(idxs, ",") << "]";
+    if ((i + 1) < membersIdx.getValue().size())
       p << ", ";
+    idxs.clear();
   }
----------------
skatrak wrote:

I think this can still be simplified a bit. Something like this:
```c++
  llvm::interleaveComma(membersIdx, p, [&p](Attribute v) {
    p << "[";
    auto memberIdx = cast<ArrayAttr>(v);
    llvm::interleaveComma(
        memberIdx.getValue(), p,
        [&p](Attribute v2) { p << cast<IntegerAttr>(v2).getInt(); });
    p << "]";
  });
```

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


More information about the llvm-branch-commits mailing list