[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / lib / IR / AffineMapDetail.h
blob732c7fd1d3a1215065b73cc4c504fefc6c20e3e5
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.
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"
22 namespace mlir {
23 namespace detail {
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>>;
31 unsigned numDims;
32 unsigned numSymbols;
33 unsigned numResults;
35 MLIRContext *context;
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
48 // caller.
49 static AffineMapStorage *
50 construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {
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;
65 } // namespace detail
66 } // namespace mlir
68 #endif // AFFINEMAPDETAIL_H_