Skip to content

[flang] Generalized simplification of HLFIR reduction ops. #136071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flang/include/flang/Optimizer/Builder/HLFIRTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ mlir::Value genExtent(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Value genLBound(mlir::Location loc, fir::FirOpBuilder &builder,
hlfir::Entity entity, unsigned dim);

/// Compute the lower bounds of \p entity, which is an array of known rank.
llvm::SmallVector<mlir::Value> genLBounds(mlir::Location loc,
fir::FirOpBuilder &builder,
hlfir::Entity entity);

/// Generate a vector of extents with index type from a fir.shape
/// of fir.shape_shift value.
llvm::SmallVector<mlir::Value> getIndexExtents(mlir::Location loc,
Expand Down
27 changes: 27 additions & 0 deletions flang/lib/Optimizer/Builder/HLFIRTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,33 @@ mlir::Value hlfir::genLBound(mlir::Location loc, fir::FirOpBuilder &builder,
return dimInfo.getLowerBound();
}

llvm::SmallVector<mlir::Value> hlfir::genLBounds(mlir::Location loc,
fir::FirOpBuilder &builder,
hlfir::Entity entity) {
assert(!entity.isAssumedRank() &&
"cannot compute all lower bounds for assumed rank");
assert(!entity.isScalar() && "expected an array entity");
int rank = entity.getRank();
mlir::Type idxTy = builder.getIndexType();
if (!entity.mayHaveNonDefaultLowerBounds())
return {static_cast<std::size_t>(rank),
builder.createIntegerConstant(loc, idxTy, 1)};

if (auto shape = tryRetrievingShapeOrShift(entity)) {
auto lbounds = getExplicitLboundsFromShape(shape);
if (!lbounds.empty())
return lbounds;
}

if (entity.isMutableBox())
entity = hlfir::derefPointersAndAllocatables(loc, builder, entity);

llvm::SmallVector<mlir::Value, Fortran::common::maxRank> lbounds;
fir::factory::genDimInfoFromBox(builder, loc, entity, &lbounds,
/*extents=*/nullptr, /*strides=*/nullptr);
return lbounds;
}

void hlfir::genLengthParameters(mlir::Location loc, fir::FirOpBuilder &builder,
Entity entity,
llvm::SmallVectorImpl<mlir::Value> &result) {
Expand Down
465 changes: 0 additions & 465 deletions flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp

Large diffs are not rendered by default.

Loading
Loading