[flang-commits] [flang] [flang] Implement !DIR$ IVDEP directive (PR #133728)
Asher Mancinelli via flang-commits
flang-commits at lists.llvm.org
Wed Apr 2 07:06:16 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);
+ }
+ }
+ }
+ }
+ }
+ }
----------------
ashermancinelli wrote:
Is `walk()` what you were looking for?
```
doLoop.walk([&] (auto *op) {
if (mlir::isa<StoreOp, LoadOp, CallOp>(op))
// ...
});
// or
doLoop.walk([&] (hlfir::AssignOp assignOp) {
// ...
});
```
https://github.com/llvm/llvm-project/pull/133728
More information about the flang-commits
mailing list