9#ifndef FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H
10#define FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H
12#include "flang/Optimizer/Dialect/FIROps.h"
13#include "mlir/Dialect/Func/IR/FuncOps.h"
14#include "mlir/IR/BuiltinOps.h"
15#include "llvm/ADT/APInt.h"
28 mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
30 for (mlir::Type t : type) {
32 effects.emplace_back(mlir::MemoryEffects::Read::get(),
33 fir::VolatileMemoryResource::get());
34 effects.emplace_back(mlir::MemoryEffects::Write::get(),
35 fir::VolatileMemoryResource::get());
43 return mlir::isa<fir::CallOp>(op) || mlir::isa<fir::DispatchOp>(op) ||
44 mlir::isa<mlir::func::CallOp>(op) ||
45 mlir::isa<mlir::func::CallIndirectOp>(op);
54 return op &&
isaCall(op) && !op->getAttr(
"pure");
63 return op &&
isaCall(op) && op->getAttr(
"pure");
71mlir::func::FuncOp
createFuncOp(mlir::Location loc, mlir::ModuleOp module,
72 llvm::StringRef name, mlir::FunctionType type,
74 const mlir::SymbolTable *symbolTable =
nullptr);
78fir::GlobalOp
createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
79 llvm::StringRef name, mlir::Type type,
80 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
81 const mlir::SymbolTable *symbolTable =
nullptr);
90static constexpr llvm::StringRef getTargetAttrName() {
return "fir.target"; }
93static constexpr llvm::StringRef getAsynchronousAttrName() {
94 return "fir.asynchronous";
98static constexpr llvm::StringRef getVolatileAttrName() {
99 return "fir.volatile";
108static constexpr llvm::StringRef getReadOnlyAttrName() {
109 return "fir.read_only";
114static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {
115 return "fir.char_proc";
119static constexpr llvm::StringRef getSymbolAttrName() {
120 return "fir.bindc_name";
124static constexpr llvm::StringRef getHostAssocAttrName() {
125 return "fir.host_assoc";
129static constexpr llvm::StringRef getHostSymbolAttrName() {
130 return "fir.host_symbol";
137static constexpr llvm::StringRef getDefiningSubmoduleAttrName() {
138 return "fir.defining_submodule";
143static constexpr llvm::StringRef getInternalFuncNameAttrName() {
144 return "fir.internal_name";
149static constexpr llvm::StringRef getHasLifetimeMarkerAttrName() {
150 return "fir.has_lifetime";
154static constexpr llvm::StringRef getAccessGroupsAttrName() {
155 return "access_groups";
162static constexpr llvm::StringRef getUniqNameAttrName() {
return "uniq_name"; }
175 return func->hasAttr(fir::getHostSymbolAttrName());
209static constexpr llvm::StringRef getAdaptToByRefAttrName() {
210 return "adapt.valuebyref";
213static constexpr llvm::StringRef getFuncPureAttrName() {
214 return "fir.func_pure";
217static constexpr llvm::StringRef getFuncElementalAttrName() {
218 return "fir.func_elemental";
221static constexpr llvm::StringRef getFuncRecursiveAttrName() {
222 return "fir.func_recursive";
225static constexpr llvm::StringRef getFortranProcedureFlagsAttrName() {
226 return "fir.proc_attrs";
234template <
typename Builder>
235inline mlir::NamedAttribute getAdaptToByRefAttr(Builder &builder) {
236 return {mlir::StringAttr::get(builder.getContext(),
237 fir::getAdaptToByRefAttrName()),
238 builder.getUnitAttr()};
241bool isDummyArgument(mlir::Value v);
243template <fir::FortranProcedureFlagsEnum Flag>
244inline bool hasProcedureAttr(fir::FortranProcedureFlagsEnumAttr flags) {
245 return flags && bitEnumContainsAny(flags.getValue(), Flag);
248template <fir::FortranProcedureFlagsEnum Flag>
249inline bool hasProcedureAttr(mlir::Operation *op) {
250 if (
auto firCallOp = mlir::dyn_cast<fir::CallOp>(op))
251 return hasProcedureAttr<Flag>(firCallOp.getProcedureAttrsAttr());
252 if (
auto firCallOp = mlir::dyn_cast<fir::DispatchOp>(op))
253 return hasProcedureAttr<Flag>(firCallOp.getProcedureAttrsAttr());
254 return hasProcedureAttr<Flag>(
255 op->getAttrOfType<fir::FortranProcedureFlagsEnumAttr>(
256 getFortranProcedureFlagsAttrName()));
259inline bool hasBindcAttr(mlir::Operation *op) {
260 return hasProcedureAttr<fir::FortranProcedureFlagsEnum::bind_c>(op);
266 const mlir::DataLayout &dl,
267 const fir::KindMapping &kindMap);
278 bool mayHaveNonDefaultLowerBounds =
true,
279 bool checkWhole =
true);
Definition AbstractConverter.h:37
constexpr llvm::StringRef getCorankAttrName()
Attribute to mark coarray Fortran entities with the CORANK attribute.
Definition FIROpsSupport.h:165
bool isContiguousEmbox(fir::EmboxOp embox, bool checkWhole=true)
Definition FIROps.cpp:2856
bool anyFuncArgsHaveAttr(mlir::func::FuncOp func, llvm::StringRef attr)
Definition FIROps.cpp:6161
bool isa_volatile_type(mlir::Type t)
Definition FIRType.cpp:768
constexpr llvm::StringRef getContiguousAttrName()
Attribute to mark Fortran entities with the CONTIGUOUS attribute.
Definition FIROpsSupport.h:84
bool reboxPreservesContinuity(fir::ReboxOp rebox, bool mayHaveNonDefaultLowerBounds=true, bool checkWhole=true)
Definition FIROps.cpp:6233
fir::GlobalOp createGlobalOp(mlir::Location loc, mlir::ModuleOp module, llvm::StringRef name, mlir::Type type, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, const mlir::SymbolTable *symbolTable=nullptr)
Definition FIROps.cpp:6025
bool hasHostAssociationArgument(mlir::func::FuncOp func)
Definition FIROps.cpp:6045
std::optional< int64_t > getAllocaByteSize(fir::AllocaOp alloca, const mlir::DataLayout &dl, const fir::KindMapping &kindMap)
Definition FIROps.cpp:6250
bool isInternalProcedure(mlir::func::FuncOp func)
Definition FIROpsSupport.h:174
std::optional< llvm::APInt > getIntIfConstant(mlir::Value value)
Unwrap an integer constant from an mlir::Value as an APInt.
Definition FIROps.cpp:6168
constexpr llvm::StringRef getOptionalAttrName()
Attribute to mark Fortran entities with the OPTIONAL attribute.
Definition FIROpsSupport.h:87
bool pureCall(mlir::Operation *op)
Definition FIROpsSupport.h:60
void addVolatileMemoryEffects(mlir::TypeRange type, llvm::SmallVectorImpl< mlir::SideEffects::EffectInstance< mlir::MemoryEffects::Effect > > &effects)
Definition FIROpsSupport.h:25
bool valueHasFirAttribute(mlir::Value value, llvm::StringRef attributeName)
Definition FIROps.cpp:6154
bool valueMayHaveFirAttributes(mlir::Value value, llvm::ArrayRef< llvm::StringRef > attributeNames)
Definition FIROps.cpp:6147
bool impureCall(mlir::Operation *op)
Definition FIROpsSupport.h:51
bool isaCall(mlir::Operation *op)
Return true iff the Operation is a call.
Definition FIROpsSupport.h:42
mlir::func::FuncOp createFuncOp(mlir::Location loc, mlir::ModuleOp module, llvm::StringRef name, mlir::FunctionType type, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, const mlir::SymbolTable *symbolTable=nullptr)
Definition FIROps.cpp:6003