@@ -83,8 +83,10 @@ bool ReductionProcessor::supportedIntrinsicProcReduction(
83
83
return redType;
84
84
}
85
85
86
- std::string ReductionProcessor::getReductionName (llvm::StringRef name,
87
- mlir::Type ty, bool isByRef) {
86
+ std::string
87
+ ReductionProcessor::getReductionName (llvm::StringRef name,
88
+ const fir::KindMapping &kindMap,
89
+ mlir::Type ty, bool isByRef) {
88
90
ty = fir::unwrapRefType (ty);
89
91
90
92
// extra string to distinguish reduction functions for variables passed by
@@ -93,47 +95,12 @@ std::string ReductionProcessor::getReductionName(llvm::StringRef name,
93
95
if (isByRef)
94
96
byrefAddition = " _byref" ;
95
97
96
- if (fir::isa_trivial (ty))
97
- return (llvm::Twine (name) +
98
- (ty.isIntOrIndex () ? llvm::Twine (" _i_" ) : llvm::Twine (" _f_" )) +
99
- llvm::Twine (ty.getIntOrFloatBitWidth ()) + byrefAddition)
100
- .str ();
101
-
102
- // creates a name like reduction_i_64_box_ux4x3
103
- if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
104
- // TODO: support for allocatable boxes:
105
- // !fir.box<!fir.heap<!fir.array<...>>>
106
- fir::SequenceType seqTy = fir::unwrapRefType (boxTy.getEleTy ())
107
- .dyn_cast_or_null <fir::SequenceType>();
108
- if (!seqTy)
109
- return {};
110
-
111
- std::string prefix = getReductionName (
112
- name, fir::unwrapSeqOrBoxedSeqType (ty), /* isByRef=*/ false );
113
- if (prefix.empty ())
114
- return {};
115
- std::stringstream tyStr;
116
- tyStr << prefix << " _box_" ;
117
- bool first = true ;
118
- for (std::int64_t extent : seqTy.getShape ()) {
119
- if (first)
120
- first = false ;
121
- else
122
- tyStr << " x" ;
123
- if (extent == seqTy.getUnknownExtent ())
124
- tyStr << ' u' ; // I'm not sure that '?' is safe in symbol names
125
- else
126
- tyStr << extent;
127
- }
128
- return (tyStr.str () + byrefAddition).str ();
129
- }
130
-
131
- return {};
98
+ return fir::getTypeAsString (ty, kindMap, (name + byrefAddition).str ());
132
99
}
133
100
134
101
std::string ReductionProcessor::getReductionName (
135
102
Fortran::parser::DefinedOperator::IntrinsicOperator intrinsicOp,
136
- mlir::Type ty, bool isByRef) {
103
+ const fir::KindMapping &kindMap, mlir::Type ty, bool isByRef) {
137
104
std::string reductionName;
138
105
139
106
switch (intrinsicOp) {
@@ -156,17 +123,17 @@ std::string ReductionProcessor::getReductionName(
156
123
break ;
157
124
}
158
125
159
- return getReductionName (reductionName, ty, isByRef);
126
+ return getReductionName (reductionName, kindMap, ty, isByRef);
160
127
}
161
128
162
129
mlir::Value
163
130
ReductionProcessor::getReductionInitValue (mlir::Location loc, mlir::Type type,
164
131
ReductionIdentifier redId,
165
132
fir::FirOpBuilder &builder) {
166
133
type = fir::unwrapRefType (type);
167
- assert (( fir::isa_integer (type) || fir::isa_real (type) ||
168
- type. isa <fir::LogicalType>()) &&
169
- " only integer, logical and real types are currently supported" );
134
+ if (! fir::isa_integer (type) && ! fir::isa_real (type) &&
135
+ !mlir:: isa<fir::LogicalType>(type))
136
+ TODO (loc, " Reduction of some types is not supported" );
170
137
switch (redId) {
171
138
case ReductionIdentifier::MAX: {
172
139
if (auto ty = type.dyn_cast <mlir::FloatType>()) {
@@ -465,8 +432,7 @@ mlir::omp::ReductionDeclareOp ReductionProcessor::createReductionDecl(
465
432
mlir::OpBuilder::InsertionGuard guard (builder);
466
433
mlir::ModuleOp module = builder.getModule ();
467
434
468
- if (reductionOpName.empty ())
469
- TODO (loc, " Reduction of some types is not supported" );
435
+ assert (!reductionOpName.empty ());
470
436
471
437
auto decl =
472
438
module .lookupSymbol <mlir::omp::ReductionDeclareOp>(reductionOpName);
@@ -607,15 +573,18 @@ void ReductionProcessor::addReductionDecl(
607
573
}
608
574
for (mlir::Value symVal : reductionVars) {
609
575
auto redType = mlir::cast<fir::ReferenceType>(symVal.getType ());
576
+ const auto &kindMap = firOpBuilder.getKindMap ();
610
577
if (redType.getEleTy ().isa <fir::LogicalType>())
611
- decl = createReductionDecl (
612
- firOpBuilder,
613
- getReductionName (intrinsicOp, firOpBuilder.getI1Type (), isByRef),
614
- redId, redType, currentLocation, isByRef);
578
+ decl = createReductionDecl (firOpBuilder,
579
+ getReductionName (intrinsicOp, kindMap,
580
+ firOpBuilder.getI1Type (),
581
+ isByRef),
582
+ redId, redType, currentLocation, isByRef);
615
583
else
616
584
decl = createReductionDecl (
617
- firOpBuilder, getReductionName (intrinsicOp, redType, isByRef),
618
- redId, redType, currentLocation, isByRef);
585
+ firOpBuilder,
586
+ getReductionName (intrinsicOp, kindMap, redType, isByRef), redId,
587
+ redType, currentLocation, isByRef);
619
588
reductionDeclSymbols.push_back (mlir::SymbolRefAttr::get (
620
589
firOpBuilder.getContext (), decl.getSymName ()));
621
590
}
@@ -640,7 +609,7 @@ void ReductionProcessor::addReductionDecl(
640
609
decl = createReductionDecl (
641
610
firOpBuilder,
642
611
getReductionName (getRealName (*reductionIntrinsic).ToString (),
643
- redType, isByRef),
612
+ firOpBuilder. getKindMap (), redType, isByRef),
644
613
redId, redType, currentLocation, isByRef);
645
614
reductionDeclSymbols.push_back (mlir::SymbolRefAttr::get (
646
615
firOpBuilder.getContext (), decl.getSymName ()));
0 commit comments