[flang-commits] [flang] 220f314 - [fir] Update fir.field_index op
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Sep 30 03:52:03 PDT 2021
Author: Valentin Clement
Date: 2021-09-30T12:51:57+02:00
New Revision: 220f314f94abfd201930ed9d491ce55695df2908
URL: https://github.com/llvm/llvm-project/commit/220f314f94abfd201930ed9d491ce55695df2908
DIFF: https://github.com/llvm/llvm-project/commit/220f314f94abfd201930ed9d491ce55695df2908.diff
LOG: [fir] Update fir.field_index op
Move the parser, printer, verifier and builder out of the .td file.
Rename lenparams to typeparams to be in sync with fir-dev.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: rovka
Differential Revision: https://reviews.llvm.org/D110690
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Optimizer/Dialect/FIROps.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 45c11e22cd30..8c392f6f868b 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -1827,66 +1827,15 @@ def fir_FieldIndexOp : fir_OneResultOp<"field_index", [NoSideEffect]> {
let arguments = (ins
StrAttr:$field_id,
TypeAttr:$on_type,
- Variadic<AnyIntegerType>:$lenparams
+ Variadic<AnyIntegerType>:$typeparams
);
- let parser = [{
- llvm::StringRef fieldName;
- auto &builder = parser.getBuilder();
- mlir::Type recty;
- if (parser.parseOptionalKeyword(&fieldName) ||
- parser.parseComma() ||
- parser.parseType(recty))
- return mlir::failure();
- result.addAttribute(fieldAttrName(), builder.getStringAttr(fieldName));
- if (!recty.dyn_cast<RecordType>())
- return mlir::failure();
- result.addAttribute(typeAttrName(), mlir::TypeAttr::get(recty));
- if (!parser.parseOptionalLParen()) {
- llvm::SmallVector<mlir::OpAsmParser::OperandType, 8> operands;
- llvm::SmallVector<mlir::Type, 8> types;
- auto loc = parser.getNameLoc();
- if (parser.parseOperandList(operands,
- mlir::OpAsmParser::Delimiter::None) ||
- parser.parseColonTypeList(types) ||
- parser.parseRParen() ||
- parser.resolveOperands(operands, types, loc, result.operands))
- return mlir::failure();
- }
- mlir::Type fieldType = fir::FieldType::get(builder.getContext());
- if (parser.addTypeToList(fieldType, result.types))
- return mlir::failure();
- return mlir::success();
- }];
+ let parser = "return parseFieldIndexOp(parser, result);";
- let printer = [{
- p << ' '
- << (*this)->getAttrOfType<mlir::StringAttr>(fieldAttrName()).getValue()
- << ", " << (*this)->getAttr(typeAttrName());
- if (getNumOperands()) {
- p << '(';
- p.printOperands(lenparams());
- auto sep = ") : ";
- for (auto op : lenparams()) {
- p << sep;
- if (op)
- p.printType(op.getType());
- else
- p << "()";
- sep = ", ";
- }
- }
- }];
+ let printer = "::print(p, *this);";
let builders = [OpBuilder<(ins "llvm::StringRef":$fieldName,
- "mlir::Type":$recTy, CArg<"mlir::ValueRange","{}">:$operands),
- [{
- $_state.addAttribute(fieldAttrName(),
- $_builder.getStringAttr(fieldName));
- $_state.addAttribute(typeAttrName(), TypeAttr::get(recTy));
- $_state.addOperands(operands);
- }]
- >];
+ "mlir::Type":$recTy, CArg<"mlir::ValueRange","{}">:$operands)>];
let extraClassDeclaration = [{
static constexpr llvm::StringRef fieldAttrName() { return "field_id"; }
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index ab6fe7f92969..7a73e42b96af 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1225,6 +1225,69 @@ void fir::ExtractValueOp::build(mlir::OpBuilder &builder,
build(builder, result, resTy, aggVal, aa);
}
+//===----------------------------------------------------------------------===//
+// FieldIndexOp
+//===----------------------------------------------------------------------===//
+
+static mlir::ParseResult parseFieldIndexOp(mlir::OpAsmParser &parser,
+ mlir::OperationState &result) {
+ llvm::StringRef fieldName;
+ auto &builder = parser.getBuilder();
+ mlir::Type recty;
+ if (parser.parseOptionalKeyword(&fieldName) || parser.parseComma() ||
+ parser.parseType(recty))
+ return mlir::failure();
+ result.addAttribute(fir::FieldIndexOp::fieldAttrName(),
+ builder.getStringAttr(fieldName));
+ if (!recty.dyn_cast<RecordType>())
+ return mlir::failure();
+ result.addAttribute(fir::FieldIndexOp::typeAttrName(),
+ mlir::TypeAttr::get(recty));
+ if (!parser.parseOptionalLParen()) {
+ llvm::SmallVector<mlir::OpAsmParser::OperandType> operands;
+ llvm::SmallVector<mlir::Type> types;
+ auto loc = parser.getNameLoc();
+ if (parser.parseOperandList(operands, mlir::OpAsmParser::Delimiter::None) ||
+ parser.parseColonTypeList(types) || parser.parseRParen() ||
+ parser.resolveOperands(operands, types, loc, result.operands))
+ return mlir::failure();
+ }
+ mlir::Type fieldType = fir::FieldType::get(builder.getContext());
+ if (parser.addTypeToList(fieldType, result.types))
+ return mlir::failure();
+ return mlir::success();
+}
+
+static void print(mlir::OpAsmPrinter &p, fir::FieldIndexOp &op) {
+ p << ' '
+ << op.getOperation()
+ ->getAttrOfType<mlir::StringAttr>(fir::FieldIndexOp::fieldAttrName())
+ .getValue()
+ << ", " << op.getOperation()->getAttr(fir::FieldIndexOp::typeAttrName());
+ if (op.getNumOperands()) {
+ p << '(';
+ p.printOperands(op.typeparams());
+ const auto *sep = ") : ";
+ for (auto op : op.typeparams()) {
+ p << sep;
+ if (op)
+ p.printType(op.getType());
+ else
+ p << "()";
+ sep = ", ";
+ }
+ }
+}
+
+void fir::FieldIndexOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &result,
+ llvm::StringRef fieldName, mlir::Type recTy,
+ mlir::ValueRange operands) {
+ result.addAttribute(fieldAttrName(), builder.getStringAttr(fieldName));
+ result.addAttribute(typeAttrName(), TypeAttr::get(recTy));
+ result.addOperands(operands);
+}
+
//===----------------------------------------------------------------------===//
// InsertOnRangeOp
//===----------------------------------------------------------------------===//
More information about the flang-commits
mailing list