[llvm-branch-commits] [flang] [flang][OpenMP] lower simple array reductions (PR #84958)
Tom Eccles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Mar 18 04:03:56 PDT 2024
================
@@ -92,10 +93,42 @@ std::string ReductionProcessor::getReductionName(llvm::StringRef name,
if (isByRef)
byrefAddition = "_byref";
- return (llvm::Twine(name) +
- (ty.isIntOrIndex() ? llvm::Twine("_i_") : llvm::Twine("_f_")) +
- llvm::Twine(ty.getIntOrFloatBitWidth()) + byrefAddition)
- .str();
+ if (fir::isa_trivial(ty))
+ return (llvm::Twine(name) +
+ (ty.isIntOrIndex() ? llvm::Twine("_i_") : llvm::Twine("_f_")) +
+ llvm::Twine(ty.getIntOrFloatBitWidth()) + byrefAddition)
+ .str();
+
+ // creates a name like reduction_i_64_box_ux4x3
+ if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
+ // TODO: support for allocatable boxes:
+ // !fir.box<!fir.heap<!fir.array<...>>>
+ fir::SequenceType seqTy = fir::unwrapRefType(boxTy.getEleTy())
+ .dyn_cast_or_null<fir::SequenceType>();
+ if (!seqTy)
+ return {};
+
+ std::string prefix = getReductionName(
+ name, fir::unwrapSeqOrBoxedSeqType(ty), /*isByRef=*/false);
+ if (prefix.empty())
+ return {};
+ std::stringstream tyStr;
+ tyStr << prefix << "_box_";
+ bool first = true;
+ for (std::int64_t extent : seqTy.getShape()) {
+ if (first)
+ first = false;
+ else
+ tyStr << "x";
+ if (extent == seqTy.getUnknownExtent())
+ tyStr << 'u'; // I'm not sure that '?' is safe in symbol names
+ else
+ tyStr << extent;
+ }
+ return (tyStr.str() + byrefAddition).str();
+ }
+
+ return {};
----------------
tblah wrote:
Yeah that looks much better, thanks! I will do it in a separate patch because I think it might change existing names.
https://github.com/llvm/llvm-project/pull/84958
More information about the llvm-branch-commits
mailing list