FLANG
HLFIRDialect.h
1//===- HLFIRDialect.h - High Level Fortran IR dialect -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the HLFIR dialect that models Fortran expressions and
10// assignments without requiring storage allocation and manipulations.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef FORTRAN_OPTIMIZER_HLFIR_HLFIRDIALECT_H
15#define FORTRAN_OPTIMIZER_HLFIR_HLFIRDIALECT_H
16
17#include "flang/Optimizer/Dialect/FIRType.h"
18#include "mlir/IR/Dialect.h"
19
20namespace hlfir {
22bool isFortranVariableType(mlir::Type);
23bool isFortranScalarCharacterType(mlir::Type);
24bool isFortranScalarCharacterExprType(mlir::Type);
25bool isFortranArrayCharacterExprType(mlir::Type);
26} // namespace hlfir
27
28#include "flang/Optimizer/HLFIR/HLFIRDialect.h.inc"
29
30#include "flang/Optimizer/HLFIR/HLFIREnums.h.inc"
31
32#define GET_TYPEDEF_CLASSES
33#include "flang/Optimizer/HLFIR/HLFIRTypes.h.inc"
34
35#define GET_ATTRDEF_CLASSES
36#include "flang/Optimizer/HLFIR/HLFIRAttributes.h.inc"
37
38namespace hlfir {
40inline mlir::Type getFortranElementType(mlir::Type type) {
42 fir::unwrapPassByRefType(fir::unwrapRefType(type)));
43 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
44 return exprType.getEleTy();
45 if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
46 return boxCharType.getEleTy();
47 return type;
48}
49
52inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) {
53 type = fir::unwrapPassByRefType(fir::unwrapRefType(type));
54 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type)) {
55 if (exprType.isArray())
56 return fir::SequenceType::get(exprType.getShape(), exprType.getEleTy());
57 return exprType.getEleTy();
58 }
59 if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
60 return boxCharType.getEleTy();
61 return type;
62}
63
66mlir::Type getExprType(mlir::Type variableType);
67
69inline bool isBoxAddressType(mlir::Type type) {
70 type = fir::dyn_cast_ptrEleTy(type);
71 return type && mlir::isa<fir::BaseBoxType>(type);
72}
73
75inline bool isBoxAddressOrValueType(mlir::Type type) {
76 return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(type));
77}
78
79inline bool isPolymorphicType(mlir::Type type) {
80 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
81 return exprType.isPolymorphic();
82 return fir::isPolymorphicType(type);
83}
84
86inline bool isFortranProcedurePointerType(mlir::Type type) {
87 return fir::isBoxProcAddressType(type);
88}
89
90inline bool isFortranPointerObjectType(mlir::Type type) {
91 auto boxTy =
92 llvm::dyn_cast_or_null<fir::BaseBoxType>(fir::dyn_cast_ptrEleTy(type));
93 return boxTy && boxTy.isPointer();
94}
95
98inline bool isFortranProcedureValue(mlir::Type type) {
99 return mlir::isa<fir::BoxProcType>(type) ||
100 (mlir::isa<mlir::TupleType>(type) &&
101 fir::isCharacterProcedureTuple(type, /*acceptRawFunc=*/false));
102}
103
105inline bool isFortranValueType(mlir::Type type) {
106 return mlir::isa<hlfir::ExprType>(type) || fir::isa_trivial(type) ||
107 isFortranProcedureValue(type);
108}
109
111inline bool isFortranValue(mlir::Value value) {
112 return isFortranValueType(value.getType());
113}
114
123inline bool isFortranEntity(mlir::Value value) {
124 return isFortranValue(value) || isFortranVariableType(value.getType());
125}
126
127bool isFortranScalarNumericalType(mlir::Type);
128bool isFortranNumericalArrayObject(mlir::Type);
129bool isFortranNumericalOrLogicalArrayObject(mlir::Type);
130bool isFortranArrayObject(mlir::Type);
131bool isFortranLogicalArrayObject(mlir::Type);
132bool isPassByRefOrIntegerType(mlir::Type);
133bool isI1Type(mlir::Type);
134// scalar i1 or logical, or sequence of logical (via (boxed?) array or expr)
135bool isMaskArgument(mlir::Type);
136bool isPolymorphicObject(mlir::Type);
137
140mlir::Value genExprShape(mlir::OpBuilder &builder, const mlir::Location &loc,
141 const hlfir::ExprType &expr);
142
148bool mayHaveAllocatableComponent(mlir::Type ty);
149
151bool isFortranIntegerScalarOrArrayObject(mlir::Type type);
152
153} // namespace hlfir
154
155#endif // FORTRAN_OPTIMIZER_HLFIR_HLFIRDIALECT_H
mlir::Type unwrapPassByRefType(mlir::Type t)
Definition FIRType.h:289
bool isCharacterProcedureTuple(mlir::Type type, bool acceptRawFunc=true)
Is this tuple type holding a character function and its result length?
Definition FIRType.cpp:1362
mlir::Type dyn_cast_ptrEleTy(mlir::Type t)
Definition FIRType.cpp:247
bool isPolymorphicType(mlir::Type ty)
Definition FIRType.cpp:391
bool isBoxProcAddressType(mlir::Type t)
Is this a fir.boxproc address type?
Definition FIRType.h:517
bool isa_trivial(mlir::Type t)
Definition FIRType.h:214
mlir::Type unwrapSequenceType(mlir::Type t)
If t is a SequenceType return its element type, otherwise return t.
Definition FIRType.h:272