70 lines · c
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-exception6//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 22namespace mlir {23namespace detail {24 25struct AffineMapStorage final26 : 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(numResults);42 }43 44 bool operator==(const KeyTy &key) const {45 return std::get<0>(key) == numDims && std::get<1>(key) == numSymbols &&46 std::get<2>(key) == results();47 }48 49 // Constructs an AffineMapStorage from a key. The context must be set by the50 // caller.51 static AffineMapStorage *52 construct(StorageUniquer::StorageAllocator &allocator, const KeyTy &key) {53 auto results = std::get<2>(key);54 auto byteSize =55 AffineMapStorage::totalSizeToAlloc<AffineExpr>(results.size());56 auto *rawMem = allocator.allocate(byteSize, alignof(AffineMapStorage));57 auto *res = new (rawMem) AffineMapStorage();58 res->numDims = std::get<0>(key);59 res->numSymbols = std::get<1>(key);60 res->numResults = results.size();61 llvm::uninitialized_copy(results, res->getTrailingObjects());62 return res;63 }64};65 66} // namespace detail67} // namespace mlir68 69#endif // AFFINEMAPDETAIL_H_70