My Project
OpInterfaces.h
Go to the documentation of this file.
1 //===- OpInterfaces.h - OpInterfaces 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 // OpInterfaces wrapper to simplify using TableGen OpInterfaces.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_TABLEGEN_OPINTERFACES_H_
14 #define MLIR_TABLEGEN_OPINTERFACES_H_
15 
16 #include "mlir/Support/LLVM.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 
20 namespace llvm {
21 class Init;
22 class Record;
23 } // end namespace llvm
24 
25 namespace mlir {
26 namespace tblgen {
27 
28 // Wrapper class with helper methods for accessing OpInterfaceMethod defined
29 // in TableGen.
31 public:
32  // This struct represents a single method argument.
33  struct Argument {
34  StringRef type;
35  StringRef name;
36  };
37 
38  explicit OpInterfaceMethod(const llvm::Record *def);
39 
40  // Return the return type of this method.
41  StringRef getReturnType() const;
42 
43  // Return the name of this method.
44  StringRef getName() const;
45 
46  // Return if this method is static.
47  bool isStatic() const;
48 
49  // Return the body for this method if it has one.
50  llvm::Optional<StringRef> getBody() const;
51 
52  // Return the default implementation for this method if it has one.
53  llvm::Optional<StringRef> getDefaultImplementation() const;
54 
55  // Return the description of this method if it has one.
56  llvm::Optional<StringRef> getDescription() const;
57 
58  // Arguments.
59  ArrayRef<Argument> getArguments() const;
60  bool arg_empty() const;
61 
62 private:
63  // The TableGen definition of this method.
64  const llvm::Record *def;
65 
66  // The arguments of this method.
67  SmallVector<Argument, 2> arguments;
68 };
69 
70 //===----------------------------------------------------------------------===//
71 // OpInterface
72 //===----------------------------------------------------------------------===//
73 
74 // Wrapper class with helper methods for accessing OpInterfaces defined in
75 // TableGen.
76 class OpInterface {
77 public:
78  explicit OpInterface(const llvm::Record *def);
79 
80  // Return the name of this interface.
81  StringRef getName() const;
82 
83  // Return the methods of this interface.
84  ArrayRef<OpInterfaceMethod> getMethods() const;
85 
86  // Return the description of this method if it has one.
87  llvm::Optional<StringRef> getDescription() const;
88 
89 private:
90  // The TableGen definition of this interface.
91  const llvm::Record *def;
92 
93  // The methods of this interface.
95 };
96 
97 } // end namespace tblgen
98 } // end namespace mlir
99 
100 #endif // MLIR_TABLEGEN_OPINTERFACES_H_
Definition: InferTypeOpInterface.cpp:20
Definition: PassRegistry.cpp:413
Definition: OpInterfaces.h:33
Definition: LLVM.h:37
Definition: OpInterfaces.h:30
Definition: LLVM.h:35
Definition: OpInterfaces.h:76
StringRef name
Definition: OpInterfaces.h:35
StringRef type
Definition: OpInterfaces.h:34