My Project
OpTrait.h
Go to the documentation of this file.
1 //===- OpTrait.h - OpTrait wrapper class ------------------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 // OpTrait wrapper to simplify using TableGen Record defining an MLIR OpTrait.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_TABLEGEN_OPTRAIT_H_
14 #define MLIR_TABLEGEN_OPTRAIT_H_
15 
16 #include "mlir/Support/LLVM.h"
17 #include "llvm/ADT/StringRef.h"
18 
19 namespace llvm {
20 class Init;
21 class Record;
22 } // end namespace llvm
23 
24 namespace mlir {
25 namespace tblgen {
26 
27 class OpInterface;
28 
29 // Wrapper class with helper methods for accessing OpTrait constraints defined
30 // in TableGen.
31 class OpTrait {
32 public:
33  // Discriminator for kinds of op traits.
34  enum class Kind {
35  // OpTrait corresponding to C++ class.
36  Native,
37  // OpTrait corresponding to predicate on operation.
38  Pred,
39  // OpTrait controlling op definition generator internals.
40  Internal,
41  // OpTrait corresponding to OpInterface.
42  Interface
43  };
44 
45  explicit OpTrait(Kind kind, const llvm::Record *def);
46 
47  // Returns an OpTrait corresponding to the init provided.
48  static OpTrait create(const llvm::Init *init);
49 
50  Kind getKind() const { return kind; }
51 
52 protected:
53  // The TableGen definition of this trait.
54  const llvm::Record *def;
56 };
57 
58 // OpTrait corresponding to a native C++ OpTrait.
59 class NativeOpTrait : public OpTrait {
60 public:
61  // Returns the trait corresponding to a C++ trait class.
62  StringRef getTrait() const;
63 
64  static bool classof(const OpTrait *t) { return t->getKind() == Kind::Native; }
65 };
66 
67 // OpTrait corresponding to a predicate on the operation.
68 class PredOpTrait : public OpTrait {
69 public:
70  // Returns the template for constructing the predicate.
71  std::string getPredTemplate() const;
72 
73  // Returns the description of what the predicate is verifying.
74  StringRef getDescription() const;
75 
76  static bool classof(const OpTrait *t) { return t->getKind() == Kind::Pred; }
77 };
78 
79 // OpTrait controlling op definition generator internals.
80 class InternalOpTrait : public OpTrait {
81 public:
82  // Returns the trait controlling op definition generator internals.
83  StringRef getTrait() const;
84 
85  static bool classof(const OpTrait *t) {
86  return t->getKind() == Kind::Internal;
87  }
88 };
89 
90 // OpTrait corresponding to an OpInterface on the operation.
91 class InterfaceOpTrait : public OpTrait {
92 public:
93  // Returns member function definitions corresponding to the trait,
94  OpInterface getOpInterface() const;
95 
96  // Returns the trait corresponding to a C++ trait class.
97  StringRef getTrait() const;
98 
99  static bool classof(const OpTrait *t) {
100  return t->getKind() == Kind::Interface;
101  }
102 
103  // Whether the declaration of methods for this trait should be emitted.
104  bool shouldDeclareMethods() const;
105 };
106 
107 } // end namespace tblgen
108 } // end namespace mlir
109 
110 #endif // MLIR_TABLEGEN_OPTRAIT_H_
Definition: InferTypeOpInterface.cpp:20
Definition: PassRegistry.cpp:413
const llvm::Record * def
Definition: OpTrait.h:54
Definition: OpTrait.h:31
Kind
Definition: OpTrait.h:34
Definition: OpTrait.h:80
static bool classof(const OpTrait *t)
Definition: OpTrait.h:99
Kind kind
Definition: OpTrait.h:55
Definition: Predicate.h:33
Definition: OpTrait.h:68
Kind getKind() const
Definition: OpTrait.h:50
Definition: OpInterfaces.h:76
static bool classof(const OpTrait *t)
Definition: OpTrait.h:64
static bool classof(const OpTrait *t)
Definition: OpTrait.h:85
Definition: OpTrait.h:91
static bool classof(const OpTrait *t)
Definition: OpTrait.h:76
Definition: OpTrait.h:59