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" |
18 | #include "mlir/Support/StorageUniquer.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 |
26 | : public StorageUniquer::BaseStorage, |
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 | |
35 | MLIRContext *context; |
36 | |
37 | /// The affine expressions for this (multi-dimensional) map. |
38 | ArrayRef<AffineExpr> results() const { |
39 | return {getTrailingObjects<AffineExpr>(), numResults}; |
40 | } |
41 | |
42 | bool operator==(const KeyTy &key) const { |
43 | return std::get<0>(t: key) == numDims && std::get<1>(t: key) == numSymbols && |
44 | std::get<2>(t: key) == results(); |
45 | } |
46 | |
47 | // Constructs an AffineMapStorage from a key. The context must be set by the |
48 | // caller. |
49 | static AffineMapStorage * |
50 | construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) { |
51 | auto results = std::get<2>(t: key); |
52 | auto byteSize = |
53 | AffineMapStorage::totalSizeToAlloc<AffineExpr>(Counts: results.size()); |
54 | auto *rawMem = allocator.allocate(size: byteSize, alignment: alignof(AffineMapStorage)); |
55 | auto *res = new (rawMem) AffineMapStorage(); |
56 | res->numDims = std::get<0>(t: key); |
57 | res->numSymbols = std::get<1>(t: key); |
58 | res->numResults = results.size(); |
59 | std::uninitialized_copy(first: results.begin(), last: results.end(), |
60 | result: res->getTrailingObjects<AffineExpr>()); |
61 | return res; |
62 | } |
63 | }; |
64 | |
65 | } // namespace detail |
66 | } // namespace mlir |
67 | |
68 | #endif // AFFINEMAPDETAIL_H_ |
69 | |