[LLVM] Fix Maintainers.md formatting (NFC)
[llvm-project.git] / mlir / lib / IR / AffineExprDetail.h
blobdfc10542b058958a2ea6b32aac3e1bf712711244
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.
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"
21 namespace mlir {
23 class MLIRContext;
25 namespace detail {
27 /// Base storage class appearing in an affine expression.
28 struct AffineExprStorage : public StorageUniquer::BaseStorage {
29 MLIRContext *context;
30 AffineExprKind kind;
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();
49 return result;
52 AffineExpr lhs;
53 AffineExpr rhs;
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;
70 return result;
73 /// Position of this identifier in the argument list.
74 unsigned position;
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;
88 return result;
91 // The constant.
92 int64_t constant;
95 } // namespace detail
96 } // namespace mlir
97 #endif // MLIR_IR_AFFINEEXPRDETAIL_H_