MLIR  20.0.0git
AffineExprDetail.h
Go to the documentation of this file.
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"
20 
21 namespace mlir {
22 
23 class MLIRContext;
24 
25 namespace detail {
26 
27 /// Base storage class appearing in an affine expression.
31 };
32 
33 /// A binary operation appearing in an affine expression.
35  using KeyTy = std::tuple<unsigned, AffineExpr, AffineExpr>;
36 
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;
40  }
41 
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;
50  }
51 
54 };
55 
56 /// A dimensional or symbolic identifier appearing in an affine expression.
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 *
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.
79  using KeyTy = int64_t;
80 
81  bool operator==(const KeyTy &key) const { return constant == key; }
82 
85  auto *result = allocator.allocate<AffineConstantExprStorage>();
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_
Base type for affine expression.
Definition: AffineExpr.h:68
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class acts as the base storage that all storage classes must derived from.
This is a utility allocator used to allocate memory for instances of derived types.
T * allocate()
Allocate an instance of the provided type.
Include the generated interface declarations.
AffineExprKind
Definition: AffineExpr.h:40
@ Constant
Constant integer.
A binary operation appearing in an affine expression.
std::tuple< unsigned, AffineExpr, AffineExpr > KeyTy
bool operator==(const KeyTy &key) const
static AffineBinaryOpExprStorage * construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key)
An integer constant appearing in affine expression.
static AffineConstantExprStorage * construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key)
bool operator==(const KeyTy &key) const
A dimensional or symbolic identifier appearing in an affine expression.
static AffineDimExprStorage * construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key)
bool operator==(const KeyTy &key) const
unsigned position
Position of this identifier in the argument list.
std::pair< unsigned, unsigned > KeyTy
Base storage class appearing in an affine expression.