Skip to content

Commit

Permalink
[flang][NFC] Cosmetic changes to make the file more homogenous
Browse files Browse the repository at this point in the history
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D128799
  • Loading branch information
clementval committed Jun 29, 2022
1 parent 7c65e62 commit be80c6d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 65 deletions.
106 changes: 54 additions & 52 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -280,46 +280,6 @@ def fir_LoadOp : fir_OneResultOp<"load", [MemoryEffects<[MemRead]>]> {
}];
}

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<!fir.char<1,?>>, i32,
!fir.ref<!fir.char<2,20>>
```

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<AnyReferenceLike, "", [MemRead]>:$from,
AnyIntegerType:$count,
Arg<AnyReferenceLike, "", [MemWrite]>:$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";

Expand Down Expand Up @@ -357,7 +317,7 @@ def fir_SaveResultOp : fir_Op<"save_result", [AttrSizedOperandSegments]> {

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
Expand All @@ -366,8 +326,8 @@ def fir_SaveResultOp : fir_Op<"save_result", [AttrSizedOperandSegments]> {
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.
Expand Down Expand Up @@ -399,6 +359,46 @@ def fir_SaveResultOp : fir_Op<"save_result", [AttrSizedOperandSegments]> {
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<!fir.char<1,?>>, i32,
!fir.ref<!fir.char<2,20>>
```

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<AnyReferenceLike, "", [MemRead]>:$from,
AnyIntegerType:$count,
Arg<AnyReferenceLike, "", [MemWrite]>:$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 = [{
Expand Down Expand Up @@ -2353,7 +2353,7 @@ def fir_DispatchOp : fir_Op<"dispatch", []> {
// 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"; }
Expand Down Expand Up @@ -2446,11 +2446,11 @@ def fir_ConstcOp : fir_Op<"constc", [NoSideEffect]> {
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()); }
}];
}

Expand Down Expand Up @@ -2677,11 +2677,13 @@ def fir_GlobalOp : fir_Op<"global", [IsolatedFromAbove, Symbol]> {
];

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();
Expand Down Expand Up @@ -2733,8 +2735,8 @@ def fir_GlobalLenOp : fir_Op<"global_len", []> {
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"; }
}];
}

Expand Down
27 changes: 14 additions & 13 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ mlir::ParseResult fir::ConstcOp::parse(mlir::OpAsmParser &parser,
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))
Expand All @@ -811,8 +811,8 @@ mlir::ParseResult fir::ConstcOp::parse(mlir::OpAsmParser &parser,

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());
}

Expand Down Expand Up @@ -1218,12 +1218,12 @@ mlir::ParseResult fir::GlobalOp::parse(mlir::OpAsmParser &parser,
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(),
Expand Down Expand Up @@ -1294,15 +1294,15 @@ void fir::GlobalOp::build(mlir::OpBuilder &builder,
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),
builder.getUnitAttr());
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());
}

Expand Down Expand Up @@ -1359,24 +1359,25 @@ mlir::ParseResult fir::GlobalLenOp::parse(mlir::OpAsmParser &parser,
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());
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit be80c6d

Please sign in to comment.