diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -35,34 +35,6 @@ }]; } -// Base builder for allocate operations -def fir_AllocateOpBuilder : OpBuilder<(ins - "mlir::Type":$inType, - CArg<"mlir::ValueRange", "{}">:$lenParams, - CArg<"mlir::ValueRange", "{}">:$sizes, - CArg<"llvm::ArrayRef", "{}">:$attributes), - [{ - $_state.addTypes(getRefTy(inType)); - $_state.addAttribute("in_type", TypeAttr::get(inType)); - $_state.addOperands(sizes); - $_state.addAttributes(attributes); - }]>; - -def fir_NamedAllocateOpBuilder : OpBuilder<(ins - "mlir::Type":$inType, - "llvm::StringRef":$name, - CArg<"mlir::ValueRange", "{}">:$lenParams, - CArg<"mlir::ValueRange","{}">:$sizes, - CArg<"llvm::ArrayRef", "{}">:$attributes), - [{ - $_state.addTypes(getRefTy(inType)); - $_state.addAttribute("in_type", TypeAttr::get(inType)); - if (!name.empty()) - $_state.addAttribute("name", $_builder.getStringAttr(name)); - $_state.addOperands(sizes); - $_state.addAttributes(attributes); - }]>; - def fir_OneResultOpBuilder : OpBuilder<(ins "mlir::Type":$resultType, "mlir::ValueRange":$operands, @@ -86,128 +58,6 @@ let builders = [fir_OneResultOpBuilder]; } -class fir_TwoBuilders { - list builders = [b1, b2]; -} - -class fir_AllocatableBaseOp traits = []> : - fir_Op, Results<(outs fir_Type:$res)> { - let arguments = (ins - OptionalAttr:$name, - OptionalAttr:$target - ); -} - -class fir_AllocatableOp traits = []> : - fir_AllocatableBaseOp]>])>, - fir_TwoBuilders, - Arguments<(ins TypeAttr:$in_type, Variadic:$args)> { - - let parser = [{ - mlir::Type intype; - if (parser.parseType(intype)) - return mlir::failure(); - auto &builder = parser.getBuilder(); - result.addAttribute(inType(), mlir::TypeAttr::get(intype)); - llvm::SmallVector operands; - llvm::SmallVector typeVec; - bool hasOperands = false; - if (!parser.parseOptionalLParen()) { - // parse the LEN params of the derived type. ( : ) - if (parser.parseOperandList(operands, - mlir::OpAsmParser::Delimiter::None) || - parser.parseColonTypeList(typeVec) || - parser.parseRParen()) - return mlir::failure(); - auto lens = builder.getI32IntegerAttr(operands.size()); - result.addAttribute(lenpName(), lens); - hasOperands = true; - } - if (!parser.parseOptionalComma()) { - // parse size to scale by, vector of n dimensions of type index - auto opSize = operands.size(); - if (parser.parseOperandList(operands, mlir::OpAsmParser::Delimiter::None)) - return mlir::failure(); - for (auto i = opSize, end = operands.size(); i != end; ++i) - typeVec.push_back(builder.getIndexType()); - hasOperands = true; - } - if (hasOperands && - parser.resolveOperands(operands, typeVec, parser.getNameLoc(), - result.operands)) - return mlir::failure(); - mlir::Type restype = wrapResultType(intype); - if (!restype) { - parser.emitError(parser.getNameLoc(), "invalid allocate type: ") - << intype; - return mlir::failure(); - } - if (parser.parseOptionalAttrDict(result.attributes) || - parser.addTypeToList(restype, result.types)) - return mlir::failure(); - return mlir::success(); - }]; - - let printer = [{ - p << ' ' << (*this)->getAttr(inType()); - if (hasLenParams()) { - // print the LEN parameters to a derived type in parens - p << '(' << getLenParams() << " : " << getLenParams().getTypes() << ')'; - } - // print the shape of the allocation (if any); all must be index type - for (auto sh : getShapeOperands()) { - p << ", "; - p.printOperand(sh); - } - p.printOptionalAttrDict((*this)->getAttrs(), {inType(), lenpName()}); - }]; - - string extraAllocClassDeclaration = [{ - static constexpr llvm::StringRef inType() { return "in_type"; } - static constexpr llvm::StringRef lenpName() { return "len_param_count"; } - mlir::Type getAllocatedType(); - - bool hasLenParams() { return bool{(*this)->getAttr(lenpName())}; } - bool hasShapeOperands() { return numShapeOperands() > 0; } - - unsigned numLenParams() { - if (auto val = (*this)->getAttrOfType(lenpName())) - return val.getInt(); - return 0; - } - - operand_range getLenParams() { - return {operand_begin(), operand_begin() + numLenParams()}; - } - - unsigned numShapeOperands() { - return operand_end() - operand_begin() + numLenParams(); - } - - operand_range getShapeOperands() { - return {operand_begin() + numLenParams(), operand_end()}; - } - - static mlir::Type getRefTy(mlir::Type ty); - - /// Get the input type of the allocation - mlir::Type getInType() { - return (*this)->getAttrOfType(inType()).getValue(); - } - }]; - - // Verify checks common to all allocation operations - string allocVerify = [{ - llvm::SmallVector visited; - if (verifyInType(getInType(), visited, numShapeOperands())) - return emitOpError("invalid type for allocation"); - if (verifyRecordLenParams(getInType(), numLenParams())) - return emitOpError("LEN params do not correspond to type"); - }]; -} - //===----------------------------------------------------------------------===// // Memory SSA operations //===----------------------------------------------------------------------===//