MLIR  20.0.0git
Builder.h
Go to the documentation of this file.
1 //===- Builder.h - Builder classes ------------------------------*- 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 // Builder wrapper to simplify using TableGen Record for building
10 // operations/types/etc.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TABLEGEN_BUILDER_H_
15 #define MLIR_TABLEGEN_BUILDER_H_
16 
17 #include "mlir/Support/LLVM.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 
22 namespace llvm {
23 class Init;
24 class Record;
25 class SMLoc;
26 } // namespace llvm
27 
28 namespace mlir {
29 namespace tblgen {
30 
31 /// Wrapper class with helper methods for accessing Builders defined in
32 /// TableGen.
33 class Builder {
34 public:
35  /// This class represents a single parameter to a builder method.
36  class Parameter {
37  public:
38  /// Return a string containing the C++ type of this parameter.
39  StringRef getCppType() const;
40 
41  /// Return an optional string containing the name of this parameter. If
42  /// std::nullopt, no name was specified for this parameter by the user.
43  std::optional<StringRef> getName() const { return name; }
44 
45  /// Return an optional string containing the default value to use for this
46  /// parameter.
47  std::optional<StringRef> getDefaultValue() const;
48 
49  private:
50  Parameter(std::optional<StringRef> name, const llvm::Init *def)
51  : name(name), def(def) {}
52 
53  /// The optional name of the parameter.
54  std::optional<StringRef> name;
55 
56  /// The tablegen definition of the parameter. This is either a StringInit,
57  /// or a CArg DefInit.
58  const llvm::Init *def;
59 
60  // Allow access to the constructor.
61  friend Builder;
62  };
63 
64  /// Construct a builder from the given Record instance.
65  Builder(const llvm::Record *record, ArrayRef<SMLoc> loc);
66 
67  /// Return a list of parameters used in this build method.
68  ArrayRef<Parameter> getParameters() const { return parameters; }
69 
70  /// Return an optional string containing the body of the builder.
71  std::optional<StringRef> getBody() const;
72 
73  /// Return the deprecation message of the builder.
74  /// Empty optional if the builder is not deprecated.
75  std::optional<StringRef> getDeprecatedMessage() const;
76 
77 protected:
78  /// The TableGen definition of this builder.
79  const llvm::Record *def;
80 
81 private:
82  /// A collection of parameters to the builder.
83  SmallVector<Parameter> parameters;
84 };
85 
86 } // namespace tblgen
87 } // namespace mlir
88 
89 #endif // MLIR_TABLEGEN_BUILDER_H_
This class represents a single parameter to a builder method.
Definition: Builder.h:36
std::optional< StringRef > getDefaultValue() const
Return an optional string containing the default value to use for this parameter.
Definition: Builder.cpp:42
StringRef getCppType() const
Return a string containing the C++ type of this parameter.
Definition: Builder.cpp:26
std::optional< StringRef > getName() const
Return an optional string containing the name of this parameter.
Definition: Builder.h:43
Wrapper class with helper methods for accessing Builders defined in TableGen.
Definition: Builder.h:33
Builder(const llvm::Record *record, ArrayRef< SMLoc > loc)
Construct a builder from the given Record instance.
const llvm::Record * def
The TableGen definition of this builder.
Definition: Builder.h:79
ArrayRef< Parameter > getParameters() const
Return a list of parameters used in this build method.
Definition: Builder.h:68
std::optional< StringRef > getDeprecatedMessage() const
Return the deprecation message of the builder.
Definition: Builder.cpp:89
std::optional< StringRef > getBody() const
Return an optional string containing the body of the builder.
Definition: Builder.cpp:84
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Include the generated interface declarations.