[flang-commits] [flang] [flang] Implement !DIR$ IVDEP directive (PR #133728)
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Mon Mar 31 09:46:57 PDT 2025
================
@@ -2046,6 +2046,37 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// so no clean-up needs to be generated for these entities.
}
+ // Add attribute(s) on operations in fir::DoLoopOp if necessary.
+ void attachAttributesToDoLoopOperations(fir::DoLoopOp &doLoop) {
+ if (!doLoop.getOperation())
+ return;
+ if (auto loopAnnotAttr = doLoop.getLoopAnnotationAttr()) {
+ if (loopAnnotAttr.getParallelAccesses().size()) {
+ mlir::LLVM::AccessGroupAttr accessGroupAttr =
+ loopAnnotAttr.getParallelAccesses().front();
+ for (mlir::Block &block : doLoop.getRegion()) {
+ mlir::ArrayAttr attrs =
+ mlir::ArrayAttr::get(builder->getContext(), {accessGroupAttr});
+ for (mlir::Operation &op : block.getOperations()) {
+ if (fir::StoreOp storeOp = mlir::dyn_cast<fir::StoreOp>(op)) {
+ storeOp.setAccessGroupsAttr(attrs);
+ } else if (fir::LoadOp loadOp = mlir::dyn_cast<fir::LoadOp>(op)) {
+ loadOp.setAccessGroupsAttr(attrs);
+ } else if (hlfir::AssignOp assignOp =
+ mlir::dyn_cast<hlfir::AssignOp>(op)) {
+ // In some loops, the HLFIR AssignOp operation can be translated
+ // into FIR operation(s) containing StoreOp. It is therefore
+ // necessary to forward the AccessGroups attribute.
+ assignOp.getOperation()->setAttr("access_groups", attrs);
+ } else if (fir::CallOp callOp = mlir::dyn_cast<fir::CallOp>(op)) {
+ callOp.setAccessGroupsAttr(attrs);
+ }
+ }
+ }
+ }
+ }
+ }
----------------
kiranchandramohan wrote:
Do we need to go into operations that are nested inside other operations?
```
subroutine sb(A)
integer, intent(inout) :: A(:)
integer :: i
!dir$ ivdep
do i=1,100
if (i .gt. 10) then
A(i) = A(i) + i
end if
end do
end subroutine
```
https://github.com/llvm/llvm-project/pull/133728
More information about the flang-commits
mailing list