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
87inline bool isFortranProcedureValue(mlir::Type type) {
88 return mlir::isa<fir::BoxProcType>(type) ||
89 (mlir::isa<mlir::TupleType>(type) &&
90 fir::isCharacterProcedureTuple(type, /*acceptRawFunc=*/false));
91}
92
94inline bool isFortranValueType(mlir::Type type) {
95 return mlir::isa<hlfir::ExprType>(type) || fir::isa_trivial(type) ||
96 isFortranProcedureValue(type);
97}
98
100inline bool isFortranValue(mlir::Value value) {
101 return isFortranValueType(value.getType());
102}
103
112inline bool isFortranEntity(mlir::Value value) {
113 return isFortranValue(value) || isFortranVariableType(value.getType());
114}
115
116bool isFortranScalarNumericalType(mlir::Type);
117bool isFortranNumericalArrayObject(mlir::Type);
118bool isFortranNumericalOrLogicalArrayObject(mlir::Type);
119bool isFortranArrayObject(mlir::Type);
120bool isFortranLogicalArrayObject(mlir::Type);
121bool isPassByRefOrIntegerType(mlir::Type);
122bool isI1Type(mlir::Type);
123// scalar i1 or logical, or sequence of logical (via (boxed?) array or expr)
124bool isMaskArgument(mlir::Type);
125bool isPolymorphicObject(mlir::Type);
126
129mlir::Value genExprShape(mlir::OpBuilder &builder, const mlir::Location &loc,
130 const hlfir::ExprType &expr);
131
137bool mayHaveAllocatableComponent(mlir::Type ty);
138
140bool isFortranIntegerScalarOrArrayObject(mlir::Type type);
141
142} // namespace hlfir
143
144#endif // FORTRAN_OPTIMIZER_HLFIR_HLFIRDIALECT_H
mlir::Type unwrapPassByRefType(mlir::Type t)
Definition: FIRType.h:266
bool isCharacterProcedureTuple(mlir::Type type, bool acceptRawFunc=true)
Is this tuple type holding a character function and its result length?
Definition: FIRType.cpp:1230
mlir::Type dyn_cast_ptrEleTy(mlir::Type t)
Definition: FIRType.cpp:216
bool isPolymorphicType(mlir::Type ty)
Definition: FIRType.cpp:358
bool isa_trivial(mlir::Type t)
Definition: FIRType.h:195
mlir::Type unwrapSequenceType(mlir::Type t)
If t is a SequenceType return its element type, otherwise return t.
Definition: FIRType.h:249