Skip to content

Commit 0389be9

Browse files
committed
[flang] Extend fir.do_loop to reuse OpenMP clause table-gen records
1 parent 8d7cb5d commit 0389be9

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

flang/include/flang/Optimizer/Dialect/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ mlir_tablegen(FIRAttr.cpp.inc -gen-attrdef-defs)
1616
set(LLVM_TARGET_DEFINITIONS FIROps.td)
1717
mlir_tablegen(FIROps.h.inc -gen-op-decls)
1818
mlir_tablegen(FIROps.cpp.inc -gen-op-defs)
19-
mlir_tablegen(FIROpsTypes.h.inc --gen-typedef-decls)
20-
mlir_tablegen(FIROpsTypes.cpp.inc --gen-typedef-defs)
19+
mlir_tablegen(FIROpsTypes.h.inc --gen-typedef-decls -typedefs-dialect=fir)
20+
mlir_tablegen(FIROpsTypes.cpp.inc --gen-typedef-defs -typedefs-dialect=fir)
2121
add_public_tablegen_target(FIROpsIncGen)
2222

2323
set(LLVM_TARGET_DEFINITIONS FortranVariableInterface.td)

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
include "mlir/Dialect/Arith/IR/ArithBase.td"
1818
include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.td"
19+
include "mlir/Dialect/OpenMP/OpenMPClauses.td"
1920
include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td"
2021
include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.td"
2122
include "flang/Optimizer/Dialect/FIRDialect.td"
@@ -2226,7 +2227,7 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
22262227
let hasVerifier = 1;
22272228
let hasCustomAssemblyFormat = 1;
22282229

2229-
let arguments = (ins
2230+
defvar opArgs = (ins
22302231
Index:$lowerBound,
22312232
Index:$upperBound,
22322233
Index:$step,
@@ -2237,6 +2238,8 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
22372238
OptionalAttr<ArrayAttr>:$reduceAttrs,
22382239
OptionalAttr<LoopAnnotationAttr>:$loopAnnotation
22392240
);
2241+
2242+
let arguments = !con(opArgs, OpenMP_PrivateClause.arguments);
22402243
let results = (outs Variadic<AnyType>:$results);
22412244
let regions = (region SizedRegion<1>:$region);
22422245

@@ -2248,10 +2251,13 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
22482251
CArg<"mlir::ValueRange", "std::nullopt">:$iterArgs,
22492252
CArg<"mlir::ValueRange", "std::nullopt">:$reduceOperands,
22502253
CArg<"llvm::ArrayRef<mlir::Attribute>", "{}">:$reduceAttrs,
2251-
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>
2254+
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes,
2255+
CArg<"mlir::ValueRange", "std::nullopt">:$private_vars,
2256+
CArg<"mlir::ArrayRef<mlir::Attribute>", "{}">:$private_syms
2257+
)>
22522258
];
22532259

2254-
let extraClassDeclaration = [{
2260+
defvar opExtraClassDeclaration = [{
22552261
mlir::Value getInductionVar() { return getBody()->getArgument(0); }
22562262
mlir::OpBuilder getBodyBuilder() {
22572263
return mlir::OpBuilder(getBody(), std::prev(getBody()->end()));
@@ -2313,6 +2319,10 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
23132319
unsigned resultNum);
23142320
mlir::Value blockArgToSourceOp(unsigned blockArgNum);
23152321
}];
2322+
2323+
let extraClassDeclaration =
2324+
!strconcat(opExtraClassDeclaration, "\n",
2325+
OpenMP_PrivateClause.extraClassDeclaration);
23162326
}
23172327

23182328
def fir_IfOp : region_Op<"if", [DeclareOpInterfaceMethods<RegionBranchOpInterface, [

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,14 +2603,16 @@ void fir::DoLoopOp::build(mlir::OpBuilder &builder,
26032603
bool finalCountValue, mlir::ValueRange iterArgs,
26042604
mlir::ValueRange reduceOperands,
26052605
llvm::ArrayRef<mlir::Attribute> reduceAttrs,
2606-
llvm::ArrayRef<mlir::NamedAttribute> attributes) {
2606+
llvm::ArrayRef<mlir::NamedAttribute> attributes,
2607+
mlir::ValueRange privateVars,
2608+
mlir::ArrayRef<mlir::Attribute> privateSyms) {
26072609
result.addOperands({lb, ub, step});
26082610
result.addOperands(reduceOperands);
26092611
result.addOperands(iterArgs);
26102612
result.addAttribute(getOperandSegmentSizeAttr(),
26112613
builder.getDenseI32ArrayAttr(
26122614
{1, 1, 1, static_cast<int32_t>(reduceOperands.size()),
2613-
static_cast<int32_t>(iterArgs.size())}));
2615+
static_cast<int32_t>(iterArgs.size()), 0}));
26142616
if (finalCountValue) {
26152617
result.addTypes(builder.getIndexType());
26162618
result.addAttribute(getFinalValueAttrName(result.name),
@@ -2716,7 +2718,7 @@ mlir::ParseResult fir::DoLoopOp::parse(mlir::OpAsmParser &parser,
27162718
result.addAttribute(getOperandSegmentSizeAttr(),
27172719
builder.getDenseI32ArrayAttr(
27182720
{1, 1, 1, static_cast<int32_t>(reduceOperands.size()),
2719-
static_cast<int32_t>(iterOperands.size())}));
2721+
static_cast<int32_t>(iterOperands.size()), 0}));
27202722

27212723
if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
27222724
return mlir::failure();

0 commit comments

Comments
 (0)