1//===- AffineExprDetail.h - MLIR Affine Expr storage details ----*- 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 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.
12//
13//===----------------------------------------------------------------------===//
14#ifndef MLIR_IR_AFFINEEXPRDETAIL_H_
15#define MLIR_IR_AFFINEEXPRDETAIL_H_
16
17#include "mlir/IR/AffineExpr.h"
18#include "mlir/IR/MLIRContext.h"
19#include "mlir/Support/StorageUniquer.h"
20
21namespace mlir {
22
23class MLIRContext;
24
25namespace detail {
26
27/// Base storage class appearing in an affine expression.
28struct AffineExprStorage : public StorageUniquer::BaseStorage {
29 MLIRContext *context;
30 AffineExprKind kind;
31};
32
33/// A binary operation appearing in an affine expression.
34struct AffineBinaryOpExprStorage : public AffineExprStorage {
35 using KeyTy = std::tuple<unsigned, AffineExpr, AffineExpr>;
36
37 bool operator==(const KeyTy &key) const {
38 return static_cast<AffineExprKind>(std::get<0>(t: key)) == kind &&
39 std::get<1>(t: key) == lhs && std::get<2>(t: key) == rhs;
40 }
41
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>(t: key));
46 result->lhs = std::get<1>(t: key);
47 result->rhs = std::get<2>(t: key);
48 result->context = result->lhs.getContext();
49 return result;
50 }
51
52 AffineExpr lhs;
53 AffineExpr rhs;
54};
55
56/// A dimensional or symbolic identifier appearing in an affine expression.
57struct AffineDimExprStorage : public AffineExprStorage {
58 using KeyTy = std::pair<unsigned, unsigned>;
59
60 bool operator==(const KeyTy &key) const {
61 return kind == static_cast<AffineExprKind>(key.first) &&
62 position == key.second;
63 }
64
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;
70 return result;
71 }
72
73 /// Position of this identifier in the argument list.
74 unsigned position;
75};
76
77/// An integer constant appearing in affine expression.
78struct AffineConstantExprStorage : public AffineExprStorage {
79 using KeyTy = int64_t;
80
81 bool operator==(const KeyTy &key) const { return constant == key; }
82
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;
88 return result;
89 }
90
91 // The constant.
92 int64_t constant;
93};
94
95} // namespace detail
96} // namespace mlir
97#endif // MLIR_IR_AFFINEEXPRDETAIL_H_
98

source code of mlir/lib/IR/AffineExprDetail.h