Skip to content

Commit 9a6433f

Browse files
authored
[flang] Inline hlfir.dot_product. (#123143)
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.
1 parent 8fa0f0e commit 9a6433f

File tree

4 files changed

+326
-115
lines changed

4 files changed

+326
-115
lines changed

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,12 @@ genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
513513
Entity loadElementAt(mlir::Location loc, fir::FirOpBuilder &builder,
514514
Entity entity, mlir::ValueRange oneBasedIndices);
515515

516+
/// Return a vector of extents for the given entity.
517+
/// The function creates new operations, but tries to clean-up
518+
/// after itself.
519+
llvm::SmallVector<mlir::Value>
520+
genExtentsVector(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity);
521+
516522
} // namespace hlfir
517523

518524
#endif // FORTRAN_OPTIMIZER_BUILDER_HLFIRTOOLS_H

flang/lib/Optimizer/Builder/HLFIRTools.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,3 +1421,15 @@ hlfir::Entity hlfir::loadElementAt(mlir::Location loc,
14211421
return loadTrivialScalar(loc, builder,
14221422
getElementAt(loc, builder, entity, oneBasedIndices));
14231423
}
1424+
1425+
llvm::SmallVector<mlir::Value>
1426+
hlfir::genExtentsVector(mlir::Location loc, fir::FirOpBuilder &builder,
1427+
hlfir::Entity entity) {
1428+
entity = hlfir::derefPointersAndAllocatables(loc, builder, entity);
1429+
mlir::Value shape = hlfir::genShape(loc, builder, entity);
1430+
llvm::SmallVector<mlir::Value, Fortran::common::maxRank> extents =
1431+
hlfir::getExplicitExtentsFromShape(shape, builder);
1432+
if (shape.getUses().empty())
1433+
shape.getDefiningOp()->erase();
1434+
return extents;
1435+
}

0 commit comments

Comments
 (0)