MLIR 22.0.0git
Trait.h
Go to the documentation of this file.
1//===- Trait.h - Trait wrapper 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// Trait wrapper to simplify using TableGen Record defining an MLIR Trait.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TABLEGEN_TRAIT_H_
14#define MLIR_TABLEGEN_TRAIT_H_
15
16#include "mlir/Support/LLVM.h"
17#include "llvm/ADT/StringRef.h"
18#include <vector>
19
20namespace llvm {
21class Init;
22class Record;
23} // namespace llvm
24
25namespace mlir {
26namespace tblgen {
27
28class Interface;
29
30// Wrapper class with helper methods for accessing Trait constraints defined in
31// TableGen.
32class Trait {
33public:
34 // Discriminator for kinds of traits.
35 enum class Kind {
36 // Trait corresponding to C++ class.
38 // Trait corresponding to a predicate.
40 // Trait controlling definition generator internals.
42 // Trait corresponding to an Interface.
44 };
45
46 explicit Trait(Kind kind, const llvm::Record *def);
47
48 // Returns an Trait corresponding to the init provided.
49 static Trait create(const llvm::Init *init);
50
51 Kind getKind() const { return kind; }
52
53 // Returns the Tablegen definition this operator was constructed from.
54 const llvm::Record &getDef() const { return *def; }
55
56protected:
57 // The TableGen definition of this trait.
58 const llvm::Record *def;
60};
61
62// Trait corresponding to a native C++ Trait.
63class NativeTrait : public Trait {
64public:
65 // Returns the trait corresponding to a C++ trait class.
66 std::string getFullyQualifiedTraitName() const;
67
68 // Returns if this is a structural op trait.
69 bool isStructuralOpTrait() const;
70
71 // Returns extra class declaration code to be added to the concrete instance
72 // when the trait is specified
73 StringRef getExtraConcreteClassDeclaration() const;
74
75 // Returns extra class definition code to be added to the concrete instance
76 // when the trait is specified
77 StringRef getExtraConcreteClassDefinition() const;
78
79 static bool classof(const Trait *t) { return t->getKind() == Kind::Native; }
80};
81
82// Trait corresponding to a predicate on the operation.
83class PredTrait : public Trait {
84public:
85 // Returns the template for constructing the predicate.
86 std::string getPredTemplate() const;
87
88 // Returns the description of what the predicate is verifying.
89 StringRef getSummary() const;
90
91 static bool classof(const Trait *t) { return t->getKind() == Kind::Pred; }
92};
93
94// Trait controlling op definition generator internals.
95class InternalTrait : public Trait {
96public:
97 // Returns the trait controlling op definition generator internals.
98 StringRef getFullyQualifiedTraitName() const;
99
100 static bool classof(const Trait *t) { return t->getKind() == Kind::Internal; }
101};
102
103// Trait corresponding to an OpInterface on the operation.
104class InterfaceTrait : public Trait {
105public:
106 // Returns interface corresponding to the trait.
107 Interface getInterface() const;
108
109 // Returns the trait corresponding to a C++ trait class.
110 std::string getFullyQualifiedTraitName() const;
111
112 static bool classof(const Trait *t) {
113 return t->getKind() == Kind::Interface;
114 }
115
116 // Whether the declaration of methods for this trait should be emitted.
117 bool shouldDeclareMethods() const;
118
119 // Returns the methods that should always be declared if this interface is
120 // emitting declarations.
121 std::vector<StringRef> getAlwaysDeclaredMethods() const;
122};
123
124} // namespace tblgen
125} // namespace mlir
126
127#endif // MLIR_TABLEGEN_TRAIT_H_
static bool classof(const Trait *t)
Definition Trait.h:112
std::vector< StringRef > getAlwaysDeclaredMethods() const
Definition Trait.cpp:101
std::string getFullyQualifiedTraitName() const
Definition Trait.cpp:90
Interface getInterface() const
Definition Trait.cpp:88
bool shouldDeclareMethods() const
Definition Trait.cpp:97
StringRef getFullyQualifiedTraitName() const
Definition Trait.cpp:67
static bool classof(const Trait *t)
Definition Trait.h:100
bool isStructuralOpTrait() const
Definition Trait.cpp:51
std::string getFullyQualifiedTraitName() const
Definition Trait.cpp:44
static bool classof(const Trait *t)
Definition Trait.h:79
StringRef getExtraConcreteClassDeclaration() const
Definition Trait.cpp:55
StringRef getExtraConcreteClassDefinition() const
Definition Trait.cpp:59
StringRef getSummary() const
Definition Trait.cpp:80
static bool classof(const Trait *t)
Definition Trait.h:91
std::string getPredTemplate() const
Definition Trait.cpp:75
const llvm::Record * def
Definition Trait.h:58
Trait(Kind kind, const llvm::Record *def)
Definition Trait.cpp:38
static Trait create(const llvm::Init *init)
Definition Trait.cpp:26
const llvm::Record & getDef() const
Definition Trait.h:54
Kind getKind() const
Definition Trait.h:51
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.