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 @@ -280,46 +280,6 @@ }]; } -def fir_CharConvertOp : fir_Op<"char_convert", []> { - let summary = [{ - Primitive to convert an entity of type CHARACTER from one KIND to a - different KIND. - }]; - - let description = [{ - Copy a CHARACTER (must be in memory) of KIND _k1_ to a CHARACTER (also must - be in memory) of KIND _k2_ where _k1_ != _k2_ and the buffers do not - overlap. This latter restriction is unchecked, as the Fortran language - definition eliminates the overlapping in memory case. - - The number of code points copied is specified explicitly as the second - argument. The length of the !fir.char type is ignored. - - ```mlir - fir.char_convert %1 for %2 to %3 : !fir.ref>, i32, - !fir.ref> - ``` - - Should future support for encodings other than ASCII be supported, codegen - can generate a call to a runtime helper routine which will map the code - points from UTF-8 to UCS-2, for example. Such remappings may not always - be possible as they may involve the creation of more code points than the - `count` limit. These details are left as future to-dos. - }]; - - let arguments = (ins - Arg:$from, - AnyIntegerType:$count, - Arg:$to - ); - - let assemblyFormat = [{ - $from `for` $count `to` $to attr-dict `:` type(operands) - }]; - - let hasVerifier = 1; -} - def fir_StoreOp : fir_Op<"store", [MemoryEffects<[MemWrite]>]> { let summary = "store an SSA-value to a memory location"; @@ -357,7 +317,7 @@ let description = [{ Save the result of a function returning an array, box, or record type value - into a memory location given the shape and length parameters of the result. + into a memory location given the shape and LEN parameters of the result. Function results of type fir.box, fir.array, or fir.rec are abstract values that require a storage to be manipulated on the caller side. This operation @@ -366,8 +326,8 @@ memory. For arrays, result, it is required to provide the shape of the result. For - character arrays and derived types with length parameters, the length - parameter values must be provided. + character arrays and derived types with LEN parameters, the LEN parameter + values must be provided. The fir.save_result associated to a function call must immediately follow the call and be in the same block. @@ -399,6 +359,46 @@ let hasVerifier = 1; } +def fir_CharConvertOp : fir_Op<"char_convert", []> { + let summary = [{ + Primitive to convert an entity of type CHARACTER from one KIND to a + different KIND. + }]; + + let description = [{ + Copy a CHARACTER (must be in memory) of KIND _k1_ to a CHARACTER (also must + be in memory) of KIND _k2_ where _k1_ != _k2_ and the buffers do not + overlap. This latter restriction is unchecked, as the Fortran language + definition eliminates the overlapping in memory case. + + The number of code points copied is specified explicitly as the second + argument. The length of the !fir.char type is ignored. + + ```mlir + fir.char_convert %1 for %2 to %3 : !fir.ref>, i32, + !fir.ref> + ``` + + Should future support for encodings other than ASCII be supported, codegen + can generate a call to a runtime helper routine which will map the code + points from UTF-8 to UCS-2, for example. Such remappings may not always + be possible as they may involve the creation of more code points than the + `count` limit. These details are left as future to-dos. + }]; + + let arguments = (ins + Arg:$from, + AnyIntegerType:$count, + Arg:$to + ); + + let assemblyFormat = [{ + $from `for` $count `to` $to attr-dict `:` type(operands) + }]; + + let hasVerifier = 1; +} + def fir_UndefOp : fir_OneResultOp<"undefined", [NoSideEffect]> { let summary = "explicit undefined value of some type"; let description = [{ @@ -2353,7 +2353,7 @@ // operand[0] is the object (of box type) operand_iterator arg_operand_begin() { return operand_begin() + 1; } operand_iterator arg_operand_end() { return operand_end(); } - static constexpr llvm::StringRef passArgAttrName() { + static constexpr llvm::StringRef getPassArgAttrName() { return "pass_arg_pos"; } static constexpr llvm::StringRef getMethodAttrNameStr() { return "method"; } @@ -2446,11 +2446,11 @@ let hasVerifier = 1; let extraClassDeclaration = [{ - static constexpr llvm::StringRef realAttrName() { return "real"; } - static constexpr llvm::StringRef imagAttrName() { return "imaginary"; } + static constexpr llvm::StringRef getRealAttrName() { return "real"; } + static constexpr llvm::StringRef getImagAttrName() { return "imaginary"; } - mlir::Attribute getReal() { return (*this)->getAttr(realAttrName()); } - mlir::Attribute getImaginary() { return (*this)->getAttr(imagAttrName()); } + mlir::Attribute getReal() { return (*this)->getAttr(getRealAttrName()); } + mlir::Attribute getImaginary() { return (*this)->getAttr(getImagAttrName()); } }]; } @@ -2677,11 +2677,13 @@ ]; let extraClassDeclaration = [{ - static constexpr llvm::StringRef symbolAttrNameStr() { return "symref"; } + static constexpr llvm::StringRef getSymbolAttrNameStr() { return "symref"; } static constexpr llvm::StringRef getConstantAttrNameStr() { return "constant"; } - static constexpr llvm::StringRef linkageAttrName() { return "linkName"; } + static constexpr llvm::StringRef getLinkageAttrNameStr() { + return "linkName"; + } /// The semantic type of the global mlir::Type resultType(); @@ -2733,8 +2735,8 @@ let hasCustomAssemblyFormat = 1; let extraClassDeclaration = [{ - static constexpr llvm::StringRef lenParamAttrName() { return "lenparam"; } - static constexpr llvm::StringRef intAttrName() { return "intval"; } + static constexpr llvm::StringRef getLenParamAttrName() { return "lenparam"; } + static constexpr llvm::StringRef getIntAttrName() { return "intval"; } }]; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -798,10 +798,10 @@ fir::RealAttr imagp; mlir::Type type; if (parser.parseLParen() || - parser.parseAttribute(realp, fir::ConstcOp::realAttrName(), + parser.parseAttribute(realp, fir::ConstcOp::getRealAttrName(), result.attributes) || parser.parseComma() || - parser.parseAttribute(imagp, fir::ConstcOp::imagAttrName(), + parser.parseAttribute(imagp, fir::ConstcOp::getImagAttrName(), result.attributes) || parser.parseRParen() || parser.parseColonType(type) || parser.addTypesToList(type, result.types)) @@ -811,8 +811,8 @@ void fir::ConstcOp::print(mlir::OpAsmPrinter &p) { p << '('; - p << getOperation()->getAttr(fir::ConstcOp::realAttrName()) << ", "; - p << getOperation()->getAttr(fir::ConstcOp::imagAttrName()) << ") : "; + p << getOperation()->getAttr(fir::ConstcOp::getRealAttrName()) << ", "; + p << getOperation()->getAttr(fir::ConstcOp::getImagAttrName()) << ") : "; p.printType(getType()); } @@ -1218,12 +1218,12 @@ if (fir::GlobalOp::verifyValidLinkage(linkage)) return mlir::failure(); mlir::StringAttr linkAttr = builder.getStringAttr(linkage); - result.addAttribute(fir::GlobalOp::linkageAttrName(), linkAttr); + result.addAttribute(fir::GlobalOp::getLinkageAttrNameStr(), linkAttr); } // Parse the name as a symbol reference attribute. mlir::SymbolRefAttr nameAttr; - if (parser.parseAttribute(nameAttr, fir::GlobalOp::symbolAttrNameStr(), + if (parser.parseAttribute(nameAttr, fir::GlobalOp::getSymbolAttrNameStr(), result.attributes)) return mlir::failure(); result.addAttribute(mlir::SymbolTable::getSymbolAttrName(), @@ -1294,7 +1294,7 @@ result.addAttribute(getTypeAttrName(result.name), mlir::TypeAttr::get(type)); result.addAttribute(mlir::SymbolTable::getSymbolAttrName(), builder.getStringAttr(name)); - result.addAttribute(symbolAttrNameStr(), + result.addAttribute(getSymbolAttrNameStr(), mlir::SymbolRefAttr::get(builder.getContext(), name)); if (isConstant) result.addAttribute(getConstantAttrName(result.name), @@ -1302,7 +1302,7 @@ if (initialVal) result.addAttribute(getInitValAttrName(result.name), initialVal); if (linkage) - result.addAttribute(linkageAttrName(), linkage); + result.addAttribute(getLinkageAttrNameStr(), linkage); result.attributes.append(attrs.begin(), attrs.end()); } @@ -1359,24 +1359,25 @@ llvm::StringRef fieldName; if (failed(parser.parseOptionalKeyword(&fieldName))) { mlir::StringAttr fieldAttr; - if (parser.parseAttribute(fieldAttr, fir::GlobalLenOp::lenParamAttrName(), + if (parser.parseAttribute(fieldAttr, + fir::GlobalLenOp::getLenParamAttrName(), result.attributes)) return mlir::failure(); } else { - result.addAttribute(fir::GlobalLenOp::lenParamAttrName(), + result.addAttribute(fir::GlobalLenOp::getLenParamAttrName(), parser.getBuilder().getStringAttr(fieldName)); } mlir::IntegerAttr constant; if (parser.parseComma() || - parser.parseAttribute(constant, fir::GlobalLenOp::intAttrName(), + parser.parseAttribute(constant, fir::GlobalLenOp::getIntAttrName(), result.attributes)) return mlir::failure(); return mlir::success(); } void fir::GlobalLenOp::print(mlir::OpAsmPrinter &p) { - p << ' ' << getOperation()->getAttr(fir::GlobalLenOp::lenParamAttrName()) - << ", " << getOperation()->getAttr(fir::GlobalLenOp::intAttrName()); + p << ' ' << getOperation()->getAttr(fir::GlobalLenOp::getLenParamAttrName()) + << ", " << getOperation()->getAttr(fir::GlobalLenOp::getIntAttrName()); } //===----------------------------------------------------------------------===//