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