xref: /llvm-project/mlir/include/mlir/IR/Traits.td (revision b448fe0c126d45eabd6f2994559bb0124dae3113)
1//===-- Traits.td - Trait definations file ------------------*- tablegen -*-===//
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 file contains definations for traits.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef TRAITS_TD
14#define TRAITS_TD
15
16include "mlir/IR/Constraints.td"
17
18//===----------------------------------------------------------------------===//
19// Trait definitions
20//===----------------------------------------------------------------------===//
21
22// Trait represents a trait regarding an attribute, operation, or type.
23class Trait;
24
25// Define a Trait corresponding to a list of Traits, this allows for specifying
26// a list of traits as trait. Avoids needing to do `[Traits, ...] # ListOfTraits
27// # [Others, ...]` while still allowing providing convenient groupings.
28class TraitList<list<Trait> props> : Trait {
29  list<Trait> traits = props;
30}
31
32// NativeTrait corresponds to the MLIR C++ trait mechanism. The purpose to wrap
33// around C++ symbol string with this class is to make traits specified for
34// entities in TableGen less alien and more integrated.
35// `extraConcreteClassDeclaration` and `extraConcreteClassDefinition` code
36// get injected into the entities in which the NativeTrait is specified for.
37class NativeTrait<string name, string entityType,
38                    code extraClassDeclaration = [{}],
39                    code extraClassDefinition = [{}]> : Trait {
40  string trait = name;
41  string cppNamespace = "::mlir::" # entityType # "Trait";
42
43  code extraConcreteClassDeclaration = extraClassDeclaration;
44  code extraConcreteClassDefinition = extraClassDefinition;
45}
46
47// ParamNativeTrait corresponds to the template-parameterized traits in the C++
48// implementation. MLIR uses nested class templates to implement such traits
49// leading to constructs of the form "TraitName<Parameters>::Impl". Use the
50// value in `prop` as the trait name and the value in `params` as parameters to
51// construct the native trait class name.
52class ParamNativeTrait<string prop, string params, string entityType>
53    : NativeTrait<prop # "<" # params # ">::Impl", entityType>;
54
55// GenInternalTrait is a trait that does not have direct C++ mapping but affects
56// an entities definition generator internals, like how operation builders and
57// operand/attribute/result getters are generated.
58class GenInternalTrait<string prop, string entityType> : Trait {
59  string trait = "::mlir::" # entityType # "Trait::" # prop;
60}
61
62// PredTrait is a trait implemented by way of a predicate on an entity.
63class PredTrait<string descr, Pred pred> : Trait {
64  string summary = descr;
65  Pred predicate = pred;
66}
67
68#endif // TRAITS_TD
69