[PATCH] D97502: [flang][fir] Upstream utility function valueHasFirAttribute()
Eric Schweitz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 26 18:32:03 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac473bb2b2ad: [flang][fir] Upstream utility function valueHasFirAttribute() (authored by schweitz).
Changed prior to commit:
https://reviews.llvm.org/D97502?vs=326512&id=326867#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97502/new/
https://reviews.llvm.org/D97502
Files:
flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
flang/lib/Optimizer/Dialect/FIROps.cpp
Index: flang/lib/Optimizer/Dialect/FIROps.cpp
===================================================================
--- flang/lib/Optimizer/Dialect/FIROps.cpp
+++ flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1966,6 +1966,47 @@
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
Index: flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
===================================================================
--- flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
+++ flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#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"
@@ -59,6 +59,21 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97502.326867.patch
Type: text/x-patch
Size: 3949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210227/ebc8f12f/attachment.bin>
More information about the llvm-commits
mailing list