@@ -109,10 +109,13 @@ def AnyShapeLike : TypeConstraint<Or<[fir_ShapeType.predicate,
109
109
fir_ShapeShiftType.predicate]>, "any legal shape type">;
110
110
def AnyShapeType : Type<AnyShapeLike.predicate, "any legal shape type">;
111
111
def fir_SliceType : Type<CPred<"$_self.isa<fir::SliceType>()">, "slice type">;
112
- def AnyEmboxLike : TypeConstraint<Or<[AnyIntegerType.predicate,
113
- AnyShapeType.predicate, fir_SliceType.predicate]>,
114
- "any legal embox argument type">;
115
- def AnyEmboxArg : Type<AnyEmboxLike.predicate, "embox argument type">;
112
+ def AffineMapAttr : Attr<
113
+ CPred<"$_self.isa<mlir::AffineMapAttr>()">, "AffineMap attribute"> {
114
+ let storageType = "mlir::AffineMapAttr";
115
+ let returnType = "mlir::AffineMap";
116
+ let valueType = Index;
117
+ let constBuilderCall = "mlir::AffineMapAttr::get($0)";
118
+ }
116
119
117
120
// A type descriptor's type
118
121
def fir_TypeDescType : Type<CPred<"$_self.isa<fir::TypeDescType>()">,
@@ -1034,9 +1037,11 @@ def fir_HasValueOp : fir_Op<"has_value", [Terminator, HasParent<"GlobalOp">]> {
1034
1037
let assemblyFormat = "$resval attr-dict `:` type($resval)";
1035
1038
}
1036
1039
1040
+ //===------------------------------------------------------------------------===//
1037
1041
// Operations on !fir.box<T> type objects
1042
+ //===------------------------------------------------------------------------===//
1038
1043
1039
- def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
1044
+ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect, AttrSizedOperandSegments ]> {
1040
1045
let summary = "boxes a given reference and (optional) dimension information";
1041
1046
1042
1047
let description = [{
@@ -1056,51 +1061,43 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
1056
1061
information through the use of additional attributes.
1057
1062
}];
1058
1063
1059
- let arguments = (ins AnyReferenceLike:$memref, Variadic<AnyEmboxArg>:$args);
1064
+ let arguments = (ins
1065
+ AnyReferenceLike:$memref,
1066
+ Optional<AnyShapeType>:$shape,
1067
+ Optional<fir_SliceType>:$slice,
1068
+ Variadic<AnyIntegerType>:$lenParams,
1069
+ OptionalAttr<AffineMapAttr>:$accessMap
1070
+ );
1060
1071
1061
1072
let results = (outs fir_BoxType);
1062
1073
1063
- let parser = "return parseEmboxOp(parser, result);";
1074
+ let builders = [
1075
+ OpBuilder<"mlir::OpBuilder &builder, mlir::OperationState &state,"
1076
+ "llvm::ArrayRef<mlir::Type> resultTypes, mlir::Value memref,"
1077
+ "mlir::Value shape = {}, mlir::Value slice = {},"
1078
+ "mlir::ValueRange lenParams = {}", [{
1079
+ return build(builder, state, resultTypes, memref, shape, slice,
1080
+ lenParams, mlir::AffineMapAttr{}); }]>
1081
+ ];
1064
1082
1065
- let printer = [{
1066
- p << getOperationName() << ' ';
1067
- p.printOperand(memref());
1068
- if (auto shape = getShape()) {
1069
- p << '(';
1070
- p.printOperand(shape);
1071
- p << ')';
1072
- }
1073
- if (auto slice = getSlice()) {
1074
- p << '[';
1075
- p.printOperand(slice);
1076
- p << ']';
1077
- }
1078
- if (auto map = getAttr(layoutName()))
1079
- p << " map " << map;
1080
- if (hasLenParams()) {
1081
- p << " typeparams ";
1082
- p.printOperands(getLenParams());
1083
- }
1084
- p.printOptionalAttrDict(getAttrs(), {layoutName(), lenpName(), shapeName(),
1085
- sliceName()});
1086
- p << " : ";
1087
- p.printFunctionalType(getOperation());
1083
+ let assemblyFormat = [{
1084
+ $memref (`(` $shape^ `)`)? (`[` $slice^ `]`)? (`typeparams` $lenParams^)? (`map` $accessMap^)? attr-dict `:` functional-type(operands, results)
1088
1085
}];
1089
1086
1090
1087
let verifier = [{
1091
1088
auto eleTy = fir::dyn_cast_ptrEleTy(memref().getType());
1092
1089
if (!eleTy)
1093
1090
return emitOpError("must embox a memory reference type");
1094
1091
if (hasLenParams()) {
1095
- auto lenParams = numLenParams();
1092
+ auto lenPs = numLenParams();
1096
1093
if (auto rt = eleTy.dyn_cast<fir::RecordType>()) {
1097
- if (lenParams != rt.getNumLenParams())
1094
+ if (lenPs != rt.getNumLenParams())
1098
1095
return emitOpError("number of LEN params does not correspond"
1099
1096
" to the !fir.type type");
1100
1097
} else {
1101
1098
return emitOpError("LEN parameters require !fir.type type");
1102
1099
}
1103
- for (auto lp : getLenParams ())
1100
+ for (auto lp : lenParams ())
1104
1101
if (!fir::isa_integer(lp.getType()))
1105
1102
return emitOpError("LEN parameters must be integral type");
1106
1103
}
@@ -1118,42 +1115,10 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
1118
1115
}];
1119
1116
1120
1117
let extraClassDeclaration = [{
1121
- static constexpr llvm::StringRef layoutName() { return "layout_map"; }
1122
- static constexpr llvm::StringRef lenpName() { return "len_param_count"; }
1123
- static constexpr llvm::StringRef shapeName() { return "shape"; }
1124
- static constexpr llvm::StringRef sliceName() { return "slice"; }
1125
-
1126
- mlir::Value getShape() {
1127
- if (auto x = getAttrOfType<mlir::UnitAttr>(shapeName()))
1128
- return *std::next(operand_begin());
1129
- return {};
1130
- }
1131
-
1132
- mlir::Value getSlice() {
1133
- if (auto x = getAttrOfType<mlir::UnitAttr>(sliceName())) {
1134
- auto iter = std::next(operand_begin());
1135
- if (getShape())
1136
- iter = std::next(iter);
1137
- return *iter;
1138
- }
1139
- return {};
1140
- }
1141
-
1142
- bool hasLenParams() { return bool{getAttr(lenpName())}; }
1143
- unsigned numLenParams() {
1144
- if (auto x = getAttrOfType<mlir::IntegerAttr>(lenpName()))
1145
- return x.getInt();
1146
- return 0;
1147
- }
1148
-
1149
- operand_range getLenParams() {
1150
- auto iter = std::next(operand_begin());
1151
- if (getShape())
1152
- iter = std::next(iter);
1153
- if (getSlice())
1154
- iter = std::next(iter);
1155
- return {iter, operand_end()};
1156
- }
1118
+ mlir::Value getShape() { return shape(); }
1119
+ mlir::Value getSlice() { return slice(); }
1120
+ bool hasLenParams() { return !lenParams().empty(); }
1121
+ unsigned numLenParams() { return lenParams().size(); }
1157
1122
}];
1158
1123
}
1159
1124
@@ -1576,7 +1541,9 @@ def fir_BoxTypeDescOp : fir_SimpleOneResultOp<"box_tdesc", [NoSideEffect]> {
1576
1541
}
1577
1542
1578
1543
// Record and array type operations
1579
- def fir_ArrayCoorOp : fir_Op<"array_coor", [NoSideEffect, AttrSizedOperandSegments]> {
1544
+ def fir_ArrayCoorOp : fir_Op<"array_coor",
1545
+ [NoSideEffect, AttrSizedOperandSegments]> {
1546
+
1580
1547
let summary = "Find the coordinate of an element of an array";
1581
1548
1582
1549
let description = [{
@@ -1601,14 +1568,18 @@ def fir_ArrayCoorOp : fir_Op<"array_coor", [NoSideEffect, AttrSizedOperandSegmen
1601
1568
```
1602
1569
}];
1603
1570
1604
- let arguments = (ins AnyReferenceLike:$memref,
1605
- Optional<AnyShapeType>:$shape, Optional<fir_SliceType>:$slice,
1606
- Variadic<AnyCoordinateType>:$indices,
1607
- Variadic<AnyIntegerType>:$lenParams);
1571
+ let arguments = (ins
1572
+ AnyReferenceLike:$memref,
1573
+ Optional<AnyShapeType>:$shape,
1574
+ Optional<fir_SliceType>:$slice,
1575
+ Variadic<AnyCoordinateType>:$indices,
1576
+ Variadic<AnyIntegerType>:$lenParams
1577
+ );
1608
1578
1609
1579
let results = (outs fir_ReferenceType);
1580
+
1610
1581
let assemblyFormat = [{
1611
- $memref (`(`$shape^`)`)? (`[`$slice^`]`)? $indices (`typeparams` $lenParams^)? `:` functional-type(operands, results) attr-dict
1582
+ $memref (`(`$shape^`)`)? (`[`$slice^`]`)? $indices (`typeparams` $lenParams^)? attr-dict `:` functional-type(operands, results)
1612
1583
}];
1613
1584
1614
1585
let verifier = [{
0 commit comments