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