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
19namespace hlfir {
21bool isFortranVariableType(mlir::Type);
22bool isFortranScalarCharacterType(mlir::Type);
23bool isFortranScalarCharacterExprType(mlir::Type);
24bool isFortranArrayCharacterExprType(mlir::Type);
25} // namespace hlfir
26
27#include "flang/Optimizer/HLFIR/HLFIRDialect.h.inc"
28
29#include "flang/Optimizer/HLFIR/HLFIREnums.h.inc"
30
31#define GET_TYPEDEF_CLASSES
32#include "flang/Optimizer/HLFIR/HLFIRTypes.h.inc"
33
34#define GET_ATTRDEF_CLASSES
35#include "flang/Optimizer/HLFIR/HLFIRAttributes.h.inc"
36
37namespace hlfir {
39inline mlir::Type getFortranElementType(mlir::Type type) {
41 fir::unwrapPassByRefType(fir::unwrapRefType(type)));
42 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
43 return exprType.getEleTy();
44 if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
45 return boxCharType.getEleTy();
46 return type;
47}
48
51inline mlir::Type getFortranElementOrSequenceType(mlir::Type type) {
52 type = fir::unwrapPassByRefType(fir::unwrapRefType(type));
53 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type)) {
54 if (exprType.isArray())
55 return fir::SequenceType::get(exprType.getShape(), exprType.getEleTy());
56 return exprType.getEleTy();
57 }
58 if (auto boxCharType = mlir::dyn_cast<fir::BoxCharType>(type))
59 return boxCharType.getEleTy();
60 return type;
61}
62
65mlir::Type getExprType(mlir::Type variableType);
66
71mlir::Type getVariableType(hlfir::ExprType exprType);
72
74inline bool isBoxAddressType(mlir::Type type) {
75 type = fir::dyn_cast_ptrEleTy(type);
76 return type && mlir::isa<fir::BaseBoxType>(type);
77}
78
80inline bool isBoxAddressOrValueType(mlir::Type type) {
81 return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(type));
82}
83
84inline bool isPolymorphicType(mlir::Type type) {
85 if (auto exprType = mlir::dyn_cast<hlfir::ExprType>(type))
86 return exprType.isPolymorphic();
87 return fir::isPolymorphicType(type);
88}
89
91inline bool isFortranProcedurePointerType(mlir::Type type) {
92 return fir::isBoxProcAddressType(type);
93}
94
95inline bool isFortranPointerObjectType(mlir::Type type) {
96 auto boxTy =
97 llvm::dyn_cast_or_null<fir::BaseBoxType>(fir::dyn_cast_ptrEleTy(type));
98 return boxTy && boxTy.isPointer();
99}
100
103inline bool isFortranProcedureValue(mlir::Type type) {
104 return mlir::isa<fir::BoxProcType>(type) ||
105 (mlir::isa<mlir::TupleType>(type) &&
106 fir::isCharacterProcedureTuple(type, /*acceptRawFunc=*/false));
107}
108
110inline bool isFortranValueType(mlir::Type type) {
111 return mlir::isa<hlfir::ExprType>(type) || fir::isa_trivial(type) ||
112 isFortranProcedureValue(type);
113}
114
116inline bool isFortranValue(mlir::Value value) {
117 return isFortranValueType(value.getType());
118}
119
128inline bool isFortranEntity(mlir::Value value) {
129 return isFortranValue(value) || isFortranVariableType(value.getType());
130}
131
132bool isFortranScalarNumericalType(mlir::Type);
133bool isFortranNumericalArrayObject(mlir::Type);
134bool isFortranNumericalOrLogicalArrayObject(mlir::Type);
135bool isFortranArrayObject(mlir::Type);
136bool isFortranLogicalArrayObject(mlir::Type);
137bool isPassByRefOrIntegerType(mlir::Type);
138bool isI1Type(mlir::Type);
139// scalar i1 or logical, or sequence of logical (via (boxed?) array or expr)
140bool isMaskArgument(mlir::Type);
141bool isPolymorphicObject(mlir::Type);
142
145mlir::Value genExprShape(mlir::OpBuilder &builder, const mlir::Location &loc,
146 const hlfir::ExprType &expr);
147
153bool mayHaveAllocatableComponent(mlir::Type ty);
154
156bool isFortranIntegerScalarOrArrayObject(mlir::Type type);
157
158} // namespace hlfir
159
160#endif // FORTRAN_OPTIMIZER_HLFIR_HLFIRDIALECT_H
mlir::Type unwrapPassByRefType(mlir::Type t)
Definition FIRType.h:314
bool isCharacterProcedureTuple(mlir::Type type, bool acceptRawFunc=true)
Is this tuple type holding a character function and its result length?
Definition FIRType.cpp:1440
mlir::Type dyn_cast_ptrEleTy(mlir::Type t)
Definition FIRType.cpp:257
bool isPolymorphicType(mlir::Type ty)
Definition FIRType.cpp:410
bool isBoxProcAddressType(mlir::Type t)
Is this a fir.boxproc address type?
Definition FIRType.h:546
bool isa_trivial(mlir::Type t)
Definition FIRType.h:239
mlir::Type unwrapSequenceType(mlir::Type t)
If t is a SequenceType return its element type, otherwise return t.
Definition FIRType.h:297