MLIR  21.0.0git
AffineMapDetail.h
Go to the documentation of this file.
1 //===- AffineMapDetail.h - MLIR Affine Map details Class --------*- 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 AffineMap.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef AFFINEMAPDETAIL_H_
14 #define AFFINEMAPDETAIL_H_
15 
16 #include "mlir/IR/AffineExpr.h"
17 #include "mlir/IR/AffineMap.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/Support/TrailingObjects.h"
21 
22 namespace mlir {
23 namespace detail {
24 
25 struct AffineMapStorage final
27  private llvm::TrailingObjects<AffineMapStorage, AffineExpr> {
28  friend llvm::TrailingObjects<AffineMapStorage, AffineExpr>;
29 
30  /// The hash key used for uniquing.
31  using KeyTy = std::tuple<unsigned, unsigned, ArrayRef<AffineExpr>>;
32 
33  unsigned numDims;
34  unsigned numSymbols;
35  unsigned numResults;
36 
38 
39  /// The affine expressions for this (multi-dimensional) map.
41  return getTrailingObjects(numResults);
42  }
43 
44  bool operator==(const KeyTy &key) const {
45  return std::get<0>(key) == numDims && std::get<1>(key) == numSymbols &&
46  std::get<2>(key) == results();
47  }
48 
49  // Constructs an AffineMapStorage from a key. The context must be set by the
50  // caller.
51  static AffineMapStorage *
53  auto results = std::get<2>(key);
54  auto byteSize =
55  AffineMapStorage::totalSizeToAlloc<AffineExpr>(results.size());
56  auto *rawMem = allocator.allocate(byteSize, alignof(AffineMapStorage));
57  auto *res = new (rawMem) AffineMapStorage();
58  res->numDims = std::get<0>(key);
59  res->numSymbols = std::get<1>(key);
60  res->numResults = results.size();
61  llvm::uninitialized_copy(results, res->getTrailingObjects());
62  return res;
63  }
64 };
65 
66 } // namespace detail
67 } // namespace mlir
68 
69 #endif // AFFINEMAPDETAIL_H_
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.
ArrayRef< AffineExpr > results() const
The affine expressions for this (multi-dimensional) map.
bool operator==(const KeyTy &key) const
std::tuple< unsigned, unsigned, ArrayRef< AffineExpr > > KeyTy
The hash key used for uniquing.
static AffineMapStorage * construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key)