1 //===- AffineExprDetail.h - MLIR Affine Expr storage details ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This holds implementation details of AffineExpr. Ideally it would not be
10 // exposed and would be kept local to AffineExpr.cpp however, MLIRContext.cpp
11 // needs to know the sizes for placement-new style Allocation.
13 //===----------------------------------------------------------------------===//
14 #ifndef MLIR_IR_AFFINEEXPRDETAIL_H_
15 #define MLIR_IR_AFFINEEXPRDETAIL_H_
17 #include "mlir/IR/AffineExpr.h"
18 #include "mlir/IR/MLIRContext.h"
19 #include "mlir/Support/StorageUniquer.h"
27 /// Base storage class appearing in an affine expression.
28 struct AffineExprStorage
: public StorageUniquer::BaseStorage
{
33 /// A binary operation appearing in an affine expression.
34 struct AffineBinaryOpExprStorage
: public AffineExprStorage
{
35 using KeyTy
= std::tuple
<unsigned, AffineExpr
, AffineExpr
>;
37 bool operator==(const KeyTy
&key
) const {
38 return static_cast<AffineExprKind
>(std::get
<0>(key
)) == kind
&&
39 std::get
<1>(key
) == lhs
&& std::get
<2>(key
) == rhs
;
42 static AffineBinaryOpExprStorage
*
43 construct(StorageUniquer::StorageAllocator
&allocator
, const KeyTy
&key
) {
44 auto *result
= allocator
.allocate
<AffineBinaryOpExprStorage
>();
45 result
->kind
= static_cast<AffineExprKind
>(std::get
<0>(key
));
46 result
->lhs
= std::get
<1>(key
);
47 result
->rhs
= std::get
<2>(key
);
48 result
->context
= result
->lhs
.getContext();
56 /// A dimensional or symbolic identifier appearing in an affine expression.
57 struct AffineDimExprStorage
: public AffineExprStorage
{
58 using KeyTy
= std::pair
<unsigned, unsigned>;
60 bool operator==(const KeyTy
&key
) const {
61 return kind
== static_cast<AffineExprKind
>(key
.first
) &&
62 position
== key
.second
;
65 static AffineDimExprStorage
*
66 construct(StorageUniquer::StorageAllocator
&allocator
, const KeyTy
&key
) {
67 auto *result
= allocator
.allocate
<AffineDimExprStorage
>();
68 result
->kind
= static_cast<AffineExprKind
>(key
.first
);
69 result
->position
= key
.second
;
73 /// Position of this identifier in the argument list.
77 /// An integer constant appearing in affine expression.
78 struct AffineConstantExprStorage
: public AffineExprStorage
{
79 using KeyTy
= int64_t;
81 bool operator==(const KeyTy
&key
) const { return constant
== key
; }
83 static AffineConstantExprStorage
*
84 construct(StorageUniquer::StorageAllocator
&allocator
, const KeyTy
&key
) {
85 auto *result
= allocator
.allocate
<AffineConstantExprStorage
>();
86 result
->kind
= AffineExprKind::Constant
;
87 result
->constant
= key
;
97 #endif // MLIR_IR_AFFINEEXPRDETAIL_H_