MLIR  16.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  public llvm::TrailingObjects<AffineMapStorage, AffineExpr> {
28  /// The hash key used for uniquing.
29  using KeyTy = std::tuple<unsigned, unsigned, ArrayRef<AffineExpr>>;
30 
31  unsigned numDims;
32  unsigned numSymbols;
33  unsigned numResults;
34 
36 
37  /// The affine expressions for this (multi-dimensional) map.
39  return {getTrailingObjects<AffineExpr>(), numResults};
40  }
41 
42  bool operator==(const KeyTy &key) const {
43  return std::get<0>(key) == numDims && std::get<1>(key) == numSymbols &&
44  std::get<2>(key) == results();
45  }
46 
47  // Constructs an AffineMapStorage from a key. The context must be set by the
48  // caller.
49  static AffineMapStorage *
51  auto results = std::get<2>(key);
52  auto byteSize =
53  AffineMapStorage::totalSizeToAlloc<AffineExpr>(results.size());
54  auto *rawMem = allocator.allocate(byteSize, alignof(AffineMapStorage));
55  auto *res = new (rawMem) AffineMapStorage();
56  res->numDims = std::get<0>(key);
57  res->numSymbols = std::get<1>(key);
58  res->numResults = results.size();
59  std::uninitialized_copy(results.begin(), results.end(),
60  res->getTrailingObjects<AffineExpr>());
61  return res;
62  }
63 };
64 
65 } // namespace detail
66 } // namespace mlir
67 
68 #endif // AFFINEMAPDETAIL_H_
Include the generated interface declarations.
This is a utility allocator used to allocate memory for instances of derived types.
bool operator==(const KeyTy &key) const
T * allocate()
Allocate an instance of the provided type.
Base type for affine expression.
Definition: AffineExpr.h:68
std::tuple< unsigned, unsigned, ArrayRef< AffineExpr > > KeyTy
The hash key used for uniquing.
This class acts as the base storage that all storage classes must derived from.
static AffineMapStorage * construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key)
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
ArrayRef< AffineExpr > results() const
The affine expressions for this (multi-dimensional) map.