MLIR  16.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  /// None, no name was specified for this parameter by the user.
43  Optional<StringRef> getName() const { return name; }
44 
45  /// Return an optional string containing the default value to use for this
46  /// parameter.
47  Optional<StringRef> getDefaultValue() const;
48 
49  private:
50  Parameter(Optional<StringRef> name, const llvm::Init *def)
51  : name(name), def(def) {}
52 
53  /// The optional name of the parameter.
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  Optional<StringRef> getBody() const;
72 
73 protected:
74  /// The TableGen definition of this builder.
75  const llvm::Record *def;
76 
77 private:
78  /// A collection of parameters to the builder.
79  SmallVector<Parameter> parameters;
80 };
81 
82 } // namespace tblgen
83 } // namespace mlir
84 
85 #endif // MLIR_TABLEGEN_BUILDER_H_
Include the generated interface declarations.
Wrapper class with helper methods for accessing Builders defined in TableGen.
Definition: Builder.h:33
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
ArrayRef< Parameter > getParameters() const
Return a list of parameters used in this build method.
Definition: Builder.h:68
This class represents a single parameter to a builder method.
Definition: Builder.h:36
const llvm::Record * def
The TableGen definition of this builder.
Definition: Builder.h:75
Optional< StringRef > getName() const
Return an optional string containing the name of this parameter.
Definition: Builder.h:43