@@ -31,57 +31,33 @@ static void checkMapType(mlir::Location location, mlir::Type type) {
31
31
}
32
32
33
33
static mlir::omp::ScheduleModifier
34
- translateScheduleModifier (const omp::clause::Schedule::ModType &m) {
34
+ translateScheduleModifier (const omp::clause::Schedule::OrderingModifier &m) {
35
35
switch (m) {
36
- case omp::clause::Schedule::ModType ::Monotonic:
36
+ case omp::clause::Schedule::OrderingModifier ::Monotonic:
37
37
return mlir::omp::ScheduleModifier::monotonic;
38
- case omp::clause::Schedule::ModType ::Nonmonotonic:
38
+ case omp::clause::Schedule::OrderingModifier ::Nonmonotonic:
39
39
return mlir::omp::ScheduleModifier::nonmonotonic;
40
- case omp::clause::Schedule::ModType::Simd:
41
- return mlir::omp::ScheduleModifier::simd;
42
40
}
43
41
return mlir::omp::ScheduleModifier::none;
44
42
}
45
43
46
44
static mlir::omp::ScheduleModifier
47
45
getScheduleModifier (const omp::clause::Schedule &clause) {
48
- using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
49
- const auto &modifier = std::get<std::optional<ScheduleModifier>>(clause.t );
50
- // The input may have the modifier any order, so we look for one that isn't
51
- // SIMD. If modifier is not set at all, fall down to the bottom and return
52
- // "none".
53
- if (modifier) {
54
- using ModType = omp::clause::Schedule::ModType;
55
- const auto &modType1 = std::get<ModType>(modifier->t );
56
- if (modType1 == ModType::Simd) {
57
- const auto &modType2 = std::get<std::optional<ModType>>(modifier->t );
58
- if (modType2 && *modType2 != ModType::Simd)
59
- return translateScheduleModifier (*modType2);
60
- return mlir::omp::ScheduleModifier::none;
61
- }
62
-
63
- return translateScheduleModifier (modType1);
64
- }
46
+ using Schedule = omp::clause::Schedule;
47
+ const auto &modifier =
48
+ std::get<std::optional<Schedule::OrderingModifier>>(clause.t );
49
+ if (modifier)
50
+ return translateScheduleModifier (*modifier);
65
51
return mlir::omp::ScheduleModifier::none;
66
52
}
67
53
68
54
static mlir::omp::ScheduleModifier
69
55
getSimdModifier (const omp::clause::Schedule &clause) {
70
- using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
71
- const auto &modifier = std::get<std::optional<ScheduleModifier>>(clause.t );
72
- // Either of the two possible modifiers in the input can be the SIMD modifier,
73
- // so look in either one, and return simd if we find one. Not found = return
74
- // "none".
75
- if (modifier) {
76
- using ModType = omp::clause::Schedule::ModType;
77
- const auto &modType1 = std::get<ModType>(modifier->t );
78
- if (modType1 == ModType::Simd)
79
- return mlir::omp::ScheduleModifier::simd;
80
-
81
- const auto &modType2 = std::get<std::optional<ModType>>(modifier->t );
82
- if (modType2 && *modType2 == ModType::Simd)
83
- return mlir::omp::ScheduleModifier::simd;
84
- }
56
+ using Schedule = omp::clause::Schedule;
57
+ const auto &modifier =
58
+ std::get<std::optional<Schedule::ChunkModifier>>(clause.t );
59
+ if (modifier && *modifier == Schedule::ChunkModifier::Simd)
60
+ return mlir::omp::ScheduleModifier::simd;
85
61
return mlir::omp::ScheduleModifier::none;
86
62
}
87
63
@@ -94,53 +70,48 @@ genAllocateClause(Fortran::lower::AbstractConverter &converter,
94
70
mlir::Location currentLocation = converter.getCurrentLocation ();
95
71
Fortran::lower::StatementContext stmtCtx;
96
72
97
- const omp::ObjectList &objectList = std::get<omp::ObjectList>(clause.t );
98
- const auto &modifier =
99
- std::get<std::optional<omp::clause::Allocate::Modifier>>(clause.t );
100
-
101
- // If the allocate modifier is present, check if we only use the allocator
102
- // submodifier. ALIGN in this context is unimplemented
103
- const bool onlyAllocator =
104
- modifier &&
105
- std::holds_alternative<omp::clause::Allocate::Modifier::Allocator>(
106
- modifier->u );
73
+ auto &objects = std::get<omp::ObjectList>(clause.t );
107
74
108
- if (modifier && !onlyAllocator) {
75
+ using Allocate = omp::clause::Allocate;
76
+ // ALIGN in this context is unimplemented
77
+ if (std::get<std::optional<Allocate::AlignModifier>>(clause.t ))
109
78
TODO (currentLocation, " OmpAllocateClause ALIGN modifier" );
110
- }
111
79
112
80
// Check if allocate clause has allocator specified. If so, add it
113
81
// to list of allocators, otherwise, add default allocator to
114
82
// list of allocators.
115
- if (onlyAllocator) {
116
- const auto &value =
117
- std::get<omp::clause::Allocate::Modifier::Allocator>(modifier->u );
118
- mlir::Value operand =
119
- fir::getBase (converter.genExprValue (value.v , stmtCtx));
120
- allocatorOperands.append (objectList.size (), operand);
83
+ using SimpleModifier = Allocate::AllocatorSimpleModifier;
84
+ using ComplexModifier = Allocate::AllocatorComplexModifier;
85
+ if (auto &mod = std::get<std::optional<SimpleModifier>>(clause.t )) {
86
+ mlir::Value operand = fir::getBase (converter.genExprValue (*mod, stmtCtx));
87
+ allocatorOperands.append (objects.size (), operand);
88
+ } else if (auto &mod = std::get<std::optional<ComplexModifier>>(clause.t )) {
89
+ mlir::Value operand = fir::getBase (converter.genExprValue (mod->v , stmtCtx));
90
+ allocatorOperands.append (objects.size (), operand);
121
91
} else {
122
92
mlir::Value operand = firOpBuilder.createIntegerConstant (
123
93
currentLocation, firOpBuilder.getI32Type (), 1 );
124
- allocatorOperands.append (objectList .size (), operand);
94
+ allocatorOperands.append (objects .size (), operand);
125
95
}
126
- genObjectList (objectList, converter, allocateOperands);
96
+
97
+ genObjectList (objects, converter, allocateOperands);
127
98
}
128
99
129
100
static mlir::omp::ClauseProcBindKindAttr
130
101
genProcBindKindAttr (fir::FirOpBuilder &firOpBuilder,
131
102
const omp::clause::ProcBind &clause) {
132
103
mlir::omp::ClauseProcBindKind procBindKind;
133
104
switch (clause.v ) {
134
- case omp::clause::ProcBind::Type ::Master:
105
+ case omp::clause::ProcBind::AffinityPolicy ::Master:
135
106
procBindKind = mlir::omp::ClauseProcBindKind::Master;
136
107
break ;
137
- case omp::clause::ProcBind::Type ::Close:
108
+ case omp::clause::ProcBind::AffinityPolicy ::Close:
138
109
procBindKind = mlir::omp::ClauseProcBindKind::Close;
139
110
break ;
140
- case omp::clause::ProcBind::Type ::Spread:
111
+ case omp::clause::ProcBind::AffinityPolicy ::Spread:
141
112
procBindKind = mlir::omp::ClauseProcBindKind::Spread;
142
113
break ;
143
- case omp::clause::ProcBind::Type ::Primary:
114
+ case omp::clause::ProcBind::AffinityPolicy ::Primary:
144
115
procBindKind = mlir::omp::ClauseProcBindKind::Primary;
145
116
break ;
146
117
}
@@ -150,21 +121,22 @@ genProcBindKindAttr(fir::FirOpBuilder &firOpBuilder,
150
121
151
122
static mlir::omp::ClauseTaskDependAttr
152
123
genDependKindAttr (fir::FirOpBuilder &firOpBuilder,
153
- const omp::clause::Depend &clause ) {
124
+ const omp::clause::Depend::TaskDependenceType kind ) {
154
125
mlir::omp::ClauseTaskDepend pbKind;
155
- const auto &inOut = std::get<omp::clause::Depend::InOut>(clause.u );
156
- switch (std::get<omp::clause::Depend::Type>(inOut.t )) {
157
- case omp::clause::Depend::Type::In:
126
+ switch (kind) {
127
+ case omp::clause::Depend::TaskDependenceType::In:
158
128
pbKind = mlir::omp::ClauseTaskDepend::taskdependin;
159
129
break ;
160
- case omp::clause::Depend::Type ::Out:
130
+ case omp::clause::Depend::TaskDependenceType ::Out:
161
131
pbKind = mlir::omp::ClauseTaskDepend::taskdependout;
162
132
break ;
163
- case omp::clause::Depend::Type ::Inout:
133
+ case omp::clause::Depend::TaskDependenceType ::Inout:
164
134
pbKind = mlir::omp::ClauseTaskDepend::taskdependinout;
165
135
break ;
166
- default :
167
- llvm_unreachable (" unknown parser task dependence type" );
136
+ case omp::clause::Depend::TaskDependenceType::Mutexinoutset:
137
+ case omp::clause::Depend::TaskDependenceType::Inoutset:
138
+ case omp::clause::Depend::TaskDependenceType::Depobj:
139
+ llvm_unreachable (" unhandled parser task dependence type" );
168
140
break ;
169
141
}
170
142
return mlir::omp::ClauseTaskDependAttr::get (firOpBuilder.getContext (),
@@ -295,16 +267,16 @@ bool ClauseProcessor::processDefault() const {
295
267
if (auto *clause = findUniqueClause<omp::clause::Default>()) {
296
268
// Private, Firstprivate, Shared, None
297
269
switch (clause->v ) {
298
- case omp::clause::Default::Type ::Shared:
299
- case omp::clause::Default::Type ::None:
270
+ case omp::clause::Default::DataSharingAttribute ::Shared:
271
+ case omp::clause::Default::DataSharingAttribute ::None:
300
272
// Default clause with shared or none do not require any handling since
301
273
// Shared is the default behavior in the IR and None is only required
302
274
// for semantic checks.
303
275
break ;
304
- case omp::clause::Default::Type ::Private:
276
+ case omp::clause::Default::DataSharingAttribute ::Private:
305
277
// TODO Support default(private)
306
278
break ;
307
- case omp::clause::Default::Type ::Firstprivate:
279
+ case omp::clause::Default::DataSharingAttribute ::Firstprivate:
308
280
// TODO Support default(firstprivate)
309
281
break ;
310
282
}
@@ -337,13 +309,13 @@ bool ClauseProcessor::processDeviceType(
337
309
if (auto *clause = findUniqueClause<omp::clause::DeviceType>()) {
338
310
// Case: declare target ... device_type(any | host | nohost)
339
311
switch (clause->v ) {
340
- case omp::clause::DeviceType::Type ::Nohost:
312
+ case omp::clause::DeviceType::DeviceTypeDescription ::Nohost:
341
313
result = mlir::omp::DeclareTargetDeviceType::nohost;
342
314
break ;
343
- case omp::clause::DeviceType::Type ::Host:
315
+ case omp::clause::DeviceType::DeviceTypeDescription ::Host:
344
316
result = mlir::omp::DeclareTargetDeviceType::host;
345
317
break ;
346
- case omp::clause::DeviceType::Type ::Any:
318
+ case omp::clause::DeviceType::DeviceTypeDescription ::Any:
347
319
result = mlir::omp::DeclareTargetDeviceType::any;
348
320
break ;
349
321
}
@@ -391,7 +363,9 @@ bool ClauseProcessor::processNumTeams(Fortran::lower::StatementContext &stmtCtx,
391
363
// TODO Get lower and upper bounds for num_teams when parser is updated to
392
364
// accept both.
393
365
if (auto *clause = findUniqueClause<omp::clause::NumTeams>()) {
394
- result = fir::getBase (converter.genExprValue (clause->v , stmtCtx));
366
+ // auto lowerBound = std::get<std::optional<ExprTy>>(clause->t);
367
+ auto &upperBound = std::get<ExprTy>(clause->t );
368
+ result = fir::getBase (converter.genExprValue (upperBound, stmtCtx));
395
369
return true ;
396
370
}
397
371
return false ;
@@ -456,24 +430,23 @@ bool ClauseProcessor::processSchedule(
456
430
if (auto *clause = findUniqueClause<omp::clause::Schedule>()) {
457
431
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
458
432
mlir::MLIRContext *context = firOpBuilder.getContext ();
459
- const auto &scheduleType =
460
- std::get<omp::clause::Schedule::ScheduleType>(clause->t );
433
+ const auto &scheduleType = std::get<omp::clause::Schedule::Kind>(clause->t );
461
434
462
435
mlir::omp::ClauseScheduleKind scheduleKind;
463
436
switch (scheduleType) {
464
- case omp::clause::Schedule::ScheduleType ::Static:
437
+ case omp::clause::Schedule::Kind ::Static:
465
438
scheduleKind = mlir::omp::ClauseScheduleKind::Static;
466
439
break ;
467
- case omp::clause::Schedule::ScheduleType ::Dynamic:
440
+ case omp::clause::Schedule::Kind ::Dynamic:
468
441
scheduleKind = mlir::omp::ClauseScheduleKind::Dynamic;
469
442
break ;
470
- case omp::clause::Schedule::ScheduleType ::Guided:
443
+ case omp::clause::Schedule::Kind ::Guided:
471
444
scheduleKind = mlir::omp::ClauseScheduleKind::Guided;
472
445
break ;
473
- case omp::clause::Schedule::ScheduleType ::Auto:
446
+ case omp::clause::Schedule::Kind ::Auto:
474
447
scheduleKind = mlir::omp::ClauseScheduleKind::Auto;
475
448
break ;
476
- case omp::clause::Schedule::ScheduleType ::Runtime:
449
+ case omp::clause::Schedule::Kind ::Runtime:
477
450
scheduleKind = mlir::omp::ClauseScheduleKind::Runtime;
478
451
break ;
479
452
}
@@ -749,13 +722,15 @@ bool ClauseProcessor::processDepend(
749
722
return findRepeatableClause<omp::clause::Depend>(
750
723
[&](const omp::clause::Depend &clause,
751
724
const Fortran::parser::CharBlock &) {
752
- assert (std::holds_alternative<omp::clause::Depend::InOut>(clause.u ) &&
753
- " Only InOut is handled at the moment" );
754
- const auto &inOut = std::get<omp::clause::Depend::InOut>(clause.u );
755
- const auto &objects = std::get<omp::ObjectList>(inOut.t );
725
+ using Depend = omp::clause::Depend;
726
+ assert (std::holds_alternative<Depend::WithLocators>(clause.u ) &&
727
+ " Only the modern form is handled at the moment" );
728
+ auto &modern = std::get<Depend::WithLocators>(clause.u );
729
+ auto kind = std::get<Depend::TaskDependenceType>(modern.t );
730
+ auto &objects = std::get<omp::ObjectList>(modern.t );
756
731
757
732
mlir::omp::ClauseTaskDependAttr dependTypeOperand =
758
- genDependKindAttr (firOpBuilder, clause );
733
+ genDependKindAttr (firOpBuilder, kind );
759
734
dependTypeOperands.append (objects.size (), dependTypeOperand);
760
735
761
736
for (const omp::Object &object : objects) {
@@ -844,39 +819,42 @@ bool ClauseProcessor::processMap(
844
819
const Fortran::parser::CharBlock &source) {
845
820
using Map = omp::clause::Map;
846
821
mlir::Location clauseLocation = converter.genLocation (source);
847
- const auto &oMapType = std::get<std::optional<Map::MapType>>(clause.t );
822
+ const auto &mapType = std::get<std::optional<Map::MapType>>(clause.t );
848
823
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
849
824
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
850
825
// If the map type is specified, then process it else Tofrom is the
851
826
// default.
852
- if (oMapType) {
853
- const Map::MapType::Type &mapType =
854
- std::get<Map::MapType::Type>(oMapType->t );
855
- switch (mapType) {
856
- case Map::MapType::Type::To:
827
+ if (mapType) {
828
+ switch (*mapType) {
829
+ case Map::MapType::To:
857
830
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
858
831
break ;
859
- case Map::MapType::Type:: From:
832
+ case Map::MapType::From:
860
833
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
861
834
break ;
862
- case Map::MapType::Type:: Tofrom:
835
+ case Map::MapType::Tofrom:
863
836
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
864
837
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
865
838
break ;
866
- case Map::MapType::Type:: Alloc:
867
- case Map::MapType::Type:: Release:
839
+ case Map::MapType::Alloc:
840
+ case Map::MapType::Release:
868
841
// alloc and release is the default map_type for the Target Data
869
842
// Ops, i.e. if no bits for map_type is supplied then alloc/release
870
843
// is implicitly assumed based on the target directive. Default
871
844
// value for Target Data and Enter Data is alloc and for Exit Data
872
845
// it is release.
873
846
break ;
874
- case Map::MapType::Type:: Delete:
847
+ case Map::MapType::Delete:
875
848
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
876
849
}
877
850
878
- if (std::get<std::optional<Map::MapType::Always>>(oMapType->t ))
879
- mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
851
+ auto &modTypeMods =
852
+ std::get<std::optional<Map::MapTypeModifiers>>(clause.t );
853
+ if (modTypeMods) {
854
+ if (llvm::is_contained (*modTypeMods, Map::MapTypeModifier::Always))
855
+ mapTypeBits |=
856
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
857
+ }
880
858
} else {
881
859
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
882
860
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
@@ -972,7 +950,7 @@ bool ClauseProcessor::processTo(
972
950
return findRepeatableClause<omp::clause::To>(
973
951
[&](const omp::clause::To &clause, const Fortran::parser::CharBlock &) {
974
952
// Case: declare target to(func, var1, var2)...
975
- gatherFuncAndVarSyms (clause.v ,
953
+ gatherFuncAndVarSyms (std::get<ObjectList>( clause.t ) ,
976
954
mlir::omp::DeclareTargetCaptureClause::to, result);
977
955
});
978
956
}
0 commit comments