Skip to content

Commit

Permalink
[flang] Inline hlfir.dot_product. (#123143)
Browse files Browse the repository at this point in the history
Some good results for induct2, where dot_product is applied
to a vector of unknow size and a known 3-element vector:
the inlining ends up generating a 3-iteration loop, which
is then fully unrolled. With late FIR simplification
it is not happening even when the simplified intrinsics
implementation is inlined by LLVM (because the loop bounds
are not known).

This change just follows the current approach to expose
the loops for later worksharing application.
  • Loading branch information
vzakhari authored Jan 16, 2025
1 parent 8fa0f0e commit 9a6433f
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 115 deletions.
6 changes: 6 additions & 0 deletions flang/include/flang/Optimizer/Builder/HLFIRTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
Entity loadElementAt(mlir::Location loc, fir::FirOpBuilder &builder,
Entity entity, mlir::ValueRange oneBasedIndices);

/// Return a vector of extents for the given entity.
/// The function creates new operations, but tries to clean-up
/// after itself.
llvm::SmallVector<mlir::Value>
genExtentsVector(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity);

} // namespace hlfir

#endif // FORTRAN_OPTIMIZER_BUILDER_HLFIRTOOLS_H
12 changes: 12 additions & 0 deletions flang/lib/Optimizer/Builder/HLFIRTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,15 @@ hlfir::Entity hlfir::loadElementAt(mlir::Location loc,
return loadTrivialScalar(loc, builder,
getElementAt(loc, builder, entity, oneBasedIndices));
}

llvm::SmallVector<mlir::Value>
hlfir::genExtentsVector(mlir::Location loc, fir::FirOpBuilder &builder,
hlfir::Entity entity) {
entity = hlfir::derefPointersAndAllocatables(loc, builder, entity);
mlir::Value shape = hlfir::genShape(loc, builder, entity);
llvm::SmallVector<mlir::Value, Fortran::common::maxRank> extents =
hlfir::getExplicitExtentsFromShape(shape, builder);
if (shape.getUses().empty())
shape.getDefiningOp()->erase();
return extents;
}
Loading

0 comments on commit 9a6433f

Please sign in to comment.