Skip to content

Commit 4dd5222

Browse files
committed
[flang] Extend fir.do_loop to reuse OpenMP clause table-gen records
1 parent 8b284dc commit 4dd5222

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"
@@ -2171,7 +2172,7 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
21712172
let hasVerifier = 1;
21722173
let hasCustomAssemblyFormat = 1;
21732174

2174-
let arguments = (ins
2175+
defvar opArgs = (ins
21752176
Index:$lowerBound,
21762177
Index:$upperBound,
21772178
Index:$step,
@@ -2182,6 +2183,8 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
21822183
OptionalAttr<ArrayAttr>:$reduceAttrs,
21832184
OptionalAttr<LoopAnnotationAttr>:$loopAnnotation
21842185
);
2186+
2187+
let arguments = !con(opArgs, OpenMP_PrivateClause.arguments);
21852188
let results = (outs Variadic<AnyType>:$results);
21862189
let regions = (region SizedRegion<1>:$region);
21872190

@@ -2193,10 +2196,13 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
21932196
CArg<"mlir::ValueRange", "std::nullopt">:$iterArgs,
21942197
CArg<"mlir::ValueRange", "std::nullopt">:$reduceOperands,
21952198
CArg<"llvm::ArrayRef<mlir::Attribute>", "{}">:$reduceAttrs,
2196-
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>
2199+
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes,
2200+
CArg<"mlir::ValueRange", "std::nullopt">:$private_vars,
2201+
CArg<"mlir::ArrayRef<mlir::Attribute>", "{}">:$private_syms
2202+
)>
21972203
];
21982204

2199-
let extraClassDeclaration = [{
2205+
defvar opExtraClassDeclaration = [{
22002206
mlir::Value getInductionVar() { return getBody()->getArgument(0); }
22012207
mlir::OpBuilder getBodyBuilder() {
22022208
return mlir::OpBuilder(getBody(), std::prev(getBody()->end()));
@@ -2258,6 +2264,10 @@ def fir_DoLoopOp : region_Op<"do_loop", [AttrSizedOperandSegments,
22582264
unsigned resultNum);
22592265
mlir::Value blockArgToSourceOp(unsigned blockArgNum);
22602266
}];
2267+
2268+
let extraClassDeclaration =
2269+
!strconcat(opExtraClassDeclaration, "\n",
2270+
OpenMP_PrivateClause.extraClassDeclaration);
22612271
}
22622272

22632273
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
@@ -2478,14 +2478,16 @@ void fir::DoLoopOp::build(mlir::OpBuilder &builder,
24782478
bool finalCountValue, mlir::ValueRange iterArgs,
24792479
mlir::ValueRange reduceOperands,
24802480
llvm::ArrayRef<mlir::Attribute> reduceAttrs,
2481-
llvm::ArrayRef<mlir::NamedAttribute> attributes) {
2481+
llvm::ArrayRef<mlir::NamedAttribute> attributes,
2482+
mlir::ValueRange privateVars,
2483+
mlir::ArrayRef<mlir::Attribute> privateSyms) {
24822484
result.addOperands({lb, ub, step});
24832485
result.addOperands(reduceOperands);
24842486
result.addOperands(iterArgs);
24852487
result.addAttribute(getOperandSegmentSizeAttr(),
24862488
builder.getDenseI32ArrayAttr(
24872489
{1, 1, 1, static_cast<int32_t>(reduceOperands.size()),
2488-
static_cast<int32_t>(iterArgs.size())}));
2490+
static_cast<int32_t>(iterArgs.size()), 0}));
24892491
if (finalCountValue) {
24902492
result.addTypes(builder.getIndexType());
24912493
result.addAttribute(getFinalValueAttrName(result.name),
@@ -2591,7 +2593,7 @@ mlir::ParseResult fir::DoLoopOp::parse(mlir::OpAsmParser &parser,
25912593
result.addAttribute(getOperandSegmentSizeAttr(),
25922594
builder.getDenseI32ArrayAttr(
25932595
{1, 1, 1, static_cast<int32_t>(reduceOperands.size()),
2594-
static_cast<int32_t>(iterOperands.size())}));
2596+
static_cast<int32_t>(iterOperands.size()), 0}));
25952597

25962598
if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
25972599
return mlir::failure();

0 commit comments

Comments
 (0)