//
//===----------------------------------------------------------------------===//
-#ifndef OPTIMIZER_DIALECT_FIROPSSUPPORT_H
-#define OPTIMIZER_DIALECT_FIROPSSUPPORT_H
+#ifndef FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H
+#define FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H
#include "flang/Optimizer/Dialect/FIROps.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
llvm::StringRef name, mlir::Type type,
llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
+/// Attribute to mark Fortran entities with the CONTIGUOUS attribute.
+constexpr llvm::StringRef getContiguousAttrName() { return "fir.contiguous"; }
+/// Attribute to mark Fortran entities with the OPTIONAL attribute.
+constexpr llvm::StringRef getOptionalAttrName() { return "fir.optional"; }
+
+/// Tell if \p value is:
+/// - a function argument that has attribute \p attributeName
+/// - or, the result of fir.alloca/fir.allocamem op that has attribute \p
+/// attributeName
+/// - or, the result of a fir.address_of of a fir.global that has attribute \p
+/// attributeName
+/// - or, a fir.box loaded from a fir.ref<fir.box> that matches one of the
+/// previous cases.
+bool valueHasFirAttribute(mlir::Value value, llvm::StringRef attributeName);
+
} // namespace fir
-#endif // OPTIMIZER_DIALECT_FIROPSSUPPORT_H
+#endif // FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H
return result;
}
+bool fir::valueHasFirAttribute(mlir::Value value,
+ llvm::StringRef attributeName) {
+ // If this is a fir.box that was loaded, the fir attributes will be on the
+ // related fir.ref<fir.box> creation.
+ if (value.getType().isa<fir::BoxType>())
+ if (auto definingOp = value.getDefiningOp())
+ if (auto loadOp = mlir::dyn_cast<fir::LoadOp>(definingOp))
+ value = loadOp.memref();
+ // If this is a function argument, look in the argument attributes.
+ if (auto blockArg = value.dyn_cast<mlir::BlockArgument>()) {
+ if (blockArg.getOwner() && blockArg.getOwner()->isEntryBlock())
+ if (auto funcOp =
+ mlir::dyn_cast<mlir::FuncOp>(blockArg.getOwner()->getParentOp()))
+ if (funcOp.getArgAttr(blockArg.getArgNumber(), attributeName))
+ return true;
+ return false;
+ }
+
+ if (auto definingOp = value.getDefiningOp()) {
+ // If this is an allocated value, look at the allocation attributes.
+ if (mlir::isa<fir::AllocMemOp>(definingOp) ||
+ mlir::isa<AllocaOp>(definingOp))
+ return definingOp->hasAttr(attributeName);
+ // If this is an imported global, look at AddrOfOp and GlobalOp attributes.
+ // Both operations are looked at because use/host associated variable (the
+ // AddrOfOp) can have ASYNCHRONOUS/VOLATILE attributes even if the ultimate
+ // entity (the globalOp) does not have them.
+ if (auto addressOfOp = mlir::dyn_cast<fir::AddrOfOp>(definingOp)) {
+ if (addressOfOp->hasAttr(attributeName))
+ return true;
+ if (auto module = definingOp->getParentOfType<mlir::ModuleOp>())
+ if (auto globalOp =
+ module.lookupSymbol<fir::GlobalOp>(addressOfOp.symbol()))
+ return globalOp->hasAttr(attributeName);
+ }
+ }
+ // TODO: Construct associated entities attributes. Decide where the fir
+ // attributes must be placed/looked for in this case.
+ return false;
+}
+
// Tablegen operators
#define GET_OP_CLASSES