FLANG

FIRAttr.h
1 //===-- Optimizer/Dialect/FIRAttr.h -- FIR attributes -----------*- 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 #ifndef OPTIMIZER_DIALECT_FIRATTR_H
10 #define OPTIMIZER_DIALECT_FIRATTR_H
11
12 #include "mlir/IR/Attributes.h"
13
14 namespace mlir {
15 class DialectAsmParser;
16 class DialectAsmPrinter;
17 } // namespace mlir
18
19 namespace fir {
20
21 class FIROpsDialect;
22
23 namespace detail {
24 struct RealAttributeStorage;
25 struct TypeAttributeStorage;
26 } // namespace detail
27
28 enum AttributeKind {
29 FIR_ATTR = mlir::Attribute::FIRST_FIR_ATTR,
30 FIR_EXACTTYPE, // instance_of, precise type relation
31 FIR_SUBCLASS, // subsumed_by, is-a (subclass) relation
32 FIR_POINT,
33 FIR_CLOSEDCLOSED_INTERVAL,
34 FIR_OPENCLOSED_INTERVAL,
35 FIR_CLOSEDOPEN_INTERVAL,
36 FIR_REAL_ATTR,
37 };
38
39 class ExactTypeAttr
40 : public mlir::Attribute::AttrBase<ExactTypeAttr, mlir::Attribute,
41 detail::TypeAttributeStorage> {
42 public:
43 using Base::Base;
44 using ValueType = mlir::Type;
45
46 static constexpr llvm::StringRef getAttrName() { return "instance"; }
47 static ExactTypeAttr get(mlir::Type value);
48
49 mlir::Type getType() const;
50
51 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
52 static constexpr unsigned getId() { return AttributeKind::FIR_EXACTTYPE; }
53 };
54
55 class SubclassAttr
56 : public mlir::Attribute::AttrBase<SubclassAttr, mlir::Attribute,
57 detail::TypeAttributeStorage> {
58 public:
59 using Base::Base;
60 using ValueType = mlir::Type;
61
62 static constexpr llvm::StringRef getAttrName() { return "subsumed"; }
63 static SubclassAttr get(mlir::Type value);
64
65 mlir::Type getType() const;
66
67 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
68 static constexpr unsigned getId() { return AttributeKind::FIR_SUBCLASS; }
69 };
70
71 // Attributes for building SELECT CASE multiway branches
72
77 class ClosedIntervalAttr
78 : public mlir::Attribute::AttrBase<ClosedIntervalAttr, mlir::Attribute,
79 mlir::AttributeStorage> {
80 public:
81 using Base::Base;
82
83 static constexpr llvm::StringRef getAttrName() { return "interval"; }
84 static ClosedIntervalAttr get(mlir::MLIRContext *ctxt);
85 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
86 static constexpr unsigned getId() {
87 return AttributeKind::FIR_CLOSEDCLOSED_INTERVAL;
88 }
89 };
90
95 class UpperBoundAttr
96 : public mlir::Attribute::AttrBase<UpperBoundAttr, mlir::Attribute,
97 mlir::AttributeStorage> {
98 public:
99 using Base::Base;
100
101 static constexpr llvm::StringRef getAttrName() { return "upper"; }
102 static UpperBoundAttr get(mlir::MLIRContext *ctxt);
103 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
104 static constexpr unsigned getId() {
105 return AttributeKind::FIR_OPENCLOSED_INTERVAL;
106 }
107 };
108
113 class LowerBoundAttr
114 : public mlir::Attribute::AttrBase<LowerBoundAttr, mlir::Attribute,
115 mlir::AttributeStorage> {
116 public:
117 using Base::Base;
118
119 static constexpr llvm::StringRef getAttrName() { return "lower"; }
120 static LowerBoundAttr get(mlir::MLIRContext *ctxt);
121 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
122 static constexpr unsigned getId() {
123 return AttributeKind::FIR_CLOSEDOPEN_INTERVAL;
124 }
125 };
126
131 class PointIntervalAttr
132 : public mlir::Attribute::AttrBase<PointIntervalAttr, mlir::Attribute,
133 mlir::AttributeStorage> {
134 public:
135 using Base::Base;
136
137 static constexpr llvm::StringRef getAttrName() { return "point"; }
138 static PointIntervalAttr get(mlir::MLIRContext *ctxt);
139 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
140 static constexpr unsigned getId() { return AttributeKind::FIR_POINT; }
141 };
142
147 class RealAttr
148 : public mlir::Attribute::AttrBase<RealAttr, mlir::Attribute,
149 detail::RealAttributeStorage> {
150 public:
151 using Base::Base;
152 using ValueType = std::pair<int, llvm::APFloat>;
153
154 static constexpr llvm::StringRef getAttrName() { return "real"; }
155 static RealAttr get(mlir::MLIRContext *ctxt, const ValueType &key);
156
157 int getFKind() const;
158 llvm::APFloat getValue() const;
159
160 static constexpr bool kindof(unsigned kind) { return kind == getId(); }
161 static constexpr unsigned getId() { return AttributeKind::FIR_REAL_ATTR; }
162 };
163
164 mlir::Attribute parseFirAttribute(FIROpsDialect *dialect,
165 mlir::DialectAsmParser &parser,
166 mlir::Type type);
167
168 void printFirAttribute(FIROpsDialect *dialect, mlir::Attribute attr,
169 mlir::DialectAsmPrinter &p);
170
171 } // namespace fir
172
173 #endif // OPTIMIZER_DIALECT_FIRATTR_H
fir::ClosedIntervalAttr
Definition: FIRAttr.h:77
fir::UpperBoundAttr
Definition: FIRAttr.h:95
mlir
Definition: ConvertType.h:25
fir::FIROpsDialect
FIR dialect.
Definition: FIRDialect.h:19
fir::SubclassAttr
Definition: FIRAttr.h:55
fir::PointIntervalAttr
Definition: FIRAttr.h:131
fir::LowerBoundAttr
Definition: FIRAttr.h:113
fir::ExactTypeAttr
Definition: FIRAttr.h:39
fir::RealAttr
Definition: FIRAttr.h:147