Data layout information allows to answer questions about the size and alignment properties of a type. It enables, among others, the generation of various linear memory addressing schemes for containers of abstract types and deeper reasoning about vectors. This introduces the subsystem for modeling data layouts in MLIR. The data layout subsystem is designed to scale to MLIR's open type and operation system. At the top level, it consists of attribute interfaces that can be implemented by concrete data layout specifications; type interfaces that should be implemented by types subject to data layout; operation interfaces that must be implemented by operations that can serve as data layout scopes (e.g., modules); and dialect interfaces for data layout properties unrelated to specific types. Built-in types are handled specially to decrease the overall query cost. A concrete default implementation of these interfaces is provided in the new Target dialect. Defaults for built-in types that match the current behavior are also provided. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D97067
30 lines
1.1 KiB
C++
30 lines
1.1 KiB
C++
//===- Traits.cpp - Traits for MLIR DLTI dialect --------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/DLTI/Traits.h"
|
|
#include "mlir/Dialect/DLTI/DLTI.h"
|
|
#include "mlir/Interfaces/DataLayoutInterfaces.h"
|
|
|
|
using namespace mlir;
|
|
|
|
LogicalResult mlir::impl::verifyHasDefaultDLTIDataLayoutTrait(Operation *op) {
|
|
// TODO: consider having trait inheritance so that HasDefaultDLTIDataLayout
|
|
// trait can inherit DataLayoutOpInterface::Trait and enforce the validity of
|
|
// the assertion below.
|
|
assert(
|
|
isa<DataLayoutOpInterface>(op) &&
|
|
"HasDefaultDLTIDataLayout trait unexpectedly attached to an op that does "
|
|
"not implement DataLayoutOpInterface");
|
|
return success();
|
|
}
|
|
|
|
DataLayoutSpecInterface mlir::impl::getDataLayoutSpec(Operation *op) {
|
|
return op->getAttrOfType<DataLayoutSpecAttr>(
|
|
DLTIDialect::kDataLayoutAttrName);
|
|
}
|