1 //===- Traits.h - Trait Declaration for MLIR DLTI dialect -------*- 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 #ifndef MLIR_DIALECT_DLTI_TRAITS_H 10 #define MLIR_DIALECT_DLTI_TRAITS_H 11 12 #include "mlir/IR/OpDefinition.h" 13 #include "mlir/Interfaces/DataLayoutInterfaces.h" 14 15 namespace mlir { 16 class DataLayoutSpecAttr; 17 18 namespace impl { 19 LogicalResult verifyHasDefaultDLTIDataLayoutTrait(Operation *op); 20 DataLayoutSpecInterface getDataLayoutSpec(Operation *op); 21 } // namespace impl 22 23 /// Trait to be used by operations willing to use the implementation of the 24 /// data layout interfaces provided by the Target dialect. 25 template <typename ConcreteOp> 26 class HasDefaultDLTIDataLayout 27 : public OpTrait::TraitBase<ConcreteOp, HasDefaultDLTIDataLayout> { 28 public: 29 /// Verifies that the operation to which this trait is attached is valid for 30 /// the trait, i.e., that it implements the data layout operation interface. verifyTrait(Operation * op)31 static LogicalResult verifyTrait(Operation *op) { 32 return impl::verifyHasDefaultDLTIDataLayoutTrait(op); 33 } 34 35 /// Returns the data layout specification as provided by the Target dialect 36 /// specification attribute. getDataLayoutSpec()37 DataLayoutSpecInterface getDataLayoutSpec() { 38 return impl::getDataLayoutSpec(this->getOperation()); 39 } 40 }; 41 } // namespace mlir 42 43 #endif // MLIR_DIALECT_DLTI_TRAITS_H 44