1 //===- AffineMapDetail.h - MLIR Affine Map details Class --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This holds implementation details of AffineMap.
11 //===----------------------------------------------------------------------===//
13 #ifndef AFFINEMAPDETAIL_H_
14 #define AFFINEMAPDETAIL_H_
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"
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
>>;
37 /// The affine expressions for this (multi-dimensional) map.
38 ArrayRef
<AffineExpr
> results() const {
39 return {getTrailingObjects
<AffineExpr
>(), numResults
};
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();
47 // Constructs an AffineMapStorage from a key. The context must be set by the
49 static AffineMapStorage
*
50 construct(StorageUniquer::StorageAllocator
&allocator
, const KeyTy
&key
) {
51 auto results
= std::get
<2>(key
);
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
>());
68 #endif // AFFINEMAPDETAIL_H_