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"
26 llvm::SmallVectorImpl<
27 mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
29 for (mlir::Type t : type) {
31 effects.emplace_back(mlir::MemoryEffects::Read::get(),
32 fir::VolatileMemoryResource::get());
33 effects.emplace_back(mlir::MemoryEffects::Write::get(),
34 fir::VolatileMemoryResource::get());
42 return mlir::isa<fir::CallOp>(op) || mlir::isa<fir::DispatchOp>(op) ||
43 mlir::isa<mlir::func::CallOp>(op) ||
44 mlir::isa<mlir::func::CallIndirectOp>(op);
53 return op &&
isaCall(op) && !op->getAttr(
"pure");
62 return op &&
isaCall(op) && op->getAttr(
"pure");
70mlir::func::FuncOp
createFuncOp(mlir::Location loc, mlir::ModuleOp module,
71 llvm::StringRef name, mlir::FunctionType type,
73 const mlir::SymbolTable *symbolTable =
nullptr);
77fir::GlobalOp
createGlobalOp(mlir::Location loc, mlir::ModuleOp module,
78 llvm::StringRef name, mlir::Type type,
79 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
80 const mlir::SymbolTable *symbolTable =
nullptr);
89static constexpr llvm::StringRef getTargetAttrName() {
return "fir.target"; }
92static constexpr llvm::StringRef getAsynchronousAttrName() {
93 return "fir.asynchronous";
97static constexpr llvm::StringRef getVolatileAttrName() {
98 return "fir.volatile";
103static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {
104 return "fir.char_proc";
108static constexpr llvm::StringRef getSymbolAttrName() {
109 return "fir.bindc_name";
113static constexpr llvm::StringRef getHostAssocAttrName() {
114 return "fir.host_assoc";
118static constexpr llvm::StringRef getHostSymbolAttrName() {
119 return "fir.host_symbol";
124static constexpr llvm::StringRef getInternalFuncNameAttrName() {
125 return "fir.internal_name";
130static constexpr llvm::StringRef getHasLifetimeMarkerAttrName() {
131 return "fir.has_lifetime";
142 return func->hasAttr(fir::getHostSymbolAttrName());
176static constexpr llvm::StringRef getAdaptToByRefAttrName() {
177 return "adapt.valuebyref";
180static constexpr llvm::StringRef getFuncPureAttrName() {
181 return "fir.func_pure";
184static constexpr llvm::StringRef getFuncElementalAttrName() {
185 return "fir.func_elemental";
188static constexpr llvm::StringRef getFuncRecursiveAttrName() {
189 return "fir.func_recursive";
192static constexpr llvm::StringRef getFortranProcedureFlagsAttrName() {
193 return "fir.proc_attrs";
201template <
typename Builder>
202inline mlir::NamedAttribute getAdaptToByRefAttr(Builder &builder) {
203 return {mlir::StringAttr::get(builder.getContext(),
204 fir::getAdaptToByRefAttrName()),
205 builder.getUnitAttr()};
208bool isDummyArgument(mlir::Value v);
210template <fir::FortranProcedureFlagsEnum Flag>
211inline bool hasProcedureAttr(fir::FortranProcedureFlagsEnumAttr flags) {
212 return flags && bitEnumContainsAny(flags.getValue(), Flag);
215template <fir::FortranProcedureFlagsEnum Flag>
216inline bool hasProcedureAttr(mlir::Operation *op) {
217 if (
auto firCallOp = mlir::dyn_cast<fir::CallOp>(op))
218 return hasProcedureAttr<Flag>(firCallOp.getProcedureAttrsAttr());
219 if (
auto firCallOp = mlir::dyn_cast<fir::DispatchOp>(op))
220 return hasProcedureAttr<Flag>(firCallOp.getProcedureAttrsAttr());
221 return hasProcedureAttr<Flag>(
222 op->getAttrOfType<fir::FortranProcedureFlagsEnumAttr>(
223 getFortranProcedureFlagsAttrName()));
226inline bool hasBindcAttr(mlir::Operation *op) {
227 return hasProcedureAttr<fir::FortranProcedureFlagsEnum::bind_c>(op);
233 const mlir::DataLayout &dl,
234 const fir::KindMapping &kindMap);
245 bool mayHaveNonDefaultLowerBounds =
true,
246 bool checkWhole =
true);
Definition AbstractConverter.h:34
bool isContiguousEmbox(fir::EmboxOp embox, bool checkWhole=true)
Definition FIROps.cpp:2057
bool anyFuncArgsHaveAttr(mlir::func::FuncOp func, llvm::StringRef attr)
Definition FIROps.cpp:4851
bool isa_volatile_type(mlir::Type t)
Definition FIRType.cpp:741
constexpr llvm::StringRef getContiguousAttrName()
Attribute to mark Fortran entities with the CONTIGUOUS attribute.
Definition FIROpsSupport.h:83
bool reboxPreservesContinuity(fir::ReboxOp rebox, bool mayHaveNonDefaultLowerBounds=true, bool checkWhole=true)
Definition FIROps.cpp:4923
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:4723
bool hasHostAssociationArgument(mlir::func::FuncOp func)
Definition FIROps.cpp:4743
std::optional< int64_t > getAllocaByteSize(fir::AllocaOp alloca, const mlir::DataLayout &dl, const fir::KindMapping &kindMap)
Definition FIROps.cpp:4940
bool isInternalProcedure(mlir::func::FuncOp func)
Definition FIROpsSupport.h:141
constexpr llvm::StringRef getOptionalAttrName()
Attribute to mark Fortran entities with the OPTIONAL attribute.
Definition FIROpsSupport.h:86
bool pureCall(mlir::Operation *op)
Definition FIROpsSupport.h:59
void addVolatileMemoryEffects(mlir::TypeRange type, llvm::SmallVectorImpl< mlir::SideEffects::EffectInstance< mlir::MemoryEffects::Effect > > &effects)
Definition FIROpsSupport.h:24
std::optional< std::int64_t > getIntIfConstant(mlir::Value value)
Unwrap integer constant from an mlir::Value.
Definition FIROps.cpp:4858
bool valueHasFirAttribute(mlir::Value value, llvm::StringRef attributeName)
Definition FIROps.cpp:4844
bool valueMayHaveFirAttributes(mlir::Value value, llvm::ArrayRef< llvm::StringRef > attributeNames)
Definition FIROps.cpp:4837
bool impureCall(mlir::Operation *op)
Definition FIROpsSupport.h:50
bool isaCall(mlir::Operation *op)
Return true iff the Operation is a call.
Definition FIROpsSupport.h:41
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:4701