Skip to content

Commit 1b7ea4f

Browse files
committed
[flang] Extend fir.do_concurrent.loop to reuse OpenMP clause table-gen records
1 parent a7039c6 commit 1b7ea4f

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

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

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

2424
set(LLVM_TARGET_DEFINITIONS FortranVariableInterface.td)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
include "mlir/Dialect/Arith/IR/ArithBase.td"
1818
include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.td"
1919
include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td"
20+
include "mlir/Dialect/OpenMP/OpenMPClauses.td"
2021
include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.td"
2122
include "flang/Optimizer/Dialect/FIRDialect.td"
2223
include "flang/Optimizer/Dialect/FIRTypes.td"
@@ -3570,7 +3571,7 @@ def fir_DoConcurrentLoopOp : fir_Op<"do_concurrent.loop",
35703571
LLVM.
35713572
}];
35723573

3573-
let arguments = (ins
3574+
defvar opArgs = (ins
35743575
Variadic<Index>:$lowerBound,
35753576
Variadic<Index>:$upperBound,
35763577
Variadic<Index>:$step,
@@ -3579,17 +3580,23 @@ def fir_DoConcurrentLoopOp : fir_Op<"do_concurrent.loop",
35793580
OptionalAttr<LoopAnnotationAttr>:$loopAnnotation
35803581
);
35813582

3583+
let arguments = !con(opArgs, OpenMP_PrivateClause.arguments);
3584+
35823585
let regions = (region SizedRegion<1>:$region);
35833586

35843587
let hasCustomAssemblyFormat = 1;
35853588
let hasVerifier = 1;
35863589

3587-
let extraClassDeclaration = [{
3590+
defvar opExtraClassDeclaration = [{
35883591
// Get Number of reduction operands
35893592
unsigned getNumReduceOperands() {
35903593
return getReduceOperands().size();
35913594
}
35923595
}];
3596+
3597+
let extraClassDeclaration =
3598+
!strconcat(opExtraClassDeclaration, "\n",
3599+
OpenMP_PrivateClause.extraClassDeclaration);
35933600
}
35943601

35953602
#endif

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
24592459
nestReduceAttrs.empty()
24602460
? nullptr
24612461
: mlir::ArrayAttr::get(builder->getContext(), nestReduceAttrs),
2462-
nullptr);
2462+
nullptr, /*private_vars=*/std::nullopt, /*private_syms=*/nullptr);
24632463

24642464
llvm::SmallVector<mlir::Type> loopBlockArgTypes(
24652465
incrementLoopNestInfo.size(), builder->getIndexType());

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4952,7 +4952,7 @@ mlir::ParseResult fir::DoConcurrentLoopOp::parse(mlir::OpAsmParser &parser,
49524952
{static_cast<int32_t>(lower.size()),
49534953
static_cast<int32_t>(upper.size()),
49544954
static_cast<int32_t>(steps.size()),
4955-
static_cast<int32_t>(reduceOperands.size())}));
4955+
static_cast<int32_t>(reduceOperands.size()), 0}));
49564956

49574957
// Parse attributes.
49584958
if (parser.parseOptionalAttrDict(result.attributes))

flang/test/Fir/invalid.fir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ func.func @dc_0d() {
11981198

11991199
func.func @dc_invalid_parent(%arg0: index, %arg1: index) {
12001200
// expected-error@+1 {{'fir.do_concurrent.loop' op expects parent op 'fir.do_concurrent'}}
1201-
"fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0>}> ({
1201+
"fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0, 0>}> ({
12021202
^bb0(%arg2: index):
12031203
%tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
12041204
}) : (index, index) -> ()
@@ -1210,7 +1210,7 @@ func.func @dc_invalid_parent(%arg0: index, %arg1: index) {
12101210
func.func @dc_invalid_control(%arg0: index, %arg1: index) {
12111211
// expected-error@+2 {{'fir.do_concurrent.loop' op different number of tuple elements for lowerBound, upperBound or step}}
12121212
fir.do_concurrent {
1213-
"fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0>}> ({
1213+
"fir.do_concurrent.loop"(%arg0, %arg1) <{operandSegmentSizes = array<i32: 1, 1, 0, 0, 0>}> ({
12141214
^bb0(%arg2: index):
12151215
%tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
12161216
}) : (index, index) -> ()
@@ -1223,7 +1223,7 @@ func.func @dc_invalid_control(%arg0: index, %arg1: index) {
12231223
func.func @dc_invalid_ind_var(%arg0: index, %arg1: index) {
12241224
// expected-error@+2 {{'fir.do_concurrent.loop' op expects the same number of induction variables: 2 as bound and step values: 1}}
12251225
fir.do_concurrent {
1226-
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0>}> ({
1226+
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0, 0>}> ({
12271227
^bb0(%arg3: index, %arg4: index):
12281228
%tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
12291229
}) : (index, index, index) -> ()
@@ -1236,7 +1236,7 @@ func.func @dc_invalid_ind_var(%arg0: index, %arg1: index) {
12361236
func.func @dc_invalid_ind_var_type(%arg0: index, %arg1: index) {
12371237
// expected-error@+2 {{'fir.do_concurrent.loop' op expects arguments for the induction variable to be of index type}}
12381238
fir.do_concurrent {
1239-
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0>}> ({
1239+
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0) <{operandSegmentSizes = array<i32: 1, 1, 1, 0, 0>}> ({
12401240
^bb0(%arg3: i32):
12411241
%tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
12421242
}) : (index, index, index) -> ()
@@ -1250,7 +1250,7 @@ func.func @dc_invalid_reduction(%arg0: index, %arg1: index) {
12501250
%sum = fir.alloca i32
12511251
// expected-error@+2 {{'fir.do_concurrent.loop' op mismatch in number of reduction variables and reduction attributes}}
12521252
fir.do_concurrent {
1253-
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0, %sum) <{operandSegmentSizes = array<i32: 1, 1, 1, 1>}> ({
1253+
"fir.do_concurrent.loop"(%arg0, %arg1, %arg0, %sum) <{operandSegmentSizes = array<i32: 1, 1, 1, 1, 0>}> ({
12541254
^bb0(%arg3: index):
12551255
%tmp = "fir.alloca"() <{in_type = i32, operandSegmentSizes = array<i32: 0, 0>}> : () -> !fir.ref<i32>
12561256
}) : (index, index, index, !fir.ref<i32>) -> ()

0 commit comments

Comments
 (0)